/* ==========================================================================
   AprendeMate — Sistema de diseño
   --------------------------------------------------------------------------
   Identidad propia: índigo profundo + ámbar académico, tipografía de sistema
   con jerarquía marcada y una fuente serif reservada a las expresiones
   matemáticas (les da peso de libro de texto sin coste de descarga).

   Construido MOBILE FIRST: el estilo base sirve desde 320 px y las consultas
   de medio añaden estructura conforme hay más espacio.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  /* Marca */
  --brand-50:  #EEF0FE;
  --brand-100: #E0E3FD;
  --brand-200: #C7CBFB;
  --brand-300: #A5A9F7;
  --brand-400: #8285F0;
  --brand-500: #6366F1;
  --brand-600: #4F46E5;
  --brand-700: #4338CA;
  --brand-800: #3730A3;
  --brand-900: #292563;

  /* Tinta y superficies */
  --ink-900: #14162B;
  --ink-800: #1F2240;
  --ink-700: #2E3150;
  --ink-600: #454969;
  --ink-500: #5A5E80;
  --ink-400: #676B8A;   /* AA >= 4.5:1 sobre TODAS las superficies claras del sistema */
  --ink-300: #8E92AD;   /* elementos no textuales: 3:1 */
  --ink-200: #C4C7DC;

  --surface:        #FFFFFF;
  --surface-alt:    #F6F7FC;
  --surface-sunken: #EDEFF8;
  --surface-raised: #FFFFFF;
  --border:         #E2E4F0;
  --border-strong:  #CDD1E4;

  /* Estado */
  --success-50: #E6F7F1;
  --success-500:#0F9D6E;
  --success-700:#0A7853;
  --danger-50:  #FDECEF;
  --danger-500: #D6455D;
  --danger-700: #AC2E43;
  --warning-50: #FDF3E3;
  --warning-500:#9D5E08; /* AA sobre --warning-50 */
  --info-50:    #E7F2FC;
  --info-500:   #0C6FBD;

  /* Gamificación */
  --gold-100: #FCF0D9;
  --gold-500: #C98A16;
  --gold-600: #96630A;  /* AA sobre --gold-100 */

  /* Dificultades */
  --level-low:    #0B7F59;  /* AA sobre --level-low-bg */
  --level-low-bg: #E6F7F1;
  --level-mid:    #9D5E08;  /* AA sobre --level-mid-bg */
  --level-mid-bg: #FDF3E3;
  --level-high:   #B3305E;
  --level-high-bg:#FCEAF1;

  /* Tipografía */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               "Noto Sans", Arial, sans-serif;
  --font-math: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;

  --text-xs:  0.75rem;
  --text-sm:  0.8125rem;
  --text-md:  0.9375rem;
  --text-base:1rem;
  --text-lg:  1.125rem;
  --text-xl:  1.3125rem;
  --text-2xl: 1.625rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;

  /* Espaciado */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* Formas */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-pill: 999px;

  /* Sombras */
  --shadow-xs: 0 1px 2px rgba(20, 22, 43, 0.06);
  --shadow-sm: 0 1px 3px rgba(20, 22, 43, 0.08), 0 1px 2px rgba(20, 22, 43, 0.04);
  --shadow-md: 0 4px 12px rgba(20, 22, 43, 0.08), 0 2px 4px rgba(20, 22, 43, 0.04);
  --shadow-lg: 0 12px 32px rgba(20, 22, 43, 0.12), 0 4px 8px rgba(20, 22, 43, 0.05);
  --shadow-focus: 0 0 0 3px rgba(99, 102, 241, 0.32);

  /* Movimiento */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 130ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  /* Estructura */
  --header-h: 60px;
  --tabbar-h: 62px;
  --container: 1180px;
}

/* Modo oscuro automático: mismos tokens, distinta escala de luminancia. */
@media (prefers-color-scheme: dark) {
  :root {
    --ink-900: #F4F5FB;
    --ink-800: #E7E9F4;
    --ink-700: #D5D8EA;
    --ink-600: #B9BDD6;
    --ink-500: #9AA0C0;
    --ink-400: #7F86A8;
    --ink-300: #666C8C;
    --ink-200: #4B506D;

    --surface:        #171A2E;
    --surface-alt:    #121425;
    --surface-sunken: #0E1020;
    --surface-raised: #1E2138;
    --border:         #2B2F4A;
    --border-strong:  #3A3F5F;

    --brand-50:  #23264A;
    --brand-100: #2A2E5C;
    --brand-200: #343A76;

    --success-50: #102C25;
    --danger-50:  #34161E;
    --warning-50: #33270F;
    --info-50:    #12283C;
    --gold-100:   #33280F;

    --level-low-bg:  #102C25;
    --level-mid-bg:  #33270F;
    --level-high-bg: #34161E;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.55);
  }
}

/* --------------------------------------------------------------------------
   2. Reset y base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.6;
  color: var(--ink-800);
  background: var(--surface-alt);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Nada debe desbordar horizontalmente en ningún ancho. */
  overflow-x: hidden;
}

