/* ==================================================== */
/*  REDONDEADOR · Estilos                                */
/* ==================================================== */

:root {
    --ink: #1d2240;
    --muted: #6b7394;
    --panel: #ffffff;
    --panel-soft: #f4f6ff;
    --line: #e4e8f7;

    --primary: #4f6bff;   --primary-dark: #3346c9;
    --violet: #8b5cf6;    --violet-dark: #6d28d9;
    --success: #22c55e;   --success-dark: #15803d;
    --danger: #ef4444;    --danger-dark: #b91c1c;
    --warning: #f59e0b;   --warning-dark: #b45309;
    --info: #06b6d4;      --info-dark: #0e7490;
    --gray: #64748b;      --gray-dark: #475569;
    --gold: #fbbf24;

    --radius: 22px;
    --shadow: 0 24px 60px rgba(5, 10, 40, 0.38);
    --font-display: 'Fredoka', 'Poppins', sans-serif;
}

/* -------------------- */
/* Estilos Generales     */
/* -------------------- */
html, body {
    height: 100%;
    margin: 0;
}

/* Estilos para el Canvas de Fondo */
#fondoCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

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

body {
    font-family: 'Poppins', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    color: var(--ink);
    padding: 20px;
    background: #0a2341;
    overflow-x: hidden;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: 0.3px; }
h2 { margin: 0 0 8px; font-size: 1.8em; }

button, input, select { font-family: inherit; }

/* ==================================================== */
/*  Contenedor del juego                                 */
/* ==================================================== */
.container {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    padding: 26px 24px 22px;
    border-radius: 28px;
    box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.7);
    width: 100%;
    max-width: 470px;
    text-align: center;
    z-index: 1;
    animation: card-turn 0.7s both;
}

.game-content-hidden { display: none; }

h1 {
    margin: 4px 0 18px;
    font-size: 2em;
    background: linear-gradient(90deg, var(--primary), var(--violet), #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

#current-player-chip {
    align-items: center;
    gap: 8px;
    padding: 4px 14px 4px 4px;
    margin-bottom: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, #eef1ff, #f7eeff);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.1em;
    box-shadow: 0 3px 10px rgba(79, 107, 255, 0.18);
    animation: card-deal 0.7s both;
}

/* Marcadores con sitio fijo: puntuación a la izquierda, tiempo/errores a la derecha
   y el marcador central siempre en su propia fila. Antes se usaba flex-wrap y,
   según lo largo que fuera el texto, el tercero cabía en la fila o saltaba
   debajo: la ventana cambiaba de alto de repente. */
.header-info {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    justify-items: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-weight: 700;
    font-size: 1.1em;
}
#score-display { grid-column: 1; grid-row: 1; }
#right-info-display { grid-column: 2; grid-row: 1; }
#center-time-display { grid-column: 1 / -1; grid-row: 2; }

.header-info span {
    max-width: 100%;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--panel-soft);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    box-sizing: border-box;
}

#score-display { color: var(--success-dark); background: #e8fbef; }
#center-time-display { color: var(--primary-dark); }
#right-info-display { color: var(--danger); background: #fff0f0; }
.time-warning { color: var(--danger) !important; animation: pulse-warn 0.8s ease-in-out infinite; }
.score-bump { display: inline-block; animation: digit-flip 0.35s cubic-bezier(.2, .9, .3, 1); }

/* Racha: pegatina sobreimpresa en la esquina de la ventana; no ocupa sitio,
   así la ventana no cambia de tamaño al aparecer o desaparecer */
#streak-badge {
    position: absolute;
    top: -14px;
    right: -12px;
    z-index: 3;
    padding: 6px 14px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05em;
    color: #fff;
    white-space: nowrap;
    background: linear-gradient(135deg, #fb923c, #ea580c);
    border-radius: 999px;
    box-shadow: 0 4px 0 #c2410c, 0 10px 22px rgba(234, 88, 12, 0.45);
    transform: rotate(8deg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s, visibility 0.25s;
}
#streak-badge.visible { opacity: 1; visibility: visible; }
.streak-pop { animation: streak-pop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes streak-pop { 0% { transform: rotate(8deg) scale(0.4); } 100% { transform: rotate(8deg) scale(1); } }

#question-area { min-height: 120px; margin-bottom: 16px; }
.question-hint { margin: 0; color: var(--muted); }

#number-to-round {
    font-family: var(--font-display);
    font-size: 3.6em;
    font-weight: 700;
    color: var(--ink);
    margin: 8px 0;
    display: flex;
    justify-content: center;
    text-shadow: 0 4px 0 rgba(79, 107, 255, 0.15);
}
.q-pop { animation: card-flip-x 0.4s both; }

/* cifra a la que hay que redondear */
/* punto de miles / millones entre los grupos de cifras */
.thousands-dot { margin: 0 1px; }

.highlighted-digit {
    display: inline-block;
    margin: 0 2px;
    padding: 0 6px;
    color: #7a4b00;
    background: linear-gradient(180deg, #ffe38a, var(--gold));
    border-radius: 12px;
    box-shadow: 0 4px 0 #d49b06, 0 8px 18px rgba(251, 191, 36, 0.45);
    text-shadow: none;
    /* visible desde el primer instante (muerte súbita de 1 s): solo un rebote */
    animation: digit-mark 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes digit-mark { 0% { transform: scale(1.3) rotate(-6deg); } 100% { transform: none; } }

#rounding-unit {
    display: inline-block;
    margin: 4px 0 2px;
    padding: 6px 16px;
    font-weight: 600;
    font-size: 1.1em;
    color: var(--primary-dark);
    background: var(--panel-soft);
    border-radius: 999px;
}
#rounding-unit:empty { display: none; }

#options-container { display: flex; flex-direction: column; gap: 16px; margin-bottom: 20px; }

/* ==================================================== */
/*  Botones                                              */
/* ==================================================== */
.option-button, .mode-button {
    --btn: var(--primary);
    --btn-dark: var(--primary-dark);
    position: relative;
    overflow: hidden;
    width: 100%;
    padding: 14px 18px;
    font-family: var(--font-display);
    font-size: 1.45em;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: #fff;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    background: var(--btn);
    background: linear-gradient(180deg, color-mix(in srgb, var(--btn) 80%, white), var(--btn));
    box-shadow: 0 6px 0 var(--btn-dark), 0 12px 20px rgba(0, 0, 0, 0.18);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.option-button::after, .mode-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: -80%;
    width: 50%;
    height: 100%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
    transform: skewX(-20deg);
    transition: left 0.5s ease;
    pointer-events: none;
}

.option-button:hover:not(:disabled), .mode-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--btn-dark), 0 16px 24px rgba(0, 0, 0, 0.2);
    filter: brightness(1.05);
}
.option-button:hover:not(:disabled)::after, .mode-button:hover:not(:disabled)::after { left: 130%; }

.option-button:active:not(:disabled), .mode-button:active:not(:disabled) {
    transform: translateY(5px);
    box-shadow: 0 1px 0 var(--btn-dark), 0 4px 8px rgba(0, 0, 0, 0.2);
}

.mode-button:disabled { opacity: 0.6; cursor: default; }

.option-button { font-size: 1.8em; padding: 16px; }
.option-button:disabled { opacity: 0.6; cursor: default; }

.btn-icon { display: inline-block; margin-right: 6px; transition: transform 0.3s; }
.mode-button:hover .btn-icon { transform: scale(1.25) rotate(-10deg); }

