/* quantumdev.io home page: the story. Loaded after site.css, on the home page only.

   Two layouts share this markup. Stacked is the default: the scenes follow one another down the page with every word
   visible, which is what a visitor gets without script, without GSAP, or with reduced motion. Pinned is added by
   home-story.js (.story.is-pinned): the stage stays in place under the nav and the scenes take turns on it while the
   visitor scrolls the track. Colours, spacing and motion are design-system tokens. The display sizes and line heights
   above the system's type scale are the home page's own, and DESIGN.md lists them under Typography. */

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* A hairline that can draw itself: --ln is how much of it is drawn, --ln-x which end it grows from. */
.door::before, .doors::after, .sc-events::before, .sc-reading::before, .join-body::before {
  content: ""; position: absolute; left: 0; right: 0; height: var(--line-thin); background: var(--border-hairline);
  transform: scaleX(var(--ln, 1)); transform-origin: var(--ln-x, 0%) 50%;
}

/* The canvas that draws text as pixels, and the text it stands in for. */
.dx-canvas { position: absolute; z-index: 2; pointer-events: none; image-rendering: pixelated; }
.dx-veil, .dx-veil * { color: transparent !important; }

/* ---------- Stacked (the default) ---------- */

.sc { position: relative; }
.sc-mark { position: absolute; inset: 0; }
.sc-doors, .sc-mission, .sc-events, .sc-reading, .sc-join { padding: var(--space-24) var(--space-8) 0; }

.doors-head { display: flex; justify-content: space-between; gap: var(--space-4); padding-bottom: var(--space-4); }
.doors-head h2, .doors-head p { margin: 0; font: var(--type-mono-sm); color: var(--text-secondary); }
.doors { list-style: none; margin: 0; padding: 0; display: grid; position: relative; }
.doors::after { bottom: 0; }
/* A name is one line of display type that does not wrap, sized by the window's width, so the room it needs grows with
   the window while a column of 34ch does not shrink with it. The text's column is therefore 34ch or 36% of the row,
   whichever is less: the name always ends inside its own column (tests/home/phases.test.mjs holds the arithmetic). */
.door {
  position: relative; display: grid; grid-template-columns: 4ch minmax(0, 1fr) minmax(0, min(34ch, 36%)); align-items: center;
  column-gap: var(--space-4); padding: var(--space-8) 0; min-height: 0;
}
.door::before { top: 0; }
.door-word { font-size: clamp(34px, 6.4vw, 88px); line-height: 0.9; white-space: nowrap; justify-self: start; }
.door-info { display: grid; gap: var(--space-3); justify-items: start; }
.door-info p { margin: 0; font: var(--weight-light) clamp(15px, 1.5vw, 22px)/1.4 var(--font-body); color: var(--text-body); text-wrap: pretty; }
.door-info .badge { justify-self: start; }
.door-info a { font: var(--type-mono); color: var(--text-primary); text-underline-offset: 4px; }
.door-act { margin-top: var(--space-1); }

.sc-mission { display: grid; gap: var(--space-16); }
.say { margin: 0; color: var(--text-primary); text-wrap: balance; }
.say-1 { font: var(--weight-thin) clamp(30px, 5.2vw, 84px)/1.08 var(--font-display); letter-spacing: var(--tracking-tight); max-width: 18em; }
.say-2 { font: var(--weight-light) clamp(20px, 2.4vw, 34px)/1.3 var(--font-display); max-width: 26em; justify-self: end; }

.sc-events, .sc-reading { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); justify-items: start; align-content: start; }
.sc-events::before, .sc-reading::before { top: var(--space-16); left: var(--space-8); right: var(--space-8); }
.ev-label, .rd-label { font: var(--type-mono-sm); color: var(--text-secondary); padding-top: var(--space-6); }
.ev-title, .rd-title { margin: 0; font: var(--weight-light) clamp(26px, 3.6vw, 56px)/1.1 var(--font-display); letter-spacing: -0.01em; color: var(--text-primary); text-wrap: balance; max-width: 20em; }
.ev-when { margin: 0; font: var(--type-mono); color: var(--text-body); }
.ev-link { margin-top: var(--space-2); }
a.text-action { text-decoration: none; display: inline-block; }
.rd-link { font: var(--type-mono); color: var(--text-primary); text-underline-offset: 4px; }

