/* =============================================================================
   ZUDOKOO V7.0 — Design System & Tokens (Dark principal / Light alternativo)
   Paleta oficial negro–azul acero–blanco (#3F658C). Cero morado/violeta.
   Contraste WCAG 2.2 AA verificado (se corrige #608AB4 usando texto oscuro cuando es fondo).
   ============================================================================= */

:root,
[data-theme="dark"] {
    --bg: #070C14;
    --surface: #111D2B;
    --surface-elevated: #17273A;
    --surface-subtle: #0D1622;
    --primary: #3F658C;
    --primary-hover: #4C77A3;
    --primary-contrast: #FFFFFF; /* 6.08:1 WCAG AA */
    --secondary: #608AB4;
    --secondary-contrast: #070C14; /* 6.45:1 WCAG AA */
    --accent: #70B4C2;
    --accent-contrast: #070C14;
    --text: #F8FAFD;
    --muted: #A8BACD;
    --border: #29435E;
    --border-strong: #3F658C;

    /* Semánticos accesibles (nunca únicos indicadores, acompañados de ícono/etiqueta) */
    --success: #45B88E;
    --warning: #E5B24C;
    --danger: #E86F74;
    --danger-bg: rgba(232, 111, 116, 0.16);
    --success-bg: rgba(69, 184, 142, 0.14);

    /* Tablero 9x9 — máxima legibilidad sin degradados distractores detrás de números */
    --board-bg: #0D1724;
    --board-cell: #111D2B;
    --board-cell-given: #152436;
    --board-cell-selected: #25486D;
    --board-cell-peer: #182C42;
    --board-cell-same: #1E3B59;
    --board-cell-tutor: rgba(112, 180, 194, 0.24);
    --board-cell-conflict: rgba(232, 111, 116, 0.28);
    --board-given-text: #F8FAFD;
    --board-user-text: #70B4C2;
    --board-note-text: #A8BACD;
    --board-grid-line: #243B54;
    --board-box-line: #608AB4;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    --focus-ring: 0 0 0 3px #70B4C2;
    --scale-factor: 1;
}

[data-theme="light"] {
    --bg: #F3F6FA;
    --surface: #FFFFFF;
    --surface-elevated: #EDF2F8;
    --surface-subtle: #E7EEF6;
    --primary: #315476;
    --primary-hover: #274460;
    --primary-contrast: #FFFFFF; /* 8.1:1 WCAG AAA */
    --secondary: #426B94;
    --secondary-contrast: #FFFFFF;
    --accent: #236A7C;
    --accent-contrast: #FFFFFF;
    --text: #172A3D;
    --muted: #52687B;
    --border: #C9D6E3;
    --border-strong: #315476;

    --success: #1E7E5B;
    --warning: #9F6B09;
    --danger: #B92E37;
    --danger-bg: rgba(185, 46, 55, 0.12);
    --success-bg: rgba(30, 126, 91, 0.10);

    --board-bg: #FFFFFF;
    --board-cell: #FFFFFF;
    --board-cell-given: #EEF3F8;
    --board-cell-selected: #CFE1F2;
    --board-cell-peer: #E9F0F7;
    --board-cell-same: #D9E8F6;
    --board-cell-tutor: rgba(35, 106, 124, 0.18);
    --board-cell-conflict: rgba(185, 46, 55, 0.18);
    --board-given-text: #172A3D;
    --board-user-text: #236A7C;
    --board-note-text: #52687B;
    --board-grid-line: #CBD7E3;
    --board-box-line: #315476;

    --shadow-sm: 0 2px 8px rgba(23, 42, 61, 0.08);
    --shadow-md: 0 10px 26px rgba(23, 42, 61, 0.12);
    --focus-ring: 0 0 0 3px #236A7C;
}

[data-scale="large"] { --scale-factor: 1.1; }
[data-scale="xlarge"] { --scale-factor: 1.22; }

*, *::before, *::after { box-sizing: border-box; }

html {
    font-size: calc(16px * var(--scale-factor));
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
[data-reduced-motion="true"] *, [data-reduced-motion="true"] *::before, [data-reduced-motion="true"] *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
}

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Header corporativo navy/steel-blue con logo 378:81 (BRAND-04) */
.site-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: linear-gradient(90deg, #070C14 0%, #111D2B 52%, #24405C 100%);
    border-bottom: 1px solid #29435E;
    color: #F8FAFD;
}

.header-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0.65rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand-link {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    border-radius: 8px;
}
.brand-link img {
    display: block;
    width: 168px;
    height: 36px; /* proporción exacta 378:81 sin CLS */
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    flex-wrap: wrap;
}
.main-nav a {
    color: #E2ECF7;
    padding: 0.5rem 0.8rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.94rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}
.main-nav a:hover, .main-nav a.active {
    background: rgba(112, 180, 194, 0.16);
    color: #FFFFFF;
    text-decoration: none;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.control-select {
    background: #111D2B;
    color: #F8FAFD;
    border: 1px solid #3F658C;
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.65rem;
    min-height: 40px;
    font-size: 0.88rem;
    cursor: pointer;
}

/* Contenedor principal */
.app-main {
    flex: 1;
    max-width: 1240px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

/* Botones accesibles >= 44px táctil */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 44px;
    padding: 0.6rem 1.15rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, transform 80ms ease;
    text-decoration: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
    background: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); text-decoration: none; }
