@font-face {
  font-family: 'Course Math';
  src: url('../shapley/fonts/STIXTwoMath-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --ink: #242424;
  --blue: #234e70;
  --rust: #a54f32;
  --teal: #007f73;
  --muted: #606060;
  --rule: #767676;
  --light-rule: #dedede;
  --paper: #fff;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
  --header-height: 64px;
  --stage-height: calc(100svh - var(--header-height));
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-height) + 18px); }
body { margin: 0; color: var(--ink); background: var(--paper); font: 1.125rem/1.65 var(--serif); }
a { color: var(--blue); text-underline-offset: .2em; text-decoration-thickness: 1px; }
p { margin: 0 0 1.2em; }
h1, h2, h3 { font-weight: 400; line-height: 1.14; letter-spacing: -.025em; }
button, input { font: inherit; }
button { min-height: 36px; padding: .35rem .8rem; border: 1px solid var(--rule); border-radius: 3px; color: var(--ink); background: var(--paper); cursor: pointer; }
button:hover:not(:disabled) { background: #f3f6f8; }
button:disabled { opacity: .4; cursor: default; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }
[hidden] { display: none !important; }
sub, sup { line-height: 0; }
.math, math { font-family: 'Course Math', 'Cambria Math', math; }
.skip-link { position: fixed; z-index: 100; top: -100px; left: 12px; padding: 10px; background: white; }
.skip-link:focus { top: 8px; }

.masthead { position: sticky; z-index: 40; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; height: var(--header-height); padding: 0 4vw; border-bottom: 1px solid var(--light-rule); background: #fffffff5; font: 14px/1.3 var(--sans); }
.masthead > a { color: var(--ink); text-decoration: none; }
.masthead nav { display: flex; gap: 24px; }
.masthead nav a { text-decoration: none; }
.reading-progress { position: fixed; z-index: 41; top: calc(var(--header-height) - 1px); right: 0; left: 0; height: 2px; }
.reading-progress span { display: block; width: 0; height: 100%; background: var(--blue); }
.title-page { display: grid; place-items: center; min-height: var(--stage-height); padding: 44px 24px 52px; text-align: center; }
.title-content { width: 100%; max-width: 1100px; }
.eyebrow { margin: 0 0 22px; color: var(--muted); font: 12px/1.5 var(--sans); letter-spacing: .13em; }
.title-page h1 { max-width: 21ch; margin: 0 auto 18px; font-size: clamp(42px, 5.4vw, 72px); line-height: 1.06; letter-spacing: -.035em; }
.title-art { width: min(100%, 820px); margin: 20px auto 6px; }
.title-art svg, .title-art img { display: block; width: 100%; height: auto; max-height: 34svh; overflow: visible; }
.start-link { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; padding: 6px; font: 15px/1.5 var(--sans); }

/* The graph and empty scroll markers share one column and one grid row. */
.story-layout { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 1200px; margin: auto; padding: 0 32px; isolation: isolate; }
.stage-shell, .scroll-track { display: none; grid-column: 1; grid-row: 1; }
html[data-enhanced='true'] .stage-shell { display: flex; }
html[data-enhanced='true'] .scroll-track { display: block; }
.stage-shell { position: sticky; top: var(--header-height); z-index: 20; flex-direction: column; align-self: start; width: 100%; min-width: 0; height: var(--stage-height); min-height: 0; padding: 12px 6px 10px; overflow-y: auto; overflow-x: hidden; background: var(--paper); pointer-events: auto; }
.scroll-track { position: relative; z-index: 0; min-width: 0; pointer-events: none; }
.step { height: calc(125svh - var(--header-height)); margin: 0; padding: 0; pointer-events: none; scroll-margin-top: var(--header-height); }
#keep-fitting { height: calc(185svh - var(--header-height)); }
#grow-one-tree, #add-stumps { height: calc(250svh - var(--header-height)); }
.stage-top { display: flex; flex: 0 0 auto; justify-content: flex-end; min-height: 15px; color: var(--muted); font: 12px/1.25 var(--sans); }
#stage-topic { display: none; }
#stage-count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.visual-heading { flex: 0 0 auto; min-height: 1.14em; margin: 3px 0 5px; text-align: center; font-size: clamp(27px, 3vw, 39px); }
.stage-equation { flex: 0 0 auto; min-height: 1.35em; margin: 0 0 3px; text-align: center; font-size: 21px; line-height: 1.35; }
.diagram { position: relative; display: flex; flex: 1 1 auto; align-items: center; justify-content: center; width: 100%; min-height: 200px; isolation: isolate; }
.diagram svg { display: block; width: 100%; height: 100%; overflow: visible; }
.transition-copy { width: min(100%, 650px); margin: 0 auto; text-align: center; font-size: clamp(20px, 2.3vw, 27px); line-height: 1.55; }
.transition-copy p { margin: 0 0 1.1em; }
.transition-copy p:last-child { margin-bottom: 0; }
.stage-shell[data-scene='6'] .visual-heading { margin-top: auto; margin-bottom: 30px; min-height: 0; }
.stage-shell[data-scene='6'] .diagram { flex: 0 0 auto; min-height: 0; padding: 0 16px 30px; }
.stage-shell[data-scene='6'] .stage-nav { margin-top: auto; }
.diagram .math-label { font-family: 'Course Math', 'Cambria Math', math; }
.diagram .muted, .diagram .axis-label { fill: var(--muted); }
.diagram .diagram-title { font-family: var(--serif); }
.diagram .point-label { paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }
.stage-caption { flex: 0 0 auto; max-width: 90ch; min-height: 2.8em; margin: 3px auto 5px; color: var(--muted); text-align: center; font: 13px/1.4 var(--sans); }
.calculation { flex: 0 0 auto; min-height: 26px; margin: 0; padding: 2px 0; color: var(--ink); text-align: center; font: 16px/1.35 'Course Math', 'Cambria Math', math; font-variant-numeric: tabular-nums; }
.calculation .readout-label { color: var(--muted); font: 11px/1.4 var(--sans); }
.stage-nav { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; padding-top: 5px; border-top: 1px solid var(--light-rule); font: 12px/1.4 var(--sans); }
.stage-nav button { min-width: 83px; font: 13px/1.4 var(--sans); }
.notes-link { text-align: center; font-size: 12px; }

.process-controls { display: grid; flex: 0 0 auto; grid-template-columns: minmax(135px, .8fr) auto minmax(190px, 1fr); align-items: center; gap: 14px; padding-top: 4px; border-top: 1px solid var(--light-rule); font: 12px/1.35 var(--sans); }
.process-status { min-height: 18px; color: var(--blue); }
.process-actions { display: flex; gap: 7px; }
.process-actions button { min-height: 30px; padding: 3px 9px; font: 11px/1.35 var(--sans); }
.process-timeline { display: grid; grid-template-columns: auto minmax(60px, 1fr); align-items: center; gap: 9px; }
.process-timeline label { color: var(--muted); font-size: 11px; }
.process-timeline input[type='range'] { width: 100%; min-height: 26px; margin: 0; accent-color: var(--blue); }
.candidate-controls { position: relative; flex: 0 0 auto; z-index: 25; font: 12px/1.4 var(--sans); }
.stage-shell:is([data-scene='0'], [data-scene='1'], [data-scene='2'], [data-scene='3'], [data-scene='4']) #candidate-controls[hidden] { display: block !important; visibility: hidden; }
.candidate-controls summary { width: fit-content; min-height: 23px; padding: 2px 0; color: var(--blue); cursor: pointer; }
.candidate-panel { position: absolute; right: 0; bottom: 100%; left: 0; max-height: min(230px, 38svh); overflow: auto; padding: 13px 15px; border: 1px solid var(--rule); background: var(--paper); }
.candidate-label { display: flex; justify-content: space-between; gap: 12px; }
.candidate-label output { color: var(--blue); font-variant-numeric: tabular-nums; }
.candidate-panel input[type='range'] { display: block; width: 100%; min-height: 32px; margin: 0; accent-color: var(--rust); }
.candidate-panel p { margin: 4px 0 0; font-size: 12px; line-height: 1.5; }
.continuation-controls { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; border-top: 1px solid var(--light-rule); font: 12px/1.4 var(--sans); }
.continuation-controls button { min-height: 30px; padding: 3px 9px; font: inherit; }
.continuation-controls span { color: var(--blue); text-align: center; }

.growth-controls { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; border-top: 1px solid var(--light-rule); font: 12px/1.4 var(--sans); }
#growth-label { min-width: 0; color: var(--blue); }
.growth-actions { display: flex; flex: 0 0 auto; gap: 7px; }
.growth-actions button { min-height: 32px; padding: 3px 9px; font: inherit; }

/* References follow the final frame. */
.afterword { max-width: 810px; margin: 20px auto 0; padding: 55px 28px 75px; border-top: 1px solid var(--rule); }
.afterword h2 { margin: 0 0 27px; font-size: clamp(31px, 4vw, 42px); }
.afterword p { margin-bottom: 23px; }
footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 20px; padding: 25px 4vw; border-top: 1px solid var(--light-rule); font: 14px/1.5 var(--sans); }
.no-script { max-width: 800px; margin: auto; padding: 24px; }

@media (max-width: 800px) {
  :root { --header-height: 56px; }
  .masthead { padding: 0 20px; }
  .masthead > a span { display: none; }
  .masthead nav { gap: 18px; }
  .title-page { padding: 34px 22px 38px; }
  .title-page h1 { font-size: clamp(40px, 9.5vw, 62px); }
  .eyebrow { margin-bottom: 22px; font-size: 10px; letter-spacing: .11em; }
  .title-art { margin: 28px auto 22px; }
  .story-layout { padding: 0 20px; }
  .stage-shell { padding: 8px 6px; }
  .stage-top { font-size: 10px; min-height: 13px; }
  .visual-heading { min-height: 2.28em; margin: 3px 0 5px; font-size: clamp(24px, 5.5vw, 32px); }
  .stage-equation { margin-bottom: 2px; font-size: 18px; }
  .diagram { min-height: 180px; }
  .stage-caption { min-height: 2.7em; margin: 2px auto 4px; font-size: 11px; line-height: 1.35; }
  .calculation { min-height: 23px; padding: 1px 0; font-size: 15px; }
  .process-controls { display: block; padding-top: 3px; font-size: 11px; }
  .process-status { min-height: 18px; }
  .process-actions { gap: 5px; }
  .process-actions button { flex: 1 1 auto; min-height: 30px; padding: 3px 5px; font-size: 10px; }
  .process-timeline { gap: 10px; }
  .process-timeline label { font-size: 10px; }
  .process-timeline input[type='range'] { min-height: 25px; }
  .candidate-controls { font-size: 11px; }
  .candidate-controls summary { min-height: 22px; }
  .candidate-panel { padding: 10px 12px; }
  .continuation-controls { font-size: 11px; }
  .growth-controls { gap: 8px; font-size: 11px; }
  .growth-actions { gap: 5px; }
  .growth-actions button { padding: 3px 6px; }
  .stage-nav { margin-top: 3px; padding-top: 4px; }
  .stage-nav button { min-height: 34px; min-width: 74px; padding: 4px 10px; font-size: 12px; }
  .notes-link { font-size: 11px; }
  .afterword { padding: 45px 22px 60px; }
  footer { padding: 22px; font-size: 13px; }
}

@media (max-width: 380px) {
  .masthead { gap: 10px; padding-right: 16px; padding-left: 16px; font-size: 12px; }
  .masthead nav { gap: 13px; }
  .story-layout { padding: 0 14px; }
  .title-page { padding-right: 16px; padding-left: 16px; }
  .title-page h1 { font-size: 39px; }
  .visual-heading { font-size: 23px; }
  .notes-link { font-size: 10px; }
}

/* Keep one stable outer height even on short screens; the stage can scroll. */
@media (max-height: 600px) {
  .stage-shell { overflow-y: auto; padding-top: 6px; padding-bottom: 6px; }
  .diagram { flex: 0 0 240px; min-height: 240px; }
  .visual-heading { font-size: 27px; }
  .stage-equation { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
  .masthead, .story-layout, .reading-progress, .start-link, .skip-link, .no-script { display: none !important; }
  .title-page { min-height: 0; padding: 20px; }
  .title-page h1 { font-size: 38px; }
  .title-art { width: min(100%, 450px); }
  .afterword { padding-top: 36px; }
  footer { font-size: 12px; }
}
