/* ==========================================================================
   Bajo Nivel — base.css
   Tokens, temas, tipografía, layout y sistema de componentes compartido.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --font-display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --font-sans: "Sora", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --max: 1200px;
  --gutter: clamp(1.15rem, 4vw, 2.75rem);
  --radius: 16px;
  --radius-lg: 22px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --header-h: 70px;

  --viz-1: #45F3C4;
  --viz-2: #FF8A5B;
  --viz-3: #C39BFF;
  --viz-4: #6FD0FF;
  --viz-5: #FFD479;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070B09;
  --bg-2: #0A100D;
  --surface: #0E1512;
  --surface-2: #121B17;
  --surface-3: #182420;
  --ink: #ECF5F0;
  --ink-soft: #C6D5CD;
  --muted: #94A79E;
  --faint: #6F827A;
  --line: rgba(213, 255, 240, .10);
  --line-strong: rgba(213, 255, 240, .20);
  --accent: #45F3C4;
  --accent-strong: #45F3C4;
  --accent-rgb: 69, 243, 196;
  --accent-text: #5BF7CC;
  --accent-ink: #04241D;
  --accent-soft: rgba(69, 243, 196, .10);
  --accent-2: #FF8A5B;
  --accent-3: #C39BFF;
  --accent-4: #6FD0FF;
  --accent-5: #FFD479;
  --danger: #FF7B7B;
  --header: rgba(7, 11, 9, .74);
  --glow-1: rgba(69, 243, 196, .07);
  --glow-2: rgba(111, 208, 255, .05);
  --shadow: 0 30px 80px -50px rgba(0, 0, 0, .95);
  --shadow-soft: 0 12px 34px -24px rgba(0, 0, 0, .85);
  --selection: rgba(69, 243, 196, .25);
  --grid-line: rgba(213, 255, 240, .07);
  --code-bg: rgba(69, 243, 196, .08);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #F7F4EC;
  --bg-2: #F1ECE0;
  --surface: #FFFDF8;
  --surface-2: #F8F4EA;
  --surface-3: #EFE9DB;
  --ink: #141B17;
  --ink-soft: #2E3B34;
  --muted: #55645C;
  --faint: #5F6D66;
  --line: rgba(20, 35, 28, .12);
  --line-strong: rgba(20, 35, 28, .24);
  --accent: #0C8B70;
  --accent-strong: #0A6F5B;
  --accent-rgb: 12, 139, 112;
  --accent-text: #056B57;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(12, 139, 112, .10);
  --accent-2: #B84A1D;
  --accent-3: #6C46A8;
  --accent-4: #1268A8;
  --accent-5: #8A6500;
  --danger: #B3261E;
  --header: rgba(247, 244, 236, .80);
  --glow-1: rgba(12, 139, 112, .10);
  --glow-2: rgba(22, 104, 168, .06);
  --shadow: 0 30px 70px -45px rgba(35, 50, 42, .38);
  --shadow-soft: 0 12px 32px -24px rgba(35, 50, 42, .30);
  --selection: rgba(12, 139, 112, .18);
  --grid-line: rgba(20, 35, 28, .08);
  --code-bg: rgba(12, 139, 112, .08);

  --viz-1: #0B8F72;
  --viz-2: #C2542A;
  --viz-3: #7548B8;
  --viz-4: #1668A8;
  --viz-5: #9A7200;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 24px);
}
body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 680px at 82% -12%, var(--glow-1), transparent 64%),
    radial-gradient(900px 620px at -10% 16%, var(--glow-2), transparent 62%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: clamp(1rem, .96rem + .15vw, 1.0625rem);
  font-weight: 400;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: .030;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}
html[data-theme="light"] body::before { opacity: .022; }

img, svg, canvas, video { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; }
ul, ol { list-style: none; padding: 0; }
table { border-collapse: collapse; }
::selection { background: var(--selection); color: var(--ink); }

h1, h2, h3, h4 {
  font-weight: 400;
  line-height: 1.12;
  text-wrap: balance;
}
h1, h2 { font-family: var(--font-display); }
h3, h4 { font-family: var(--font-sans); font-weight: 600; }
p { text-wrap: pretty; }
strong { font-weight: 600; color: var(--ink); }
code, kbd, samp {
  font-family: var(--font-mono);
  font-size: .88em;
  color: var(--accent-text);
  background: var(--code-bg);
  border-radius: 5px;
  padding: .08em .3em;
}

:where(a, button, input, textarea, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 3px;
  border-radius: 5px;
}

/* ---------- Utilidades ---------- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon circle[r="1"], .icon circle[r=".8"] { fill: currentColor; stroke: none; }
.skip-link {
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 300;
  transform: translateY(-220%);
  background: var(--accent-strong);
  color: var(--accent-ink);
  padding: .6rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: .88rem;
  text-decoration: none;
  transition: transform .2s var(--ease);
}
.skip-link:focus { transform: translateY(0); }
.mono-label {
  display: block;
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--muted);
}
.noscript {
  position: fixed;
  left: 1rem; right: 1rem; bottom: 1rem;
  z-index: 200;
  padding: .9rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: .9rem;
}

/* ---------- Header ---------- */
.site-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 100;
  background: var(--header);
  border-bottom: 1px solid transparent;
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  transition: border-color .3s, box-shadow .3s, background .3s;
}
.site-header.is-scrolled {
  border-bottom-color: var(--line);
  box-shadow: 0 18px 40px -30px rgba(0, 0, 0, .6);
}
.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  min-height: var(--header-h);
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  gap: .9rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  text-decoration: none;
  color: var(--ink);
  letter-spacing: -.02em;
  flex: none;
}
.brand-mark {
  width: 30px;
  height: 30px;
  color: var(--accent-text);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.brand-word { font-weight: 600; font-size: 1.04rem; line-height: 1; }
.brand-slash {
  display: inline-block;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--accent-text);
  padding: 0 .04em;
  font-weight: 400;
}
.main-nav {
  display: flex;
  align-items: center;
  gap: .1rem;
  margin-left: auto;
}
.main-nav a {
  position: relative;
  text-decoration: none;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 500;
  padding: .48rem .68rem;
  border-radius: 8px;
  transition: color .2s, background .2s;
  white-space: nowrap;
}
.main-nav a:hover { color: var(--ink); background: var(--surface-2); }
.main-nav a.is-active { color: var(--accent-text); }
.main-nav a.is-active::after {
  content: "";
  position: absolute;
  left: .68rem; right: .68rem; bottom: .26rem;
  height: 1px;
  background: var(--accent);
  opacity: .7;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin-left: auto;
}
.main-nav + .header-actions { margin-left: .4rem; }
.level-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}
.level-switch button {
  border-radius: 999px;
  padding: .3rem .66rem;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--muted);
  transition: background .2s, color .2s, box-shadow .2s;
  white-space: nowrap;
}
.level-switch button:hover { color: var(--ink); }
.level-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12), inset 0 0 0 1px var(--line);
}
.icon-btn {
  width: 38px; height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  transition: color .2s, border-color .2s, background .2s, transform .2s;
  flex: none;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-2); }
