@charset "UTF-8";
/* ==========================================================================
   TeoriaWeb — tema compartido para apuntes académicos
   Estilo: libro de texto · Tipografía: Source Serif 4 (lectura) + Source Sans 3 (interfaz)
   Estructura: secciones numeradas, entornos tipo teorema, tablas con filetes,
   figuras y tablas numeradas, «Ideas clave» al final de cada lección.
   ========================================================================== */

:root {
  /* Papel y tinta */
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f4f1ea;
  --fg: #1b1d22;
  --fg-muted: #55595f;
  --border: #e3ded3;
  --rule: #1b1d22;

  /* Color de la asignatura (por defecto: burdeos) */
  --primary: #8b1e2f;
  --primary-soft: #f6e9ea;
  --on-primary: #ffffff;
  --ring: #8b1e2f;

  /* Entornos semánticos */
  --accent: #2f6b3f;
  --accent-soft: #eaf2ea;
  --warn: #8f4500;
  --warn-soft: #fbf0e2;
  --danger: #a3222b;
  --danger-soft: #fbeaea;
  --info: #23606c;
  --info-soft: #e6f0f2;

  --shadow: none;
  --shadow-lg: 0 10px 30px -12px rgba(27, 29, 34, .25);

  --font-head: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-body: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-ui: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;

  --radius: 6px;
  --radius-sm: 4px;
  --topbar-h: 56px;
  --sidebar-w: 280px;
  --rail-w: 220px;
  --measure: 70ch;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 180ms;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141518; --surface: #1b1c20; --surface-2: #23252b; --fg: #e8e6e1; --fg-muted: #aaa69e;
    --border: #34363d; --rule: #e8e6e1;
    --primary: #eaa0a8; --primary-soft: #3a1f24; --on-primary: #1b0b0e; --ring: #eaa0a8;
    --accent: #8fcf9c; --accent-soft: #1c2c20; --warn: #f0b36a; --warn-soft: #33260f;
    --danger: #f08c92; --danger-soft: #3a1a1c; --info: #8cc9d4; --info-soft: #142a2e;
    --shadow-lg: 0 10px 30px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141518; --surface: #1b1c20; --surface-2: #23252b; --fg: #e8e6e1; --fg-muted: #aaa69e;
  --border: #34363d; --rule: #e8e6e1;
  --primary: #eaa0a8; --primary-soft: #3a1f24; --on-primary: #1b0b0e; --ring: #eaa0a8;
  --accent: #8fcf9c; --accent-soft: #1c2c20; --warn: #f0b36a; --warn-soft: #33260f;
  --danger: #f08c92; --danger-soft: #3a1a1c; --info: #8cc9d4; --info-soft: #142a2e;
  --shadow-lg: 0 10px 30px -12px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* Paradigmas: azul tinta */
[data-subject="papr"] { --primary: #1f4e8c; --primary-soft: #e8eef7; --ring: #1f4e8c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) [data-subject="papr"] { --primary: #9fbde8; --primary-soft: #1c2a40; --on-primary: #0b1626; --ring: #9fbde8; }
}
:root[data-theme="dark"] [data-subject="papr"] { --primary: #9fbde8; --primary-soft: #1c2a40; --on-primary: #0b1626; --ring: #9fbde8; }

/* Ingeniería del Software: ciruela */
[data-subject="inso"] { --primary: #5b2a86; --primary-soft: #f0e9f6; --ring: #5b2a86; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) [data-subject="inso"] { --primary: #cdaef0; --primary-soft: #2c2140; --on-primary: #1a0f28; --ring: #cdaef0; }
}
:root[data-theme="dark"] [data-subject="inso"] { --primary: #cdaef0; --primary-soft: #2c2140; --on-primary: #1a0f28; --ring: #cdaef0; }

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 24px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 1.125rem; line-height: 1.7;
  font-optical-sizing: auto; min-height: 100dvh; overflow-x: hidden;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; }
a { color: var(--primary); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 3px; }
::selection { background: var(--primary-soft); }
code, kbd { font-family: var(--font-mono); font-size: .84em; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 3px; padding: .05em .3em; }
kbd { font-family: var(--font-ui); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 3px; padding: 0 .4em; background: var(--surface); font-size: .78rem; color: var(--fg-muted); }

h1, h2, h3, h4 { font-family: var(--font-head); color: var(--fg); margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: clamp(2.1rem, 4.6vw, 3rem); font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: clamp(1.7rem, 3.4vw, 2.2rem); font-weight: 700; }
h3 { font-size: clamp(1.35rem, 2.6vw, 1.6rem); }
h4 { font-size: 1.2rem; margin-top: 2.2rem; margin-bottom: .6rem; }
p { margin: 0 0 1rem; hyphens: auto; }
ul, ol { padding-left: 1.4rem; margin: 0 0 1rem; }
li { margin-bottom: .35rem; }
li::marker { color: var(--primary); }
strong { font-weight: 700; }
em { font-style: italic; }

.secnum { font-family: var(--font-ui); font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; margin-right: .5em; }
h4 .secnum { font-size: .9em; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 1000; background: var(--primary); color: var(--on-primary);
  padding: 10px 16px; border-radius: var(--radius-sm); font-family: var(--font-ui); font-weight: 700; text-decoration: none;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ==========================================================================
   Barra superior
   ========================================================================== */
.progress { position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 60; }
.progress span { display: block; height: 100%; width: 100%; background: var(--primary); transform-origin: 0 50%; transform: scaleX(0); }

.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  font-family: var(--font-ui);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-head); font-weight: 700; font-size: 1.15rem; color: var(--fg); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 32px; height: 32px; border-radius: 4px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.brand-mark .icon { width: 18px; height: 18px; }
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--fg-muted); font-size: .9rem; min-width: 0; }
.crumbs a { color: var(--fg-muted); text-decoration: none; }
.crumbs a:hover { color: var(--primary); }
.crumbs .sep { opacity: .5; }
.crumbs .current { color: var(--fg); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--fg); cursor: pointer; touch-action: manipulation;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.menu-btn { display: none; }

