/* ==========================================================================
   Cowpedia · tema sobre Zensical
   Valores tomados de las maquetas R3 y de la especificación COWPEDIA_DISENO.md.
   Los colores por bloque se definen en comun.yml (extra.estilo_bloques).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
/* Paleta de GitHub (Primer), temas «Light default» y «Dark default». */
:root,
[data-md-color-scheme="default"] {
  --cw-bg: #FFFFFF;
  --cw-header-bg: #F6F8FA;   /* barra superior */
  --cw-sub: #F6F8FA;
  --cw-panel: #FFFFFF;
  --cw-border: #D1D9E0;
  --cw-text: #1F2328;
  --cw-lead: #1F2328;
  --cw-muted: #59636E;
  --cw-faint: #59636E;
  --cw-accent: #0969DA;
  --cw-accent-soft: #DDF4FF;
  --cw-chip-bg: #E6EAEF;
  --cw-chip-on: #FFFFFF;
  --cw-warn: #D1242F;
  --cw-warn-bg: #FFF5F5;
  --cw-warn-border: #FFCECB;
  --cw-code-bg: #FFFFFF;
  --cw-gutter: #F6F8FA;
  --cw-shadow: 0 18px 48px rgba(31, 35, 40, .12);
  --cw-shadow-card: 0 14px 36px rgba(31, 35, 40, .12);
  --cw-tile-hover: #54AEFF;

  /* Sintaxis (GitHub) */
  --cw-tk: #CF222E;   /* keyword */
  --cw-tf: #8250DF;   /* función / nombre */
  --cw-tn: #0550AE;   /* número / constante */
  --cw-tc: #59636E;   /* comentario */
  --cw-ts: #0A3069;   /* cadena */

  /* Tinta por defecto (sin bloque) */
  --cw-ink: var(--cw-accent);
  --cw-cover: var(--cw-accent-soft);
  --cw-iconbg: #DDF4FF;

  --cw-header-h: 64px;
  /* Anchuras fluidas: crecen con la pantalla hasta un máximo */
  --cw-page-max: 1680px;                         /* portada y cabecera */
  --cw-read: clamp(780px, 58vw, 1080px);         /* artículo con barra lateral */
  --cw-read-wide: clamp(860px, 66vw, 1240px);    /* artículo con la barra oculta */
  --cw-gutter-x: clamp(24px, 3vw, 56px);         /* márgenes laterales */
  --cw-term: #0F766E;                            /* términos del glosario */
  --cw-ease: .18s ease;
}

[data-md-color-scheme="slate"] {
  --cw-bg: #0D1117;
  --cw-header-bg: #010409;
  --cw-sub: #151B23;
  --cw-panel: #151B23;
  --cw-border: #3D444D;
  --cw-text: #F0F6FC;
  --cw-lead: #D1D7E0;
  --cw-muted: #9198A1;
  --cw-faint: #9198A1;
  --cw-accent: #4493F8;
  --cw-accent-soft: #12233D;
  --cw-chip-bg: #212830;
  --cw-chip-on: #2F3742;
  --cw-warn: #F85149;
  --cw-warn-bg: #25171C;
  --cw-warn-border: #5E2A2C;
  --cw-code-bg: #0D1117;
  --cw-gutter: #151B23;
  --cw-shadow: 0 18px 48px rgba(1, 4, 9, .70);
  --cw-shadow-card: 0 14px 36px rgba(1, 4, 9, .60);
  --cw-tile-hover: #4493F8;

  --cw-tk: #FF7B72;
  --cw-tf: #D2A8FF;
  --cw-tn: #79C0FF;
  --cw-tc: #9198A1;
  --cw-ts: #A5D6FF;

  --cw-iconbg: #12233D;
  --cw-term: #56D4BC;
}

/* Mapeo a las variables del tema */
:root,
[data-md-color-scheme="default"],
[data-md-color-scheme="slate"] {
  --md-default-bg-color: var(--cw-bg);
  --md-default-bg-color--light: var(--cw-bg);
  --md-default-fg-color: var(--cw-text);
  --md-default-fg-color--light: var(--cw-muted);
  --md-default-fg-color--lighter: var(--cw-faint);
  --md-default-fg-color--lightest: var(--cw-border);
  --md-primary-fg-color: var(--cw-accent);
  --md-primary-fg-color--light: var(--cw-accent);
  --md-primary-fg-color--dark: var(--cw-accent);
  --md-primary-bg-color: var(--cw-bg);
  --md-accent-fg-color: var(--cw-accent);
  --md-accent-fg-color--transparent: var(--cw-accent-soft);
  --md-typeset-color: var(--cw-text);
  --md-typeset-a-color: var(--cw-accent);
  --md-typeset-mark-color: color-mix(in srgb, var(--cw-accent) 22%, transparent);
  --md-typeset-table-color: var(--cw-border);
  --md-typeset-table-color--light: var(--cw-sub);
  --md-typeset-kbd-color: var(--cw-sub);
  --md-typeset-kbd-accent-color: var(--cw-border);
  --md-typeset-kbd-border-color: var(--cw-border);
  --md-admonition-fg-color: var(--cw-text);
  --md-admonition-bg-color: var(--cw-sub);
  --md-footer-fg-color: var(--cw-muted);
  --md-footer-fg-color--light: var(--cw-muted);
  --md-footer-fg-color--lighter: var(--cw-faint);
  --md-footer-bg-color: var(--cw-bg);
  --md-footer-bg-color--dark: var(--cw-bg);

  --md-code-fg-color: var(--cw-text);
  --md-code-bg-color: var(--cw-sub);
  --md-code-bg-color--light: var(--cw-sub);
  --md-code-bg-color--lighter: var(--cw-sub);
  --md-code-hl-color: var(--cw-accent);
  --md-code-hl-color--light: color-mix(in srgb, var(--cw-accent) 12%, transparent);
  --md-code-hl-keyword-color: var(--cw-tk);
  --md-code-hl-function-color: var(--cw-tf);
  --md-code-hl-name-color: var(--cw-text);
  --md-code-hl-number-color: var(--cw-tn);
  --md-code-hl-constant-color: var(--cw-tn);
  --md-code-hl-special-color: var(--cw-tn);
  --md-code-hl-string-color: var(--cw-ts);
  --md-code-hl-comment-color: var(--cw-tc);
  --md-code-hl-operator-color: var(--cw-muted);
  --md-code-hl-punctuation-color: var(--cw-muted);
  --md-code-hl-variable-color: var(--cw-text);
  --md-code-hl-generic-color: var(--cw-muted);

  --md-shadow-z1: none;
  --md-shadow-z2: var(--cw-shadow);
  --md-shadow-z3: var(--cw-shadow);
}

/* Buscador nativo (Shadow DOM): usa tripletes RGB */
[data-md-color-scheme="default"] {
  --color-foreground: 17 17 20;
  --color-background: 255 255 255;
  --color-background-subtle: 250 250 251;
}
[data-md-color-scheme="slate"] {
  --color-foreground: 236 236 239;
  --color-background: 38 39 45;
  --color-background-subtle: 36 37 43;
  --color-backdrop: 10 10 12;
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
html { scroll-padding-top: calc(var(--cw-header-h) + 16px); }

body {
  background: var(--cw-bg);
  color: var(--cw-text);
  -webkit-font-smoothing: antialiased;
}

body,
input,
button {
  font-family: var(--md-text-font, "Geist"), system-ui, -apple-system, "Segoe UI", sans-serif;
}

code, kbd, pre,
.md-typeset code,
.md-typeset kbd,
.md-typeset pre {
  font-family: var(--md-code-font, "Geist Mono"), ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-ligatures: none;
}

.md-container { background: var(--cw-bg); }

.md-main__inner.md-grid {
  max-width: none;
  margin: 0;
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - var(--cw-header-h));
}

