/* ==========================================================================
   Lampblack
   Three materials instead of a palette:
     ink    absorbs light   (display type; multiplied onto the lit floor)
     chalk  returns light   (text type; added to the lit floor)
     ember  emits light     (coloured by black-body temperature, set from JS)
   With the lights on, all three collapse to black on paper.
   ========================================================================== */

@font-face { font-family: "LB Display"; src: url("../fonts/lb-roman-display.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "LB Roman";   src: url("../fonts/lb-roman.woff2") format("woff2");         font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "LB Roman";   src: url("../fonts/lb-italic.woff2") format("woff2");        font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "LB Roman";   src: url("../fonts/lb-bold.woff2") format("woff2");          font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "LB Mono";    src: url("../fonts/lb-mono.woff2") format("woff2");          font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "LB Math";    src: url("../fonts/lb-math.woff2") format("woff2");          font-weight: 400; font-style: normal; font-display: swap; }

:root {
  --roman: "LB Roman", "Latin Modern Roman", "CMU Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --display: "LB Display", var(--roman);
  --mono: "LB Mono", "Latin Modern Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --math: "LB Math", "Latin Modern Math", "Cambria Math", var(--roman);

  --margin: clamp(1.25rem, 4.2vw, 5rem);
  --gap: clamp(1rem, 2vw, 2.25rem);
  --step-0: clamp(1.125rem, 0.96rem + 0.55vw, 1.75rem);
  --step--1: clamp(0.95rem, 0.86rem + 0.3vw, 1.35rem);
  --step-1: clamp(1.45rem, 1.1rem + 1.25vw, 2.9rem);
  --step-label: clamp(0.6875rem, 0.58rem + 0.16vw, 0.875rem);

  /* Lights off. */
  --floor: #08080a;
  --ink: #3b3a3f;
  --chalk: #8f8b83;
  --chalk-dim: #6e6a64;
  --cold: #625e59;
  --rule: rgb(143 139 131 / 0.28);
  --blend-ink: multiply;
  --blend-chalk: plus-lighter;
  --selection-bg: transparent;
  --selection-fg: #fff;

  color-scheme: dark;
}

/* Lights on: the same page as print. Also the no-script, no-WebGL and
   high-contrast rendering (and the markup's default until boot.js says
   otherwise), so it has to stand entirely on its own. */
:root[data-lights="on"] {
  --floor: #f2efe8;
  --ink: #111112;
  --chalk: #1f1e1c;
  --chalk-dim: #5c5953;
  --cold: #1f1e1c;
  --rule: rgb(31 30 28 / 0.3);
  --blend-ink: normal;
  --blend-chalk: normal;
  --selection-bg: #111112;
  --selection-fg: #f2efe8;
  color-scheme: light;
}
/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--floor);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 4rem;
  overflow-x: clip;
}

body {
  margin: 0;
  /* The floor colour is on <html>. Anything painted on <body> would sit in
     front of the light canvas, which is at z-index -1 behind the text. */
  background: none;
  position: relative;
  font: 400 var(--step-0)/1.5 var(--roman);
  font-kerning: normal;
  font-optical-sizing: none;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  color: var(--chalk);
  overflow-x: clip;
}

::selection { background: var(--selection-bg); color: var(--selection-fg); }

h1, h2, p, ol, figure, blockquote, table { margin: 0; padding: 0; }
ol { list-style: none; }
i, em { font-style: italic; }
b, strong, th { font-weight: 700; }