/* las opciones se voltean como naipes en cada pregunta nueva */
.opt-flip { animation: card-flip-x 0.38s both; }
#option2.opt-flip { animation-delay: 0.05s; }
#option3.opt-flip { animation-delay: 0.1s; }

.btn-chrono { --btn: var(--primary); --btn-dark: var(--primary-dark); }
.btn-sudden { --btn: var(--danger); --btn-dark: var(--danger-dark); }
.btn-free   { --btn: var(--success); --btn-dark: var(--success-dark); }
.btn-violet { --btn: var(--violet); --btn-dark: var(--violet-dark); }

.correct-answer {
    --btn: var(--success) !important;
    --btn-dark: var(--success-dark) !important;
    opacity: 1 !important;
    animation: correct-pop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
    box-shadow: 0 6px 0 var(--success-dark), 0 0 24px rgba(34, 197, 94, 0.7) !important;
}
.incorrect-choice {
    --btn: var(--danger) !important;
    --btn-dark: var(--danger-dark) !important;
    opacity: 1 !important;
}

#feedback-message {
    margin-bottom: 15px;
    font-weight: 700;
    font-size: 1.15em;
    min-height: 1.6em;   /* reserva la línea de "¡Correcto!" para que la ventana no crezca */
    line-height: 1.6em;
    transition: opacity 0.2s;
}
.feedback-correct { color: var(--success-dark); }
.feedback-incorrect { color: var(--danger); }   /* la opacidad la pone ui-manager.js: con !important el cartel se quedaba al pasar a la pregunta siguiente */

#main-menu-button {
    --btn: var(--gray);
    --btn-dark: var(--gray-dark);
    margin-top: 12px;
    padding: 12px;
    font-size: 1.15em;
}

/* Botones pequeños tipo "píldora" */
.chip-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.95em;
    font-weight: 600;
    color: var(--ink);
    background: #fff;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 3px 0 #d5dbf2, 0 6px 14px rgba(0, 0, 0, 0.12);
    transition: transform 0.12s, box-shadow 0.12s, background 0.2s;
    white-space: nowrap;
}
.chip-button:hover:not(:disabled) { transform: translateY(-2px); }
.chip-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #d5dbf2; }
.chip-button:disabled { opacity: 0.5; cursor: default; }
.chip-button.primary { color: #fff; background: linear-gradient(90deg, var(--primary), var(--violet)); box-shadow: 0 3px 0 var(--violet-dark), 0 6px 14px rgba(79, 107, 255, 0.35); }
.chip-button.danger { color: var(--danger-dark); }
.chip-button.ghost { color: #fff; background: rgba(255, 255, 255, 0.12); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.5); }
.chip-button.ghost-dark { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1.5px var(--line); }

.icon-button {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.05em;
    opacity: 0.45;
    transition: opacity 0.2s, transform 0.2s;
}
.icon-button:hover { opacity: 1; transform: scale(1.2); }

/* ==================================================== */
/*  Modales y paneles                                    */
/* ==================================================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(6, 10, 32, 0.6);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    justify-content: safe center;
    z-index: 10;
    padding: 20px 16px;
    overflow: auto;
}

#mode-selection-modal {
    background: rgba(6, 10, 32, 0.2);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

#ranking-area, #player-name-area, #mode-selection-area, #time-selection-area, .panel {
    position: relative;
    width: 100%;
    max-width: 420px;
    padding: 26px 24px;
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    animation: card-turn 0.7s both;
    flex-shrink: 0;
}

.panel-sm { max-width: 400px; }
.panel-xl { max-width: 980px; }

.panel-subtitle { margin: 0 0 14px; color: var(--muted); }

.panel-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 18px;
}
.panel-actions .mode-button { width: auto; min-width: 200px; font-size: 1.15em; padding: 12px 22px; }

.close-x {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 1.1em;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    z-index: 2;
}
.close-x:hover { transform: rotate(90deg); background: #e6e9fb; color: var(--ink); }

.toolbar {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0;
}

select, input[type="text"], input[type="password"], input[type="search"] {
    padding: 10px 14px;
    font-size: 1em;
    color: var(--ink);
    background: var(--panel-soft);
    border: 2px solid var(--line);
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
select:focus, input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 107, 255, 0.15); }
select { cursor: pointer; }

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.95em;
}
.inline-field { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }

.form-error { color: var(--danger); font-weight: 600; min-height: 1.2em; margin: 4px 0 10px; }
.hint { color: var(--muted); font-size: 0.85em; margin: 16px 0 0; }

.empty-state {
    grid-column: 1 / -1;
    padding: 30px 16px;
    color: var(--muted);
    font-size: 1.05em;
    line-height: 1.6;
    background: var(--panel-soft);
    border-radius: 16px;
}

.tabs {
    display: flex;
    gap: 6px;
    padding: 5px;
    margin: 10px auto 14px;
    width: fit-content;
    max-width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    background: var(--panel-soft);
    border-radius: 16px;
}
.tabs button, .segmented button, .chips button {
    padding: 8px 16px;
    font-weight: 600;
    font-size: 0.95em;
    color: var(--muted);
    background: transparent;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s;
}
.tabs button:hover, .segmented button:hover, .chips button:hover { color: var(--ink); }
.tabs button.active, .segmented button.active {
    color: #fff;
    background: linear-gradient(90deg, var(--primary), var(--violet));
    box-shadow: 0 4px 12px rgba(79, 107, 255, 0.35);
}

.segmented {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: var(--panel-soft);
    border-radius: 14px;
    margin-bottom: 10px;
}
.chips { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chips button { background: var(--panel-soft); border-radius: 999px; padding: 6px 14px; }
.chips button.active { color: #fff; background: var(--ink); }

/* -------------------- */
/* Logo                  */
/* -------------------- */
#logo-container {
    text-align: center;
    margin-bottom: 20px;
    z-index: 11;
}

#game-logo {
    max-width: 100%;
    height: auto;
    width: 300px;
    display: block;
    margin-left: auto;
    margin-right: auto;
    animation: pulsating-zoom 2s ease-in-out infinite;
    filter: drop-shadow(0 10px 25px rgba(79, 107, 255, 0.45));
}

@keyframes pulsating-zoom {
    0%   { transform: scale(1.20); opacity: 1; }
    50%  { transform: scale(1.05); opacity: 0.5; }
    100% { transform: scale(1.20); opacity: 1; }
}

/* -------------------- */
/* Menú principal        */
/* -------------------- */
#mode-selection-area { max-width: 360px; margin-bottom: 20px; }
#mode-selection-area .mode-button { margin-bottom: 16px; animation: card-flip-x 0.55s both; }
#mode-selection-area .mode-button:nth-of-type(1) { animation-delay: 0.25s; }
#mode-selection-area .mode-button:nth-of-type(2) { animation-delay: 0.35s; }
#mode-selection-area .mode-button:nth-of-type(3) { animation-delay: 0.45s; }
#mode-hint { color: var(--muted); }

#teacher-bar {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 12;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    animation: fade-in 0.6s ease both;
}

#teacher-info {
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 10px 8px 16px;
    color: #fff;
    background: rgba(10, 20, 55, 0.55);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.teacher-hello { margin-right: 4px; }
#teacher-info select { padding: 7px 12px; border-radius: 999px; font-weight: 600; max-width: 160px; }