/* Buscador */
.search { position: relative; width: min(320px, 36vw); flex: none; }
.search label { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--fg-muted); display: flex; pointer-events: none; }
.search input {
  width: 100%; height: 40px; padding: 0 40px 0 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--fg); font: inherit; font-size: 1rem;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.search input::placeholder { color: var(--fg-muted); }
.search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; width: min(440px, calc(100vw - 32px));
  max-height: min(60vh, 460px); overflow: auto; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.search-results[hidden] { display: none; }
.search-results li { margin: 0; }
.search-results a { display: block; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--fg); text-decoration: none; }
.search-results a:hover, .search-results a[aria-selected="true"] { background: var(--primary-soft); }
.search-results .r-title { font-weight: 700; display: block; }
.search-results .r-path { font-size: .78rem; color: var(--fg-muted); display: block; }
.search-results .r-snip { font-family: var(--font-body); font-size: .9rem; color: var(--fg-muted); display: block; margin-top: 2px; }
.search-results mark { background: color-mix(in srgb, var(--primary) 22%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
.search-results .empty { padding: 12px; color: var(--fg-muted); }

/* ==========================================================================
   Maquetación: índice | texto | margen
   ========================================================================== */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); max-width: 1440px; margin: 0 auto; }
@media (min-width: 1280px) { .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--rail-w); } }

