/* ==========================================================================
   Las familias ocultas · Gaia como laboratorio computacional
   Concepto de maquetación: «cuaderno de observación». Columna de lectura
   estrecha (~68 caracteres) interrumpida por paneles-instrumento anchos
   donde viven las demostraciones. Tema nocturno deliberado (única apariencia),
   heredado de la paleta de la conferencia.
   ========================================================================== */
:root {
  /* Superficies (cielo nocturno con sesgo azul, no gris neutro) */
  --night-0: #070B1E;
  --night-1: #0B1230;
  --night-2: #111A3D;
  --night-3: #18234F;
  --rule: #263361;
  /* Tinta */
  --ink: #E8ECFA;
  --ink-2: #B3BCDF;
  --ink-3: #8691BE;
  /* Acentos de interfaz (de la presentación) */
  --cyan: #3DD6D0;
  --coral: #FF7A59;
  /* Serie de datos (validada sobre fondo oscuro: banda L, croma, daltonismo, contraste) */
  --c-fam: #1FA8A3;   /* familia / candidatas / clase positiva */
  --c-alt: #E8603D;   /* contraste / campo en clasificación / pesos negativos */
  --c-true: #9A7BE0;  /* verdad conocida (miembros simulados) */
  --c-field: #4A5583; /* contexto, deliberadamente apagado */

  --f-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", "Verdana", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;

  /* Escala tipográfica (razón ~1.25) */
  --t-xs: 0.78rem;
  --t-sm: 0.9rem;
  --t-md: 1.05rem;
  --t-lg: 1.3rem;
  --t-xl: 1.7rem;
  --t-2xl: clamp(1.9rem, 1.3rem + 2.2vw, 2.7rem);
  --t-3xl: clamp(2.4rem, 1.4rem + 4.2vw, 4.4rem);

  --measure: 68ch;
  --wide: 1180px;
  --gutter: clamp(16px, 4vw, 40px);
  --radius: 10px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--night-1);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--t-md);
  line-height: 1.6;
  overflow-x: hidden;
}
#starfield {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: -1; pointer-events: none;
  background: radial-gradient(120% 80% at 70% -10%, #16224f 0%, var(--night-1) 55%, var(--night-0) 100%);
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--cyan); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; border-radius: 4px; }

