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

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

    --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 del tablero: escalan con la ALTURA de la ventana para evitar scroll */
    --board-gap: clamp(8px, 1.8vh, 18px);
    --card-h: clamp(70px, 15vh, 100px);
    --op-size: clamp(42px, 8vh, 55px);
}

/* ==========================================================================
   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;
}

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

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

/* ==========================================================================
   3. CABECERA
   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 Y PANTALLAS
   ========================================================================== */
.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;
}

.screen {
    display: none;
    animation: fadeIn 0.4s ease forwards;
}

.screen.active {
    display: block;
}

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

/* ==========================================================================
   5. TEXTOS GENERALES
   ========================================================================== */
.main-title {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 40px;
}

.section-title {
    text-align: center;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
}

/* ==========================================================================
   6. SELECCIÓN DE DIFICULTAD
   ========================================================================== */
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 25px;
    margin-top: 20px;
}

.card-diff {
    width: 100%;
    padding: 12px 20px;
    background: var(--surface);
    border: 2px solid var(--border-soft);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    color: inherit;
}

.diff-title {
    font-size: 1.6rem;
    margin-bottom: 15px;
}

.diff-icon {
    display: flex;
    align-items: center;
    height: 80px;
    font-size: 2rem;
    font-weight: bold;
}

.diff-desc {
    margin-top: 15px;
    font-size: 1rem;
    color: #555;
}

.card-diff.easy .diff-icon   { color: var(--color-easy); }
.card-diff.medium .diff-icon { color: var(--color-medium); }
.card-diff.hard .diff-icon   { color: var(--color-hard); }

.card-diff.easy:hover   { border-color: var(--color-easy);   box-shadow: 0 10px 20px rgba(76, 175, 80, 0.1); }
.card-diff.medium:hover { border-color: var(--color-medium); box-shadow: 0 10px 20px rgba(33, 150, 243, 0.1); }
.card-diff.hard:hover   { border-color: var(--color-hard);   box-shadow: 0 10px 20px rgba(244, 67, 54, 0.1); }

/* ==========================================================================
   7. MENSAJES (flotan sobre el tablero: no ocupan espacio ni provocan scroll)
   ========================================================================== */
.feedback-banner {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    text-align: center;
    font-weight: 600;
    font-size: 1.05rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    animation: slideDown 0.3s ease-out;
}

.feedback-banner.success { display: block; background: #e8f5e9; color: #2e7d32; border: 1px solid #c8e6c9; }
.feedback-banner.error   { display: block; background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }

/* Mensaje de fin de partida: cubre todo el tablero */
.feedback-banner.final {
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    font-size: 1.2rem;
}

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

/* ==========================================================================
   8. TABLERO DE JUEGO
   Todo el tablero se apila en columna con un único "gap" entre bloques.
   ========================================================================== */
.screen-board {
    position: relative;
}

.screen-board.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--board-gap);
}

.board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    width: 100%;
}

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

/* Número objetivo */
.target-area {
    text-align: center;
}

.target-area p {
    margin-bottom: 4px;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #777;
}

.target-bubble {
    display: inline-block;
    min-width: 1.9em;
    padding: 2px 18px;
    background: var(--surface);
    border: 3px solid var(--text-dark);
    border-radius: 50px;
    font-size: clamp(1.8rem, 5.5vh, 2.5rem);
    font-weight: bold;
}

/* Ecuación en construcción */
.equation-preview {
    width: 100%;
    min-height: clamp(44px, 8vh, 60px);
    padding: 8px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f0ede6;
    border-radius: var(--radius-md);
    font-size: 1.3rem;
    font-weight: 500;
    text-align: center;
}

/* Cartas */
.cards-hand {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
}

.num-card {
    width: calc(var(--card-h) * 0.7);
    height: var(--card-h);
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--surface);
    border: 2px solid var(--text-dark);
    border-radius: var(--radius-md);
    font-size: clamp(1.4rem, 3.4vh, 1.8rem);
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.num-card:hover:not(:disabled) {
    transform: translateY(-5px);
}

.num-card:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Operadores */
.operators-grid {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.btn-op {
    width: var(--op-size);
    height: var(--op-size);
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-op:hover:not(:disabled) {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

.btn-op:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.board-footer {
    display: flex;
    justify-content: center;
    gap: 20px;
}

/* ==========================================================================
   9. BOTONES GENERALES
   ========================================================================== */
.btn-primary,
.btn-secondary,
.btn-success,
.btn-danger {
    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; }
.btn-success   { padding: clamp(8px, 1.6vh, 12px) 30px; background: var(--color-easy); color: #fff; border: none; font-size: 1rem; }
.btn-danger    { padding: clamp(8px, 1.6vh, 12px) 30px; background: var(--color-danger-soft); color: #fff; border: none; font-size: 1rem; }

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

.btn-success:disabled,
.btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   10. MODAL DE REGLAS
   ========================================================================== */
.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; }

/* ==========================================================================
   11. PANTALLAS BAJAS (portátiles con ventana de poca altura)
   ========================================================================== */
@media (max-height: 560px),
       (max-width: 768px) and (max-height: 700px) {
    .section-title {
        display: none;
    }
}

/* ==========================================================================
   12. MÓVIL
   ========================================================================== */
@media (max-width: 768px) {
    :root {
        --page-pad: 15px;
    }

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

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

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

    .subtitle {
        margin-bottom: 20px;
    }

    .difficulty-grid {
        gap: 12px;
        margin-top: 0;
    }

    .card-diff {
        padding: 10px 16px;
    }

    .diff-title {
        margin-bottom: 4px;
        font-size: 1.4rem;
    }

    .diff-icon {
        height: auto;
        font-size: 1.6rem;
    }

    .diff-desc {
        margin-top: 4px;
    }

    /* Estadísticas en matriz 2x2 */
    .board-header {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-box {
        padding: 6px 10px;
        font-size: 0.9rem;
        text-align: center;
    }

    .board-header .btn-secondary {
        width: 100%;
        padding: 6px 10px;
    }

    .equation-preview {
        font-size: 1.1rem;
    }

    .cards-hand,
    .operators-grid {
        gap: 10px;
    }

    .board-footer {
        gap: 12px;
    }

    .btn-success,
    .btn-danger {
        padding-left: 24px;
        padding-right: 24px;
    }
}