.sidebar {
  position: sticky; top: var(--topbar-h); align-self: start; height: calc(100dvh - var(--topbar-h));
  overflow-y: auto; padding: 24px 12px 40px 16px; border-right: 1px solid var(--border);
  font-family: var(--font-ui); scrollbar-width: thin;
}
.sidebar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 8px 10px; }
.sidebar-head .label { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-muted); }
.sidebar-head .count { font-size: .8rem; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.meter { height: 4px; border-radius: 99px; background: var(--surface-2); margin: 0 8px 18px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 300ms var(--ease); }

.toc, .toc ol { list-style: none; padding: 0; margin: 0; }
.toc > li { margin-bottom: 10px; }
.toc .toc-block {
  display: flex; gap: 10px; align-items: baseline; padding: 6px 8px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: .95rem; line-height: 1.35; color: var(--fg); text-decoration: none;
}
.toc .toc-block .num { flex: none; min-width: 1.4em; color: var(--primary); font-variant-numeric: tabular-nums; }
.toc ol { margin: 2px 0 0 8px; }
.toc ol a {
  display: flex; align-items: baseline; gap: 8px; padding: 5px 8px 5px 10px;
  border-left: 2px solid var(--border); color: var(--fg-muted); font-size: .9rem; line-height: 1.35; text-decoration: none;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.toc ol a .num { flex: none; min-width: 2.2em; font-variant-numeric: tabular-nums; color: var(--fg-muted); }
.toc a:hover { color: var(--fg); background: var(--surface-2); }
.toc a.active { color: var(--primary); border-left-color: var(--primary); font-weight: 700; }
.toc a.active .num { color: var(--primary); }
.toc .toc-block.active { background: var(--primary-soft); }
.toc .done-dot { margin-left: auto; color: var(--accent); flex: none; visibility: hidden; align-self: center; }
.toc .done-dot .icon { width: 15px; height: 15px; }
.toc a.is-done .done-dot { visibility: visible; }

/* Margen derecho: «En esta lección» */
.rail { display: none; }
@media (min-width: 1280px) {
  .rail {
    display: block; position: sticky; top: var(--topbar-h); align-self: start; max-height: calc(100dvh - var(--topbar-h));
    overflow-y: auto; padding: 40px 16px 40px 8px; font-family: var(--font-ui);
  }
}
.rail-title { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-muted); margin: 0 0 8px; }
.rail-lesson { font-size: .88rem; font-weight: 700; color: var(--fg); margin: 0 0 10px; line-height: 1.35; }
.rail ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.rail li { margin: 0; }
.rail a { display: block; padding: 4px 0 4px 12px; margin-left: -1px; border-left: 2px solid transparent; font-size: .84rem; line-height: 1.35; color: var(--fg-muted); text-decoration: none; }
.rail a:hover { color: var(--fg); }
.rail a.active { color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.rail-empty { font-size: .84rem; color: var(--fg-muted); }

.scrim { display: none; }

.content { padding: 48px clamp(16px, 4vw, 64px) 96px; min-width: 0; }
.content > * { max-width: var(--measure); }
.content > .wide { max-width: 980px; }

/* ==========================================================================
   Portada de la unidad
   ========================================================================== */
.hero { padding-bottom: 28px; margin-bottom: 8px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-ui); font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--primary); margin-bottom: 14px; }
.eyebrow .icon { width: 16px; height: 16px; }
.hero h1 { margin-bottom: 16px; max-width: 24ch; }
.lead { font-size: 1.2rem; color: var(--fg-muted); max-width: 62ch; font-style: italic; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 18px; color: var(--fg-muted); font-family: var(--font-ui); font-size: .9rem; }
.meta span { display: inline-flex; align-items: center; gap: 6px; }
.meta .icon { width: 16px; height: 16px; }

