/* Diseño pensado primero para móvil; a partir de 720px se ajusta para escritorio. */
:root {
  --bg: #f4f5fb;
  --bg-2: #eceef7;
  --card: #ffffff;
  --text: #1b1e2e;
  --muted: #6b7087;
  --line: #e2e5f0;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #eef0ff;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff5e0;
  --shadow: 0 1px 2px rgba(20, 24, 60, .05), 0 4px 14px rgba(20, 24, 60, .06);
  --shadow-hover: 0 2px 4px rgba(20, 24, 60, .08), 0 12px 32px rgba(20, 24, 60, .12);
  --radius: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --tabbar: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --bg-2: #1a1d33;
    --card: #171a2e;
    --text: #e9eaf5;
    --muted: #9a9eb8;
    --line: #2a2e4a;
    --primary: #818cf8;
    --primary-2: #a78bfa;
    --primary-soft: #23264a;
    --ok: #4ade80;
    --ok-soft: #122b1c;
    --bad: #f87171;
    --bad-soft: #351818;
    --warn: #fbbf24;
    --warn-soft: #33280f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .2);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button, a, .opcion { touch-action: manipulation; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.015em; }
h1 { font-size: 1.5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
code { font-size: .85em; background: var(--bg-2); padding: .1em .35em; border-radius: 6px; }
svg.ico { width: 22px; height: 22px; flex: none; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: calc(.6rem + var(--safe-top)) 16px .6rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.logo { font-weight: 800; font-size: 1.05rem; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: .55rem; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: .95rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.nav { display: none; }
.boton-icono {
  margin-left: auto; width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer; transition: background .2s, color .2s;
}
.boton-icono:active { background: var(--bg-2); color: var(--text); }

/* ---------- Barra de pestañas inferior (móvil) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 6px 6px calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 96px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 4px; border-radius: 14px; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 700;
  transition: color .2s;
}
.tabbar a .ico-wrap { width: 52px; height: 30px; border-radius: 99px; display: grid; place-items: center; transition: background .25s var(--ease), transform .15s; }
.tabbar a.activo { color: var(--primary); }
.tabbar a.activo .ico-wrap { background: var(--primary-soft); }
.tabbar a:active .ico-wrap { transform: scale(.92); }

main { max-width: 960px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar) + 24px + var(--safe-bottom)); }
body.en-test main { padding-bottom: calc(96px + var(--safe-bottom)); }
/* Los gestos horizontales del test son nuestros: que el navegador no los use para ir atrás */
html:has(body.en-test), body.en-test { overscroll-behavior-x: none; }
body.en-test #tarjeta { touch-action: pan-y; }
body.en-test .topbar, body.en-test .tabbar, body.sin-sesion .tabbar, body.sin-sesion .topbar { display: none; }
body.sin-sesion main { padding-bottom: 32px; }

/* ---------- Tarjetas y botones ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.grid { display: grid; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 48px;
  border: 0; border-radius: 14px; padding: .7rem 1.2rem; font-weight: 700; cursor: pointer; text-decoration: none;
  background: var(--primary); color: #fff;
  transition: transform .15s var(--ease), box-shadow .2s, background .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.sec { background: var(--bg-2); color: var(--text); }
.btn.fantasma { background: transparent; color: var(--muted); padding: .5rem .75rem; min-height: 40px; }
.btn.grande { min-height: 54px; font-size: 1.05rem; }
.btn.bloque { width: 100%; }

/* ---------- Formularios ---------- */
.campo { display: grid; gap: .35rem; margin-bottom: 1rem; }
.campo label { font-weight: 600; font-size: .9rem; }
.campo input, textarea {
  width: 100%; min-height: 50px; padding: .75rem .9rem; border-radius: 14px; border: 1px solid var(--line); background: var(--bg);
  font-size: 16px; /* evita el zoom automático de iOS */
  transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; }
.campo input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.error { color: var(--bad); font-size: .9rem; min-height: 1.3em; }

.auth { max-width: 420px; margin: 0 auto; min-height: calc(100dvh - 48px); display: flex; flex-direction: column; justify-content: center; padding-top: var(--safe-top); }
.auth-hero { text-align: center; margin-bottom: 24px; }
.auth-hero .logo-mark { width: 64px; height: 64px; border-radius: 20px; font-size: 1.8rem; margin: 0 auto 14px; box-shadow: 0 10px 30px color-mix(in srgb, var(--primary) 35%, transparent); }
.tabs { display: flex; background: var(--bg-2); border-radius: 14px; padding: 4px; margin-bottom: 20px; position: relative; }
.tabs button { flex: 1; min-height: 42px; border: 0; background: none; border-radius: 11px; font-weight: 700; cursor: pointer; color: var(--muted); position: relative; z-index: 1; transition: color .25s; }
.tabs button.activo { color: var(--text); }
.tabs .indicador { position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px); border-radius: 11px; background: var(--card); box-shadow: var(--shadow); transition: transform .3s var(--ease); }

/* ---------- Inicio ---------- */
.hero { display: flex; gap: 16px; align-items: center; }
.hero-texto { flex: 1; min-width: 0; }
.hero h1 { font-size: 1.3rem; overflow-wrap: anywhere; }
.anillo { position: relative; flex: none; }
.anillo svg { transform: rotate(-90deg); display: block; }
.anillo .fondo { stroke: var(--line); }
.anillo .valor { stroke: url(#degradado); stroke-linecap: round; transition: stroke-dashoffset 1.2s var(--ease); }
.anillo .centro { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.anillo .centro b { font-size: 1.5rem; line-height: 1; }
.anillo .centro span { font-size: .68rem; color: var(--muted); line-height: 1.2; margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--bg-2); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.25rem; line-height: 1.2; }
.stat span { font-size: .75rem; color: var(--muted); }

.modos { display: grid; gap: 10px; }
.modo {
  cursor: pointer; text-align: left; display: flex; align-items: center; gap: 14px; width: 100%; text-decoration: none; color: inherit;
  transition: transform .2s var(--ease), box-shadow .25s, border-color .25s;
}
.modo:active { transform: scale(.985); }
.modo:disabled { opacity: .55; cursor: default; }
.modo .icono { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.4rem; flex: none; }
.modo .texto { flex: 1; min-width: 0; }
.modo h3 { margin: 0 0 .1rem; font-size: 1rem; display: flex; align-items: center; gap: .4rem; }
.modo p { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.35; }
.modo .flecha { color: var(--muted); flex: none; }
.chip { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .55rem; border-radius: 99px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.pregunta-num .chip { white-space: normal; max-width: 100%; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; align-items: center; gap: .75rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.lista li:last-child { border-bottom: 0; }
.lista .grow { flex: 1; min-width: 0; }
.lista a { text-decoration: none; color: inherit; }
.lista a.grow { display: block; }
.card > .lista { margin: -.25rem 0; }
.seccion { margin-top: 24px; }
.seccion > h2 { font-size: 1.1rem; }

/* ---------- Exámenes fijos ---------- */
.fijos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.fijo {
  aspect-ratio: 1; border-radius: 16px; border: 1px solid var(--line); background: var(--card); cursor: pointer; box-shadow: var(--shadow); padding: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  transition: transform .2s var(--ease), box-shadow .2s;
}
.fijo:active { transform: scale(.95); }
.fijo b { font-size: 1.4rem; line-height: 1.1; }
.fijo span { font-size: .66rem; color: var(--muted); }
.fijo .nota { font-weight: 700; margin-top: 2px; }
.fijo.aprobado { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); background: var(--ok-soft); }
.fijo.aprobado .nota { color: var(--ok); }
.fijo.suspenso .nota { color: var(--bad); }

/* ---------- Barras de progreso ---------- */
.barra { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.barra > i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .6s var(--ease); }

.tema { cursor: pointer; border-radius: 12px; }
.tema:active { background: var(--bg-2); }

/* ---------- Test ---------- */
.test-cabecera {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  margin: -16px -16px 12px; padding: calc(8px + var(--safe-top)) 12px 8px 6px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.test-cabecera .barra { flex: 1; }
.test-cabecera .boton-icono { margin-left: 0; }
.contador { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.test-titulo { font-size: .8rem; color: var(--muted); margin: -4px 0 10px; display: flex; justify-content: space-between; gap: 1rem; }

.pregunta { overflow: hidden; padding: 16px; }
.pregunta-num { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.enunciado { font-size: 1.02rem; font-weight: 700; margin: .5rem 0 1rem; line-height: 1.45; overflow-wrap: anywhere; }
.opciones { display: grid; gap: 10px; }
.opcion {
  display: flex; gap: .75rem; align-items: flex-start; text-align: left; width: 100%; min-height: 56px;
  padding: .8rem .9rem; border-radius: 14px; border: 2px solid var(--line); background: var(--card); cursor: pointer;
  font-size: .95rem; line-height: 1.4; overflow-wrap: anywhere;
  transition: border-color .2s, background .2s, transform .12s var(--ease);
  user-select: none; -webkit-user-select: none;
}
button.opcion:active:not(:disabled) { transform: scale(.985); }
.opcion:disabled, div.opcion { cursor: default; }
.opcion .letra {
  flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-weight: 800; font-size: .85rem;
  background: var(--bg-2); color: var(--muted); transition: background .2s, color .2s;
}
.opcion > span:last-child { padding-top: 3px; }
.opcion.elegida { border-color: var(--primary); background: var(--primary-soft); }
.opcion.elegida .letra { background: var(--primary); color: #fff; }
.opcion.correcta { border-color: var(--ok); background: var(--ok-soft); }
.opcion.correcta .letra { background: var(--ok); color: #fff; }
.opcion.incorrecta { border-color: var(--bad); background: var(--bad-soft); }
.opcion.incorrecta .letra { background: var(--bad); color: #fff; }
.opcion.apagada { opacity: .5; }

.explicacion { margin-top: 14px; border-radius: 14px; padding: 14px; background: var(--bg-2); overflow: hidden; font-size: .95rem; }
.explicacion.ok { background: var(--ok-soft); }
.explicacion.bad { background: var(--bad-soft); }
.explicacion h4 { margin: 0 0 .35rem; font-size: 1rem; }
.explicacion p { margin: 0 0 .5rem; }
.fuente { font-size: .82rem; color: var(--muted); }
.aviso-dudosa { margin-top: .6rem; font-size: .85rem; padding: .5rem .7rem; border-radius: 10px; background: var(--warn-soft); color: var(--warn); }
.acciones { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.acciones .derecha { margin-left: auto; }

/* Barra de acciones fija abajo durante el test, al alcance del pulgar */
.barra-test {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 10px; align-items: center;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.barra-test .btn { flex: 1; }
.barra-test .btn.cuadrado { flex: none; width: 52px; padding: 0; }

.puntos { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.punto {
  aspect-ratio: 1; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: .95rem; font-weight: 700; cursor: pointer; color: var(--muted);
  transition: background .2s, border-color .2s, transform .12s;
}
.punto:active { transform: scale(.92); }
.punto.respondida { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.punto.actual { box-shadow: 0 0 0 2px var(--primary); }
.puntos-inline { display: none; }

.atajos { display: none; }

/* ---------- Resultado ---------- */
.resultado { text-align: center; padding: 28px 16px 20px; }
.resultado .anillo { margin: 0 auto 12px; }
.resultado .anillo .centro b { font-size: 2.3rem; }
.resultado h2 { font-size: 1.4rem; }
.resultado .acciones { justify-content: center; }
.resultado .acciones .btn { flex: 1; max-width: 200px; }
.filtros {
  display: flex; gap: 8px; margin: 16px -16px 12px; padding: 6px 16px; overflow-x: auto; scrollbar-width: none;
  position: sticky; top: calc(54px + var(--safe-top)); z-index: 5; background: var(--bg);
}
.filtros::-webkit-scrollbar { display: none; }
.filtros button { flex: none; min-height: 38px; border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: .35rem .95rem; font-weight: 600; cursor: pointer; font-size: .85rem; transition: all .2s; }
.filtros button.activo { background: var(--text); color: var(--bg); border-color: var(--text); }
.revision .card { margin-bottom: 12px; }

/* ---------- Ranking ---------- */
.ranking li .pos { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; background: var(--bg-2); flex: none; }
.ranking li:nth-child(1) .pos { background: #fde68a; color: #92400e; }
.ranking li:nth-child(2) .pos { background: #e5e7eb; color: #374151; }
.ranking li:nth-child(3) .pos { background: #fed7aa; color: #9a3412; }
.ranking li.yo { background: var(--primary-soft); border-radius: 12px; padding-left: .6rem; padding-right: .6rem; margin: 0 -.6rem; }
.ranking .puntos-rk { text-align: right; }
.ranking .puntos-rk b { display: block; font-size: 1.1rem; }

/* ---------- Hoja inferior (modales) ---------- */
.modal-fondo { position: fixed; inset: 0; background: rgba(10, 12, 30, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal {
  width: 100%; max-height: 88dvh; overflow-y: auto;
  border-radius: 24px 24px 0 0; border-bottom: 0; padding: 12px 20px calc(20px + var(--safe-bottom));
}
.modal::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 14px; }
.modal h3 { font-size: 1.15rem; }
.modal .acciones .btn { flex: 1; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar) + 16px + var(--safe-bottom)); z-index: 60; text-align: center;
  background: var(--text); color: var(--bg); padding: .8rem 1.1rem; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow-hover);
}
body.en-test .toast { bottom: calc(90px + var(--safe-bottom)); }
.vacio { text-align: center; padding: 28px 16px; color: var(--muted); }
.cargando { display: grid; place-items: center; padding: 64px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: girar .8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

#confeti { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
kbd { font-family: inherit; font-size: .75rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 .35rem; background: var(--card); }

/* ---------- Escritorio ---------- */
@media (min-width: 720px) {
  h1 { font-size: 1.75rem; }
  .topbar { padding: .75rem max(24px, calc((100vw - 960px) / 2)); }
  .nav { display: flex; gap: .25rem; margin-left: auto; }
  .nav a {
    text-decoration: none; color: var(--muted); padding: .45rem .8rem; border-radius: 10px; font-weight: 600; font-size: .9rem;
    transition: background .2s, color .2s;
  }
  .nav a:hover { background: var(--bg-2); color: var(--text); }
  .nav a.activo { background: var(--primary-soft); color: var(--primary); }
  .topbar .boton-icono { display: none; }
  .tabbar { display: none; }
  main { padding: 28px 24px 64px; }
  body.en-test main { padding-bottom: 120px; }
  .card { padding: 20px; }
  .hero { gap: 28px; padding: 24px; }
  .hero h1 { font-size: 1.75rem; }
  .modos { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .modo { padding: 20px; }
  .fijos { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; }
  .pregunta { padding: 24px; }
  .enunciado { font-size: 1.12rem; }
  .test-cabecera { margin: -28px -24px 12px; padding: 12px 24px; }
  .barra-test { left: 50%; transform: translateX(-50%); width: min(912px, calc(100% - 48px)); bottom: 16px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-hover); padding: 10px; }
  .barra-test .btn { flex: none; min-width: 140px; }
  .barra-test .btn.cuadrado { min-width: 0; width: 52px; }
  .barra-test .btn:last-child { margin-left: auto; }
  .solo-movil { display: none !important; }
  .puntos-inline { display: grid; grid-template-columns: repeat(10, 40px); justify-content: center; gap: 6px; margin-top: 20px; }
  .puntos-inline .punto { min-height: 0; font-size: .8rem; border-radius: 10px; }
  .atajos { display: block; margin-top: 14px; text-align: center; font-size: .8rem; color: var(--muted); }
  .filtros { margin: 24px 0 12px; padding: 6px 0; top: 64px; }
  .modal-fondo { align-items: center; padding: 16px; }
  .modal { width: min(480px, 100%); border-radius: var(--radius); border-bottom: 1px solid var(--line); padding: 24px; }
  .modal::before { display: none; }
  .toast { left: 50%; right: auto; transform: translateX(-50%); bottom: 24px; }
}

@media (hover: hover) and (min-width: 720px) {
  .btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 35%, transparent); }
  .btn.sec:hover, .btn.fantasma:hover { box-shadow: none; background: var(--line); }
  .btn:disabled:hover { transform: none; box-shadow: none; }
  .modo:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
  .fijo:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
  button.opcion:hover:not(:disabled) { border-color: color-mix(in srgb, var(--primary) 50%, var(--line)); }
  .tema:hover { background: var(--bg-2); }
  .punto:hover { transform: scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