:focus-visible { outline: 2px solid var(--cw-accent); outline-offset: 2px; }

.cw-iconbtn {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid var(--cw-border);
  background: var(--cw-sub);
  color: var(--cw-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
  cursor: pointer;
  transition: color var(--cw-ease), background-color var(--cw-ease), border-color var(--cw-ease);
}
.cw-iconbtn:hover { color: var(--cw-text); }
.cw-iconbtn svg { width: 17px; height: 17px; display: block; }
.cw-iconbtn--ghost { width: 36px; height: 36px; border-color: transparent; background: transparent; border-radius: 8px; }
.cw-iconbtn--ghost:hover { background: var(--cw-chip-bg); }

/* --------------------------------------------------------------------------
   3. Cabecera
   -------------------------------------------------------------------------- */
.md-header.cw-header {
  position: sticky;
  top: 0;
  z-index: 5;
  height: auto;
  background: var(--cw-header-bg);
  color: var(--cw-text);
  border-bottom: 1px solid var(--cw-border);
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.md-header.cw-header.md-header--shadow { box-shadow: none; }

.cw-header__bar {
  height: var(--cw-header-h);
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 32px;
}

.cw-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--cw-text);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex: 0 0 auto;
}
.cw-brand:hover,
.cw-brand:focus { color: var(--cw-text); }
.cw-brand__logo { width: 32px; height: 32px; border-radius: 50%; display: block; }

.cw-blocks { display: flex; gap: 4px; font-size: 15px; }
.cw-blocks > span { display: flex; }
.cw-blocks__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--cw-muted);
  font: inherit;
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--cw-ease), background-color var(--cw-ease), opacity var(--cw-ease);
}
.cw-blocks__item:hover { color: var(--cw-text); }
.cw-blocks__item:focus { color: var(--cw-muted); }
.cw-blocks__item.is-current,
.cw-blocks__item[aria-expanded="true"] { color: var(--cw-text); background: var(--cw-chip-bg); }
.cw-blocks__chevron { transition: transform var(--cw-ease); }
.cw-blocks__item[aria-expanded="true"] .cw-blocks__chevron { transform: rotate(180deg); }

.cw-header__spacer { flex: 1 1 20px; }
.cw-header__actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* Buscador nativo reestilizado */
.md-search.cw-search { display: flex; margin: 0; padding: 0; flex: 0 0 auto; }
.md-search__button.cw-search__button,
[dir=ltr] .md-search__button.cw-search__button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  width: 240px;
  margin: 0;
  padding: 0 8px 0 10px;
  border: 1px solid var(--cw-border);
  border-radius: 9px;
  background: var(--cw-sub);
  color: var(--cw-muted);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--cw-ease), color var(--cw-ease);
}
.md-search__button.cw-search__button::before,
.md-search__button.cw-search__button::after { display: none; }
.md-search__button.cw-search__button:hover { border-color: var(--cw-faint); color: var(--cw-text); }
.cw-search__button svg { flex: 0 0 auto; }
.cw-search__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-search__kbd {
  font-family: var(--md-code-font), monospace;
  font-size: 11px;
  line-height: 18px;
  color: var(--cw-muted);
  border: 1px solid var(--cw-border);
  border-radius: 5px;
  padding: 0 5px;
  background: transparent;
}

/* Conmutador de tema nativo reestilizado */
.cw-header .md-header__option { display: flex; margin: 0; flex: 0 0 auto; max-width: none; opacity: 1; }
.cw-header .md-header__option .md-header__button.md-icon {
  width: 38px;
  height: 38px;
  margin: 0;
  padding: 0;
  border-radius: 9px;
  border: 1px solid var(--cw-border);
  background: var(--cw-sub);
  color: var(--cw-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color var(--cw-ease);
}
.cw-header .md-header__option .md-header__button.md-icon[hidden] { display: none; }
.cw-header .md-header__option .md-header__button.md-icon:hover { color: var(--cw-text); opacity: 1; }
.cw-header .md-header__option .md-header__button svg { width: 16px; height: 16px; }

/* Selector de idioma (partials/cw-idioma.html): desplegable con banderas */
.cw-lang { position: relative; flex: 0 0 auto; }
.cw-lang__button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 10px;
  box-sizing: border-box;
  border: 1px solid var(--cw-border);
  border-radius: 9px;
  background: var(--cw-header-bg);
  color: var(--cw-muted);
  cursor: pointer;
  list-style: none;
  transition: color var(--cw-ease);
}
.cw-lang__button::-webkit-details-marker { display: none; }
.cw-lang__button:hover,
.cw-lang[open] .cw-lang__button { color: var(--cw-text); }
.cw-lang__chevron { transition: transform .15s ease; }
.cw-lang[open] .cw-lang__chevron { transform: rotate(180deg); }
.cw-lang__flag {
  display: block;
  width: 21px;
  height: 14px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18);
}
.cw-lang__code { font-size: 12px; font-weight: 600; color: var(--cw-text); }
.cw-lang__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  min-width: 160px;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--cw-panel);
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  box-shadow: var(--cw-shadow-card);
}
.cw-lang__option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--cw-text);
  font-size: 14px;
  white-space: nowrap;
  text-decoration: none;
}
.cw-lang__option:hover,
.cw-lang__option:focus-visible { background: var(--cw-chip-bg); color: var(--cw-text); }
.cw-lang__option.is-current { font-weight: 600; }
.cw-lang__name { flex: 1 1 auto; }
.cw-lang__check { color: var(--cw-accent); }

.cw-header__drawer { display: none; }

/* --------------------------------------------------------------------------
   4. Desplegable de bloques
   -------------------------------------------------------------------------- */
.cw-mega {
  position: absolute;
  left: 50%;
  top: calc(var(--cw-header-h) - 2px);
  width: min(1400px, calc(100% - 48px));
  box-sizing: border-box;
  padding: 12px;
  background: var(--cw-panel);
  border: 1px solid var(--cw-border);
  border-radius: 16px;
  box-shadow: var(--cw-shadow);
  transform: translateX(-50%) translateY(-4px);
  opacity: 0;
  transition: opacity .15s ease, transform .15s ease;
}
.cw-mega[hidden] { display: none; }
.cw-mega.is-open { opacity: 1; transform: translateX(-50%) translateY(0); }

.cw-mega__grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 12px;
}

.cw-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  background: var(--cw-panel);
  color: var(--cw-text);
  line-height: 1.5;
  transition: background-color .15s ease, border-color .15s ease;
}

.cw-tile--inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  align-self: start;
}
.cw-tile:hover,
.cw-tile:focus-visible { border-color: var(--cw-ink); color: var(--cw-text); }
.cw-tile:focus { color: var(--cw-text); }
.cw-tile__name { font-weight: 600; font-size: 16px; }
.cw-tile__desc { font-size: 14px; color: var(--cw-muted); }
.cw-tile__icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--cw-iconbg);
  color: var(--cw-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cw-tile__icon svg { width: 17px; height: 17px; }
.cw-tile__icon--sm { width: 28px; height: 28px; border-radius: 7px; }
.cw-tile__icon--sm svg { width: 15px; height: 15px; }

.cw-mega__links {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-content: start;
}

.cw-tile--feature {
  padding: 0;
  gap: 0;
  overflow: hidden;
  background: var(--cw-cover);
}
.cw-tile__art {
  flex: 1;
  min-height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cw-ink);
}
.cw-tile__art svg { max-width: 80%; height: auto; }
.cw-tile__foot {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  background: var(--cw-panel);
  border-top: 1px solid var(--cw-border);
}
.cw-tile--feature .cw-tile__name { font-size: 17px; }