/* The date's digits roll into place: each digit is a window one line tall onto a reel of digits. */
.roll { display: inline-block; height: 1.5em; overflow: hidden; vertical-align: bottom; }
.roll-reel { display: block; transform: translateY(calc(var(--at, 0) * -1.5em)); }
.roll-reel > span { display: block; height: 1.5em; }

.ev-strip { list-style: none; margin: var(--space-12) 0 0; padding: var(--space-5) 0 var(--space-6); display: flex; flex-wrap: wrap; gap: var(--space-6) clamp(28px, 5vw, 72px); justify-self: stretch; border-top: var(--line-thin) solid var(--border-hairline); border-bottom: var(--line-thin) solid var(--border-hairline); }
.ev-strip[hidden] { display: none; }
.ev-strip li { display: grid; gap: 6px; }
.ev-strip b { font: 400 clamp(26px, 4.2vw, 60px)/1 var(--font-hero); letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-secondary); white-space: nowrap; }

.sc-join { overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr); }
.mq { display: grid; gap: var(--space-2); margin: 0 calc(-1 * var(--space-8)); }
.mq-row { display: flex; gap: 0.6em; width: max-content; font: 400 clamp(56px, 13vw, 220px)/0.95 var(--font-hero); letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-primary); white-space: nowrap; }
.mq-row + .mq-row { display: none; }
.join-body { position: relative; display: grid; gap: var(--space-4); justify-items: start; margin-top: var(--space-12); padding-top: var(--space-8); }
.join-body::before { top: 0; }
.join-title { font-size: clamp(22px, 2.4vw, 34px); }
.join-say { margin: 0; font: var(--type-body-lg); color: var(--text-body); max-width: 32em; }

/* ---------- Pinned (added by home-story.js) ---------- */

html.has-story { scroll-behavior: auto; }

/* The story's hairlines have short windows on the scroll clock. So each also eases to where the clock puts it, at an
   even rate over the system's slow duration: however fast the page is scrolled, a hairline takes most of a second to
   draw and never snaps in. (The circuit's gates keep a pace of their own in home-circuit.js.) Rows and text follow the
   clock alone. */
.story.is-pinned { --stroke-ease: var(--dur-slow) linear; }
.story.is-pinned .door::before, .story.is-pinned .doors::after, .story.is-pinned .sc-events::before, .story.is-pinned .sc-reading::before, .story.is-pinned .join-body::before { transition: transform var(--stroke-ease); }

/* The track: 3492vh of scrolling, 34.9 screens (home-phases.js END), plus the one stage that is held. */
.story.is-pinned { height: calc(3492vh + 100vh - var(--nav-height)); height: calc(3492svh + 100svh - var(--nav-height)); }
.story.is-pinned .story-stage { position: sticky; top: var(--nav-height); height: calc(100vh - var(--nav-height)); height: calc(100svh - var(--nav-height)); overflow: hidden; }
/* A scene arriving shows at once. A scene leaving stays for the length of the hairlines' ease: its words have gone by
   then, and a hairline that is still withdrawing finishes instead of being cut off. */
.story.is-pinned .sc { position: absolute; inset: 0; height: auto; min-height: 0; margin: 0; padding: 0 var(--space-8); opacity: 0; pointer-events: none; transition: opacity 0s linear var(--dur-slow); }
.story.is-pinned .sc[data-on] { opacity: 1; pointer-events: auto; transition-delay: 0s; }
/* When the story is put somewhere at once (a focus rest, a resize, a page restored part-way down), nothing eases: the
   hairlines take their places with the rows and the text, and the scene that was on stage goes at once. */
.story.is-pinned.is-landing { --stroke-ease: 0s linear; }
.story.is-pinned.is-landing .sc { transition: none; }
.story.is-pinned .sc-hero { padding: 0; }
/* Off stage the mark's box goes, so the 3D scene is not drawn under every other scene. */
.story.is-pinned .sc-hero:not([data-on]) .sc-mark { display: none; }

