/* ═══════════════════════════════════════════════════════════════════════
   design-system.css — Sistema visual de UniversityTestPro (v3)

   Capa ADITIVA: se carga la última, después de styles.css, public-site.css
   y las hojas de cada módulo. No sustituye la identidad verde agro de la
   v2; la ordena en tokens, corrige incoherencias y añade los componentes
   compartidos de presentación (estados, avisos, explicaciones, figuras).

   Guía y ejemplos: docs/09_diseno/SISTEMA_VISUAL.md
   Componentes JS:  src/ui/components.js  (window.UTP.ui)

   Índice
     1. Tokens (claro)          6. Examen: opciones accesibles
     2. Tokens (oscuro)         7. Lectura: explicaciones, fórmulas, figuras
     3. Base y foco             8. Componentes ds-*
     4. Botones                 9. Responsive
     5. Formularios            10. Movimiento reducido y alto contraste
   ═══════════════════════════════════════════════════════════════════════ */

/* ── 1. TOKENS (CLARO) ─────────────────────────────────────────────────── */
:root {
  /* Marca. Mismos verdes que la v2: no se rediseña la identidad. */
  --ds-brand-700: #0f5439;
  --ds-brand-600: #1a7a57;
  --ds-brand-500: #22a671;
  --ds-brand-100: #d8f0e5;
  --ds-brand-50:  #eef8f3;
  /* Relleno para botones y marcas con texto blanco. El #22a671 de la v2
     solo daba 3,1:1 con blanco; el degradado ahora termina en #1d8560
     (4,6:1) y el texto es legible en todo el botón. */
  --ds-fill: #1a7a57;
  --ds-fill-end: #1d8560;
  --ds-fill-hover: #0f5439;

  /* Semánticos. Texto sobre su fondo >= 4.5:1 (WCAG AA). */
  --ds-success:        #15803d;
  --ds-success-bg:     #e7f8ee;
  --ds-success-border: #86d9a8;
  --ds-success-text:   #14532d;
  --ds-danger:         #b42318;
  --ds-danger-bg:      #fdeceb;
  --ds-danger-border:  #f4b4ad;
  --ds-danger-text:    #7a1a12;
  --ds-warning:        #a15c07;
  --ds-warning-bg:     #fff6e0;
  --ds-warning-border: #f1c96b;
  --ds-warning-text:   #6b3d02;
  --ds-info:           #1d5fa8;
  --ds-info-bg:        #eaf2fc;
  --ds-info-border:    #a8c8ee;
  --ds-info-text:      #123d6e;

  /* Foco: anillo doble para que se vea sobre cualquier fondo. */
  --ds-focus: #0f5439;
  --ds-focus-halo: rgba(34, 166, 113, .35);

  /* Tipografía. Escala modular 1.2, en rem para respetar el zoom. */
  --ds-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --ds-font-mono: ui-monospace, 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  --ds-text-xs: .8125rem;   /* 13px */
  --ds-text-sm: .875rem;    /* 14px */
  --ds-text-md: 1rem;       /* 16px */
  --ds-text-lg: 1.125rem;   /* 18px */
  --ds-text-xl: 1.375rem;   /* 22px */
  --ds-text-2xl: clamp(1.5rem, 2.6vw, 1.875rem);
  --ds-text-3xl: clamp(1.75rem, 3.6vw, 2.5rem);
  --ds-leading-tight: 1.25;
  --ds-leading-body: 1.6;
  --ds-leading-read: 1.72;
  --ds-measure: 72ch;       /* ancho máximo de lectura cómoda */

  /* Espaciado en múltiplos de 4. */
  --ds-space-1: 4px;  --ds-space-2: 8px;  --ds-space-3: 12px;
  --ds-space-4: 16px; --ds-space-5: 20px; --ds-space-6: 24px;
  --ds-space-8: 32px; --ds-space-10: 40px; --ds-space-12: 48px;

  /* Radios. Tres tamaños en vez de los 8–24 px que convivían. */
  --ds-radius-sm: 10px;
  --ds-radius-md: 14px;
  --ds-radius-lg: 20px;
  --ds-radius-pill: 999px;

  /* Elevación. */
  --ds-shadow-sm: 0 1px 2px rgba(15, 40, 28, .06), 0 2px 6px rgba(15, 40, 28, .05);
  --ds-shadow-md: 0 10px 28px rgba(26, 122, 87, .10);

  /* Movimiento: corto y con curva de salida; nada de rebotes. */
  --ds-ease: cubic-bezier(.2, .7, .2, 1);
  --ds-dur-fast: 120ms;
  --ds-dur: 200ms;
  --ds-dur-slow: 320ms;

  /* Objetivo táctil mínimo (WCAG 2.5.5 recomienda 44 px). */
  --ds-target: 44px;
}

