/* ==========================================================================
   Markdown: guía completa — hoja de estilos
   Temas claro/oscuro, accesibilidad, legibilidad y animaciones discretas.
   --------------------------------------------------------------------------
   Índice:
     1. Tokens de diseño (temas)
     2. Reset y base
     3. Estructura: cabecera, barra lateral y contenido
     4. Navegación y migas
     5. Tipografía del contenido
     6. Listas, citas y tablas
     7. Código y resaltado
     8. Diagramas y medios
     9. Navegación entre capítulos y pie
    10. Utilidades, estados y animaciones
    11. Preferencias del usuario y adaptación
   ========================================================================== */

/* 1. Tokens de diseño ------------------------------------------------------ */
:root {
  color-scheme: light;

  --bg: #fbfaf8;
  --bg-alt: #f2efe9;
  --surface: #ffffff;
  --text: #191817;
  --muted: #56514a;
  --border: #ddd7cc;
  --accent: #0b5cab;
  --accent-hover: #084583;
  --on-accent: #ffffff;
  --accent-soft: #e8f0fb;
  --code-bg: #f4f1ea;
  --code-border: #e2dcd0;
  --focus: #9a3d00;
  --shadow: 0 1px 2px rgba(25, 24, 23, .06), 0 10px 30px rgba(25, 24, 23, .07);

  --wrap: 64rem;
  --header-h: 3.5rem;
  --sidebar-w: 19rem;
  --content-w: 52rem;
  --sidebar-bg: #f5f2ec;
  --radius: .7rem;
  --radius-sm: .45rem;
  --step: 1rem;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

/* Tema oscuro explícito (botón) */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #111318;
  --bg-alt: #171a21;
  --surface: #191d25;
  --text: #eae8e3;
  --muted: #aaa59c;
  --border: #2b3039;
  --accent: #93c2ff;
  --accent-hover: #b7d6ff;
  --on-accent: #0a1420;
  --accent-soft: #16233a;
  --code-bg: #1a1e27;
  --code-border: #262c36;
  --focus: #ffb457;
  --sidebar-bg: #0d0f14;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px rgba(0, 0, 0, .45);
}

/* Tema oscuro del sistema (cuando no hay elección guardada / sin JS) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #111318;
    --bg-alt: #171a21;
    --surface: #191d25;
    --text: #eae8e3;
    --muted: #aaa59c;
    --border: #2b3039;
    --accent: #93c2ff;
    --accent-hover: #b7d6ff;
    --on-accent: #0a1420;
    --accent-soft: #16233a;
    --code-bg: #1a1e27;
    --code-border: #262c36;
    --focus: #ffb457;
    --sidebar-bg: #0d0f14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px rgba(0, 0, 0, .45);
  }
}

/* 2. Reset y base ---------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: clamp(1rem, .96rem + .18vw, 1.075rem);
  line-height: 1.72;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

::selection {
  background-color: var(--accent);
  color: var(--on-accent);
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: .08em;
  text-underline-offset: .18em;
  transition: color .15s ease, text-decoration-color .15s ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration-thickness: .14em;
}

:where(a, button, summary, input, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: .2rem;
}

/* 3. Estructura: cabecera, barra lateral y contenido ------------------------ */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  align-items: start;
  min-height: calc(100vh - var(--header-h));
}

.page {
  display: flex;
  min-width: 0;
  min-height: calc(100vh - var(--header-h));
  flex-direction: column;
}

.main {
  flex: 1 1 auto;
  padding-block: 2rem 3.5rem;
}

.main:focus {
  outline: none;
}

.page__inner {
  width: min(100% - 3rem, var(--content-w));
  margin-inline: auto;
}

.skip-link {
  position: absolute;
  top: -4rem;
  left: 1rem;
  z-index: 60;
  padding: .65rem 1rem;
  border-radius: var(--radius-sm);
  background-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  transition: top .18s ease;
}

.skip-link:focus {
  top: .75rem;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background-color: var(--bg);
  background-color: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: .85rem;
  height: 100%;
  padding-inline: clamp(.7rem, 1.6vw, 1.15rem);
}

.brand {
  display: inline-flex;
  min-width: 0;
  margin-inline-end: auto;
  align-items: center;
  gap: .55rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -.01em;
  text-decoration: none;
}

.brand:hover {
  color: var(--text);
}

.brand__mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: .5rem;
  background-color: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
}