h1, h2, h3, h4 {
  font-family: var(--f-display);
  line-height: 1.12;
  text-wrap: balance;
  margin: 0;
  letter-spacing: -0.01em;
}
h1 { font-size: var(--t-3xl); font-weight: 700; }
h2 { font-size: var(--t-2xl); font-weight: 650; }
h3 { font-size: var(--t-lg); font-weight: 600; }
h4 { font-size: var(--t-md); font-weight: 600; }
p { margin: 0; }
code, kbd, pre, .mono { font-family: var(--f-mono); font-size: 0.9em; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Estructura ---------- */
.wrap { width: 100%; max-width: var(--wide); margin-inline: auto; padding-inline: var(--gutter); }
.prose { max-width: var(--measure); }
.prose > * + * { margin-top: 1em; }
.prose ul, .prose ol { padding-left: 1.2em; margin-block: 0.6em 0; }
.prose li + li { margin-top: 0.35em; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.lead { font-size: var(--t-lg); color: var(--ink-2); line-height: 1.5; max-width: 60ch; }
.muted { color: var(--ink-3); }
.small { font-size: var(--t-sm); }
.eyebrow {
  font-family: var(--f-mono);
  font-size: var(--t-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
}

/* ---------- Barra de navegación ---------- */
.site-head {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50;
  background: color-mix(in srgb, var(--night-0) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.site-head .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 60px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 0.6rem;
  color: var(--ink); text-decoration: none;
  font-family: var(--f-display); font-weight: 700; font-size: 1.05rem;
}
.brand-mark { width: 26px; height: 26px; flex: none; }
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav a {
  color: var(--ink-2); text-decoration: none;
  padding: 0.45rem 0.8rem; border-radius: 999px;
  font-size: var(--t-sm);
}
.nav a:hover { color: var(--ink); background: var(--night-3); }
.nav a[aria-current="page"] { color: var(--night-0); background: var(--cyan); font-weight: 700; }
.nav-toggle { display: none; }
@media (max-width: 720px) {
  .nav-toggle {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: transparent; color: var(--ink); border: 1px solid var(--rule);
    border-radius: 8px; padding: 0.4rem 0.7rem; font: inherit; font-size: var(--t-sm); cursor: pointer;
  }
  .nav { display: none; width: 100%; padding-bottom: 0.75rem; }
  .nav.open { display: flex; }
  .nav a { flex: 1 1 45%; text-align: center; background: var(--night-2); }
}

/* ---------- Secciones ---------- */
main { display: block; }
.section { padding-block: clamp(3rem, 7vw, 6rem); }
.section + .section { border-top: 1px solid var(--rule); }
.section-head { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 2rem; max-width: var(--measure); }

.page-hero { padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(1.5rem, 4vw, 2.5rem); }
.page-hero h1 { font-size: var(--t-2xl); max-width: 22ch; }
.page-hero .lead { margin-top: 1rem; }
.toc { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.75rem; padding: 0; list-style: none; }
.toc a {
  display: inline-flex; align-items: baseline; gap: 0.5rem;
  text-decoration: none; color: var(--ink);
  border: 1px solid var(--rule); border-radius: 999px;
  padding: 0.4rem 0.9rem; font-size: var(--t-sm); background: var(--night-2);
}
.toc a:hover { border-color: var(--cyan); }
.toc .k { font-family: var(--f-mono); color: var(--cyan); font-size: var(--t-xs); }

/* ---------- Panel-instrumento (demostraciones) ---------- */
.instrument {
  background: linear-gradient(180deg, var(--night-2), color-mix(in srgb, var(--night-2) 70%, var(--night-1)));
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: clamp(14px, 2.4vw, 24px);
  display: grid;
  gap: clamp(14px, 2vw, 22px);
}
.instrument-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem 1rem; }
.instrument-head h3 { font-size: var(--t-lg); }
.tag {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0.2rem 0.55rem; border-radius: 999px; border: 1px solid var(--rule); color: var(--ink-2);
}
.tag.real { color: var(--cyan); border-color: color-mix(in srgb, var(--cyan) 45%, transparent); }
.tag.sim { color: #C9B6FF; border-color: color-mix(in srgb, var(--c-true) 55%, transparent); }
.tag.model { color: #FFB49F; border-color: color-mix(in srgb, var(--coral) 45%, transparent); }

.split { display: grid; gap: clamp(14px, 2vw, 22px); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .split { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
  .split.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .split.side { grid-template-columns: minmax(250px, 300px) minmax(0, 1fr); }
}
.grid-2 { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.figure { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.figure figcaption, .figcap { font-size: var(--t-sm); color: var(--ink-3); }
.panel-title { font-size: var(--t-sm); color: var(--ink-2); font-weight: 700; display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }

canvas.plot {
  width: 100%; display: block;
  background: var(--night-1);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  touch-action: pan-y;
}
canvas.plot.drag2d { touch-action: none; }
.ar-4-3 { aspect-ratio: 4 / 3; }
.ar-16-10 { aspect-ratio: 16 / 10; }
.ar-1 { aspect-ratio: 1 / 1; }
.ar-wide { aspect-ratio: 2.2 / 1; }
.ar-3-2 { aspect-ratio: 3 / 2; }
canvas.plot.grab { cursor: grab; }
canvas.plot.grabbing { cursor: grabbing; }

/* ---------- Controles ---------- */
.controls { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.control { display: flex; flex-direction: column; gap: 0.35rem; }
.control label, .control .label { font-size: var(--t-sm); color: var(--ink-2); display: flex; justify-content: space-between; gap: 0.5rem; }
.control output, .readout-v { font-family: var(--f-mono); color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--rule); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--rule); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--cyan); margin-top: -7px; border: 3px solid var(--night-1);
  box-shadow: 0 0 0 1px var(--cyan);
}
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--cyan); border: 3px solid var(--night-1); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font: inherit; font-size: var(--t-sm); font-weight: 700;
  padding: 0.55rem 1rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--night-3); color: var(--ink);
  text-decoration: none; line-height: 1.2;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--cyan); color: var(--night-0); border-color: var(--cyan); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn[aria-pressed="true"] { background: color-mix(in srgb, var(--cyan) 22%, var(--night-3)); border-color: var(--cyan); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button {
  font: inherit; font-size: var(--t-sm); padding: 0.45rem 0.8rem; cursor: pointer;
  background: transparent; color: var(--ink-2); border: 0; border-right: 1px solid var(--rule);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--cyan); color: var(--night-0); font-weight: 700; }
@media (max-width: 560px) {
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1 1 auto; }
}

select, input[type="number"], input[type="text"] {
  font: inherit; font-size: var(--t-sm);
  background: var(--night-1); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 8px; padding: 0.45rem 0.6rem;
  min-width: 0;
}
input[type="number"] { font-family: var(--f-mono); width: 100%; }
.check { display: inline-flex; align-items: center; gap: 0.45rem; font-size: var(--t-sm); color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--cyan); width: 16px; height: 16px; }

/* ---------- Lecturas / métricas ---------- */
.readouts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
.readout {
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 0.6rem 0.75rem;
  background: var(--night-1); display: flex; flex-direction: column; gap: 0.1rem; min-width: 0;
}
.readout .v { font-family: var(--f-display); font-size: var(--t-xl); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.readout .k { font-size: var(--t-xs); color: var(--ink-3); }
.readout.good .v { color: var(--cyan); }
.readout.bad .v { color: var(--coral); }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: var(--t-sm); color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.sw.ring { background: transparent; border: 2px solid var(--c-true); }
.sw.line { width: 18px; height: 3px; border-radius: 2px; }

.note {
  border: 1px solid var(--rule);
  background: color-mix(in srgb, var(--night-3) 55%, transparent);
  border-radius: var(--radius); padding: 0.85rem 1rem; font-size: var(--t-sm); color: var(--ink-2);
  display: flex; gap: 0.75rem; align-items: flex-start;
}
.note strong { color: var(--ink); }
.note svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--coral); }