/* ── 2. TOKENS (OSCURO) ───────────────────────────────────────────────────
   Antes había DOS modos oscuros: el elegido con el botón (verde) y el que
   llega por la preferencia del sistema (azul #4f92f0, de una versión
   anterior). Quien tenía el sistema en oscuro y nunca pulsó el botón veía
   la marca en azul. Aquí ambos caminos comparten la misma paleta verde.  */
html[data-theme="dark"] {
  --bg: #0c1a14; --card: #111f18; --text: #e2f0e8; --muted: #8fbca0;
  --primary: #22a671; --primary-dark: #1a7a57; --border: #24402f;
  --surface: #142219; --surface-blue: #131f17; --surface-hover: #1c2e22;
  --input-bg: #0f1c15; --topbar-bg: rgba(11, 25, 18, .9); --dropdown-bg: rgba(17, 31, 24, .98);
  --table-head: #13241a; --progress-bg: #1d3426;
  --chip-bg: #17301f; --chip-text: #a7e8c3; --event-bg: #17301f; --event-text: #a7e8c3;
  --ok: #4ade80; --ok-bg: rgba(21, 128, 61, .2); --ok-border: rgba(110, 231, 183, .32); --ok-text: #86efac;
  --bad: #f87171; --bad-bg: rgba(185, 28, 28, .18); --bad-border: rgba(248, 113, 113, .35);
  --warn: #fbbf24; --warn-bg: rgba(161, 98, 7, .2); --warn-border: rgba(251, 191, 36, .35); --warn-text: #fcd34d;
  --shadow: 0 18px 45px rgba(0, 0, 0, .38);

  --ds-success: #4ade80; --ds-success-bg: rgba(21, 128, 61, .18); --ds-success-border: rgba(74, 222, 128, .38); --ds-success-text: #bbf7d0;
  --ds-danger: #f87171;  --ds-danger-bg: rgba(185, 28, 28, .18);  --ds-danger-border: rgba(248, 113, 113, .4);  --ds-danger-text: #fecaca;
  --ds-warning: #fbbf24; --ds-warning-bg: rgba(161, 98, 7, .2);   --ds-warning-border: rgba(251, 191, 36, .38); --ds-warning-text: #fde68a;
  --ds-info: #7cb6f5;    --ds-info-bg: rgba(29, 95, 168, .2);     --ds-info-border: rgba(124, 182, 245, .38);  --ds-info-text: #d6e8fc;
  --ds-focus: #6ee7b7; --ds-focus-halo: rgba(110, 231, 183, .3);
  --ds-shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --ds-shadow-md: 0 10px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1a14; --card: #111f18; --text: #e2f0e8; --muted: #8fbca0;
    --primary: #22a671; --primary-dark: #1a7a57; --border: #24402f;
    --surface: #142219; --surface-blue: #131f17; --surface-hover: #1c2e22;
    --input-bg: #0f1c15; --topbar-bg: rgba(11, 25, 18, .9); --dropdown-bg: rgba(17, 31, 24, .98);
    --table-head: #13241a; --progress-bg: #1d3426;
    --chip-bg: #17301f; --chip-text: #a7e8c3; --event-bg: #17301f; --event-text: #a7e8c3;
    --ok: #4ade80; --ok-bg: rgba(21, 128, 61, .2); --ok-border: rgba(110, 231, 183, .32); --ok-text: #86efac;
    --bad: #f87171; --bad-bg: rgba(185, 28, 28, .18); --bad-border: rgba(248, 113, 113, .35);
    --warn: #fbbf24; --warn-bg: rgba(161, 98, 7, .2); --warn-border: rgba(251, 191, 36, .35); --warn-text: #fcd34d;
    --shadow: 0 18px 45px rgba(0, 0, 0, .38);

    --ds-success: #4ade80; --ds-success-bg: rgba(21, 128, 61, .18); --ds-success-border: rgba(74, 222, 128, .38); --ds-success-text: #bbf7d0;
    --ds-danger: #f87171;  --ds-danger-bg: rgba(185, 28, 28, .18);  --ds-danger-border: rgba(248, 113, 113, .4);  --ds-danger-text: #fecaca;
    --ds-warning: #fbbf24; --ds-warning-bg: rgba(161, 98, 7, .2);   --ds-warning-border: rgba(251, 191, 36, .38); --ds-warning-text: #fde68a;
    --ds-info: #7cb6f5;    --ds-info-bg: rgba(29, 95, 168, .2);     --ds-info-border: rgba(124, 182, 245, .38);  --ds-info-text: #d6e8fc;
    --ds-focus: #6ee7b7; --ds-focus-halo: rgba(110, 231, 183, .3);
    --ds-shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --ds-shadow-md: 0 10px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

/* Piezas del oscuro que en styles.css quedaron con degradados azules. */
html[data-theme="dark"] body {
  background: radial-gradient(circle at 7% 7%, rgba(26, 122, 87, .18), transparent 30%),
              linear-gradient(180deg, #0a1810 0%, #0c1e16 42%, #0a1810 100%);
}
html[data-theme="dark"] .brandBlock h1,
html[data-theme="dark"] .heroHeader h2 {
  background: linear-gradient(90deg, #e2f0e8 0%, #6ee7b7 60%, #22a671 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body {
    background: radial-gradient(circle at 7% 7%, rgba(26, 122, 87, .18), transparent 30%),
                linear-gradient(180deg, #0a1810 0%, #0c1e16 42%, #0a1810 100%);
  }
  :root:not([data-theme="light"]) .brandBlock h1,
  :root:not([data-theme="light"]) .heroHeader h2 {
    background: linear-gradient(90deg, #e2f0e8 0%, #6ee7b7 60%, #22a671 100%);
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }
  :root:not([data-theme="light"]) .primary { box-shadow: 0 10px 22px rgba(34, 166, 113, .22); }
  :root:not([data-theme="light"]) .explanation strong { color: var(--text); }
}

/* ── 3. BASE Y FOCO ────────────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { text-rendering: optimizeLegibility; overflow-wrap: break-word; }
img, svg, video, canvas { max-width: 100%; }
img { height: auto; }

/* Un único anillo de foco, visible en claro y oscuro, solo con teclado. */
:where(a, button, input, select, textarea, summary, [tabindex], .buttonLike):focus-visible {
  outline: 3px solid var(--ds-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--ds-focus-halo);
}
:where(a, button, summary):focus:not(:focus-visible) { outline: none; }

/* Saltar al contenido (lo añade index.html; ver guía). */
.ds-skip-link {
  position: fixed; left: var(--ds-space-4); top: var(--ds-space-4); z-index: 1000;
  transform: translateY(calc(-100% - 40px)); opacity: 0;
  padding: var(--ds-space-3) var(--ds-space-4); border-radius: var(--ds-radius-md);
  background: var(--card); color: var(--text); font-weight: 700;
  box-shadow: var(--ds-shadow-md); text-decoration: none;
}
.ds-skip-link:focus { transform: none; opacity: 1; }
/* Solo dentro de la app: la capa pública y el acceso no tienen ese destino. */
body:not(.auth-authenticated) .ds-skip-link { display: none; }
#mainContent:focus { outline: none; }

.ds-visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── 4. BOTONES ────────────────────────────────────────────────────────── */
button, .buttonLike {
  font-family: inherit;
  line-height: 1.2;
  transition: background-color var(--ds-dur) var(--ds-ease), border-color var(--ds-dur) var(--ds-ease),
              box-shadow var(--ds-dur) var(--ds-ease), color var(--ds-dur) var(--ds-ease),
              transform var(--ds-dur-fast) var(--ds-ease);
}
/* Primario: mismo verde de marca, con contraste AA en claro y oscuro. */
.primary, html[data-theme="dark"] .primary {
  background: linear-gradient(135deg, var(--ds-fill) 0%, var(--ds-fill-end) 100%);
  color: #fff;
}
.primary:hover:not(:disabled), html[data-theme="dark"] .primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--ds-fill-hover) 0%, var(--ds-fill) 100%);
}
.authModeSwitch button.active, .reviewFilters button.active { background: var(--ds-fill); color: #fff; }
.menuDropdown button:hover:not(:disabled) { background: var(--ds-fill); color: #fff; }

/* Deshabilitado: además de la opacidad, sin sombra ni elevación, para que no
   parezca pulsable. */
button:disabled, button[aria-disabled="true"] {
  box-shadow: none !important; transform: none !important; filter: saturate(.4);
}
.ghost:hover:not(:disabled) { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
/* Acción destructiva: rojo legible y fondo de aviso al pasar el ratón. */
.danger.ghost:hover:not(:disabled) { background: var(--ds-danger-bg); border-color: var(--ds-danger-border); color: var(--ds-danger-text); }

/* ── 5. FORMULARIOS ────────────────────────────────────────────────────── */
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]), select, textarea) {
  font: inherit;
  color: var(--text);
  background-color: var(--input-bg, var(--card));
  border: 1px solid var(--border);
  border-radius: var(--ds-radius-sm);
  transition: border-color var(--ds-dur) var(--ds-ease), box-shadow var(--ds-dur) var(--ds-ease);
}
:where(input, select, textarea):hover:not(:disabled):not(:focus) { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
:where(input, select, textarea)[aria-invalid="true"] { border-color: var(--ds-danger); }
:where(input, select, textarea):disabled { opacity: .6; cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 18px; height: 18px; }
::placeholder { color: var(--muted); opacity: .85; }

.ds-field { display: grid; gap: var(--ds-space-2); }
.ds-field > label, .ds-label { font-weight: 700; font-size: var(--ds-text-sm); }
.ds-hint { font-size: var(--ds-text-xs); color: var(--muted); line-height: 1.5; margin: 0; }
.ds-field-error { font-size: var(--ds-text-xs); color: var(--ds-danger); font-weight: 600; margin: 0; }

/* ── 6. EXAMEN: OPCIONES ACCESIBLES ────────────────────────────────────────
   styles.css ocultaba el radio/checkbox con display:none, así que las
   opciones de respuesta NO se podían elegir con teclado. Se ocultan solo
   visualmente: siguen siendo enfocables y el anillo se pinta en la tarjeta. */
.option input {
  display: block !important;
  position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none;
}
.option { position: relative; transition: border-color var(--ds-dur) var(--ds-ease), background-color var(--ds-dur) var(--ds-ease), box-shadow var(--ds-dur) var(--ds-ease); }
.option:has(input:focus-visible) {
  outline: 3px solid var(--ds-focus); outline-offset: 2px; box-shadow: 0 0 0 6px var(--ds-focus-halo);
}
/* Elegida: no solo cambia el color, la letra se rellena (señal no cromática). */
.option.selected, .option:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 9%, var(--card));
}
.option.selected .optionLetter, .option:has(input:checked) .optionLetter {
  background: var(--ds-fill); color: #fff;
}
.optionText { line-height: 1.55; }