h1, h2, h3, h4, h5 {
  margin: 0;
  color: var(--ink-900);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

h1 { font-size: var(--text-2xl); letter-spacing: -0.025em; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }

p { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--brand-600);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
a:hover { color: var(--brand-700); text-decoration: underline; }

img, svg { max-width: 100%; height: auto; display: block; }

ul, ol { margin: 0 0 var(--sp-3); padding-left: 1.25rem; }
ul:last-child, ol:last-child { margin-bottom: 0; }

small { font-size: var(--text-xs); }
strong { font-weight: 650; color: var(--ink-900); }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-6) 0;
}

code, kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-sunken);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
}

/* Foco visible y consistente en todo el sistema. */
:focus-visible {
  outline: 2px solid var(--brand-600);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--brand-200); color: var(--ink-900); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Accesibilidad: saltar al contenido */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  padding: var(--sp-3) var(--sp-4);
  background: var(--brand-700);
  color: #fff;
  border-radius: 0 0 var(--radius) 0;
  font-weight: 600;
}
.skip-link:focus { left: 0; text-decoration: none; }

.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;
}

/* --------------------------------------------------------------------------
   3. Estructura
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--sp-4);
}
.container-narrow { max-width: 720px; }
.container-tight  { max-width: 520px; }

.page { padding-block: var(--sp-6) var(--sp-10); }

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-6); }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
}
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-top { align-items: flex-start; }
.row-tight { gap: var(--sp-2); }
.grow { flex: 1 1 auto; min-width: 0; }

.grid { display: grid; gap: var(--sp-4); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
/* Por debajo de 400 px, dos columnas dejan menos de 150 px por tarjeta y el
   contenido se desborda: en esos anchos se apilan en una sola columna. */
.grid-stats { grid-template-columns: minmax(0, 1fr); }

@media (min-width: 400px) {
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-sidebar { grid-template-columns: minmax(0, 1fr) 320px; }
}

.text-muted  { color: var(--ink-500); }
.text-subtle { color: var(--ink-400); }
.text-sm  { font-size: var(--text-sm); }
.text-xs  { font-size: var(--text-xs); }
.text-lg  { font-size: var(--text-lg); }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-success { color: var(--success-700); }
.text-danger  { color: var(--danger-700); }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.full-width { width: 100%; }

/* --------------------------------------------------------------------------
   4. Cabecera de aplicación
   -------------------------------------------------------------------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
}

.appbar-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--header-h);
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--sp-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 750;
  font-size: var(--text-base);
  letter-spacing: -0.02em;
  color: var(--ink-900);
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: var(--ink-900); }
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; }
.brand-name { display: none; }
@media (min-width: 400px) { .brand-name { display: inline; } }

.appnav { display: none; gap: var(--sp-1); margin-left: var(--sp-4); }
@media (min-width: 900px) { .appnav { display: flex; } }

.appnav a {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  font-weight: 550;
  font-size: var(--text-md);
  color: var(--ink-600);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.appnav a:hover { background: var(--surface-sunken); color: var(--ink-900); text-decoration: none; }
.appnav a[aria-current="page"] { background: var(--brand-50); color: var(--brand-700); }

.appbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

/* Marcador de puntos en la cabecera */
.points-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  background: var(--gold-100);
  color: var(--gold-600);
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

/* Avatar y menú de cuenta */
.account { position: relative; }
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--brand-600);
  color: #fff;
  font-weight: 700;
  font-size: var(--text-sm);
  border: 0;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.avatar:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.avatar-lg { width: 64px; height: 64px; font-size: var(--text-xl); }

/* Avatar con foto: la imagen llena el círculo sin deformarse. */
.avatar-photo { padding: 0; overflow: hidden; background: var(--surface-sunken); }
.avatar-photo img,
.avatar-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.avatar-button { overflow: hidden; padding: 0; }
span.avatar { cursor: default; }
span.avatar:hover { transform: none; box-shadow: none; }

/* Campo para subir la foto, con vista previa al lado. */
.photo-field {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
}
.photo-preview {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  border: 1px dashed var(--border);
  color: var(--ink-400);
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-preview.has-photo { border-style: solid; }

@media (max-width: 520px) {
  .photo-field { flex-direction: column; align-items: stretch; }
  .photo-preview { margin-inline: auto; }
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-2);
  z-index: 70;
}
.menu[hidden] { display: none; }
.menu-header {
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-2);
}
.menu a, .menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-radius: var(--radius);
  background: none;
  font: inherit;
  font-size: var(--text-md);
  color: var(--ink-700);
  cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--surface-sunken); text-decoration: none; color: var(--ink-900); }
.menu form { margin: 0; }

/* Barra de pestañas inferior (móvil) */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 60;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 900px) { .tabbar { display: none; } }
body.has-tabbar { padding-bottom: var(--tabbar-h); }
@media (min-width: 900px) { body.has-tabbar { padding-bottom: 0; } }

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-h);
  padding: var(--sp-2) var(--sp-1);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--ink-400);
}
.tabbar a:hover { text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--brand-600); }
.tabbar svg { width: 22px; height: 22px; }