.story.is-pinned .sc-doors { display: grid; grid-template-rows: auto minmax(0, 1fr); padding-top: var(--space-4); padding-bottom: var(--space-8); }
.story.is-pinned .doors { grid-template-rows: repeat(4, minmax(0, 1fr)); min-height: 0; }
.story.is-pinned .door { container-type: size; padding: 0; }
.story.is-pinned .door-word { font-size: clamp(18px, min(60cqh, 9.6vw), 190px); }
.story.is-pinned .door-info { pointer-events: none; }
.story.is-pinned .door.is-open .door-info { pointer-events: auto; }

.story.is-pinned .sc-mission { align-content: center; }
.story.is-pinned .sc-events::before, .story.is-pinned .sc-reading::before { top: 24%; }
.story.is-pinned .sc-events, .story.is-pinned .sc-reading { align-content: start; gap: var(--space-4); padding-top: calc(24vh + var(--space-2)); padding-top: calc(24svh + var(--space-2)); }
.story.is-pinned .ev-title, .story.is-pinned .rd-title { font: var(--weight-thin) clamp(32px, 5.4vw, var(--text-6xl))/var(--leading-tight) var(--font-display); letter-spacing: var(--tracking-tight); max-width: 16em; }
.story.is-pinned .ev-when, .story.is-pinned .rd-link { font-size: clamp(13px, 1.2vw, 17px); }
/* The strip takes the last row and sits at its foot, so however tall the words above grow it never lies over them. */
.story.is-pinned .sc-events { grid-template-rows: repeat(4, auto) 1fr; }
.story.is-pinned .ev-strip { align-self: end; margin: 0 0 var(--space-16); flex-wrap: nowrap; width: max-content; will-change: transform; }
.story.is-pinned .roll-reel { transition: transform var(--dur-base) var(--ease-out); }

.story.is-pinned .sc-join { display: grid; grid-template-rows: minmax(0, 1fr) auto; align-items: center; padding-bottom: var(--space-16); }
.story.is-pinned .mq { align-self: center; }
.story.is-pinned .mq-row { will-change: transform; }
.story.is-pinned .mq-row + .mq-row { display: flex; color: var(--text-primary); }
.story.is-pinned .join-body { margin-top: 0; }

/* ---------- The circuit over the product rows (home-circuit.js; pinned only) ----------
   The rows' hairlines are the wires. Gates are the system's circuit device (site.css .circuit): boxes on the canvas with
   a strong outline, the control dot and the target in ink. home-circuit.js sets each stroke from the scroll clock, at
   a pace of its own. */
.story.is-pinned .qc { position: absolute; inset: 0; pointer-events: none; --qg: clamp(26px, 2vw, 32px); }
.story.is-pinned .qc svg { position: absolute; display: block; overflow: visible; }
.story.is-pinned .qg { top: 0; width: var(--qg); height: var(--qg); opacity: 0; }
.story.is-pinned .qg-h { transform: translate(-50%, -50%); }
.story.is-pinned .qg-m { right: 0; transform: translateY(-50%); }
.story.is-pinned .qg-box { fill: var(--bg-canvas); fill-opacity: 0; stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 1; stroke-dashoffset: 1; }
.story.is-pinned .qg-label { font: var(--type-mono-sm); fill: var(--text-primary); opacity: 0; }
.story.is-pinned .qg-dial, .story.is-pinned .qg-needle { fill: none; stroke: var(--text-primary); stroke-width: 1.25; stroke-linecap: round; }
.story.is-pinned .qg-dial { stroke-dasharray: 1; stroke-dashoffset: 1; opacity: 0; }
.story.is-pinned .qg-needle { transform-box: view-box; transform-origin: 14px 18.5px; opacity: 0; }
.story.is-pinned .qx { position: absolute; top: 0; bottom: 0; width: 0; }
.story.is-pinned .qx-line { position: absolute; top: 0; bottom: 0; left: calc(var(--line-thin) / -2); width: var(--line-thin); background: var(--wire); transform: scaleY(0); transform-origin: 50% 0; }
.story.is-pinned .qx-dot { position: absolute; left: 0; top: 0; width: 7px; height: 7px; border-radius: 50%; background: var(--text-primary); transform: translate(-50%, -50%) scale(0); }
.story.is-pinned .qx-target { left: 0; bottom: 0; width: calc(var(--qg) * 0.72); height: calc(var(--qg) * 0.72); transform: translate(-50%, 50%); opacity: 0; }
.story.is-pinned .qx-ring { fill: var(--bg-canvas); stroke: var(--text-primary); stroke-width: 1; stroke-dasharray: 1; stroke-dashoffset: 1; }
.story.is-pinned .qx-plus { fill: none; stroke: var(--text-primary); stroke-width: 1; stroke-dasharray: 1; stroke-dashoffset: 1; }
.story.is-pinned .qx-pulse { position: absolute; left: 0; width: calc(var(--qg) * 0.72); height: calc(var(--qg) * 0.72); border: var(--line-thin) solid var(--text-primary); border-radius: 50%; opacity: 0; }
.story.is-pinned .qx-pulse.is-control { top: 0; transform: translate(-50%, -50%); }
.story.is-pinned .qx-pulse.is-target { bottom: 0; transform: translate(-50%, 50%); }
/* With the circuit on stage, each wire's label sits on its wire, at the wire's left end, as in any circuit diagram,
   and the name under it starts at the page's edge. The query is the exact complement of the phone block below, so no width
   gets the gates without this layout. */
