@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #121316;
  --paper: #F4F3EF;
  --red: #E8432B;
  --light: #ECEAE4;
  --muted-on-ink: #A3A5AA;
  --muted-on-paper: #55575C;
  --gutter: clamp(20px, 5vw, 72px);
  --max: 1240px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--ink);
  color: var(--light);
  font-family: "Fraunces", Georgia, serif;
  font-weight: 400;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 0, "WONK" 0;
  font-size: clamp(17px, 1.15vw + 11px, 21px);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { display: block; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }
.band { padding: clamp(88px, 12vw, 176px) 0; }
.ink { background: var(--ink); color: var(--light); }
.paper { background: var(--paper); color: var(--ink); }
.red { background: var(--red); color: var(--paper); }

/* Hero */
.hero { position: relative; height: 100vh; height: 100svh; min-height: 480px; background: var(--ink); overflow: hidden; }
.hero iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; pointer-events: none; }
.nav {
  position: absolute; top: 0; right: 0; z-index: 2;
  display: flex; gap: clamp(18px, 2.4vw, 36px);
  padding: calc(env(safe-area-inset-top, 0px) + clamp(18px, 3vw, 36px)) var(--gutter) 0;
  font-size: 16px; letter-spacing: 0.01em;
}
.nav a {
  color: var(--muted-on-ink); text-decoration: none;
  padding: 12px 0; min-height: 44px; display: inline-flex; align-items: center;
  transition: color .2s;
}
.nav a:hover, .nav a:focus-visible { color: var(--light); }

/* Type */
.display {
  margin: 0; font-weight: 400; letter-spacing: -0.02em; line-height: 1.04;
  font-size: clamp(38px, 5.6vw, 92px); max-width: 15ch; text-wrap: balance;
}
.lede {
  margin: clamp(28px, 3.5vw, 48px) 0 0; max-width: 34em;
  color: var(--muted-on-ink); font-size: clamp(18px, 1.4vw + 10px, 26px); line-height: 1.45;
}
.kicker {
  margin: 0 0 clamp(36px, 5vw, 72px); font-size: 15px; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.ink .kicker { color: var(--muted-on-ink); }
.paper .kicker { color: var(--muted-on-paper); }

.display.small { font-size: clamp(36px, 4.6vw, 76px); max-width: 18ch; }
.night { background: #0B0C0E; color: var(--light); }
.night .kicker { color: var(--muted-on-ink); }

/* Play */
.play-band { padding-bottom: clamp(40px, 5vw, 72px); }
.play-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); gap: clamp(20px, 4vw, 72px); align-items: end; }
.play-head .kicker { margin-bottom: 18px; }
.play-how { margin: 0; color: var(--muted-on-ink); max-width: 28em; }
.play-stage {
  position: relative; margin: clamp(36px, 5vw, 64px) auto 0; width: 100%; max-width: 1600px;
  padding: 0 var(--gutter);
}
canvas.play {
  display: block; width: 100%; height: clamp(380px, 64vh, 680px);
  background: #0B0C0E; border-top: 1px solid #22242A; border-bottom: 1px solid #22242A;
  touch-action: none; cursor: crosshair;
  max-height: calc(100svh - 96px);        /* always leave room to scroll past on short screens */
}
.hud {
  position: absolute; top: 14px; left: calc(var(--gutter) + 16px);
  display: flex; gap: 22px; font-size: 15px; font-variant-numeric: tabular-nums; pointer-events: none;
}
.hud-k { color: #7D8086; margin-right: 4px; }
.flash {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.96);
  font-size: clamp(64px, 10vw, 160px); letter-spacing: -0.03em; color: var(--light);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .6s cubic-bezier(.2,.8,.2,1);
}
.flash.on { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }

