/* ==========================================================================
   Base: tokens (tema oscuro y claro), tipografía, estructura y navegación.
   Tokens cálidos del UI Kit (Plantillas) · bandas alternas del Alcoholímetro.
   ========================================================================== */

/* ── TOKENS · oscuro por defecto ── */
:root {
  color-scheme: dark;
  --bg: #0b0a09; --bg-alt: #100e0c;
  --surface: #161411; --surface2: #1e1b17; --surface3: #28241f;
  --border: rgba(255, 255, 255, .07); --border2: rgba(255, 255, 255, .13);
  --text: #f3eee7; --text2: #bcb4a8; --muted: #8a8278;
  --accent: #e2602f; --accent-soft: rgba(226, 96, 47, .14); --accent-text: #f08a5b;
  --good: #22c38e; --good-text: #3ad6a0; --good-soft: rgba(34, 195, 142, .13);
  --bad: #ff5a6e; --bad-text: #ff7d8c; --bad-soft: rgba(255, 90, 110, .13);
  --warn: #f4b740;
  /* series de datos (paleta validada para daltonismo, pasos del tema oscuro) */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s7: #9085e9; --s8: #e66767;
  --grid: #2a2622; --axis: #3d3832;
  /* partidos */
  --pp: #1d84ce; --psoe: #e1251b; --vox: #5fb336; --fa: #a24bb5; --otros: #8f8c85;
  --erc: #e0a100; --bildu: #2aa198; --junts: #d0559a; --pnv: #9a7b4f;
  --shadow: 0 18px 50px -24px rgba(0, 0, 0, .7);
  --ease-out: cubic-bezier(.23, 1, .32, 1); --ease-spring: cubic-bezier(.34, 1.56, .64, 1); --ease-drawer: cubic-bezier(.32, .72, 0, 1);
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Bricolage Grotesque', 'Plus Jakarta Sans', system-ui, sans-serif;
  --lateral: 264px;
}

/* ── TOKENS · claro («papel») ── */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5efe6; --bg-alt: #efe7db;
  --surface: #fffdf9; --surface2: #f3ebdf; --surface3: #e8dccb;
  --border: rgba(40, 28, 18, .09); --border2: rgba(40, 28, 18, .16);
  --text: #211a14; --text2: #54493f; --muted: #6f6458;
  --accent: #d0541f; --accent-soft: rgba(208, 84, 31, .11); --accent-text: #a8400f;
  --good: #14a37c; --good-text: #0b7a5b; --good-soft: rgba(20, 163, 124, .12);
  --bad: #d83a55; --bad-text: #b52440; --bad-soft: rgba(216, 58, 85, .1);
  --warn: #b97c06;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s7: #6250d6; --s8: #e34948;
  --grid: #e3d9cb; --axis: #c9bcaa;
  --shadow: 0 16px 40px -22px rgba(80, 52, 12, .35);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f5efe6; --bg-alt: #efe7db;
    --surface: #fffdf9; --surface2: #f3ebdf; --surface3: #e8dccb;
    --border: rgba(40, 28, 18, .09); --border2: rgba(40, 28, 18, .16);
    --text: #211a14; --text2: #54493f; --muted: #6f6458;
    --accent: #d0541f; --accent-soft: rgba(208, 84, 31, .11); --accent-text: #a8400f;
    --good: #14a37c; --good-text: #0b7a5b; --good-soft: rgba(20, 163, 124, .12);
    --bad: #d83a55; --bad-text: #b52440; --bad-soft: rgba(216, 58, 85, .1);
    --warn: #b97c06;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s7: #6250d6; --s8: #e34948;
    --grid: #e3d9cb; --axis: #c9bcaa;
    --shadow: 0 16px 40px -22px rgba(80, 52, 12, .35);
  }
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15.5px/1.55 var(--font); -webkit-font-smoothing: antialiased; overflow-x: clip; }
h1, h2, h3, h4, p, ul, ol { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--accent-text); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.ic { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.18em; }
.saltar { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-weight: 700; text-decoration: none; transition: transform .2s var(--ease-out); }
.saltar:focus { transform: translateY(72px); }

/* ── ESTRUCTURA ── */
.shell { display: grid; grid-template-columns: var(--lateral) minmax(0, 1fr); min-height: 100dvh; }