.btn-outline {
    background: transparent;
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-outline:hover:not(:disabled) { background: var(--surface-elevated); text-decoration: none; }
.btn-accent {
    background: var(--accent);
    color: var(--accent-contrast);
}
.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-sm { min-height: 38px; padding: 0.4rem 0.8rem; font-size: 0.86rem; }

/* Tarjetas y grids */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.35rem;
    box-shadow: var(--shadow-sm);
}
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.65rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    color: var(--text);
}
.badge-accent { border-color: var(--accent); color: var(--accent); }
.badge-success { border-color: var(--success); color: var(--success); background: var(--success-bg); }
.badge-danger { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; }
.field label { font-size: 0.88rem; font-weight: 600; }
.input, select.input, textarea.input {
    width: 100%;
    min-height: 44px;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
}
textarea.input { min-height: 110px; resize: vertical; }

/* Hero */
.hero {
    padding: 2.4rem 1.75rem;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-elevated) 100%);
    border: 1px solid var(--border);
    margin-bottom: 1.75rem;
}
.hero h1 { font-size: clamp(1.85rem, 3.4vw, 2.75rem); margin: 0.4rem 0 0.75rem; line-height: 1.18; }
.hero p.lead { font-size: 1.1rem; color: var(--muted); max-width: 68ch; margin: 0 0 1.35rem; }
.cta-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

/* ======================== TABLERO SUDOKU 9x9 ======================== */
.play-layout {
    display: grid;
    grid-template-columns: minmax(290px, 520px) minmax(260px, 1fr);
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 880px) {
    .play-layout { grid-template-columns: 1fr; }
}

.board-wrapper {
    position: relative;
    background: var(--board-bg);
    border: 2.5px solid var(--board-box-line);
    border-radius: 10px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    user-select: none;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    height: 100%;
}

.sudoku-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0.5px solid var(--board-grid-line);
    background: var(--board-cell);
    color: var(--board-user-text);
    font-family: var(--font-mono);
    font-size: clamp(1.15rem, 3.2vw, 1.85rem);
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}
.sudoku-cell[data-col="2"], .sudoku-cell[data-col="5"] { border-right: 2px solid var(--board-box-line); }
.sudoku-cell[data-row="2"], .sudoku-cell[data-row="5"] { border-bottom: 2px solid var(--board-box-line); }
.sudoku-cell.is-given { background: var(--board-cell-given); color: var(--board-given-text); font-weight: 800; }
.sudoku-cell.is-peer { background: var(--board-cell-peer); }
.sudoku-cell.is-same { background: var(--board-cell-same); }
.sudoku-cell.is-tutor-related { box-shadow: inset 0 0 0 2px var(--accent); }
.sudoku-cell.is-tutor-target { background: var(--board-cell-tutor); box-shadow: inset 0 0 0 3px var(--accent); }
.sudoku-cell.is-selected { background: var(--board-cell-selected); box-shadow: inset 0 0 0 2.5px var(--accent); }
.sudoku-cell.is-conflict { background: var(--board-cell-conflict); color: var(--danger); }
.sudoku-cell.is-conflict::after {
    content: "!";
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.62rem;
    font-weight: 800;
    color: var(--danger);
}

.notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 92%;
    height: 92%;
    font-size: clamp(0.52rem, 1.15vw, 0.72rem);
    line-height: 1;
    color: var(--board-note-text);
    font-weight: 500;
}
.notes-grid span { display: flex; align-items: center; justify-content: center; }

.board-overlay {
    position: absolute;
    inset: 0;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    padding: 1.5rem;
    text-align: center;
    z-index: 10;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0.35rem;
    margin-top: 0.9rem;
}
@media (max-width: 520px) {
    .numpad { grid-template-columns: repeat(5, 1fr); }
}
.numpad-btn {
    min-height: 48px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.numpad-btn small { font-size: 0.65rem; color: var(--muted); font-weight: 500; }
.numpad-btn.is-done { opacity: 0.38; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* Tablas accesibles */
.table-wrap { overflow-x: auto; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.93rem;
}
table.data-table th, table.data-table td {
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
table.data-table th { background: var(--surface-elevated); font-weight: 700; }

/* Slots publicitarios (solo Free, jamás sobre tablero activo) */
.ad-slot {
    margin-top: 1.25rem;
    padding: 0.9rem 1.1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-subtle);
    font-size: 0.85rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Alertas y notificaciones */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    margin: 0.75rem 0;
}
.alert-success { border-color: var(--success); background: var(--success-bg); }
.alert-danger { border-color: var(--danger); background: var(--danger-bg); }
.alert-accent { border-color: var(--accent); }

/* Tabs */
.tabs { display: flex; gap: 0.4rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    padding: 0.65rem 1rem;
    min-height: 44px;
    font-weight: 600;
    cursor: pointer;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

/* Gráficos SVG */
.chart-box { width: 100%; overflow-x: auto; }
.chart-box svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }

/* Banner de privacidad / cookies */
.consent-bar {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    max-width: 780px;
    margin: 0 auto;
    background: var(--surface);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-md);
    z-index: 60;
}

/* Modal accesible */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(7, 12, 20, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 70;
}
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    max-width: 560px;
    width: 100%;
    padding: 1.5rem;
    max-height: 90vh;
    overflow-y: auto;
}

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    background: var(--surface-subtle);
    padding: 1.75rem 1.25rem;
    font-size: 0.88rem;
    color: var(--muted);
}
.footer-inner {
    max-width: 1240px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}
.footer-links { display: flex; flex-wrap: wrap; gap: 1rem; }