/* Índice tipo libro */
.contents { margin-top: 28px; padding-top: 18px; border-top: 2px solid var(--rule); font-family: var(--font-ui); }
.contents-title { font-family: var(--font-head); font-size: 1.3rem; font-weight: 700; margin: 0 0 10px; }
.contents ol { list-style: none; padding: 0; margin: 0; }
.contents > ol > li { margin: 0 0 10px; }
.contents li { margin: 0; }
.contents a { display: flex; align-items: baseline; gap: 10px; color: var(--fg); text-decoration: none; padding: 3px 0; }
.contents a:hover .c-title { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
.contents .c-num { flex: none; min-width: 2.4em; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.contents .c-title { flex: 0 1 auto; }
.contents .c-dots { flex: 1; border-bottom: 1px dotted var(--border); transform: translateY(-4px); min-width: 16px; }
.contents .c-state { flex: none; font-size: .78rem; color: var(--accent); font-weight: 700; }
.contents > ol > li > a { font-weight: 700; font-size: 1.02rem; }
.contents > ol > li > ol { margin-left: 2.4em; }
.contents > ol > li > ol a { font-size: .95rem; color: var(--fg-muted); }

/* ==========================================================================
   Temas y lecciones
   ========================================================================== */
.block { padding-top: 40px; margin-top: 56px; border-top: 2px solid var(--rule); }
.block:first-of-type { margin-top: 0; }
.block-head { display: flex; gap: 20px; align-items: flex-end; margin-bottom: 24px; }
.block-num { font-family: var(--font-head); font-size: 3.6rem; line-height: .9; color: var(--primary); font-weight: 700; font-variant-numeric: lining-nums tabular-nums; }
.block-kicker { font-family: var(--font-ui); font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-muted); margin-bottom: 4px; }

.lesson { padding-top: 40px; }
.lesson-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.lesson-head h3 { flex: 1; }

.done-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; flex: none;
  border: 1px solid var(--border); border-radius: 99px; background: var(--surface); color: var(--fg-muted);
  font-family: var(--font-ui); font-size: .82rem; font-weight: 700; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.done-btn:hover { border-color: var(--accent); color: var(--accent); }
.done-btn .icon { width: 15px; height: 15px; }
.done-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ==========================================================================
   Entornos (tipo teorema): Nota, Concepto clave, Consejo, Atención
   ========================================================================== */
.callout {
  --env: var(--info); --env-soft: var(--info-soft);
  position: relative; margin: 22px 0; padding: 12px 18px 14px;
  background: var(--env-soft); border-left: 3px solid var(--env); border-radius: 0 var(--radius) var(--radius) 0;
}
.callout::before {
  content: "Nota"; display: block; margin-bottom: 4px;
  font-family: var(--font-ui); font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--env);
}
.callout > .icon { display: none; }
.callout p:last-child { margin-bottom: 0; }
.callout-title { display: block; font-weight: 700; margin-bottom: 2px; }
.callout.key { --env: var(--primary); --env-soft: var(--primary-soft); }
.callout.key::before { content: "Concepto clave"; }
.callout.tip { --env: var(--accent); --env-soft: var(--accent-soft); }
.callout.tip::before { content: "Consejo"; }
.callout.warn { --env: var(--warn); --env-soft: var(--warn-soft); }
.callout.warn::before { content: "Atención"; }
.callout.muted { --env: var(--fg-muted); --env-soft: transparent; border-left-style: dashed; color: var(--fg-muted); font-size: .95rem; }
.callout.muted::before { content: "Material original"; }

/* Ideas clave */
.summary {
  margin: 32px 0 8px; padding: 16px 20px 6px; background: var(--surface); border: 1px solid var(--border);
  border-top: 3px solid var(--primary); border-radius: 0 0 var(--radius) var(--radius);
}
.summary-title { display: flex; align-items: center; gap: 8px; font-family: var(--font-ui); font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--primary); margin: 0 0 8px; }
.summary-title .icon { width: 16px; height: 16px; }
.summary ul { list-style: none; padding: 0; }
.summary li { position: relative; padding-left: 1.3em; margin-bottom: .45rem; font-size: 1.02rem; }
.summary li::before { content: ""; position: absolute; left: .15em; top: .62em; width: .45em; height: .45em; background: var(--primary); transform: rotate(45deg); }

/* ==========================================================================
   Componentes
   ========================================================================== */
.grid { display: grid; gap: 12px; margin: 20px 0; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card .ttl { color: var(--fg); font-family: var(--font-ui); font-size: 1rem; font-weight: 700; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.card .ttl .icon { width: 17px; height: 17px; color: var(--primary); }
.card p { margin: 0; color: var(--fg-muted); font-size: .98rem; line-height: 1.55; }
.card .card-icon { width: 32px; height: 32px; border-radius: 4px; display: grid; place-items: center; color: var(--primary); border: 1px solid var(--border); margin-bottom: 10px; }
.card .card-icon .icon { width: 18px; height: 18px; }
.card ul { margin: 6px 0 0; font-size: .98rem; color: var(--fg-muted); }
a.card { display: block; color: inherit; text-decoration: none; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
a.card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); }
.card .tag { display: inline-block; font-family: var(--font-ui); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); margin-bottom: 6px; }