/* ── 7. LECTURA: EXPLICACIONES, FÓRMULAS, FIGURAS ──────────────────────── */
.ds-prose, .explanation, .studyBlock :is(.themeText, .simpleText) {
  font-size: var(--ds-text-md);
  line-height: var(--ds-leading-read);
  max-width: var(--ds-measure);
  hyphens: auto;
}
.ds-prose > * + * { margin-top: .85em; }
.ds-prose :is(h3, h4) { line-height: var(--ds-leading-tight); margin-top: 1.4em; }
.ds-prose :is(ul, ol) { padding-left: 1.3em; }
.ds-prose li + li { margin-top: .35em; }
.ds-prose code, .ds-formula-inline { font-family: var(--ds-font-mono); font-size: .92em; padding: .08em .35em; border-radius: 6px; background: var(--surface); }

/* Fórmula en bloque: nunca desborda la pantalla; se desplaza dentro. */
.ds-formula, .katex-display {
  overflow-x: auto; overflow-y: hidden; max-width: 100%;
  padding: var(--ds-space-3) var(--ds-space-4); margin: var(--ds-space-4) 0;
  border-radius: var(--ds-radius-md); background: var(--surface);
  -webkit-overflow-scrolling: touch;
}
.katex { font-size: 1.08em; }

/* Figura con pie: imagen nunca más ancha que la columna, alto acotado. */
.ds-figure { margin: var(--ds-space-5) 0; display: grid; gap: var(--ds-space-2); }
.ds-figure img, .ds-figure svg {
  display: block; width: 100%; height: auto; max-height: min(70vh, 620px); object-fit: contain;
  border-radius: var(--ds-radius-md); background: #fff; border: 1px solid var(--border);
}
.ds-figure figcaption { font-size: var(--ds-text-sm); color: var(--muted); line-height: 1.55; }

