/* The home page (src/pages/home.mjs): scenes on native scroll. A scene is a tall section; its stage stays pinned for
   the section's run (sticky, full bleed) while its words scroll past over it. The stage follows the scroll through a
   few figures that assets/js/pages/home.js sets (transforms and opacity only). Reduced motion: nothing is pinned,
   every stage is shown at rest beside its words. */
.home main { overflow-x: clip; }
/* The scrollbar's place is kept while the opening holds the page still, so nothing moves sideways when it lets go. */
html { scrollbar-gutter: stable; }
/* Written by scroll.js on each scene; read by nothing beneath it, so it never restyles the scene's contents. */
@property --p { syntax: '<number>'; inherits: false; initial-value: 0; }
.scene { position: relative; }
/* The stage is as tall as the largest view (a phone's toolbar hidden), so no strip is ever left bare under it. */
.scene__stage { position: sticky; top: 0; height: 100lvh; overflow: hidden; }
.scene__copy { position: relative; z-index: 1; margin-top: -100lvh; pointer-events: none; }
.scene__copy a, .scene__copy button, .beat__in, .hero { pointer-events: auto; }
/* Each beat takes a screen and a half of scrolling, so the stage has time to do what the words say; its words stay in
   view beside the stage for all of it (sticky), coming in and going out with the scroll (a scroll-driven animation on
   the beat's own stretch), so no part of the story is a bare stage. */
.scene__head { min-height: 120svh; view-timeline-name: --beat; }
.scene__head-in { position: sticky; top: calc(var(--hdr-h) + 20svh); display: grid; gap: var(--space-4); justify-items: start; }
.scene__head .sec__h { max-width: min(17ch, 40vw); }
.scene__head .sec__p { margin: 0; max-width: min(46ch, 40vw); color: var(--ink-muted); font-size: 17px; }

/* Words over a stage. */
.beats { list-style: none; margin: 0 auto; padding: 0; }
.beat { min-height: 140svh; view-timeline-name: --beat; }
.beat__in { position: sticky; top: calc(var(--hdr-h) + 20svh); display: grid; gap: var(--space-3); justify-items: start; max-width: 31rem; }
/* Their own motion replaces the sections' reveal (which still starts their figures counting). */
.beat[data-reveal], .scene__head[data-reveal] { opacity: 1; transform: none; }
@supports (animation-timeline: view()) {
  html:not(.is-still) :is(.beat__in, .scene__head-in) {
    animation: beat-in linear both, beat-out linear forwards; animation-timeline: --beat, --beat;
    animation-range: cover 4% cover 24%, cover 56% cover 68%;
  }
}
@keyframes beat-in { from { opacity: 0; transform: translateY(var(--space-12)); } to { opacity: 1; transform: none; } }
@keyframes beat-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(calc(-1 * var(--space-8))); } }
.beat__n, .hero__label { margin: 0; font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-muted); }
.beat__h { margin: 0; font: 600 clamp(26px, 3vw, 36px)/1.08 var(--font-sans); letter-spacing: -0.02em; text-wrap: balance; }
.beat__p { margin: 0; max-width: 44ch; color: var(--ink-muted); font-size: 17px; }
/* A link to read on: its words dimensioned (components.css .ei-dim), the dimension line shown faint and inked when
   pointed at. */
.beat__go { position: relative; display: inline-flex; align-items: center; gap: var(--space-1); min-height: var(--space-6); padding: 0 var(--space-2) var(--space-2); margin-inline-start: calc(-1 * var(--space-2)); color: var(--ink); font-weight: 500; text-decoration: none; }
@media (pointer: coarse) { .beat__go { min-height: 44px; } }
.beat__go::after { transform: scaleX(1); opacity: .45; transition: opacity var(--dur-tick) var(--ease-instrument); }
.beat__go:is(:hover, :focus-visible)::after { opacity: 1; }
.facts-row { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); margin: 0; font: 500 12px/1.5 var(--font-mono); letter-spacing: 0.04em; color: var(--ink-muted); }
.facts-row b { font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }
.facts-row .is-open b { color: var(--laser-ink); }
.facts-row__k { color: var(--ink); letter-spacing: 0.12em; text-transform: uppercase; }

/* The opening (assets/js/opening.js): the lockup drawn on the bare sheet, over everything, then the sheet gives way
   and the wordmark flies to the header. The header shows only its wordmark's place until then. */