/* Pie */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-block: var(--sp-8);
  margin-top: var(--sp-12);
  font-size: var(--text-sm);
  color: var(--ink-500);
}
.site-footer a { color: var(--ink-600); }

/* --------------------------------------------------------------------------
   5. Botones
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  /* 44 px de alto mínimo: objetivo táctil cómodo. */
  min-height: 44px;
  padding: var(--sp-2) var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--brand-600);
  color: #fff;
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--brand-700); color: #fff; text-decoration: none; box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink-800);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-sunken); color: var(--ink-900); border-color: var(--ink-300); }

.btn-ghost { background: transparent; color: var(--ink-600); }
.btn-ghost:hover { background: var(--surface-sunken); color: var(--ink-900); box-shadow: none; }

.btn-danger { background: var(--danger-500); }
.btn-danger:hover { background: var(--danger-700); }

.btn-success { background: var(--success-500); }
.btn-success:hover { background: var(--success-700); }

.btn-sm { min-height: 36px; padding: var(--sp-1) var(--sp-3); font-size: var(--text-sm); }
.btn-lg { min-height: 52px; padding: var(--sp-3) var(--sp-8); font-size: var(--text-base); }
.btn-block { width: 100%; }
.btn-icon { padding-inline: var(--sp-3); }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Estado de carga */
.btn[data-loading="true"] { pointer-events: none; opacity: 0.8; }
.btn[data-loading="true"]::after {
  content: "";
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   6. Tarjetas y superficies
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  box-shadow: var(--shadow-xs);
}
.card-flush { padding: 0; overflow: hidden; }
.card-pad { padding: var(--sp-5); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.card-title { font-size: var(--text-base); font-weight: 700; }
.card-subtitle { font-size: var(--text-sm); color: var(--ink-500); margin-top: 2px; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.panel {
  background: var(--surface-sunken);
  border-radius: var(--radius);
  padding: var(--sp-4);
}

/* Tarjeta enlazada (materias, temas, subtemas) */
.link-card {
  position: relative;
  display: block;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  color: inherit;
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
.link-card:hover {
  text-decoration: none;
  color: inherit;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.link-card:active { transform: translateY(0); }

/* Franja de color de la materia */
.subject-card { padding-top: var(--sp-6); overflow: hidden; }
.subject-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--accent, var(--brand-600));
}
.subject-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent, var(--brand-600)) 12%, transparent);
  color: var(--accent, var(--brand-600));
  margin-bottom: var(--sp-3);
}
.subject-icon svg { width: 24px; height: 24px; }

/* --------------------------------------------------------------------------
   7. Insignias y etiquetas
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px var(--sp-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.01em;
  background: var(--surface-sunken);
  color: var(--ink-600);
  white-space: nowrap;
}
.badge-success { background: var(--success-50); color: var(--success-700); }
.badge-danger  { background: var(--danger-50);  color: var(--danger-700); }
.badge-warning { background: var(--warning-50); color: var(--warning-500); }
.badge-info    { background: var(--info-50);    color: var(--info-500); }
.badge-brand   { background: var(--brand-50);   color: var(--brand-700); }
.badge-gold    { background: var(--gold-100);   color: var(--gold-600); }
/* Carné y otros códigos: ancho fijo para que se lean en columna. */
/* Zona de acciones irreversibles: se distingue del resto de la ficha. */
.zona-peligro {
  border-color: var(--danger-500);
  background: var(--danger-50);
}
.zona-peligro .card-title { color: var(--danger-700); }

.badge-mono {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  letter-spacing: .02em;
}

/* Nivel de dificultad: color + forma, nunca sólo color. */
.level {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px var(--sp-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.level::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 2px;
  background: currentColor;
}
.level-bajo  { background: var(--level-low-bg);  color: var(--level-low); }
.level-medio { background: var(--level-mid-bg);  color: var(--level-mid); }
.level-medio::before { border-radius: 50%; }
.level-alto  { background: var(--level-high-bg); color: var(--level-high); }
.level-alto::before { border-radius: 1px; transform: rotate(45deg); }

/* --------------------------------------------------------------------------
   8. Progreso
   -------------------------------------------------------------------------- */
.progress {
  height: 8px;
  background: var(--surface-sunken);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent, var(--brand-600));
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease);
}
.progress-sm { height: 5px; }
.progress-lg { height: 12px; }

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-500);
  margin-bottom: 6px;
}

/* Anillo de progreso */
.ring { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
.ring svg { transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-sunken); }
.ring-fill  { stroke: var(--brand-600); stroke-linecap: round; transition: stroke-dashoffset var(--dur-slow) var(--ease); }
.ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 750;
  font-size: var(--text-lg);
  color: var(--ink-900);
  font-variant-numeric: tabular-nums;
}