/* ── MENÚ LATERAL (índice que te sigue) ── */
.lateral { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; padding: 18px 12px 14px; border-right: 1px solid var(--border); background: var(--bg); overflow: hidden; }
.marca { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; text-decoration: none; color: var(--text); }
.marca-logo { width: 36px; height: 36px; flex: none; display: block; border-radius: 10px; box-shadow: 0 0 0 1px var(--border2); }
/* La aguja del medidor duda entre «peor» y «mejor» al pasar el ratón */
.marca-logo .aguja { transform-origin: 16px 21.5px; transition: transform .5s var(--ease-spring); }
@media (hover: hover) { .marca:hover .marca-logo .aguja { transform: rotate(-38deg); } }
.marca b { font: 800 16px/1.1 var(--display); letter-spacing: -.02em; display: block; }
.marca small { font-size: 11.5px; color: var(--muted); font-weight: 600; }
/* Solo se desliza la lista: marca, buscar, copiar y tema se quedan siempre arriba */
.indice { display: flex; flex-direction: column; gap: 1px; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 0 -4px; padding: 0 4px 8px; scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
.indice-grupo { font-size: 10.5px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 5px; }
.indice a { position: relative; display: flex; align-items: center; gap: 10px; padding: 7px 12px 9px; border-radius: 10px; color: var(--text2); text-decoration: none; font-size: 13.5px; font-weight: 600; transition: color .15s var(--ease-out), background-color .15s var(--ease-out); }
.indice a .ic { opacity: .6; transition: opacity .15s; }
.indice a .n { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.indice a::after { /* raíl que se rellena con lo leído */
  content: ""; position: absolute; left: 12px; right: 12px; bottom: 3px; height: 2px; border-radius: 2px;
  background: var(--accent); opacity: .55; transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform .25s linear;
}
@media (hover: hover) { .indice a:hover { color: var(--text); background: var(--surface); } .indice a:hover .ic { opacity: .9; } }
.indice a.activo { color: var(--text); background: var(--surface2); box-shadow: inset 0 0 0 1px var(--border); }
.indice a.activo .ic { opacity: 1; color: var(--accent); }
.indice a.activo::before { content: ""; position: absolute; left: 0; top: 50%; translate: 0 -50%; width: 3px; height: 16px; border-radius: 0 3px 3px 0; background: var(--accent); }
.indice a.leido .n { color: var(--good-text); }
.lateral-pie { flex: none; display: flex; gap: 6px; padding-bottom: 10px; margin-bottom: 2px; border-bottom: 1px solid var(--border); }
.boton-suave { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text2); font-size: 13px; font-weight: 600; text-decoration: none; transition: background-color .15s var(--ease-out), color .15s var(--ease-out), border-color .15s; }
@media (hover: hover) { .boton-suave:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); } }
.boton-suave.ancho { flex: 1; }