/* ⚙️ Botón de opciones del menú principal */
.settings-gear {
    width: 42px;
    height: 42px;
    padding: 0;
    font-size: 1.3em;
    color: #fff;
    background: rgba(10, 20, 55, 0.55);
    box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.35);
    transition: transform 0.3s, background 0.2s;
}
.settings-gear:hover:not(:disabled) { transform: rotate(60deg); }

/* Menú de opciones (ajustes.js · rendimiento.js) */
.settings-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; text-align: left; }
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    padding: 12px 16px;
    font: inherit;
    color: var(--ink);
    background: var(--panel-soft);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
}
.setting-row:hover { background: #e6e9fb; }
.setting-text { display: flex; flex-direction: column; gap: 2px; }
.setting-text small { color: var(--muted); }
.setting-row .perf-switch { flex-shrink: 0; background: #c9cfe6; }
.setting-row[aria-pressed="true"] .perf-switch { background: var(--success); }
.setting-row[aria-pressed="true"] .perf-switch::after { transform: translateX(13px); }

.perf-switch {
    position: relative;
    width: 30px;
    height: 17px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.28);
    transition: background 0.2s;
}
.perf-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
}

/* Modo ligero: fuera el desenfoque; los velos se oscurecen un poco
   para que las ventanas se sigan leyendo igual de bien */
html.ligero *,
html.ligero *::before,
html.ligero *::after {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
}
html.ligero .modal { background: rgba(6, 10, 32, 0.78); }
html.ligero #mode-selection-modal { background: rgba(6, 10, 32, 0.2); }
html.ligero #teacher-info,
html.ligero .settings-gear { background: rgba(10, 20, 55, 0.85); }

/* Escala fija (escala.js): se amplía o reduce lo que va dentro de los velos,
   no los velos, que siguen cubriendo toda la pantalla */
html.escala-fija #game-container,
html.escala-fija .modal > *,
html.escala-fija .dialog-overlay > *,
html.escala-fija #countdown-overlay > *,
html.movil #game-container,
html.movil .modal > *,
html.movil .dialog-overlay > *,
html.movil #countdown-overlay > * {
    zoom: var(--escala, 1);
}
html, body { overflow-x: hidden; }

@media (max-width: 900px) {
    #teacher-bar { flex-wrap: wrap; }
    #teacher-bar { position: static; margin-bottom: 26px; justify-content: center; max-width: 100%; }
    #teacher-info { border-radius: 22px; justify-content: center; padding: 10px; }
}

/* 🔴 Botón de sonido */
#mute-toggle-button-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0;
    gap: 10px;
    color: #ffffff;
    font-size: 1em;
    font-weight: 500;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
    flex-wrap: wrap;
    max-width: 300px;
    text-align: center;
}

#mute-toggle-button {
    --btn: var(--gray);
    --btn-dark: var(--gray-dark);
    position: static;
    padding: 0;
    font-size: 1.4em;
    border-radius: 50%;
    height: 46px;
    width: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    margin: 0;
    flex-shrink: 0;
    box-shadow: 0 4px 0 var(--btn-dark);
}

/* -------------------- */
/* Selección de tiempo   */
/* -------------------- */
#time-selection-area .time-button {
    --btn: var(--info);
    --btn-dark: var(--info-dark);
    margin-bottom: 12px;
    padding: 10px;
    font-size: 1.2em;
    animation: card-flip-x 0.5s both;
    animation-delay: 0.2s;
}
#time-selection-area .time-button:nth-of-type(2) { animation-delay: 0.26s; }
#time-selection-area .time-button:nth-of-type(3) { animation-delay: 0.32s; }
#time-selection-area .time-button:nth-of-type(4) { animation-delay: 0.38s; }
#time-selection-area .time-button:nth-of-type(5) { animation-delay: 0.44s; }
#time-selection-area .time-button:nth-of-type(6) { animation-delay: 0.5s; }
#time-selection-area .back-button { margin-top: 6px; }