.open { display: none; }
html.is-opening { overflow: hidden; }
html.is-opening .open { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; pointer-events: none; }
.open__bg { position: absolute; inset: 0; background: var(--surface-000); }
.open .open__mark { position: relative; width: min(62vw, 560px); height: auto; overflow: visible; }
.open .wm-dot { opacity: 0; }
/* The first part is drawn by CSS from the first paint, so the sheet is never bare while the scripts arrive: the datum's
   ring traced, its ticks and point set, the letters inked in reading order. opening.js waits for it, then throws the
   dot. Its timing is OPEN_DRAWN in opening.js. */
html.is-opening .open .lk-ring { stroke-dasharray: 51.84; animation: open-ring var(--dur-draw) var(--ease-draw) both; }
html.is-opening .open :is(.lk-tick, .lk-pt) { animation: open-in var(--dur-move) var(--ease-instrument) both; animation-delay: calc(var(--dur-draw) * .5); }
html.is-opening .open .lk-pt { animation-delay: calc(var(--dur-draw) * .7); }
html.is-opening .open .wm-letters path { animation: open-in calc(var(--dur-move) * 1.5) linear both; animation-delay: calc(var(--dur-tick) * (2 + var(--k, 0) * .6)); }
.open .wm-letters path:nth-child(2) { --k: 1; }
.open .wm-letters path:nth-child(3) { --k: 2; }
.open .wm-letters path:nth-child(4) { --k: 3; }
.open .wm-letters path:nth-child(5) { --k: 4; }
.open .wm-letters path:nth-child(6) { --k: 5; }
@keyframes open-ring { from { stroke-dashoffset: 51.84; } to { stroke-dashoffset: 0; } }
@keyframes open-in { from { opacity: 0; } to { opacity: 1; } }
html.is-opening .hdr { background-color: transparent; border-bottom-color: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }
html.is-opening .hdr .brand { visibility: hidden; }
html.is-opening .hdr .nav, html.is-opening .hdr .hdr__end { opacity: 0; }
html.is-opened .hdr .nav, html.is-opened .hdr .hdr__end { transition: opacity var(--dur-draw) var(--ease-instrument); }

/* 1. The scan. The stage runs up under the header, so the picture fills the first screen. */
.scene--scan { margin-top: calc(-1 * var(--hdr-h)); }
.ei-scan[data-frame="home"] { --zoom: 1.12; --shift-x: 11%; --shift-x2: 3%; --shift-y: 2%; }
[dir="rtl"] .ei-scan[data-frame="home"] { --shift-x: -17%; --shift-x2: -22%; }
/* While the storeys are apart and after, the view pulls back a little (--pull) and comes to the middle (--pan), so the
   roof stays under the header and the levels on the screen. */
.ei-scan[data-frame="home"] .ei-scan__stage {
  translate: calc(-50% + var(--shift-x) * (1 - var(--pan, 0)) + var(--shift-x2) * var(--pan, 0)) calc(-50% + var(--shift-y) + var(--pull, 0) * 4%);
  scale: calc(var(--zoom) * (1 - var(--pull, 0) * .18));
}
.scene__veil {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, color-mix(in srgb, var(--surface-000) 96%, transparent) 0%, color-mix(in srgb, var(--surface-000) 84%, transparent) 34%, transparent 58%);
}
[dir="rtl"] .scene__veil { background: linear-gradient(270deg, color-mix(in srgb, var(--surface-000) 96%, transparent) 0%, color-mix(in srgb, var(--surface-000) 84%, transparent) 34%, transparent 58%); }
.scene__cap { position: absolute; inset-inline-end: var(--gutter); bottom: var(--space-4); margin: 0; max-width: 46ch; padding: var(--space-1) var(--space-2); font-size: 12px; line-height: 1.45; color: var(--ink-muted); text-align: end; background: color-mix(in srgb, var(--surface-000) 90%, transparent); }
.hero { min-height: 100svh; display: grid; align-content: end; justify-items: start; gap: var(--space-4); padding-block: calc(var(--hdr-h) + var(--space-12)) var(--space-16); }
.hero__h { margin: 0; font: 600 clamp(44px, 7vw, 92px)/0.96 var(--font-sans); letter-spacing: -0.03em; max-width: 11ch; text-wrap: balance; }
.hero__h em { font-style: normal; color: var(--laser-ink); }
/* Over the picture the words take full ink: muted ink holds its contrast only on the plain ground. */
.hero__lead { margin: 0; max-width: 42ch; color: var(--ink); font-size: 18px; }
.hero__facts, .hero__label { color: var(--ink); }
.hero .actions { display: flex; flex-wrap: wrap; gap: var(--space-4) var(--space-8); margin-top: var(--space-2); }
.hero__facts { margin-top: var(--space-4); }