/* ── MÓVIL: PÍLDORA QUE SE DESPLIEGA (como «Navegación › Píldora» del UI Kit) ── */
.boton-icono { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.pil-nav { display: none; position: fixed; top: max(10px, env(safe-area-inset-top)); left: 0; right: 0; z-index: 50; pointer-events: none; }
.pil-caja { pointer-events: auto; margin: 0 auto; width: max-content; max-width: calc(100vw - 24px); overflow: hidden; border-radius: 99px; border: 1px solid var(--border2);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 14px 34px -16px rgba(0, 0, 0, .55); }
.pil-caja[data-abierta="true"] { width: min(380px, calc(100vw - 24px)); border-radius: 20px; }
.pil-cab { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 7px 14px 7px 9px; border-radius: inherit; color: var(--text); font-size: 14px; font-weight: 700; text-align: left; }
.pil-cab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pil-aro { flex: none; width: 26px; height: 26px; rotate: -90deg; }
.pil-aro circle { fill: none; stroke-width: 2.8; }
.pil-aro .pista { stroke: var(--border2); }
.pil-aro .prog { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .12s linear; }
.pil-aro .prog.salta { transition: none; }
.pil-aro .prog.gira { transition: stroke-dashoffset .5s cubic-bezier(.4, 0, .2, 1); }
/* Anillo que se va: termina su vuelta (al bajar) o se deshace hacia atrás (al subir) */
.pil-aro .fantasma { opacity: 0; transition: none; }
.pil-tit { position: relative; flex: 1; min-width: 0; height: 20px; overflow: hidden; }
.pil-tit > span { position: absolute; inset: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 20px; }
.pil-caja[data-abierta="false"] .pil-tit { width: min(46vw, 210px); }
.pil-n { font-size: 11.5px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.pil-flecha { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: rotate .3s var(--ease-out); }
.pil-caja[data-abierta="true"] .pil-flecha { rotate: 180deg; }
.pil-panel { display: none; }
.pil-caja[data-abierta="true"] .pil-panel { display: flex; flex-direction: column; max-height: min(70dvh, 620px); padding: 0 8px 10px; }
/* Buscar, copiar y tema fijos arriba: solo se desliza la lista */
#pilLista { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
#pilLista::-webkit-scrollbar { display: none; }
.pil-acciones { flex: none; display: flex; gap: 8px; padding: 2px 6px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pil-acciones .boton-suave { flex: 1; }
.pil-acciones [data-tema] { flex: none; width: 44px; }
.pil-grupo { font-size: 10.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; }
.pil-lista { list-style: none; margin: 0; padding: 0; }
.pil-lista a { display: grid; grid-template-columns: 24px 1fr; align-items: center; column-gap: 8px; row-gap: 5px; padding: 8px 10px; border-radius: 10px; color: var(--text2); text-decoration: none; font-size: 14px; font-weight: 600; }
.pil-lista a:focus-visible, .pil-lista a:active { background: var(--surface2); outline: none; }
.pil-lista a[aria-current] { color: var(--text); font-weight: 800; }
.pil-lista .n { font-size: 11px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.pil-lista a[aria-current] .n { color: var(--accent); }
.pil-lista i { grid-column: 2; height: 3px; border-radius: 3px; background: var(--border); overflow: hidden; }
.pil-lista i b { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); }
/* ── CONTENIDO ── */
main { min-width: 0; }
.seccion { padding: 72px clamp(16px, 4vw, 56px) 40px; border-bottom: 1px solid var(--border); counter-increment: sec; }
.seccion { --sec-bg: var(--bg); }
.seccion:nth-of-type(even) { --sec-bg: var(--bg-alt); background: var(--bg-alt); }
main { counter-reset: sec -1; }
.caja { max-width: 1080px; margin: 0 auto; }
.sec-cab { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.sec-cab > div { flex: 1; min-width: 0; }
.antetitulo { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-text); margin-bottom: 10px; }
.antetitulo::before { content: counter(sec, decimal-leading-zero); color: var(--muted); }
h2 { font: 800 clamp(28px, 4.2vw, 44px)/1.04 var(--display); letter-spacing: -.025em; text-wrap: balance; }
.entradilla { color: var(--text2); font-size: clamp(16px, 1.6vw, 18px); max-width: 68ch; margin: 12px 0 28px; text-wrap: pretty; }
.copiar { flex: none; margin-top: 30px; }
h3 { font: 700 17px/1.25 var(--display); letter-spacing: -.01em; }
.siguiente { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 56px; padding: 18px 0 4px; border-top: 1px solid var(--border2); text-decoration: none; color: var(--text); }
.siguiente small { display: block; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.siguiente b { font: 700 18px/1.2 var(--display); }
.siguiente .ic { width: 22px; height: 22px; color: var(--accent); transition: transform .2s var(--ease-out); }
@media (hover: hover) { .siguiente:hover b { color: var(--accent-text); } .siguiente:hover .ic { transform: translateX(4px); } }

/* ── AVISO FLOTANTE ── */
.aviso { position: fixed; left: 50%; bottom: 24px; z-index: 80; translate: -50% 0; display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-weight: 700; font-size: 14px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); transition: opacity .2s var(--ease-out), transform .25s var(--ease-out); pointer-events: none; }
.aviso.ver { opacity: 1; transform: none; }

/* ── MÓVIL Y TABLET ── */
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .lateral { display: none; }
  .pil-nav { display: block; }
  .seccion { padding-top: 84px; }
  html { scroll-padding-top: 70px; }
}
/* En el ordenador el contenido sigue justo debajo: el enlace «Siguiente» sobra */
@media (min-width: 961px) { .siguiente { display: none; } }
/* «Ctrl K» solo tiene sentido con teclado y ratón */
@media not ((hover: hover) and (pointer: fine)) { .busca-boton kbd { display: none; } }
/* ── CAMBIO DE TEMA SUAVE ── */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 2; }
html.tema-fundiendo *, html.tema-fundiendo *::before, html.tema-fundiendo *::after {
  transition: background-color .4s ease, color .4s ease, border-color .4s ease, fill .4s ease, stroke .4s ease !important;
}

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