/* Estadística destacada */
.stat {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
}
.stat-label {
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-400);
}
.stat-value {
  font-size: var(--text-2xl);
  font-weight: 750;
  color: var(--ink-900);
  line-height: 1.15;
  margin-top: var(--sp-1);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat-help { font-size: var(--text-xs); color: var(--ink-500); margin-top: 2px; }

/* --------------------------------------------------------------------------
   9. Formularios
   -------------------------------------------------------------------------- */
.field { margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--ink-700);
}
.label .req { color: var(--danger-500); margin-left: 2px; }

.input, .select, .textarea {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-900);
  font: inherit;
  /* 16 px en móvil evita el zoom automático de iOS al enfocar. */
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
@media (min-width: 768px) { .input, .select, .textarea { font-size: var(--text-md); } }

.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-300); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: var(--shadow-focus);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-300); }
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-sunken);
  color: var(--ink-400);
  cursor: not-allowed;
}

.textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.textarea-lg { min-height: 160px; }

.select {
  padding-right: var(--sp-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%235A5E80' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M5 8l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  background-size: 18px;
}

.input-error, .select-error, .textarea-error {
  border-color: var(--danger-500);
  background: var(--danger-50);
}
.field-error {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin-top: 6px;
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--danger-700);
}
.field-help { margin-top: 6px; font-size: var(--text-sm); color: var(--ink-500); }

.input-group { display: flex; gap: var(--sp-2); align-items: stretch; }
.input-group .input { flex: 1; }

/* Casillas y radios */
.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  cursor: pointer;
  min-height: 40px;
}
.check input[type="checkbox"], .check input[type="radio"] {
  width: 20px; height: 20px;
  margin: 2px 0 0;
  accent-color: var(--brand-600);
  flex-shrink: 0;
  cursor: pointer;
}
.check-text { font-size: var(--text-md); color: var(--ink-700); }
.check-text strong { display: block; color: var(--ink-900); }

/* Interruptor */
.switch { display: flex; align-items: center; gap: var(--sp-3); cursor: pointer; min-height: 44px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  width: 46px; height: 26px;
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  transition: background var(--dur) var(--ease);
  flex-shrink: 0;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch-track { background: var(--brand-600); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--shadow-focus); }

fieldset { border: 0; margin: 0; padding: 0; }
legend {
  padding: 0;
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--ink-700);
  margin-bottom: var(--sp-2);
}

/* --------------------------------------------------------------------------
   10. Avisos
   -------------------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--text-md);
  margin-bottom: var(--sp-4);
}
.alert svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-50); color: var(--success-700); border-color: color-mix(in srgb, var(--success-500) 22%, transparent); }
.alert-error   { background: var(--danger-50);  color: var(--danger-700);  border-color: color-mix(in srgb, var(--danger-500) 22%, transparent); }
.alert-info    { background: var(--info-50);    color: var(--info-500);    border-color: color-mix(in srgb, var(--info-500) 22%, transparent); }
.alert-warning { background: var(--warning-50); color: var(--warning-500); border-color: color-mix(in srgb, var(--warning-500) 25%, transparent); }

.flash-stack {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-3));
  z-index: 50;
}

/* Cerrar un aviso: objetivo tactil comodo (36 px) aunque el icono sea pequeno. */
.alert-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: -6px -6px -6px 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  cursor: pointer;
  flex-shrink: 0;
  opacity: .7;
  transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.alert-close:hover { opacity: 1; background: rgba(0, 0, 0, .06); }

/* --------------------------------------------------------------------------
   11. Tablas
   -------------------------------------------------------------------------- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-md);
  min-width: 560px;
}
.table th, .table td {
  padding: var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-400);
  background: var(--surface-alt);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.table tbody tr { transition: background var(--dur-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-alt); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* En móvil, las tablas de datos se convierten en fichas apiladas. */
@media (max-width: 639px) {
  .table-cards, .table-cards thead, .table-cards tbody,
  .table-cards th, .table-cards td, .table-cards tr { display: block; }
  .table-cards { min-width: 0; }
  .table-cards thead { display: none; }
  .table-cards tr {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--sp-3);
    margin-bottom: var(--sp-3);
  }
  .table-cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-3);
    border: 0;
    padding: var(--sp-1) 0;
    text-align: right;
  }
  .table-cards td::before {
    content: attr(data-label);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-400);
    text-align: left;
    flex-shrink: 0;
  }
  .table-cards td.cell-actions { justify-content: flex-end; padding-top: var(--sp-3); }
  .table-cards td.cell-actions::before { content: none; }
}

/* --------------------------------------------------------------------------
   12. Paginación
   -------------------------------------------------------------------------- */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-600);
  font-size: var(--text-sm);
  font-weight: 600;
}
.pagination a:hover { background: var(--surface-sunken); text-decoration: none; color: var(--ink-900); }
.pagination .current { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.pagination .disabled { opacity: 0.45; pointer-events: none; }

/* --------------------------------------------------------------------------
   13. Estados vacíos y esqueletos
   -------------------------------------------------------------------------- */
.empty {
  text-align: center;
  padding: var(--sp-10) var(--sp-4);
  color: var(--ink-500);
}
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 62px; height: 62px;
  border-radius: 50%;
  background: var(--surface-sunken);
  color: var(--ink-300);
  margin-bottom: var(--sp-4);
}
.empty-icon svg { width: 30px; height: 30px; }
.empty h3 { margin-bottom: var(--sp-2); }
.empty p { max-width: 46ch; margin-inline: auto; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--border) 37%, var(--surface-sunken) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.skeleton-line { height: 12px; margin-bottom: var(--sp-2); }
.skeleton-title { height: 20px; width: 55%; margin-bottom: var(--sp-3); }