/* 2. Parcel 542, set out on the right of its words. */
.scene--plot .scene__stage { background: var(--surface-000); border-top: var(--stroke-hair) solid var(--line); }
.scene__plot { position: absolute; inset: calc(var(--hdr-h) + var(--space-4)) var(--gutter) var(--space-8) 44%; }
[dir="rtl"] .scene__plot { inset: calc(var(--hdr-h) + var(--space-4)) 44% var(--space-8) var(--gutter); }
.scene__plot .ei-frame__hud { position: absolute; left: 0; bottom: 0; }

/* 3. Before site: the page's one inverse slab. Its own ink, lines and laser are the theme's inverse ones. */
.scene--clash {
  --ink: var(--on-inverse);
  --ink-muted: color-mix(in srgb, var(--on-inverse) 72%, var(--surface-inverse));
  --line: color-mix(in srgb, var(--on-inverse) 16%, var(--surface-inverse));
  --line-strong: color-mix(in srgb, var(--on-inverse) 42%, var(--surface-inverse));
  --laser: var(--laser-on-inverse); --laser-ink: var(--laser-on-inverse);
  --focus: var(--on-inverse);
  background: var(--surface-inverse); color: var(--on-inverse);
}
.scene__cd { position: absolute; inset-inline-end: var(--gutter); top: 50%; translate: 0 -46%; width: min(56vw, calc(72svh * var(--ar))); aspect-ratio: var(--ar); }
.cd { display: block; width: 100%; height: 100%; overflow: visible; }
.cd path { fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.cd-grid { stroke: var(--line); stroke-width: 1; }
.cd-arch { stroke: var(--ink-muted); stroke-width: 1; opacity: 0.7; }
.cd-struct { stroke: var(--ink); stroke-width: 1.25; opacity: 0.85; }
.cd-dim { stroke: var(--line-strong); stroke-width: 1; }
.cd-mep { stroke: var(--nerve); stroke-width: 2; }
/* Each clash shows when the count found passes its place (--i), and turns resolved when the count resolved passes
   its place among the resolved (--j); the open one keeps its laser. */
/* Without the page's script (no JS) the figures default to the end: every clash found, all but one resolved. */
.cl { opacity: clamp(0, var(--found, 99) - var(--i), 1); --r: clamp(0, var(--done, 99) - var(--j, 99), 1); }
.cl__ring, .cl__tick { fill: none; stroke: var(--laser); stroke-width: 1.5; vector-effect: non-scaling-stroke; opacity: calc(1 - 0.7 * var(--r)); }
.cl__dot { fill: var(--laser); opacity: calc(1 - var(--r)); }
.cl__ok { fill: none; stroke: var(--resolved); stroke-width: 2; vector-effect: non-scaling-stroke; opacity: var(--r); }
.cd-open {
  position: absolute; left: var(--x); top: var(--y); margin: 0; translate: var(--space-6) calc(-100% - var(--space-4));
  display: grid; gap: var(--space-1); max-width: 24ch; padding: var(--space-2) var(--space-3);
  font: 500 12px/1.4 var(--font-mono); color: var(--ink); background: var(--surface-inverse); border: var(--stroke-hair) solid var(--laser);
  opacity: var(--open-o, 0);
}
.cd-open b { color: var(--laser); font-weight: 500; }
.cd-read { position: absolute; top: calc(var(--hdr-h) + var(--space-6)); inset-inline-end: var(--gutter); display: flex; gap: var(--space-8); font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-muted); }
.cd-read span { display: grid; gap: var(--space-1); }
.cd-read b { min-width: 2ch; font: 500 40px/1 var(--font-mono); letter-spacing: -0.04em; color: var(--ink); font-variant-numeric: tabular-nums; }
.cd-read--open b { color: var(--laser); }