a { color: inherit; text-decoration-line: underline; text-decoration-thickness: 0.045em; text-underline-offset: 0.2em; text-decoration-color: var(--rule); transition: text-decoration-color 0.25s; }
a:hover { text-decoration-color: currentColor; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; text-align: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

:focus { outline: none; }
:focus-visible { outline: 1px solid currentColor; outline-offset: 0.35em; }

kbd { font: 0.82em var(--mono); padding: 0.08em 0.42em 0.12em; border: 1px solid var(--rule); border-radius: 0.2em; }

.mono { font-family: var(--mono); font-size: var(--step-label); letter-spacing: 0.08em; text-transform: uppercase; font-variant-numeric: tabular-nums; }

.skip { position: fixed; z-index: 30; top: 0.75rem; left: 0.75rem; padding: 0.5rem 0.8rem; background: var(--chalk); color: var(--floor); text-decoration: none; transform: translateY(-300%); }
.skip:focus { transform: none; }

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

/* Copy that only makes sense in one state of the lights. */
.in-light, :root[data-lights="on"] .in-dark { display: none; }
:root[data-lights="on"] .in-light { display: revert; }

/* Controls that need scripting are not offered without it. */
:root:not(.js) :is(.switch, .end__switch, .aside) { display: none; }

.if-coarse { display: none; }
@media not ((hover: hover) and (pointer: fine)) {
  .if-fine { display: none; }
  .if-coarse { display: inline; }
}

/* ---------- Materials ---------- */

/* Blend modes need the canvas and the text in one stacking context, so nothing
   between <body> and a [data-m] element may create one (no transforms, no
   opacity, no z-index on ancestors). */
[data-m="ink"] { color: var(--ink); mix-blend-mode: var(--blend-ink); }
[data-m="chalk"] { color: var(--chalk); mix-blend-mode: var(--blend-chalk); }

.ember {
  --heat: 0;
  --hot: #ffb46b;
  color: color-mix(in srgb, var(--cold), var(--hot) calc(var(--heat) * 100%));
  mix-blend-mode: var(--blend-chalk);
}
:root[data-lights="on"] .ember { color: var(--cold); }
:root[data-lights="on"] .ember[aria-pressed="true"] { text-decoration: underline; text-decoration-thickness: 0.03em; text-underline-offset: 0.14em; }

/* ---------- The light ---------- */

.stage { position: absolute; inset: 0; z-index: -1; overflow: clip; pointer-events: none; contain: strict; }
.stage canvas { position: absolute; top: 0; left: 0; display: block; will-change: transform; }
:root[data-lights="on"] .stage, :root:not([data-lamp]) .stage, .stage canvas:not([data-live]) { visibility: hidden; }

/* ---------- Layout ---------- */

.sec {
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
  align-content: center;
  min-height: 100svh;
  padding: clamp(7rem, 22vh, 15rem) var(--margin);
}

.sec__text { grid-column: 2 / span 5; max-width: 31em; }
.sec__text > * + * { margin-top: 1.05em; }
.sec__text--wide { grid-column: 2 / span 8; max-width: none; }

h2 { font: 700 var(--step-1)/1.15 var(--roman); letter-spacing: -0.005em; margin-bottom: 0.9em; }
.sec__no { display: inline-block; min-width: 1.35em; }

.runin { margin-right: 0.35em; }

.sec__num {
  position: absolute;
  font: 400 clamp(15rem, 52vh, 34rem)/0.74 var(--display);
  letter-spacing: -0.04em;
  user-select: none;
  pointer-events: none;
}

/* Title page */
.hero { grid-template-rows: 1fr auto auto; align-content: stretch; padding-top: clamp(6rem, 17vh, 11rem); padding-bottom: clamp(2.25rem, 6vh, 4rem); }
.hero__abstract { grid-column: 8 / span 4; align-self: start; max-width: 25em; }
.hero__abstract > * + * { margin-top: 1.05em; }
.hero__title {
  grid-column: 1 / -1;
  font: 400 21.4vw/0.8 var(--display);
  letter-spacing: -0.028em;
  margin: 0 0 0.02em -0.055em;
  white-space: nowrap;
}
.hero__meta { grid-column: 1 / -1; margin-top: clamp(1.25rem, 3.5vh, 2.5rem); color: var(--chalk-dim); }

/* 1 Ink */
.sec--ink .sec__text { grid-column: 2 / span 4; align-self: center; }
.sec--ink .sec__num, .sec--method .sec__num { display: none; }
.eq { align-self: center; }
.eq--ink { grid-column: 7 / -1; }
.eq__body {
  font: italic 400 clamp(4.5rem, 12.6vw, 14rem)/1 var(--roman);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.eq__body i { font-style: italic; }
.eq__op { font-family: var(--display); font-style: normal; margin: 0 0.2em; }
.eq__body sup, .eq__body sub { font-size: 0.56em; line-height: 0; position: relative; vertical-align: baseline; }
.eq__body sup { top: -0.74em; margin-left: 0.04em; }
.eq__body sub { top: 0.26em; font-style: normal; font-family: var(--display); margin: 0 0.06em 0 0.02em; }
.eq__body sup .eq__op { margin: 0 0.06em 0 0; }
.gk { font-family: var(--math); font-style: normal; }
.eq figcaption { display: grid; grid-template-columns: 3.1em minmax(0, 1fr); font-size: var(--step--1); line-height: 1.45; max-width: 30em; margin-top: 2.2em; }

/* 2 Chalk */
.sec--chalk { align-content: center; row-gap: clamp(4rem, 12vh, 8rem); }
.quote { grid-column: 1 / span 8; }
.quote blockquote { font: italic 400 clamp(1.7rem, 3.5vw, 3.7rem)/1.2 var(--roman); letter-spacing: -0.005em; text-wrap: balance; }
.quote blockquote p { text-indent: -0.46em; }
.quote figcaption { margin-top: 1.6em; font-size: var(--step--1); }
.sec--chalk .sec__text { grid-column: 7 / span 5; }
.sec--chalk .sec__num { right: calc(var(--margin) * 0.6); top: 9vh; }

/* 3 Ember */
.sec--ember { align-content: start; row-gap: clamp(3rem, 8vh, 6rem); }
.sec--ember .sec__text { grid-column: 2 / span 4; grid-row: 1; align-self: start; }
.sec--ember .sec__num { left: calc(var(--margin) * 0.55); bottom: 10vh; }
.ladder { grid-column: 7 / -1; grid-row: 1; }
.ladder li { display: flex; align-items: baseline; justify-content: space-between; gap: 1.5rem; border-top: 1px solid var(--rule); padding: 0.5rem 0 0.9rem; }
.ladder li:last-child { border-bottom: 1px solid var(--rule); }
.ember { font: 400 clamp(2.7rem, 6.9vw, 7rem)/1.02 var(--display); letter-spacing: -0.02em; white-space: nowrap; touch-action: manipulation; }
.ladder__k { color: var(--chalk-dim); flex: none; }
.ladder figcaption { margin-top: 1.6em; font-size: var(--step--1); max-width: 27em; }

/* 4 Mark */
.sec--mark .sec__text { grid-column: 2 / span 8; }
.lede { font-size: clamp(1.55rem, 3.05vw, 3.1rem); line-height: 1.24; letter-spacing: -0.008em; max-width: 21em; text-wrap: pretty; }
.sec__text > .aside { font-size: var(--step--1); margin-top: 2.2em; }
.link { text-decoration: underline; text-decoration-thickness: 0.045em; text-underline-offset: 0.2em; text-decoration-color: var(--rule); transition: text-decoration-color 0.25s; }
.link:hover { text-decoration-color: currentColor; }
.sec--mark .sec__num { right: calc(var(--margin) * 0.8); bottom: 12vh; }

/* 5 Company */
.sec--company { align-content: start; }
.sec--company .sec__text { grid-column: 7 / span 5; }
.sec--company .sec__num { left: calc(var(--margin) * 0.6); top: 16vh; }
.dark { grid-column: 1 / -1; min-height: 92svh; display: grid; place-items: center; }
.dark figcaption { font-size: var(--step--1); color: var(--chalk-dim); }

/* 6 Method */
.sec--method { align-content: start; row-gap: clamp(5rem, 14vh, 9rem); padding-bottom: clamp(3rem, 8vh, 5rem); }
.sec--method .sec__text { grid-column: 2 / span 5; }
.table { grid-column: 8 / span 4; align-self: end; }
table { width: 100%; border-collapse: collapse; }
caption { text-align: left; font: 400 var(--step--1)/1.4 var(--roman); letter-spacing: 0; text-transform: none; padding-bottom: 0.9em; }
th, td { padding: 0.62em 0; border-top: 1px solid var(--rule); font-weight: 400; text-align: left; vertical-align: baseline; }
tr:last-child > * { border-bottom: 1px solid var(--rule); }
td { text-align: right; color: var(--chalk); white-space: nowrap; }
th { color: var(--chalk-dim); }
.eq--merge { grid-column: 1 / -1; justify-self: center; }
.eq--merge .eq__body { font-size: clamp(3.6rem, 11.5vw, 12.5rem); }

.endmatter { grid-column: 2 / span 10; display: grid; grid-template-columns: subgrid; font-size: var(--step--1); line-height: 1.45; }
.refs { grid-column: 1 / span 6; }
.refs h2 { font-size: var(--step-0); margin-bottom: 1em; }
.refs ol { counter-reset: ref; }
.refs li { counter-increment: ref; position: relative; padding-left: 2.4em; }
.refs li + li { margin-top: 0.7em; }
.refs li::before { content: "[" counter(ref) "]"; position: absolute; left: 0; }
.refs a { overflow-wrap: anywhere; }
.notes { grid-column: 8 / span 3; align-self: end; }
.notes ol { counter-reset: note; }
.notes li { counter-increment: note; position: relative; padding-left: 1.2em; }
.notes li::before { content: counter(note); position: absolute; left: 0; font-size: 0.7em; top: -0.1em; }
.notes a { text-decoration: none; }
.fn { font-size: 0.68em; vertical-align: 0.5em; line-height: 0; margin-left: 0.08em; text-decoration: none; }
.cite { text-decoration: none; }

.end { grid-column: 1 / -1; display: grid; justify-items: center; gap: 2.4rem; padding-top: clamp(3rem, 12vh, 8rem); }
.end__switch { font: 400 clamp(2rem, 5.4vw, 5.4rem)/1.05 var(--display); letter-spacing: -0.02em; padding: 0.2em 0.1em; touch-action: manipulation; }
.end__note { color: var(--chalk-dim); text-align: center; line-height: 1.7; }

:target { scroll-margin-top: 30vh; }
.refs li:target, .notes li:target { text-decoration: underline; text-decoration-thickness: 0.045em; text-underline-offset: 0.2em; }

/* 404.html: no engine, no script; plain chalk on the unlit floor. */
.lost { color: var(--chalk); }
.lost__code { font-weight: 400; color: var(--chalk-dim); margin-bottom: 2.4em; }
.lost__back { font-size: var(--step--1); margin-top: 2.2em; }

/* ---------- Instrument chrome ---------- */

.hud {
  position: fixed; z-index: 10; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 1.5rem;
  padding: 0 var(--margin);
  font: 400 var(--step-label)/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; font-variant-numeric: tabular-nums;
  color: var(--chalk-dim);
  mix-blend-mode: var(--blend-chalk);
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud--top { top: 0; height: clamp(3.25rem, 8vh, 4.75rem); padding-top: env(safe-area-inset-top); }
.hud--bottom { bottom: 0; height: clamp(2.75rem, 7vh, 4rem); padding-bottom: env(safe-area-inset-bottom); pointer-events: none; }
.hud--bottom > * { pointer-events: none; }
.hud__mark { text-decoration: none; padding: 0.9rem 0; color: var(--chalk); }
.hud__controls { display: flex; gap: clamp(1rem, 2.5vw, 2.25rem); }
.switch { padding: 0.9rem 0; letter-spacing: inherit; text-transform: inherit; touch-action: manipulation; transition: color 0.25s; }
.switch:hover, .switch[aria-pressed="true"] { color: var(--chalk); }
.switch__state { display: inline-block; min-width: 1.9em; }
.hud__read { text-align: right; white-space: pre; }

.toc { position: fixed; z-index: 10; right: calc(var(--margin) * 0.38); top: 50%; translate: 0 -50%; font: 400 var(--step-label)/1 var(--mono); color: var(--chalk-dim); mix-blend-mode: var(--blend-chalk); }
.toc ol { display: grid; }
.toc a { display: block; padding: 0.62rem 0.5rem; text-decoration: none; position: relative; transition: color 0.25s; }
.toc a::before { content: ""; position: absolute; right: -0.15rem; top: 50%; width: 0; height: 1px; background: currentColor; transition: width 0.35s cubic-bezier(0.2, 0.7, 0.2, 1); }
.toc a:hover, .toc a[aria-current] { color: var(--chalk); }
.toc a[aria-current]::before { width: 0.45rem; }

/* The lamp replaces the pointer wherever it is lit. */
.cursor { display: none; }
@media (hover: hover) and (pointer: fine) {
  :root[data-lamp="on"], :root[data-lamp="on"] * { cursor: none !important; }
  :root[data-lamp="on"] .cursor {
    display: block; position: fixed; z-index: 40; top: 0; left: 0; width: 0; height: 0; pointer-events: none;
    transform: translate3d(var(--x, -100px), var(--y, -100px), 0);
  }
  .cursor::before {
    content: ""; position: absolute; left: -3px; top: -3px; width: 6px; height: 6px; border-radius: 50%;
    background: #fff6e6; box-shadow: 0 0 0 0 rgb(255 246 230 / 0);
    transition: 0.28s cubic-bezier(0.2, 0.7, 0.2, 1);
    transition-property: width, height, left, top, border-radius, background-color, box-shadow, opacity;
  }
  .cursor[data-over="action"]::before { left: -17px; top: -17px; width: 34px; height: 34px; background: rgb(255 246 230 / 0); box-shadow: 0 0 0 1px rgb(255 246 230 / 0.85); }
  .cursor[data-over="text"]::before { left: -0.5px; top: -11px; width: 1.5px; height: 22px; border-radius: 1px; }
  .cursor[data-down]::before { opacity: 0.55; }
  .cursor[data-hidden]::before { opacity: 0; }
}

/* ---------- Lights on ---------- */

:root[data-lights="on"] .dark figcaption i::after { content: " (It isn’t now.)"; }

::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { animation: flood 0.9s cubic-bezier(0.3, 0, 0.1, 1) both; }
@keyframes flood {
  from { clip-path: circle(0 at var(--vt-x, 50%) var(--vt-y, 50%)); }
  to { clip-path: circle(var(--vt-r, 150vmax) at var(--vt-x, 50%) var(--vt-y, 50%)); }
}

/* ---------- Narrower than a paper ---------- */

@media (max-width: 1023px) {
  .sec__text, .sec--ink .sec__text, .sec--chalk .sec__text, .sec--ember .sec__text, .sec--company .sec__text, .sec--method .sec__text { grid-column: 2 / span 7; }
  .sec--mark .sec__text { grid-column: 2 / span 10; }
  .hero__abstract { grid-column: 6 / span 6; }
  .sec--ink { row-gap: clamp(4rem, 12vh, 7rem); }
  .eq--ink { grid-column: 2 / -1; }
  .eq__body { font-size: clamp(4.5rem, 19vw, 11rem); }
  .quote { grid-column: 1 / span 11; }
  .quote blockquote { font-size: clamp(1.7rem, 5vw, 3rem); }
  .sec--ember .sec__text, .ladder { grid-row: auto; }
  .ladder { grid-column: 2 / -1; }
  .ember { font-size: clamp(2.7rem, 10.5vw, 6rem); }
  .table { grid-column: 2 / span 7; }
  .endmatter { grid-column: 2 / span 10; display: block; }
  .notes { margin-top: 2.5em; }
  /* No margin left to float in: the numerals open each section instead. */
  .sec { align-content: start; }
  .sec__num { position: static; grid-column: 1 / -1; font-size: clamp(14rem, 44vw, 24rem); text-align: right; margin: 0 -0.03em clamp(3rem, 9vh, 6rem) 0; }
}

@media (max-width: 639px) {
  :root { --margin: 1.25rem; --gap: 0.75rem; }
  .toc, .hud--bottom { display: none; }
  /* The top bar steps aside while reading down and returns on the way up. */
  .hud--top { transition: translate 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }
  :root[data-hud="away"] .hud--top:not(:focus-within) { translate: 0 -110%; }
  .sec { display: block; padding-block: clamp(6rem, 18vh, 9rem); }
  .sec > * + * { margin-top: clamp(3.5rem, 10vh, 5.5rem); }
  .sec__text { max-width: none; }
  .sec__num { font-size: 58vw; margin-bottom: 0; }
  .sec > .sec__num + * { margin-top: clamp(2.5rem, 7vh, 4rem); }

  .hero { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr auto auto; padding-top: 6.5rem; }
  .hero > * + * { margin-top: 0; }
  .hero__abstract, .hero__title, .hero__meta { grid-column: 1; }
  .hero__abstract { max-width: 19em; }
  .hero__title { font-size: 40.5vw; line-height: 0.78; white-space: normal; margin-bottom: 0.05em; }
  .hero__title span { display: block; }
  .hero__title span + span { margin-left: 0.02em; }
  .hero__meta { margin-top: 1.5rem; }
  .hero__meta-rev { display: block; margin-top: 0.6em; }
  .hero__meta-rev::first-letter { text-transform: uppercase; }
  .hero__meta-comma { display: none; }

  .eq__body { font-size: 21vw; }
  .eq figcaption { margin-top: 1.8em; }
  .ember { font-size: 13.2vw; }
  .ladder li { padding: 0.35rem 0 0.7rem; gap: 0.75rem; }
  .dark { min-height: 78svh; }
  .eq--merge .eq__body { font-size: 14.2vw; }
  .end__switch { font-size: 11vw; }
}

/* ---------- Preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  ::view-transition-new(root) { animation: none; }
}

@media (forced-colors: active) {
  .stage, .cursor { display: none !important; }
  [data-m], .ember, .hud, .toc { mix-blend-mode: normal; color: CanvasText; }
}

@media print {
  :root, :root[data-lights] {
    --floor: #fff; --ink: #000; --chalk: #000; --chalk-dim: #333; --cold: #000; --rule: #999;
    --blend-ink: normal; --blend-chalk: normal;
  }
  .stage, .hud, .toc, .cursor, .skip, .end__switch, .aside, .if-fine { display: none !important; }
  .sec { min-height: 0; padding-block: 2.5rem; break-inside: avoid; }
  .dark { min-height: 6rem; }
}