/* Lab */
.lab-lede { margin: 22px 0 0; color: var(--muted-on-paper); max-width: 30em; }
.lab-grid { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.4fr); gap: clamp(28px, 4vw, 64px); margin-top: clamp(36px, 5vw, 64px); align-items: stretch; }
.levers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.lever {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
  min-height: 200px; padding: 18px 18px 16px; border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform .08s, background .15s;
}
.lever:hover { background: #ECEBE6; }
.lever:active { transform: translateY(2px); }
.lever-name { font-size: clamp(56px, 6vw, 96px); line-height: 0.9; letter-spacing: -0.03em; }
.lever-pts { font-size: 15px; color: var(--muted-on-paper); font-variant-numeric: tabular-nums; }
.lever-pop { position: absolute; right: 16px; top: 14px; font-size: 22px; color: var(--red); opacity: 0; transform: translateY(6px); transition: opacity .15s, transform .4s; }
.lever.paid .lever-pop { opacity: 1; transform: translateY(-6px); }
.record { margin: 0; border-top: 1.5px solid var(--ink); padding-top: 14px; }
.record svg { display: block; width: 100%; height: auto; overflow: visible; }
.record-grid line { stroke: #DEDDD7; stroke-width: 1; }
.rec { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.rec-a { stroke: var(--ink); }
.rec-b { stroke: var(--red); }
.ticks line { stroke-width: 2; stroke-linecap: round; }
.ticks-a line { stroke: var(--ink); }
.ticks-b line { stroke: var(--red); }
.record figcaption { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 15px; color: var(--muted-on-paper); }
.key { display: inline-block; width: 18px; height: 2.5px; }
.key-a { background: var(--ink); }
.key-b { background: var(--red); margin-left: 10px; }
.rec-axis { margin-left: auto; }
.reveal { margin-top: clamp(36px, 5vw, 64px); padding-top: 28px; border-top: 1px solid #DEDDD7; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 4vw, 64px); align-items: start; }
.reveal[hidden] { display: none; }
.reveal-result { margin: 0; font-size: clamp(26px, 2.6vw, 40px); line-height: 1.15; letter-spacing: -0.015em; text-wrap: balance; }
.reveal-note { margin: 0; color: var(--muted-on-paper); }
.again {
  grid-column: 1 / -1; justify-self: start; font: inherit; font-size: 16px; color: var(--ink); background: none;
  border: 0; border-bottom: 1.5px solid var(--ink); padding: 10px 0 4px; min-height: 44px; cursor: pointer;
}

/* Notes */
.note-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(18px, 2vw, 28px); margin-top: clamp(40px, 5vw, 72px); }
.note { border-top: 1px solid #2E3036; padding-top: 22px; }
.note .dia { display: block; width: 100%; height: auto; margin-bottom: 18px; overflow: visible; }
.note-year { margin: 0; font-size: 15px; color: var(--red); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.note h3 { margin: 6px 0 6px; font-weight: 400; font-size: clamp(22px, 1.7vw, 28px); line-height: 1.15; letter-spacing: -0.01em; }
.note-who { margin: 0 0 12px; font-size: 15px; color: #8C8F95; }
.note p:last-child { margin: 0; font-size: 16px; color: var(--muted-on-ink); line-height: 1.5; }
.dia path, .dia circle { fill: none; stroke: var(--light); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.dia-field circle, .dia-circle .in, .dia-flow .walker { fill: var(--red); stroke: none; }
.dia-field circle { animation: nudge 4s ease-in-out infinite; }
.dia-circle .ring { stroke-dasharray: 3 5; animation: spin 24s linear infinite; transform-origin: 80px 50px; }
.dia-circle .out { fill: #5A5D63; stroke: none; }
.dia-circle .i1 { animation: orbit1 5s ease-in-out infinite; }
.dia-circle .i2 { animation: orbit2 6.5s ease-in-out infinite; }
.dia-circle .i3 { animation: orbit3 4.2s ease-in-out infinite; }
.dia .axis { stroke: #4A4D53; }
.dia-steps .cum { stroke-dasharray: 260; stroke-dashoffset: 260; animation: draw 5s ease-out infinite; }
.dia-steps .tick { stroke: var(--red); stroke-width: 2; opacity: 0; animation: ticks 5s ease-out infinite; }
.dia-sdt .tri { stroke: #4A4D53; }
.dia-sdt .n { fill: var(--light); stroke: none; transform-box: fill-box; transform-origin: center; animation: pulse 3.6s ease-in-out infinite; }
.dia-sdt .n2 { animation-delay: 1.2s; } .dia-sdt .n3 { animation-delay: 2.4s; }
.dia-flow .chan { fill: rgba(232, 67, 43, 0.12); stroke: none; }
.dia-flow .walker { offset-path: path("M19 84 C50 70 70 56 90 46 S130 22 146 14"); animation: walk 6s ease-in-out infinite alternate; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(6px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes orbit1 { 0%, 100% { transform: translate(-16px, -8px); } 50% { transform: translate(14px, 12px); } }
@keyframes orbit2 { 0%, 100% { transform: translate(18px, -14px); } 50% { transform: translate(-12px, 16px); } }
@keyframes orbit3 { 0%, 100% { transform: translate(-6px, 18px); } 50% { transform: translate(10px, -20px); } }
@keyframes draw { 0% { stroke-dashoffset: 260; } 70%, 100% { stroke-dashoffset: 0; } }
@keyframes ticks { 0%, 55% { opacity: 0; } 70%, 100% { opacity: 1; } }
@keyframes pulse { 0%, 100% { transform: scale(1); fill: var(--light); } 30% { transform: scale(1.5); fill: var(--red); } 60% { transform: scale(1); } }
@keyframes walk { 0% { offset-distance: 0%; } 100% { offset-distance: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .dia * { animation: none !important; }
  .dia-steps .cum { stroke-dashoffset: 0; } .dia-steps .tick { opacity: 1; }
  .dia-flow .walker { offset-distance: 60%; }
}

/* Practice */
.practice { padding-top: clamp(72px, 9vw, 136px); border-top: 1px solid #DEDDD7; }
.cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(28px, 4vw, 64px); }
.cols article { border-top: 1.5px solid var(--ink); padding-top: 22px; }
.num { display: block; font-size: 15px; color: var(--red); letter-spacing: 0.04em; margin-bottom: 18px; }
.cols h3 { margin: 0 0 12px; font-weight: 400; font-size: clamp(30px, 2.6vw, 42px); letter-spacing: -0.015em; line-height: 1.1; }
.cols p { margin: 0; color: var(--muted-on-paper); }

/* Principles */
.rules { list-style: none; margin: 0; padding: 0; counter-reset: rule; }
.rules li {
  counter-increment: rule; display: grid; grid-template-columns: 3.2em minmax(0, 1fr); align-items: baseline;
  padding: clamp(18px, 2.2vw, 30px) 0; border-top: 1px solid #2A2C31;
  font-size: clamp(28px, 3.6vw, 56px); letter-spacing: -0.015em; line-height: 1.12;
  text-wrap: balance;
}
.rules li:last-child { border-bottom: 1px solid #2A2C31; }
.rules li::before { content: counter(rule, decimal-leading-zero); font-size: 15px; color: var(--red); letter-spacing: 0.04em; }

/* Contact */
.contact .display { max-width: 16ch; }
.mail {
  display: inline-block; margin-top: clamp(32px, 4vw, 56px);
  font-size: clamp(22px, 2.4vw, 36px); text-decoration: none;
  border-bottom: 2px solid currentColor; padding: 6px 0 4px; overflow-wrap: anywhere;
}
.mail:hover, .mail:focus-visible { border-bottom-color: transparent; }

/* Footer */
.foot { padding: 40px 0 calc(40px + env(safe-area-inset-bottom, 0px)); }
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.foot p { margin: 0; font-size: 15px; color: var(--muted-on-ink); }

:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; }
.red :focus-visible { outline-color: var(--paper); }

@media (max-width: 1100px) {
  .note-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 40px; }
}
@media (max-width: 860px) {
  .play-head, .lab-grid, .reveal { grid-template-columns: minmax(0, 1fr); }
  .play-stage { padding: 0; }
  canvas.play { height: clamp(360px, 62vh, 560px); }
  .hud { left: var(--gutter); }
  .note-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lever { min-height: 150px; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .rules li { grid-template-columns: 2.6em minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .note-grid { grid-template-columns: minmax(0, 1fr); }
  .note .dia { max-width: 240px; }
}
@media (max-width: 480px) {
  .nav { gap: 16px; font-size: 15px; }
  .foot-row { flex-direction: column; align-items: flex-start; }
}
