/* AgilKey — Estilo Minimalista y Limpio */
:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #10b981;
    --success-soft: #ecfdf5;
    --danger: #ef4444;
    --danger-soft: #fef2f2;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.03);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.95rem; }
.muted-xs { color: var(--muted); font-size: 0.8rem; }

/* Header */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 800;
}

.nav-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--bg);
    padding: 0.25rem;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.nav-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 0.4rem 0.95rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.nav-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 600;
}

.link-btn {
    border: none;
    background: none;
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    margin-left: 0.25rem;
}

.admin-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}
.admin-link:hover { color: var(--text); }

/* Layout Principal */
.layout {
    max-width: 1120px;
    margin: 1.75rem auto;
    padding: 0 1.25rem 3rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1.5rem;
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.75rem;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.65rem 1.15rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.92; }
.btn-lg { padding: 0.85rem 1.4rem; font-size: 1rem; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-full { width: 100%; }

.icon-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 1rem;
}

/* Formularios */
.auth-card { max-width: 480px; margin: 1rem auto; }
.auth-header { margin-bottom: 1.4rem; }
.auth-header h1 { font-size: 1.55rem; letter-spacing: -0.02em; margin-bottom: 0.35rem; }

.form-stack { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.88rem; font-weight: 600; color: var(--text); }

.field input,
.field select {
    width: 100%;
    padding: 0.72rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.alert-error {
    background: var(--danger-soft);
    color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 0.7rem 0.9rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-success {
    background: var(--success-soft);
    color: #047857;
    border: 1px solid #a7f3d0;
    padding: 0.7rem 0.9rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
}

.segmented {
    display: inline-flex;
    background: var(--bg);
    padding: 0.25rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

.seg-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 0.4rem 0.85rem;
    border-radius: 7px;
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
}

.seg-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Hub de Desafíos */
.section-head { margin-bottom: 1.25rem; }
.section-head h2 { font-size: 1.4rem; letter-spacing: -0.02em; }

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.game-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow);
}

.game-tile h3 { font-size: 1.15rem; margin-bottom: 0.35rem; }
.game-meta {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-soft);
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    margin-bottom: 0.6rem;
}

.future-note {
    margin-top: 1.25rem;
    padding: 0.9rem 1.1rem;
    border: 1px dashed var(--border);
    border-radius: 12px;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: center;
}

/* Pantalla del Juego */
.game-card { padding: 1.4rem 1.75rem 1.75rem; }

.game-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1.1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
}

.hud-block { display: flex; flex-direction: column; }
.hud-center { align-items: center; }
.hud-right { flex-direction: row; align-items: center; gap: 0.5rem; }
.hud-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }

.timer-display {
    font-size: 1.65rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    color: var(--text);
}
.timer-display.urgent { color: var(--danger); }

.score-display {
    font-size: 1.65rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--primary);
}

/* Operación al centro + 5 opciones a la derecha */
.game-arena {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 210px;
    gap: 1.5rem;
    align-items: center;
    min-height: 310px;
}

.problem-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: background-color 0.14s ease, border-color 0.14s ease;
}

.problem-zone.flash-ok {
    background: var(--success-soft);
    border-color: var(--success);
}

.problem-zone.flash-bad {
    background: var(--danger-soft);
    border-color: var(--danger);
}

.problem-badge {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.85rem;
}

