/* The world: a printed editorial spread. Paper white with a little grain, a strict column grid ruled in
   hairlines, one signal red, a big grotesk, mono labels, crop marks and one red registration target. */

@font-face { font-family: "Instrument Sans"; src: url("fonts/instrument-sans.woff2") format("woff2"); font-weight: 400 700; font-stretch: 75% 100%; font-display: block; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono.woff2") format("woff2"); font-weight: 100 800; font-display: block; }

:root {
  --paper: #f3f3ef;
  --paper-deep: #e7e7e2;
  --ink: #121212;
  --ink-2: #57574f;
  --rule: rgba(18, 18, 18, .16);
  --rule-strong: rgba(18, 18, 18, .55);
  --red: #d42019;
  --face: "Instrument Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --peel-face: var(--face);
  --peel-label: var(--mono);
  --peel-mono: var(--mono);
  --peel-radius: 2;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .07  0 0 0 0 .07  0 0 0 0 .06  .32 0 0 0 -.12'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  color-scheme: light;
}

* { box-sizing: border-box; }
html { background: var(--paper) var(--grain); scrollbar-color: var(--ink) var(--paper-deep); scrollbar-width: thin; }
body { margin: 0; color: var(--ink); font: 400 15px/24px var(--face); -webkit-font-smoothing: antialiased; overflow-x: clip; }
main { container-type: inline-size; }
::selection { background: var(--ink); color: var(--paper); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* ───────── The spread ───────── */

.booth {
  --pad: 32px;
  --gut: 16px;
  --col: calc((100cqw - 2 * var(--pad) - 11 * var(--gut)) / 12);
  --mw: calc(2 * var(--col) + var(--gut));
  --sw: calc(10 * var(--col) + 9 * var(--gut));
  --head-h: clamp(104px, 15svh, 140px);
  --sh: max(400px, calc(100svh - var(--head-h) - 168px));
  --sheet-w: var(--sw);
  --sheet-h: var(--sh);
  position: relative;
  height: max(100svh, calc(var(--sh) + var(--head-h) + 168px));
  display: grid;
  grid-template-columns: [l] var(--pad) [m] var(--mw) [m-end] var(--gut) [s] var(--sw) [s-end] var(--pad) [r];
  grid-template-rows: [run] 36px [head] var(--head-h) [gap] 24px [sheet] var(--sh) [gap2] 18px [foot] 56px [end] 1fr;
  overflow: clip;
  isolation: isolate;
}
/* Hairline rules across the whole sheet of paper: under the running head, and under the headline. */
.booth::before, .booth::after { content: ""; grid-column: l / r; height: 1px; background: var(--rule); align-self: end; pointer-events: none; transform-origin: 0 0; }
.booth::before { grid-row: run; margin: 0 var(--pad); }
.booth::after { grid-row: head; margin: 0 var(--pad) -12px; }

.run {
  grid-row: run; align-self: center; margin: 0; z-index: 3;
  font: 500 10.5px/14px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2);
}
.run--l { grid-column: m / s-end; display: flex; gap: calc(var(--mw) + var(--gut) - 4ch); }
.run--l span:first-child { min-width: 4ch; color: var(--ink); }
.run--r { grid-column: s / s-end; justify-self: end; display: inline-flex; align-items: center; gap: 8px; text-align: right; }
.run--r::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); }
.run--r[data-mode="live"] { color: var(--ink); }
.run--r[data-mode="live"]::before { background: var(--ink); animation: live 2.4s ease-in-out infinite; }
@keyframes live { 50% { opacity: .25; } }

.head {
  grid-row: head; grid-column: m / s-end; z-index: 3;
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--gut); align-items: end;
}
.head__name {
  grid-column: 1 / 5; margin: 0 0 -.135em -.055em;
  font: 700 calc(var(--head-h) * 1.32)/.8 var(--face); font-stretch: 100%; letter-spacing: -.055em;
  color: var(--red); white-space: nowrap;
}
.head__line, .head__word { align-self: end; min-height: 74px; display: flex; flex-direction: column; justify-content: flex-end; }
.head__line {
  grid-column: 5 / 10; margin: 0; padding-top: 10px; border-top: 1px solid var(--ink); max-width: 30ch;
  font: 600 clamp(20px, 1.85cqw, 27px)/1.12 var(--face); letter-spacing: -.02em; text-wrap: balance;
}
.head__word {
  grid-column: 10 / 13; margin: 0; padding-top: 10px; border-top: 1px solid var(--ink);
  font: 400 13px/17px var(--face); color: var(--ink-2); text-wrap: pretty;
}
.head__word b { font: 700 13px/17px var(--face); color: var(--ink); }
.head__word i { font: 400 11px/17px var(--mono); }

