/* ==========================================================================
   use-case-driven-content-kit · estilo compartido
   Terminal: todo monoespaciado, cabecera como barra de pestañas, títulos
   como comentarios (// 01) y cada simulación dentro de una ventana.
   Claro y oscuro con la misma estructura; solo cambian los colores.
   El color se reserva para estados y el rojo siempre es fallo.
   ========================================================================== */

@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,500;0,700;1,400&display=swap");

:root {
  --paper: #f7f7f5;
  --paper-2: #efefec;
  --paper-3: #e4e4e0;
  --chrome: #e9e9e5;     /* barras: cabecera y ventanas */
  --ink: #1f2328;
  --ink-strong: #0b0d10;
  --ink-soft: #636c76;
  --line: #b3bac2;
  --line-soft: #dcdfe3;
  --accent: #3d7a1c;     /* prompt, cursor, viñetas */
  --code: #b3541e;     /* código en línea */
  --shadow: rgba(20, 24, 30, 0.10);

  /* Estados: el único sitio donde hay color */
  --active: #0969da;   /* en curso, seleccionado, message en vuelo */
  --ok: #1a7f37;       /* completado */
  --slow: #9a6700;     /* lento, pendiente, en cola */
  --fail: #cf222e;     /* fallo (siempre rojo) */

  --active-bg: rgba(9, 105, 218, 0.09);
  --ok-bg: rgba(26, 127, 55, 0.09);
  --slow-bg: rgba(154, 103, 0, 0.11);
  --fail-bg: rgba(207, 34, 46, 0.08);

  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: var(--mono);

  --width-text: 46rem;
  --width-wide: 72rem;
  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1115;
    --paper-2: #161a20;
    --paper-3: #1e232b;
    --chrome: #0a0c0f;
    --ink: #d7dce3;
    --ink-strong: #ffffff;
    --ink-soft: #7d8794;
    --line: #3a434f;
    --line-soft: #242a33;
    --accent: #c3e88d;
    --code: #f78c6c;
    --shadow: rgba(0, 0, 0, 0.45);
    --active: #6cb6ff;
    --ok: #57d68d;
    --slow: #f0b34a;
    --fail: #ff6464;
    --active-bg: rgba(108, 182, 255, 0.12);
    --ok-bg: rgba(87, 214, 141, 0.11);
    --slow-bg: rgba(240, 179, 74, 0.12);
    --fail-bg: rgba(255, 100, 100, 0.12);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0f1115;
  --paper-2: #161a20;
  --paper-3: #1e232b;
  --chrome: #0a0c0f;
  --ink: #d7dce3;
  --ink-strong: #ffffff;
  --ink-soft: #7d8794;
  --line: #3a434f;
  --line-soft: #242a33;
  --accent: #c3e88d;
  --code: #f78c6c;
  --shadow: rgba(0, 0, 0, 0.45);
  --active: #6cb6ff;
  --ok: #57d68d;
  --slow: #f0b34a;
  --fail: #ff6464;
  --active-bg: rgba(108, 182, 255, 0.12);
  --ok-bg: rgba(87, 214, 141, 0.11);
  --slow-bg: rgba(240, 179, 74, 0.12);
  --fail-bg: rgba(255, 100, 100, 0.12);
  color-scheme: dark;
}

/* ---------- Base ---------- */

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.75;
  overflow-x: hidden;
}

a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--active); color: var(--active); }
:focus-visible { outline: 2px solid var(--active); outline-offset: 2px; }

h1, h2, h3 { line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); letter-spacing: -0.02em; margin: 0.2em 0 0.4em; }
h2 { font-size: 1.15rem; margin: 2.2em 0 0.6em; }
h3 { font-size: 1rem; margin: 1.8em 0 0.4em; }
h3::before { content: "## "; color: var(--ink-soft); font-weight: 400; }
p, ul, ol { margin: 0 0 1em; }
li { margin-bottom: 0.3em; }
strong { font-weight: 700; color: var(--ink-strong); }
em { color: var(--accent); }

code, kbd, .mono { font-family: var(--mono); font-size: 1em; }
code { color: var(--code); overflow-wrap: anywhere; }

/* Listas del texto con guion, como en un README */
.section ul { list-style: none; padding-left: 1.4em; }
.section ul > li::before { content: "- "; color: var(--accent); display: inline-block; width: 1.4em; margin-left: -1.4em; }

/* ---------- Estructura de página ---------- */

