/* ==========================================================================
   Universal Sleep Solutions — Editions
   Motion system modelled on Shopify Editions (Spring '26):
   scroll-driven reveals, a 3D letter ring, and per-chapter parallax scenes.
   ========================================================================== */

/* ---------- Registered properties (animatable custom props) --------------- */
@property --scroll-reveal {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* ---------- Tokens -------------------------------------------------------- */
:root {
  /* Brand — sampled from the USS logo */
  --navy-900: #05070f;
  --navy-800: #081228;
  --navy-700: #0b2450;
  --sky: #86c7e2;
  --sky-bright: #a8dcf2;
  --moon: #faedc4;

  --bg: var(--navy-900);
  --fg: #ffffff;
  --fg-muted: rgba(255, 255, 255, 0.66);
  --fg-faint: rgba(255, 255, 255, 0.42);
  --rule: rgba(255, 255, 255, 0.14);
  --color-link-underline: rgba(255, 255, 255, 0.55);

  /* Type scale — Editions uses light weights with very tight tracking */
  --display: clamp(3.75rem, 11.5vw, 10rem);
  --headline: clamp(2.25rem, 5.2vw, 4rem);

  /* Easings lifted from the reference stylesheet */
  --ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
  --ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --gutter: clamp(1.25rem, 5vw, 5rem);
  --measure: 78rem;
  --nav-h: 3rem;

  /* Type: the platform's own UI face (San Francisco, Segoe UI, Roboto).
     No web fonts are downloaded; see docs/THEME.md. */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

/* Anchor jumps glide; the wheel is left entirely to the browser. */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.45;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

h1, h2, h3, h4, p, figure, ul { margin: 0; }
ul { padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }

a { color: inherit; }

::selection {
  background: var(--sky);
  color: var(--navy-700);
}

:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 3px;
  border-radius: 2px;
}

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

/* ---------- Typography helpers ------------------------------------------- */
.display {
  font-size: var(--display);
  font-weight: 400;
  line-height: 0.94;
  letter-spacing: -0.05em;
}

.headline {
  font-size: var(--headline);
  font-weight: 400;
  line-height: 0.96;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.body {
  color: var(--fg-muted);
  font-size: 1rem;
  line-height: 1.45;
  letter-spacing: -0.005em;
}

.eyebrow {
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  color: var(--fg-faint);
}

/* ---------- Animated underline (link-march) ------------------------------- */
.link-underline {
  padding-bottom: 1px;
  background-image: linear-gradient(
    var(--color-link-underline),
    var(--color-link-underline)
  );
  background-position: 0 100%;
  background-repeat: no-repeat;
  background-size: 100% 1px;
  text-decoration: none;
  transition: --color-link-underline 0.2s linear;
}

.link-underline:hover { --color-link-underline: #fff; }

@keyframes link-march { to { background-position: 3px 100%; } }

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .link-underline:hover {
    background-image: linear-gradient(90deg, #fff 50%, transparent 0);
    background-size: 6px 1px;
    background-repeat: repeat-x;
    animation: 0.6s linear infinite link-march;
  }
}

.link-arrow::after {
  content: "";
  display: inline-block;
  width: 0.6em; height: 0.6em;
  margin-left: 0.45em;
  border-right: 1px solid currentColor;
  border-top: 1px solid currentColor;
  transform: rotate(45deg) translateY(0.05em);
  transition: translate 0.3s var(--ease-out-cubic);
}
.link-arrow:hover::after { translate: 3px 0; }

/* ==========================================================================
   Scroll reveal
   Native scroll-driven animation drives --scroll-reveal 0 -> 1 as a block
   enters the viewport; children interpolate off it with a stagger index.
   JS adds .is-revealed as the fallback where view() is unsupported.
   ========================================================================== */
.reveal-scope { --scroll-reveal: 0; }

.reveal {
  opacity: var(--scroll-reveal);
  translate: calc(-12px + (var(--scroll-reveal) * 12px)) 0;
  transition-property: opacity, translate;
  transition-duration: 0.5s, 1s;
  transition-delay: calc(var(--reveal-index, 0) * 0.1s);
  transition-timing-function: linear, var(--ease-out-cubic);
}

/* Vertical variant used for large headlines and media panels */
.reveal-up {
  opacity: var(--scroll-reveal);
  translate: 0 calc(24px - (var(--scroll-reveal) * 24px));
  transition-property: opacity, translate;
  transition-duration: 0.6s, 1.1s;
  transition-delay: calc(var(--reveal-index, 0) * 0.08s);
  transition-timing-function: linear, var(--ease-out-expo);
}

@keyframes scroll-reveal-trigger { to { --scroll-reveal: 1; } }

@supports (animation-timeline: view()) and (animation-range: entry 0% entry 100%) {
  @media (prefers-reduced-motion: no-preference) {
    .reveal-scope {
      animation: step-start both scroll-reveal-trigger;
      animation-timeline: view();
      animation-range: entry 75% entry 100%;
    }
  }
}

/* Fallback / reduced-motion */
.reveal-scope.is-revealed { --scroll-reveal: 1; }

@media (prefers-reduced-motion: reduce) {
  .reveal-scope { --scroll-reveal: 1; }
  .reveal, .reveal-up { transition: none; }
}

/* Masked word reveal (scene-text-word-in) --------------------------------- */
.word-mask {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  padding-bottom: 0.06em;
}

.word-mask > span {
  display: inline-block;
  translate: 0 calc((1 - var(--scroll-reveal)) * (100% + 0.1em));
  transition: translate 0.85s var(--ease-out-expo);
  transition-delay: calc(var(--reveal-index, 0) * 0.055s);
}

@media (prefers-reduced-motion: reduce) {
  .word-mask > span { translate: 0; transition: none; }
}

/* ==========================================================================
   Top navigation
   ========================================================================== */
.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 60;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 clamp(0.75rem, 2vw, 1.25rem);
  background: linear-gradient(to bottom, rgba(5, 7, 15, 0.72), transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

@keyframes nav-item-in {
  0% { opacity: 0; translate: 0 -100%; }
  to { opacity: 1; translate: 0; }
}

.nav > * {
  animation: nav-item-in 0.7s var(--ease-out-expo) both;
  animation-delay: calc(0.06s * var(--nav-index, 0));
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  flex: 0 0 auto;
}

.nav-brand img { height: 1.625rem; width: auto; }

.nav-title {
  font-size: 0.875rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.nav-edition {
  font-size: 0.875rem;
  letter-spacing: -0.02em;
  color: var(--fg-faint);
  white-space: nowrap;
}

.nav-spacer { flex: 1 1 auto; }

.nav-link {
  font-size: 0.875rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
  color: var(--fg-muted);
  transition: color 0.2s var(--ease-standard);
}
.nav-link:hover { color: #fff; }

.nav-cta {
  display: inline-flex;
  align-items: center;
  height: 2rem;
  padding: 0 0.875rem;
  border-radius: 999px;
  background: #fff;
  color: var(--navy-900);
  font-size: 0.875rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s var(--ease-standard), scale 0.2s var(--ease-out-cubic);
}
.nav-cta:hover { background: var(--sky-bright); scale: 1.03; }

/* Narrow screens: the nav keeps brand + chapters only. -------------------- */
@media (max-width: 52rem) {
  .nav { gap: 1rem; }
  .nav-link, .nav-cta { display: none; }
}

@media (max-width: 30rem) {
  .nav { gap: 0.75rem; }
  .nav-edition { display: none; }
  /* Allow the brand to shrink so the title can ellipsize. */
  .nav-brand { min-width: 0; flex: 0 1 auto; }
  .nav-title {
    font-size: 0.8125rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nav-menu { flex: 0 0 auto; }
}

/* Very narrow: the logo mark carries the brand on its own. */
@media (max-width: 23.5rem) {
  .nav-title { display: none; }
}

/* Chapter dropdown -------------------------------------------------------- */
.nav-menu { position: relative; }

.nav-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: none;
  border: 0;
  padding: 0.25rem 0;
  font-size: 0.875rem;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.nav-menu-btn svg { transition: rotate 0.3s var(--ease-out-cubic); }
.nav-menu[data-open="true"] .nav-menu-btn svg { rotate: 180deg; }

.nav-menu-panel {
  position: absolute;
  top: calc(100% + 0.625rem);
  left: -0.75rem;
  min-width: 13rem;
  padding: 0.5rem;
  border-radius: 0.875rem;
  background: rgba(10, 16, 32, 0.92);
  border: 1px solid var(--rule);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  opacity: 0;
  translate: 0 -6px;
  pointer-events: none;
  transition: opacity 0.25s var(--ease-standard), translate 0.35s var(--ease-out-expo);
}

.nav-menu[data-open="true"] .nav-menu-panel {
  opacity: 1;
  translate: 0;
  pointer-events: auto;
}

.nav-menu-panel a {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--fg-muted);
  transition: background 0.18s var(--ease-standard), color 0.18s var(--ease-standard);
}
.nav-menu-panel a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav-menu-panel a span { color: var(--fg-faint); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Scene backgrounds — one fixed canvas, per-chapter colour crossfade
   ========================================================================== */
.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.scene canvas { width: 100%; height: 100%; display: block; }

/* Vignette + grain sit above the canvas to sell the WebGL look */
.scene-vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(130% 90% at 50% 0%, transparent 55%, rgba(5, 7, 15, 0.38) 100%),
    linear-gradient(to bottom, transparent 72%, var(--bg) 100%);
}

.scene-grain {
  position: fixed;
  inset: -50%;
  z-index: 2;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-shift 0.7s steps(3) infinite;
}

@keyframes grain-shift {
  0%   { transform: translate(0, 0); }
  33%  { transform: translate(-2%, 1%); }
  66%  { transform: translate(1%, -2%); }
  100% { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .scene-grain { animation: none; }
}

/* Everything above the scene */
#scroll-content { position: relative; z-index: 3; }

/* ==========================================================================
   Hero — 3D letter ring
   Geometry mirrors the reference: radius 37vmin, glyphs at
   rotateY(theta) translateZ(radius), container tilted on X.
   ========================================================================== */
.hero {
  position: relative;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 1fr auto;
}

.hero-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding-top: var(--nav-h);
  perspective: 190vmin;
}

/* Logo and ring live in one 3D rendering context, so depth sorts between
   them: letters on the near side of the ring cross in front of the logo,
   letters on the far side pass behind it. */
.hero-orbit {
  --ring-radius: 48vmin;
  position: relative;
  width: calc(var(--ring-radius) * 2);
  /* The ring is tilted nearly edge-on, so it needs far less height than
     its diameter; this keeps the hero copy above the fold. */
  height: calc(var(--ring-radius) * 1.15);
  transform-style: preserve-3d;
}

/* Narrow portrait screens: pull the ring in so it stays on screen. */
@media (max-aspect-ratio: 3 / 4) {
  .hero-orbit { --ring-radius: 43vmin; }
}

.hero-ring {
  --ring-tilt: -20deg;   /* seen from just above, like a planet's ring */
  --ring-from: 102deg;
  --ring-to: -295deg;
  --intro-duration: 4.5s;
  --ambient-duration: 90s;

  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(var(--ring-tilt)) rotateY(var(--ring-from));
  will-change: transform;
}

@keyframes hero-ring-intro {
  0%  { transform: rotateX(var(--ring-tilt)) rotateY(var(--ring-from)); }
  to  { transform: rotateX(var(--ring-tilt)) rotateY(var(--ring-to)); }
}

@keyframes hero-ring-ambient {
  0%  { transform: rotateX(var(--ring-tilt)) rotateY(var(--ring-to)); }
  to  { transform: rotateX(var(--ring-tilt)) rotateY(calc(var(--ring-to) - 360deg)); }
}

[data-hero-revealed="true"] .hero-ring {
  animation:
    hero-ring-intro var(--intro-duration) var(--ease-out-quint) both,
    hero-ring-ambient var(--ambient-duration) linear var(--intro-duration) infinite;
}

/* Each ring letter is a small solid: a face plus darker copies stepped back
   toward the centre of the ring. It is revealed through a registered
   property read by the leaves, because clip-path or opacity on the letter
   itself would flatten its depth. */
@property --letter-alpha {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

.hero-ring-letter {
  --letter-alpha: 0;
  --letter-step: 0.32vmin;
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: calc(var(--ring-radius) * 0.0775);
  line-height: 1;
  font-weight: 600;
  letter-spacing: 0;
  white-space: pre;
  transform: var(--letter-from);
  transform-style: preserve-3d;
}

.hero-ring-face,
.hero-ring-depth {
  display: block;
  opacity: var(--letter-alpha);
}

.hero-ring-face {
  position: relative;
  /* A cool grey, so the ring frames the logo rather than competing with it */
  color: #8e98a8;
  text-shadow: 0 0 1vmin rgba(134, 160, 190, 0.18);
}

.hero-ring-depth {
  position: absolute;
  inset: 0;
  color: rgb(calc(30 + var(--shade) * 60), calc(36 + var(--shade) * 64), calc(48 + var(--shade) * 70));
  transform: translateZ(calc(var(--k) * var(--letter-step) * -1));
}

@keyframes hero-letter-slide {
  0%  { transform: var(--letter-from); }
  to  { transform: var(--letter-to); }
}

@keyframes hero-letter-reveal {
  0%  { --letter-alpha: 0; }
  to  { --letter-alpha: 1; }
}

[data-hero-revealed="true"] .hero-ring-letter {
  animation:
    hero-letter-slide 0.65s ease-out var(--letter-delay, 0s) forwards,
    hero-letter-reveal 0.4s ease-out var(--reveal-delay, 0s) forwards;
}

@media (prefers-reduced-motion: reduce) {
  [data-hero-revealed="true"] .hero-ring,
  [data-hero-revealed="true"] .hero-ring-letter { animation: none; }
  .hero-ring-letter { transform: var(--letter-to); --letter-alpha: 1; }
}

/* A haze plane just behind the logo. The far side of the ring passes
   behind it and dims, so the mirrored letters recede instead of competing
   with the near side. */
.hero-haze {
  position: absolute;
  inset: -14%;
  transform: translateZ(-24vmin);
  background: radial-gradient(closest-side,
    rgba(7, 11, 28, 0.78) 0%,
    rgba(7, 11, 28, 0.62) 55%,
    rgba(7, 11, 28, 0) 100%);
  pointer-events: none;
}

/* Hero logo — extruded mark at the centre of the ring ---------------------
   uss.js stacks darkened copies of the logo behind the face, one step deeper
   each. Opacity is set through a registered property on the leaves:
   opacity on the 3D container itself would flatten the extrusion.
   No fade-in, so the logo counts as painted at once (LCP). */
@property --logo-alpha {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

.hero-logo {
  --logo-step: 0.42vmin;
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--ring-radius) * 1.9);
  aspect-ratio: 588 / 206;
  transform-style: preserve-3d;
  transform: translate(-50%, -50%) rotateX(7deg) rotateY(-15deg);
  pointer-events: none;
}

.hero-logo img,
.hero-logo-sheen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: var(--logo-alpha);
  backface-visibility: hidden;
}

.hero-logo-layer {
  transform: translateZ(calc(var(--i) * var(--logo-step) * -1));
  filter: brightness(var(--shade)) saturate(1.5);
}

/* The deepest layer throws a soft shadow down into the space behind. */
.hero-logo-layer:first-child {
  filter: brightness(0.3) saturate(1.5) drop-shadow(0 2.4vmin 3vmin rgba(0, 0, 0, 0.6));
}

.hero-logo-face {
  transform: translateZ(0);
  filter: drop-shadow(0 0 1.6vmin rgba(134, 199, 226, 0.28));
}

/* A band of light that sweeps across the face, masked to the logo. */
.hero-logo-sheen {
  transform: translateZ(0.5px);
  background: linear-gradient(105deg,
    rgba(255, 255, 255, 0) 38%,
    rgba(255, 255, 255, 0.5) 50%,
    rgba(255, 255, 255, 0) 62%) no-repeat;
  background-size: 260% 100%;
  background-position: 120% 0;
  -webkit-mask: url("../public/uss-logo-3d.svg") center / 100% 100% no-repeat;
          mask: url("../public/uss-logo-3d.svg") center / 100% 100% no-repeat;
}

@keyframes hero-logo-intro {
  0% {
    transform: translate(-50%, -50%) translateZ(-60vmin) rotateX(18deg) rotateY(-80deg);
  }
  to {
    transform: translate(-50%, -50%) rotateX(7deg) rotateY(-15deg);
  }
}

/* A slow turn and drift, so the extruded sides catch the light. */
@keyframes hero-logo-sway {
  0%   { transform: translate(-50%, -50%) rotateX(7deg) rotateY(-15deg) translateY(0); }
  50%  { transform: translate(-50%, -50%) rotateX(-5deg) rotateY(15deg) translateY(-1.2vmin); }
  to   { transform: translate(-50%, -50%) rotateX(7deg) rotateY(-15deg) translateY(0); }
}

@keyframes hero-logo-sheen {
  0%, 55% { background-position: 120% 0; }
  to      { background-position: -20% 0; }
}

[data-hero-revealed="true"] .hero-logo {
  animation:
    hero-logo-intro 2.6s var(--ease-out-quint) 0.2s both,
    hero-logo-sway 11s ease-in-out 2.8s infinite;
}

[data-hero-revealed="true"] .hero-logo-sheen {
  animation: hero-logo-sheen 7s ease-in-out 2.4s infinite;
}

@media (prefers-reduced-motion: reduce) {
  [data-hero-revealed="true"] .hero-logo,
  [data-hero-revealed="true"] .hero-logo-sheen { animation: none; }
}

/* Hero footer row --------------------------------------------------------- */
.hero-foot {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: clamp(1.5rem, 5vw, 4rem);
  align-items: start;
  padding: 0 var(--gutter) clamp(3.5rem, 8vh, 6rem);
}

.hero-foot p { max-width: 22rem; }

.hero-index {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem 1.5rem;
  align-content: start;
}

.hero-index a {
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  width: fit-content;
}

@media (max-width: 47.99rem) {
  .hero-foot { grid-template-columns: 1fr; }
  .hero-index { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ==========================================================================
   Chapter intro — full-bleed word over the scene
   ========================================================================== */
.chapter-intro {
  position: relative;
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding: 0 var(--gutter);
}

.chapter-intro .display {
  margin-left: -0.06em; /* optical alignment for the tight tracking */
}

.chapter-intro .eyebrow { margin-bottom: 1.25rem; }

/* ==========================================================================
   Feature blocks
   ========================================================================== */
.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.feature {
  padding-block: clamp(4rem, 12vh, 9rem) clamp(2rem, 6vh, 4rem);
}

.feature-head {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: clamp(1.5rem, 5vw, 5rem);
  align-items: end;
  margin-bottom: clamp(1.75rem, 4vw, 3rem);
}

.feature-head .body { max-width: 26rem; }
.feature-head .body + a { display: inline-block; margin-top: 1rem; }

@media (max-width: 55rem) {
  .feature-head { grid-template-columns: 1fr; align-items: start; }
}

/* ==========================================================================
   Card grid
   ========================================================================== */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 2.5vw, 2rem);
  padding-block: clamp(1rem, 3vh, 2.5rem) clamp(3rem, 10vh, 7rem);
}

@media (max-width: 55rem) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 34rem) { .cards { grid-template-columns: 1fr; } }

.card-media {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 0.25rem;
  overflow: hidden;
  margin-bottom: 0.875rem;
  background: linear-gradient(140deg, #10203f, #070c18);
}

.card-media::after {
  content: "";
  position: absolute;
  inset: -25%;
  background: radial-gradient(
    50% 60% at var(--gx, 40%) var(--gy, 40%),
    var(--glow, rgba(134, 199, 226, 0.4)),
    transparent 70%
  );
  filter: blur(24px);
  transition: transform 0.9s var(--ease-out-expo);
}

.card:hover .card-media::after { transform: scale(1.25); }

.card-media svg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.card-title {
  font-size: 1.0625rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 0.375rem;
}

.card .body { font-size: 0.9375rem; line-height: 1.4; }

/* ==========================================================================
   Chapter pill (bottom-centre progress indicator)
   ========================================================================== */
.pill {
  position: fixed;
  z-index: 55;
  left: 50%;
  bottom: 1.25rem;
  translate: -50% 0;
  display: flex;
  align-items: stretch;
  height: 2.375rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--navy-900);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  opacity: 0;
  transform: translateY(120%);
  transition: opacity 0.4s var(--ease-standard), transform 0.6s var(--ease-out-expo);
}

.pill[data-visible="true"] { opacity: 1; transform: translateY(0); }

.pill-label {
  display: inline-flex;
  align-items: center;
  padding: 0 0.5rem 0 1rem;
  font-size: 0.8125rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}

.pill-label span {
  display: inline-block;
  transition: translate 0.45s var(--ease-out-expo), opacity 0.3s linear;
}

.pill-label[data-swapping="true"] span { translate: 0 -110%; opacity: 0; }

.pill-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  border: 0;
  border-left: 1px solid rgba(0, 0, 0, 0.12);
  background: none;
  cursor: pointer;
}

.pill-toggle span {
  display: block;
  width: 0.875rem;
  height: 1px;
  background: currentColor;
  transition: transform 0.35s var(--ease-out-expo);
}
.pill-toggle span + span { margin-top: 0.25rem; }

.pill[data-open="true"] .pill-toggle span:first-child { transform: translateY(2.5px) rotate(45deg); }
.pill[data-open="true"] .pill-toggle span:last-child { transform: translateY(-2.5px) rotate(-45deg); }

/* Chapter index overlay --------------------------------------------------- */
.index-overlay {
  position: fixed;
  inset: 0;
  z-index: 54;
  display: grid;
  align-content: center;
  padding: 0 var(--gutter);
  background: rgba(5, 7, 15, 0.88);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s var(--ease-standard);
}

.index-overlay[data-open="true"] { opacity: 1; pointer-events: auto; }

.index-overlay ol {
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: var(--measure);
  margin-inline: auto;
  width: 100%;
}

.index-overlay li { overflow: hidden; }

.index-overlay a {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  padding: clamp(0.4rem, 1.4vh, 0.9rem) 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-decoration: none;
  font-size: clamp(1.75rem, 5.5vw, 3.5rem);
  letter-spacing: -0.045em;
  line-height: 1;
  color: var(--fg-muted);
  translate: 0 110%;
  transition: translate 0.7s var(--ease-out-expo), color 0.25s var(--ease-standard);
  transition-delay: calc(var(--i, 0) * 0.045s), 0s;
}

.index-overlay[data-open="true"] a { translate: 0; }
.index-overlay a:hover { color: #fff; }

.index-overlay a i {
  font-style: normal;
  font-size: 0.8125rem;
  letter-spacing: 0;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Contact / closing chapter
   ========================================================================== */
.contact-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: clamp(2rem, 6vw, 5rem);
  padding-block: clamp(2rem, 6vh, 4rem) clamp(4rem, 10vh, 7rem);
}

@media (max-width: 55rem) { .contact-grid { grid-template-columns: 1fr; } }

.detail-list { display: grid; gap: 1.25rem; }

.detail-list dt {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-bottom: 0.25rem;
}

.detail-list dd { margin: 0; font-size: 1.0625rem; letter-spacing: -0.02em; }

.vcard {
  border: 1px solid var(--rule);
  border-radius: 0.75rem;
  padding: clamp(1.25rem, 3vw, 2rem);
  background: rgba(255, 255, 255, 0.025);
  text-align: center;
}

.vcard img {
  width: min(11rem, 60%);
  height: auto;
  margin: 0 auto 1rem;
  border-radius: 0.375rem;
  background: #fff;
  padding: 0.5rem;
  transition: scale 0.35s var(--ease-out-expo);
}

.vcard a.qr:hover img { scale: 1.04; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.625rem 1rem;
  margin-top: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(134, 199, 226, 0.4);
  color: var(--sky);
  font-size: 0.9375rem;
  text-decoration: none;
  transition: background 0.2s var(--ease-standard), border-color 0.2s var(--ease-standard);
}
.btn-ghost:hover { background: rgba(134, 199, 226, 0.1); border-color: var(--sky); }

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  border-top: 1px solid var(--rule);
  padding: 2rem var(--gutter) 5.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  justify-content: space-between;
  align-items: center;
  color: var(--fg-muted);
  font-size: 0.875rem;
}

.footer a { text-decoration: none; }

/* ---------- Utilities ----------------------------------------------------- */

/* ==========================================================================
   Chapter scenes
   The aurora is full strength behind a chapter intro and drops back for
   content, matching the reference's title-screen / content rhythm.
   ========================================================================== */
.scene,
.scene-vignette {
  opacity: var(--scene-strength, 1);
  transition: opacity 0.6s var(--ease-standard);
}

/* The grain is a 5% veil; scene-strength scales that base rather than
   replacing it, or it washes the whole scene out to grey. */
.scene-grain {
  opacity: calc(0.05 * var(--scene-strength, 1));
  transition: opacity 0.6s var(--ease-standard);
}

/* ==========================================================================
   Figures — animated clinical canvases
   ========================================================================== */
.figure {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background:
    radial-gradient(120% 140% at 12% 0%, rgba(134, 199, 226, 0.09), transparent 60%),
    #080c16;
  overflow: hidden;
}

.figure canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.figure[data-ratio="wide"]    { aspect-ratio: 16 / 7; }
.figure[data-ratio="classic"] { aspect-ratio: 16 / 9; }
.figure[data-ratio="tall"]    { aspect-ratio: 4 / 3; }
.figure[data-ratio="square"]  { aspect-ratio: 1 / 1; }
.figure[data-ratio="band"]    { aspect-ratio: 16 / 4; }

/* The anatomical plate is portrait. On a wide screen the drawing takes 60%
   of a 4/3 frame, which already gives it a portrait panel; below the width
   where the legend drops out the drawing fills the canvas, so the frame has
   to turn portrait too or the plate is cropped top and bottom. */
.figure[data-ratio="plate"] { aspect-ratio: 4 / 3; }
@media (max-width: 60rem) {
  .figure[data-ratio="plate"] { aspect-ratio: 4 / 5; }
}

@media (max-width: 44rem) {
  .figure[data-ratio="wide"] { aspect-ratio: 4 / 3; }
  .figure[data-ratio="band"] { aspect-ratio: 4 / 3; }
}

/* The night timeline stacks its eight steps vertically on a phone. */
.figure[data-ratio="timeline"] { aspect-ratio: 16 / 4; }
@media (max-width: 44rem) { .figure[data-ratio="timeline"] { aspect-ratio: 4 / 3; } }
@media (max-width: 38rem) { .figure[data-ratio="timeline"] { aspect-ratio: 3 / 4; } }

.figure-head {
  position: absolute;
  top: 0; left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

.figure-head::before {
  content: "";
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--sky);
  box-shadow: 0 0 0 3px rgba(134, 199, 226, 0.16);
  animation: figure-live 2.4s ease-in-out infinite;
}

@keyframes figure-live {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .figure-head::before { animation: none; }
}

.figure-note {
  margin-top: 0.625rem;
  font-size: 0.8125rem;
  color: var(--fg-faint);
  letter-spacing: -0.005em;
}

/* ==========================================================================
   Explainer clips — three short captioned videos
   ========================================================================== */
.videos {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
}

@media (max-width: 60rem) {
  .videos { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
}

.video {
  margin: 0;
  min-width: 0;
}

.video video {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  background: #050b18;
  object-fit: cover;
}

.video figcaption {
  display: grid;
  gap: 0.25rem;
  margin-top: 0.75rem;
}

.video figcaption strong {
  font-weight: 500;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
}

.video figcaption span {
  font-size: 0.75rem;
  color: var(--fg-faint);
  letter-spacing: 0.02em;
}

/* ==========================================================================
   Split feature — copy beside a figure
   ========================================================================== */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  align-items: center;
  padding-block: clamp(2.5rem, 7vh, 5rem);
}

/* Reversing the order alone would hand the figure the narrower column,
   so mirror the track sizes too. */
.split.is-reversed { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.split.is-reversed > *:first-child { order: 2; }

.subhead-2 {
  font-size: clamp(1.5rem, 2.8vw, 2.25rem);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.split h3 { margin-bottom: 0.875rem; }
.split .body { max-width: 34ch; }
.split .body + a { display: inline-block; margin-top: 1rem; }

@media (max-width: 55rem) {
  .split { grid-template-columns: 1fr; }
  .split.is-reversed > *:first-child { order: 0; }
}

/* ==========================================================================
   Dense list grid — the long tail of a chapter
   ========================================================================== */
.list-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 clamp(1rem, 3vw, 3rem);
  padding-block: clamp(1rem, 3vh, 2rem) clamp(3rem, 9vh, 6rem);
  border-top: 1px solid var(--rule);
}

.list-grid > * {
  padding-block: clamp(1rem, 2.5vh, 1.75rem);
  border-bottom: 1px solid var(--rule);
}

.list-grid h3 {
  font-size: 0.9375rem;
  font-weight: 400;
  letter-spacing: -0.015em;
  margin-bottom: 0.3125rem;
}

.list-grid p {
  color: var(--fg-muted);
  font-size: 0.875rem;
  line-height: 1.4;
}

@media (max-width: 55rem) { .list-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 34rem) { .list-grid { grid-template-columns: 1fr; } }

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-top: clamp(2rem, 6vh, 4rem);
  padding-bottom: 0.75rem;
}

.list-head h3 {
  font-size: 1.25rem;
  font-weight: 400;
  letter-spacing: -0.03em;
}

/* ==========================================================================
   Stat band — a row of large figures
   ========================================================================== */
.stat-band {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: clamp(1.25rem, 3vw, 2.5rem);
  padding-block: clamp(2rem, 6vh, 4rem);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.stat-band b {
  display: block;
  font-size: clamp(2rem, 4vw, 3.25rem);
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.045em;
  margin-bottom: 0.5rem;
}

.stat-band span {
  color: var(--fg-muted);
  font-size: 0.9375rem;
  line-height: 1.35;
}

/* ==========================================================================
   Pull quote
   ========================================================================== */
.pull {
  padding-block: clamp(3rem, 9vh, 6rem);
  max-width: 46rem;
}

.pull p {
  font-size: clamp(1.375rem, 3vw, 2.125rem);
  font-weight: 300;
  line-height: 1.18;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.pull cite {
  display: block;
  margin-top: 1.25rem;
  font-style: normal;
  font-size: 0.875rem;
  color: var(--fg-faint);
}

/* ==========================================================================
   Chapter outro — back to the index
   ========================================================================== */
.chapter-outro {
  padding-block: clamp(1rem, 3vh, 2rem) clamp(4rem, 12vh, 8rem);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
  color: var(--fg-muted);
  cursor: pointer;
  transition: color 0.2s var(--ease-standard);
}

.back-link:hover { color: #fff; }

.back-link::before {
  content: "";
  width: 0.5em; height: 0.5em;
  border-left: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(45deg);
  transition: translate 0.3s var(--ease-out-cubic);
}

.back-link:hover::before { translate: -3px 0; }

/* ==========================================================================
   FAQ
   ========================================================================== */
.faq { border-top: 1px solid var(--rule); }

.faq details {
  border-bottom: 1px solid var(--rule);
}

.faq summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: clamp(0.875rem, 2.4vh, 1.375rem) 0;
  font-size: clamp(1rem, 1.6vw, 1.1875rem);
  letter-spacing: -0.025em;
  cursor: pointer;
  list-style: none;
}

.faq summary::-webkit-details-marker { display: none; }

.faq summary::after {
  content: "";
  flex: 0 0 auto;
  width: 0.7em; height: 0.7em;
  border-right: 1px solid var(--fg-faint);
  border-bottom: 1px solid var(--fg-faint);
  transform: rotate(45deg) translateY(-0.15em);
  transition: rotate 0.3s var(--ease-out-cubic);
}

.faq details[open] summary::after { rotate: -180deg; }

.faq details > div {
  padding-bottom: clamp(0.875rem, 2.4vh, 1.375rem);
  max-width: 62ch;
  color: var(--fg-muted);
  line-height: 1.5;
}

/* ==========================================================================
   Hours table
   ========================================================================== */
.hours {
  display: grid;
  gap: 0;
  margin-top: 0.5rem;
}

.hours div {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.9375rem;
}

.hours dt { color: var(--fg-muted); }
.hours dd { margin: 0; }

/* ---------- Homepage summaries: bullets + "Read more" (docs/ARTICLES.md §1) */
.points { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.points > li {
  position: relative;
  padding: 0.55rem 1rem 0.55rem 2.25rem;
  border-radius: 0.625rem;
  background: rgba(255, 255, 255, 0.045);
  color: var(--fg-muted);
  font-size: 1rem;
  line-height: 1.5;
}
.points > li::before { content: "\2726"; position: absolute; left: 0.85rem; top: 0.55rem; color: var(--sky); font-size: 0.875em; }
.points strong { color: var(--fg); font-weight: 500; }
.points-2 { grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); }
.read-more { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-top: 1rem; font-size: 0.9375rem; }
.read-more-label { color: var(--fg-faint); width: 100%; font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; }
.read-more a { color: var(--sky-bright); text-decoration: underline; text-decoration-color: rgba(168, 220, 242, 0.4); text-underline-offset: 0.18em; }
.read-more a::after { content: " \2192"; }
.chapter-faq { padding-block: clamp(1.5rem, 5vh, 3rem); }

/* Headings that receive focus from arrow-key chapter navigation */
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }
.index-hint { position: absolute; bottom: 5rem; inset-inline: 0; text-align: center; color: var(--fg-faint); font-size: .8125rem; }
.index-hint kbd { font: inherit; padding: 0 .4rem; border: 1px solid var(--rule); border-radius: .3rem; }