/* The margin of the proof: corrections land here, beside the sheet, with the credits under them. */
.margin { grid-row: sheet; grid-column: m; z-index: 3; display: flex; flex-direction: column; justify-content: flex-end; min-height: 0; }
.credits { margin: 0; display: grid; gap: 14px; text-align: right; }
.credit[hidden] { display: none; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.credit { display: grid; gap: 3px; padding-top: 8px; border-top: 1px solid var(--rule); }
.credit dt { font: 500 10px/12px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-2); }
.credit dd { margin: 0; font: 400 13px/17px var(--face); text-wrap: pretty; }
.credit--found { border-top-color: var(--red); }
.credit--found dt, .credit--found dd { color: var(--red); }
.credit--found dd span { display: block; }
.credit--found b { font-weight: 700; font-feature-settings: "tnum"; }
#hint-row dd { color: var(--ink); }

.proof { grid-row: sheet; grid-column: s; position: relative; width: var(--sw); height: var(--sh); }
.proof::before {
  content: ""; position: absolute; inset: 0; border-radius: calc(var(--peel-radius) * 1px);
  box-shadow: 0 0 0 .5px rgba(18, 18, 18, .18), 0 1px 1px rgba(18, 18, 18, .12), 0 14px 28px -14px rgba(18, 18, 18, .28);
}
peel-layer { width: 100%; height: 100%; }
.marks { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 0; }

/* The depth ladder, ruled like an index: [000] to [005]. */
.foot { grid-row: foot; grid-column: s; z-index: 3; }
.ladder { display: flex; height: 56px; border-top: 1px solid var(--ink); }
.ladder:focus-visible { outline-offset: 4px; }
.rung {
  flex: 1 1 0; min-width: 0; position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; align-content: start; column-gap: 8px; row-gap: 3px;
  padding: 9px 12px 0 10px; border: 0; border-left: 1px solid var(--rule);
  background: transparent; color: var(--ink); text-align: left; cursor: pointer; font: inherit;
  transition: background-color 180ms var(--ease-out), color 180ms var(--ease-out);
}
.rung:first-child { border-left-color: transparent; padding-left: 0; }
.rung i { font: 500 10px/12px var(--mono); font-style: normal; letter-spacing: .04em; color: var(--ink-2); }
.rung u { justify-self: end; align-self: center; width: 9px; height: 9px; background: var(--tone); box-shadow: inset 0 0 0 .75px var(--rule-strong); }
.rung b { font: 600 15px/18px var(--face); letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rung span { font: 400 10.5px/18px var(--mono); color: var(--ink-2); white-space: nowrap; justify-self: end; }
.rung::after { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 3px; background: var(--ink); transform: scaleX(0); transform-origin: 0 50%; transition: transform 240ms var(--ease-out); }
.rung:first-child::after { left: 0; }
.rung:hover::after { transform: scaleX(1); }
.rung:active { background: rgba(18, 18, 18, .06); }
.rung[data-on="true"] { background: var(--ink); color: var(--paper); padding-left: 10px; }
.rung[data-on="true"] i, .rung[data-on="true"] span { color: rgba(243, 243, 239, .72); }
.rung[data-on="true"] u { box-shadow: inset 0 0 0 .75px rgba(243, 243, 239, .5); }

/* Over the sheet: the plate names, the redlines, and how to start. */
.grab {
  position: absolute; left: 0; top: 0; z-index: 5; margin: 0; pointer-events: none;
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  font: 500 11px/14px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink);
  opacity: 0; transition: opacity 240ms var(--ease-out);
}
.grab[data-on] { opacity: 1; }
.grab svg { flex: none; }
.grab[data-side="left"] { flex-direction: row-reverse; }
.grab[data-side="left"] svg { transform: scaleX(-1); }
.grab[data-side="dr"] svg { transform: rotate(-135deg); }
.grab[data-side="ur"] svg { transform: rotate(135deg); }
.grab[data-side="dr"], .grab[data-side="ur"] { flex-direction: row-reverse; }
.grab[data-side="dl"] svg { transform: rotate(-45deg); }
.grab[data-side="ul"] svg { transform: rotate(45deg); }

/* ───────── After the spread ───────── */

.after { padding: 120px 0 128px; width: calc(100cqw - 64px); margin: 0 auto; display: grid; gap: 112px; border-top: 1px solid var(--rule); }
.term { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: 16px; align-items: end; }
.term__word { grid-column: 1 / 7; margin: 0 0 -.16em; font: 700 clamp(88px, 14cqw, 200px)/.8 var(--face); letter-spacing: -.06em; }
.term__def { grid-column: 8 / 13; margin: 0; padding-top: 12px; border-top: 1px solid var(--ink); font-size: 20px; line-height: 28px; text-wrap: pretty; }
.term__def i { font: 400 13px/28px var(--mono); }