.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin: 20px 0; border-top: 2px solid var(--rule); border-bottom: 2px solid var(--rule); }
.compare > div { padding: 16px 18px 10px; }
.compare > div + div { border-left: 1px solid var(--border); }
.compare .ttl { color: var(--fg); font-family: var(--font-ui); font-weight: 700; font-size: 1.02rem; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.compare .ttl .icon { width: 18px; height: 18px; }
.compare .red .ttl { color: var(--danger); }
.compare .blue .ttl { color: var(--info); }
.compare p, .compare ul { font-size: 1rem; color: var(--fg-muted); }
@media (max-width: 600px) { .compare > div + div { border-left: 0; border-top: 1px solid var(--border); } }

.steps { counter-reset: step; list-style: none; padding: 0; margin: 20px 0; }
.steps > li { counter-increment: step; position: relative; padding: 0 0 16px 48px; margin: 0; }
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: .1em; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; border: 2px solid var(--primary); color: var(--primary);
  font-family: var(--font-ui); font-weight: 700; font-size: .88rem;
}
.steps > li::after { content: ""; position: absolute; left: 15px; top: 36px; bottom: 4px; width: 1px; background: var(--border); }
.steps > li:last-child::after { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; padding: 0; list-style: none; font-family: var(--font-ui); }
.chips li { margin: 0; padding: 3px 10px; border-radius: 3px; border: 1px solid var(--border); background: var(--surface); font-size: .88rem; font-weight: 600; }

/* Tablas con filetes (estilo booktabs) */
.table-wrap { overflow-x: auto; margin: 24px 0; }
table { width: 100%; border-collapse: collapse; font-family: var(--font-ui); font-size: .95rem; border-top: 2px solid var(--rule); border-bottom: 2px solid var(--rule); }
caption { caption-side: top; text-align: left; padding: 0 0 8px; font-size: .9rem; color: var(--fg-muted); }
caption .fig-label, figcaption .fig-label { font-weight: 700; color: var(--fg); }
th, td { text-align: left; padding: 9px 12px; vertical-align: top; }
thead th { font-weight: 700; color: var(--fg); border-bottom: 1px solid var(--rule); font-size: .85rem; }
tbody tr + tr td { border-top: 1px solid var(--border); }
tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 50%, transparent); }
td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }
td:first-child { font-weight: 600; }

.bar { display: flex; align-items: center; gap: 10px; }
.bar i { display: block; height: 8px; background: var(--primary); min-width: 4px; }

