:root {
    --fg: #1f2937;
    --muted: #6b7280;
    --bg: #fff;
    --card: #fff;
    --bd: #e5e7eb;
    --pill: #f1f5f9;
    --falso: #fee2e2;
    --eng: #fef3c7;
    --spr: #e5e7eb;
    --verd: #dcfce7;
    --link: #0b67ff;
    --page-gutter: 14px;
}

/* PROTECCIÓN PRINCIPAL CONTRA OVERFLOW */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0 auto;
    padding: 16px var(--page-gutter);
    max-width: 1200px;
    width: 100%;
    color: var(--fg);
    background: var(--bg);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.45;
}

/* PROTECCIÓN PARA TEXTO LARGO */
.wrap, h1, h2, h3, p, .meta, .source span, .btn, nav a {
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
}

header {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 6px;
    padding: 0 var(--page-gutter);
}

h1 {
    font-size: 28px;
    margin: 0;
}

nav a {
    margin-right: 12px;
    color: var(--link);
    text-decoration: none;
}

nav a:hover {
    text-decoration: underline;
}

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

input, select {
    padding: 8px;
    border: 1px solid var(--bd);
    border-radius: 8px;
    min-width: 160px;
    max-width: 100%;
}

/* GRID SEGURO */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 18px;
    margin-top: 14px;
    width: 100%;
    overflow-x: clip;
    padding: 0 var(--page-gutter);
    align-items: start;
}

/* CARDS PROTEGIDAS */
.card {
    border: 1px solid var(--bd);
    border-radius: 12px;
    background: var(--card);
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.card * {
    min-width: 0;
    max-width: 100%;
}

.card-cover {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    background: #f3f4f6;
    aspect-ratio: 16/9;
    margin: 0 0 10px 0;
    width: 100%;
}

.card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-cover.noimg {
    background: linear-gradient(135deg, #e5e7eb, #f1f5f9);
}

h2 {
    font-size: 1.08rem;
    margin: .25rem 0 .15rem;
    line-height: 1.28;
}

h2 a {
    color: inherit;
    text-decoration: none;
}

.meta {
    color: var(--muted);
    font-size: .9em;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--pill);
    margin-top: 6px;
}

.badge.small {
    font-size: .8em;
    padding: 3px 7px;
}

.pill {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--pill);
    font-size: .9em;
}

.counter {
    color: var(--muted);
    margin-top: 8px;
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.source {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    color: var(--muted);
    font-size: .9em;
    overflow: hidden;
}

.source img {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
}

.source span {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btnrow {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
    max-width: 100%;
}

.btn {
    display: inline-block;
    padding: 8px 10px;
    border: 1px solid var(--bd);
    border-radius: 10px;
    background: #fff;
    white-space: nowrap;
}

.btn:hover {
    background: #f8fafc;
}

.clamp-3 {
    -webkit-box-orient: vertical;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Media queries responsivas */
@media (max-width: 420px) {
    :root {
        --page-gutter: 10px;
    }
    
    .filters {
        flex-direction: column;
    }
    
    input, select {
        min-width: 100%;
    }
}

@media (min-width: 1280px) {
    :root {
        --page-gutter: 18px;
    }
}

/* Modo oscuro */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b0e12;
        --card: #0f1318;
        --fg: #e5e7eb;
        --bd: #1f2937;
        --pill: #111827;
    }
}

footer {
    padding: 0 var(--page-gutter);
}