.cw-tile--row {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
}

/* --------------------------------------------------------------------------
   5. Barra lateral, raíl y cajón
   -------------------------------------------------------------------------- */
.cw-sidebar-col {
  flex: 0 0 270px;
  width: 270px;
  box-sizing: border-box;
  border-right: 1px solid var(--cw-border);
}
.cw-sidebar {
  position: sticky;
  top: var(--cw-header-h);
  max-height: calc(100vh - var(--cw-header-h));
  overflow-y: auto;
  box-sizing: border-box;
  padding: 22px 16px 28px 24px;
  font-size: 14.5px;
  line-height: 1.5;
  scrollbar-width: thin;
}
.cw-sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px 8px;
}
.cw-sidebar__label {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--cw-faint);
}
.cw-sidebar ul { list-style: none; margin: 0; padding: 0; }

.cw-group__button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--cw-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: opacity var(--cw-ease), background-color var(--cw-ease);
}
.cw-group__button:hover { opacity: .75; }
.cw-group__chevron { flex: 0 0 auto; color: var(--cw-faint); transition: transform .15s ease; }
.cw-group__button[aria-expanded="true"] .cw-group__chevron { transform: rotate(90deg); }

.cw-group__panel {
  display: grid;
  grid-template-rows: 0fr;
  visibility: hidden;
  transition: grid-template-rows .15s ease, visibility 0s linear .15s;
}
.cw-group__button[aria-expanded="true"] + .cw-group__panel {
  grid-template-rows: 1fr;
  visibility: visible;
  transition: grid-template-rows .15s ease, visibility 0s;
}
.cw-group__panel > .cw-group__list {
  min-height: 0;
  overflow: hidden;
}
.cw-sidebar .cw-group__list {
  display: flex;
  flex-direction: column;
  margin: 2px 0 6px 14px;
  padding-left: 12px;
  border-left: 1px solid var(--cw-border);
}
.cw-group__button[aria-expanded="false"] + .cw-group__panel > .cw-group__list { margin-block: 0; }

.cw-sidebar__link {
  display: block;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--cw-muted);
  transition: opacity var(--cw-ease), color var(--cw-ease);
}
.cw-sidebar__link--top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 8px;
}
.cw-sidebar__link:hover { color: var(--cw-muted); opacity: .75; }
.cw-sidebar__link:focus { color: var(--cw-muted); }
.cw-sidebar__link.is-current,
.cw-sidebar__link.is-current:hover {
  color: var(--cw-accent);
  font-weight: 500;
  background: var(--cw-accent-soft);
  opacity: 1;
}

.cw-rail {
  display: none;
  flex: 0 0 64px;
  justify-content: center;
  align-items: flex-start;
  padding-top: 22px;
}
.cw-rail .cw-iconbtn { width: 40px; height: 40px; position: sticky; top: calc(var(--cw-header-h) + 22px); }

html[data-cw-sidebar="closed"] .cw-sidebar-col { display: none; }
html[data-cw-sidebar="closed"] .cw-rail { display: flex; }

/* El cajón nativo solo se usa en pantallas estrechas */
@media screen and (min-width: 76.25em) {
  .md-sidebar--primary.cw-drawer { display: none; }
}

/* --------------------------------------------------------------------------
   6. Zona de contenido + índice
   -------------------------------------------------------------------------- */
.cw-stage {
  flex: 1 1 560px;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(32px, 3.5vw, 72px);
  padding: 28px var(--cw-gutter-x) 80px;
}
.cw-stage > .md-content {
  flex: 1 1 auto;
  min-width: 0;
  max-width: var(--cw-read);
  margin: 0;
}
html[data-cw-sidebar="closed"] .cw-stage > .md-content { max-width: var(--cw-read-wide); }
.cw-stage .md-content__inner { margin: 0; padding: 0; }
.cw-stage .md-content__inner::before { display: none; }

.cw-toc {
  flex: 0 0 210px;
  position: sticky;
  top: calc(var(--cw-header-h) + 24px);
  max-height: calc(100vh - var(--cw-header-h) - 48px);
  overflow-y: auto;
  padding-top: 8px;
  font-size: 13.5px;
  line-height: 1.5;
  scrollbar-width: thin;
}
.cw-toc__title { margin: 0 0 10px; font-weight: 500; color: var(--cw-text); }
.cw-toc ul { list-style: none; margin: 0; padding: 0; }
.cw-toc__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-left: 1px solid var(--cw-border);
}
.cw-toc__sub { display: flex; flex-direction: column; gap: 6px; margin-top: 6px !important; }
.cw-toc__link {
  display: block;
  padding-left: 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--cw-muted);
  transition: color .15s ease, border-color .15s ease;
}
.cw-toc__sub .cw-toc__link { padding-left: 24px; font-size: 13px; }
.cw-toc__link:hover,
.cw-toc__link:focus { color: var(--cw-text); }
.cw-toc__link.is-active { color: var(--cw-text); border-left-color: var(--cw-accent); }

/* Desplegables de h3 en el índice (los botones los crea cowpedia.js). */
.cw-toc__group { position: relative; }
.cw-toc__group > .cw-toc__link { padding-right: 24px; }
.cw-toc__toggle {
  position: absolute;
  top: 1px;
  right: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--cw-faint);
  cursor: pointer;
}
.cw-toc__toggle:hover,
.cw-toc__toggle:focus-visible { color: var(--cw-text); background: var(--cw-sub); }
.cw-toc__toggle svg { transition: transform .15s ease; transform: rotate(-90deg); }
.cw-toc__group.is-open > .cw-toc__toggle svg { transform: none; }
.cw-toc__group:not(.is-open) > .cw-toc__sub { display: none; }

/* Numeración de h2 en el índice (a juego con .cw-num del artículo). */
.cw-toc__list--num { counter-reset: cw-toc-h2; }
.cw-toc__list--num > li:not(.cw-toc__extra) { counter-increment: cw-toc-h2; }
.cw-toc__list--num > li:not(.cw-toc__extra) > .cw-toc__link::before { content: counter(cw-toc-h2) ". "; }

/* --------------------------------------------------------------------------
   7. Entrada: tipografía y cabecera
   -------------------------------------------------------------------------- */
.md-typeset {
  font-size: 16px;
  line-height: 1.7;
  color: var(--cw-text);
}
.md-typeset a { color: var(--cw-accent); text-decoration: none; }
.md-typeset a:hover { text-decoration: underline; text-underline-offset: 3px; }
.md-typeset p,
.md-typeset ul,
.md-typeset ol,
.md-typeset dl,
.md-typeset blockquote,
.md-typeset table:not([class]) { margin: 0 0 16px; }
.md-typeset ul li,
.md-typeset ol li { margin-bottom: .35em; }
.md-typeset hr { border-bottom: 1px solid var(--cw-border); margin: 32px 0; }
.md-typeset strong { font-weight: 600; }
.md-typeset img { border-radius: 10px; }