.header {
  border-bottom: 1px solid var(--line-soft);
  background: var(--chrome);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header__inner {
  max-width: var(--width-wide);
  margin: 0 auto;
  padding: 0.6rem 16px;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-soft);
}
/* Migas como pestañas: la última es la activa */
.header__series { text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.header__breadcrumbs { display: flex; align-items: stretch; margin: -0.6rem 0; min-width: 0; }
.header__root { text-decoration: none; white-space: nowrap; flex-shrink: 0; }
.header__root::before { content: "~/"; color: var(--ink-soft); }
.header__breadcrumbs > * { padding: 0.6rem 1rem; border-right: 1px solid var(--line-soft); }
.header__breadcrumbs > :first-child { padding-left: 0; }
.header__breadcrumbs > :last-child { background: var(--paper); color: var(--ink); box-shadow: inset 0 2px 0 var(--accent); padding-left: 1rem; }
.header__breadcrumbs .header__series::before { content: "▸ "; color: var(--accent); }
@media (max-width: 480px) {
  .header__breadcrumbs .header__root { font-size: 0; }
  .header__breadcrumbs .header__root::before { font-size: 0.8rem; }
}
.header__spacer { flex: 1; }

.theme-button {
  font: inherit;
  color: inherit;
  background: none;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 0.2rem 0.6rem;
  cursor: pointer;
  white-space: nowrap;
}
.theme-button:hover { border-color: var(--line); color: var(--ink); }

main { padding: 0 16px 4rem; }
[id] { scroll-margin-top: 4rem; }

.text {
  max-width: var(--width-text);
  margin-left: auto;
  margin-right: auto;
}
.wide {
  max-width: var(--width-wide);
  margin-left: auto;
  margin-right: auto;
}

.cover { padding-top: 3.5rem; }
.episode-label {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
}
.episode-label::before { content: "$ cat "; color: var(--ink-soft); }
.cover h1::after { content: "▍"; color: var(--accent); margin-left: 0.1em; animation: parpadeo 1.1s steps(1) infinite; }
@keyframes parpadeo { 50% { opacity: 0; } }
.lead { font-size: 1.05rem; color: var(--ink-soft); }

.meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
}
.meta span::before { content: "--"; color: var(--ink-soft); }

/* Secciones de la plantilla de episodio: numeradas como un plano */
.section { counter-increment: section; }
body { counter-reset: section; }
.section > h2::before,
.section > .text > h2::before {
  content: "// " counter(section, decimal-leading-zero) " ";
  font-weight: 400;
  color: var(--ink-soft);
}

/* Nota lateral (p. ej. "banco ficticio") */
.note {
  font-size: 0.92rem;
  border-left: 2px solid var(--accent);
  padding: 0.2rem 0 0.2rem 0.9rem;
  color: var(--ink-soft);
  margin: 1.2rem 0;
}
.note strong { color: var(--ink); }

/* Aviso callout con estado */
.callout {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin: 1.4rem 0;
  background: var(--paper-2);
}
.callout--fail { border-color: var(--fail); background: var(--fail-bg); }
.callout--ok { border-color: var(--ok); background: var(--ok-bg); }
.callout--slow { border-color: var(--slow); background: var(--slow-bg); }
.callout > :last-child { margin-bottom: 0; }

/* Enlace "ver en el mapa" */
.view-map {
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 0 0.35em;
  margin-left: 0.2em;
  vertical-align: 0.1em;
  color: var(--ink-soft);
}
.view-map::before { content: "⌖ "; }

/* ---------- Recuadro de support (desplegable, reutilizable) ---------- */

.support {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  margin: 1.2rem 0;
  font-size: 0.95rem;
}
.support > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.55rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink-soft);
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
}
.support > summary::-webkit-details-marker { display: none; }
.support > summary::before {
  content: "+";
  display: inline-block;
  width: 1ch;
  color: var(--line);
}
.support[open] > summary::before { content: "−"; }
.support > summary .support__type {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--line);
}
.support > summary:hover { color: var(--ink); }
.support__body { padding: 0 1rem 0.9rem 2.4rem; }
.support__body > :last-child { margin-bottom: 0; }

/* ---------- Tablas ---------- */

.table-wrapper { overflow-x: auto; margin: 1.2rem 0; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom-color: var(--line);
}

/* ---------- Bloques de código ---------- */