.icon-btn .icon { width: 18px; height: 18px; }
.index-btn {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: 0 .8rem;
  font-size: .8rem;
  font-weight: 500;
}
.index-btn span { line-height: 1; }
.classroom-btn {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 0 .7rem;
  font-size: .78rem;
  font-weight: 500;
}
.classroom-btn span { line-height: 1; }
html[data-classroom="on"] .classroom-btn {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-soft);
}
.icon-sun, .icon-moon { transition: transform .3s var(--ease); }
html[data-theme="dark"] .icon-sun { display: block; }
html[data-theme="dark"] .icon-moon { display: none; }
html[data-theme="light"] .icon-sun { display: none; }
html[data-theme="light"] .icon-moon { display: block; }
.js-theme-toggle:hover .icon { transform: rotate(18deg); }

.progress {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
}
.progress span {
  display: block;
  height: 100%;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--accent), var(--accent-4));
  will-change: transform;
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(6.5rem, 14vh, 9rem) var(--gutter) clamp(4.5rem, 9vh, 7rem);
  overflow: hidden;
}
#hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  opacity: .55;
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 52%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 0%, #000 52%, transparent 100%);
}
.hero-glow {
  position: absolute;
  z-index: -1;
  top: 36%; left: 50%;
  width: min(720px, 90vw);
  height: min(560px, 70vh);
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, var(--glow-1), transparent 68%);
  pointer-events: none;
}
.hero-inner { position: relative; max-width: 980px; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font-family: var(--font-mono);
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.5rem;
}
.eyebrow::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
  flex: none;
}
.hero h1 {
  font-size: clamp(3.35rem, 10.8vw, 7.9rem);
  line-height: .93;
  letter-spacing: -.028em;
  margin: 0 0 1.55rem;
}
.hero h1 em {
  display: inline-block;
  font-style: italic;
  color: var(--accent-text);
  letter-spacing: -.012em;
  text-shadow: 0 0 70px rgba(var(--accent-rgb), .18);
}
.hero-lead {
  font-size: clamp(1.02rem, 2.1vw, 1.2rem);
  line-height: 1.65;
  color: var(--muted);
  max-width: 680px;
  margin: 0 auto 2.15rem;
  font-weight: 300;
}
.hero-lead strong { color: var(--ink); font-weight: 500; }
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .7rem;
  margin-bottom: 2.1rem;
}
.token-stream {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .34rem;
  max-width: 760px;
  min-height: 2.2rem;
  margin: 0 auto 1.5rem;
  font-family: var(--font-mono);
  font-size: .74rem;
}
.stream-token {
  padding: .22rem .5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-soft);
  opacity: 0;
  transform: translateY(7px);
  transition: opacity .4s var(--ease), transform .4s var(--ease), color .4s, border-color .4s;
}
.stream-token.on { opacity: 1; transform: none; }
.stream-token.is-accent { color: var(--accent-text); border-color: rgba(var(--accent-rgb), .28); }
.stream-token.is-warm { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 30%, transparent); }
.stream-token.is-ghost { color: var(--faint); }
.stream-token.is-caret { border-color: var(--accent); color: var(--accent-text); }
.hero-meta {
  font-family: var(--font-mono);
  font-size: .68rem;
  letter-spacing: .08em;
  color: var(--faint);
}
.scroll-cue {
  position: absolute;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
}
.scroll-cue-line {
  display: block;
  width: 1px;
  height: 38px;
  background: linear-gradient(180deg, transparent, var(--accent));
  position: relative;
  overflow: hidden;
}
.scroll-cue-line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: translateY(-100%);
  animation: cue 2.4s var(--ease) infinite;
}
@keyframes cue {
  0% { transform: translateY(-100%); }
  55%, 100% { transform: translateY(100%); }
}