.problem-text {
    font-size: clamp(2.2rem, 5vw, 3.3rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.15;
}

.problem-hint {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.options-column {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.option-btn {
    width: 100%;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 1.25rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.06s ease, border-color 0.12s ease, background-color 0.12s ease;
    touch-action: manipulation;
}

.option-btn:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.option-btn:active { transform: scale(0.98); }

.option-key {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Resultados */
.result-card { text-align: center; }
.result-top { margin-bottom: 1.5rem; }
.result-top h2 { font-size: 1.6rem; margin-top: 0.5rem; }

.pill-success {
    display: inline-block;
    background: var(--success-soft);
    color: #047857;
    border: 1px solid #a7f3d0;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.result-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.9rem;
    margin-bottom: 1.6rem;
}

.metric-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.metric-primary {
    background: var(--primary-soft);
    border-color: #bfdbfe;
}

.metric-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.metric-value { font-size: 1.85rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.metric-primary .metric-value { color: var(--primary); }
.metric-sub { font-size: 0.8rem; color: var(--muted); }

.result-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Rankings */
.rankings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.rankings-head .segmented { margin-bottom: 0; }

.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.filter-bar select {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 0.9rem;
}

.table-wrap { overflow-x: auto; }
.clean-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.clean-table th {
    text-align: left;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    padding: 0.65rem 0.6rem;
    border-bottom: 1px solid var(--border);
}
.clean-table td {
    padding: 0.72rem 0.6rem;
    border-bottom: 1px solid #f1f5f9;
}
.clean-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-cell { text-align: center; color: var(--muted); padding: 1.5rem 0.5rem; list-style: none; }

/* Sidebar Top 10 */
.sidebar { display: flex; flex-direction: column; gap: 1rem; }
.sidebar-card { padding: 1.25rem; }
.sidebar-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.85rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-head h3 { font-size: 1rem; }

.top10-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.top10-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.55rem;
    border-radius: 9px;
    font-size: 0.9rem;
}
.top10-item:nth-child(odd) { background: var(--bg); }

.top10-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.rank-num {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    font-size: 0.76rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e2e8f0;
    color: var(--text);
    flex-shrink: 0;
}
.rank-num.r1 { background: #fef08a; color: #854d0e; }
.rank-num.r2 { background: #e2e8f0; color: #334155; }
.rank-num.r3 { background: #fed7aa; color: #9a3412; }

.top10-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top10-score {
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.apk-card {
    padding: 1.15rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Responsive Móvil */
@media (max-width: 860px) {
    .layout {
        grid-template-columns: 1fr;
        margin-top: 1rem;
    }
    .result-metrics {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .card { padding: 1.2rem; }
    .game-arena {
        grid-template-columns: 1fr;
        gap: 1rem;
        min-height: auto;
    }
    .problem-zone { padding: 1.5rem 0.75rem; }
    .option-key { display: none; }
    .option-btn { justify-content: center; padding: 0.95rem; font-size: 1.3rem; }
    .timer-display, .score-display { font-size: 1.35rem; }
}

/* Estilo para Matemática con Palabras */
.problem-text.word-mode {
    font-size: clamp(1.35rem, 3vw, 2.05rem);
    line-height: 1.3;
    max-width: 100%;
    overflow-wrap: break-word;
}

/* 6 opciones en 2 columnas (3 izquierda + 3 derecha) y vista móvil compacta sin scroll */
.game-arena {
    grid-template-columns: minmax(0, 1fr) 260px;
}
.options-column {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
}
.problem-text.seq-mode {
    font-size: clamp(1.5rem, 3.6vw, 2.35rem);
    letter-spacing: 0.01em;
}
@media (max-width: 640px) {
    .topbar-inner { padding: 0.5rem 0.9rem; gap: 0.5rem; }
    .layout { margin-top: 0.65rem; padding: 0 0.75rem 2rem; gap: 1rem; }
    .game-card { padding: 0.85rem 0.9rem 1rem; }
    .game-hud { padding-bottom: 0.65rem; margin-bottom: 0.85rem; }
    .problem-zone { padding: 1rem 0.65rem; }
    .problem-badge { margin-bottom: 0.35rem; font-size: 0.72rem; }
    .problem-hint { display: none; }
    .game-arena { gap: 0.75rem; }
    .options-column {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.55rem;
    }
    .option-btn {
        padding: 0.85rem 0.5rem;
        font-size: 1.25rem;
        min-height: 54px;
    }
}

/* Lógica Visual: 4 tarjetas en secuencia + 4 opciones SVG */
.visual-seq-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    flex-wrap: nowrap;
    width: 100%;
}
.visual-tile {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 0.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 66px;
    height: 66px;
    flex-shrink: 1;
}
.visual-tile svg { width: 100%; height: 100%; }
.visual-tile.visual-q {
    border-style: dashed;
    border-color: var(--primary);
    color: var(--primary);
    font-size: 1.55rem;
    font-weight: 800;
    background: var(--primary-soft);
}
.option-btn.visual-opt {
    padding: 0.5rem;
    min-height: 76px;
    justify-content: center;
    position: relative;
}
.option-btn.visual-opt .option-key {
    position: absolute;
    top: 6px;
    left: 6px;
}
.option-btn.visual-opt svg {
    width: 54px;
    height: 54px;
}
@media (max-width: 640px) {
    .visual-seq-row { gap: 0.3rem; }
    .visual-tile { width: 54px; height: 54px; padding: 0.25rem; }
    .option-btn.visual-opt { min-height: 70px; padding: 0.4rem; }
    .option-btn.visual-opt svg { width: 48px; height: 48px; }
}

/* Logos alegóricos en cada tarjeta de desafío */
.game-tile-head {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-bottom: 0.6rem;
}
.game-tile-head .game-meta { margin-bottom: 0.25rem; }
.game-tile-head h3 { margin-bottom: 0; }
.game-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
}

/* Logo principal en la página de inicio y selector de idioma */
.hero-banner {
    margin-bottom: 1.1rem;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    background: var(--surface);
}
.hero-banner img {
    display: block;
    width: 100%;
    height: auto;
}
.lang-select {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 8px;
    padding: 0.32rem 0.5rem;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}
.lang-select:focus { border-color: var(--primary); }
@media (max-width: 640px) {
    .hero-banner { margin-bottom: 0.85rem; }
    .hero-banner img { max-height: 145px; }
}
