/* Scenes that the scroll drives.

   A scene is a part of the page whose picture is worked out from one
   number, --p, which runs from 0 to 1 as the reader scrolls through it.
   Scroll a little and it moves a little; scroll back and it runs backwards.
   A scene holds still on the screen meanwhile (.pin) and, while it does,
   takes the whole of it from edge to edge (.whole): one large thing, and
   one statement beside it in the heavy face.

   A scene is long: three or four screens of scrolling, so that it is still
   there for someone who scrolls as people do, fast and without looking. It
   is cut into beats. Each beat is most of a screen long, eased at both
   ends, and there is a stretch between beats, and at each end of the scene,
   where nothing changes and what is there can be read. --s1 and --l1 say
   where the first beat starts and how long it is, as shares of the scene;
   --b1 is how far through it the scroll is, and --e1 the same, eased.

   Where the browser has scroll-driven animations, the styles here work --p
   out themselves. Elsewhere js/scenes.js sets it, from the same arithmetic
   (html.by-script). Either way only transforms and opacities are drawn from
   it (and the dash of a pen stroke, and how far along it the pen is):
   nothing is laid out again on scroll.

   The scroll only drives anything on html.scrubs, which js/boot.js sets. As
   pages, with less motion asked for, or with scripts off, --p is 1: every
   scene is simply shown finished, in its place in the text, and nothing is
   held. Nothing outside a scene changes with the scroll at all. */