/* ---------- Capítulos ---------- */
.chapter {
  position: relative;
  padding: clamp(4.5rem, 9vw, 8rem) var(--gutter);
  border-top: 1px solid var(--line);
  scroll-margin-top: calc(var(--header-h) + 16px);
}
.chapter--tint {
  background: linear-gradient(180deg, transparent, var(--surface-2) 14%, var(--surface-2) 86%, transparent);
}
.chapter-inner { max-width: var(--max); margin: 0 auto; }
.chapter-head { max-width: 800px; margin-bottom: clamp(2rem, 4.5vw, 3.2rem); }
.kicker {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .7rem;
}
.kicker-num { color: var(--accent-text); }
.kicker-line {
  display: inline-block;
  width: 26px;
  height: 1px;
  background: var(--line-strong);
}
.chapter h2 {
  font-size: clamp(2.15rem, 5.2vw, 4.15rem);
  line-height: .99;
  letter-spacing: -.024em;
  margin-bottom: 1.1rem;
}
.chapter h2 em {
  font-style: italic;
  color: var(--accent-text);
}
.lead {
  font-size: clamp(1rem, 1.7vw, 1.1rem);
  line-height: 1.7;
  color: var(--muted);
  max-width: 68ch;
  font-weight: 300;
}
.section-note {
  font-size: .82rem;
  line-height: 1.65;
  color: var(--faint);
  border-left: 2px solid var(--line-strong);
  padding: .15rem 0 .15rem .9rem;
  max-width: 70ch;
  margin: 1.2rem 0 1.6rem;
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .48rem;
  padding: .76rem 1.28rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: .86rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .25s var(--ease), background .25s, border-color .25s, color .25s, box-shadow .25s;
}
.btn .icon { width: 16px; height: 16px; }
.btn-primary {
  background: var(--accent-strong);
  color: var(--accent-ink);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px -16px rgba(var(--accent-rgb), .75);
}
.btn-ghost {
  border-color: var(--line-strong);
  color: var(--ink);
  background: transparent;
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent-soft);
}
.btn-soft {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
}
.btn-soft:hover { border-color: var(--line-strong); background: var(--surface-3); }
.btn-small { padding: .5rem .85rem; font-size: .76rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .26rem .55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .64rem;
  font-weight: 500;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.4;
}
.chip-plain { color: var(--accent-3); border-color: color-mix(in srgb, var(--accent-3) 28%, transparent); }
.chip-demo { color: var(--accent-4); border-color: color-mix(in srgb, var(--accent-4) 28%, transparent); }
.chip-tech { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 28%, transparent); }
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .42rem .72rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .76rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  transition: color .2s, border-color .2s, background .2s;
}
.chip-btn:hover, .chip-btn[aria-pressed="true"] {
  color: var(--accent-text);
  border-color: rgba(var(--accent-rgb), .4);
  background: var(--accent-soft);
}
.sample-row, .chip-row, .preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
}