@media not all and (max-width: 720px) {
  .story.is-pinned .doors-head { padding-bottom: var(--space-6); }
  /* One track exactly as tall as the door: a closed door's hidden line of text is taller than the door, and without
     this it stretches the track and pushes the name below the middle, onto the label of the wire under it. */
  .story.is-pinned .door { grid-template-columns: minmax(0, 1fr) minmax(0, min(34ch, 36%)); grid-template-rows: minmax(0, 1fr); }
  .story.is-pinned .door-q { position: absolute; left: 0; top: 0; z-index: 1; padding-right: var(--space-3); background: var(--bg-canvas); line-height: 1; transform: translateY(-50%); }
}

/* Forced colours repaint backgrounds but not SVG fills, so the gates would show as bright tiles with no wires between
   them. The circuit is ornament: it steps aside. */
@media (forced-colors: active) {
  .story.is-pinned .qc { display: none; }
}

/* While the page goes from the pinned story to the stacked page, nothing eases. Under reduced motion the site gives
   every element a transition of a hundredth of a millisecond, and a transition that has just started still reports
   the value it started from: measured in that moment, the stacked page is half the pinned layout, and the visitor would
   be put some hundreds of pixels from the section they were on. (home-story.js sets the class for the swap alone.) */
html.is-switching *, html.is-switching *::before, html.is-switching *::after { transition: none !important; }

/* The footer follows the story with no gap of its own in the pinned layout. */
html.has-story .footer { margin-top: 0; }

@media (max-width: 720px) {
  .sc-doors, .sc-mission, .sc-events, .sc-reading, .sc-join { padding: var(--space-16) var(--space-5) 0; }
  .sc-events::before, .sc-reading::before { left: var(--space-5); right: var(--space-5); }
  .door { grid-template-columns: 4ch minmax(0, 1fr); row-gap: var(--space-3); padding: var(--space-6) 0; }
  .door-info { grid-column: 2; }
  .say-2 { justify-self: start; }
  .mq { margin: 0 calc(-1 * var(--space-5)); }
  .story.is-pinned .sc { padding-left: var(--space-5); padding-right: var(--space-5); }
  .story.is-pinned .sc-hero { padding-left: 0; padding-right: 0; }
  .story.is-pinned .door { align-content: center; row-gap: 0; }
  .story.is-pinned .door-word { font-size: clamp(18px, min(34cqh, 12.5vw), 120px); }
  /* The line of text takes its room by a number home-story.js sets on the row (--info): the room grows as the row
     starts to open, is half there when the text starts to show and whole by half open, so the name above it glides
     and nothing is clipped. */
  .story.is-pinned .door-info { max-height: calc(12em * var(--info, 0)); margin-top: calc(var(--space-3) * var(--info, 0)); overflow: clip; }
  .story.is-pinned .ev-strip { margin-bottom: var(--space-10); }
  /* A phone has no room for the circuit beside the names: the rows keep their labels and carry no gates. */
  .story.is-pinned .qc { display: none; }
}
