/* ==========================================================================
   Ya no hay excusas — formato lectura e interactivos
   Se carga después de course.css y reutiliza sus variables y componentes.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens propios (estado de los interactivos y puertas)
   -------------------------------------------------------------------------- */

:root {
  --ok: #4ade80;
  --ok-soft: rgb(74 222 128 / 0.12);
  --ko: #f87171;
  --ko-soft: rgb(248 113 113 / 0.12);
  --topbar-h: 3.25rem;
  --prose-w: 44rem;
}

:root[data-theme="light"] {
  --ok: #15803d;
  --ok-soft: rgb(21 128 61 / 0.1);
  --ko: #b91c1c;
  --ko-soft: rgb(185 28 28 / 0.08);
}

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body.reader {
  font-size: clamp(1.05rem, 0.6rem + 0.7vw, 1.2rem);
  line-height: 1.7;
  overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   Barra superior y progreso de lectura
   -------------------------------------------------------------------------- */

.read-progress {
  position: fixed;
  left: 0; top: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  box-shadow: 0 0 8px rgb(255 204 77 / 0.5);
  z-index: 40;
}

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 clamp(1rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.topbar .brand { font-size: 1rem; }
.topbar__title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__spacer { flex: 1; }
.topbar__btn {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 0.35rem;
  padding: 0.25rem 0.6rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.topbar__btn:hover { color: var(--accent); border-color: var(--accent); }
.topbar__btn--toc { display: none; }

/* --------------------------------------------------------------------------
   Portada
   -------------------------------------------------------------------------- */

.hero {
  min-height: 92vh;
  min-height: 92dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 64rem;
  margin: 0 auto;
  padding: calc(var(--topbar-h) + 2rem) clamp(1rem, 6vw, 4rem) 3rem;
}
.hero h1 { margin-bottom: 0.25em; }
.hero p { max-width: 40rem; }
.hero .subtitle { max-width: 46rem; font-size: clamp(1.05rem, 1.8vw, 1.45rem); line-height: 1.45; }
.hero__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 1rem; }
.hero__meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 2rem; }

.btn { text-decoration: none; display: inline-block; }

.resume {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 0.95rem;
  color: var(--text-soft);
  max-width: 40rem;
}
.resume[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Layout: índice lateral + texto
   -------------------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 14rem minmax(0, var(--prose-w));
  justify-content: center;
  gap: clamp(2rem, 5vw, 5rem);
  padding: 0 clamp(1rem, 4vw, 3rem) 6rem;
}

.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 2rem);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 4rem);
  overflow-y: auto;
  font-size: 0.9rem;
}
.toc__label { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); margin: 0 0 0.75rem; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc li { margin: 0; }
.toc a {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem 0.4rem 0.9rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.35;
}
.toc a::before { content: attr(data-num); font-family: var(--font-mono); font-size: 0.8em; padding-top: 0.15em; }
.toc a::after { content: ""; font-size: 0.8em; color: var(--accent); }
.toc a.is-visited::after { content: "✓"; }
.toc a:hover { color: var(--text); }
.toc a[aria-current="true"] { color: var(--accent); border-left-color: var(--accent); }

.content { min-width: 0; }

/* --------------------------------------------------------------------------
   Capítulos y prosa
   -------------------------------------------------------------------------- */

.chapter {
  padding: clamp(3.5rem, 8vh, 6rem) 0 1rem;
  border-top: 1px solid var(--border);
  scroll-margin-top: var(--topbar-h);
}
.chapter:first-child { border-top: 0; }
.chapter > h2 { margin-bottom: 0.4em; }
.chapter__lead {
  font-family: var(--font-mono);
  font-size: 0.95em;
  color: var(--accent);
  margin-bottom: 2rem;
}

.prose h3 { margin-top: 2.2em; font-size: clamp(1.25rem, 1.8vw, 1.6rem); }
.prose ul { list-style: none; padding: 0; margin: 0 0 1.2em; }
.prose ul > li { position: relative; padding-left: 1.6em; margin: 0.5em 0; color: var(--text-soft); }
.prose ul > li::before { content: "▹"; position: absolute; left: 0; color: var(--accent); }
.prose ol { padding-left: 1.4em; margin: 0 0 1.2em; color: var(--text-soft); }
.prose ol > li { margin: 0.5em 0; padding-left: 0.3em; }
.prose ol > li::marker { color: var(--accent); font-family: var(--font-mono); font-weight: 500; }
.prose blockquote { margin: 1.8em 0 0.4em; }
.prose blockquote + .cite { display: block; margin-bottom: 1.8em; }
.prose blockquote p { color: var(--text); margin: 0; }

