:root {
  color-scheme: light;
  --paper: #f6f3ec;
  --ink: #20243b;
  --muted: #50536a;
  --rule: #d2cbbc;
  --night: #1f243d;
  --surface: #252b46;
  --night-rule: #4a5478;
  --light: #f3f2fb;
  --quiet: #c1c7e2;
  --accent: #f4cf78;
  --feedback: #c4baff;
  --conditional: #9bdfce;
  font: 100%/1.55 "Avenir Next", "Segoe UI", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}
* { box-sizing: border-box; }
body, h1, h2, h3, h4, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }
code { font-family: "SFMono-Regular", Consolas, monospace; }
.wrap { width: min(71rem, calc(100% - 3rem)); margin-inline: auto; }
::selection { background: var(--accent); color: var(--ink); }
:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
.masthead { border-bottom: 1px solid var(--rule); }
.masthead-inner { display: flex; justify-content: space-between; align-items: center; min-height: 3.5rem; }
.masthead strong { font-size: 1.14rem; letter-spacing: -.025em; }
.masthead span { color: var(--muted); font-weight: 600; }
.intro { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 2rem; padding-block: clamp(1.7rem, 3.8vw, 3.1rem) 1.6rem; }
h1 { font-size: clamp(2rem, 5.5vw, 4.35rem); font-weight: 700; letter-spacing: -.037em; line-height: 1.02; }
.intro p { max-width: 62ch; color: var(--muted); margin-top: .8rem; }
.example { display: grid; grid-template-columns: auto auto; align-items: center; gap: .32rem 1.25rem; padding-block: .5rem; padding-inline-start: 1.25rem; border-inline-start: 1px solid var(--rule); }
.example span { font-size: .9rem; color: var(--muted); }
.example code { font-size: clamp(1rem, 2vw, 1.4rem); font-weight: 700; white-space: nowrap; }