/* ── 8. COMPONENTES ds-* ───────────────────────────────────────────────── */

/* 8.1 Estado (vacío, carga, error, éxito). Generado por UTP.ui.state(). */
.ds-state {
  display: grid; justify-items: center; text-align: center; gap: var(--ds-space-3);
  padding: clamp(24px, 5vw, 40px) var(--ds-space-5);
  border: 1px dashed var(--border); border-radius: var(--ds-radius-lg);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text);
}
.ds-state__icon {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  background: var(--chip-bg); color: var(--chip-text);
}
.ds-state__icon svg { width: 24px; height: 24px; }
.ds-state__title { margin: 0; font-size: var(--ds-text-lg); line-height: var(--ds-leading-tight); }
.ds-state__body { margin: 0; color: var(--muted); max-width: 52ch; line-height: var(--ds-leading-body); }
.ds-state__actions { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); justify-content: center; margin-top: var(--ds-space-2); }
.ds-state--error { border-style: solid; border-color: var(--ds-danger-border); background: var(--ds-danger-bg); }
.ds-state--error .ds-state__icon { background: var(--card); color: var(--ds-danger); }
.ds-state--error .ds-state__body { color: var(--ds-danger-text); }
.ds-state--success { border-style: solid; border-color: var(--ds-success-border); background: var(--ds-success-bg); }
.ds-state--success .ds-state__icon { background: var(--card); color: var(--ds-success); }
.ds-state--compact { padding: var(--ds-space-5); justify-items: start; text-align: left; grid-template-columns: auto 1fr; align-items: start; column-gap: var(--ds-space-4); }
.ds-state--compact .ds-state__icon { grid-row: span 3; width: 40px; height: 40px; }
.ds-state--compact .ds-state__actions { justify-content: flex-start; }