/* --------------------------------------------------------------------------
   14. Migas de pan
   -------------------------------------------------------------------------- */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-sm);
  color: var(--ink-400);
  margin-bottom: var(--sp-4);
  padding: 0;
  list-style: none;
}
.breadcrumb li { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; }
.breadcrumb li + li::before { content: "/"; color: var(--ink-200); }
.breadcrumb a { color: var(--ink-500); font-weight: 550; }
.breadcrumb a:hover { color: var(--brand-600); }
.breadcrumb [aria-current] { color: var(--ink-700); font-weight: 650; }

/* --------------------------------------------------------------------------
   15. Notación matemática
   -------------------------------------------------------------------------- */
.math, .prompt {
  font-family: var(--font-math);
  font-size: 1.0625em;
  line-height: 1.75;
}

.mfrac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  margin: 0 0.18em;
  font-size: 0.92em;
  line-height: 1.15;
}
.mfrac-num { padding: 0 0.28em 0.06em; border-bottom: 1.4px solid currentColor; }
.mfrac-den { padding: 0.06em 0.28em 0; }

.mroot { display: inline-flex; align-items: flex-start; margin: 0 0.1em; }
.mroot-index { font-size: 0.66em; transform: translateY(-0.15em); margin-right: -0.22em; }
.mroot-sign { font-size: 1.08em; line-height: 1; }
.mroot-body {
  border-top: 1.4px solid currentColor;
  padding: 0.1em 0.22em 0 0.14em;
  margin-left: -0.06em;
}

sup, sub { font-size: 0.68em; line-height: 0; }
sup { vertical-align: super; }
sub { vertical-align: sub; }

/* --------------------------------------------------------------------------
   16. Figuras
   -------------------------------------------------------------------------- */
.exercise-figure {
  margin: var(--sp-5) 0;
  padding: var(--sp-4);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
}
.exercise-figure figcaption {
  margin-top: var(--sp-3);
  font-size: var(--text-sm);
  color: var(--ink-500);
}
.figure-svg {
  width: 100%;
  max-width: 340px;
  height: auto;
  margin-inline: auto;
}

.fig-shape { fill: color-mix(in srgb, var(--brand-500) 12%, transparent); stroke: var(--brand-600); stroke-width: 2; }
.fig-line { stroke: var(--ink-400); stroke-width: 1.5; }
.fig-line-strong { stroke: var(--ink-700); stroke-width: 2; }
.fig-grid { stroke: var(--border); stroke-width: 1; }
.fig-tick { stroke: var(--ink-500); stroke-width: 1.5; }
.fig-mark { stroke: var(--brand-600); stroke-width: 1.6; }
.fig-arc { stroke: var(--gold-500); stroke-width: 2; }
.fig-arrow { fill: var(--ink-700); }
.fig-point { fill: var(--ink-700); }
.fig-point-strong { fill: var(--brand-600); }
/* Sin selección de texto en el área del estudiante.
   Los campos donde se escribe la respuesta sí se pueden seleccionar: hacen
   falta para corregir un número o mover el cursor. */
body.no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body.no-select input,
body.no-select textarea,
body.no-select [contenteditable="true"] {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}
/* Las imágenes tampoco se arrastran fuera de la página. */
body.no-select img,
body.no-select svg { -webkit-user-drag: none; user-drag: none; }

/* Aviso al intentar pegar una respuesta */
.paste-warning {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  padding: .6rem .9rem;
  border: 1px solid var(--danger-500);
  border-radius: var(--radius-md);
  background: var(--danger-50);
  color: var(--danger-700);
  font-size: var(--text-sm);
}
.paste-warning svg { flex: none; }
/* `display:flex` gana a la regla del navegador para [hidden]. */
.paste-warning[hidden] { display: none; }

/* Aviso flotante cuando se intenta copiar o usar un atajo bloqueado */
.guard-toast {
  position: fixed;
  left: 50%;
  bottom: 5rem;
  transform: translateX(-50%);
  z-index: 880;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: min(92vw, 26rem);
  padding: .7rem 1rem;
  border: 1px solid var(--danger-500);
  border-radius: 999px;
  background: var(--danger-50);
  color: var(--danger-700);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
}
.guard-toast[hidden] { display: none; }
.guard-toast svg { flex: none; }