/* ---------- Tarjetas y listas ---------- */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.card {
  background: var(--night-2); border: 1px solid var(--rule); border-radius: 12px;
  padding: 1.1rem 1.15rem; display: flex; flex-direction: column; gap: 0.5rem; min-width: 0;
}
.card h3 { font-size: var(--t-md); }
.card p { color: var(--ink-2); font-size: var(--t-sm); }
.card .icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--night-3); color: var(--cyan); }
.card .icon svg { width: 20px; height: 20px; }
a.card { text-decoration: none; color: inherit; transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--cyan); transform: translateY(-2px); }
@media (prefers-reduced-motion: reduce) { a.card:hover { transform: none; } }
a.card .go { margin-top: auto; color: var(--cyan); font-size: var(--t-sm); font-weight: 700; }

.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.stat { display: flex; flex-direction: column; gap: 0.2rem; }
.stat .v { font-family: var(--f-display); font-weight: 700; font-size: clamp(2rem, 1.5rem + 2vw, 3rem); line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 0.45em; color: var(--ink-3); font-weight: 600; margin-left: 0.2em; }
.stat .k { color: var(--ink-2); font-size: var(--t-sm); }

/* Tabla */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
th, td { text-align: left; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { color: var(--ink-3); font-weight: 700; font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.06em; background: var(--night-2); }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--f-mono); white-space: nowrap; }
td code { color: var(--cyan); }

/* Código */
.code {
  position: relative;
  background: var(--night-0);
  border: 1px solid var(--rule); border-radius: var(--radius);
  min-width: 0;
}
.code pre { margin: 0; padding: 1rem 1.1rem; overflow-x: auto; font-size: 0.86rem; line-height: 1.6; color: var(--ink); }
.code .copy { position: absolute; top: 8px; right: 8px; padding: 0.3rem 0.6rem; font-size: var(--t-xs); }
.code .copy ~ pre { padding-top: 2.6rem; }
.code .kw { color: var(--cyan); }
.code .str { color: #FFB49F; }
.code .cm { color: var(--ink-3); }
.code .nb { color: #C9B6FF; }

/* Pasos numerados (secuencia real) */
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; counter-reset: paso; }
.steps > li { counter-increment: paso; display: grid; grid-template-columns: 2.4rem minmax(0, 1fr); gap: 0.9rem; align-items: start; }
.steps > li::before {
  content: counter(paso);
  width: 2.4rem; height: 2.4rem; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--f-display); font-weight: 700;
  background: var(--night-3); color: var(--cyan); border: 1px solid var(--rule);
}
.steps h3 { font-size: var(--t-md); margin-bottom: 0.25rem; }
.steps p { color: var(--ink-2); font-size: var(--t-sm); }

/* Tooltip */
.tip {
  position: fixed; z-index: 100; pointer-events: none;
  background: var(--night-0); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 8px;
  padding: 0.5rem 0.65rem; font-size: var(--t-xs); line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  max-width: 260px; font-variant-numeric: tabular-nums;
}
.tip b { font-family: var(--f-mono); font-weight: 600; }

/* Pie */
.site-foot { border-top: 1px solid var(--rule); background: color-mix(in srgb, var(--night-0) 85%, transparent); padding-block: 2.5rem; font-size: var(--t-sm); color: var(--ink-3); }
.site-foot .wrap { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 800px) { .site-foot .wrap { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; } }
.site-foot .who { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.site-foot .who img { height: 56px; width: auto; }
.site-foot .who img.faena { height: 34px; opacity: 0.85; }
.site-foot strong { color: var(--ink-2); }
.site-foot p + p { margin-top: 0.5rem; }

/* Pasar página */
.next-page {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  border: 1px solid var(--rule); border-radius: 14px; padding: 1.25rem 1.4rem; background: var(--night-2);
  text-decoration: none; color: var(--ink);
}
.next-page:hover { border-color: var(--cyan); }
.next-page .t { font-family: var(--f-display); font-size: var(--t-lg); font-weight: 650; }
.next-page .go { color: var(--cyan); font-weight: 700; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.hide-sm { display: initial; }
@media (max-width: 560px) { .hide-sm { display: none; } }
