/* ==========================================================================
   TeóricoB — estilos
   Movimiento: solo transform/opacity, curvas propias, < 300 ms en UI.
   Hover solo con ratón; feedback de pulsación con :active en táctil.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --ink: #0f1b2d;
  --muted: #5b6577;
  --line: #dde2ea;
  --accent: #1f5bd6;
  --accent-strong: #1748ad;
  --accent-soft: #e6eefc;
  --on-accent: #ffffff;
  --ok: #0f8a4f;
  --ok-soft: #e3f5eb;
  --ko: #c81e3a;
  --ko-soft: #fde8ec;
  --warn: #b45d00;
  --warn-soft: #fff1dc;
  --shadow: 0 1px 2px rgb(15 27 45 / 0.06), 0 4px 16px rgb(15 27 45 / 0.06);
  --shadow-lg: 0 12px 40px rgb(15 27 45 / 0.18);
  --radius: 14px;
  --radius-sm: 10px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b23;
    --surface-2: #1e2530;
    --ink: #e8edf5;
    --muted: #9aa5b6;
    --line: #2a3240;
    --accent: #5b8cff;
    --accent-strong: #7aa2ff;
    --accent-soft: #1b2a4a;
    --on-accent: #0b1220;
    --ok: #3ccf86;
    --ok-soft: #0f2c1f;
    --ko: #ff6b81;
    --ko-soft: #3a1520;
    --warn: #ffb44d;
    --warn-soft: #3a2a10;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.25);
    --shadow-lg: 0 12px 40px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

/* ---------- Base y ajustes de móvil ---------- */

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

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
}
h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
}
h2 {
  font-size: 1.25rem;
}
h3 {
  font-size: 1.05rem;
}
p {
  margin: 0 0 0.75rem;
}
a {
  color: var(--accent);
}

button,
a,
[role='button'],
label {
  touch-action: manipulation;
}

button,
.btn,
.tab,
.chip,
.opt,
.grid-num {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

input,
select,
textarea {
  font: inherit;
  font-size: 16px; /* evita el zoom de iOS al enfocar */
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

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

.muted {
  color: var(--muted);
}
.small {
  font-size: 0.875rem;
}
.tnum {
  font-variant-numeric: tabular-nums;
}

/* ---------- Carga inicial ---------- */

.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 600ms linear infinite; /* rápido: la espera parece más corta */
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Botones ---------- */

.btn {
  --btn-bg: var(--surface-2);
  --btn-ink: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 160ms var(--ease-out),
    background-color 150ms ease,
    opacity 150ms ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn-primary {
  --btn-bg: var(--accent);
  --btn-ink: var(--on-accent);
}
.btn-ghost {
  --btn-bg: transparent;
  --btn-ink: var(--muted);
}
.btn-danger {
  --btn-bg: var(--ko-soft);
  --btn-ink: var(--ko);
}
.btn-lg {
  min-height: 52px;
  padding: 0.8rem 1.4rem;
  font-size: 1.05rem;
}
.btn-block {
  width: 100%;
}
.btn-icon {
  min-width: 44px;
  padding: 0.5rem;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--btn-bg) 88%, var(--ink));
  }
  .btn-primary:hover:not(:disabled) {
    background: var(--accent-strong);
  }
  .btn-ghost:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--ink);
  }
}

/* ---------- Estructura ---------- */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  height: 60px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
}
.brand b {
  color: var(--accent);
}
.nav {
  display: none;
  gap: 0.25rem;
  margin-left: 1rem;
}
.nav a {
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav a[aria-current='page'] {
  color: var(--accent);
  background: var(--accent-soft);
}
@media (hover: hover) and (pointer: fine) {
  .nav a:hover:not([aria-current='page']) {
    color: var(--ink);
    background: var(--surface-2);
  }
}
.user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.9rem;
}
.user-name {
  display: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.page {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  flex: 1;
}
.page-head {
  margin-bottom: 1.25rem;
}
.page-head p {
  color: var(--muted);
  margin: 0;
}

/* Barra de pestañas inferior (móvil) */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
  transition: color 150ms ease;
}
.tabbar a svg {
  width: 24px;
  height: 24px;
  transition: transform 160ms var(--ease-out);
}
.tabbar a:active svg {
  transform: scale(0.9);
}
.tabbar a[aria-current='page'] {
  color: var(--accent);
}