pre {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  background: var(--paper-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  overflow-x: auto;
  margin: 1rem 0;
}

/* ---------- Controles ---------- */

.button {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  line-height: 1.3;
}
.button:hover:not(:disabled) { border-color: var(--active); color: var(--active); }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button--primary { background: var(--accent); color: var(--paper); border-color: var(--accent); font-weight: 500; }
.button--primary:hover:not(:disabled) { background: var(--active); border-color: var(--active); color: var(--paper); }
.button--fail { border-color: var(--fail); color: var(--fail); }
.button--fail:hover:not(:disabled) { background: var(--fail-bg); color: var(--fail); border-color: var(--fail); }

/* Control segmented (radio buttons) */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  color: var(--ink-soft);
  border-left: 1px solid var(--line-soft);
}
.segmented label:first-of-type { border-left: 0; }
.segmented input:focus-visible + label { outline: 2px solid var(--active); outline-offset: -2px; }
.segmented input:checked + label { color: var(--ink); background: var(--paper-3); }
.segmented input[value="slow"]:checked + label { color: var(--slow); background: var(--slow-bg); }
.segmented input[value="down"]:checked + label { color: var(--fail); background: var(--fail-bg); }
.segmented input[value="ok"]:checked + label { color: var(--ok); background: var(--ok-bg); }

/* ---------- Diagramas SVG (clases comunes) ---------- */

.diagram { display: block; width: 100%; height: auto; overflow: visible; }
.diagram text { font-family: var(--mono); fill: var(--ink); }

.node rect { fill: var(--paper); stroke: var(--ink); stroke-width: 1; }
.node .node__name { font-size: 11px; font-weight: 500; text-anchor: middle; }
.node .node__state { font-size: 8.5px; text-anchor: middle; fill: var(--ink-soft); }
.node--slow rect { stroke: var(--slow); fill: var(--slow-bg); }
.node--slow .node__state { fill: var(--slow); }
.node--down rect { stroke: var(--fail); stroke-dasharray: 4 3; fill: var(--fail-bg); }
.node--down .node__state { fill: var(--fail); }
.node--active rect { stroke: var(--active); stroke-width: 2; }
.node--ok rect { stroke: var(--ok); stroke-width: 1.6; }
.node--fail rect { stroke: var(--fail); stroke-width: 2; }

.edge { fill: none; stroke: var(--line); stroke-width: 1; }
.edge--sync { stroke-dasharray: 5 4; }
.arrowhead { fill: var(--line); }

.message circle { fill: var(--active); }
.message text { font-size: 8.5px; fill: var(--active); text-anchor: middle; font-weight: 500; }
.message rect { fill: var(--paper); opacity: 0.9; }
.message--ok circle { fill: var(--ok); }
.message--ok text { fill: var(--ok); }
.message--fail circle { fill: var(--fail); }
.message--fail text { fill: var(--fail); }
.message--slow circle { fill: var(--slow); }
.message--slow text { fill: var(--slow); }

/* ---------- Siguiente episodio ---------- */

.next {
  display: block;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  background: var(--paper-2);
  margin: 1rem 0;
}
.next:hover { border-color: var(--active); color: inherit; }
.next__label { font-family: var(--mono); font-size: 0.75rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }
.next__label::before { content: "→ "; color: var(--accent); }
.next__title { font-size: 1.2rem; font-weight: 600; display: block; margin: 0.2rem 0; }
.next--pending { border-style: dashed; cursor: default; }
.next--pending:hover { border-color: var(--line); }

.footer {
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
  padding: 1.5rem 16px 3rem;
  text-align: center;
}
.footer::before { content: "[exit 0] "; color: var(--ok); }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .cover h1::after { animation: none; }
}

/* ---------- Criterio: árbol de decisión ---------- */

.tree { list-style: none; padding: 0; margin: 1.5rem 0; counter-reset: pregunta; }
.tree > li { counter-increment: pregunta; display: grid; grid-template-columns: minmax(0, 1fr) 11rem; gap: 0 1rem; margin: 0; }
.tree__question {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  background: var(--paper);
}
.tree__question::before {
  content: "P" counter(pregunta) " ";
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--line);
}
.tree__question small { display: block; color: var(--ink-soft); font-size: 0.85rem; margin-top: 0.2rem; }
.tree__yes {
  align-self: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  background: var(--paper-2);
}
.tree__yes::before { content: "sí → "; color: var(--ink-soft); }
.tree__no {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
  padding: 0.2rem 0 0.2rem 1.2rem;
  border-left: 1px solid var(--line);
  margin-left: 1.2rem;
}
.tree__final {
  display: block;
  font-family: var(--mono);
  font-size: 0.85rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
}
@media (max-width: 560px) {
  .tree > li { grid-template-columns: 1fr; }
  .tree__yes { justify-self: start; margin-top: 0.4rem; }
}
.figures { font-variant-numeric: tabular-nums; }