.md-typeset h1,
.md-typeset h2,
.md-typeset h3,
.md-typeset h4,
[data-md-color-scheme=slate] .md-typeset h1,
[data-md-color-scheme=slate] .md-typeset h2,
[data-md-color-scheme=slate] .md-typeset h3,
[data-md-color-scheme=slate] .md-typeset h4 { color: var(--cw-text); }

.md-typeset h1 {
  margin: 0 0 8px;
  font-size: 40px;
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.035em;
}
.md-typeset h2 {
  margin: 40px 0 12px;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.025em;
}
.md-typeset h3 {
  margin: 28px 0 8px;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.015em;
}
.md-typeset h4 { margin: 22px 0 6px; font-size: 16px; font-weight: 600; letter-spacing: 0; }
.md-typeset .headerlink { color: var(--cw-faint); margin-left: .35em; }

/* Subrayado de títulos (opt-in con `underline: true` en el front matter):
   h2 continuo, h3 discontinuo. Solo en el cuerpo de las páginas de contenido.
   El enlace ¶ es inline-block para que no herede el subrayado. */
.cw-body.cw-underline :is(h2, h3) {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .22em;
}
.cw-body.cw-underline h3 { text-decoration-style: dashed; }
.cw-body.cw-underline :is(h2, h3) .headerlink { display: inline-block; }

/* Numeración automática de h2 (solo h2). Se desactiva con `numerar: false`
   en el front matter; el glosario nunca se numera. */
.cw-body.cw-num { counter-reset: cw-h2; }
.cw-body.cw-num h2 { counter-increment: cw-h2; }
.cw-body.cw-num h2::before { content: counter(cw-h2) ". "; }
.md-typeset .headerlink:hover { color: var(--cw-accent); text-decoration: none; }

.cw-entry { margin-bottom: 0; }
.cw-cover {
  height: 150px;
  margin-bottom: 28px;
  padding-right: 40px;
  border-radius: 14px;
  background: var(--cw-cover);
  color: var(--cw-ink);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.cw-cover svg { height: 140px; width: auto; max-width: 70%; }

.md-typeset .cw-crumb {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--cw-muted);
}
.cw-crumb__sep { color: var(--cw-faint); margin: 0 .5em; }
.md-typeset .cw-meta {
  margin: 0 0 30px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--cw-muted);
}
.md-typeset .cw-body--lead > p:first-child {
  margin-bottom: 36px;
  font-size: 19px;
  line-height: 1.6;
  color: var(--cw-lead);
}
.md-typeset .cw-body > :first-child:is(h2, h3) { margin-top: 8px; }

/* Código en línea */
.md-typeset code:not(pre code) {
  padding: .1em .35em;
  border-radius: 5px;
  border: 1px solid var(--cw-border);
  background: var(--cw-sub);
  color: var(--cw-text);
  font-size: .86em;
  word-break: break-word;
}
.md-typeset a code:not(pre code) { color: var(--cw-accent); }

.md-typeset kbd {
  font-size: .8em;
  padding: 0 .4em;
  border-radius: 5px;
  border: 1px solid var(--cw-border);
  background: var(--cw-sub);
  box-shadow: 0 1px 0 var(--cw-border);
  color: var(--cw-text);
}

/* Tablas */
.md-typeset table:not([class]) {
  font-size: 14.5px;
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  box-shadow: none;
  background: var(--cw-bg);
}
.md-typeset table:not([class]) th {
  background: var(--cw-sub);
  font-weight: 600;
  color: var(--cw-text);
}
.md-typeset table:not([class]) td,
.md-typeset table:not([class]) th { border-top-color: var(--cw-border); }

/* Citas */
.md-typeset blockquote {
  border-left: 2px solid var(--cw-border);
  color: var(--cw-muted);
  padding-left: 16px;
}

/* Fórmulas */
.md-typeset div.arithmatex {
  margin: 0 0 32px;
  font-size: 21px;
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
}
.md-typeset div.arithmatex > * { margin-inline: auto !important; }

/* --------------------------------------------------------------------------
   8. Recuadros (admonitions y details)
   -------------------------------------------------------------------------- */
.md-typeset .admonition,
.md-typeset details,
.md-typeset :is(.admonition, details)[class] {
  margin: 0 0 24px;
  padding: 14px 18px;
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  background: var(--cw-sub);
  box-shadow: none;
  color: var(--cw-text);
  font-size: 16px;
  line-height: 1.7;
  page-break-inside: avoid;
}
.md-typeset .admonition:focus-within,
.md-typeset details:focus-within { box-shadow: none; }
.md-typeset :is(.admonition, details)[class] > :last-child { margin-bottom: 0 !important; }
.md-typeset :is(.admonition, details)[class] > :first-child { margin-top: 0; }

