:root {
  --paper: #f3efe5;
  --paper-deep: #e7e0d2;
  --ink: #152721;
  --muted: #66716b;
  --line: #cfc7b8;
  --orange: #e75d2a;
  --teal: #14796e;
  --blue: #3c66a4;
  --gold: #bd8a25;
  --white: #fffdf8;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; overflow-x: hidden; color: var(--ink); background: var(--paper); font-family: "Manrope", sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }

.site-header { height: 70px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 max(24px, 4vw); border-bottom: 1px solid var(--line); }
.wordmark { color: var(--ink); font-size: .9rem; font-weight: 800; letter-spacing: -.03em; text-decoration: none; }
.wordmark span { color: var(--orange); }
.site-header p { margin: 0; color: var(--muted); font-family: "DM Mono", monospace; font-size: .67rem; letter-spacing: .08em; text-transform: uppercase; }
.site-header p i { padding: 0 5px; color: var(--orange); font-style: normal; }
.home-link { justify-self: end; color: var(--ink); font-size: .72rem; font-weight: 700; text-decoration: none; }
.home-link span { color: var(--orange); }

main { width: min(1440px, 92vw); margin: 0 auto; }
.hero { min-height: 480px; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); align-items: center; gap: 8vw; padding: 70px 2vw 60px; }
.overline, .chapter-label, .reading-notes > p { margin: 0 0 20px; color: var(--orange); font-family: "DM Mono", monospace; font-size: .68rem; font-weight: 500; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { text-wrap: pretty; }
h1 { margin: 0; font-family: "Newsreader", serif; font-size: clamp(3.8rem, 7.4vw, 7.2rem); font-weight: 500; letter-spacing: -.06em; line-height: .82; }
h1 em { color: var(--orange); font-weight: 500; }
.intro { max-width: 640px; margin: 30px 0 0; color: var(--muted); font-size: 1rem; line-height: 1.75; }
.hero-note { position: relative; max-width: 420px; padding: 28px 28px 18px; border: 1px solid var(--ink); background: var(--paper-deep); box-shadow: 10px 10px 0 var(--ink); transform: rotate(1.2deg); }
.hero-note > span, .equation-card span, .connection-block > span, .chart-heading span { color: var(--muted); font-family: "DM Mono", monospace; font-size: .62rem; letter-spacing: .12em; }
.hero-note > p { margin: 18px 0 25px; font-family: "Newsreader", serif; font-size: 1.45rem; line-height: 1.25; }
.zero-sum { display: flex; justify-content: space-between; align-items: flex-end; border-top: 1px solid var(--ink); }
.zero-sum b { color: var(--orange); font-family: "Newsreader", serif; font-size: 3.7rem; font-weight: 500; line-height: 1; }
.zero-sum strong { font-family: "DM Mono", monospace; font-size: 4.4rem; font-weight: 400; line-height: .95; }

.chapter-nav { display: grid; grid-template-columns: repeat(6, 1fr); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.chapter-tab { position: relative; min-height: 118px; padding: 20px; border: 0; border-right: 1px solid var(--line); color: var(--muted); background: transparent; text-align: left; transition: background 160ms ease, color 160ms ease; }
.chapter-tab:last-child { border-right: 0; }
.chapter-tab:hover { background: rgba(255,255,255,.35); }
.chapter-tab.active { color: var(--white); background: var(--ink); }
.chapter-tab small { display: block; margin-bottom: 22px; font-family: "DM Mono", monospace; font-size: .62rem; letter-spacing: .08em; }
.chapter-tab strong { display: block; max-width: 240px; font-family: "Newsreader", serif; font-size: 1.23rem; font-weight: 600; line-height: 1.08; }
.chapter-tab.active::after { content: ""; position: absolute; inset: auto 18px 8px auto; width: 16px; height: 3px; background: var(--orange); }

.workspace { padding: 76px 0 30px; }
.workspace-heading, .lab-heading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 500px); gap: 40px; align-items: end; margin-bottom: 32px; }
.workspace-heading h2, .lab-heading h2 { margin: 0; font-family: "Newsreader", serif; font-size: clamp(2.3rem, 4vw, 4rem); font-weight: 500; letter-spacing: -.045em; line-height: .95; }
.chapter-summary, .lab-heading > p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.75; }
.chapter-label { margin-bottom: 12px; }
.model-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; min-height: 650px; border: 1px solid var(--ink); background: var(--white); box-shadow: 12px 12px 0 var(--paper-deep); }
.graph-panel { min-width: 0; }
.panel-bar { height: 56px; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.panel-bar > div { display: flex; align-items: center; gap: 9px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(20,121,110,.12); }
.panel-bar strong { font-family: "DM Mono", monospace; font-size: .68rem; letter-spacing: .05em; text-transform: uppercase; }
.panel-bar small { color: var(--muted); font-family: "DM Mono", monospace; font-size: .6rem; }
.graph-actions button { padding: 7px 10px; border: 1px solid var(--line); color: var(--muted); background: transparent; font-family: "DM Mono", monospace; font-size: .58rem; text-transform: uppercase; }
.graph-actions button:hover, .graph-actions button.active { border-color: var(--ink); color: var(--white); background: var(--ink); }
.flow-state { display: inline-flex; align-items: center; gap: 7px; color: var(--teal); font-family: "DM Mono", monospace; font-size: .58rem; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.flow-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(20,121,110,.12); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; transform: scale(.72); } }
.graph-wrap { position: relative; min-height: 592px; overflow: hidden; background-image: radial-gradient(var(--line) .8px, transparent .8px); background-size: 18px 18px; }
#modelGraph { width: 100%; height: 570px; display: block; }
.edge { fill: none; stroke: #a9aaa2; stroke-width: 1.5; marker-end: url(#arrow-flow); transition: opacity 180ms ease, stroke 180ms ease, stroke-width 180ms ease; }
.edge.identity { stroke-dasharray: 5 4; marker-end: url(#arrow-identity); }
.edge.active { stroke: var(--orange); stroke-width: 2.7; }
.edge.flowing { stroke-dasharray: 7 7; animation: flow 850ms linear infinite; }
@keyframes flow { to { stroke-dashoffset: -28; } }
.edge-label { fill: var(--muted); font: 500 11px "DM Mono", monospace; paint-order: stroke; stroke: var(--white); stroke-width: 5px; stroke-linejoin: round; }
.node { cursor: pointer; outline: none; }
.node rect { fill: var(--white); stroke: var(--ink); stroke-width: 1.4; filter: url(#nodeShadow); transition: fill 150ms ease, opacity 150ms ease, stroke-width 150ms ease; }
.node .node-accent { stroke: none; filter: none; }
.node[data-type="flow"] .node-accent { fill: var(--orange); }
.node[data-type="stock"] .node-accent { fill: var(--teal); }
.node[data-type="actor"] .node-accent { fill: var(--blue); }
.node[data-type="external"] .node-accent { fill: var(--gold); }
.node .symbol { fill: var(--ink); font: 600 21px "Newsreader", serif; }
.node .label { fill: var(--muted); font: 500 10px "DM Mono", monospace; letter-spacing: .02em; }
.node:hover rect:first-child, .node.selected rect:first-child { stroke-width: 2.5; }
.node.selected rect:first-child { fill: #fff7ea; }
.graph-legend { position: absolute; left: 16px; bottom: 14px; display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 8px 11px; border: 1px solid var(--line); background: rgba(255,253,248,.9); color: var(--muted); font-family: "DM Mono", monospace; font-size: .55rem; }
.graph-legend span { display: inline-flex; align-items: center; gap: 5px; }
.graph-legend i { width: 7px; height: 7px; border-radius: 50%; }
.graph-legend .flow { background: var(--orange); } .graph-legend .stock { background: var(--teal); } .graph-legend .actor { background: var(--blue); } .graph-legend .external { background: var(--gold); }

.inspector { padding: 28px; border-left: 1px solid var(--ink); background: var(--paper-deep); }
.inspector-kicker { margin: 0 0 28px; color: var(--muted); font-family: "DM Mono", monospace; font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; }
.node-symbol { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 20px; border: 1px solid var(--ink); color: var(--white); background: var(--orange); font-family: "Newsreader", serif; font-size: 1.55rem; box-shadow: 5px 5px 0 var(--ink); }
.node-symbol.stock { background: var(--teal); }.node-symbol.actor { background: var(--blue); }.node-symbol.external { background: var(--gold); }
.inspector h3 { margin: 0; font-family: "Newsreader", serif; font-size: 2rem; font-weight: 600; line-height: 1; }
.inspector > p:not(.inspector-kicker) { min-height: 80px; margin: 18px 0 24px; color: var(--muted); font-size: .78rem; line-height: 1.65; }
.equation-card { min-height: 105px; padding: 16px; border: 1px solid var(--line); background: var(--white); }
.equation-card code { display: block; margin-top: 15px; color: var(--ink); font-family: "DM Mono", monospace; font-size: .76rem; line-height: 1.55; white-space: normal; }
.connection-block { margin-top: 28px; }
#connections { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.connection-chip { padding: 6px 8px; border: 1px solid var(--line); color: var(--ink); background: rgba(255,255,255,.42); font-family: "DM Mono", monospace; font-size: .58rem; }

.lab { margin: 80px 0; padding: 52px; color: var(--white); background: var(--ink); }
.lab .chapter-label { color: #ff8b61; }
.lab-heading > p { color: #aab7b1; }
.lab-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 52px; }
.controls { display: flex; flex-direction: column; gap: 23px; padding-top: 12px; }
.control label { display: flex; justify-content: space-between; margin-bottom: 10px; color: #cbd3cf; font-family: "DM Mono", monospace; font-size: .66rem; }
.control output { color: #ff8b61; }
.control input { width: 100%; accent-color: var(--orange); }
.control-scale { display: flex; justify-content: space-between; margin-top: 3px; color: #76847e; font-family: "DM Mono", monospace; font-size: .52rem; }
.chart-card { min-width: 0; padding: 18px 18px 10px; border: 1px solid #3c4c45; background: #1a3029; }
.chart-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 3px 4px 16px; }
.chart-heading strong { display: block; margin-top: 5px; font-family: "Newsreader", serif; font-size: 1.25rem; }
.series-legend { display: flex; gap: 12px; color: #aab7b1; font-family: "DM Mono", monospace; font-size: .55rem; }
.series-legend span { display: inline-flex; align-items: center; gap: 5px; }
.series-legend i { width: 15px; height: 2px; }
#simulationChart { width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: #355047; stroke-width: 1; }
.chart-axis-label { fill: #82928a; font: 10px "DM Mono", monospace; }
.chart-line { fill: none; stroke-width: 2.4; vector-effect: non-scaling-stroke; }
.chart-readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 5px; background: #3c4c45; }
.readout-item { padding: 10px 12px; background: #1a3029; }
.readout-item span { display: block; color: #82928a; font-family: "DM Mono", monospace; font-size: .52rem; }
.readout-item strong { display: block; margin-top: 5px; font-family: "DM Mono", monospace; font-size: .75rem; }

.reading-notes { margin: 100px 0; padding-top: 25px; border-top: 1px solid var(--ink); }
.reading-notes > div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4vw; margin-left: 24%; }
.reading-notes article > span { color: var(--orange); font-family: "DM Mono", monospace; font-size: .65rem; }
.reading-notes h3 { margin: 12px 0 9px; font-family: "Newsreader", serif; font-size: 1.45rem; }
.reading-notes article p { margin: 0; color: var(--muted); font-size: .74rem; line-height: 1.6; }
.site-footer { min-height: 90px; display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 20px max(24px, 4vw); border-top: 1px solid var(--line); color: var(--muted); font-family: "DM Mono", monospace; font-size: .58rem; text-transform: uppercase; }
.site-footer p { margin: 0; }

@media (max-width: 1000px) {
  .chapter-nav { grid-template-columns: repeat(3, 1fr); }
  .model-layout { grid-template-columns: 1fr; }
  .inspector { border-top: 1px solid var(--ink); border-left: 0; }
  .inspector > p:not(.inspector-kicker) { min-height: 0; }
  .lab-grid { grid-template-columns: 1fr; }
  .controls { display: grid; grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .site-header { grid-template-columns: 1fr 1fr; }
  .site-header p { display: none; }
  main { width: min(94vw, 680px); }
  .hero { min-height: 0; grid-template-columns: 1fr; padding: 55px 0 65px; }
  h1 { font-size: clamp(3.6rem, 18vw, 5.5rem); }
  .hero-note { max-width: none; margin: 20px 10px 0 0; }
  .chapter-nav { grid-template-columns: repeat(2, 1fr); }
  .chapter-tab { min-height: 96px; border-bottom: 1px solid var(--line); }
  .chapter-tab small { margin-bottom: 12px; }
  .chapter-tab.active::after { display: none; }
  .workspace { padding-top: 55px; }
  .workspace-heading, .lab-heading { grid-template-columns: 1fr; gap: 20px; }
  .model-layout { box-shadow: 6px 6px 0 var(--paper-deep); }
  .panel-bar { height: auto; min-height: 62px; align-items: flex-start; padding: 12px; }
  .panel-bar > div:first-child { flex-wrap: wrap; }
  #modelGraph { width: 920px; max-width: none; }
  .graph-wrap { overflow-x: auto; }
  .graph-legend { position: sticky; width: max-content; }
  .lab { width: 100vw; margin-left: calc(50% - 50vw); padding: 42px 5vw; }
  .controls { grid-template-columns: 1fr; }
  .reading-notes > div { grid-template-columns: 1fr; gap: 30px; margin-left: 0; }
  .site-footer { align-items: flex-start; flex-direction: column; }
}

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