.brand__text {
  overflow: hidden;
  font-size: .97rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Botón de menú: solo con JavaScript y en pantallas estrechas. */
.menu-toggle {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 2.3rem;
  height: 2.3rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease;
}

.menu-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.menu-toggle__bars {
  display: grid;
  gap: 3px;
  width: 1rem;
}

.menu-toggle__bars span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background-color: currentColor;
}

/* Barra lateral con el índice completo. */
.sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border);
  background-color: var(--sidebar-bg);
  scrollbar-color: var(--border) transparent;
  scrollbar-width: thin;
}

.sidebar__inner {
  padding: 0 .65rem 2.25rem;
}

/* Cabecera y filtro fijos mientras se recorre el índice. */
.sidebar__top {
  position: sticky;
  top: 0;
  z-index: 3;
  padding-top: .95rem;
  border-bottom: 1px solid var(--border);
  background-color: var(--sidebar-bg);
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding-inline: .5rem;
}

.sidebar__title {
  margin: 0;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.sidebar__close {
  display: none;
  padding: .2rem .4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
  line-height: 1.2;
  cursor: pointer;
}

.sidebar__close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar__search {
  display: none;
  margin: .8rem .5rem .35rem;
}

.js .sidebar__search {
  display: block;
}

.sidebar__input {
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
}

.sidebar__input::placeholder {
  color: var(--muted);
}

.sidebar__status {
  margin: 0 .5rem;
  color: var(--muted);
  font-size: .74rem;
  line-height: 1.4;
}

.sidebar__status:empty {
  display: none;
}

.sidebar__empty {
  margin: .9rem .65rem;
  color: var(--muted);
  font-size: .85rem;
}

/* Índice: capítulos y secciones. */
.toc__list,
.toc__sections {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc__list {
  margin-top: .45rem;
}

.toc__item {
  margin: .08rem 0;
}

.toc__row {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-sm);
}

.toc__link {
  flex: 1 1 auto;
  min-width: 0;
  padding: .38rem .45rem .38rem .65rem;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
  font-size: .875rem;
  line-height: 1.38;
  text-decoration: none;
  overflow-wrap: break-word;
  transition: background-color .14s ease, color .14s ease,
    border-color .14s ease;
}

.toc__link:hover {
  background-color: var(--accent-soft);
  color: var(--accent);
}

.toc__item.is-current > .toc__row .toc__link {
  border-left-color: var(--accent);
  background-color: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.toc__toggle {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.js .toc__toggle {
  display: inline-flex;
}

.toc__toggle:hover {
  background-color: var(--accent-soft);
  color: var(--accent);
}

.toc__chevron {
  display: block;
  width: .42rem;
  height: .42rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .18s ease;
}

.toc__item.is-open > .toc__row .toc__chevron {
  transform: rotate(45deg);
}

.toc__sections {
  margin: .1rem 0 .35rem;
}

.toc__section-link {
  display: block;
  padding: .3rem .45rem .3rem 1.5rem;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.38;
  text-decoration: none;
  overflow-wrap: break-word;
  transition: background-color .14s ease, color .14s ease;
}

.toc__section-link:hover {
  background-color: var(--accent-soft);
  color: var(--accent);
}

/* Sin JavaScript, todas las secciones permanecen visibles. */
.js .toc__sections {
  display: none;
}

.js .toc__item.is-open > .toc__sections {
  display: block;
}

.toc__item[hidden],
.toc__sections li[hidden] {
  display: none;
}

/* 4. Navegación y migas ---------------------------------------------------- */
.site-nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  font-size: .93rem;
}

.site-nav > a {
  color: var(--text);
  text-decoration: none;
  padding-block: .25rem;
  border-bottom: 2px solid transparent;
  transition: border-color .18s ease, color .18s ease;
}

.site-nav > a:hover {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.theme-toggle {
  display: none;
  align-items: center;
  gap: .45rem;
  padding: .38rem .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .88rem;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease,
    transform .18s ease;
}

.js .theme-toggle {
  display: inline-flex;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-toggle:active {
  transform: scale(.97);
}

.theme-toggle__icon {
  font-size: 1rem;
  line-height: 1;
  transition: transform .35s ease;
}

.theme-toggle:hover .theme-toggle__icon {
  transform: rotate(-18deg);
}

.breadcrumb {
  margin: 0 0 1.1rem;
  font-size: .86rem;
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.breadcrumb li + li::before {
  content: "›";
  margin-right: .5rem;
  color: var(--muted);
}

.breadcrumb a {
  color: var(--muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* 5. Tipografía del contenido ---------------------------------------------- */
.content {
  max-width: 100%;
}

.content :is(h1, h2, h3, h4, h5, h6) {
  max-width: 46ch;
  margin: 2.2em 0 .6em;
  line-height: 1.22;
  letter-spacing: -.015em;
  text-wrap: balance;
  scroll-margin-top: calc(var(--header-h) + 1.5rem);
}

.content h1 {
  margin-top: .4em;
  font-size: clamp(1.85rem, 1.45rem + 1.8vw, 2.6rem);
  letter-spacing: -.03em;
}

.content h2 {
  padding-top: .2em;
  font-size: clamp(1.4rem, 1.2rem + .9vw, 1.75rem);
}

.content h3 {
  font-size: 1.22rem;
}

.content h4 {
  font-size: 1.06rem;
}

.content :is(h2, h3) {
  border-bottom: 1px solid transparent;
}

.content :is(p, ul, ol, dl, details, figure, table, blockquote) {
  margin-block: 1.1rem;
}

.content :is(p, ul, ol, dl, blockquote, details, figure) {
  max-width: 70ch;
}

.content p {
  text-wrap: pretty;
}

.content strong {
  font-weight: 650;
}

.content abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

.content sup,
.content sub {
  line-height: 0;
}

.content hr {
  height: 1px;
  margin: 3rem 0;
  border: 0;
  background-color: var(--border);
}

/* 6. Listas, citas y tablas ------------------------------------------------ */
.content ul,
.content ol {
  padding-left: 1.4em;
}

.content li + li {
  margin-top: .35em;
}

.content li > ul,
.content li > ol {
  margin-block: .35em;
}

.content blockquote {
  margin-inline: 0;
  padding: .2rem 0 .2rem 1.15rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  background-color: transparent;
}

.content blockquote > :first-child {
  margin-top: 0;
}

.content blockquote > :last-child {
  margin-bottom: 0;
}

.content details {
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
}

.content summary {
  cursor: pointer;
  font-weight: 600;
}

.content summary:hover {
  color: var(--accent);
}

.content details[open] summary {
  margin-bottom: .6rem;
}

.content input[type="checkbox"] {
  width: 1em;
  height: 1em;
  margin-right: .5em;
  accent-color: var(--accent);
  vertical-align: -.1em;
}

.content li:has(> input[type="checkbox"]) {
  list-style: none;
  margin-left: -1.3em;
}

/* Tablas: contenedor con desplazamiento creado por js/app.js */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
}

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

.content table {
  width: 100%;
  border-collapse: collapse;
  font-size: .93rem;
  line-height: 1.55;
}

.content th,
.content td {
  padding: .58rem .75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: break-word;
}

.content thead th {
  background-color: var(--bg-alt);
  font-weight: 650;
  white-space: nowrap;
}

.content tbody tr:last-child td {
  border-bottom: 0;
}

.content tbody tr:hover td {
  background-color: var(--accent-soft);
}

/* 7. Código y resaltado ---------------------------------------------------- */
.content code,
.content kbd,
.content samp {
  font-family: var(--font-mono);
  font-size: .88em;
}

.content :not(pre) > code {
  padding: .12em .38em;
  border: 1px solid var(--code-border);
  border-radius: .35rem;
  background-color: var(--code-bg);
  overflow-wrap: break-word;
}

.content pre {
  max-width: 100%;
  margin-block: 1.2rem;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  background-color: var(--code-bg);
  font-size: .9rem;
  line-height: 1.55;
  tab-size: 2;
}

.content pre code {
  font-size: inherit;
  background: none;
  border: 0;
  padding: 0;
}

.content kbd {
  padding: .1em .4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: .3rem;
  background-color: var(--surface);
  font-size: .82em;
}

/* Envoltura que genera Rouge (kramdown) */
.highlighter-rouge {
  margin-block: 1.2rem;
}

.highlighter-rouge .highlight {
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  background-color: var(--code-bg);
  overflow-x: auto;
}

.highlighter-rouge pre {
  margin: 0;
  border: 0;
}

/* Colores de resaltado (compatibles con ambos temas) */
.highlight .c,
.highlight .c1,
.highlight .cm,
.highlight .cs {
  color: var(--muted);
  font-style: italic;
}

.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kr,
.highlight .kt {
  color: var(--accent);
  font-weight: 600;
}

.highlight .s,
.highlight .s1,
.highlight .s2,
.highlight .sb,
.highlight .sc,
.highlight .sd,
.highlight .se,
.highlight .si,
.highlight .sr,
.highlight .ss {
  color: #1c7a4a;
}

.highlight .m,
.highlight .mi,
.highlight .mf,
.highlight .mh,
.highlight .il {
  color: #a35400;
}

.highlight .nf,
.highlight .fm,
.highlight .nc,
.highlight .nn {
  color: #7b3fa0;
}

.highlight .na,
.highlight .nb,
.highlight .nt {
  color: #0a6b73;
}

.highlight .o,
.highlight .p {
  color: var(--text);
}

.highlight .gd {
  color: #b3261e;
}

.highlight .gi {
  color: #1c7a4a;
}

.highlight .gh,
.highlight .gu {
  color: var(--muted);
  font-weight: 600;
}

:root[data-theme="dark"] .highlight .s,
:root[data-theme="dark"] .highlight .s1,
:root[data-theme="dark"] .highlight .s2,
:root[data-theme="dark"] .highlight .sb,
:root[data-theme="dark"] .highlight .sc,
:root[data-theme="dark"] .highlight .sd,
:root[data-theme="dark"] .highlight .se,
:root[data-theme="dark"] .highlight .si,
:root[data-theme="dark"] .highlight .sr,
:root[data-theme="dark"] .highlight .ss,
:root[data-theme="dark"] .highlight .gi {
  color: #7fd39b;
}

:root[data-theme="dark"] .highlight .m,
:root[data-theme="dark"] .highlight .mi,
:root[data-theme="dark"] .highlight .mf,
:root[data-theme="dark"] .highlight .mh,
:root[data-theme="dark"] .highlight .il {
  color: #f0b072;
}

:root[data-theme="dark"] .highlight .nf,
:root[data-theme="dark"] .highlight .fm,
:root[data-theme="dark"] .highlight .nc,
:root[data-theme="dark"] .highlight .nn {
  color: #d2a8ff;
}

:root[data-theme="dark"] .highlight .na,
:root[data-theme="dark"] .highlight .nb,
:root[data-theme="dark"] .highlight .nt {
  color: #7ad4dc;
}

:root[data-theme="dark"] .highlight .gd {
  color: #ff8a80;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .highlight .s,
  :root:not([data-theme="light"]) .highlight .s1,
  :root:not([data-theme="light"]) .highlight .s2,
  :root:not([data-theme="light"]) .highlight .sb,
  :root:not([data-theme="light"]) .highlight .sc,
  :root:not([data-theme="light"]) .highlight .sd,
  :root:not([data-theme="light"]) .highlight .se,
  :root:not([data-theme="light"]) .highlight .si,
  :root:not([data-theme="light"]) .highlight .sr,
  :root:not([data-theme="light"]) .highlight .ss,
  :root:not([data-theme="light"]) .highlight .gi {
    color: #7fd39b;
  }

  :root:not([data-theme="light"]) .highlight .m,
  :root:not([data-theme="light"]) .highlight .mi,
  :root:not([data-theme="light"]) .highlight .mf,
  :root:not([data-theme="light"]) .highlight .mh,
  :root:not([data-theme="light"]) .highlight .il {
    color: #f0b072;
  }

  :root:not([data-theme="light"]) .highlight .nf,
  :root:not([data-theme="light"]) .highlight .fm,
  :root:not([data-theme="light"]) .highlight .nc,
  :root:not([data-theme="light"]) .highlight .nn {
    color: #d2a8ff;
  }

  :root:not([data-theme="light"]) .highlight .na,
  :root:not([data-theme="light"]) .highlight .nb,
  :root:not([data-theme="light"]) .highlight .nt {
    color: #7ad4dc;
  }

  :root:not([data-theme="light"]) .highlight .gd {
    color: #ff8a80;
  }
}

/* 8. Diagramas y medios ---------------------------------------------------- */
.content .mermaid {
  display: flex;
  justify-content: center;
  margin-block: 1.5rem;
  padding: 1rem .5rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
}

.content .mermaid svg {
  max-width: 100%;
  height: auto;
}

.content figure {
  margin-inline: 0;
}

.content figcaption {
  margin-top: .5rem;
  color: var(--muted);
  font-size: .88rem;
}

.content img {
  border-radius: var(--radius-sm);
}

/* 9. Navegación entre capítulos y pie -------------------------------------- */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.pager__link {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: .9rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.pager__link:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  color: var(--text);
}

.pager__link--next {
  grid-column: 2;
  text-align: right;
}

.pager__label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.pager__title {
  font-weight: 600;
  line-height: 1.35;
}

.site-footer {
  border-top: 1px solid var(--border);
  background-color: var(--bg-alt);
  color: var(--muted);
  font-size: .89rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .35rem 1.5rem;
  width: min(100% - 3rem, var(--content-w));
  margin-inline: auto;
  padding-block: 1.75rem;
}

.site-footer p {
  margin: 0;
}

/* Portada: rejilla compacta de los 60 capítulos. */
.content .chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: .55rem;
  max-width: none;
  margin: 1.4rem 0 2rem;
  padding: 0;
  list-style: none;
}

.content .chapter-grid li {
  margin: 0;
}

.chapter-grid a {
  display: flex;
  height: 100%;
  align-items: baseline;
  gap: .6rem;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: .9rem;
  line-height: 1.38;
  text-decoration: none;
  transition: border-color .16s ease, color .16s ease,
    transform .16s ease, box-shadow .16s ease;
}

.chapter-grid a:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.chapter-grid__num {
  flex: none;
  min-width: 1.8ch;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .78rem;
  text-align: right;
}

/* 10. Utilidades, estados y animaciones ------------------------------------ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:target {
  animation: target-fade 1.4s ease-out 1;
}

@keyframes target-fade {
  from {
    background-color: var(--accent-soft);
    box-shadow: 0 0 0 .4rem var(--accent-soft);
  }

  to {
    background-color: transparent;
    box-shadow: 0 0 0 .4rem transparent;
  }
}

/* 11. Preferencias del usuario y adaptación -------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }

  .content {
    animation: rise .35s ease-out both;
  }

  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(8px);
    }

    to {
      opacity: 1;
      transform: none;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 64rem) {
  .shell {
    display: block;
    min-height: 0;
  }

  .page {
    min-height: 0;
  }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    z-index: 45;
    width: min(21rem, 86vw);
    height: auto;
    align-self: auto;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }

  .menu-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform .22s ease, visibility 0s linear;
  }

  .menu-open {
    overflow: hidden;
  }

  .sidebar__close {
    display: inline-flex;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: var(--header-h) 0 0;
    z-index: 40;
    display: none;
    background-color: rgba(10, 12, 16, .5);
    backdrop-filter: blur(1px);
  }

  .sidebar-backdrop:not([hidden]) {
    display: block;
  }

  .js .menu-toggle {
    display: inline-flex;
  }

  /* Sin JavaScript no hay cajón: el índice queda sobre el contenido. */
  html:not(.js) .sidebar {
    position: static;
    width: auto;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    transform: none;
    visibility: visible;
  }
}

@media (max-width: 46rem) {
  .header-inner {
    gap: .6rem;
    padding-inline: .7rem;
  }

  .brand {
    gap: .45rem;
  }

  .brand__text {
    font-size: .88rem;
  }

  .site-nav {
    gap: .7rem;
  }

  .page__inner,
  .footer-inner {
    width: min(100% - 1.75rem, var(--content-w));
  }

  .main {
    padding-block: 1.5rem 2.5rem;
  }

  .content h1 {
    font-size: 1.7rem;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager__link--next {
    grid-column: 1;
    text-align: left;
  }

  .content table {
    font-size: .88rem;
  }

  .content .chapter-grid {
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  }
}

@media (max-width: 30rem) {
  .site-nav > a {
    display: none;
  }

  .theme-toggle__text {
    display: none;
  }

  .theme-toggle {
    padding: .45rem .6rem;
  }

  .content .chapter-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-contrast: more) {
  :root {
    --border: #8a8478;
    --muted: #3d3934;
  }

  :root[data-theme="dark"] {
    --border: #6b7280;
    --muted: #cfcac2;
  }

  .content :not(pre) > code {
    border-color: var(--muted);
  }
}

@media print {
  .site-header,
  .site-footer,
  .sidebar,
  .sidebar-backdrop,
  .menu-toggle,
  .pager,
  .breadcrumb,
  .skip-link,
  .theme-toggle {
    display: none !important;
  }

  .shell {
    display: block;
  }

  .page__inner,
  .footer-inner {
    width: auto;
    max-width: none;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .content a {
    color: #000;
    text-decoration: underline;
  }

  .content pre,
  .content .table-wrap {
    border: 1px solid #999;
    break-inside: avoid;
  }

  .content h1,
  .content h2,
  .content h3 {
    break-after: avoid;
  }
}