.md-typeset .admonition-title,
.md-typeset summary {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 2px !important;
  padding: 0 !important;
  border: 0;
  background: transparent !important;
  color: var(--cw-muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.6;
}
.md-typeset .admonition-title::before,
.md-typeset summary::before {
  position: static;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin: 0;
  background-color: currentColor !important;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}
.md-typeset summary { cursor: pointer; }
.md-typeset summary::after {
  position: static;
  order: 3;
  margin-left: auto;
  width: 14px;
  height: 14px;
  background-color: var(--cw-faint);
  transition: transform .15s ease;
}
.md-typeset details:not([open]) > summary { margin-bottom: 0 !important; }

/* Tipos propios. Iconos de trazo (Lucide) */
.md-typeset :is(.intuicion, .definicion, .formula, .ejemplo, .example) > :is(.admonition-title, summary)::before {
  -webkit-mask-image: var(--cw-icon);
  mask-image: var(--cw-icon);
}
.md-typeset .intuicion { --cw-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><path d='M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7V17h8v-2.3A7 7 0 0 0 12 2z'/></svg>"); }
.md-typeset .definicion { --cw-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M4 19.5A2.5 2.5 0 0 1 6.5 17H20V3H6.5A2.5 2.5 0 0 0 4 5.5z'/></svg>"); }
.md-typeset .formula { --cw-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M18 7V4H6l6 8-6 8h12v-3'/></svg>"); }
.md-typeset .ejemplo { --cw-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M10 2v7.31L4.5 19a2 2 0 0 0 1.74 3h11.52a2 2 0 0 0 1.74-3L14 9.31V2M8.5 2h7M7 16h10'/></svg>"); }

/* Error típico (también `danger`, `failure`, `bug`) */
.md-typeset :is(.admonition, details):is(.error, .danger, .failure, .bug) {
  background: var(--cw-warn-bg);
  border-color: var(--cw-warn-border);
}
.md-typeset :is(.admonition, details):is(.error, .danger, .failure, .bug) > :is(.admonition-title, summary) { color: var(--cw-warn); }
.md-typeset :is(.error) > :is(.admonition-title, summary)::before {
  -webkit-mask-image: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0zM12 9v4M12 17h.01'/></svg>");
  mask-image: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0zM12 9v4M12 17h.01'/></svg>");
}

/* --------------------------------------------------------------------------
   9. Bloques de código
   -------------------------------------------------------------------------- */
.md-typeset .highlight,
.md-typeset .pyodide {
  position: relative;
  margin: 0 0 16px;
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--cw-code-bg);
  font-size: 14px;
}
.md-typeset .highlight + :not(.highlight),
.md-typeset .pyodide + :not(.pyodide) { margin-top: 0; }

/* Sin la tabla de números (por si se desactiva linenums) */
.md-typeset .highlight > pre,
.md-typeset .highlighttable pre { margin: 0; position: static; }
.md-typeset .highlight pre > code,
.md-typeset .highlighttable .code pre > code {
  display: block;
  margin: 0;
  padding: 14px 18px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--cw-text);
  font-size: 14px;
  line-height: 1.85;
  overflow-x: auto;
  scrollbar-width: thin;
}

/* Tabla de números de línea */
.md-typeset .highlighttable {
  display: block;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
}
.md-typeset .highlighttable > tbody { display: block; }
.md-typeset .highlighttable tr { display: flex; background: transparent; }
.md-typeset .highlighttable td,
.md-typeset .highlighttable th {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
}
.md-typeset .highlighttable td.code { flex: 1; min-width: 0; }
.md-typeset .highlighttable td.linenos {
  flex: 0 0 auto;
  background: var(--cw-gutter);
  border-right: 1px solid var(--cw-border);
  user-select: none;
}
.md-typeset .highlighttable .linenodiv { padding: 0; box-shadow: none; background: transparent; }
.md-typeset .highlighttable .linenodiv pre {
  margin: 0;
  padding: 14px 12px;
  background: transparent;
  color: var(--cw-faint);
  font-size: 14px;
  line-height: 1.85;
  text-align: right;
  box-shadow: none;
}
.md-typeset .highlighttable .linenodiv pre span,
.md-typeset .highlighttable .linenodiv a { color: var(--cw-faint); }
/* Bloques de una sola línea: sin canal de números */
.md-typeset .highlighttable:not(:has(.linenodiv .normal ~ .normal, .linenodiv .special ~ .normal, .linenodiv .normal ~ .special)) td.linenos { display: none; }

/* Cabecera con nombre de fichero (title="…") */
.md-typeset .highlight span.filename,
.md-typeset .highlighttable th.filename {
  display: flex;
  align-items: center;
  height: 44px;
  margin: 0;
  padding: 0 96px 0 14px;
  border: 0;
  border-bottom: 1px solid var(--cw-border);
  border-radius: 0;
  background: var(--cw-sub);
  color: var(--cw-muted);
  font-family: var(--md-code-font), monospace;
  font-size: 13px;
  font-weight: 400;
  text-align: left;
}
.md-typeset .highlighttable th.filename { width: 100%; box-sizing: border-box; }
.md-typeset .highlighttable th.filename span.filename {
  display: inline;
  height: auto;
  padding: 0;
  border: 0;
  background: none;
}
.md-typeset .highlighttable tr:has(> th.filename) { display: block; }

/* Botón de copiar */
.md-typeset .md-code__nav {
  position: absolute;
  top: 7px;
  right: 7px;
  padding: 0;
  gap: 2px;
  background: transparent;
  border-radius: 6px;
  opacity: 0;
  transition: opacity .15s ease;
}
.md-typeset .highlight:hover .md-code__nav,
.md-typeset .highlight:focus-within .md-code__nav,
.md-typeset .highlight:has(.filename) .md-code__nav { opacity: 1; }
.md-typeset :hover > .md-code__nav { background: transparent; }
.md-typeset .highlight:has(.filename) .md-code__nav { top: 5px; right: 6px; }
.md-typeset .md-code__button {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  color: var(--cw-muted);
  background: var(--cw-code-bg);
  transition: color .15s ease, background-color .15s ease;
}
.md-typeset .highlight:has(.filename) .md-code__button { background: transparent; }
.md-typeset .md-code__button::after {
  width: 15px;
  height: 15px;
  margin: auto;
  background-color: currentColor;
}
.md-typeset .md-code__button:hover,
.md-typeset .md-code__button:focus-visible { color: var(--cw-text); background: var(--cw-chip-bg); }

/* Resaltado de líneas */
.md-typeset .highlight .hll { background: color-mix(in srgb, var(--cw-accent) 10%, transparent); }

/* Pygments (lo que no cubren las variables) */
.md-typeset .highlight :is(.k, .kn, .kd, .kr, .kt, .kp, .kc, .ow) { color: var(--cw-tk); }
.md-typeset .highlight :is(.nf, .fm, .nb, .bp, .nc, .nd, .ne) { color: var(--cw-tf); }
.md-typeset .highlight :is(.mi, .mf, .mh, .mo, .il, .m, .kc) { color: var(--cw-tn); }
.md-typeset .highlight :is(.c, .c1, .cm, .ch, .cs, .cp, .cpf) { color: var(--cw-tc); font-style: normal; }
.md-typeset .highlight :is(.s, .s1, .s2, .sa, .sb, .sc, .sd, .se, .sh, .si, .sx, .sr, .ss) { color: var(--cw-ts); }
.md-typeset .highlight :is(.nn, .n, .nv, .na, .py) { color: var(--cw-text); }
.md-typeset .highlight :is(.o, .p) { color: var(--cw-muted); }
.md-typeset .highlight .gp { color: var(--cw-faint); user-select: none; }
.md-typeset .highlight .go { color: var(--cw-muted); }

/* Pestañas de contenido */
.md-typeset .tabbed-set { margin: 0 0 16px; border-radius: 12px; }
.md-typeset .tabbed-labels > label { font-size: 14px; color: var(--cw-muted); }
.md-typeset .tabbed-labels > label:hover { color: var(--cw-text); }
.md-typeset .tabbed-set > input:checked + label,
.js .md-typeset .tabbed-labels > label.tabbed-label--active { color: var(--cw-text); }
.md-typeset .tabbed-labels::before { background: var(--cw-accent); }

/* --------------------------------------------------------------------------
   10. Bloques Pyodide (mismo aspecto que el código normal)
   -------------------------------------------------------------------------- */
.md-typeset .pyodide { padding: 0; font-family: var(--md-text-font), sans-serif; }
.md-typeset .pyodide > pre { margin: 0; }

.cw-code__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 44px;
  padding: 0 6px 0 14px;
  border-bottom: 1px solid var(--cw-border);
  background: var(--cw-sub);
}
.cw-code__info { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.cw-code__file {
  font-family: var(--md-code-font), monospace;
  font-size: 13px;
  color: var(--cw-muted);
  white-space: nowrap;
}
.cw-code__hint { font-size: 12px; color: var(--cw-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cw-code__actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.cw-code__copy {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--cw-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color .15s ease, background-color .15s ease;
}
.cw-code__copy:hover { color: var(--cw-text); background: var(--cw-chip-bg); }
.cw-code__copy.is-done { color: var(--cw-accent); }
.md-typeset .pyodide .cw-code__run,
.cw-code__run {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: var(--cw-text);
  color: var(--cw-bg);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  text-align: left;
  cursor: pointer;
  transition: opacity .15s ease;
}
.cw-code__run:hover { opacity: .85; }
.cw-code__run svg { width: 10px; height: 10px; }
.pyodide[data-md-exec-state="loading"] .cw-code__run { opacity: .6; cursor: progress; }

/* Editor Ace */
.md-typeset .pyodide .pyodide-editor {
  width: 100%;
  margin: 0;
  font-size: 14px;
  line-height: 1.85;
}
.md-typeset .pyodide .ace_editor,
.md-typeset .pyodide .ace-zensical {
  background: var(--cw-code-bg);
  color: var(--cw-text);
  font-family: var(--md-code-font), monospace !important;
  font-size: 14px !important;
  line-height: 1.85 !important;
}
.md-typeset .pyodide .ace_gutter {
  background: var(--cw-gutter) !important;
  border-right: 1px solid var(--cw-border);
  color: var(--cw-faint) !important;
}
.md-typeset .pyodide .ace_gutter-cell { padding: 0 12px 0 12px !important; text-align: right; }
.md-typeset .pyodide .ace_editor:not(.ace_focus) .ace_cursor { opacity: 0; }
.md-typeset .pyodide .ace_content { padding-left: 6px; }
.md-typeset .pyodide .ace_gutter-active-line,
.md-typeset .pyodide .ace_marker-layer .ace_active-line { background: transparent !important; }
.md-typeset .pyodide .ace_cursor { color: var(--cw-text); }
.md-typeset .pyodide .ace_marker-layer .ace_selection { background: color-mix(in srgb, var(--cw-accent) 20%, transparent); }
.md-typeset .pyodide .ace_keyword,
.md-typeset .pyodide .ace_storage { color: var(--cw-tk); }
.md-typeset .pyodide .ace_support.ace_function,
.md-typeset .pyodide .ace_entity.ace_name.ace_function,
.md-typeset .pyodide .ace_identifier.ace_function { color: var(--cw-tf); }
.md-typeset .pyodide .ace_constant.ace_numeric,
.md-typeset .pyodide .ace_constant.ace_language { color: var(--cw-tn); }
.md-typeset .pyodide .ace_comment { color: var(--cw-tc); font-style: normal; }
.md-typeset .pyodide .ace_string { color: var(--cw-ts); }
.md-typeset .pyodide .ace_paren,
.md-typeset .pyodide .ace_punctuation,
.md-typeset .pyodide .ace_keyword.ace_operator { color: var(--cw-muted); }

/* Pie de salida */
.cw-code__foot {
  position: relative;
  border-top: 1px solid var(--cw-border);
}
.md-typeset .pyodide .cw-code__foot pre { margin: 0; }
.md-typeset .pyodide .pyodide-output {
  display: block;
  min-height: 0;
  max-height: 400px;
  margin: 0;
  padding: 10px 84px 10px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--cw-text);
  font-family: var(--md-code-font), monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow: auto;
}
.md-typeset .pyodide .pyodide-output:empty::before {
  content: attr(data-cw-placeholder);
  color: var(--cw-faint);
}
.cw-code__clear {
  position: absolute;
  top: 8px;
  right: 8px;
  height: 26px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--cw-faint);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.cw-code__clear:hover { color: var(--cw-text); background: var(--cw-chip-bg); }
.pyodide .pyodide-editor-bar[hidden] { display: none; }

/* Estado sin JavaScript propio: no romper el diseño base */
.md-typeset .pyodide:not(.cw-pyodide) .pyodide-editor-bar {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--cw-sub);
  color: var(--cw-muted);
  font-size: 13px;
}

/* --------------------------------------------------------------------------
   11. Glosario
   -------------------------------------------------------------------------- */
.md-typeset abbr,
.md-typeset .cw-term {
  color: var(--cw-term);
  text-decoration: none;
  border-bottom: 1px dotted color-mix(in srgb, var(--cw-term) 70%, transparent);
  cursor: help;
  transition: background-color .15s ease;
}
.md-typeset .cw-term:hover,
.md-typeset .cw-term:focus-visible { background: color-mix(in srgb, var(--cw-term) 10%, transparent); border-radius: 3px; }
.md-typeset .cw-term:focus-visible { outline-offset: 1px; border-radius: 2px; }

.cw-tip {
  position: absolute;
  z-index: 10;
  width: 290px;
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
  padding: 12px 14px;
  background: var(--cw-panel);
  color: var(--cw-text);
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  box-shadow: var(--cw-shadow);
  font-size: 14px;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease;
  pointer-events: none;
}
.cw-tip.is-open { opacity: 1; transform: translateY(0); pointer-events: auto; }
.cw-tip[hidden] { display: none; }
.cw-tip__term { display: block; margin-bottom: 2px; font-weight: 600; }
.cw-tip__link { display: inline-block; margin-top: 6px; font-size: 13px; color: var(--cw-accent); }
.cw-tip__link:hover { color: var(--cw-accent); text-decoration: underline; text-underline-offset: 3px; }

.md-typeset .cw-glo { margin: 0 0 24px; }
.cw-glo__item {
  padding: 12px 0;
  border-top: 1px solid var(--cw-border);
  scroll-margin-top: calc(var(--cw-header-h) + 24px);
}
.cw-glo__item:target,
.cw-glo__item.is-target { background: linear-gradient(90deg, var(--cw-accent-soft), transparent); }
.cw-glo__alias { margin-left: .6em; font-size: 13px; font-weight: 400; color: var(--cw-faint); }
.md-typeset .cw-glo dl { margin: 0 0 24px; }
.cw-anchor { display: block; scroll-margin-top: calc(var(--cw-header-h) + 24px); }
.md-typeset .cw-glo dt { font-weight: 600; }
.md-typeset .cw-glo dd { margin: 2px 0 0; color: var(--cw-muted); }

/* --------------------------------------------------------------------------
   12. Véase también
   -------------------------------------------------------------------------- */
.cw-related {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.md-typeset .cw-related__card {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  background: var(--cw-panel);
  color: var(--cw-text);
  line-height: 1.45;
  transition: border-color .15s ease, transform .15s ease;
}
.md-typeset .cw-related__card:hover { transform: translateY(-2px); text-decoration: none; color: var(--cw-text); border-color: var(--cw-faint); }
.cw-related__sub { display: block; margin-bottom: 2px; font-size: 13px; color: var(--cw-muted); }
.cw-related__title { font-weight: 500; }

/* --------------------------------------------------------------------------
   13. Portada (tablero)
   -------------------------------------------------------------------------- */
.md-content.cw-home {
  flex: 1 1 auto;
  max-width: var(--cw-page-max);
  margin: 0 auto;
  padding: 56px var(--cw-gutter-x) 80px;
  box-sizing: border-box;
}
.cw-home .md-content__inner { margin: 0; padding: 0; font-size: 16px; line-height: 1.6; }
.cw-home .md-content__inner::before { display: none; }
.cw-home a { text-decoration: none; }

.cw-home__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}
.cw-home__title {
  margin: 0 0 4px;
  font-size: 40px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.035em;
  color: var(--cw-text);
}
.cw-home__lead { margin: 0; font-size: 17px; line-height: 1.6; color: var(--cw-muted); }

.cw-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--cw-chip-bg);
}
.cw-filter__btn {
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--cw-muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.cw-filter__btn:hover { color: var(--cw-text); }
.cw-filter__btn[aria-pressed="true"] {
  background: var(--cw-chip-on);
  color: var(--cw-text);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

.cw-board { columns: 320px 5; column-gap: 20px; }

.cw-card {
  break-inside: avoid;
  display: inline-block;
  width: 100%;
  margin: 0 0 20px;
  box-sizing: border-box;
  background: var(--cw-panel);
  border: 1px solid var(--cw-border);
  border-radius: 14px;
  overflow: hidden;
  color: var(--cw-text);
  line-height: 1.6;
  transition: transform var(--cw-ease), box-shadow var(--cw-ease), border-color var(--cw-ease);
}
.cw-card:hover { transform: translateY(-3px); box-shadow: var(--cw-shadow-card); }
.cw-card[hidden] { display: none; }
.cw-card__link { display: block; color: var(--cw-text); }
.cw-card__link:hover,
.cw-card__link:focus { color: var(--cw-text); }
.cw-card__cover {
  padding: 40px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cw-cover);
  color: var(--cw-ink);
  overflow: hidden;
}
.cw-card__cover svg { max-width: 86%; height: auto; }
.cw-card__body { display: block; padding: 18px 20px 20px; }
.cw-card__meta { display: block; margin: 0 0 6px; font-size: 13px; color: var(--cw-muted); }
.cw-card__title {
  display: block;
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.cw-card__title--sm { font-size: 19px; line-height: 1.3; letter-spacing: -0.015em; margin: 0; }
.cw-card__desc { display: block; color: var(--cw-muted); font-size: 15px; }
.cw-card__link--text { display: flex; gap: 14px; padding: 20px; }
.cw-card__link--text .cw-card__desc { margin: 4px 0 8px; }
.cw-card__icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--cw-iconbg);
  color: var(--cw-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cw-card__icon svg { width: 17px; height: 17px; }
.cw-card__text { display: block; min-width: 0; }
.cw-card__foot { display: block; font-size: 13px; color: var(--cw-faint); }
.cw-card__type { display: block; margin-top: 2px; font-size: 13px; color: var(--cw-faint); }

.cw-gcard { padding: 20px; }
.cw-gcard__title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--cw-text);
}
.cw-gcard__list { display: flex; flex-direction: column; }
.cw-gcard__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--cw-border);
  color: var(--cw-text);
  transition: color .15s ease;
}
.cw-gcard__row:hover,
.cw-gcard__row:focus { color: var(--cw-accent); }
.cw-gcard__tag { font-size: 13px; color: var(--cw-faint); }
.cw-gcard__all {
  display: block;
  padding-top: 12px;
  border-top: 1px solid var(--cw-border);
  font-size: 14px;
  color: var(--cw-accent);
}
.cw-gcard__all:hover,
.cw-gcard__all:focus { color: var(--cw-text); }