/* ---------- Formularios ---------- */
.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .5rem;
}
.field { display: flex; flex-direction: column; gap: .1rem; }
.textarea, .select, .search-input, .input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  padding: .78rem .92rem;
  font-size: .94rem;
  line-height: 1.55;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.textarea { resize: vertical; min-height: 80px; }
.textarea::placeholder, .search-input::placeholder, .input::placeholder { color: var(--faint); }
.textarea:focus, .select:focus, .search-input:focus, .input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236F827A' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .8rem center;
  background-size: 16px;
  padding-right: 2.3rem;
  cursor: pointer;
}
html[data-theme="light"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236C7A73' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
.control { display: flex; flex-direction: column; gap: .45rem; }
.control > label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.control output {
  font-size: .84rem;
  color: var(--accent-text);
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.control-note {
  font-size: .76rem;
  line-height: 1.5;
  color: var(--faint);
}

/* rangos */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0 var(--fill, 50%), var(--surface-3) var(--fill, 50%) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  transition: box-shadow .2s, transform .2s;
}
input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 0 6px var(--accent-soft); }
input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
}
input[type="range"]::-moz-range-progress {
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 4px; border-radius: 999px; }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  width: fit-content;
  max-width: 100%;
}
.segmented button {
  border-radius: 7px;
  padding: .38rem .62rem;
  font-size: .75rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: background .2s, color .2s;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* ---------- Demo / panel ---------- */
.demo {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(1.05rem, 3vw, 1.7rem);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.demo::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent 62%);
  opacity: .55;
  pointer-events: none;
}
.demo-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  margin-bottom: 1.3rem;
}
.demo-actions { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.demo-note {
  font-size: .77rem;
  line-height: 1.55;
  color: var(--faint);
  max-width: 65ch;
}
.demo-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  margin-top: 1.2rem;
}

/* ---------- Cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .9rem;
  margin-top: 1.8rem;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem;
  box-shadow: var(--shadow-soft);
  transition: transform .35s var(--ease), border-color .35s, box-shadow .35s;
}
@media (hover: hover) {
  .card:hover {
    transform: translateY(-3px);
    border-color: var(--line-strong);
    box-shadow: var(--shadow);
  }
}
.card-icon {
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--accent-soft);
  color: var(--accent-text);
  margin-bottom: .95rem;
}
.card-icon .icon { width: 19px; height: 19px; }
.card h3 { font-size: 1rem; letter-spacing: -.012em; margin-bottom: .4rem; }
.card p { font-size: .88rem; line-height: 1.62; color: var(--muted); }

/* ---------- Callout "en criollo" ---------- */
.plain {
  position: relative;
  margin: 1.9rem 0;
  padding: 1.15rem 1.35rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent-3);
  border-radius: 0 14px 14px 0;
  background: linear-gradient(90deg, var(--surface-2), transparent 92%);
}
.plain .mono-label { color: var(--accent-3); margin-bottom: .35rem; }
.plain p:last-child {
  font-size: .94rem;
  line-height: 1.68;
  color: var(--ink-soft);
  max-width: 74ch;
}
.plain--tight { margin: 0; background: var(--bg-2); }