/* Indicador de carga: anillo que gira; con movimiento reducido, pulso suave. */
.ds-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--progress-bg); border-top-color: var(--primary);
  animation: ds-spin 800ms linear infinite;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }

/* Esqueleto para listas y tarjetas que aún cargan. */
.ds-skeleton {
  display: block; border-radius: var(--ds-radius-sm); min-height: 1em;
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-hover) 50%, var(--surface) 100%);
  background-size: 200% 100%; animation: ds-shimmer 1.4s ease-in-out infinite;
}
.ds-skeleton + .ds-skeleton { margin-top: var(--ds-space-2); }
.ds-skeleton--short { width: 60%; }
@keyframes ds-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* 8.2 Aviso en línea (info / éxito / aviso / error). UTP.ui.callout(). */
.ds-callout {
  display: grid; grid-template-columns: auto 1fr; gap: var(--ds-space-1) var(--ds-space-3);
  align-items: start; padding: var(--ds-space-4); border-radius: var(--ds-radius-md);
  border: 1px solid var(--ds-info-border); background: var(--ds-info-bg); color: var(--ds-info-text);
  line-height: var(--ds-leading-body);
}
.ds-callout__icon { display: grid; place-items: center; width: 22px; height: 22px; margin-top: 1px; color: var(--ds-info); }
.ds-callout__icon svg { width: 20px; height: 20px; }
.ds-callout__title { margin: 0; font-weight: 800; font-size: var(--ds-text-md); }
.ds-callout__body { grid-column: 2; margin: 0; }
.ds-callout__body > * { margin: 0; }
.ds-callout__body > * + * { margin-top: .5em; }
.ds-callout--success { border-color: var(--ds-success-border); background: var(--ds-success-bg); color: var(--ds-success-text); }
.ds-callout--success .ds-callout__icon { color: var(--ds-success); }
.ds-callout--warning { border-color: var(--ds-warning-border); background: var(--ds-warning-bg); color: var(--ds-warning-text); }
.ds-callout--warning .ds-callout__icon { color: var(--ds-warning); }
.ds-callout--danger { border-color: var(--ds-danger-border); background: var(--ds-danger-bg); color: var(--ds-danger-text); }
.ds-callout--danger .ds-callout__icon { color: var(--ds-danger); }

/* 8.3 Barra de contexto: curso › asignatura › tema + progreso. UTP.ui.context(). */
.ds-context {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--ds-space-2) var(--ds-space-4); margin: 0 0 var(--ds-space-4);
  font-size: var(--ds-text-sm); color: var(--muted);
}
.ds-context__trail { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-1) var(--ds-space-2); margin: 0; padding: 0; list-style: none; min-width: 0; }
.ds-context__trail li { display: inline-flex; align-items: center; gap: var(--ds-space-2); min-width: 0; }
.ds-context__trail li + li::before { content: "›"; color: var(--muted); opacity: .7; }
.ds-context__trail [aria-current] { color: var(--text); font-weight: 700; }
.ds-context__trail span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 32ch; }
.ds-context .ds-meter { min-width: 180px; flex: 0 1 260px; }

/* 8.4 Medidor de progreso con etiqueta. UTP.ui.meter(). */
.ds-meter { display: grid; gap: 6px; }
.ds-meter__label { display: flex; justify-content: space-between; gap: var(--ds-space-2); font-size: var(--ds-text-xs); color: var(--muted); font-weight: 600; }
.ds-meter__label strong { color: var(--text); font-variant-numeric: tabular-nums; }
.ds-meter__track { height: 8px; border-radius: var(--ds-radius-pill); background: var(--progress-bg); overflow: hidden; }
.ds-meter__fill {
  height: 100%; width: calc(var(--ds-meter, 0) * 100%); border-radius: inherit;
  background: var(--primary); transition: width var(--ds-dur-slow) var(--ds-ease);
}
.ds-meter--success .ds-meter__fill { background: var(--ds-success); }
.ds-meter--warning .ds-meter__fill { background: var(--ds-warning); }
.ds-meter--danger .ds-meter__fill { background: var(--ds-danger); }

/* 8.5 Explicación por opción tras corregir. UTP.ui.explanation().
   Correcta / incorrecta se distinguen por icono + texto, no solo color. */