/* --------------------------------------------------------------------------
   14. Pie
   -------------------------------------------------------------------------- */
.md-footer.cw-footer {
  background: var(--cw-bg);
  color: var(--cw-muted);
  border-top: 1px solid var(--cw-border);
}
.cw-pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--cw-page-max);
  margin: 0 auto;
  padding: 24px 32px 0;
}
.cw-pager__link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 48%;
  padding: 12px 16px;
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  color: var(--cw-text);
  font-size: 14px;
  line-height: 1.4;
  transition: border-color .15s ease, transform .15s ease;
}
.cw-pager__link:hover,
.cw-pager__link:focus { color: var(--cw-text); border-color: var(--cw-faint); }
.cw-pager__link--next { margin-left: auto; text-align: right; }
.cw-pager__dir { font-size: 13px; color: var(--cw-muted); }
.cw-pager__title { font-weight: 500; }
.cw-footer__meta {
  max-width: var(--cw-page-max);
  margin: 0 auto;
  padding: 20px 32px 28px;
  font-size: 13px;
  color: var(--cw-faint);
}

/* Botón «volver arriba» */
.md-top {
  background: var(--cw-panel);
  color: var(--cw-muted);
  border: 1px solid var(--cw-border);
  box-shadow: var(--cw-shadow-card);
  font-size: 13px;
}
.md-top:hover { background: var(--cw-panel); color: var(--cw-text); }