@media (min-width: 860px) {
  .nav {
    display: flex;
  }
  .user-name {
    display: inline;
  }
  .tabbar {
    display: none;
  }
  .page {
    padding: 32px 24px 48px;
  }
}

/* ---------- Tarjetas y rejillas ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.grid {
  display: grid;
  gap: 12px;
}
@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}
.stack > * + * {
  margin-top: 12px;
}

/* Entrada escalonada de bloques (pantallas que se ven pocas veces) */
.stagger > * {
  animation: rise 360ms var(--ease-out) both;
}
.stagger > *:nth-child(2) {
  animation-delay: 40ms;
}
.stagger > *:nth-child(3) {
  animation-delay: 80ms;
}
.stagger > *:nth-child(4) {
  animation-delay: 120ms;
}
.stagger > *:nth-child(5) {
  animation-delay: 160ms;
}
.stagger > *:nth-child(n + 6) {
  animation-delay: 200ms;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* Tarjeta-enlace pulsable */
.tile {
  display: flex;
  gap: 14px;
  align-items: center;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 160ms var(--ease-out),
    border-color 150ms ease;
}
.tile:active {
  transform: scale(0.98);
}
@media (hover: hover) and (pointer: fine) {
  .tile:hover {
    border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  }
}
.tile-icon {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 1.2rem;
}
.tile-icon.ko {
  background: var(--ko-soft);
  color: var(--ko);
}
.tile-icon.ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.tile-icon.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.tile-body {
  flex: 1;
  min-width: 0;
}
.tile-body h3 {
  margin: 0 0 2px;
}
.tile-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.tile-chevron {
  color: var(--muted);
  flex: none;
}

/* Tarjeta principal del examen */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent) 0%, #173f99 100%);
  color: #fff;
  border: 0;
  padding: 22px;
}
.hero h2 {
  font-size: 1.5rem;
}
.hero p {
  color: rgb(255 255 255 / 0.85);
}
.hero .btn {
  --btn-bg: #fff;
  --btn-ink: #173f99;
}
.hero-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 18px;
}
.hero-facts span {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.16);
  font-size: 0.85rem;
  font-weight: 600;
}
.hero-signs {
  position: absolute;
  right: -28px;
  bottom: -28px;
  width: 130px;
  opacity: 0.14;
  pointer-events: none;
}
@media (min-width: 640px) {
  .hero-signs {
    right: 22px;
    top: 22px;
    bottom: auto;
    width: 110px;
    opacity: 0.95;
  }
}

/* Indicador de preparación */
.dots {
  display: flex;
  gap: 6px;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--line);
}
.dot.ok {
  background: var(--ok);
}
.dot.ko {
  background: var(--ko);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.new {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.badge.ko {
  background: var(--ko-soft);
  color: var(--ko);
}

/* Barras de progreso */
.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(var(--p, 0));
  transition: transform 400ms var(--ease-out);
}
.bar.ok > span {
  background: var(--ok);
}
.bar.warn > span {
  background: var(--warn);
}
.bar.ko > span {
  background: var(--ko);
}

/* ---------- Autenticación ---------- */

.auth {
  min-height: 100dvh;
  display: grid;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  place-items: center;
}
.auth-wrap {
  width: 100%;
  max-width: 980px;
  display: grid;
  gap: 24px;
  align-items: center;
}
.auth-intro h1 {
  font-size: clamp(1.75rem, 5vw, 2.6rem);
  letter-spacing: -0.03em;
}
.auth-intro p {
  color: var(--muted);
  font-size: 1.05rem;
}
.auth-signs {
  display: flex;
  gap: 10px;
  margin: 18px 0;
}
.auth-signs svg {
  width: 52px;
  height: 52px;
}
.auth-facts {
  display: none;
  list-style: none;
  padding: 0;
  margin: 0;
}
.auth-facts li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
}
.auth-facts li::before {
  content: '✓';
  color: var(--ok);
  font-weight: 800;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  justify-self: center;
  padding: 22px;
}
@media (min-width: 860px) {
  .auth-wrap {
    grid-template-columns: 1.1fr 1fr;
    gap: 56px;
  }
  .auth-facts {
    display: block;
  }
}