@property --p { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b1 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b2 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b3 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b4 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b5 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b6 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b7 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --b8 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e1 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e2 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e3 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e4 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e5 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e6 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e7 { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --e8 { syntax: "<number>"; inherits: true; initial-value: 1; }

.scene {
  --p: 1;
  --b1: clamp(0, calc((var(--p) - var(--s1, 0)) / var(--l1, 1)), 1);
  --b2: clamp(0, calc((var(--p) - var(--s2, 0)) / var(--l2, 1)), 1);
  --b3: clamp(0, calc((var(--p) - var(--s3, 0)) / var(--l3, 1)), 1);
  --b4: clamp(0, calc((var(--p) - var(--s4, 0)) / var(--l4, 1)), 1);
  --b5: clamp(0, calc((var(--p) - var(--s5, 0)) / var(--l5, 1)), 1);
  --b6: clamp(0, calc((var(--p) - var(--s6, 0)) / var(--l6, 1)), 1);
  --b7: clamp(0, calc((var(--p) - var(--s7, 0)) / var(--l7, 1)), 1);
  --b8: clamp(0, calc((var(--p) - var(--s8, 0)) / var(--l8, 1)), 1);
  --e1: calc(var(--b1) * var(--b1) * (3 - 2 * var(--b1)));
  --e2: calc(var(--b2) * var(--b2) * (3 - 2 * var(--b2)));
  --e3: calc(var(--b3) * var(--b3) * (3 - 2 * var(--b3)));
  --e4: calc(var(--b4) * var(--b4) * (3 - 2 * var(--b4)));
  --e5: calc(var(--b5) * var(--b5) * (3 - 2 * var(--b5)));
  --e6: calc(var(--b6) * var(--b6) * (3 - 2 * var(--b6)));
  --e7: calc(var(--b7) * var(--b7) * (3 - 2 * var(--b7)));
  --e8: calc(var(--b8) * var(--b8) * (3 - 2 * var(--b8)));
}
/* What is only there when the scroll drives the scenes, and what is only
   there when it does not. */
html:not(.scrubs) .only-scrub { display: none; }
html.scrubs .only-still { display: none; }
.pen, .say, .leafing, .shot-notes li { -webkit-column-break-inside: avoid; break-inside: avoid; }

/* A scene is a screen tall and --far more: that much scrolling goes by
   while its .pin stays where it is. */
html.scrubs .scene {
  --p: 0;
  min-height: calc(100svh - var(--bar) + var(--far, 0px));
}
html.scrubs .scene > .pin {
  position: sticky; top: var(--bar);
  min-height: calc(100svh - var(--bar));
}
/* While it is held, a wide scene is the whole screen under the bar. */
html.scrubs .scene.whole > .pin {
  height: calc(100svh - var(--bar));
  margin: 0 calc(50% - 50vw);
  overflow: hidden;
}
html.scrubs main { overflow-x: clip; }

@supports (animation-timeline: view()) {
  @keyframes scrub { from { --p: 0; } to { --p: 1; } }
  /* From the scene's top reaching the foot of the bar to its foot reaching
     the foot of the screen. */
  html.scrubs:not(.by-script) .scene {
    animation: scrub 1ms linear both;
    animation-timeline: view(block var(--bar) 0px);
    animation-range: contain 0% contain 100%;
  }
}

/* What a wide scene is made of: one statement at a time (.told), in the
   heavy face at the size of a chapter's heading, and the thing itself
   (.prop). On a phone the statement is above the thing; on a wide screen
   it is beside it. */
.plate { position: relative; }
html.scrubs .plate {
  display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 10px;
  height: 100%;
  padding: 14px 14px 18px;
}
.told { position: relative; height: 3.3em; font: 900 clamp(22px, 6.4vw, 29px)/1.04 var(--sans); }
.book .told p {
  --from: -1; --to: 2;
  position: absolute; left: 0; right: 0; top: 0;
  margin: 0;
  letter-spacing: -0.035em;
  text-align: left; text-indent: 0; text-wrap: balance; hyphens: manual; -webkit-hyphens: manual;
  /* A statement is there from the start of its beat to the start of the
     next. One goes before the next comes, in a few pixels of scrolling,
     so that there are never two at once. */
  opacity: clamp(0, min(calc((var(--p) - var(--from)) / 0.007), calc((var(--to) - var(--p)) / 0.007)), 1);
}
.told p:nth-child(1) { --to: var(--s1); }
.told p:nth-child(2) { --from: var(--s1); --to: var(--s2); }
.told p:nth-child(3) { --from: var(--s2); --to: var(--s3); }
.told p:nth-child(4) { --from: var(--s3); --to: var(--s4); }
.told p:nth-child(5) { --from: var(--s4); --to: var(--s5); }
.told p:nth-child(6) { --from: var(--s5); --to: var(--s6); }
.book .told p:last-child { --to: 2; }
.prop { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }

@media (min-width: 900px) {
  html.scrubs .plate {
    grid-template-rows: none; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 4vw; align-items: center;
    padding: 26px 5vw 30px;
  }
  html.scrubs .told { height: 3.4em; font-size: clamp(34px, 3.7vw, 60px); }
}


/* ---------- 1. The opening: the mark fills the screen, and goes to the bar ---------- */

/* Two screens of scrolling. The mark travels (beat 1), the name comes up
   (2), the first sentence sets a word at a time (3), the pen goes under it
   (4), and the rest arrives (5). */
html.scrubs .hero {
  --far: 190svh;
  --s1: 0.04; --l1: 0.44;
  --s2: 0.4; --l2: 0.12;
  --s3: 0.53; --l3: 0.25;
  --s4: 0.79; --l4: 0.07;
  --s5: 0.88; --l5: 0.07;
}
html.scrubs:not(.paged) .book { padding-top: 0; }
/* The words are only as tall as they are, so that when the scene is over
   what follows comes up under them, and no screen is left half empty. */
html.scrubs .hero > .pin { min-height: 0; padding-top: 32px; }
@media (max-height: 600px) {
  html.scrubs .hero > .pin { padding-top: 14px; }
}

/* The black ground and the white letter, over everything. The ground is the
   whole screen and ends as the tile of the mark in the bar; the letter ends
   as the letter in it. js/scenes.js measures where that is. */
.traveller { display: none; }
html.scrubs .traveller {
  display: block;
  position: fixed; z-index: 16; left: 0; top: 0;
  transform-origin: 0 0;
  pointer-events: none;
  opacity: clamp(0, calc((0.9995 - var(--b1)) * 4000), 1);
}
html.scrubs .z-ground {
  width: 100vw; height: 100vh; height: 100lvh;
  background: #0B0B0B;
  transform:
    translate(calc(var(--e1) * var(--gx, 0px)), calc(var(--e1) * var(--gy, 0px)))
    scale(calc(1 - var(--e1) * (1 - var(--gsx, 1))), calc(1 - var(--e1) * (1 - var(--gsy, 1))));
}
html.scrubs .z-letter {
  --zs: min(124vw, 112svh);
  left: calc(50vw - var(--zs) / 2); top: calc(50svh - var(--zs) / 2);
  width: var(--zs); height: var(--zs);
  fill: #FFFFFF;
  transform:
    translate(calc(var(--e1) * var(--zx, 0px)), calc(var(--e1) * var(--zy, 0px)))
    scale(calc(1 - var(--e1) * (1 - var(--zk, 1))));
}
/* One plain word at the foot of the first screen. */
html.scrubs .z-hint {
  position: fixed; z-index: 16; left: 0; right: 0; bottom: max(26px, env(safe-area-inset-bottom, 0px));
  margin: 0;
  color: #FFFFFF;
  font: 800 11px/1 var(--sans);
  letter-spacing: 0.18em; text-transform: uppercase; text-align: center; text-indent: 0;
  pointer-events: none;
  opacity: clamp(0, calc(1 - var(--p) * 30), 1);
}
/* A reader who arrives part way down the page is not shown the opening
   until it is known where they are. */
html.scrubs:not(.fresh):not(.scrubbing) .traveller, html.scrubs:not(.fresh):not(.scrubbing) .z-hint { visibility: hidden; }
/* Under the ground nothing can be pressed by mistake. */
html.scrubs.opening .bar, html.scrubs.opening .hero > .pin { pointer-events: none; }
/* For a reader who got to something under it with the keyboard, the
   opening is over, wherever the scroll is (js/scenes.js). */
html.opened .scene.hero { --p: 1 !important; }
html.opened .traveller, html.opened .z-hint { display: none; }

/* (js/scenes.js tells the words of the sentence apart: .w.) */
html.scrubs .hero .cover-mark { display: none; }
html.scrubs .hero h1 { opacity: var(--e2); transform: translateY(calc((1 - var(--e2)) * 0.3em)); }
html.scrubs .hero .lede { opacity: clamp(0, calc(var(--b3) * 40), 1); }
html.scrubs .hero .lede .w { opacity: clamp(0, calc((var(--b3) - var(--a, 0)) * 12), 1); }
html.scrubs .hero .pm-line { background: none; }
html.scrubs .hero .pm-line .w { position: relative; }
html.scrubs .hero .pm-line .w::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0.02em;
  height: 0.11em;
  background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(clamp(0, calc((var(--b4) - var(--u, 0)) * var(--un, 20)), 1));
}
html.scrubs .hero .stamp, html.scrubs .hero .lede-more, html.scrubs .hero .first-do {
  opacity: var(--e5);
  transform: translateY(calc((1 - var(--e5)) * 0.5em));
}

@media (min-width: 700px) {
  html.scrubs .hero > .pin { padding-top: 56px; }
}
/* On a wide screen the page that reads itself stays beside the words. */
@media (min-width: 1000px) {
  html:not(.paged) .cover > .hero { grid-column: 1; }
  html.scrubs .cover > .live { position: sticky; top: calc(var(--bar) + 56px); margin-top: 56px; }
}

/* ---------- 2. Any file in: a page of a PDF, taken apart and set again ---------- */

/* On ink blue, a sheet of white paper with a hard shadow, whatever paper
   the site is on: a PDF is always white. It is in three pieces. The strip
   with the running head is torn off and carried away, and the strip with
   the page number (beat 1). On what is left, the pieces slide down their
   own columns until each is level with its place in reading order (2);
   the second column slides across into the gaps left for it (3); and the
   one column grows to the width of the page, which turns the colour of
   zinked's paper (4). In none of those moves does one piece cross another.

   The page is the finished one: a single column, in reading order, laid
   out by the browser. js/scenes.js measures it and gives each piece --T
   (its top), --dA (how far the second beat takes it) and --xo (how far
   across the second column is). Everything on the sheet is sized from the
   sheet's width (cqw), so the lines break the same way on every screen. */
html.scrubs .pdf {
  --far: 355svh;
  --s1: 0.0423; --l1: 0.1972;
  --s2: 0.2817; --l2: 0.1972;
  --s3: 0.5211; --l3: 0.1972;
  --s4: 0.7606; --l4: 0.1972;
  --drop: 9px;
}
.pdf > .pin { background: #27408B; color: #FFFFFF; }
.pdf .sheet {
  position: relative;
  width: min(100%, calc((100svh - var(--bar) - 136px) / 1.38));
  aspect-ratio: 1 / 1.38;
  container-type: inline-size;
  color: #0B0B0B;
  text-align: left;
  --S: calc(var(--s, 0.518) + (1 - var(--s, 0.518)) * var(--e4));
  --lift: calc(4 * var(--b4) * (1 - var(--b4)));
  --away: calc(var(--e1) * var(--e1) * var(--e1));
  --moving: clamp(0, calc(4 * var(--b2) * (1 - var(--b2)) + 4 * var(--b3) * (1 - var(--b3))), 1);
}
@media (min-width: 900px) {
  .pdf .sheet { width: min(100%, calc((100svh - var(--bar) - 84px) / 1.38)); }
}
/* The three pieces of paper, and under all of them their shadows. */
.pdf .paper, .pdf .fall { position: absolute; left: 0; right: 0; margin: 0; }
.pdf .paper { z-index: 1; border: 2px solid #0B0B0B; background: #FFFFFF; }
.pdf .fall { z-index: 0; background: #0B0B0B; }
.pdf-head, .s-head { top: 0; height: 10cqw; }
.pdf-body, .s-body { top: 10cqw; bottom: 9cqw; }
.pdf-foot, .s-foot { bottom: 0; height: 9cqw; }
.pdf .pdf-head { border-bottom: 0; }
.pdf .pdf-foot { border-top: 0; }
/* The strips are torn off and carried away, each with its shadow: the
   head off to the right and the page number off to the left, clear of the
   statement. A strip lifts first (it turns a little, and its shadow falls
   further from it) and then goes, slowly and then fast (--away). */
.pdf-head { transform: translate(calc(var(--away) * 112vw), calc(var(--away) * -4svh)) rotate(calc(var(--e1) * 9deg)); }
.s-head { transform: translate(calc(var(--away) * 112vw + var(--drop) + var(--e1) * 16px), calc(var(--away) * -4svh + var(--drop) + var(--e1) * 16px)) rotate(calc(var(--e1) * 9deg)); }
.pdf-foot { transform: translate(calc(var(--away) * -112vw), calc(var(--away) * 3svh)) rotate(calc(var(--e1) * 8deg)); }
.s-foot { transform: translate(calc(var(--away) * -112vw + var(--drop) + var(--e1) * 16px), calc(var(--away) * 3svh + var(--drop) + var(--e1) * 16px)) rotate(calc(var(--e1) * 8deg)); }
.s-body { transform: translate(var(--drop), var(--drop)); }
/* The page lifts as it is set again, and settles. */
.pdf-body { overflow: hidden; transform: translate(calc(var(--lift) * -5px), calc(var(--lift) * -5px)); }
.book .pdf-head, .book .pdf-foot { font: italic 2.3cqw/1.2 var(--serif); text-indent: 0; }
.pdf-head { display: flex; align-items: flex-end; justify-content: space-between; padding: 0 5.5cqw 1.6cqw; }
.pdf-foot { display: grid; place-items: center; font-style: normal; }
.pdf-tint { position: absolute; inset: 0; background: #F6F2E9; opacity: var(--e4); }

/* The PDF's page: margins of 5.5, two columns of 42.5 with 4 between them.
   The finished page: one column of 82 with margins of 9. (js/scenes.js
   reads the 42.5 and the 4 from here.) */
.pdf-flow {
  --pdf-column: 42.5; --pdf-gutter: 4;
  position: absolute; z-index: 1; left: 9cqw; top: 5cqw;
  width: 82cqw;
  font: 4.6cqw/1.4 var(--serif);
  text-align: justify; hyphens: auto; -webkit-hyphens: auto;
}
.pdf-flow .b {
  position: relative;
  margin: 0;
  text-indent: 0;
  transform-origin: 0 0;
  transform:
    translate(
      calc((1 - var(--e4)) * -3.5cqw + var(--S) * (1 - var(--e3)) * var(--xo, 0px)),
      calc((1 - var(--e4)) * -2cqw + var(--S) * (var(--T, 0px) - (1 - var(--e2)) * var(--dA, 0px)) - var(--T, 0px)))
    scale(var(--S));
}
/* While the pieces are being moved they are seen to be pieces: each has a
   line round it, the chart and the table a heavier one in ink blue. */
.pdf-flow .b::after {
  content: "";
  position: absolute; inset: -0.9cqw -1.2cqw;
  border: 0.25cqw solid #0B0B0B;
  opacity: calc(var(--moving) * 0.3);
  pointer-events: none;
}
.pdf-flow .fig::after, .pdf-flow .cap::after, .pdf-flow .tab::after { border: 0.5cqw solid #27408B; opacity: var(--moving); }
.pdf-flow .b + .b { margin-top: 0.62em; }
.pdf-flow .fig { padding: 0; border: 0; }
.pdf-flow .fig svg { max-width: none; }
.pdf-flow .fig .grid { stroke: #77726A; }
.pdf-flow .fig .dark, .pdf-flow .fig text.l { fill: #0B0B0B; }
.pdf-flow .fig .a { fill: #27408B; }
.pdf-flow .fig + .cap { margin-top: 0.25em; }
.pdf-flow .cap { font: 0.72em/1.35 var(--sans); text-align: left; hyphens: manual; -webkit-hyphens: manual; }
.pdf-flow table { font-size: 0.72em; line-height: 1.2; border-top-color: #0B0B0B; }
.pdf-flow th { padding: 0.35em 0.6em 0.3em 0; border-bottom-color: #0B0B0B; font-size: 0.82em; }
.pdf-flow td { padding: 0.3em 0.6em 0.3em 0; border-bottom-color: #0B0B0B; }
.pdf-flow .ref { font-size: 0.7em; line-height: 1.35; text-align: left; hyphens: manual; -webkit-hyphens: manual; }
.pdf-flow .ref + .ref { margin-top: 0.4em; }
/* The finished page ends at the foot of a line: what is below the last
   line that fits (js/scenes.js finds it) is under a strip of paper. */
.pdf-cut {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; top: var(--cut, 100%);
  background: #F6F2E9;
  opacity: clamp(0, calc((var(--b4) - 0.85) / 0.15), 1);
}
.pdf .sheet.measuring .b { transform: none; }

/* ---------- 5. Pages: a leaf that turns with the scroll ---------- */

/* An open book, on the page's own paper. The right-hand leaf swings over
   the spine as --t goes from 0 to 1; its back is the next page, the page
   beneath is in its shade until it has gone, and the shade follows the
   leaf's edge. Flat tones, as in a real turn (reader.css). Not held by the
   scroll, it is shown with the leaf in the air. */
.leafing { --t: 0.3; }
html.scrubs .leafing { --far: 170svh; --s1: 0.1176; --l1: 0.7059; --t: var(--e1); }
html.scrubs .leafing > .pin { background: var(--paper); }
/* Its one statement is always there, and the button under it. */
.leafing .told { height: auto; }
.book .leafing .told p { position: static; opacity: 1; }
html.scrubs .leafing .plate { grid-template-rows: auto minmax(0, 1fr); }
html:not(.scrubs) .leafing .told { margin-top: 0.4em; font: 0.8em/1.45 var(--sans); }
html:not(.scrubs) .book .leafing .told p { letter-spacing: 0; }
.paged .leafing { display: none; }
/* (Its words are sized from its width, which an old browser cannot do.) */
@supports not (width: 1cqw) {
  .leafing { display: none; }
}
html:not(.js) .leafing .do, html:not(.js) .say-do { display: none; }
.spread3d {
  position: relative;
  width: min(100%, calc((100svh - var(--bar) - 210px) * 1.45));
  aspect-ratio: 1.45 / 1;
  margin: 1.2em auto 2.4em;
  perspective: 2400px; perspective-origin: 50% 40%;
  container-type: inline-size;
}
.spread3d .pg {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: 50%;
  padding: 5.2cqw 4.6cqw 0;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: var(--paper); color: var(--ink);
  font: 2.5cqw/1.5 var(--serif);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
}
/* A page ends at the foot of a line, not part way down one. */
.pg .text { height: 22.5em; overflow: hidden; }
.spread3d > .pg.r { left: calc(50% - 2px); width: calc(50% + 2px); }
.pg b { display: block; margin-bottom: 0.6em; font: 900 1.7em/1 var(--sans); letter-spacing: -0.03em; }
.pg .para { display: block; }
.pg .para + .para { text-indent: 1.4em; }
.pg .folio3d { position: absolute; left: 0; right: 0; bottom: 2.4cqw; font: 800 2cqw/1 var(--sans); letter-spacing: 0.08em; text-align: center; }
.pg .tone { position: absolute; inset: 0; background: var(--tone); opacity: 0; }
.leaf3d {
  position: absolute; top: 0; bottom: 0; left: calc(50% - 2px);
  width: calc(50% + 2px);
  transform-origin: 0 50%;
  transform: rotateY(calc(var(--t) * -180deg));
}
/* One flat leaf with two sides: its front until it stands upright, its
   back (drawn the other way round) after. */
.leaf3d .pg { width: 100%; }
.leaf3d .front { opacity: clamp(0, calc((0.5 - var(--t)) * 2000), 1); }
.leaf3d .back { transform: scaleX(-1); opacity: clamp(0, calc((var(--t) - 0.5) * 2000), 1); }
.leaf3d .tone { opacity: calc(var(--t) * (1 - var(--t)) * 0.8); }
.spread3d > .pg.l .tone { opacity: calc(max(0, var(--t) - 0.5) * (1 - var(--t)) * 0.9); }
/* The shade on the page beneath reaches as far as the leaf's edge and a
   little beyond it. (The edge is the cosine of the turn; this is close.) */
.cast3d {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 50%;
  background: var(--tone);
  transform-origin: 0 50%;
  transform: scaleX(calc(max(0, (1 - 4 * var(--t) * var(--t)) / (1 + var(--t) * var(--t))) + 0.8 * var(--t) * (1 - var(--t))));
  opacity: calc(min(1, var(--t) * (1 - var(--t)) * 12) * 0.2);
}

/* ---------- 3. The pen: a rough stroke, and the mark it snaps into ---------- */

/* Real sentences, large, on the page's own paper. js/scenes.js finds the
   words on them and draws, over the sheet, each stroke as a hand makes it
   (.rough: ink that comes on where the pen lands and thins where it lifts,
   uncovered along its length by the scroll, with the pen itself at its
   end, .pen-dot) and the mark it becomes (.clean). A stroke is drawn in one
   beat; in the short beat after it the rough stroke goes and the mark
   lands in its place, a little large, and settles. Then the note writes
   itself a letter at a time (7), and the agent's answer comes under it (8). */
html.scrubs .pen {
  --far: 370svh;
  --s1: 0.0405; --l1: 0.1486; --s2: 0.1892; --l2: 0.0324;
  --s3: 0.2568; --l3: 0.1351; --s4: 0.3919; --l4: 0.0324;
  --s5: 0.4595; --l5: 0.1622; --s6: 0.6216; --l6: 0.0324;
  --s7: 0.6892; --l7: 0.1622;
  --s8: 0.8784; --l8: 0.0541;
}
html:not(.js) .scene.pen { display: none; }
html.scrubs .pen > .pin { background: var(--paper); }
.pen .told p:nth-child(1) { --to: var(--s3); }
.pen .told p:nth-child(2) { --from: var(--s3); --to: var(--s5); }
.pen .told p:nth-child(3) { --from: var(--s5); --to: var(--s7); }
.pen .told p:nth-child(4) { --from: var(--s7); --to: var(--s8); }
.pen .told p:nth-child(5) { --from: var(--s8); }
.pen .sheet {
  position: relative;
  margin: 1.1em 0;
  padding: 1em 1.1em 1.1em;
  border: 2px solid var(--ink);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
}
html.scrubs .pen .sheet {
  width: 100%; max-width: 23em;
  margin: 0; padding: 0;
  border: 0;
  font-size: clamp(19px, 5.4vw, 23px);
}
.book .pen .sheet p { text-indent: 0; }
.pen .sheet > p:not(.hand):not(.agent-note) { line-height: 1.72; }
.pen .sheet .pass { margin-top: 0.5em; text-wrap: balance; }
.pen .t[data-t="under"], .pen .t[data-t="ring"] { white-space: nowrap; }
.pen .t[data-t="ring"] { margin: 0 0.16em; }
.pen .hand { margin-top: 0.8em; font-size: 1.14em; }
.pen .hand .w { opacity: clamp(0, calc((var(--b7) - var(--a, 0)) * 40), 1); }
.pen .agent-note { opacity: var(--e8); transform: translateY(calc((1 - var(--e8)) * 0.4em)); transition: none; }
.pen-ink { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.pen-ink .rough { fill: var(--accent); }
.pen-ink .reveal { fill: none; stroke: #FFFFFF; stroke-width: 16; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 2; stroke-dashoffset: calc(1 - var(--q)); }
.pen-ink .clean {
  fill: none; stroke: var(--accent); stroke-width: 2.6;
  transform-box: fill-box; transform-origin: 50% 50%;
  /* It lands a little large, and settles. */
  transform: scale(calc(1 + (1 - var(--x)) * 0.1), calc(1 + (1 - var(--x)) * 1.2));
  opacity: clamp(0, calc(var(--x) * 3 - 0.9), 1);
}
/* (A ring lands a little large all round; a line lands thick.) */
.pen-ink .beat2 .clean { transform: scale(calc(1 + (1 - var(--x)) * 0.14)); }
.pen-ink .rough { opacity: calc(clamp(0, calc(var(--q) * 300), 1) * clamp(0, calc(1 - var(--x) * 1.7), 1)); }
.pen-ink .beat1, .pen-dot.dot1 { --q: var(--e1); --x: var(--b2); }
.pen-ink .beat2, .pen-dot.dot2 { --q: var(--e3); --x: var(--b4); }
.pen-ink .beat3, .pen-dot.dot3 { --q: var(--e5); --x: var(--b6); }
/* The pen itself: where the hand is, at the end of the ink. */
.pen-dot { display: none; }
html.scrubs .pen-dot {
  display: block;
  position: absolute; left: 0; top: 0;
  width: 20px; height: 20px;
  border: 3px solid var(--paper); border-radius: 50%;
  background: var(--ink);
  offset-rotate: 0deg;
  offset-distance: calc(var(--q) * 100%);
  opacity: clamp(0, min(calc(var(--q) * 300), calc(1 - var(--x) * 4)), 1);
  pointer-events: none;
}
@media (min-width: 900px) {
  html.scrubs .pen .sheet { font-size: clamp(22px, 2.15vw, 33px); }
}

/* ---------- 4. Listening: the scroll says two sentences ---------- */

/* The one part of the page in the other colours: the app's focus view. One
   sentence at a time, large. The scroll says it, a word at a time (--t,
   from before its first word to after its last): words said are in full
   ink, words to come are pale, and the word being said has the rule under
   it. Each word has --a and --b, when it begins and ends, from the
   recording's own times where there is one (js/scenes.js). Then the next
   sentence takes its place. Under them is the chapter as sound: a bar for
   each sentence, as long as the sentence takes to say, and a line through
   them where the voice is (--ph, across the strip from 0 to 1). */
.say { --t: 2; }
html.scrubs .say {
  --far: 320svh;
  --s1: 0.0469; --l1: 0.25;
  --s2: 0.3438; --l2: 0.4063;
  --s3: 0.7969; --l3: 0.0938;
  --ph: calc(var(--x1, 0) + (var(--x2, 0) - var(--x1, 0)) * var(--b1) + (var(--x3, 0) - var(--x2, 0)) * var(--b2));
}
.say .canvas {
  --rule-c: #A3B8FF;
  display: grid; align-content: center;
  min-height: 13em;
  margin: 1.1em 0;
  padding: 1.6em 1.3em;
  background: var(--ink); color: var(--paper);
  text-align: left; hyphens: manual; -webkit-hyphens: manual;
}
:root[data-theme="dusk"] .say .canvas, :root[data-theme="black"] .say .canvas { --rule-c: #27408B; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .say .canvas { --rule-c: #27408B; }
}
html.scrubs .say .canvas {
  height: 100%; min-height: 0;
  margin: 0;
  padding: 24px max(22px, 8vw) 30px;
}
.book .say p { text-indent: 0; }
.book .say-where { margin: 0 0 1.4em; font: 800 11px/1.3 var(--sans); letter-spacing: 0.11em; text-transform: uppercase; }
.say-lines { display: grid; }
.say-line {
  grid-area: 1 / 1;
  max-width: 17em;
  font-family: var(--face); font-size: clamp(27px, min(8.4vw, 11svh), 58px); line-height: 1.22;
  text-wrap: pretty;
}
/* With nothing driving it, the second sentence is the one shown. */
html:not(.scrubs) .say-line:first-child { display: none; }
html.scrubs .say-line:nth-child(1) { --t: calc(var(--b1) * 1.04 - 0.02); opacity: clamp(0, calc((var(--s2) - var(--p)) / 0.008), 1); }
html.scrubs .say-line:nth-child(2) { --t: calc(var(--b2) * 1.04 - 0.02); opacity: clamp(0, calc((var(--p) - var(--s2)) / 0.008 + 1), 1); }
.say-line .piece { opacity: calc(0.3 + 0.7 * clamp(0, calc((var(--t) - var(--a, 0)) * 60 + 1), 1)); }
.say-line .word { position: relative; }
.say-line .word::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0.03em;
  height: 0.07em;
  background: var(--rule-c);
  opacity: clamp(0, calc(min(var(--t) - var(--a, 0), var(--b, 1) - var(--t)) * 4000 + 1), 1);
}
html.scrubs .say-strip {
  position: relative;
  display: flex; align-items: flex-end; gap: 3px;
  height: clamp(44px, 9svh, 76px);
  margin-top: clamp(22px, 5svh, 48px);
}
.say-strip .sound { position: relative; flex: var(--len, 1) 1 0; height: var(--tall, 60%); min-width: 2px; }
.say-strip .sound::before { content: ""; position: absolute; inset: 0; background: var(--paper); opacity: 0.26; }
/* A bar fills as the voice crosses it. */
.say-strip .sound i {
  position: absolute; inset: 0;
  background: var(--paper);
  transform-origin: 0 50%;
  transform: scaleX(clamp(0, calc((var(--ph) - var(--x, 0)) / var(--wide, 1)), 1));
}
.say-strip .head {
  position: absolute; left: 0; top: -8px; bottom: -8px;
  width: 100%;
  border-left: 3px solid var(--rule-c);
  transform: translateX(calc(var(--ph) * 100%));
}
.say-do {
  align-items: center;
  margin-top: 1.7em !important;
  font: 600 14px/1.3 var(--sans);
  opacity: var(--e3);
  transform: translateY(calc((1 - var(--e3)) * 0.5em));
}
.say .btn { border-color: var(--paper); background: var(--paper); color: var(--ink); }
@media (hover: hover) {
  .say .btn:hover { background: var(--ink); color: var(--paper); }
}

/* ---------- 6. The app itself: the folding phone, on black ---------- */

/* With nothing driving it this is a list: each screen beside what it shows.
   Driven by the scroll, it is one large phone on black. Its cover screen
   changes three times (beats 1 to 3: each screen comes up over the last),
   and then the phone opens (4): the half with the cover screen on it swings
   over the hinge, its other side is the left-hand page, the half beneath is
   the right-hand page, and the gutter between them is the hinge. Flat
   tones, as when a leaf turns. The phone is drawn to the left as it opens,
   and made smaller if two halves are wider than the screen (--open, which
   js/scenes.js measures), so that the open phone is in the middle. */
.shots { margin-top: 1.2em; }
.shot-notes { margin: 0; padding: 0; list-style: none; text-align: left; hyphens: manual; -webkit-hyphens: manual; }
.shot-notes li {
  display: grid; grid-template-columns: 6.6em minmax(0, 1fr); column-gap: 1.1em; align-content: start;
  padding: 1em 0;
  border-top: 2px solid var(--ink);
}
.shot-notes li:last-child { border-bottom: 2px solid var(--ink); }
.shot-notes img { grid-row: 1 / span 2; display: block; width: 100%; height: auto; border: 2px solid var(--ink); border-radius: 0.7em; }
.shot-notes b { align-self: end; font: 900 1.2em/1.05 var(--sans); letter-spacing: -0.03em; }
.shot-notes span { margin-top: 0.35em; font: 0.8em/1.45 var(--sans); }
/* Two pages side by side. */
.shot-notes li.two { grid-template-columns: 3.25em 3.25em minmax(0, 1fr); column-gap: 0.1em; }
.shot-notes li.two img { border-radius: 0.4em; }
.shot-notes li.two b, .shot-notes li.two span { grid-column: 3; margin-left: 1em; }

html.scrubs .shots {
  --far: 370svh;
  --s1: 0.0405; --l1: 0.1486;
  --s2: 0.2297; --l2: 0.1486;
  --s3: 0.4189; --l3: 0.1486;
  --s4: 0.6081; --l4: 0.2703;
  margin-top: 1.6em;
}
html.scrubs .shots > .pin { background: #0B0B0B; color: #FFFFFF; }
/* The list is still there for a reader who cannot see the phone. */
html.scrubs .shot-notes { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.duo {
  --dh: min(calc(100svh - var(--bar) - 156px), calc((100vw - 34px) / 0.687));
  position: relative;
  width: calc(var(--dh) * 0.687); height: var(--dh);
  perspective: 3200px; perspective-origin: 0 45%;
  transform:
    translateX(calc(var(--e4) * var(--open, 1) * var(--dh) * 0.3435))
    scale(calc(1 - var(--e4) * (1 - var(--open, 1))));
}
.duo .half { position: absolute; inset: 0; }
.duo .side {
  position: absolute; inset: 0;
  overflow: hidden;
  border: 3px solid #EFEBE2; border-radius: 1.3em;
  background: #000000;
}
.duo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* The half that swings is one flat thing with two sides: its front until
   it stands upright and its back after, which is drawn the other way round
   so that it reads the right way once the half has gone over. (Which side
   shows is said outright, not left to the browser to work out from which
   way the half is facing: that proved unreliable on the way back.) */
.duo .flap { transform-origin: 0 50%; transform: rotateY(calc(var(--e4) * -180deg)); }
.duo .front { opacity: clamp(0, calc((0.5 - var(--e4)) * 2000), 1); }
.duo .back { transform: scaleX(-1); opacity: clamp(0, calc((var(--e4) - 0.5) * 2000), 1); }
/* The cover screen: each screen comes up over the one before. */
.duo .front img:nth-child(2) { transform: translateY(calc((1 - var(--e1)) * 101%)); }
.duo .front img:nth-child(3) { transform: translateY(calc((1 - var(--e2)) * 101%)); }
.duo .front img:nth-child(4) { transform: translateY(calc((1 - var(--e3)) * 101%)); }
/* The half that swings is a slab of the phone, not a sheet of paper: as
   it turns away from the light its side goes nearly to black, inside its
   pale rim, and comes back as it lies down. */
.duo .tone { position: absolute; inset: 0; background: #0B0B0B; opacity: calc(16 * var(--e4) * var(--e4) * (1 - var(--e4)) * (1 - var(--e4)) * 0.94); }
.duo .dim {
  position: absolute; inset: 0;
  border-radius: 1.3em;
  background: #000000;
  transform-origin: 0 50%;
  transform: scaleX(calc(max(0, (1 - 4 * var(--e4) * var(--e4)) / (1 + var(--e4) * var(--e4))) + 0.3 * var(--e4) * (1 - var(--e4))));
  opacity: calc(min(1, var(--e4) * (1 - var(--e4)) * 12) * 0.3);
}
@media (min-width: 900px) {
  .duo { --dh: min(calc((100svh - var(--bar)) * 0.8), 29vw / 0.687); }
  html.scrubs .spread3d { width: min(100%, calc((100svh - var(--bar) - 120px) * 1.45)); }
}

/* ---------- A screen with little height: a phone on its side ---------- */

/* There is no room there to hold a page of a PDF and read it, or a book
   with a leaf turning. They are shown as they are with nothing driving
   them: the two pages drawn side by side, and the leaf in the air. */
@media (max-height: 520px) {
  html.scrubs .pdf.only-scrub { display: none; }
  html.scrubs .drawing.only-still { display: block; }
  html.scrubs .leafing { --far: 0px; --t: 0.3; min-height: 0; }
  html.scrubs .leafing > .pin { position: static; height: auto; min-height: 0; margin: 0; overflow: visible; background: none; }
  html.scrubs .leafing .plate { display: block; height: auto; padding: 0; }
  html.scrubs .leafing .told { margin-top: 0.4em; font: 0.8em/1.45 var(--sans); }
  html.scrubs .spread3d, .spread3d { width: min(100%, 26em); }
}
