/* ==========================================================================
   1. VARIABLES DE DISEÑO (mismas que MATEMATICAS)
   ========================================================================== */
:root {
    --bg-main: #fcfbf7;
    --surface: #ffffff;
    --text-dark: #1a1a1a;
    --text-muted: #666;
    --border-soft: #e0dcd3;
    --tag-bg: #f0ede6;

    --color-easy: #4caf50;
    --color-medium: #2196f3;

    --radius-lg: 16px;
    --radius-md: 8px;
    --transition: all 0.3s ease;

    /* Ancho máximo compartido por cabecera y contenido */
    --page-max: 1050px;
    --page-pad: 20px;

    /* Tarjetas de juegos: nº por fila, separación y altura de la imagen */
    --cards-per-row: 4;
    --cards-gap: 16px;
    --img-h: clamp(110px, 22vh, 190px);
}

/* ==========================================================================
   2. BASE
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-dark);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

a:focus-visible {
    outline: 3px solid var(--color-medium);
    outline-offset: 2px;
}

/* ==========================================================================
   3. CABECERA (logo Kj igual que en los juegos)
   La banda ocupa todo el ancho; su contenido se centra con un máximo de 1050px.
   ========================================================================== */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
}

.header-inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 12px var(--page-pad);
}

.logo {
    justify-self: start;
    font-size: 1.25rem;
    letter-spacing: -0.5px;
}

.site-name {
    justify-self: center;
    color: var(--color-easy);
    font-size: clamp(0.9rem, 3.8vw, 1.3rem);
    font-weight: 800;
    white-space: nowrap;
}

.header-note {
    justify-self: end;
    color: var(--text-muted);
    font-size: 0.95rem;
    white-space: nowrap;
}

/* ==========================================================================
   4. CONTENEDOR Y TEXTOS
   ========================================================================== */
.game-container {
    flex: 1;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: clamp(10px, 2.5vh, 2px) var(--page-pad);
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.intro {
    margin-bottom: clamp(14px, 3vh, 28px);
    text-align: center;
}

.main-title {
    margin-bottom: 8px;
    font-size: 2.2rem;
}

.subtitle {
    max-width: 720px;
    margin: 0 auto;
    color: var(--text-muted);
}

/* ==========================================================================
   5. LISTA DE JUEGOS
   Las tarjetas se reparten en filas y la última fila queda centrada.
   ========================================================================== */
.games-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--cards-gap);
}

.game-card {
    width: calc((100% - (var(--cards-per-row) - 1) * var(--cards-gap)) / var(--cards-per-row));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border: 2px solid var(--border-soft);
    border-radius: var(--radius-lg);
    transition: var(--transition);
}

.game-card:hover,
.game-card:focus-within {
    transform: translateY(-4px);
    border-color: var(--color-easy);
    box-shadow: 0 10px 20px rgba(76, 175, 80, 0.1);
}

.game-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    color: inherit;
    text-decoration: none;
    outline-offset: -4px;
}

.game-image {
    padding: 10px;
    display: grid;
    place-items: center;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-soft);
}

.game-image img {
    display: block;
    width: 100%;
    height: var(--img-h);
    object-fit: contain;
}

.game-content {
    flex: 1;
    padding: 14px;
    display: flex;
    flex-direction: column;
}

.game-category {
    align-self: flex-start;
    margin-bottom: 8px;
    padding: 3px 10px;
    background: var(--tag-bg);
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
}

.game-content h2 {
    font-size: 1.25rem;
    line-height: 1.25;
}

.game-content p {
    margin: 8px 0 12px;
    color: var(--text-muted);
    font-size: 1rem;
}

.play-link {
    margin-top: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--color-easy);
    font-size: 1.05rem;
    font-weight: 800;
}

.play-link span {
    transition: transform 0.2s ease;
}

.game-card:hover .play-link span {
    transform: translateX(4px);
}

/* ==========================================================================
   6. PIE
   ========================================================================== */
.footer-note {
    margin-top: auto;
    padding-top: clamp(14px, 3vh, 28px);
    color: #888;
    text-align: center;
}

.footer-note p + p {
    margin-top: 2px;
}

/* ==========================================================================
   7. PANTALLAS BAJAS (portátiles con ventana de poca altura)
   ========================================================================== */
@media (min-width: 1000px) and (max-height: 700px) {
    .main-title {
        font-size: 2rem;
    }
}

/* ==========================================================================
   8. ADAPTACIÓN POR ANCHO
   ========================================================================== */
/* La nota del header solo se muestra cuando cabe en una línea */
@media (max-width: 1080px) {
    .header-note {
        display: none;
    }
}

@media (max-width: 999px) {
    :root {
        --cards-per-row: 3;
    }
}

@media (max-width: 768px) {
    :root {
        --page-pad: 15px;
        --img-h: clamp(120px, 22vh, 190px);
    }

    /* Cabecera móvil: logo a la izquierda, título centrado y la frase debajo */
    .header-inner {
        grid-template-columns: 1fr auto 1fr;
        row-gap: 2px;
        padding: 10px var(--page-pad);
    }

    .site-name {
        font-size: clamp(0.78rem, 3.7vw, 1.2rem);
    }

    .header-note {
        display: block;
        grid-column: 1 / -1;
        justify-self: center;
        text-align: center;
        text-wrap: balance;
        white-space: normal;
    }

    .main-title {
        font-size: 1.4rem;
    }
}

@media (max-width: 640px) {
    :root {
        --cards-per-row: 1;
    }

    .games-grid {
        width: 100%;
        max-width: 460px;
        margin: 0 auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .game-card,
    .play-link span {
        transition: none;
    }
}