/* Cajón nativo (móvil) */
.md-nav--primary .md-nav__title { background: var(--cw-bg); color: var(--cw-text); box-shadow: none; }
.md-sidebar--primary .md-nav__link--active,
.md-sidebar--primary .md-nav__item .md-nav__link--active { color: var(--cw-accent); }
.md-nav__link:is(:focus, :hover) { color: var(--cw-accent); }

/* --------------------------------------------------------------------------
   15. Responsive
   -------------------------------------------------------------------------- */
@media screen and (max-width: 76.234375em) {
  .cw-sidebar-col,
  .cw-rail,
  html[data-cw-sidebar="closed"] .cw-rail { display: none; }
  .cw-header__drawer { display: inline-flex; }
  .cw-header__bar { gap: 20px; }
  .md-sidebar--primary.cw-drawer { background: var(--cw-bg); }
  html[data-cw-sidebar="closed"] .cw-stage > .md-content { max-width: var(--cw-read-wide); }
}

@media screen and (max-width: 999px) {
  .cw-toc { display: none; }
  .cw-blocks,
  .cw-mega { display: none !important; }
  .cw-stage { padding: 24px 24px 64px; }
  .cw-related { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media screen and (max-width: 699px) {
  .cw-header__bar { padding: 0 16px; gap: 12px; }
  .md-search__button.cw-search__button,
  [dir=ltr] .md-search__button.cw-search__button { width: 38px; padding: 0; justify-content: center; }
  .cw-search__label,
  .cw-search__kbd { display: none; }
  .cw-stage { padding: 20px 16px 56px; }
  .md-content.cw-home { padding: 32px 16px 64px; }
  .md-typeset h1,
  .cw-home__title { font-size: 32px; }
  .cw-cover { height: 120px; padding-right: 16px; }
  .cw-cover svg { height: 110px; }
  .cw-related { grid-template-columns: minmax(0, 1fr); }
  .cw-pager { padding: 20px 16px 0; }
  .cw-footer__meta { padding: 16px 16px 24px; }
  .md-typeset .cw-body--lead > p:first-child { font-size: 17.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { transition-duration: 0s !important; }
}

@media print {
  .cw-header,
  .cw-sidebar-col,
  .cw-rail,
  .cw-toc,
  .cw-footer,
  .cw-code__actions { display: none !important; }
}

/* --------------------------------------------------------------------------
   16. Páginas índice (bloques y subniveles)
   -------------------------------------------------------------------------- */
.cw-stage--index > .md-content,
html[data-cw-sidebar="closed"] .cw-stage--index > .md-content { max-width: var(--cw-page-max); }
.md-typeset .cw-index__lead {
  margin: -14px 0 32px;
  font-size: 19px;
  line-height: 1.6;
  color: var(--cw-lead);
  max-width: 62ch;
}
.cw-index .cw-body:empty { display: none; }

.cw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  align-items: start;
  margin-top: 8px;
}
.md-typeset .cw-grid a { text-decoration: none; }

/* Índice de un subnivel: un apartado por grupo (sección con páginas dentro). */
.md-typeset .cw-index__group {
  margin: 40px 0 4px;
  font-size: 19px;
  letter-spacing: -0.015em;
}
.md-typeset .cw-index__group a { color: var(--cw-text); }
.md-typeset .cw-index__group a:hover { color: var(--cw-ink); text-decoration: none; }
.cw-grid > .cw-card { margin: 0; display: block; }

.cw-scard {
  padding: 20px;
  background: var(--cw-panel);
  border: 1px solid var(--cw-border);
  border-radius: 14px;
  line-height: 1.5;
  transition: box-shadow var(--cw-ease), transform var(--cw-ease);
}
.cw-scard:hover { box-shadow: var(--cw-shadow-card); }
.md-typeset .cw-scard__head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  color: var(--cw-text);
  margin-bottom: 12px;
}
.md-typeset .cw-scard__head:hover .cw-scard__title { color: var(--cw-ink); }
.cw-scard__head .cw-tile__icon { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px; }
.cw-scard__text { display: block; min-width: 0; }
.cw-scard__title {
  display: block;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  transition: color .15s ease;
}
.cw-scard__desc { display: block; margin-top: 2px; font-size: 15px; color: var(--cw-muted); }
.md-typeset .cw-scard__list { list-style: none; margin: 0; padding: 0; }
.md-typeset .cw-scard__list li { margin: 0; }
.md-typeset .cw-scard__list a {
  display: block;
  padding: 8px 0;
  border-top: 1px solid var(--cw-border);
  color: var(--cw-text);
  font-size: 15px;
  transition: color .15s ease;
}
.md-typeset .cw-scard__list a:hover { color: var(--cw-ink); text-decoration: none; }
.md-typeset .cw-scard__count { margin: 8px 0 0; font-size: 13px; color: var(--cw-faint); }

/* Ruta enlazada y etiqueta del bloque en la barra lateral */
.md-typeset .cw-crumb a { color: var(--cw-muted); }
.md-typeset .cw-crumb a:hover { color: var(--cw-text); text-decoration: none; }
a.cw-sidebar__label { color: var(--cw-faint); transition: color .15s ease; }
a.cw-sidebar__label:hover,
a.cw-sidebar__label.is-current { color: var(--cw-accent); }
.cw-sidebar__link--index { color: var(--cw-faint); font-size: 14px; }

/* Tarjetas dentro del contenido: sin color de enlace ni sangría de listas */
.md-typeset .cw-card__link,
.md-typeset .cw-card__link:hover,
.md-typeset .cw-card__link:focus { color: var(--cw-text); text-decoration: none; }
.md-typeset .cw-card__title { color: var(--cw-text); }
.md-typeset .cw-scard__list { margin-left: 0; }
.md-typeset .cw-scard__list li { margin-left: 0; list-style: none; }
[dir] .md-typeset .cw-scard__list { margin: 0; padding: 0; }
[dir] .md-typeset .cw-scard__list li { margin: 0; padding: 0; }

/* --------------------------------------------------------------------------
   17. Portada: tablero + columna fija del glosario
   -------------------------------------------------------------------------- */
.cw-home__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}
.cw-home__aside {
  position: sticky;
  top: calc(var(--cw-header-h) + 24px);
}
.cw-home__aside .cw-card { margin: 0; }
/* Sin términos recientes (la tarjeta sigue oculta): fuera la columna entera, etiqueta incluida */
.cw-home__layout:has([data-cw-recientes][hidden]) { grid-template-columns: minmax(0, 1fr); }
.cw-home__aside:has([data-cw-recientes][hidden]) { display: none; }
/* Etiqueta de sección (portada y páginas de bloque) */
.cw-section-label,
.md-typeset .cw-section-label {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--cw-muted);
}
.cw-board + .cw-section-label,
.md-typeset .cw-board + .cw-section-label { margin-top: 12px; }
@media screen and (max-width: 999px) {
  .cw-home__layout { grid-template-columns: minmax(0, 1fr); }
  .cw-home__aside { position: static; }
}