.lesson { display: grid; grid-template-columns: minmax(16rem, 26%) minmax(0, 1fr); align-items: start; background: var(--night); color: var(--light); border: 1px solid var(--night-rule); border-radius: 14px; }
.guide { position: sticky; top: 0; z-index: 4; align-self: start; background: var(--night); border-radius: 14px 0 0 0; }
.phases { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--night-rule); }
.phases li { padding: .65rem .15rem .45rem; text-align: center; font-size: .81rem; font-weight: 600; color: var(--quiet); border-bottom: 2px solid transparent; }
.phases li:first-child { border-start-start-radius: 13px; }
.phases [aria-current] { color: var(--accent); border-color: var(--accent); background: #2d334f; }
.controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; padding: .8rem 1rem 0; }
button { min-height: 2.75rem; border: 1px solid #737fa4; padding: .35rem .55rem; border-radius: 8px; background: #2b3455; color: var(--light); font: inherit; font-weight: 600; cursor: pointer; }
button:hover:not([aria-disabled="true"]) { background: #404c73; }
button[aria-disabled="true"] { opacity: .55; cursor: default; }
button.play { grid-column: 1 / -1; background: var(--accent); border-color: var(--accent); color: var(--ink); }
button.play:hover { background: #ffe3a2; }
button.play:focus-visible { outline-color: var(--light); }
.narration { padding: .8rem 1rem .95rem; }
.count { color: var(--accent); font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.narration h2 { margin-block: .25rem .4rem; font-size: 1.21rem; letter-spacing: -.022em; line-height: 1.16; }
.narration [data-detail] { color: var(--quiet); font-size: .93rem; }
.branch-control { margin: 0 1rem .8rem; font-size: .86rem; color: var(--conditional); }
.branch-control[aria-pressed="true"] { border-color: var(--conditional); }
.static-note { padding: 0 1rem .7rem; }

.chart {
  position: relative;
  display: grid;
  gap: 1.95rem;
  padding: 1.25rem clamp(1.8rem, 4vw, 3.5rem) 1.6rem;
  border-inline-start: 1px solid var(--night-rule);
  min-width: 0;
  background: var(--surface);
  border-radius: 0 13px 13px 0;
}
.group { position: relative; display: grid; gap: 1.65rem; padding: .7rem .85rem .85rem; border: 1px solid var(--night-rule); border-radius: 12px; }
.group h3, .group h4 { position: relative; z-index: 2; justify-self: start; max-width: 100%; padding: .18rem .35rem; border-radius: 4px; background: var(--surface); color: var(--quiet); font-size: .88rem; line-height: 1.22; }
.group.reconcile { padding-block-start: .5rem; border-style: dashed; }
.group.reconcile h4 { font-size: .81rem; }
.inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; gap: .65rem; }
.node {
  position: relative;
  z-index: 2;
  display: grid;
  align-content: start;
  gap: .25rem;
  min-width: 0;
  padding: .55rem .8rem;
  border: 1px solid #657195;
  border-radius: 8px;
  background: #303859;
  font-size: .9rem;
  line-height: 1.34;
  overflow-wrap: anywhere;
}
.node strong { font-weight: 700; }
.node span { color: var(--quiet); font-size: .8rem; }
.node.optional { border-style: dashed; }
.node[data-active] { border-color: var(--accent); background: #443f46; }
.node[data-active] strong { color: var(--accent); }
.node[data-active="optional"] { border-color: var(--conditional); background: #2d444d; }
.node[data-active="optional"] strong { color: var(--conditional); }
.node.trigger { justify-self: center; min-width: 55%; text-align: center; }
.browser .node { grid-template-columns: auto minmax(0, 1fr); align-items: baseline; column-gap: .6rem; }
.browser .node.frame { grid-template-columns: 1fr; text-align: center; }
.dom-sample { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .3rem; margin-top: .25rem; }
.dom-sample li { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: .08rem .4rem; border: 1px solid #707da2; border-radius: 5px; padding: .18rem .28rem; background: var(--surface); }
.dom-sample small { color: var(--quiet); font-size: .72rem; white-space: nowrap; }
.dom-sample [data-key="d"] { border-color: var(--conditional); color: var(--conditional); }
.wires { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.edge { color: #a0aaca; }
.edge[data-branch="feedback"] { color: var(--feedback); }
.edge[data-branch="conditional"] { color: var(--conditional); }
.edge[data-active] { color: var(--accent); }
.edge[data-active][data-branch="feedback"] { color: var(--feedback); }
.edge[data-active][data-branch="conditional"], .edge[data-active="optional"] { color: var(--conditional); }
.edge-line, .pulse { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.edge[data-branch] .edge-line, .edge[data-active="optional"] .edge-line { stroke-dasharray: 4 4; }
.edge[data-active] .edge-line { stroke-width: 2.6; }
.edge .pulse { stroke: #fff5da; stroke-width: 4; opacity: 0; }
.edge text { fill: currentColor; stroke: var(--surface); stroke-width: 5px; stroke-linejoin: round; paint-order: stroke; font-size: .74rem; font-weight: 600; }
.reading { display: grid; grid-template-columns: minmax(12rem, .45fr) minmax(0, 1fr); gap: 2rem; padding-block: 2.15rem 3rem; }
.reading h2 { font-size: clamp(1.3rem, 2.6vw, 1.9rem); letter-spacing: -.027em; line-height: 1.15; }
.reading p { max-width: 70ch; }
.reading p + p { margin-top: .75rem; }
.sources { display: flex; gap: .4rem 1rem; flex-wrap: wrap; font-size: .9rem; }
.sources a { color: #433d88; text-underline-offset: .2em; }
@media (max-width: 47rem) {
  .lesson { display: block; }
  .guide { border-radius: 13px 13px 0 0; border-bottom: 1px solid var(--night-rule); }
  .controls { grid-template-columns: minmax(0, 1.65fr) repeat(2, minmax(0, 1fr)); padding: .45rem .65rem 0; }
  button.play { grid-column: auto; }
  .narration { padding: .4rem .65rem .55rem; }
  .narration h2 { font-size: 1.03rem; }
  .narration [data-detail] { font-size: .86rem; line-height: 1.35; }
  .branch-control { margin: 0 .65rem .5rem; min-height: 2.4rem; }
  .chart { border: 0; border-radius: 0 0 13px 13px; }
}
@media (max-width: 38rem) {
  .wrap { width: calc(100% - 1.15rem); }
  .intro { grid-template-columns: 1fr; gap: .6rem; }
  .example { justify-content: start; grid-template-columns: repeat(4, auto); gap: .4rem .7rem; padding: .2rem 0 0; border: 0; }
  .chart { padding-inline: 1.8rem; }
  .group { padding-inline: .32rem; gap: 1.65rem; }
  .group.reconcile { padding-inline: .875rem; }
  .inputs { gap: .38rem; }
  .node { padding-inline: .45rem; font-size: .82rem; }
  .node.trigger { min-width: 73%; }
  .group h3 { font-size: .81rem; }
  .group.reconcile h4 { font-size: .75rem; }
  .edge text { font-size: .65rem; }
  .controls button { font-size: .8rem; }
  .reading { grid-template-columns: 1fr; gap: .65rem; }
}