.ds-explain { display: grid; gap: var(--ds-space-3); margin-top: var(--ds-space-4); }
.ds-explain__item {
  display: grid; grid-template-columns: auto 1fr; gap: var(--ds-space-1) var(--ds-space-3);
  padding: var(--ds-space-4); border-radius: var(--ds-radius-md);
  border: 1px solid var(--border); border-left-width: 4px; background: var(--card);
}
.ds-explain__badge {
  grid-row: span 2; display: grid; place-items: center; width: 32px; height: 32px;
  border-radius: var(--ds-radius-sm); font-weight: 900; background: var(--surface); color: var(--text);
}
.ds-explain__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--ds-space-1) var(--ds-space-3); margin: 0; font-size: var(--ds-text-md); }
.ds-explain__verdict { display: inline-flex; align-items: center; gap: 6px; font-size: var(--ds-text-xs); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.ds-explain__verdict svg { width: 16px; height: 16px; }
.ds-explain__option { font-weight: 600; }
.ds-explain__text { grid-column: 2; margin: 0; line-height: var(--ds-leading-read); max-width: var(--ds-measure); }
.ds-explain__chosen { font-size: var(--ds-text-xs); font-weight: 700; color: var(--muted); }
.ds-explain__item--correct { border-left-color: var(--ds-success); background: var(--ds-success-bg); }
.ds-explain__item--correct .ds-explain__badge { background: #15803d; color: #fff; }
.ds-explain__item--correct .ds-explain__verdict { color: var(--ds-success-text); }
.ds-explain__item--wrong { border-left-color: var(--ds-danger-border); }
.ds-explain__item--wrong .ds-explain__verdict { color: var(--ds-danger); }
.ds-explain__item--wrong.is-chosen { border-left-color: var(--ds-danger); background: var(--ds-danger-bg); }
.ds-explain__item--wrong.is-chosen .ds-explain__badge { background: #b42318; color: #fff; }

/* 8.6 Insignias de procedencia (examen real / del temario). */
.ds-tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: var(--ds-radius-pill); font-size: var(--ds-text-xs); font-weight: 700;
  background: var(--chip-bg); color: var(--chip-text); white-space: nowrap;
}
.ds-tag--exam { background: var(--ds-info-bg); color: var(--ds-info-text); }
.ds-tag--warning { background: var(--ds-warning-bg); color: var(--ds-warning-text); }

/* 8.7 Región que anuncia cambios a lectores de pantalla. UTP.ui.announce(). */
#dsLiveRegion { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── 9. RESPONSIVE ─────────────────────────────────────────────────────── */
/* Ningún bloque puede ensanchar la página en móvil. */
html, body { overflow-x: clip; }
.tableWrap, .ds-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (pointer: coarse) {
  :where(button, .buttonLike, select, input:not([type="checkbox"]):not([type="radio"]):not([type="range"])) { min-height: var(--ds-target); }
  .navDot { min-height: 40px; }
}
@media (max-width: 600px) {
  /* 16 px evita que iOS haga zoom al enfocar un campo. */
  :where(input, select, textarea) { font-size: max(16px, 1em); }
  .ds-explain__item { padding: var(--ds-space-3); }
  .ds-context .ds-meter { flex-basis: 100%; }
}

/* ── 10. MOVIMIENTO REDUCIDO Y ALTO CONTRASTE ──────────────────────────────
   Quien pide menos movimiento no ve desplazamientos, pulsos ni sirenas.
   Los cambios de estado siguen siendo visibles por color y texto. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  :where(button, .option, .card, .studyCatalogCard, .publicFeature):hover { transform: none !important; }
  .ds-spinner { animation: none; border-top-color: var(--primary); border-right-color: var(--primary); }
  .ds-skeleton { animation: none; }
}
@media (forced-colors: active) {
  .option.selected, .option:has(input:checked) { outline: 2px solid Highlight; }
  .ds-explain__item, .ds-callout, .ds-state { border: 1px solid CanvasText; }
  .ds-meter__fill { background: Highlight; }
}

@media print {
  .topbar, .menuWrap, .ds-skip-link, .appToast, .questionActions, .reviewFilters { display: none !important; }
  body { background: #fff !important; color: #000; }
  .card { box-shadow: none !important; border-color: #999 !important; }
  .ds-explain__item, .reviewCard { break-inside: avoid; }
}

/* ═══════════════════════════════════════════════════════════════════════
   11. PANTALLAS
   Ajustes por pantalla sobre las clases existentes. Solo presentación:
   no cambian qué se muestra ni el orden de las acciones.
   ═══════════════════════════════════════════════════════════════════════ */

/* 11.1 Cabecera de la app.
   La marca ocupaba 34 px y competía con el contenido. En móvil la fila de
   sesión (width:100% sin flex-wrap) ensanchaba la página a 615 px. */
.topbar { padding-block: 14px; min-height: 0; }
.topbar .brandBlock h1 { font-size: clamp(20px, 2.2vw, 26px); letter-spacing: -.01em; }
.topbar .brandBlock p { font-size: var(--ds-text-xs); font-weight: 600; }
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 14px; }
  .topbar .brandBlock { flex: 1 1 auto; min-width: 0; }
  .topbar .brandBlock p { display: none; }
  .topbar .authWidget { order: 3; flex: 1 1 100%; width: auto; min-width: 0; flex-wrap: nowrap; justify-content: space-between; }
  .topbar .headerProfileBtn { min-width: 0; flex: 0 1 auto; overflow: hidden; }
  .topbar .authStatusText { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .menuWrap { margin-left: 0; }
}

html[data-theme="dark"] .tableWrap th { background: var(--table-head); }
@media (max-width: 860px) {
  .topbar .authWidget .headerProfileBtn { flex: 1 1 auto; justify-content: flex-start; }
  .topbar .authWidget #authSignOutBtn { flex: 0 0 auto; width: auto; }
}

/* 11.2 Espacio de la asignatura (‹ Mis estudios · Hidráulica · Simulador…). */
.subjectWorkspace { box-shadow: var(--ds-shadow-sm); }
.subjectWorkspaceTitle { font-size: var(--ds-text-lg); font-weight: 800; }
.subjectWorkspace nav button[aria-current="page"],
.subjectWorkspace nav button.active { background: var(--ds-fill); color: #fff; border-color: transparent; }
@media (max-width: 720px) {
  .subjectWorkspace { padding: 10px 12px; gap: 8px; margin-bottom: 14px; }
  .subjectWorkspace > div { display: flex; align-items: center; gap: 8px; min-width: 0; width: 100%; }
  .subjectWorkspace > div > button { flex: 0 0 auto; width: auto; }
  .subjectWorkspaceTitle { display: inline; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* 11.3 Catálogo de estudios. */
.studyCatalogCard { background: var(--card); border-color: var(--border); box-shadow: var(--ds-shadow-sm); }
.studyCatalogCard:hover { border-color: var(--primary); box-shadow: var(--ds-shadow-md); }
.studyCatalogCard > span:not(.catalogEyebrow):not(.catalogArrow) { color: var(--muted); }
.studyCatalogCard > span[aria-hidden="true"]:last-child,
.studyCatalogCard .catalogArrow {
  margin-top: auto; align-self: flex-end; font-size: 1.25rem; color: var(--primary);
  transition: transform var(--ds-dur) var(--ds-ease);
}
.studyCatalogCard:hover > span[aria-hidden="true"]:last-child { transform: translateX(3px); }
.catalogEyebrow { color: var(--primary); font-weight: 700; }
.studyBreadcrumb button { color: var(--muted); text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; }
.studyBreadcrumb button:hover { color: var(--text); text-decoration-color: currentColor; background: transparent; }

/* 11.4 Configurar examen.
   - La franja arcoíris superior pasa a la marca (era la única pieza
     multicolor que quedaba en la app).
   - Las tarjetas de modo elegidas se veían azules (#eef5ff): ahora verdes.
   - «Generar examen» quedaba 1.800 px por debajo; ahora se queda pegado
     abajo mientras se configuran las opciones. */
.homePro::before { background: linear-gradient(90deg, var(--ds-brand-600), var(--ds-brand-500)); height: 6px; }
.modeOption:hover, .modeOption:focus-within { border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); background: color-mix(in srgb, var(--primary) 5%, var(--card)); box-shadow: none; }
.modeOption:focus-within { outline: none; }
.modeOption:has(input:focus-visible) { outline: 3px solid var(--ds-focus); outline-offset: 2px; }
.modeOption:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 9%, var(--card));
  box-shadow: inset 0 0 0 1px var(--primary);
}
.modeOption small { color: var(--muted); }
#simulatorScreen .primaryActionOnly {
  position: sticky; bottom: 0; z-index: 5;
  margin: 24px calc(-1 * clamp(18px, 5vw, 48px)) calc(-1 * clamp(18px, 5vw, 48px));
  padding: 14px clamp(18px, 5vw, 48px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  border-radius: 0 0 24px 24px;
}
#simulatorScreen .primaryActionOnly .primary { min-width: min(100%, 260px); }
.setupAvailability { background: var(--card); }
.availabilityChip { font-variant-numeric: tabular-nums; }
.coverageNotice { border-radius: var(--ds-radius-md); }

/* 11.5 Examen.
   En móvil el panel lateral (modo, temporizador, progreso, navegación)
   ocupaba 440 px antes de la pregunta. Se compacta a una franja. */
.questionCard h2, #questionStatement { line-height: 1.3; }
.questionMeta span { font-size: var(--ds-text-xs); }
.navDot { font-variant-numeric: tabular-nums; }
.navDot.current { outline: 3px solid var(--primary); outline-offset: 1px; }
.timerBox { font-variant-numeric: tabular-nums; }
@media (max-width: 860px) {
  .examLayout { gap: 12px; }
  .examLayout .sidePanel {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 12px; padding: 12px 14px;
  }
  .sidePanel #examModeText { grid-column: 1 / -1; margin: 0; font-size: var(--ds-text-xs); }
  .sidePanel .timerBox { grid-column: 2; grid-row: 2 / span 2; margin: 0; padding: 6px 10px; font-size: 20px; }
  .sidePanel .timerBox > span, .sidePanel .timerBox small { display: none; }
  .sidePanel .timerBox .timerProgress { margin-top: 4px; }
  .sidePanel .progressText { margin: 0; font-size: var(--ds-text-sm); }
  .sidePanel .progress { grid-column: 1; }
  .sidePanel .questionNav {
    grid-column: 1 / -1; display: flex; gap: 6px; margin: 2px 0 0; overflow-x: auto; padding: 4px 2px;
    scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
  }
  .sidePanel .navDot { flex: 0 0 40px; scroll-snap-align: start; }
  .sidePanel #submitBtn { grid-column: 1 / -1; margin-top: 4px; }
  .questionCard { padding: 18px 16px; }
}

/* 11.6 Resultados.
   El mensaje de nota medía hasta 42 px en negrita 950 sobre degradado azul:
   gritaba más que la nota. Ahora es una frase de orientación tranquila. */
.gradeMessage {
  display: block; max-width: 60ch; margin: 12px auto 4px; padding: 12px 18px;
  font-size: var(--ds-text-lg); font-weight: 600; line-height: 1.45;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--ds-radius-md);
  box-shadow: none; color: var(--text);
}
html[data-theme="dark"] .gradeMessage { background: var(--surface); border-color: var(--border); color: var(--text); }
.gradeLabel { font-size: var(--ds-text-lg); }
.gradeCircle span { font-variant-numeric: tabular-nums; }
.scoreDetails { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.scoreDetails div { background: var(--card); }
.scoreDetails strong { font-variant-numeric: tabular-nums; }
.results table { font-variant-numeric: tabular-nums; }
.results .statsBox { line-height: var(--ds-leading-body); }

/* 11.7 Revisión y explicaciones.
   Texto de 14–15 px con borde azul heredado de la v1; ahora verde de marca,
   16 px y ancho de lectura limitado. */
.reviewCard { padding: clamp(18px, 3vw, 26px); }
.reviewCard h3 { font-size: var(--ds-text-lg); line-height: 1.4; }
.reviewCard > p { line-height: var(--ds-leading-body); }
.reviewCard.correct { border-left-width: 6px; }
.reviewCard.wrong { border-left-width: 6px; }
.reviewCard.blank { border-left-width: 6px; }
.reviewHeader { align-items: center; row-gap: 4px; }
.explanation {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  box-shadow: none; padding: 16px 20px; font-size: var(--ds-text-md);
}
.explanation strong { color: var(--text); }
.explanation details > summary { padding: 6px 0; }
.explanation details ul, .reviewCard details ul { padding-left: 1.2em; }
.explanation details li + li, .reviewCard details li + li { margin-top: 8px; }
.sourceLine { font-size: var(--ds-text-xs); }

/* 11.8 Repaso por temas: esquemas en la paleta de marca. */
.schemeRoot { background: linear-gradient(90deg, var(--ds-brand-600), var(--ds-brand-500)); }
.schemeBranchTitle { background: linear-gradient(90deg, var(--ds-brand-700), var(--ds-brand-600)); color: #fff; }
.schemeNode { background: var(--card); border-color: var(--border); box-shadow: var(--ds-shadow-sm); }
.schemeNode span, .quickReviewGrid span { background: var(--ds-fill); color: #fff; }
.studyBlock :is(.themeText, .simpleText) { max-width: none; }
.studyBlock :is(.themeText, .simpleText) p { max-width: var(--ds-measure); }

/* 11.9 Página de asignatura: cobertura real (catalogBrowser, N-09). */
.subjectCoverage {
  margin-top: var(--ds-space-6); padding: var(--ds-space-5); display: grid; gap: var(--ds-space-4);
  border: 1px solid var(--border); border-radius: var(--ds-radius-lg); background: var(--surface);
}
.subjectCoverage h3 { margin: 0; font-size: var(--ds-text-lg); }
.subjectCoverageBody { display: grid; gap: var(--ds-space-4); }
.subjectStats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: var(--ds-space-3); }
.subjectStat {
  display: grid; gap: 2px; padding: var(--ds-space-4); border-radius: var(--ds-radius-md);
  background: var(--card); border: 1px solid var(--border);
}
.subjectStat strong { font-size: var(--ds-text-2xl); line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--text); }
.subjectStat span { font-weight: 700; font-size: var(--ds-text-sm); }
.subjectStat small { color: var(--muted); font-size: var(--ds-text-xs); line-height: 1.4; }
.subjectCoverageCta { margin: 0; font-size: var(--ds-text-sm); color: var(--muted); }
.subjectCoverageCta a { color: var(--primary); font-weight: 700; }
.subjectThemes > summary { font-weight: 700; padding: 4px 0; }
.subjectThemeList { margin: var(--ds-space-3) 0 0; padding-left: 1.4em; display: grid; gap: 6px; columns: 2 280px; }
.subjectThemeList li { break-inside: avoid; line-height: 1.45; }
.subjectThemeList small { margin-left: 8px; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .subjectCoverage { padding: var(--ds-space-4); } }