/* Pie: Volver · dificultad elegida · Más opciones */
.time-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.time-footer .back-button { margin-top: 0; justify-self: start; }
.time-footer .more-button { justify-self: end; }
.time-footer .chip-button { padding: 7px 12px; font-size: 0.9em; }
/* «Más opciones» con el color del modo (btn-chrono / btn-sudden / btn-free) */
.time-footer .more-button {
    color: #fff;
    background: linear-gradient(180deg, color-mix(in srgb, var(--btn) 82%, #fff), var(--btn));
    box-shadow: 0 3px 0 var(--btn-dark), 0 6px 14px color-mix(in srgb, var(--btn) 35%, transparent);
}
.time-footer .more-button:active:not(:disabled) { box-shadow: 0 1px 0 var(--btn-dark); }
.time-variant {
    padding: 5px 12px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95em;
    border-radius: 999px;
    white-space: nowrap;
}
.time-variant.ranked { color: var(--primary-dark); background: var(--panel-soft); }
.time-variant.ranked::before { content: "🏆 "; }
.time-variant.unranked { color: var(--warning-dark); background: #fff4dc; }
.time-variant.unranked::before { content: "📝 "; }
.time-variant.neutral { color: var(--success-dark); background: #e8f8ee; }
.time-variant.neutral::before { content: "🎯 "; }
#time-selection-area .free-start-button { --btn: var(--success); --btn-dark: var(--success-dark); font-size: 1.4em; padding: 14px; }

/* ⚙️ Más opciones (opciones.js) */
#options-area { max-width: 460px; text-align: left; }
#options-area h2 { text-align: center; }
.op-bloque { margin-top: 14px; }
.op-bloque h3 { margin: 0 0 8px; font-size: 1.05em; color: var(--ink); }
.op-dificultad { display: flex; margin-bottom: 6px; }
.op-dificultad button { flex: 1; }
.op-explica { margin: 4px 2px 0; color: var(--muted); }
.op-cifras select {
    padding: 4px 8px;
    font: inherit;
    font-weight: 700;
    color: var(--ink);
    border: 2px solid var(--line);
    border-radius: 10px;
    background: #fff;
}
.op-unidades { justify-content: center; }
.op-bloque:has(.op-unidades) h3 { text-align: center; }
.op-unidades button { min-width: 52px; font-family: var(--font-display); font-size: 1em; font-weight: 700; padding: 6px 12px; }
.op-unidades button:disabled { opacity: 0.35; cursor: not-allowed; text-decoration: line-through; }
.op-aviso { margin: 6px 2px 0; color: var(--danger-dark); font-weight: 600; font-size: 0.92em; }
.op-extras { margin-top: 14px; }
.op-ranking { margin: 14px 0 0; padding: 10px 14px; border-radius: 14px; font-size: 0.92em; }
.op-ranking.si { color: var(--primary-dark); background: var(--panel-soft); }
.op-ranking.no { color: #7a4b00; background: #fff4dc; }
#options-area .panel-actions .mode-button:disabled { opacity: 0.5; cursor: default; transform: none; }

/* números de 7 cifras: un poco más pequeños para que quepan */
#number-to-round.long-number { font-size: 3em; }

#player-name-input {
    width: 100%;
    margin-bottom: 15px;
}

/* ==================================================== */
/*  Fin de partida                                       */
/* ==================================================== */
#end-game-title {
    font-size: 2em;
    background: linear-gradient(90deg, var(--primary), var(--violet), #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.summary-stats {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin: 15px 0;
    font-size: 1.05em;
    text-align: center;
}

.summary-stats div {
    flex-basis: 48%;
    margin-bottom: 10px;
    padding: 10px 5px;
    border-radius: 14px;
    font-weight: 600;
    animation: card-reveal 0.7s both;
    animation-delay: 0.35s;
}
.summary-stats div:nth-child(2) { animation-delay: 0.45s; }
.summary-stats div:nth-child(3) { animation-delay: 0.55s; }
.summary-stats div:nth-child(4) { animation-delay: 0.65s; }

.summary-stats .stat-total   { background: #eef3ff; color: var(--primary-dark); }
.summary-stats .stat-correct { background: #e8fbef; color: var(--success-dark); }
.summary-stats .stat-wrong   { background: #fff0f0; color: var(--danger-dark); }
.summary-stats .score-per-sec { background: #fff6dc; color: var(--warning-dark); }

.summary-stats span {
    display: block;
    font-size: 1.3em;
    font-weight: 700;
    margin-top: 4px;
    font-family: var(--font-display);
}
.summary-stats span:first-child { font-size: 0.9em; font-family: 'Poppins', sans-serif; margin-top: 0; }

#ranking-table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 0.95em; }
#ranking-table th, #ranking-table td { border-bottom: 1px solid var(--line); padding: 8px; text-align: center; }
#ranking-table th { background-color: var(--panel-soft); color: var(--ink); }
.you-score { background-color: #ffe082 !important; font-weight: bold; }

#revisit-options {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 20px;
    width: 100%;
}
#revisit-options button { padding: 12px; font-size: 1.2em; }

#same-player-button, #teacher-again-button { --btn: var(--success); --btn-dark: var(--success-dark); }
#other-player-button, #teacher-next-button { --btn: var(--info); --btn-dark: var(--info-dark); }
#teacher-rankings-button { --btn: var(--warning); --btn-dark: var(--warning-dark); }
#mode-select-button { --btn: var(--gray); --btn-dark: var(--gray-dark); }

#reset-ranking-button {
    display: block;
    margin: 0 auto 10px;
    width: fit-content;
    padding: 4px 10px;
    font-size: 0.8em;
    font-weight: 600;
    color: var(--danger);
    background-color: #f8f9fa;
    border: 1px solid #ced4da;
    border-radius: 8px;
    cursor: pointer;
}

/* Resultado del modo docente: ventana horizontal en dos columnas */
#ranking-area.teacher-layout {
    max-width: 940px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    grid-template-areas:
        "title   title"
        "header  result"
        "stats   result"
        "buttons buttons";
    grid-template-rows: auto auto 1fr auto;
    column-gap: 30px;
    align-items: start;
    padding: 22px 30px 26px;
}
.teacher-layout #end-game-title { grid-area: title; margin-bottom: 6px; }
.teacher-layout #teacher-result-header { grid-area: header; }
.teacher-layout .summary-stats { grid-area: stats; margin: 10px 0 0; }
.teacher-layout #teacher-result-area { grid-area: result; align-self: center; }
.teacher-layout #revisit-options {
    grid-area: buttons;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 22px;
}
.teacher-layout #revisit-options button { font-size: 1.1em; padding: 11px; }
.teacher-layout #teacher-result-header .avatar-xl { --size: 108px; }
.teacher-layout .mini-ranking { max-height: 250px; overflow-y: auto; padding: 4px; }

@media (max-width: 760px) {
    #ranking-area.teacher-layout {
        display: block;
        max-width: 440px;
        padding: 22px 16px;
    }
    .teacher-layout #revisit-options { grid-template-columns: 1fr; }
}

#teacher-result-header {
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin: 6px 0 4px;
    animation: card-deal 0.8s both;
    animation-delay: 0.2s;
}
.result-student-name { font-family: var(--font-display); font-size: 1.4em; font-weight: 700; }
.result-mode { color: var(--muted); font-size: 0.9em; }

.result-status { padding: 8px 12px; border-radius: 12px; font-weight: 600; font-size: 0.92em; margin-bottom: 10px; }
.result-status.ok { background: #e8fbef; color: var(--success-dark); }
.result-status.warn { background: #fff6dc; color: var(--warning-dark); }
.result-status.muted { background: var(--panel-soft); color: var(--muted); }

.record-badge {
    display: inline-block;
    padding: 8px 18px;
    margin-bottom: 10px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2em;
    color: #7a4b00;
    background: linear-gradient(90deg, #ffe38a, var(--gold), #ffe38a);
    background-size: 200% 100%;
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(251, 191, 36, 0.5);
    animation: card-flip-x 0.6s 0.3s both, shimmer 2s linear infinite;
}
.pb-line { color: var(--muted); margin-bottom: 8px; }
.session-pos { font-size: 1.1em; margin: 6px 0 10px; }
.session-pos strong { font-family: var(--font-display); font-size: 1.4em; color: var(--violet); }

.mini-ranking { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.mini-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 12px;
    background: var(--panel-soft);
    animation: card-row 0.45s both;
    animation-delay: calc(300ms + var(--i) * 70ms);
}
.mini-row.me { background: linear-gradient(90deg, #fff1c2, #ffe38a); font-weight: 700; box-shadow: 0 4px 12px rgba(251, 191, 36, 0.35); }
.mini-pos { width: 28px; text-align: center; font-weight: 700; }
.mini-name { flex: 1; }
.mini-score { font-family: var(--font-display); font-weight: 700; font-size: 1.2em; }
.mini-gap { text-align: center; color: var(--muted); line-height: 0.6; }

/* ==================================================== */
/*  Avatares                                             */
/* ==================================================== */
.avatar {
    --size: 64px;
    width: var(--size);
    height: var(--size);
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
    object-position: center 30%;
    background: #dde3fb;
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ring, #c7d2fe), 0 6px 14px rgba(0, 0, 0, 0.18);
}
.avatar-initials {
    display: grid;
    place-items: center;
    color: #fff;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: calc(var(--size) * 0.38);
    background: linear-gradient(135deg, hsl(var(--hue) 80% 62%), hsl(calc(var(--hue) + 40) 80% 50%));
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.avatar-xs { --size: 26px; box-shadow: 0 0 0 2px #fff; vertical-align: middle; }
.avatar-sm { --size: 36px; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ring, #c7d2fe); }
.avatar-lg { --size: 88px; }
.avatar-xl { --size: 120px; --ring: var(--gold); }

/* ==================================================== */
/*  Cuadrícula de alumnos                                */
/* ==================================================== */
.student-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 14px;
    padding: 12px 6px 6px;
    max-height: 58vh;
    overflow-y: auto;
}

.student-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px 12px;
    color: var(--ink);
    background: var(--panel-soft);
    border: 2px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.2, 1.4, 0.4, 1), box-shadow 0.2s, border-color 0.2s, background 0.2s;
    animation: card-deal 0.65s both;
    animation-delay: calc(min(var(--i), 30) * 35ms);
}
.no-anim .student-card { animation: none; }
/* cada carta llega del mazo con una inclinación distinta */
.student-card:nth-child(4n+1), .review-card:nth-child(4n+1) { --tilt: -9deg; }
.student-card:nth-child(4n+2), .review-card:nth-child(4n+2) { --tilt: 6deg; }
.student-card:nth-child(4n+3), .review-card:nth-child(4n+3) { --tilt: -4deg; }
.student-card:nth-child(4n),   .review-card:nth-child(4n)   { --tilt: 11deg; }
.student-card:hover { transform: translateY(-5px) rotate(-1.5deg); background: #fff; border-color: #c7d2fe; box-shadow: 0 14px 26px rgba(79, 107, 255, 0.22); }
.student-card:hover .avatar { --ring: var(--primary); }
.student-card:active { transform: scale(0.96); }

.student-name { font-family: var(--font-display); font-weight: 600; font-size: 1.08em; line-height: 1.2; }
.student-surname { color: var(--muted); font-size: 0.8em; line-height: 1.2; }

.student-card.has-played { background: #effbf3; }
.student-card.has-played .avatar { --ring: var(--success); }
.played-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 8px;
    font-size: 0.78em;
    font-weight: 700;
    color: #fff;
    background: var(--success);
    border-radius: 999px;
}
.played-badge:empty { display: none; }

.student-card.roulette {
    transform: scale(1.08);
    background: #fff7d6;
    border-color: var(--gold);
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.4), 0 12px 30px rgba(251, 191, 36, 0.45);
    transition-duration: 0.08s;
}
.student-card.chosen {
    z-index: 2;
    border-color: var(--gold);
    background: #fff7d6;
    animation: chosen 0.6s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}

.picker-toolbar { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 4px; }
#picker-search { flex: 1; min-width: 200px; max-width: 360px; }

/* Revisión de importación */
.review-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px 10px;
    background: var(--panel-soft);
    border-radius: 18px;
    transition: opacity 0.2s, filter 0.2s;
    animation: card-deal 0.65s both;
    animation-delay: calc(min(var(--i), 30) * 35ms);
}
.review-card.excluded { opacity: 0.4; filter: grayscale(1); }
.review-card input[type="text"] { width: 100%; padding: 6px 8px; font-size: 0.85em; text-align: center; border-radius: 8px; }
.review-card .rv-first { font-weight: 700; }
.review-check { position: absolute; top: 8px; left: 8px; }
.review-check input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--success); }

/* Zona de importación */
#import-drop {
    padding: 22px 16px;
    margin: 6px 0 10px;
    border: 3px dashed #c7d2fe;
    border-radius: 20px;
    background: linear-gradient(135deg, #f4f6ff, #faf5ff);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s, background 0.2s;
}
#import-drop:hover, #import-drop.dragging { border-color: var(--primary); transform: scale(1.01); background: #eef1ff; }
#import-drop.busy { pointer-events: none; opacity: 0.6; }
#import-drop small { color: var(--muted); }
.import-icon { font-size: 2.2em; animation: float 3s ease-in-out infinite; }
#import-status { min-height: 1.4em; }

.grid-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
#students-count { color: var(--muted); font-weight: 600; }

/* Editor de alumno */
#student-edit-photo { display: flex; justify-content: center; margin: 12px 0; cursor: pointer; transition: transform 0.2s; }
#student-edit-photo:hover { transform: scale(1.05); }
.photo-actions { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.field input { width: 100%; }

/* Selector de alumnos: fitPickerGrid() (teacher-ui.js) calcula --pick, el tamaño de
   cada tarjeta, para que quepa toda la clase sin scroll */
#student-picker-modal .panel { max-width: 1500px; padding-bottom: 16px; }
#picker-grid {
    --pick: 140px;
    justify-content: center;
    max-height: none;
    overflow: visible;   /* la tarjeta elegida crece y gira sin que se corte */
    gap: calc(var(--pick) * 0.09);
    padding: calc(var(--pick) * 0.08) calc(var(--pick) * 0.06);
}
#picker-grid.scrolls { max-height: 62vh; overflow-y: auto; }
#picker-grid .student-card {
    padding: calc(var(--pick) * 0.1) 6px calc(var(--pick) * 0.08);
    gap: calc(var(--pick) * 0.05);
    border-radius: calc(var(--pick) * 0.14);
}
#picker-grid .avatar-lg { --size: calc(var(--pick) * 0.62); }
#picker-grid .student-name { font-size: clamp(12px, calc(var(--pick) * 0.12), 18px); line-height: 1.2; }
#picker-grid .played-badge { font-size: clamp(10px, calc(var(--pick) * 0.075), 13px); }

/* ==================================================== */
/*  Cuadros de diálogo propios (effects.js)              */
/* ==================================================== */
.dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    background: rgba(6, 10, 32, 0.6);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: fade-in 0.2s ease;
}
html.ligero .dialog-overlay { background: rgba(6, 10, 32, 0.78); }
.dialog-overlay.dialog-out { animation: fade-out 0.2s ease forwards; }
.dialog-box {
    width: 100%;
    max-width: 400px;
    padding: 26px 24px 22px;
    text-align: center;
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: card-turn 0.5s both;
}
.dialog-icon { font-size: 2.4em; line-height: 1; margin-bottom: 8px; animation: pop-in 0.4s 0.15s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.dialog-title { margin: 0 0 8px; font-size: 1.45em; }
.dialog-message { margin: 0 0 6px; color: var(--muted); line-height: 1.5; }
.dialog-input { width: 100%; margin: 8px 0 4px; }
.dialog-actions { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.dialog-actions .mode-button { width: auto; min-width: 150px; padding: 11px 22px; font-size: 1.15em; }

/* ==================================================== */
/*  Rankings                                             */
/* ==================================================== */
.class-pill {
    display: inline-block;
    vertical-align: middle;
    padding: 2px 12px;
    margin-left: 6px;
    font-size: 0.55em;
    color: #fff;
    background: linear-gradient(90deg, var(--primary), var(--violet));
    border-radius: 999px;
}
.class-pill:empty { display: none; }

#rk-content { min-height: 200px; margin-top: 10px; }

.podium {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-items: end;
    gap: 12px;
    max-width: 560px;
    margin: 10px auto 22px;
}
.podium-slot { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: card-deal 0.7s both; }
.podium-slot.place-3 { animation-delay: 0s; }
.podium-slot.place-2 { animation-delay: 0.2s; }
.podium-slot.place-1 { animation-delay: 0.4s; }
.podium-medal { font-size: 1.8em; animation: pop-in 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.podium-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05em; }
.podium-block {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    border-radius: 16px 16px 6px 6px;
    transform-origin: bottom;
    animation: grow-up 0.7s cubic-bezier(0.2, 1.2, 0.4, 1) both;
}
.podium-score { font-family: var(--font-display); font-weight: 700; font-size: 2em; line-height: 1; }
.podium-block small { opacity: 0.85; }
.place-1 .podium-block { height: 130px; background: linear-gradient(180deg, #ffd75e, #f59e0b); animation-delay: 0.45s; }
.place-2 .podium-block { height: 100px; background: linear-gradient(180deg, #d9e0ec, #94a3b8); animation-delay: 0.2s; }
.place-3 .podium-block { height: 78px;  background: linear-gradient(180deg, #f3b98a, #c2703d); animation-delay: 0s; }
.place-1 .podium-medal { animation-delay: 0.9s; }
.place-2 .podium-medal { animation-delay: 0.65s; }
.place-3 .podium-medal { animation-delay: 0.45s; }
.place-1 .avatar { animation: glow 2s ease-in-out infinite; }
.place-2 .avatar { --ring: #cbd5e1; }
.place-3 .avatar { --ring: #e8a472; }

.rk-list { display: flex; flex-direction: column; gap: 8px; text-align: left; max-width: 720px; margin: 0 auto; }
.rk-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--panel-soft);
    border-radius: 16px;
    animation: card-row 0.45s both;
    animation-delay: calc(900ms + min(var(--i), 25) * 50ms);
}
.rk-row.top { background: linear-gradient(90deg, #fff8e1, var(--panel-soft)); }
.rk-pos { width: 28px; text-align: center; font-family: var(--font-display); font-weight: 700; font-size: 1.2em; color: var(--muted); }
.rk-main { flex: 1; min-width: 0; }
.rk-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rk-meta { color: var(--muted); font-size: 0.78em; }
.rk-bar { height: 8px; margin: 4px 0; background: #e3e7f7; border-radius: 999px; overflow: hidden; }
.rk-bar div {
    height: 100%;
    width: var(--w);
    background: linear-gradient(90deg, var(--primary), var(--violet), #ec4899);
    border-radius: 999px;
    animation: bar-grow 1s cubic-bezier(0.2, 1, 0.4, 1) both;
    animation-delay: 0.3s;
}
.rk-score { font-family: var(--font-display); font-weight: 700; font-size: 1.6em; color: var(--primary-dark); }

.history-wrap { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 0.92em; text-align: left; }
.history-table th { position: sticky; top: 0; padding: 10px 8px; color: var(--muted); font-size: 0.85em; text-transform: uppercase; background: var(--panel); border-bottom: 2px solid var(--line); }
.history-table td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history-table tr { transition: opacity 0.3s, transform 0.3s; }
.history-table tr.row-out { opacity: 0; transform: translateX(30px); }
.history-table tbody tr:hover { background: var(--panel-soft); }
.h-student { font-weight: 600; }
.h-score { font-family: var(--font-display); font-weight: 700; font-size: 1.15em; color: var(--success-dark); }
.h-errors { color: var(--danger); }
#rk-more { margin-top: 14px; }

/* ==================================================== */
/*  Efectos: cuenta atrás, toasts, confeti, flotantes    */
/* ==================================================== */
#countdown-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: radial-gradient(circle, rgba(40, 30, 110, 0.75), rgba(5, 8, 30, 0.9));
    animation: fade-in 0.25s ease;
}
#countdown-overlay.countdown-out { animation: fade-out 0.3s ease forwards; }
.countdown-player { display: flex; flex-direction: column; align-items: center; gap: 12px; animation: pop-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1); }
.countdown-player .avatar { --size: 150px; }
.countdown-player-name { font-family: var(--font-display); font-weight: 700; font-size: 2.2em; color: #fff; text-shadow: 0 4px 20px rgba(139, 92, 246, 0.8); }
.countdown-number {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: min(38vw, 210px);
    line-height: 1;
    color: #fff;
    text-shadow: 0 0 30px rgba(79, 107, 255, 0.9), 0 10px 0 rgba(0, 0, 0, 0.25);
}
.countdown-number.go { color: var(--gold); font-size: min(26vw, 150px); text-shadow: 0 0 40px rgba(251, 191, 36, 0.9); }
.count-pop { animation: count-flip 0.38s both; }

#toast-container {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: min(92vw, 480px);
    transform: translateX(-50%);
    pointer-events: none;
}
.toast {
    padding: 12px 18px;
    font-weight: 600;
    color: #fff;
    background: var(--ink);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    animation: card-flip-x 0.5s both;
    text-align: center;
}
.toast-success { background: linear-gradient(90deg, var(--success-dark), var(--success)); }
.toast-error { background: linear-gradient(90deg, var(--danger-dark), var(--danger)); }
.toast-warn { background: linear-gradient(90deg, var(--warning-dark), var(--warning)); }
.toast-out { animation: toast-out 0.4s ease forwards; }

.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti-layer i {
    position: absolute;
    top: -20px;
    left: var(--x);
    width: 10px;
    height: 14px;
    border-radius: 2px;
    animation: confetti-fall var(--dur) cubic-bezier(0.25, 0.6, 0.4, 1) var(--delay) forwards;
}

.float-text {
    position: fixed;
    z-index: 60;
    pointer-events: none;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 2.2em;
    transform: translate(-50%, -50%);
    animation: float-up 0.9s ease-out forwards;
}
.float-good { color: var(--success); text-shadow: 0 3px 0 #fff, 0 6px 16px rgba(34, 197, 94, 0.6); }

.shake { animation: shake 0.4s ease; }

.loader {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--line);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}
.loading-line { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 16px; color: var(--muted); font-weight: 600; }

/* ==================================================== */
/*  Explicación del error (explicacion.js)               */
/* ==================================================== */
/* si no cabe en alto, se desplaza el velo y la ventana empieza arriba */
.ex-overlay { overflow-y: auto; align-items: center; align-items: safe center; }
.ex-box { position: relative; max-width: 560px; padding: 22px 22px 20px; margin: auto 0; }

.ex-cabecera {
    margin: -6px -6px 4px;
    padding: 14px 44px 14px;
    border-radius: 18px;
    background: linear-gradient(135deg, #fff0f0, #f7eeff 60%, #eef1ff);
}
.ex-emoji { font-size: 2.6em; line-height: 1; animation: pop-in 0.45s 0.15s cubic-bezier(0.2, 1.6, 0.4, 1) both, ex-duda 2.4s 0.8s ease-in-out infinite; }
.ex-titulo {
    margin: 6px 0 2px;
    font-size: 1.6em;
    background: linear-gradient(90deg, var(--danger), #ec4899, var(--violet));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.ex-enunciado { margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.ex-enunciado b { color: var(--ink); font-family: var(--font-display); font-size: 1.15em; }
.ex-respuestas { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.ex-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95em;
    animation: pop-in 0.35s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.ex-pill b { font-family: var(--font-display); font-size: 1.2em; }
.ex-pill.mal { color: var(--danger-dark); background: #fff; box-shadow: inset 0 0 0 2px #fecaca, 0 3px 0 #fecaca; animation-delay: 0.3s; }
.ex-pill.mal b { text-decoration: line-through; text-decoration-thickness: 2px; }
.ex-pill.bien { color: var(--success-dark); background: #fff; box-shadow: inset 0 0 0 2px #bbf7d0, 0 3px 0 #bbf7d0; animation-delay: 0.42s; }

.ex-card {
    margin-top: 12px;
    padding: 12px 16px 14px;
    text-align: left;
    border-radius: 18px;
    border-left: 6px solid var(--c, var(--primary));
    background: var(--bg, var(--panel-soft));
    animation: card-flip-x 0.45s both;
}
.ex-card h4 { margin: 0 0 6px; font-family: var(--font-display); font-size: 1.15em; color: var(--c-dark, var(--ink)); }
.ex-card p { margin: 0; line-height: 1.55; }
.ex-por-que { --c: var(--danger); --c-dark: var(--danger-dark); --bg: #fff5f5; animation-delay: 0.25s; }
.ex-como    { --c: var(--primary); --c-dark: var(--primary-dark); --bg: #f4f6ff; animation-delay: 0.4s; }
.ex-recta   { --c: var(--violet); --c-dark: var(--violet-dark); --bg: #faf7ff; animation-delay: 0.55s; }

.ex-mal { color: var(--danger-dark); }
.ex-bien { color: var(--success-dark); }
.ex-azul { color: var(--primary-dark); }
.ex-morado { color: var(--violet-dark); }

/* 4.5[6]7 ➜ 4.600 */
.ex-transforma {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin: 4px 0 8px;
}
.ex-num {
    display: inline-flex;
    align-items: center;
    font-family: var(--font-display);
    font-size: 2.1em;
    font-weight: 700;
    line-height: 1.25;
}
.ex-d { display: inline-block; padding: 0 2px; }
.ex-dot { margin: 0 1px; }
.ex-d.oro {
    margin: 0 2px;
    padding: 0 6px;
    color: #7a4b00;
    background: linear-gradient(180deg, #ffe38a, var(--gold));
    border-radius: 10px;
    box-shadow: 0 3px 0 #d49b06;
}
.ex-d.decide {
    margin: 0 2px;
    padding: 0 5px;
    color: var(--violet-dark);
    border-radius: 10px;
    box-shadow: inset 0 0 0 3px var(--violet);
    animation: ex-latido 1.4s 1s ease-in-out 2;
}
.ex-d.cero { color: #9aa3c4; }
.ex-d.cambia {
    margin: 0 2px;
    padding: 0 5px;
    color: var(--success-dark);
    background: #e8fbef;
    border-radius: 10px;
    box-shadow: 0 3px 0 #b6ebc8;
}
.ex-flecha { font-size: 1.6em; color: var(--primary); animation: ex-empuja 1.2s ease-in-out infinite; }

.ex-pasos { margin: 0; padding: 0; list-style: none; counter-reset: paso; }
.ex-pasos li {
    position: relative;
    padding: 4px 0 4px 36px;
    line-height: 1.5;
    counter-increment: paso;
}
.ex-pasos li::before {
    content: counter(paso);
    position: absolute;
    left: 0;
    top: 4px;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    color: #fff;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--violet));
    box-shadow: 0 2px 0 var(--primary-dark);
}
.ex-pasos small { color: var(--muted); }
.ex-badge {
    display: inline-block;
    min-width: 1.7em;
    padding: 0 6px;
    font-family: var(--font-display);
    font-weight: 700;
    text-align: center;
    border-radius: 8px;
}
.ex-badge.oro { color: #7a4b00; background: linear-gradient(180deg, #ffe38a, var(--gold)); box-shadow: 0 2px 0 #d49b06; }
.ex-badge.decide { color: var(--violet-dark); background: #fff; box-shadow: inset 0 0 0 2px var(--violet); }

/* recta numérica */
.ex-svg { display: block; width: 100%; height: auto; margin: 2px 0 4px; overflow: visible; }
.ex-svg text { font-family: var(--font-display); text-anchor: middle; }
.ex-eje { stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.ex-eje-punta { fill: var(--ink); }
.ex-marca { stroke: #8890b5; stroke-width: 2; stroke-linecap: round; }
.ex-marca.mayor { stroke: var(--ink); stroke-width: 3.5; }
.ex-zona { fill: rgba(34, 197, 94, 0.22); animation: fade-in 0.5s 1s both; }
.ex-etq { font-size: 20px; font-weight: 600; fill: var(--ink); }
.ex-etq.bien { font-weight: 700; fill: var(--success-dark); }
.ex-mitad { stroke: var(--violet); stroke-width: 2.5; stroke-dasharray: 5 5; }
.ex-etq-mitad { font-size: 16px; font-weight: 600; fill: var(--violet-dark); }
.ex-arco {
    fill: none;
    stroke: #16a34a;
    stroke-width: 3.5;
    stroke-linecap: round;
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    animation: ex-traza 0.8s 1.1s ease-out forwards;
}
.ex-punto-bien { fill: var(--success); stroke: #fff; stroke-width: 3; animation: pop-in 0.35s 1.75s cubic-bezier(0.2, 1.6, 0.4, 1) both; transform-box: fill-box; transform-origin: center; }
.ex-aspa path { stroke: var(--danger); stroke-width: 4; stroke-linecap: round; fill: none; }
.ex-aspa { animation: pop-in 0.35s 0.75s cubic-bezier(0.2, 1.6, 0.4, 1) both; transform-box: fill-box; transform-origin: center; }
.ex-guia-mal { stroke: #fca5a5; stroke-width: 2; stroke-dasharray: 3 4; }
.ex-etq-mal { font-size: 16px; font-weight: 600; fill: var(--danger-dark); }
.ex-pin { animation: ex-cae 0.55s 0.65s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.ex-pin-palo { stroke: var(--primary); stroke-width: 2.5; }
.ex-pin-caja { fill: var(--primary); filter: drop-shadow(0 3px 0 var(--primary-dark)); }
.ex-pin-txt { font-size: 22px; font-weight: 700; fill: #fff; }
.ex-pin-punto { fill: var(--primary); stroke: #fff; stroke-width: 3; }
.ex-pie { font-size: 0.95em; color: var(--ink); text-align: center; }

.ex-box .dialog-actions .ex-ok { min-width: 240px; }

@keyframes ex-duda { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(-12deg); } 30% { transform: rotate(10deg); } 45% { transform: rotate(0); } }
@keyframes ex-latido { 50% { transform: scale(1.25); } }
@keyframes ex-empuja { 50% { transform: translateX(5px); } }
@keyframes ex-traza { to { stroke-dashoffset: 0; } }
@keyframes ex-cae { 0% { opacity: 0; transform: translateY(-26px); } 100% { opacity: 1; transform: none; } }

@media (max-width: 500px) {
    .ex-box { padding: 18px 14px 16px; }
    .ex-cabecera { padding: 12px 38px; }
    .ex-titulo { font-size: 1.35em; }
    .ex-num { font-size: 1.6em; }
    .ex-card { padding: 10px 12px 12px; }
    .ex-box .dialog-actions .ex-ok { min-width: 0; width: 100%; }
}

/* ==================================================== */
/*  Animaciones                                          */
/* ==================================================== */
/* --- Estilo "Cartas": todo entra dándose la vuelta, como un naipe sobre la mesa ---
   Giros cortos con perspectiva y un pequeño rebote; se voltean y se quedan quietos. */
@keyframes card-turn {      /* paneles y ventanas */
    0%   { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: .2; transform: perspective(1600px) rotateY(-70deg) scale(.86); }
    65%  { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: 1; transform: perspective(1600px) rotateY(8deg) scale(1.01); }
    100% { opacity: 1; transform: none; }
}
@keyframes card-flip-x {    /* botones: caen hacia delante */
    0%   { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: 0; transform: perspective(900px) rotateX(-85deg); }
    60%  { opacity: 1; transform: perspective(900px) rotateX(9deg); }
    100% { opacity: 1; transform: none; }
}
@keyframes card-reveal {    /* estadísticas: giran sobre el eje vertical */
    0%   { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: 0; transform: perspective(1000px) rotateY(70deg); }
    65%  { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: 1; transform: perspective(1000px) rotateY(-7deg); }
    100% { opacity: 1; transform: none; }
}
@keyframes card-deal {      /* tarjetas de alumno: se reparten boca abajo y se dan la vuelta */
    0%   { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: 0; transform: perspective(700px) translateY(-40px) rotate(var(--tilt, 0deg)) rotateY(-180deg) scale(.8); }
    55%  { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: 1; }
    80%  { transform: perspective(700px) rotateY(10deg) scale(1.03); }
    100% { opacity: 1; transform: none; }
}
@keyframes card-row {       /* filas de ranking: se abaten como una paleta */
    0%   { animation-timing-function: cubic-bezier(.45, .05, .35, 1); opacity: 0; transform: perspective(700px) rotateX(-90deg); }
    100% { opacity: 1; transform: none; }
}
@keyframes digit-flip {     /* marcador: reloj de paletas */
    0%   { transform: perspective(200px) rotateX(-90deg); }
    100% { transform: perspective(200px) rotateX(0); }
}
@keyframes count-flip {     /* cuenta atrás: entra con un golpe de escala (sin giro: en iPhone el 2, el 3… se veían reflejados) */
    0%   { animation-timing-function: cubic-bezier(.2, .8, .3, 1); opacity: 0; transform: scale(1.9); }
    65%  { animation-timing-function: ease-out; opacity: 1; transform: scale(0.92); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes modal-in { from { opacity: 0; transform: translateY(24px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { 0% { opacity: 0; transform: scale(0.5); } 100% { opacity: 1; transform: scale(1); } }
@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: none; } }
@keyframes q-pop { 0% { opacity: 0; transform: scale(0.6) rotate(-4deg); } 100% { opacity: 1; transform: none; } }
@keyframes correct-pop { 0% { transform: scale(1); } 50% { transform: scale(1.08); } 100% { transform: scale(1.04); } }
@keyframes bump { 50% { transform: scale(1.18); } }
@keyframes pulse-warn { 50% { transform: scale(1.12); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes chosen {         /* la carta elegida da una vuelta completa */
    0%   { animation-timing-function: cubic-bezier(.45, .05, .35, 1); transform: perspective(700px) rotateY(0) scale(1); }
    60%  { animation-timing-function: cubic-bezier(.45, .05, .35, 1); transform: perspective(700px) rotateY(380deg) scale(1.2); box-shadow: 0 0 0 8px rgba(251, 191, 36, 0.5), 0 20px 40px rgba(251, 191, 36, 0.5); }
    100% { transform: perspective(700px) rotateY(360deg) scale(1.12); box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.5); }
}
@keyframes count-pop { 0% { opacity: 0; transform: scale(2.2); } 60% { opacity: 1; transform: scale(0.9); } 100% { transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(20px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }
@keyframes confetti-fall { 0% { transform: translate(0, 0) rotate(0); opacity: 1; } 100% { transform: translate(var(--drift), 110vh) rotate(var(--rot)); opacity: 0.9; } }
@keyframes float-up { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); } 20% { opacity: 1; transform: translate(-50%, -80%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -220%) scale(1); } }
@keyframes grow-up { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes bar-grow { from { width: 0; } }
@keyframes glow { 50% { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--gold), 0 0 30px 8px rgba(251, 191, 36, 0.6); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes spin { to { transform: rotate(360deg); } }


/* ==================================================== */
/*  Móvil                                                */
/* ==================================================== */
@media (max-width: 500px) {
    body { padding: 12px; }
    .container { padding: 18px 14px; max-width: none; }
    .summary-stats { font-size: 1em; }
    #number-to-round { font-size: 3em; }
    .header-info { font-size: 1em; gap: 6px; }
    .header-info span { padding: 5px 10px; }
    /* "a la decena de millar más cercana." cabe en una línea: la ventana no cambia de alto */
    #rounding-unit { font-size: 0.95em; padding: 6px 12px; white-space: nowrap; }
    .panel, #ranking-area, #mode-selection-area, #time-selection-area, #player-name-area { padding: 22px 16px; }
    .student-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
    .avatar-lg { --size: 72px; }
    .avatar-xl { --size: 96px; }
    .podium { gap: 6px; }
    .podium-score { font-size: 1.5em; }
    .rk-meta { display: none; }
    .panel-actions .mode-button { min-width: 0; width: 100%; }
}


/* ==================================================== */
/*  Móvil: la pantalla de juego ocupa todo el alto       */
/* ==================================================== */
@media (max-width: 500px) {
    body { padding: 10px; min-height: 100vh; min-height: 100dvh; }
    #game-container:not(.game-content-hidden) {
        min-height: calc(100vh - 20px); min-height: calc(100dvh - 20px);
        display: flex; flex-direction: column; justify-content: space-evenly;
    }
    #game-container h1 { font-size: 1.9em; }
    #question-area { min-height: 0; margin-bottom: 0; }
    #number-to-round { font-size: clamp(3em, 16vw, 4.6em); margin: 12px 0; }
    #number-to-round.long-number { font-size: clamp(2.4em, 12vw, 3.6em); }
    #rounding-unit { font-size: 1.05em; }
    #options-container { gap: 18px; margin-bottom: 0; }
    .option-button { font-size: 2em; padding: 22px 16px; }
    #feedback-message { min-height: 1.6em; }
}



/* ===== html.movil: copia de los @media (max-width) de arriba (900, 760 y 500 px) para que valgan también cuando Safari
   informa de una ventana virtual más ancha que el teléfono (escala.js pone la clase html.movil en los teléfonos) ===== */
html.movil #teacher-bar { flex-wrap: wrap; }html.movil #teacher-bar { position: static; margin-bottom: 26px; justify-content: center; max-width: 100%; }html.movil #teacher-info { border-radius: 22px; justify-content: center; padding: 10px; }

html.movil #ranking-area.teacher-layout {
        display: block;
        max-width: 440px;
        padding: 22px 16px;
    }html.movil .teacher-layout #revisit-options { grid-template-columns: 1fr; }

html.movil .ex-box { padding: 18px 14px 16px; }html.movil .ex-cabecera { padding: 12px 38px; }html.movil .ex-titulo { font-size: 1.35em; }html.movil .ex-num { font-size: 1.6em; }html.movil .ex-card { padding: 10px 12px 12px; }html.movil .ex-box .dialog-actions .ex-ok { min-width: 0; width: 100%; }

html.movil body { padding: 12px; }html.movil .container { padding: 18px 14px; max-width: none; }html.movil .summary-stats { font-size: 1em; }html.movil #number-to-round { font-size: 3em; }html.movil .header-info { font-size: 1em; gap: 6px; }html.movil .header-info span { padding: 5px 10px; }html.movil #rounding-unit { font-size: 0.95em; padding: 6px 12px; white-space: nowrap; }html.movil .panel,
html.movil #ranking-area,
html.movil #mode-selection-area,
html.movil #time-selection-area,
html.movil #player-name-area { padding: 22px 16px; }html.movil .student-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }html.movil .avatar-lg { --size: 72px; }html.movil .avatar-xl { --size: 96px; }html.movil .podium { gap: 6px; }html.movil .podium-score { font-size: 1.5em; }html.movil .rk-meta { display: none; }html.movil .panel-actions .mode-button { min-width: 0; width: 100%; }

html.movil body { padding: 10px; min-height: 100vh; min-height: 100dvh; }html.movil #game-container:not(.game-content-hidden) {
        min-height: calc(100vh - 20px); min-height: calc(100dvh - 20px);
        display: flex; flex-direction: column; justify-content: space-evenly;
    }html.movil #game-container h1 { font-size: 1.9em; }html.movil #question-area { min-height: 0; margin-bottom: 0; }html.movil #number-to-round { font-size: clamp(3em, 16vw, 4.6em); margin: 12px 0; }html.movil #number-to-round.long-number { font-size: clamp(2.4em, 12vw, 3.6em); }html.movil #rounding-unit { font-size: 1.05em; }html.movil #options-container { gap: 18px; margin-bottom: 0; }html.movil .option-button { font-size: 2em; padding: 22px 16px; }html.movil #feedback-message { min-height: 1.6em; }


/* teléfono: altura de la pantalla de juego dividida por la escala (ventana virtual de Safari compensada con zoom) */
html.movil #game-container:not(.game-content-hidden) { min-height: calc((100dvh - 20px) / var(--escala, 1)); }

/* el brillo ::after de los botones se escapaba (el botón de música no tiene position: relative) y salía como una franja en la esquina */
#mute-toggle-button::after { display: none; }