.big-question {
  margin: 2.5rem 0;
  padding: 2rem 1rem;
  text-align: center;
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
  background: radial-gradient(ellipse 70% 70% at 50% 50%, rgb(255 204 77 / 0.08), transparent 70%);
}

/* Diálogo corto */
.dialogue { margin: 1.5rem 0; padding: 0; list-style: none; }
.dialogue li { margin: 0.5rem 0; padding: 0.6rem 1rem; border-radius: var(--radius-lg); max-width: 85%; color: var(--text-soft); }
.dialogue li:nth-child(odd) { background: var(--surface); border: 1px solid var(--border); }
.dialogue li:nth-child(even) { margin-left: auto; background: rgb(255 204 77 / 0.08); border: 1px solid var(--border-strong); color: var(--text); }
.prose .dialogue li { padding-left: 1rem; }
.prose .dialogue li::before { content: none; }

/* Escenas del capítulo 2 */
.scene { margin: 2rem 0; }
.scene h3 { margin-top: 0; }
.scene .badge { margin-bottom: 0.6rem; }
.order {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.8rem;
  margin: 1rem 0 0;
  font-size: 0.95em;
}
.order dt { font-family: var(--font-mono); font-size: 0.8em; color: var(--muted); padding-top: 0.2em; }
.order dd { margin: 0; color: var(--text-soft); }
.order dd.hl { color: var(--accent); }

/* Tres ideas en tarjetas */
.trio { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr)); margin: 1.5rem 0 2rem; }
.trio .card { padding: 1.1rem 1.2rem; }
.trio .card h4 { margin: 0 0 0.4rem; font-size: 1rem; line-height: 1.3; color: var(--text); }
.trio .card p { font-size: 0.92em; margin: 0; }

/* "En corto" */
.tldr {
  margin: 3rem 0 0;
  padding: 1.2rem 1.4rem;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}
.tldr .kicker { margin-bottom: 0.4rem; }
.tldr p { margin: 0; color: var(--text); }

/* Ciclo virtuoso */
.cycle .flow { justify-content: center; }

/* --------------------------------------------------------------------------
   Interactivos: contenedor y controles comunes
   -------------------------------------------------------------------------- */

.widget { margin: 2.5rem 0; padding: 1.75rem 1.5rem 1.5rem; }
.widget > h3 { margin: 0 0 0.3rem; font-size: 1.2rem; }
.widget__intro { font-size: 0.95em; color: var(--muted); margin-bottom: 1.2rem; }
.widget__hint { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); margin: 1rem 0 0; }

