:root {
  --paper: #f2ecdb;
  --ink: #2a2a30;
  --ink-soft: #5d5d62;
  --ink-faint: #8b8a84;
  --blue: #3a70a8;
  --blue-faint: rgba(58, 112, 168, .28);
  --warm: #c8542a;
  --hand: "Noteworthy", "Bradley Hand", "Segoe Print", "Comic Neue", "Patrick Hand", cursive;
  --body: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --note-w: 348px;
  --dock-h: 78px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); }
body { font: 15px/1.5 var(--body); -webkit-font-smoothing: antialiased; }
#stage { position: fixed; inset: 0; display: block; touch-action: none; outline: none; }

/* ---------- Botones a lápiz ---------- */
button, summary {
  font: inherit; color: inherit; background: transparent; cursor: pointer;
  border: 1.2px solid rgba(42, 42, 48, .62);
  border-radius: 3px 9px 4px 8px / 8px 3px 9px 4px;
  padding: 7px 12px; position: relative; line-height: 1.2;
  transition: background-color .18s ease, border-color .18s ease, transform .12s ease, opacity .2s;
}
button::after, summary::after {
  content: ""; position: absolute; inset: 2px -2px -2px 1px; pointer-events: none;
  border: 1px solid rgba(42, 42, 48, .16);
  border-radius: 8px 3px 9px 4px / 3px 8px 4px 9px;
  transform: rotate(-.4deg);
}
button:hover, summary:hover { background-color: rgba(42, 42, 48, .055); }
button:active { transform: translateY(1px) rotate(-.4deg); }
button:disabled { opacity: .35; cursor: default; }
button:disabled:hover { background: transparent; }
:focus-visible { outline: 2px dashed var(--blue); outline-offset: 4px; border-radius: 4px; }
button[aria-pressed="true"], button[aria-current] {
  background-image: repeating-linear-gradient(-58deg, rgba(42, 42, 48, .13) 0 1px, transparent 1px 4px);
  border-color: var(--ink);
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .ghost { opacity: .3; stroke-width: 1; }
summary { list-style: none; display: inline-flex; gap: 7px; align-items: center; }
summary::-webkit-details-marker { display: none; }

/* ---------- Encabezado ---------- */
#top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; gap: 18px; padding: 14px 24px 10px;
}
.brand { margin: 0; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.brand b { display: block; font: 400 21px/1.05 var(--hand); letter-spacing: -.2px; }
.brand small { display: block; font: 10.5px/1.4 var(--mono); letter-spacing: 1.4px; text-transform: uppercase; color: var(--ink-faint); }
.brand-mark { width: 28px; height: 22px; border: 1.3px solid var(--ink); border-radius: 2px 5px 2px 4px; position: relative; }
.brand-mark::before { content: ""; position: absolute; left: 3px; top: 3px; width: 14px; height: 13px; border: 1px solid var(--ink-soft); }
.brand-mark::after { content: ""; position: absolute; right: 3px; top: 4px; width: 4px; height: 11px; background: repeating-linear-gradient(0deg, var(--ink-soft) 0 1px, transparent 1px 3px); }

#chapters { display: flex; gap: 6px; margin-left: auto; }
#chapters button { display: flex; gap: 7px; align-items: baseline; padding: 6px 11px; border-color: transparent; }
#chapters button::after { border-color: transparent; }
#chapters button:hover { border-color: rgba(42, 42, 48, .35); }
#chapters button[aria-current] { border-color: var(--ink); }
#chapters button[aria-current]::after { border-color: rgba(42, 42, 48, .2); }
#chapters .num { font: 11px var(--mono); color: var(--blue); }
#chapters .lbl { font: 16px var(--hand); }

.pop { position: relative; }
.pop > summary { font-size: 13px; padding: 6px 11px; border-color: rgba(42, 42, 48, .4); }
.pop[open] > summary { background-color: rgba(42, 42, 48, .06); }
.pop-body {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 10; width: min(560px, 88vw);
  max-height: 72vh; overflow: auto; padding: 18px 22px 14px; background: #f6f1e3;
  border: 1.2px solid rgba(42, 42, 48, .55); border-radius: 4px 10px 5px 9px;
  box-shadow: 0 18px 40px rgba(60, 50, 30, .16); font-size: 13.5px;
}
.pop-body h2 { font: 400 18px var(--hand); margin: 4px 0 6px; }
.pop-body p { margin: 0 0 9px; color: #3d3d42; }
.pop-body ul { padding-left: 18px; margin: 4px 0 6px; }
.pop-body li { margin-bottom: 7px; }
.pop-body a { color: var(--blue); text-underline-offset: 3px; }
.pop.up .pop-body { top: auto; bottom: calc(100% + 10px); width: 250px; }
.menu { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.menu button { text-align: left; }

/* ---------- Nota de margen ---------- */
#note {
  position: fixed; z-index: 2; left: 24px; top: 92px; width: var(--note-w);
  bottom: calc(var(--dock-h) + 16px); overflow-y: auto; padding: 4px 18px 10px 14px;
  border-left: 1px solid var(--blue-faint); scrollbar-width: thin;
}
#note::before { content: ""; position: absolute; left: 4px; top: 0; bottom: 0; border-left: 1px solid rgba(58, 112, 168, .13); }
.kicker { font: 11.5px var(--mono); letter-spacing: 2px; color: var(--blue); margin: 4px 0 6px; text-transform: uppercase; }
#title { font: 400 30px/1.12 var(--hand); margin: 0 0 14px; letter-spacing: -.3px; }
.text { font-size: 16.5px; line-height: 1.55; color: #2f2f35; min-height: 5.5em; }
.text p { margin: 0 0 10px; }
.text.in { animation: write .9s cubic-bezier(.3, .1, .2, 1) both; }
@keyframes write { from { opacity: 0; clip-path: inset(0 100% 0 0); } 40% { opacity: 1; } to { opacity: 1; clip-path: inset(0 0 0 0); } }
.text em { font-style: normal; background: linear-gradient(transparent 62%, rgba(200, 84, 42, .2) 62% 92%, transparent 92%); }
.text strong { font-weight: 600; }
.text .w { color: var(--warm); }

.scene-controls { display: flex; flex-wrap: wrap; gap: 7px; margin: 14px 0 6px; opacity: 0; transform: translateY(6px); transition: opacity .5s ease .1s, transform .5s ease .1s; visibility: hidden; }
.scene-controls > div { display: contents; }
.scene-controls.ready { opacity: 1; transform: none; visibility: visible; }
.scene-controls .group-label { flex-basis: 100%; font: 11px var(--mono); letter-spacing: 1.5px; color: var(--ink-faint); text-transform: uppercase; margin: 6px 0 0; }
.scene-controls button { font-size: 14px; padding: 7px 11px; }
.scene-controls button .n { font: 11px var(--mono); color: var(--blue); margin-right: 5px; }
.scene-controls .seg { display: inline-flex; border: 1.2px solid rgba(42, 42, 48, .6); border-radius: 3px 9px 4px 8px; }
.scene-controls .seg button { border: 0; border-radius: 0; }
.scene-controls .seg button::after { display: none; }
.scene-controls .seg button + button { border-left: 1px solid rgba(42, 42, 48, .35); }
.scene-controls .cta { border-color: var(--warm); color: #8a3315; }
.scene-controls .cta::after { border-color: rgba(200, 84, 42, .25); }
.scene-controls label.range { flex-basis: 100%; display: grid; gap: 4px; font-size: 13px; color: var(--ink-soft); }
input[type="range"] { width: 100%; accent-color: var(--ink); }
.status-chip { flex-basis: 100%; font: 12px var(--mono); letter-spacing: 1px; color: var(--ink-soft); }
.status-chip b { color: var(--warm); font-weight: 600; }
.status-chip.off b { color: var(--ink-soft); }

.defs { margin: 16px 0 10px; display: grid; gap: 9px; }
.defs div { animation: write .8s ease both; }
.defs div:nth-child(2) { animation-delay: .15s; }
.defs div:nth-child(3) { animation-delay: .3s; }
.defs div:nth-child(4) { animation-delay: .45s; }
.defs dt { font: 16px var(--hand); display: inline; }
.defs dt::after { content: " — "; color: var(--ink-faint); }
.defs dd { display: inline; margin: 0; font-size: 14px; color: #47474c; }
.scope { font: 11px/1.5 var(--mono); color: var(--ink-faint); letter-spacing: .4px; border-top: 1px dashed rgba(42, 42, 48, .2); padding-top: 8px; margin-top: 12px; }

/* ---------- Dock ---------- */
#dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; height: var(--dock-h);
  display: flex; align-items: center; gap: 16px; padding: 10px 24px calc(10px + env(safe-area-inset-bottom));
}
.nav-btn { display: flex; align-items: center; gap: 8px; padding: 9px 14px; font: 17px var(--hand); }
.nav-btn svg { width: 34px; }
.transport { flex: 1; display: flex; align-items: center; gap: 18px; min-width: 0; }
.phase-wrap { flex: 1; min-width: 0; }
.phases { list-style: none; display: flex; margin: 0 0 6px; padding: 0; gap: 4px; }
.phases li { flex: 1; font: 10.5px var(--mono); letter-spacing: .8px; text-transform: uppercase; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color .3s; }
.phases li.past { color: var(--ink-soft); }
.phases li.on { color: var(--ink); }
.phases li.on span { background: linear-gradient(transparent 70%, rgba(58, 112, 168, .3) 70%); }
.track { height: 2px; background: rgba(42, 42, 48, .14); position: relative; }
.fill { height: 100%; background: var(--ink-soft); transform-origin: left; transform: scaleX(0); }
.tools { display: flex; gap: 6px; align-items: center; }
.tools button, .tools summary { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 7px 10px; }
#play .i-play { display: none; }
#play.is-paused .i-play { display: inline; }
#play.is-paused .i-pause { display: none; }
.kbd-hint { position: fixed; right: 26px; bottom: calc(var(--dock-h) - 6px); margin: 0; font: 10px var(--mono); color: var(--ink-faint); letter-spacing: .5px; z-index: 2; pointer-events: none; }

.toast { position: fixed; left: 50%; top: 76px; transform: translate(-50%, -8px); opacity: 0; z-index: 20; font: 15px var(--hand); background: var(--paper); padding: 6px 14px; border: 1px solid rgba(42, 42, 48, .4); border-radius: 3px 8px 4px 7px; transition: opacity .25s, transform .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: 40% 0 auto; text-align: center; }

@media (max-width: 1250px) {
  :root { --note-w: 300px; }
  #chapters .lbl { font-size: 14px; }
  .tools .lbl { display: none; }
  .tools button, .tools summary { padding: 8px; }
  .kbd-hint { display: none; }
}

/* ---------- Móvil y tableta vertical ---------- */
@media (max-width: 899px) {
  :root { --dock-h: 64px; }
  #top { flex-wrap: wrap; gap: 6px 10px; padding: 8px 10px 4px; background: linear-gradient(var(--paper) 75%, rgba(242, 236, 219, 0)); }
  .brand b { font-size: 17px; }
  .brand small { display: none; }
  .brand-mark { width: 22px; height: 18px; }
  #sources { margin-left: auto; }
  #sources > summary { font-size: 12px; padding: 5px 9px; }
  #chapters { order: 3; flex-basis: 100%; margin: 0; overflow-x: auto; scrollbar-width: none; gap: 2px; }
  #chapters button { padding: 5px 8px; flex: none; }
  #chapters .lbl { font-size: 14px; }
  .pop-body { position: fixed; left: 8px; right: 8px; top: 52px; width: auto; max-height: 70vh; }
  .pop.up .pop-body { position: absolute; left: auto; right: 0; top: auto; width: 230px; }
  #note {
    left: 0; right: 0; width: auto; top: auto; bottom: var(--dock-h); max-height: 40vh; height: 40vh;
    padding: 10px 16px 8px; border-left: 0; border-top: 1px solid rgba(42, 42, 48, .28);
  }
  #note::before { display: none; }
  .kicker { margin: 0 0 2px; font-size: 10.5px; }
  #title { font-size: 22px; margin-bottom: 6px; }
  .text { font-size: 15.5px; min-height: 0; }
  #dock { gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .nav-btn { padding: 8px; }
  .nav-btn .lbl { display: none; }
  .nav-btn svg { width: 28px; }
  .transport { gap: 6px; flex-direction: column; align-items: stretch; }
  .phases li { font-size: 9px; letter-spacing: .2px; }
  .phases li:not(.on) span { visibility: hidden; }
  .tools { justify-content: center; gap: 4px; }
  .tools button, .tools summary { padding: 6px 8px; min-height: 32px; }
  .phase-wrap { order: 2; }
}
@media (max-width: 899px) and (min-height: 820px) { #note { max-height: 36vh; height: 36vh; } }

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