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

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

    --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;

    /* Tamaños que escalan con la ALTURA de la ventana para evitar scroll */
    --block-gap: clamp(8px, 1.8vh, 18px);
    --img-h: clamp(56px, 13vh, 110px);
}

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

[hidden] {
    display: none !important;
}

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;
}

button {
    font-family: inherit;
    font-weight: 600;
}

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

/* ==========================================================================
   3. CABECERA (igual que MATEMATICAS)
   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;
}

.nav-link {
    justify-self: center;
    color: var(--color-easy);
    font-size: clamp(0.9rem, 3.8vw, 1.125rem);
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.nav-link:hover {
    color: #000;
    text-decoration: underline;
}

.site-header .btn-secondary {
    justify-self: end;
}

/* ==========================================================================
   4. CONTENEDOR
   Los bloques se apilan en columna con un único "gap" entre ellos.
   ========================================================================== */
.game-container {
    flex: 1;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: clamp(10px, 2.5vh, 28px) var(--page-pad);
    display: flex;
    flex-direction: column;
    gap: var(--block-gap);
}

.intro {
    text-align: center;
}

.intro h1 {
    font-size: clamp(1.3rem, 3.6vh, 1.7rem);
    letter-spacing: -0.5px;
}

.intro p {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* ==========================================================================
   5. ESTADO Y CONTROLES
   ========================================================================== */
.status-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.stat-box {
    padding: 8px 18px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

.stat-box strong {
    color: var(--text-dark);
}

.controls-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.level-picker {
    display: flex;
    align-items: center;
    gap: 10px;
}

.level-picker-label {
    color: var(--text-muted);
    font-weight: 600;
}

.level-buttons {
    display: flex;
    gap: 6px;
}

/* Cada nivel usa su color (verde / azul / rojo), como en MATEMATICAS */
.level-button {
    --level-color: var(--text-dark);
    padding: 8px 16px;
    background: var(--surface);
    color: var(--text-dark);
    border: 2px solid var(--border-soft);
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

.level-button.easy   { --level-color: var(--color-easy); }
.level-button.medium { --level-color: var(--color-medium); }
.level-button.hard   { --level-color: var(--color-hard); }

.level-button:hover {
    border-color: var(--level-color);
}

.level-button.is-active {
    background: var(--level-color);
    border-color: var(--level-color);
    color: #fff;
}

/* ==========================================================================
   6. PANELES DE JUEGO Y RESULTADOS
   ========================================================================== */
.panel {
    padding: clamp(10px, 2vh, 18px) 16px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    text-align: center;
}

.panel h2 {
    font-size: clamp(1.15rem, 3vh, 1.4rem);
    letter-spacing: -0.3px;
}

.instructions {
    margin: 2px 0 clamp(6px, 1.4vh, 12px);
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Las fichas se centran aunque haya menos de 5 */
.objects-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.object-tile,
.choice {
    width: 140px;
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--surface);
    color: var(--text-dark);
    border: 2px solid var(--border-soft);
    border-radius: var(--radius-md);
}

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

.object-name {
    color: #555;
    font-size: 1.05rem;
    font-weight: 500;
    line-height: 1.2;
}

.choice {
    cursor: pointer;
    transition: var(--transition);
}

.choice:hover:not(:disabled) {
    transform: translateY(-4px);
    border-color: var(--text-dark);
}

.choice:disabled {
    cursor: default;
}

.choice.correct {
    background: #e8f5e9;
    border-color: var(--color-easy);
}

.choice.wrong {
    background: #ffebee;
    border-color: var(--color-hard);
}

.bottom-row {
    min-height: 42px;
    margin-top: clamp(6px, 1.4vh, 12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.timer-note {
    color: var(--text-muted);
}

.results {
    padding-top: 22px;
    padding-bottom: 22px;
}

.result-emoji {
    font-size: 2.6rem;
}

.results h2 {
    margin: 6px 0;
    font-size: 1.6rem;
}

.results p {
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 1.1rem;
}

.results .results-score {
    color: var(--text-dark);
}

.results .btn-primary {
    margin-top: 8px;
}

/* ==========================================================================
   7. PROGRESO Y MENSAJES
   El mensaje reserva siempre su altura para que el tablero no "salte".
   ========================================================================== */
.progress-track {
    height: 6px;
    overflow: hidden;
    background: var(--border-soft);
    border-radius: 99px;
}

#progress-bar {
    width: 0;
    height: 100%;
    background: var(--color-easy);
    border-radius: inherit;
    transition: width 0.25s;
}

.feedback {
    min-height: 44px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 1.05rem;
    font-weight: 600;
    text-align: center;
}

.feedback.is-correct { background: #e8f5e9; color: #2e7d32; border-color: #c8e6c9; }
.feedback.is-wrong   { background: #ffebee; color: #c62828; border-color: #ffcdd2; }

.footer-note {
    color: #888;
    text-align: center;
}

/* ==========================================================================
   8. BOTONES
   ========================================================================== */
.btn-primary,
.btn-secondary {
    border-radius: var(--radius-md);
    cursor: pointer;
}

.btn-primary   { padding: 10px 20px; background: var(--text-dark); color: #fff; border: none; font-size: 1rem; }
.btn-secondary { padding: 8px 16px; background: transparent; color: var(--text-dark); border: 1px solid var(--text-dark); font-size: 0.9rem; }

button:hover:not(:disabled) {
    opacity: 0.9;
}

/* Hover de los botones de contorno (Irten, Nola jokatu?...) */
.btn-secondary {
    transition: var(--transition);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--text-dark);
    color: #fff;
    opacity: 1;
}

/* ==========================================================================
   9. MODAL DE REGLAS (igual que MATEMATICAS)
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 90%;
    max-width: 500px;
    padding: 30px;
    background: var(--surface);
    border-radius: var(--radius-lg);
}

.modal-content h2 { margin-bottom: 15px; }
.modal-content p  { margin-bottom: 15px; color: #444; }
.modal-content ul { margin: 0 0 25px 20px; color: #555; }
.modal-content li { margin-bottom: 8px; }

/* ==========================================================================
   10. PANTALLAS BAJAS (portátiles con ventana de poca altura)
   ========================================================================== */
@media (max-height: 700px) {
    .intro p,
    .footer-note {
        display: none;
    }
}

@media (max-height: 560px) {
    .intro,
    .instructions {
        display: none;
    }
}

/* ==========================================================================
   11. MÓVIL
   ========================================================================== */
@media (max-width: 768px) {
    :root {
        --page-pad: 15px;
        --img-h: clamp(48px, 10vh, 80px);
    }

    .header-inner {
        grid-template-columns: auto 1fr auto;
        padding: 10px var(--page-pad);
    }

    .site-header .btn-secondary {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .intro p {
        font-size: 1rem;
    }

    .status-row {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .stat-box {
        padding: 6px 4px;
        font-size: 0.85rem;
        text-align: center;
        white-space: normal;
    }

    .level-picker-label {
        display: none;
    }

    .level-button {
        padding: 7px 10px;
        font-size: 0.9rem;
    }

    .objects-grid {
        gap: 8px;
    }

    /* Tres fichas por fila */
    .object-tile,
    .choice {
        width: calc((100% - 16px) / 3);
    }

    .object-name {
        font-size: 0.9rem;
    }

    .instructions {
        font-size: 1rem;
    }

    .feedback {
        min-height: 38px;
        padding: 6px 12px;
        font-size: 0.95rem;
    }
}

@media (max-width: 768px) and (max-height: 700px) {
    .intro,
    .instructions {
        display: none;
    }
}

@media (max-width: 768px) and (max-height: 620px) {
    :root {
        --img-h: 44px;
        --block-gap: 6px;
    }

    .header-inner {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .game-container {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .stat-box {
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .panel {
        padding: 8px 8px;
    }

    .bottom-row {
        min-height: 36px;
        margin-top: 6px;
    }

    .feedback {
        min-height: 34px;
        font-size: 0.9rem;
    }
}