.chip {
  font: inherit;
  font-size: 0.92em;
  line-height: 1.35;
  text-align: left;
  color: var(--text-soft);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.chip:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.chip[aria-pressed="true"], .chip.is-active {
  border-color: var(--accent);
  color: var(--text);
  background: rgb(255 204 77 / 0.1);
}
.chip:disabled { cursor: default; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; margin: 0 0 1rem; }
.seg .chip { font-family: var(--font-mono); font-size: 0.8rem; padding: 0.3rem 0.7rem; }

.answer {
  margin: 0.6rem 0 0;
  padding: 0.75rem 1rem;
  font-size: 0.92em;
  border-radius: var(--radius);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  color: var(--text-soft);
}
.answer[hidden] { display: none; }

/* Excusas (cap. 0) */
.excusas { display: grid; gap: 0.75rem; }
.excusa__item .chip { width: 100%; }
.excusa__item .chip::before { content: "○ "; color: var(--muted); font-family: var(--font-mono); }
.excusa__item .chip[aria-pressed="true"]::before { content: "● "; color: var(--accent); }

/* --------------------------------------------------------------------------
   Preguntas (quiz.js)
   -------------------------------------------------------------------------- */

.quiz { margin: 0 0 1.5rem; }
.quiz:last-child { margin-bottom: 0; }
.quiz__q { color: var(--text); font-weight: 600; margin-bottom: 0.7rem; }
.quiz__options { display: grid; gap: 0.5rem; }
.quiz__opt.is-correct { border-color: var(--ok); background: var(--ok-soft); color: var(--text); }
.quiz__opt.is-wrong { border-color: var(--ko); background: var(--ko-soft); color: var(--text); }
.quiz__opt:disabled:not(.is-correct):not(.is-wrong) { opacity: 0.55; }
.quiz__verdict { font-family: var(--font-mono); font-weight: 700; margin-right: 0.4em; }
.quiz[data-state="right"] .quiz__verdict { color: var(--ok); }
.quiz[data-state="wrong"] .quiz__verdict { color: var(--ko); }

/* Pregunta suelta dentro del texto */
.check { margin: 2.5rem 0; }

/* Cartas de segundo orden */
.cards { display: grid; gap: 1rem; }
.quiz--card {
  margin: 0;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.quiz--card .quiz__first { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); margin: 0 0 0.2rem; }
.quiz--card .quiz__q { font-size: 1.05em; }

/* Clasificación en fila (¿abundante o escaso?) */
.quiz--inline {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem 1rem;
  align-items: center;
  margin: 0;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}
.quiz--inline .quiz__q { margin: 0; font-weight: 500; }
.quiz--inline .quiz__options { grid-template-columns: auto auto; gap: 0.35rem; }
.quiz--inline .quiz__opt { font-family: var(--font-mono); font-size: 0.75rem; padding: 0.3rem 0.6rem; }
.quiz--inline .answer { grid-column: 1 / -1; margin-top: 0.2rem; }
@media (max-width: 30rem) { .quiz--inline { grid-template-columns: 1fr; } }

.quiz-set__score {
  margin: 1.2rem 0 0;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  background: rgb(255 204 77 / 0.08);
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.quiz-set__score[hidden] { display: none; }

[role="tabpanel"][hidden] { display: none; }

/* --------------------------------------------------------------------------
   Simulador de Jevons
   -------------------------------------------------------------------------- */

.jevons__controls { display: grid; gap: 0.9rem; margin-bottom: 1rem; }
.jevons__slider { display: grid; gap: 0.3rem; }
.jevons__slider label { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); }
.jevons input[type="range"] { width: 100%; accent-color: var(--accent-fill); }
.jevons__stats { display: grid; gap: 0.6rem; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 1rem 0; }
.jevons__stats .stat { padding: 0.6rem 0.8rem; }
.jevons__stats .stat b { font-size: clamp(1.2rem, 2.4vw, 1.7rem); }
.jevons__stats .stat span { display: block; line-height: 1.3; }
.jevons__chart { width: 100%; height: auto; display: block; }
.jevons__chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.jevons__chart .base { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.jevons__chart .curve { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.jevons__chart .dot { fill: var(--accent-fill); stroke: var(--bg); stroke-width: 2; }
.jevons__chart text { fill: var(--muted); font-family: var(--font-mono); font-size: 11px; }
.jevons__msg { margin: 0.8rem 0 0; color: var(--text); }
.jevons__msg b { color: var(--accent); }
@media (max-width: 30rem) { .jevons__stats { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------------------
   Las dos puertas
   -------------------------------------------------------------------------- */

.doors { width: 100%; height: auto; display: block; margin: 1.5rem 0; }
.doors .ground { stroke: var(--text-soft); stroke-width: 2; }
.doors .frame { fill: none; stroke-width: 3; }
.doors .frame--ok { stroke: var(--ok); }
.doors .frame--ko { stroke: var(--ko); }
.doors .frame--door { stroke: var(--text-soft); stroke-width: 2; }
.doors .label { font-family: var(--font-sans); font-weight: 700; font-size: 17px; text-anchor: middle; }
.doors .label--ok { fill: var(--ok); }
.doors .label--ko { fill: var(--ko); }
.doors .person { fill: var(--bg); stroke: var(--text-soft); stroke-width: 1.6; }
.doors .you { opacity: 0; transition: opacity 0.4s ease, transform 0.6s ease; }
.doors .you { fill: var(--accent-fill); stroke: var(--on-accent); stroke-width: 1.6; }
.doors .you text { fill: var(--accent); stroke: none; font-family: var(--font-mono); font-size: 13px; font-weight: 700; text-anchor: middle; }
.doors[data-you] .you { opacity: 1; }
.doors[data-you="clientes"] .you { transform: translate(-190px, -20px); }
@media (prefers-reduced-motion: reduce) { .doors .you { transition: none; } }

.tareas { display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr)); }
.tareas .chip { width: 100%; height: 100%; }
.tareas .chip.door-clientes.is-revealed { border-color: var(--ok); }
.tareas .chip.door-construir.is-revealed { border-color: var(--ko); }
.puertas__status { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1rem; font-family: var(--font-mono); font-size: 0.85rem; color: var(--muted); }

/* --------------------------------------------------------------------------
   Grafo
   -------------------------------------------------------------------------- */

.grafo__stage {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  overflow: hidden;
}
.grafo__svg { width: 100%; height: auto; display: block; touch-action: manipulation; }
.grafo__svg .edge { stroke: var(--border-strong); stroke-width: 2; }
.grafo__svg .edge.is-new { stroke: var(--accent); }
.grafo__svg .node { cursor: pointer; outline: none; }
.grafo__svg .node circle {
  fill: color-mix(in srgb, var(--secondary) 28%, var(--surface-solid));
  stroke: var(--secondary);
  stroke-width: 2;
  transition: r 0.35s ease, fill 0.35s ease;
}
.grafo__svg .node.is-top circle { fill: var(--accent-fill); stroke: var(--accent-strong); }
.grafo__svg .node.is-selected circle { stroke: var(--text); stroke-width: 3; }
.grafo__svg .node:focus-visible circle { stroke: var(--accent); stroke-width: 4; }
.grafo__svg .node text {
  fill: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--surface-solid);
  stroke-width: 4px;
  pointer-events: none;
}
.grafo__svg .node.comp-1 circle { stroke: var(--ko); fill: color-mix(in srgb, var(--ko) 22%, var(--surface-solid)); }
.grafo__svg .node.comp-2 circle { stroke: var(--ok); fill: color-mix(in srgb, var(--ok) 22%, var(--surface-solid)); }
@media (prefers-reduced-motion: reduce) { .grafo__svg .node circle { transition: none; } }

.grafo__bar { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; align-items: center; margin-bottom: 0.8rem; }
.grafo__bar .seg { margin: 0; }
.grafo__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.9rem 0 0; }
.grafo__actions .chip { font-family: var(--font-mono); font-size: 0.8rem; padding: 0.35rem 0.75rem; }
.grafo__info { margin-top: 0.9rem; font-size: 0.92em; }
.grafo__info p { margin: 0 0 0.4rem; }
.grafo__rank { font-family: var(--font-mono); font-size: 0.82rem; color: var(--muted); }
.grafo__rank b { color: var(--accent); font-weight: 700; }
.grafo__alert { color: var(--ko); font-weight: 600; }
.grafo__metric-help { font-size: 0.88em; color: var(--muted); margin: 0.4rem 0 0; }

/* --------------------------------------------------------------------------
   Compromiso (cap. 7)
   -------------------------------------------------------------------------- */

.compromiso__field { display: grid; gap: 0.35rem; margin-bottom: 1rem; }
.compromiso__field label { font-family: var(--font-mono); font-size: 0.8rem; color: var(--accent); }
.compromiso textarea, .compromiso select, .compromiso input {
  font: inherit;
  font-size: 0.95em;
  color: var(--text);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  width: 100%;
  resize: vertical;
}
.compromiso textarea:focus, .compromiso select:focus, .compromiso input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.compromiso__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.compromiso__status { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }

/* --------------------------------------------------------------------------
   Créditos y pie
   -------------------------------------------------------------------------- */

.credits { margin-top: 3rem; }
.credits ul { font-size: 0.95em; }
.footer {
  padding: 2rem clamp(1rem, 4vw, 3rem) 3rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Responsive: índice como panel en pantallas estrechas
   -------------------------------------------------------------------------- */

@media (max-width: 64rem) {
  .layout { grid-template-columns: minmax(0, var(--prose-w)); }
  .topbar__btn--toc { display: inline-block; }
  .toc {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(20rem, 85vw);
    max-height: none;
    padding: 1.5rem 1rem;
    background: var(--surface-solid);
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 25;
  }
  body.toc-open .toc { transform: none; box-shadow: var(--glow-strong); }
  .topbar__title { display: none; }
}
@media (prefers-reduced-motion: reduce) { .toc { transition: none; } }

/* --------------------------------------------------------------------------
   Impresión
   -------------------------------------------------------------------------- */

@media print {
  body { background: #fff; color: #000; }
  .topbar, .read-progress, .toc, .hero__actions, .resume, .widget__hint { display: none !important; }
  .layout { display: block; padding: 0; }
  .chapter { break-before: page; }
  [hidden] { display: none !important; }

  /* Solo la tarjeta de compromiso */
  body.print-compromiso > *:not(.layout) { display: none !important; }
  body.print-compromiso .chapter > *:not(.compromiso),
  body.print-compromiso .chapter:not(#sin-excusas) { display: none !important; }
  body.print-compromiso .compromiso { box-shadow: none; border: 1px solid #000; }
  body.print-compromiso .compromiso__actions { display: none !important; }
}