/* Pestañas con indicador deslizante */
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  margin-bottom: 18px;
  border-radius: 12px;
  background: var(--surface-2);
}
.tabs::before {
  content: '';
  position: absolute;
  inset: 4px auto 4px 4px;
  width: calc(50% - 4px);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 240ms var(--ease-in-out);
}
.tabs[data-active='1']::before {
  transform: translateX(100%);
}
.tab {
  position: relative;
  min-height: 40px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: color 200ms ease;
}
.tab[aria-selected='true'] {
  color: var(--ink);
}

.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}
.field input {
  width: 100%;
  min-height: 48px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.field input[aria-invalid='true'] {
  border-color: var(--ko);
}
.field-error {
  display: block;
  margin-top: 6px;
  color: var(--ko);
  font-size: 0.85rem;
  font-weight: 600;
}
.form-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--ko-soft);
  color: var(--ko);
  font-weight: 600;
  font-size: 0.9rem;
}
.form-error:empty,
.field-error:empty {
  display: none;
}

/* Botón con contenido que cambia de estado (difuminado durante el cambio) */
.btn-label {
  transition: filter 200ms ease, opacity 200ms ease;
}
.is-loading .btn-label {
  filter: blur(2px);
  opacity: 0.6;
}

/* ---------- Pregunta ---------- */