/* Figuras */
.diagram { margin: 28px 0; padding: 20px 16px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.diagram figcaption { font-family: var(--font-ui); font-size: .88rem; color: var(--fg-muted); margin-top: 12px; text-align: center; }
.diagram svg { display: block; margin: 0 auto; height: auto; }
.diagram text { font-family: var(--font-ui); }

/* ATT&CK */
.tactics { list-style: none; padding: 0; margin: 20px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; counter-reset: tac; font-family: var(--font-ui); }
.tactics li { counter-increment: tac; margin: 0; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--danger); }
.tactics li::before { content: counter(tac, decimal-leading-zero); display: block; font-size: .72rem; font-weight: 700; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.tactics strong { display: block; font-size: .95rem; }
.tactics span { display: block; font-size: .85rem; color: var(--fg-muted); }

/* Niveles anidados (IG / ASVS) */
.levels { margin: 20px 0; font-family: var(--font-ui); }
.levels > div { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--primary-soft); }
.levels > div > div { margin-top: 10px; }
.levels .lv { display: flex; gap: 10px; align-items: baseline; }
.levels .lv b { color: var(--primary); white-space: nowrap; }
.levels .lv span { color: var(--fg-muted); font-size: .95rem; }
.levels .l2 { background: var(--surface-2); padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.levels .l2 > div:last-child { background: var(--surface); padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* Pipeline */
.pipeline { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 20px 0; font-family: var(--font-ui); }
.pipeline li { flex: 1 1 140px; margin: 0; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pipeline li b { display: block; color: var(--accent); font-size: .95rem; }
.pipeline li span { font-size: .85rem; color: var(--fg-muted); }

pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; font-size: .88rem; line-height: 1.55; }
pre code { background: none; border: 0; padding: 0; }

/* Repaso */
.qa { margin: 20px 0; display: grid; gap: 0; border-top: 2px solid var(--rule); border-bottom: 2px solid var(--rule); counter-reset: qa; }
.qa details { border-bottom: 1px solid var(--border); counter-increment: qa; }
.qa details:last-child { border-bottom: 0; }
.qa summary { list-style: none; cursor: pointer; padding: 12px 44px 12px 2.6em; font-weight: 600; position: relative; min-height: 44px; }
.qa summary::-webkit-details-marker { display: none; }
.qa summary::before { content: counter(qa) "."; position: absolute; left: 0; width: 2em; text-align: right; font-family: var(--font-ui); font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.qa summary::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--fg-muted); border-bottom: 2px solid var(--fg-muted); transform: rotate(45deg); transition: transform var(--dur) var(--ease);
}
.qa details[open] summary::after { transform: rotate(-135deg); margin-top: -2px; }
.qa details[open] summary { color: var(--primary); }
.qa .answer { padding: 0 16px 14px 2.6em; color: var(--fg-muted); }
.qa .answer p:last-child { margin: 0; }

.collapsible { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin: 20px 0; }
.collapsible summary { cursor: pointer; padding: 12px 16px; font-family: var(--font-ui); font-weight: 700; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.collapsible > div { padding: 0 18px 8px; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 64px; padding-top: 20px; border-top: 2px solid var(--rule); font-family: var(--font-ui); }
.pager a { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); text-decoration: none; font-weight: 700; background: var(--surface); }
.pager a:hover { border-color: var(--primary); }

.to-top {
  position: fixed; right: 16px; bottom: 16px; z-index: 40; width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--fg); box-shadow: var(--shadow-lg);
  display: grid; place-items: center; cursor: pointer; opacity: 0; pointer-events: none;
  transform: translateY(8px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.to-top.show { opacity: 1; pointer-events: auto; transform: none; }
.footer { color: var(--fg-muted); font-family: var(--font-ui); font-size: .85rem; margin-top: 40px; }

/* ==========================================================================
   Índices de asignatura y portada
   ========================================================================== */
.units { list-style: none; padding: 0; margin: 24px 0; border-top: 2px solid var(--rule); }
.units li { margin: 0; border-bottom: 1px solid var(--border); }
.units .card { display: flex; gap: 18px; align-items: flex-start; border: 0; border-radius: 0; background: transparent; padding: 18px 4px; }
.units a.card:hover { box-shadow: none; background: var(--surface); }
.units .card .ttl { font-family: var(--font-head); font-size: 1.35rem; font-weight: 600; margin-bottom: 4px; }
.units .u-num { font-family: var(--font-head); font-size: 2.2rem; line-height: 1; font-weight: 700; color: var(--primary); min-width: 1.4ch; }
.units .soon { opacity: .6; }
.units .soon .u-num { color: var(--fg-muted); }
.units .progress-line { font-family: var(--font-ui); font-size: .82rem; color: var(--accent); font-weight: 700; margin-top: 8px; display: inline-flex; align-items: center; gap: 6px; }
.units .progress-line[hidden] { display: none; }
.units .progress-line .icon { width: 15px; height: 15px; }

.subjects { list-style: none; padding: 0; margin: 24px 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.subjects li { margin: 0; }
.subjects .card { height: 100%; border-top: 3px solid var(--primary); }
.subjects .sub-mark { width: 40px; height: 40px; border-radius: 4px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); margin-bottom: 12px; }
.subjects .card .ttl { font-family: var(--font-head); font-size: 1.4rem; font-weight: 600; }
.subjects .units-line { display: block; margin-top: 10px; font-family: var(--font-ui); font-size: .85rem; color: var(--fg-muted); }

/* ==========================================================================
   Bloques de código (estilo IDE en ambos temas)
   ========================================================================== */
:root { --code-bg: #0f172a; --code-head: #1a2338; --code-fg: #e2e8f0; --code-muted: #a5b4cb; --code-border: #1f2a44; }
.code { margin: 16px 0; border-radius: var(--radius); background: var(--code-bg); border: 1px solid var(--code-border); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 38px; padding: 0 4px 0 14px; background: var(--code-head); border-bottom: 1px solid var(--code-border); }
.code-lang { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .04em; color: var(--code-muted); text-transform: uppercase; }
.code-copy {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--code-muted); font-family: var(--font-ui); font-size: .8rem; font-weight: 700; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.code-copy:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.code-copy .icon { width: 15px; height: 15px; }
.code-copy.copied { color: #4ade80; }
.code pre { margin: 0; border: 0; border-radius: 0; background: transparent; color: var(--code-fg); padding: 14px 16px; tab-size: 4; -moz-tab-size: 4; }
.code pre code { color: inherit; font-family: var(--font-mono); font-size: .88rem; }
.code.output { background: var(--surface-2); border-color: var(--border); }
.code.output .code-head { background: transparent; border-bottom-color: var(--border); }
.code.output .code-lang { color: var(--fg-muted); }
.code.output pre { color: var(--fg); }
.code.output .code-copy { display: none; }
.code.error pre { color: var(--danger); }

.token.comment, .token.prolog, .token.doctype, .token.cdata { color: #8b9bb4; font-style: italic; }
.token.punctuation { color: #a5b4cb; }
.token.keyword, .token.boolean, .token.important, .token.atrule { color: #c4a7ff; }
.token.string, .token.char, .token.attr-value, .token.triple-quoted-string { color: #86efac; }
.token.number, .token.constant { color: #fbbf24; }
.token.function, .token.class-name { color: #7dd3fc; }
.token.builtin, .token.variable, .token.parameter { color: #f9a8d4; }
.token.operator, .token.entity, .token.url { color: #e2e8f0; }
.token.decorator, .token.annotation { color: #fda4af; }

/* Pestañas */
.tabs { margin: 16px 0; }
.tablist { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border); font-family: var(--font-ui); }
.tablist [role="tab"] {
  min-height: 42px; padding: 0 14px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  background: transparent; color: var(--fg-muted); font: inherit; font-size: .92rem; font-weight: 700; cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tablist [role="tab"]:hover { color: var(--fg); }
.tablist [role="tab"][aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tabs [role="tabpanel"] > .code:first-child { margin-top: 12px; }

/* Ejercicios */
.exercise { margin: 28px 0; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; background: var(--surface); padding: 14px 18px; }
.exercise > .ex-label { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-ui); font-size: .74rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.exercise > .ex-label .icon { width: 15px; height: 15px; }
.exercise .ttl { font-weight: 700; font-size: 1.08rem; margin: 0 0 8px; }
.exercise ol, .exercise ul { margin-bottom: .5rem; }
.exercise details { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 4px; }
.exercise summary { cursor: pointer; font-family: var(--font-ui); font-weight: 700; color: var(--primary); min-height: 44px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.exercise summary .badge { font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 8px; border-radius: 3px; background: var(--warn-soft); color: var(--warn); }
.exercise summary .badge.ok { background: var(--accent-soft); color: var(--accent); }

/* Flujos de datos (map / filter / reduce) */
.flow { margin: 20px 0; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); display: grid; gap: 10px; }
.flow-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.flow-label { width: 100%; font-family: var(--font-ui); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-muted); }
.tok { font-family: var(--font-mono); font-size: .86rem; padding: 3px 9px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); }
.tok.out { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.tok.drop { text-decoration: line-through; opacity: .6; }
.flow-op { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: .84rem; color: var(--accent); font-weight: 600; }
.flow-op .icon { width: 18px; height: 18px; }

/* Matriz de lenguajes */
.matrix th, .matrix td { text-align: center; padding: 9px 8px; }
.matrix th:first-child, .matrix td:first-child { text-align: left; padding-left: 12px; }
.matrix thead th { white-space: normal; font-size: .72rem; line-height: 1.25; vertical-align: bottom; }
.mk { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: .78rem; font-weight: 700; }
.mk.yes { background: var(--accent); color: var(--surface); }
.mk.part { border: 2px solid var(--accent); color: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-family: var(--font-ui); font-size: .85rem; color: var(--fg-muted); margin: 0 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Fichas de paradigma */
.pcard dl { margin: 10px 0 0; display: grid; gap: 8px; font-size: .95rem; }
.pcard dt { font-family: var(--font-ui); font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-muted); }
.pcard dd { margin: 0; }
.card.pcard .ttl { font-family: var(--font-head); font-size: 1.2rem; font-weight: 600; }


/* ==========================================================================
   Citas y definiciones de autor, cronología y calculadoras
   ========================================================================== */
blockquote { margin: 22px 0; padding: 4px 0 4px 22px; border-left: 2px solid var(--primary); }
blockquote p { font-style: italic; font-size: 1.12rem; margin-bottom: .5rem; }
blockquote footer, blockquote cite { display: block; font-family: var(--font-ui); font-style: normal; font-size: .88rem; color: var(--fg-muted); }
blockquote footer::before { content: "— "; }
blockquote.epigraph { border-left: 0; padding-left: 0; text-align: center; max-width: 52ch; margin: 28px auto; }
blockquote.epigraph p { font-size: 1.2rem; }

.timeline { list-style: none; margin: 22px 0; padding: 0 0 0 0; position: relative; font-family: var(--font-ui); }
.timeline::before { content: ""; position: absolute; left: 4.6em; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; display: grid; grid-template-columns: 4.2em 1fr; gap: 1.4em; margin: 0 0 12px; align-items: baseline; }
.timeline li::before { content: ""; position: absolute; left: calc(4.6em - 4px); top: .45em; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline .year { font-weight: 700; color: var(--primary); text-align: right; font-variant-numeric: tabular-nums; }
.timeline .ev { font-size: .98rem; }

.calc { margin: 24px 0; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-family: var(--font-ui); }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.calc fieldset { margin: 0; padding: 12px 14px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.calc legend { padding: 0 6px; font-weight: 700; color: var(--primary); }
.calc label { display: block; font-size: .85rem; font-weight: 600; color: var(--fg-muted); margin: 10px 0 4px; }
.calc input { width: 100%; height: 44px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); font: inherit; font-size: 1rem; font-variant-numeric: tabular-nums; }
.calc input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.calc .help { font-size: .8rem; color: var(--fg-muted); margin-top: 4px; }
.calc-out { margin-top: 16px; }
.calc-verdict { font-size: 1rem; margin: 0 0 8px; }
.calc-verdict strong { color: var(--primary); }
.calc table { font-size: .9rem; }
.calc td.win { color: var(--accent); font-weight: 700; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1023px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-grid; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100dvh; width: min(320px, 86vw); z-index: 80;
    background: var(--bg); border-right: 1px solid var(--border); box-shadow: var(--shadow-lg);
    transform: translateX(-102%); transition: transform 260ms var(--ease); padding-top: 20px; visibility: hidden;
  }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 70; background: rgba(8, 6, 16, .5); opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .crumbs .hide-sm { display: none; }
}
@media (max-width: 720px) {
  body { font-size: 1.0625rem; }
  .topbar-spacer { display: none; }
  .search { width: auto; flex: 1; }
  .search kbd { display: none; }
  .search input { padding-right: 12px; }
  .brand-text, .crumbs { display: none; }
  .lesson-head { flex-direction: column; gap: 10px; }
  .block-num { font-size: 2.6rem; }
  .content { padding-top: 28px; }
  .diagram-scroll svg { min-width: 500px; }
  .contents > ol > li > ol { margin-left: 1.2em; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

@media print {
  .topbar, .sidebar, .rail, .progress, .to-top, .done-btn, .scrim, .code-copy, .pager { display: none !important; }
  .layout { display: block; }
  .content > * { max-width: none; }
  body { font-size: 11pt; background: #fff; }
  .block { break-before: page; }
  .qa details, .callout, .summary, .exercise, figure, table { break-inside: avoid; }
  .qa details { display: block; }
  .qa details > .answer { display: block; }
}