/* Aviso de atención: tapa la práctica mientras el estudiante está fuera */
.focus-guard {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(9, 11, 24, .92);
  backdrop-filter: blur(6px);
  cursor: pointer;
}
.focus-guard[hidden] { display: none; }
.focus-guard-card {
  max-width: 26rem;
  padding: var(--sp-6);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink-900);
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.focus-guard-card svg { color: var(--danger-500); }
.focus-guard-card h2 { margin: var(--sp-3) 0 var(--sp-2); }
.focus-guard-card strong {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  color: var(--danger-700);
}
.focus-guard-help {
  margin-top: var(--sp-3);
  font-size: var(--text-sm);
  color: var(--ink-500);
}
/* Mientras el aviso está a la vista, el enunciado no debe poder leerse. */
body.is-away .page,
body.is-away .appbar,
body.is-away .tabbar { filter: blur(9px); }

/* Cronómetro del ejercicio */
.timer {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: .35rem .85rem;
  margin-bottom: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--ink-700);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.timer-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-md);
  min-width: 3.2rem;
  text-align: center;
}
.timer-help { font-size: var(--text-xs); color: var(--ink-500); }
.timer.is-warning {
  background: var(--warning-50, var(--gold-100));
  border-color: var(--warning-500, var(--gold-500));
  color: var(--warning-500, var(--gold-600));
}
.timer.is-over {
  background: var(--danger-50);
  border-color: var(--danger-500);
  color: var(--danger-700);
}
.timer.is-over .timer-help { color: var(--danger-700); }

/* Tabla de verdad: las casillas por completar son campos de una letra. */
.truth-table th { text-align: center; }
.truth-table td { text-align: center; font-family: var(--font-math); font-weight: 700; }
.truth-table .truth-blank { padding: 5px; }
.truth-input {
  width: 2.6rem;
  height: 2.4rem;
  padding: 0;
  text-align: center;
  font-family: var(--font-math);
  font-size: var(--text-md);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-900);
  border: 1.5px dashed var(--brand-600);
  border-radius: var(--radius-sm, 6px);
  background: var(--surface);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.truth-input:hover { border-color: var(--brand-700); }
.truth-input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 28%, transparent);
}
.truth-input.is-filled { border-style: solid; background: var(--brand-50); }

@media (max-width: 480px) {
  .truth-input { width: 2.2rem; height: 2.2rem; }
}

.fig-curve { fill: none; stroke: var(--brand-600); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.fig-curve-1 { stroke: var(--gold-500); stroke-dasharray: 6 4; }
.fig-bar { fill: var(--brand-500); }
.fig-cell { fill: var(--surface); stroke: var(--brand-600); stroke-width: 1.5; }
.fig-cell-filled { fill: color-mix(in srgb, var(--brand-500) 45%, transparent); stroke: var(--brand-600); stroke-width: 1.5; }

.fig-label { fill: var(--ink-800); font-size: 14px; font-family: var(--font-math); font-weight: 600; }
.fig-label-muted { fill: var(--ink-400); font-size: 12px; font-family: var(--font-sans); }
.fig-tick-label { fill: var(--ink-500); font-size: 11px; font-family: var(--font-sans); font-weight: 600; }

.fig-slice-0 { fill: var(--brand-600); }
.fig-slice-1 { fill: var(--gold-500); }
.fig-slice-2 { fill: var(--success-500); }
.fig-slice-3 { fill: var(--info-500); }
.fig-slice-4 { fill: var(--danger-500); }
.fig-slice-5 { fill: var(--brand-300); }

.figure-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-md);
  min-width: 260px;
}
.figure-table th, .figure-table td {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-strong);
  text-align: center;
}
.figure-table th { background: var(--surface-sunken); font-weight: 700; }

/* --------------------------------------------------------------------------
   17. Pantalla de ejercicio
   -------------------------------------------------------------------------- */
.exercise-shell { max-width: 720px; margin-inline: auto; }

.exercise-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  font-size: var(--text-sm);
  color: var(--ink-500);
}

.exercise-progress {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.exercise-progress .progress { flex: 1; }
.exercise-progress-count {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--ink-600);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.exercise-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
@media (min-width: 768px) { .exercise-card { padding: var(--sp-8); } }

.exercise-instructions {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--brand-700);
  background: var(--brand-50);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  display: inline-block;
  margin-bottom: var(--sp-4);
}

.exercise-prompt {
  font-family: var(--font-math);
  font-size: var(--text-lg);
  line-height: 1.7;
  color: var(--ink-900);
  margin-bottom: var(--sp-5);
}
@media (min-width: 768px) { .exercise-prompt { font-size: var(--text-xl); } }

.answer-area { margin-top: var(--sp-6); }
.answer-input {
  font-family: var(--font-math);
  font-size: 1.25rem;
  text-align: center;
  min-height: 58px;
  letter-spacing: 0.01em;
}
.answer-unit {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-4);
  background: var(--surface-sunken);
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-weight: 650;
  color: var(--ink-600);
  white-space: nowrap;
}
.answer-with-unit { display: flex; }
.answer-with-unit .answer-input { border-radius: var(--radius) 0 0 var(--radius); }

/* Opciones de respuesta */
.options { display: grid; gap: var(--sp-3); margin-top: var(--sp-2); }

.option {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  min-height: 56px;
  transition: border-color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}