.q {
  display: grid;
  gap: 16px;
}
.q-figure {
  display: grid;
  place-items: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.q-figure svg {
  width: min(150px, 40vw);
  height: auto;
}
.q-text {
  font-size: 1.15rem;
  font-weight: 650;
  line-height: 1.4;
  margin: 0;
}
.q-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
@media (min-width: 760px) {
  .q.has-figure {
    grid-template-columns: 220px 1fr;
    align-items: start;
  }
  .q-figure {
    padding: 24px;
  }
  .q-figure svg {
    width: 170px;
  }
}

.options {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.opt {
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-height: 56px;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    transform 140ms var(--ease-out),
    border-color 150ms ease,
    background-color 150ms ease;
}
.opt:active:not(:disabled) {
  transform: scale(0.985);
}
.opt:disabled {
  cursor: default;
}
.opt-letter {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  font-weight: 800;
  transition: background-color 150ms ease, color 150ms ease;
}
.opt-text {
  padding-top: 3px;
}
.opt.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.opt.is-selected .opt-letter {
  background: var(--accent);
  color: var(--on-accent);
}
.opt.is-correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}
.opt.is-correct .opt-letter {
  background: var(--ok);
  color: #fff;
}
.opt.is-wrong {
  border-color: var(--ko);
  background: var(--ko-soft);
}
.opt.is-wrong .opt-letter {
  background: var(--ko);
  color: #fff;
}
@media (hover: hover) and (pointer: fine) {
  .opt:hover:not(:disabled):not(.is-selected) {
    border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  }
}

.explain {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  transition:
    opacity 220ms var(--ease-out),
    transform 220ms var(--ease-out);
}
@starting-style {
  .explain {
    opacity: 0;
    transform: translateY(6px);
  }
}
.explain.ok {
  border-left-color: var(--ok);
}
.explain.ko {
  border-left-color: var(--ko);
}
.explain strong {
  display: block;
  margin-bottom: 4px;
}
.explain p {
  margin: 0;
}

/* ---------- Práctica ---------- */

.runner-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.runner-head .bar {
  flex: 1;
}
.runner-foot {
  position: sticky;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
@media (min-width: 860px) {
  .runner-foot {
    bottom: 16px;
  }
}

/* ---------- Examen ---------- */

.exam {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.exam-head {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--safe-top);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.exam-head-inner {
  max-width: 1040px;
  margin: 0 auto;
  height: 60px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: background-color 300ms ease, color 300ms ease;
}
.timer.low {
  background: var(--ko-soft);
  color: var(--ko);
}
.exam-count {
  font-weight: 700;
  color: var(--muted);
}
.exam-head .btn-primary {
  margin-left: auto;
}
.exam-body {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px calc(84px + var(--safe-bottom));
  display: grid;
  gap: 24px;
  align-content: start;
}
.exam-foot {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.exam-side {
  display: none;
}
.qgrid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.grid-num {
  aspect-ratio: 1;
  min-height: 40px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition:
    transform 140ms var(--ease-out),
    background-color 150ms ease,
    border-color 150ms ease;
}
.grid-num:active {
  transform: scale(0.94);
}
.grid-num.answered {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}
.grid-num.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
}
.grid-num.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}
.grid-num.ko {
  background: var(--ko-soft);
  border-color: var(--ko);
  color: var(--ko);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.8rem;
}
.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  border-radius: 3px;
  vertical-align: -1px;
  border: 2px solid var(--line);
}
.legend i.answered {
  background: var(--accent-soft);
}

@media (min-width: 900px) {
  .exam-body {
    grid-template-columns: 1fr 320px;
    padding-bottom: 100px;
  }
  .exam-side {
    display: block;
    position: sticky;
    top: 84px;
    align-self: start;
  }
  .exam-foot {
    padding-inline: max(16px, calc((100% - 1040px) / 2 + 16px));
    grid-template-columns: 180px 1fr 180px;
  }
  .exam-foot .grid-toggle {
    visibility: hidden;
  }
}

/* ---------- Resultado ---------- */

.result {
  text-align: center;
  padding: 28px 18px;
}
.result-badge {
  display: inline-grid;
  place-items: center;
  width: 120px;
  height: 120px;
  margin-bottom: 12px;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1.1;
  text-align: center;
  font-weight: 900;
  letter-spacing: 0.04em;
  animation: pop 420ms var(--ease-out) both;
}
.result-badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 18%, transparent);
}
.result-badge.ko {
  background: var(--ko-soft);
  color: var(--ko);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--ko) 18%, transparent);
}
@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
}
.kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 18px;
}
.kpi {
  padding: 12px 8px;
  text-align: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.kpi b {
  display: block;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}
.kpi span {
  color: var(--muted);
  font-size: 0.8rem;
}
.result .grid {
  margin-top: 18px;
}
.exam-count small {
  font-weight: 600;
}
.review-item {
  padding: 16px;
}
.review-item + .result .grid {
  margin-top: 18px;
}
.exam-count small {
  font-weight: 600;
}
.review-item {
  margin-top: 12px;
}
.filters {
  display: flex;
  gap: 8px;
  margin: 20px 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chip {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition:
    transform 140ms var(--ease-out),
    background-color 150ms ease,
    color 150ms ease;
}
.chip:active {
  transform: scale(0.96);
}
.chip[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

/* ---------- Estadísticas ---------- */

.stat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.stat-row:last-child {
  border-bottom: 0;
}
.stat-row .bar {
  grid-column: 1 / -1;
}
.history {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding-top: 8px;
}
.history-bar {
  flex: 1;
  max-width: 22px;
  height: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--ok);
  transform-origin: bottom;
  transform: scaleY(var(--h, 0.05));
  transition: transform 400ms var(--ease-out);
}
.history-bar.ko {
  background: var(--ko);
}
.history-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
}

/* ---------- Novedades ---------- */

.news h3 {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.news ul {
  margin: 0;
  padding-left: 1.1rem;
}
.news li + li {
  margin-top: 6px;
}

.empty {
  text-align: center;
  padding: 36px 18px;
}
.empty-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.footer-note {
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* ---------- Diálogos y hoja inferior ---------- */

.modal {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity 150ms ease,
    transform 150ms var(--ease-out);
}
.modal.is-open {
  opacity: 1;
  transform: scale(1);
  transition-duration: 220ms;
}
.modal::backdrop {
  background: rgb(8 12 20 / 0);
  transition: background-color 200ms ease;
}
.modal.is-open::backdrop {
  background: rgb(8 12 20 / 0.5);
}
.modal-body {
  padding: 22px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}
.modal-actions .btn {
  flex: 1;
}

/* En móvil, la rejilla de preguntas es una hoja que sube desde abajo */
.modal.sheet {
  width: 100%;
  max-width: 100%;
  margin: auto 0 0;
  border-radius: 20px 20px 0 0;
  padding-bottom: var(--safe-bottom);
  transform: translateY(100%);
  opacity: 1;
  transition: transform 200ms var(--ease-drawer);
}
.modal.sheet.is-open {
  transform: translateY(0);
  transition-duration: 320ms;
}
.sheet-handle {
  width: 40px;
  height: 5px;
  margin: 10px auto 0;
  border-radius: 999px;
  background: var(--line);
}
.modal.sheet .modal-body {
  max-height: 70dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ---------- Avisos (toasts) ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  z-index: 60;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100% - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}
@media (min-width: 860px) {
  .toasts {
    bottom: 24px;
  }
}
.in-exam .toasts {
  bottom: calc(84px + var(--safe-bottom));
}
.toast {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 0.92rem;
  pointer-events: auto;
  transition:
    opacity 260ms ease,
    transform 260ms ease;
}
@starting-style {
  .toast {
    opacity: 0;
    transform: translateY(100%);
  }
}
.toast.is-leaving {
  opacity: 0;
  transform: translateY(100%);
  transition-duration: 180ms;
}
.toast .btn {
  --btn-bg: transparent;
  --btn-ink: var(--bg);
  min-height: 32px;
  margin-left: auto;
  padding: 0.25rem 0.6rem;
  text-decoration: underline;
}

/* Luz intermitente del semáforo */
.blink {
  animation: blink 1s steps(1, end) infinite;
}
@keyframes blink {
  50% {
    opacity: 0.15;
  }
}

/* ---------- Movimiento reducido: solo fundidos ---------- */

@media (prefers-reduced-motion: reduce) {
  .stagger > *,
  .result-badge {
    animation-name: fade;
  }
  .btn:active,
  .tile:active,
  .opt:active,
  .chip:active,
  .grid-num:active {
    transform: none;
  }
  .modal,
  .modal.is-open,
  .modal.sheet,
  .modal.sheet.is-open {
    transform: none;
  }
  .modal.sheet {
    opacity: 0;
    transition-property: opacity;
  }
  .modal.sheet.is-open {
    opacity: 1;
  }
  .toast,
  .toast.is-leaving {
    transform: none;
  }
  .tabs::before,
  .bar > span,
  .history-bar {
    transition: none;
  }
  .blink {
    animation-duration: 2s;
  }
}
@keyframes fade {
  from {
    opacity: 0;
  }
}

/* ---------- Tarjetas pulsables: títulos como elementos de frase ---------- */

button.tile {
  width: 100%;
  font: inherit;
  text-align: left;
  color: inherit;
}
.tile-title {
  display: block;
  margin-bottom: 2px;
  font-size: 1.05rem;
  line-height: 1.25;
}
.tile-sub {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}
.tile-body .bar {
  margin-top: 10px;
}
.bar {
  display: block;
}
.topics-list,
.page > .grid + .grid,
.page > .btn + .grid,
.page > .card + .grid {
  margin-top: 12px;
}
.hero .tile-title,
.hero .tile-sub {
  color: inherit;
}
