/* ==========================================================================
   HQDM v5: home "space story" section (from invisible to page one). Agent A.
   r3 (Milan 08.11, "cinematic, not vibe coded"): a film title sequence, prototyped in 05-design/story-proto-r3.
   One camera move (arc + dolly) towards the HQDM planet across the four pillar orbits; the pillar titles track in
   like film titles; the end card sets the four titles as credits. Markup: 07-build/home_v5.py story(); rendering and
   timing: assets/js/space.js (canvas 2D + a small WebGL shader). Decorative scene (aria-hidden).
   States: default (no JS / no WebGL / .is-static) = a CSS still of the end frame + the credits;
   .is-live = the canvas has taken over; .is-armed = scrubbing (titles and credits driven by space.js);
   .is-still = reduced motion, the canvas holds the end frame.
   ========================================================================== */
.hq-story {
	position: relative;
	padding: 0 !important;
	isolation: isolate;
}
.hq-story > * { max-width: none !important; }

.hq-story__pin {
	position: relative;
	height: 100vh;
	height: 100svh;
	min-height: 560px;
	overflow: hidden;
}
/* The key light: violet, from the top-left, the same side the planet is lit from (world light in space.js).
   Faded at both edges so it never ends on the section boundary. */
.hq-story__pin::before {
	content: "";
	position: absolute;
	inset: 0;
	background: radial-gradient(58% 66% at 14% 20%, rgba(151, 71, 255, .13), transparent 70%);
	-webkit-mask-image: linear-gradient(transparent, #000 22%, #000 78%, transparent);
	mask-image: linear-gradient(transparent, #000 22%, #000 78%, transparent);
	pointer-events: none;
}

.hq-story__canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	/* the top and bottom 13% fade into the page: drawn by space.js into the canvas (r3 mobile: no CSS mask on a layer
	   that redraws every frame) */
}
.hq-story.is-live .hq-story__canvas { opacity: 1; }

/* ---------------------------------------------------------------- still frame (no JS / no WebGL)
   The end frame in CSS: the planet lit from the top-left with its cyan rim, the mark, the inner orbit (back half
   behind the planet, front half over it). Geometry follows the camera's last frame in space.js. */
.hq-story__still {
	--d: 55.2svh;          /* planet diameter */
	--ow: 101svh;          /* inner orbit width */
	--cx: 64%;
	--cy: 46.5%;
	position: absolute;
	inset: 0;
	pointer-events: none;
}
.hq-story.is-live .hq-story__still { display: none; }
.hq-story__orb, .hq-story__orbit { position: absolute; left: var(--cx); top: var(--cy); translate: -50% -50%; }
.hq-story__orb {
	z-index: 1;
	display: grid;
	place-items: center;
	width: var(--d);
	aspect-ratio: 1;
	border-radius: 50%;
	background:
		radial-gradient(circle at 30% 24%, rgba(205, 196, 255, .2), transparent 42%),
		radial-gradient(120% 120% at 86% 96%, rgba(3, 0, 12, .85), transparent 58%),
		radial-gradient(circle at 36% 30%, #2d2170 0%, #1a1248 40%, #0c0727 72%, #060215 100%);
	box-shadow:
		inset 10px 10px 26px -12px rgba(103, 232, 249, .55),
		inset 0 0 4px 0 rgba(103, 232, 249, .35),
		-8px -8px 40px -14px rgba(103, 232, 249, .35);
}
.hq-story__orb img { width: 60%; height: auto; opacity: .92; }
.hq-story__orbit {
	width: var(--ow);
	aspect-ratio: 1 / .245;
	border-radius: 50%;
	box-shadow: inset 0 0 0 1px rgba(103, 232, 249, .42);
}
.hq-story__orbit--front { z-index: 2; clip-path: inset(50% 0 0 0); box-shadow: inset 0 0 0 1px rgba(103, 232, 249, .7); }

/* ---------------------------------------------------------------- titles (film titles) */
.hq-story__titles {
	position: absolute;
	left: max(24px, 5vw, calc((100% - var(--wide)) / 2));
	bottom: 12svh;
	z-index: 2;
	display: none;
	pointer-events: none;
}
.hq-story.is-armed .hq-story__titles { display: block; }
.hq-story__title {
	position: absolute;
	left: 0;
	bottom: 28px;
	margin: 0;
	font-family: var(--ff-heading);
	font-size: clamp(1.75rem, .85rem + 3.3vw, 4.25rem);
	font-weight: 300;
	line-height: 1.04;
	letter-spacing: .14em;
	text-transform: uppercase;
	color: var(--c-text-strong);
	white-space: nowrap;
	visibility: hidden;
}
.hq-story__line { display: block; white-space: pre; }
.hq-story__ch { display: inline-block; }

/* chapter meter: four hairlines under the title, the running one fills cyan */
.hq-story__meter {
	position: absolute;
	left: 0;
	bottom: 0;
	display: flex;
	gap: 6px;
	opacity: 0;
}
.hq-story__meter i {
	position: relative;
	width: 28px;
	height: 1px;
	background: rgba(255, 255, 255, .16);
	overflow: hidden;
}
.hq-story__meter i::after {
	content: "";
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, .55);
	transform: scaleX(var(--f, 0));
	transform-origin: left;
}
.hq-story__meter i.is-on::after { background: var(--c-cyan); }

/* ---------------------------------------------------------------- end card: the four titles as credits */
.hq-story__credits {
	position: absolute;
	left: max(24px, 5vw, calc((100% - var(--wide)) / 2));
	bottom: 12svh;
	z-index: 2;
	margin: 0;
	padding: 22px 0 0;
	list-style: none;
	font-family: var(--ff-heading);
	font-size: clamp(.875rem, .78rem + .4vw, 1.125rem);
	font-weight: 400;
	line-height: 2.25;
	letter-spacing: .26em;
	text-transform: uppercase;
	color: var(--c-text);
	pointer-events: none;
}
.hq-story__credits::before {
	content: "";
	position: absolute;
	left: 0;
	top: 0;
	width: 28px;
	height: 1px;
	background: var(--c-cyan);
	opacity: var(--k, 1);
}
.hq-story__credits li { margin: 0; padding: 0; max-width: none; }
.hq-story.is-armed .hq-story__credits li { opacity: 0; }

/* ---------------------------------------------------------------- scroll range
   The section is taller than the frame and the frame sticks (no JS pin, no layout shift). r3: 190 + 90 for the rocket
   beat (the chapters keep their pace per scroll px). */
@media (prefers-reduced-motion: no-preference) {
	.hq-js .hq-story:not(.is-static) { height: calc(100vh + 280vh); height: calc(100svh + 280svh); }   /* one locked unit: the URL bar never changes the scroll range */
	.hq-js .hq-story:not(.is-static) .hq-story__pin { position: sticky; top: 0; }
}

/* ---------------------------------------------------------------- touch screens (r3 mobile fix)
   The stage is position: fixed for as long as the section is on screen (never sticky, never switched), so the
   compositor holds it exactly like the fixed header during touch / momentum scroll and URL bar moves; a sticky
   full-screen layer can be re-positioned a frame behind the scroll there, which shows as the whole stage shaking.
   The section's mask (masks, unlike overflow, also apply to fixed descendants) shows the stage only inside the
   section's box and fades it in and out over 14svh at both ends, so the page reveals the scene and covers it again.
   Nothing changes position type mid-scroll (no layout shift). Hidden while the section is off screen (.is-near). */
@media (prefers-reduced-motion: no-preference) {
	.hq-js .hq-story.is-touchpin {
		-webkit-mask-image: linear-gradient(transparent, #000 14svh, #000 calc(100% - 14svh), transparent);
		mask-image: linear-gradient(transparent, #000 14svh, #000 calc(100% - 14svh), transparent);
	}
	.hq-js .hq-story.is-touchpin .hq-story__pin { position: fixed; top: 0; left: 0; width: 100%; transform: translateZ(0); contain: layout paint; }
	.hq-js .hq-story.is-touchpin:not(.is-near) .hq-story__pin { visibility: hidden; }
}

/* ---------------------------------------------------------------- portrait (phones, portrait tablets) */
@media (max-aspect-ratio: 6 / 5) {
	.hq-story__still { --d: 55vw; --ow: 85.6vw; --cx: 50%; --cy: 37.5%; }
	.hq-story__titles, .hq-story__credits { left: 50%; translate: -50% 0; bottom: 9svh; text-align: center; }
	.hq-story__title { left: 50%; translate: -50% 0; font-size: clamp(1.5rem, .9rem + 3vw, 2.75rem); letter-spacing: .12em; }
	.hq-story__meter { left: 50%; translate: -50% 0; }
	.hq-story__credits { width: max-content; }
	.hq-story__credits::before { left: 50%; translate: -50% 0; }
}