.option:hover { border-color: var(--brand-400); background: var(--brand-50); }
.option:active { transform: scale(0.995); }
.option input { position: absolute; opacity: 0; width: 0; height: 0; }
.option-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  font-weight: 750;
  font-size: var(--text-sm);
  color: var(--ink-500);
  flex-shrink: 0;
  transition: all var(--dur-fast) var(--ease);
}
.option-body { font-family: var(--font-math); font-size: var(--text-base); line-height: 1.5; padding-top: 3px; }
/* Estado seleccionado. Se usa :has() en navegadores modernos y la clase
   .is-selected (que aplica app.js) como respaldo universal. */
.option:has(input:checked),
.option.is-selected { border-color: var(--brand-600); background: var(--brand-50); }
.option:has(input:checked) .option-marker,
.option.is-selected .option-marker { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.option:has(input:focus-visible),
.option.is-focused { box-shadow: var(--shadow-focus); }

/* Verdadero / falso */
.truefalse { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.truefalse .option { justify-content: center; align-items: center; font-weight: 700; min-height: 72px; }
.truefalse .option-body { font-family: var(--font-sans); }

/* Resultado */
.result {
  margin-top: var(--sp-5);
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  padding: var(--sp-5);
  animation: rise var(--dur-slow) var(--ease);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.result-correct   { background: var(--success-50); border-color: color-mix(in srgb, var(--success-500) 35%, transparent); }
.result-incorrect { background: var(--danger-50);  border-color: color-mix(in srgb, var(--danger-500) 30%, transparent); }

.result-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.result-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  color: #fff;
}
.result-correct .result-icon   { background: var(--success-500); }
.result-incorrect .result-icon { background: var(--danger-500); }
.result-icon svg { width: 24px; height: 24px; }
.result-title { font-size: var(--text-lg); font-weight: 750; }
.result-correct .result-title   { color: var(--success-700); }
.result-incorrect .result-title { color: var(--danger-700); }
.result-points { font-size: var(--text-sm); font-weight: 650; color: var(--ink-600); }

.result-block {
  background: var(--surface-raised);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin-top: var(--sp-3);
}
.result-block h4 {
  font-size: var(--text-xs);
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-400);
  margin-bottom: var(--sp-2);
}
.result-answer { font-family: var(--font-math); font-size: var(--text-lg); font-weight: 650; color: var(--ink-900); }
.result-explanation { font-family: var(--font-math); line-height: 1.75; color: var(--ink-700); }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}
.result-actions .btn { flex: 1 1 160px; }

/* Pista desplegable */
.hint { margin-top: var(--sp-4); }
.hint summary {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--brand-700);
  padding: var(--sp-2) 0;
  min-height: 40px;
  list-style: none;
}
.hint summary::-webkit-details-marker { display: none; }
.hint summary:hover { color: var(--brand-800); }
.hint[open] summary { margin-bottom: var(--sp-2); }
.hint-body {
  background: var(--warning-50);
  border-left: 3px solid var(--warning-500);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-math);
  color: var(--ink-700);
}

/* Aviso de logro */
.achievement-toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--gold-100);
  border: 1px solid color-mix(in srgb, var(--gold-500) 35%, transparent);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-3);
}
.achievement-toast .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gold-500);
  color: #fff;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   18. Portada
   -------------------------------------------------------------------------- */
.hero { padding-block: var(--sp-10) var(--sp-8); }
@media (min-width: 768px) { .hero { padding-block: var(--sp-16) var(--sp-12); } }

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px var(--sp-3);
  background: var(--brand-50);
  color: var(--brand-700);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-bottom: var(--sp-4);
}
.hero-title {
  font-size: clamp(1.9rem, 6.2vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  margin-bottom: var(--sp-4);
  max-width: 18ch;
}
.hero-title em {
  font-style: normal;
  background: linear-gradient(100deg, var(--brand-600), var(--brand-400));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-lead {
  font-size: var(--text-lg);
  color: var(--ink-500);
  max-width: 54ch;
  margin-bottom: var(--sp-6);
}
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.hero-actions .btn { flex: 1 1 200px; }
@media (min-width: 560px) { .hero-actions .btn { flex: 0 0 auto; } }

.hero-figure {
  margin-top: var(--sp-8);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-lg);
}
@media (min-width: 1024px) {
  .hero-grid { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: var(--sp-10); align-items: center; }
  .hero-figure { margin-top: 0; }
}

.feature { display: flex; gap: var(--sp-4); }
.feature-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: var(--radius);
  background: var(--brand-50);
  color: var(--brand-700);
  flex-shrink: 0;
}
.feature-icon svg { width: 22px; height: 22px; }

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--brand-600);
  color: #fff;
  font-weight: 750;
  font-size: var(--text-sm);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   19. Autenticación
   -------------------------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--sp-6) var(--sp-4) var(--sp-10);
}
.auth-card {
  width: 100%;
  max-width: 440px;
  margin-inline: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
}
@media (min-width: 480px) { .auth-card { padding: var(--sp-8); } }