/* ---------- Fórmulas ---------- */
.formula {
  font-family: var(--font-mono);
  font-size: .84rem;
  line-height: 1.7;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 12px 12px 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin-bottom: 1.4rem;
  color: var(--ink);
}
.formula small {
  display: block;
  font-size: .69rem;
  line-height: 1.55;
  color: var(--muted);
  margin-top: .45rem;
}
.formula--compact {
  margin: 1rem 0 0;
  padding: .7rem .85rem;
  font-size: .73rem;
  line-height: 1.6;
  border-radius: 10px;
  border-left-width: 2px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Tablas ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}
.table-wrap table { width: 100%; font-size: .85rem; }
.table-wrap caption {
  caption-side: top;
  text-align: left;
  padding: 1rem 1.15rem;
  font-size: .76rem;
  line-height: 1.5;
  color: var(--faint);
  border-bottom: 1px solid var(--line);
}
.table-wrap th, .table-wrap td {
  padding: .82rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.table-wrap th {
  font-family: var(--font-mono);
  font-size: .63rem;
  font-weight: 500;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}
.table-wrap tbody tr:last-child td { border-bottom: 0; }
.table-wrap tbody tr { transition: background .15s; }
.table-wrap tbody tr:hover { background: var(--accent-soft); }
.table-wrap td { color: var(--ink-soft); vertical-align: middle; }

/* ---------- Filtros ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  margin-bottom: 1rem;
}
.filters button {
  padding: .4rem .75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .77rem;
  font-weight: 500;
  transition: color .2s, background .2s, border-color .2s;
}
.filters button:hover { color: var(--ink); border-color: var(--line-strong); }
.filters button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.filter-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--faint);
}

/* ---------- Diálogo índice ---------- */
dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  width: fit-content;
  height: fit-content;
  max-width: 96vw;
  max-height: 94vh;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}
dialog::backdrop {
  background: rgba(4, 7, 6, .62);
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
}
html[data-theme="light"] dialog::backdrop { background: rgba(30, 40, 34, .38); }
dialog[open] { animation: dialog-in .28s var(--ease); }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(.99); }
}
.dialog-card {
  width: min(940px, 92vw);
  max-height: 86vh;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  padding: clamp(1.3rem, 4vw, 2.2rem);
  box-shadow: 0 50px 140px -50px rgba(0, 0, 0, .85);
}
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.6rem;
}
.dialog-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 1.05;
  margin-top: .25rem;
}
.idx-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 1.5rem;
}
.idx-group h3 {
  font-family: var(--font-mono);
  font-size: .64rem;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: .55rem;
}
.idx-link {
  display: flex;
  align-items: baseline;
  gap: .65rem;
  padding: .42rem 0;
  text-decoration: none;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.35;
  border-bottom: 1px solid transparent;
  transition: color .2s, border-color .2s;
}
.idx-link:hover { color: var(--ink); border-bottom-color: var(--line); }
.idx-num {
  min-width: 1.5rem;
  font-family: var(--font-mono);
  font-size: .64rem;
  color: var(--faint);
}
.dialog-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  margin: 0 0 1.4rem;
  padding: 0 0 1.2rem;
  border-bottom: 1px solid var(--line);
}
.setting { display: flex; align-items: center; gap: .8rem; }
.setting .mono-label { margin: 0; }
.dialog-note {
  flex: 1;
  min-width: 220px;
  font-size: .78rem;
  line-height: 1.55;
  color: var(--faint);
}