/* --------------------------------------------------------------------------
   18. «Ver más» (tableros de subnivel y glosario)
   -------------------------------------------------------------------------- */
.cw-more-hidden { display: none !important; }
.cw-more {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 10px 6px 0;
  border: 0;
  background: transparent;
  color: var(--cw-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s ease;
}
.cw-more:hover { color: var(--cw-text); }
.cw-more svg { transition: transform .15s ease; }
.cw-more[aria-expanded="true"] svg { transform: rotate(180deg); }
.cw-glo .cw-more { margin: -8px 0 24px; }

/* --------------------------------------------------------------------------
   19. Color por tipo de recuadro (fondo suave, borde fino, título en color)
   `intuicion`, `definicion`, `formula`, `ejemplo` y `quote` siguen en gris.
   -------------------------------------------------------------------------- */
:root,
[data-md-color-scheme="default"] {
  --cw-ad-blue: #0969DA;   --cw-ad-blue-bg: #F3F9FF;   --cw-ad-blue-bd: #C8E1FF;
  --cw-ad-green: #1A7F37;  --cw-ad-green-bg: #F2FBF4;  --cw-ad-green-bd: #B4E8C2;
  --cw-ad-amber: #9A6700;  --cw-ad-amber-bg: #FFFBEB;  --cw-ad-amber-bd: #F0DC9C;
  --cw-ad-violet: #8250DF; --cw-ad-violet-bg: #FAF5FF; --cw-ad-violet-bd: #E1CCFF;
}
[data-md-color-scheme="slate"] {
  --cw-ad-blue: #4493F8;   --cw-ad-blue-bg: #111D2E;   --cw-ad-blue-bd: #1F3F6E;
  --cw-ad-green: #3FB950;  --cw-ad-green-bg: #12211A;  --cw-ad-green-bd: #1E4A2B;
  --cw-ad-amber: #D29922;  --cw-ad-amber-bg: #221D12;  --cw-ad-amber-bd: #5A4518;
  --cw-ad-violet: #AB7DF8; --cw-ad-violet-bg: #1C1830; --cw-ad-violet-bd: #432F6E;
}

.md-typeset :is(.admonition, details):is(.note, .abstract, .summary, .tldr, .todo, .seealso) {
  --cw-ad: var(--cw-ad-blue); background: var(--cw-ad-blue-bg); border-color: var(--cw-ad-blue-bd);
}
.md-typeset :is(.admonition, details):is(.tip, .hint, .important, .success, .check, .done) {
  --cw-ad: var(--cw-ad-green); background: var(--cw-ad-green-bg); border-color: var(--cw-ad-green-bd);
}
.md-typeset :is(.admonition, details):is(.warning, .caution, .attention) {
  --cw-ad: var(--cw-ad-amber); background: var(--cw-ad-amber-bg); border-color: var(--cw-ad-amber-bd);
}
/* `info` (usado como «Importante») en violeta para distinguirlo de las notas */
.md-typeset :is(.admonition, details):is(.info, .question, .help, .faq) {
  --cw-ad: var(--cw-ad-violet); background: var(--cw-ad-violet-bg); border-color: var(--cw-ad-violet-bd);
}
.md-typeset :is(.admonition, details):is(.note, .info, .abstract, .summary, .tldr, .todo, .seealso, .tip, .hint, .important, .success, .check, .done, .warning, .caution, .attention, .question, .help, .faq, .example) > :is(.admonition-title, summary) {
  color: var(--cw-ad);
}

/* Ejemplos (`example` nativo y `ejemplo` propio): naranja con bombilla */
:root,
[data-md-color-scheme="default"] { --cw-ad-orange: #BC4C00; --cw-ad-orange-bg: #FFF5EB; --cw-ad-orange-bd: #FFD3AC; }
[data-md-color-scheme="slate"] { --cw-ad-orange: #DB6D28; --cw-ad-orange-bg: #221811; --cw-ad-orange-bd: #5E3417; }
.md-typeset :is(.admonition, details):is(.example, .ejemplo) {
  --cw-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><path d='M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7V17h8v-2.3A7 7 0 0 0 12 2z'/></svg>");
  background: var(--cw-ad-orange-bg);
  border-color: var(--cw-ad-orange-bd);
}
.md-typeset :is(.admonition, details):is(.example, .ejemplo) > :is(.admonition-title, summary) { color: var(--cw-ad-orange); }

/* --------------------------------------------------------------------------
   20. Barra superior con la paleta de GitHub
   -------------------------------------------------------------------------- */
.md-search__button.cw-search__button,
[dir=ltr] .md-search__button.cw-search__button,
.cw-header .md-header__option .md-header__button.md-icon,
.cw-header__drawer { background: var(--cw-header-bg); }

/* Marco de la franja de portada (entradas e índices) */
.cw-cover {
  border: 1px solid var(--cw-border);
  box-sizing: border-box;
}