.auth-head { text-align: center; margin-bottom: var(--sp-6); }
.auth-head .brand { justify-content: center; margin-bottom: var(--sp-4); font-size: var(--text-lg); }
.auth-head .brand-name { display: inline; }
.auth-foot {
  text-align: center;
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
  font-size: var(--text-md);
  color: var(--ink-500);
}

/* Medidor de contraseña */
.pw-meter { display: flex; gap: 4px; margin-top: 8px; }
.pw-meter span {
  flex: 1;
  height: 4px;
  background: var(--surface-sunken);
  border-radius: var(--radius-pill);
  transition: background var(--dur) var(--ease);
}
.pw-meter[data-score="1"] span:nth-child(1) { background: var(--danger-500); }
.pw-meter[data-score="2"] span:nth-child(-n+2) { background: var(--warning-500); }
.pw-meter[data-score="3"] span:nth-child(-n+3) { background: var(--brand-500); }
.pw-meter[data-score="4"] span { background: var(--success-500); }

.honeypot {
  position: absolute !important;
  left: -9999px;
  opacity: 0;
  height: 0;
  width: 0;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   20. Panel del estudiante
   -------------------------------------------------------------------------- */
.greeting-card {
  background: linear-gradient(135deg, var(--brand-700), var(--brand-500));
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.greeting-card::after {
  content: "";
  position: absolute;
  top: -70px; right: -70px;
  width: 210px; height: 210px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.09);
}
.greeting-card h1 { color: #fff; font-size: var(--text-2xl); margin-bottom: var(--sp-2); }
.greeting-card p { color: rgba(255, 255, 255, 0.86); position: relative; }
.greeting-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-5);
  margin-top: var(--sp-5);
  position: relative;
}
.greeting-stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 650;
}
.greeting-stat-value {
  font-size: var(--text-xl);
  font-weight: 750;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.resume-card {
  border: 1.5px solid var(--brand-200);
  background: var(--brand-50);
}

.level-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.activity-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: 0; padding-bottom: 0; }
.activity-item:first-child { padding-top: 0; }
.activity-dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.activity-dot svg { width: 18px; height: 18px; }
.activity-ok  { background: var(--success-500); }
.activity-bad { background: var(--danger-500); }
.activity-body { min-width: 0; flex: 1; }
.activity-title {
  font-weight: 600;
  font-size: var(--text-md);
  color: var(--ink-800);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.achievement {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
}
.achievement-locked { opacity: 0.6; }
.achievement-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--gold-100);
  color: var(--gold-600);
  flex-shrink: 0;
}
.achievement-locked .achievement-icon { background: var(--surface-sunken); color: var(--ink-300); }

/* Selector de nivel */
.level-picker { display: grid; gap: var(--sp-4); }
@media (min-width: 768px) { .level-picker { grid-template-columns: repeat(3, 1fr); } }

.level-option {
  display: block;
  border: 1.5px solid var(--border);
  border-left-width: 5px;
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  background: var(--surface-raised);
  color: inherit;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.level-option:hover { text-decoration: none; color: inherit; transform: translateY(-2px); box-shadow: var(--shadow-md); }
.level-option[data-level="bajo"]  { border-left-color: var(--level-low); }
.level-option[data-level="medio"] { border-left-color: var(--level-mid); }
.level-option[data-level="alto"]  { border-left-color: var(--level-high); }
.level-option-disabled { opacity: 0.55; pointer-events: none; }

/* Barra de progreso circular pequeña en tarjetas */
.mini-ring { width: 44px; height: 44px; flex-shrink: 0; }
.mini-ring text { font-size: 12px; font-weight: 700; fill: var(--ink-700); font-family: var(--font-sans); }

/* --------------------------------------------------------------------------
   21. Utilidades finales
   -------------------------------------------------------------------------- */
.divider { height: 1px; background: var(--border); margin: var(--sp-5) 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.sr-focusable:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media print {
  .appbar, .tabbar, .site-footer, .btn, .flash-stack { display: none !important; }
  body { background: #fff; }
  .card, .exercise-card { box-shadow: none; border-color: #ccc; }
}

/* ==========================================================================
   Navegación del recorrido (subtema anterior / siguiente, volver al tema)
   Aparece al final de las páginas de tema y subtema para que nadie quede
   atrapado al terminar una serie. En móvil se apila; desde 640px va en fila.
   ========================================================================== */
.course-nav {
  margin-top: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  align-items: stretch;
}

.course-nav .btn {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  min-height: 48px;
}

.course-nav-side { display: flex; min-width: 0; }
.course-nav-side:empty { display: none; }

.course-nav-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.course-nav-label {
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: .75;
  font-weight: 700;
}

.course-nav-name {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 640px) {
  .course-nav {
    flex-direction: row;
    align-items: center;
    gap: var(--sp-4);
  }

  .course-nav-side { flex: 1 1 0; }
  .course-nav-end { justify-content: flex-end; }
  .course-nav .btn { width: auto; }
  .course-nav-up { flex: 0 0 auto; }
  .course-nav-end .btn { text-align: right; }
  .course-nav-end .course-nav-text { align-items: flex-end; }
}