/* 4. The instruments, side by side: the row scrolls under the hand and snaps to a card; the page's scroll never drives
   it. It starts in line with the page's column and runs to the screen's edge. */
.row { padding-block: var(--space-24) var(--space-8); }
.row__head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--space-6); margin-bottom: var(--space-8); }
.row__head .sec__h { margin: 0; }
.row__track {
  --in: max(var(--gutter), calc((100% - var(--max)) / 2));
  display: grid; grid-auto-flow: column; grid-auto-columns: min(80vw, 360px); gap: var(--space-4);
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding-inline: var(--in);
  padding: 0 var(--in) var(--space-4);
}
.row__track > .tc { scroll-snap-align: start; }
.row__track:focus-visible { outline: var(--stroke-focus) solid var(--focus); outline-offset: var(--space-1); }

/* What each stage keeps beside its drawing: the services' legend as they come forward; the survey's table, typed in
   point by point as the points are set out; the clash log, a row for each clash as it is found, turning resolved as
   it is resolved, the last six in view. On screens tall and wide enough to hold them beside the words. */
.scene__legend {
  position: absolute; inset-inline-end: var(--gutter); bottom: calc(var(--space-16) + var(--space-6)); margin: 0; display: grid; gap: var(--space-2);
  font: 500 12px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink);
  opacity: var(--mep, 0); transform: translateY(calc((1 - var(--mep, 0)) * var(--space-4)));
}
.scene__legend span { display: flex; align-items: center; gap: var(--space-2); }
.scene__legend span::before { content: ''; width: var(--space-6); height: 2px; background: var(--ice-ink); }
.scene__legend .scene__legend--power::before { background: var(--nerve); }
.scene__legend b { font-weight: 500; }
.survey {
  position: absolute; inset-inline-start: max(var(--gutter), calc((100% - var(--max)) / 2)); bottom: var(--space-8); border-collapse: collapse;
  font: 500 12px/1.2 var(--font-mono); color: var(--ink); background: color-mix(in srgb, var(--surface-000) 92%, transparent); border: var(--stroke-hair) solid var(--line);
}
.survey th { padding: var(--space-2) var(--space-3); font-size: 11px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; text-align: start; color: var(--ink-muted); border-bottom: var(--stroke-hair) solid var(--line-strong); }
.survey td { padding: var(--space-1) var(--space-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.survey td:first-child { color: var(--ink-muted); }
.survey .is-control td:first-child { color: var(--laser-ink); }
.survey tbody tr { opacity: 0; transform: translateX(calc(-1 * var(--space-2))); transition: opacity var(--dur-move) var(--ease-instrument), transform var(--dur-move) var(--ease-instrument); transition-delay: calc(var(--i, 0) * var(--dur-tick)); }
.scene--plot:is([data-stage="1"], [data-stage="2"], [data-stage="3"]) .survey tbody tr { opacity: 1; transform: none; }
.cd-log {
  --row: 28px;
  position: absolute; inset-inline-start: max(var(--gutter), calc((100% - var(--max)) / 2)); bottom: var(--space-8); width: min(440px, 34vw); height: calc(var(--row) * 6); overflow: hidden;
  -webkit-mask-image: linear-gradient(transparent, #000 34%); mask-image: linear-gradient(transparent, #000 34%);
}
.cd-log ol { list-style: none; margin: 0; padding: 0; transform: translateY(calc(var(--row) * -1 * max(0, min(var(--found, 99), var(--rows, 14)) - 6))); }
.cd-log li {
  --r: clamp(0, var(--done, 99) - var(--j, 99), 1);
  display: grid; grid-template-columns: 7em minmax(0, 1fr) auto; gap: var(--space-3); align-items: center; height: var(--row);
  font: 500 12px/1 var(--font-mono); color: var(--ink-muted); border-bottom: var(--stroke-hair) solid var(--line);
  opacity: clamp(0, var(--found, 99) - var(--i), 1);
}
.cd-log li b { font-weight: 500; color: color-mix(in srgb, var(--ink) calc(var(--r) * 100%), var(--laser)); }
.cd-log li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-log li em { position: relative; font-style: normal; color: var(--ink); padding-inline-start: var(--space-3); }
.cd-log li em::before { content: ''; position: absolute; inset-inline-start: 0; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: color-mix(in srgb, var(--resolved) calc(var(--r) * 100%), var(--laser)); }
/* Found, then resolved: the two words in one place, crossing over as the row turns. */
.cd-log li:not(.is-open) em { display: grid; }
.cd-log li:not(.is-open) em i { grid-area: 1 / 1; font-style: normal; }
.cd-log li:not(.is-open) em i:first-child { opacity: calc(1 - var(--r)); color: var(--laser); }
.cd-log li:not(.is-open) em i:last-child { opacity: var(--r); }
.cd-log li.is-open b, .cd-log li.is-open em { color: var(--laser); }
@media (max-width: 1099px), (max-height: 819px) { .survey, .cd-log { display: none; } }

/* The inverse slab opens like an aperture as it arrives, and closes as it goes. */
@supports (animation-timeline: view()) {
  html:not(.is-still) .scene--clash { animation: slab-open linear both, slab-close linear forwards; animation-timeline: view(), view(); animation-range: cover 0% cover 100svh, cover calc(100% - 100svh) cover 100%; }
}
@keyframes slab-open { from { clip-path: inset(0 9% round var(--radius-2)); } to { clip-path: inset(0 0 round 0); } }
@keyframes slab-close { from { clip-path: inset(0 0 round 0); } to { clip-path: inset(0 9% round var(--radius-2)); } }

/* Phones and narrow windows: the words sit on a card at the foot of the stage; the stage keeps the top. */
@media (max-width: 859px) {
  @container (max-aspect-ratio: 1/1) { .ei-scan[data-frame="home"] .ei-scan__stage { --zoom: .5; --shift-x: -2.6%; --shift-x2: -2.6%; --shift-y: -20%; } }
  .scene__veil, [dir="rtl"] .scene__veil { background: linear-gradient(0deg, color-mix(in srgb, var(--surface-000) 96%, transparent) 0%, color-mix(in srgb, var(--surface-000) 88%, transparent) 46%, transparent 66%); }
  .scene__cap { top: calc(var(--hdr-h) + var(--space-2)); bottom: auto; max-width: 30ch; font-size: 11px; }
  .scene__legend { display: none; }
  .hero { padding-bottom: var(--space-8); }
  .beat, .scene__head { display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: var(--space-8); }
  .beat__in, .scene__head-in { top: auto; bottom: var(--space-6); }
  @supports (animation-timeline: view()) {
    html:not(.is-still) :is(.beat__in, .scene__head-in) { animation-range: cover 0% cover 14%, cover 50% cover 62%; }
  }
  .beat__in { padding: var(--space-4); background: color-mix(in srgb, var(--surface-000) 92%, transparent); border: var(--stroke-hair) solid var(--line); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
  .scene__head-in { padding: var(--space-4); background: color-mix(in srgb, var(--surface-000) 92%, transparent); border: var(--stroke-hair) solid var(--line); }
  .scene--clash .scene__head-in { background: color-mix(in srgb, var(--surface-inverse) 92%, transparent); }
  .scene__head .sec__h, .scene__head .sec__p { max-width: none; }
  .scene--clash .beat__in { background: color-mix(in srgb, var(--surface-inverse) 92%, transparent); }
  .scene__plot, [dir="rtl"] .scene__plot { inset: calc(var(--hdr-h) + var(--space-2)) var(--gutter) 46svh; }
  .scene__cd { top: calc(var(--hdr-h) + var(--space-16)); translate: none; inset-inline: var(--gutter); width: auto; max-height: 40svh; margin-inline: auto; }
  .cd-read { top: calc(var(--hdr-h) + var(--space-3)); inset-inline: var(--gutter); gap: var(--space-6); }
  .cd-read b { font-size: 28px; }
  .cd-open { translate: -50% var(--space-6); max-width: 30ch; }
}

/* At rest (reduced motion, ?p): nothing pinned. The scan stays behind the first screen; the other stages stand before
   their words. */
html.is-still .scene__copy { margin-top: 0; }
html.is-still .scene__stage { position: relative; height: 72svh; }
html.is-still .scene--scan .scene__stage { position: absolute; inset: 0 0 auto; height: 100svh; }
html.is-still .beat, html.is-still .scene__head { min-height: 0; padding-block: var(--space-8); }
html.is-still :is(.beat__in, .scene__head-in) { position: static; }
html.is-still .scene--plot .beats, html.is-still .scene--clash .beats { padding-bottom: var(--space-16); }