/* ---------- Rail ---------- */
.rail {
  position: fixed;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 60;
  display: none;
  flex-direction: column;
  gap: 1px;
}
.rail a {
  position: relative;
  display: flex;
  align-items: center;
  width: 22px;
  height: 20px;
  text-decoration: none;
}
.rail a::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background .2s, width .2s, height .2s, box-shadow .2s;
}
.rail a:hover::before { background: var(--muted); }
.rail a[aria-current="true"]::before {
  width: 7px; height: 7px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.rail-tip {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translate(-5px, -50%);
  padding: .22rem .5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: .68rem;
  font-family: var(--font-mono);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  box-shadow: var(--shadow-soft);
}
.rail a:hover .rail-tip, .rail a:focus-visible .rail-tip {
  opacity: 1;
  transform: translate(0, -50%);
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  padding: clamp(3rem, 7vw, 5rem) var(--gutter) 1.8rem;
}
.footer-inner { max-width: var(--max); margin: 0 auto; }
.footer-top { margin-bottom: 2.5rem; }
.footer-brand {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 7vw, 4.6rem);
  line-height: .95;
  letter-spacing: -.03em;
  color: var(--ink);
}
.footer-brand span { color: var(--accent-text); font-style: italic; }
.footer-tag {
  margin-top: .7rem;
  color: var(--muted);
  font-size: .95rem;
  max-width: 46ch;
}
.footer-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1.6rem;
  padding-top: 1.8rem;
  border-top: 1px solid var(--line);
}
.footer-cols .mono-label { margin-bottom: .6rem; }
.footer-cols a {
  display: block;
  padding: .28rem 0;
  text-decoration: none;
  color: var(--muted);
  font-size: .86rem;
  transition: color .2s;
}
.footer-cols a:hover { color: var(--accent-text); }
.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .6rem;
  margin-top: 2.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--faint);
}
.footer-bottom a { color: var(--muted); text-decoration: none; }
.footer-bottom a:hover { color: var(--accent-text); }

/* ---------- Nivel esencial / técnico ---------- */
html[data-level="esencial"] .tech-only { display: none !important; }
html[data-level="tecnico"] .esencial-only { display: none !important; }
html[data-level="esencial"] .models-table { min-width: 0; }

/* ---------- Reveal ---------- */
.will-reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity .75s var(--ease), transform .75s var(--ease);
}
.will-reveal.is-in { opacity: 1; transform: none; }

/* ---------- Scrollbar ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 99px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .main-nav { display: none; }
  .header-actions { margin-left: auto; }
}
@media (max-width: 860px) {
  :root { --header-h: 64px; }
  .brand-word { font-size: .98rem; }
  .hero { min-height: 92svh; }
  .chapter { padding-top: clamp(3.8rem, 8vw, 6rem); padding-bottom: clamp(3.8rem, 8vw, 6rem); }
  .footer-bottom { flex-direction: column; }
}
@media (max-width: 720px) {
  .header-actions .level-switch { display: none; }
  .header-inner { gap: .55rem; }
  .index-btn span { display: none; }
  .index-btn { width: 38px; padding: 0; }
  .classroom-btn span { display: none; }
  .classroom-btn { width: 38px; padding: 0; }
  .hero h1 { font-size: clamp(3rem, 14vw, 5rem); }
  .hero-lead { font-size: 1rem; }
  .scroll-cue { display: none; }
  .dialog-card { width: 94vw; max-height: 90vh; border-radius: 18px; }
  .dialog-settings { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 520px) {
  :root { --gutter: 1.1rem; }
  .hero { padding-top: 5.8rem; }
  .hero h1 { font-size: clamp(2.75rem, 15.5vw, 4.1rem); }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .hero-actions .btn { width: 100%; }
  .token-stream { font-size: .68rem; }
  .chapter h2 { font-size: clamp(1.95rem, 8.4vw, 2.8rem); }
  .card { padding: 1.1rem; }
  .plain { padding: 1rem 1.1rem; }
  .filter-count { margin-left: 0; width: 100%; }
}
@media (min-width: 1400px) {
  .rail { display: flex; }
}

/* ---------- Accesibilidad de movimiento ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .will-reveal { opacity: 1; transform: none; }
}

/* ---------- Alto contraste ---------- */
@media (prefers-contrast: more) {
  html[data-theme="dark"] { --muted: #C3D2CA; --faint: #A7B8AF; --line: rgba(213, 255, 240, .22); }
  html[data-theme="light"] { --muted: #2F3D35; --faint: #445249; --line: rgba(20, 35, 28, .24); }
  .card, .demo { border-width: 2px; }
}

/* ---------- Impresión ---------- */
@media print {
  body::before, .site-header, .rail, .scroll-cue, #hero-canvas, .hero-glow, .site-footer, .demo-actions, .btn, .filters, .missions-fab, .mission-toast, .classroom-bar, .classroom-notes, .footer-docente, dialog { display: none !important; }
  body { background: #fff; color: #111; }
  .chapter { border-top: 1px solid #ccc; page-break-inside: avoid; padding: 1.5rem 0; }
  .card, .demo, .plain { border: 1px solid #ddd; box-shadow: none; }
  a { text-decoration: underline; }
}