.how { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: 16px; align-items: start; }
.section { grid-column: 1 / 7; margin: 0; position: sticky; top: 24px; }
.section canvas { display: block; width: 100%; aspect-ratio: 8 / 5; background: #fff; box-shadow: 0 0 0 .5px rgba(18, 18, 18, .2); }
.section figcaption { margin-top: 10px; font: 400 11px/16px var(--mono); letter-spacing: .02em; color: var(--ink-2); white-space: pre; }
.how__text { grid-column: 8 / 13; margin: 0; }
.how__text dt { padding-top: 10px; border-top: 1px solid var(--ink); font: 600 17px/24px var(--face); letter-spacing: -.01em; }
.how__text dd { margin: 4px 0 36px; max-width: 62ch; text-wrap: pretty; color: var(--ink); }
.how__text dd:last-child { margin-bottom: 0; }

.take { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.take__item { min-width: 0; display: flex; flex-direction: column; }
.take h3 { margin: 0 0 12px; padding-top: 10px; border-top: 1px solid var(--ink); font: 600 17px/24px var(--face); letter-spacing: -.01em; }
.sheet {
  margin: 0; flex: 1; padding: 18px 20px; background: var(--ink); color: #e9e9e4;
  font: 400 11.5px/20px var(--mono); overflow: auto; white-space: pre;
  scrollbar-color: #55554f transparent; scrollbar-width: thin;
}
.sheet--tall { max-height: 380px; }
.sheet ::selection { background: var(--paper); color: var(--ink); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.action {
  appearance: none; border: 0; height: 40px; padding: 0 16px; display: inline-flex; align-items: center; border-radius: 2px;
  background: var(--ink); color: var(--paper); font: 600 14px/20px var(--face); text-decoration: none; cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--ink);
  transition: transform 140ms var(--ease-out), background-color 160ms, color 160ms;
}
.action:hover { background: transparent; color: var(--ink); }
.action:active { transform: translateY(1px); }

/* ───────── Opening: the rules draw, the headline sets ───────── */
@media (prefers-reduced-motion: no-preference) {
  .booth::before, .booth::after { animation: rule 900ms var(--ease-out) both; }
  .booth::after { animation-delay: 120ms; }
  .head__name { animation: set 900ms var(--ease-out) 80ms both; }
  .head__line, .head__word, .credit, .ladder { animation: lift 700ms var(--ease-out) both; }
  .head__line { animation-delay: 200ms; }
  .head__word { animation-delay: 260ms; }
  .credit { animation-delay: 320ms; }
  .ladder { animation-delay: 360ms; }
}
@keyframes rule { from { transform: scaleX(0); } }
@keyframes set { from { clip-path: inset(0 0 100% 0); transform: translateY(.18em); } to { clip-path: inset(-.2em -.2em -.4em -.2em); } }
@keyframes lift { from { opacity: 0; transform: translateY(6px); } }

/* ───────── Narrower spreads ───────── */
@media (max-width: 1100px) {
  .booth { --mw: 0px; --gut: 0px; --sw: calc(100cqw - 2 * var(--pad)); --sh: max(400px, calc(100svh - var(--head-h) - 236px)); grid-template-rows: [run] 36px [head] var(--head-h) [gap] 24px [sheet] var(--sh) [gap2] 18px [foot] 56px [found] auto [end] 1fr; height: auto; min-height: 100svh; }
  .margin { grid-row: found; grid-column: s; justify-content: flex-start; padding: 12px 0 16px; }
  .credits { text-align: left; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .credits > :not(.credit--found):not(#hint-row) { display: none; }
  .credit--found { grid-column: 1 / -1; }
  .credit--found dd { display: flex; flex-wrap: wrap; gap: 0 18px; }
  #hint-row { grid-column: 1 / -1; }
  .run--l { gap: 24px; }
  .head__name { grid-column: 1 / 6; }
  .head__line { grid-column: 6 / 13; }
  .head__word { display: none; }
}
@media (max-width: 760px) {
  .booth { --pad: 16px; --head-h: 132px; --sh: max(380px, calc(100svh - 314px)); grid-template-rows: [run] 32px [head] var(--head-h) [gap] 16px [sheet] var(--sh) [gap2] 14px [foot] 48px [found] auto [end] 1fr; }
  .head { grid-template-columns: minmax(0, 1fr); row-gap: 10px; align-content: end; }
  .head__name { grid-column: 1; font-size: 104px; margin-bottom: -.12em; }
  .head__line { grid-column: 1; font-size: 16px; line-height: 20px; padding-top: 0; border-top: 0; max-width: 34ch; }
  .run--l { display: none; }
  .marks .red { display: none; }
  .ladder { height: 48px; }
  .rung { padding: 7px 4px 0 6px; grid-template-columns: minmax(0, 1fr); row-gap: 2px; }
  .rung:first-child { padding-left: 0; }
  .rung[data-on="true"] { padding-left: 6px; }
  .rung b { font-size: 12px; line-height: 16px; letter-spacing: 0; text-overflow: clip; }
  .rung span, .rung u { display: none; }
  .rung i { font-size: 9px; }
  .credit dd { font-size: 12px; line-height: 16px; }
  .after { padding: 72px 0 80px; gap: 72px; width: calc(100cqw - 32px); }
  .term, .how, .take { grid-template-columns: minmax(0, 1fr); row-gap: 24px; }
  .term__word, .term__def, .section, .how__text { grid-column: 1; }
  .section { position: static; }
  .term__def { font-size: 18px; line-height: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .rung, .rung::after, .action, .grab { transition: none; }
  .run--r::before { animation: none !important; }
}
