/* ============================================================
   Matcha Atelier — Motion Layer
   Derived from motion-teardown-report.md (priority tier 1 + 2)
   All animations use transform/opacity only → compositor-friendly, 60fps.
   Every effect degrades under prefers-reduced-motion.
   ============================================================ */

/* ---------- 1. Floating icon field (from report §1.2 / §4.1) ---------- */
.floaties {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.floaties--fixed {
  position: fixed;
  z-index: 1;
}

.floatie {
  position: absolute;
  display: block;
  will-change: transform;
  opacity: 0;
  color: var(--matcha-600);
  filter: drop-shadow(0 6px 14px rgba(20, 35, 15, 0.14));
  animation-name: float-drift;
  animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
  animation-iteration-count: infinite;
}

[data-theme="dark"] .floatie {
  color: var(--matcha-300);
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.5));
}

.floatie svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Each icon drifts through 4 waypoints + rotates — organic, never looped-looking.
   Amplitude comes from --float-drift / --float-rot (written by syncVars). */
@keyframes float-drift {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  25% {
    transform: translate3d(
        calc(var(--float-drift, 34px) * 0.76),
        calc(var(--float-drift, 34px) * -1),
        0
      )
      rotate(var(--float-rot, 12deg));
  }
  50% {
    transform: translate3d(
        calc(var(--float-drift, 34px) * -0.53),
        calc(var(--float-drift, 34px) * -1.82),
        0
      )
      rotate(calc(var(--float-rot, 12deg) * -0.58));
  }
  75% {
    transform: translate3d(
        calc(var(--float-drift, 34px) * 1),
        calc(var(--float-drift, 34px) * -0.76),
        0
      )
      rotate(calc(var(--float-rot, 12deg) * 0.75));
  }
  100% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
}

/* ---------- 2. Grid texture background (report §3.3) ---------- */
.texture-grid,
.texture-stripes {
  position: relative;
}

/* keep real content above the decorative layer */
.texture-grid > *,
.texture-stripes > * {
  position: relative;
  z-index: 1;
}

/* …but the ghost word sits behind content, not in front of it */
.texture-grid > .ghost-word,
.texture-stripes > .ghost-word {
  z-index: 0;
}

.texture-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(
      circle at center,
      var(--grid-dot) 1px,
      transparent 1.2px
    );
  background-size: var(--grid-size, 26px) var(--grid-size, 26px);
  opacity: var(--grid-opacity, 0.55);
  mask-image: radial-gradient(120% 90% at 50% 40%, #000 30%, transparent 78%);
  -webkit-mask-image: radial-gradient(
    120% 90% at 50% 40%,
    #000 30%,
    transparent 78%
  );
}

:root {
  --grid-dot: rgba(63, 100, 48, 0.28);
  --grid-opacity: 0.55;
}

[data-theme="dark"] {
  --grid-dot: rgba(185, 210, 148, 0.22);
  --grid-opacity: 0.42;
}

/* ---------- 3. Diagonal stripe texture (report §4.6) ---------- */
.texture-stripes::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 11px,
    var(--stripe-line) 11px,
    var(--stripe-line) 12px
  );
  opacity: 0.5;
}

:root {
  --stripe-line: rgba(63, 100, 48, 0.05);
}

[data-theme="dark"] {
  --stripe-line: rgba(185, 210, 148, 0.05);
}

/* ---------- 4. Oversized ghost word (report §4.3) ---------- */
.ghost-word {
  position: absolute;
  left: 50%;
  bottom: -0.18em;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(6rem, 17vw, 17rem);
  line-height: 0.8;
  letter-spacing: -0.03em;
  white-space: nowrap;
  color: var(--text);
  opacity: var(--ghost-opacity, 0.045);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

[data-theme="dark"] .ghost-word {
  opacity: 0.07;
}

/* ---------- 5. Magnetic button (report §4 micro-interactions) ---------- */
.magnetic {
  display: inline-flex;
  will-change: transform;
  transition: transform 0.42s var(--ease-out);
}

.magnetic.is-active {
  transition: transform 0.12s linear;
}

/* ---------- 6. Custom cursor follower ---------- */
.cursor-dot,
.cursor-ring {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  pointer-events: none;
  border-radius: 50%;
  mix-blend-mode: difference;
  opacity: 0;
  transition: opacity 0.3s ease;
  will-change: transform;
}

.cursor-dot {
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  background: #f4f7ec;
}

.cursor-ring {
  width: var(--cursor-ring, 34px);
  height: var(--cursor-ring, 34px);
  margin: calc(var(--cursor-ring, 34px) / -2) 0 0
    calc(var(--cursor-ring, 34px) / -2);
  border: 1.4px solid rgba(244, 247, 236, 0.75);
  transition: opacity 0.3s ease, width 0.3s var(--ease-out),
    height 0.3s var(--ease-out), margin 0.3s var(--ease-out),
    background-color 0.3s ease;
}

.cursor-on .cursor-dot,
.cursor-on .cursor-ring {
  opacity: 1;
}

.cursor-hot .cursor-ring {
  width: var(--cursor-hot, 58px);
  height: var(--cursor-hot, 58px);
  margin: calc(var(--cursor-hot, 58px) / -2) 0 0
    calc(var(--cursor-hot, 58px) / -2);
  background: rgba(244, 247, 236, 0.16);
}

/* Hide native cursor only on precise pointers */
@media (hover: hover) and (pointer: fine) {
  .cursor-on,
  .cursor-on * {
    cursor: none !important;
  }
}

/* ---------- 7. Scroll progress bar ---------- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 100%;
  z-index: 120;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(
    90deg,
    var(--matcha-600),
    var(--matcha-500) 45%,
    var(--gold) 100%
  );
  will-change: transform;
  pointer-events: none;
}

[data-theme="dark"] .scroll-progress {
  background: linear-gradient(
    90deg,
    var(--matcha-300),
    var(--matcha-500) 45%,
    var(--gold-soft) 100%
  );
}

/* ---------- 8. Staggered reveal v2 (report §2.1 / §4.2) ---------- */
/* unify the standalone .reveal from styles.css with the tunable values */
.reveal {
  transform: translateY(var(--reveal-dist, 28px));
  transition: opacity var(--reveal-dur, 750ms) var(--ease-out),
    transform var(--reveal-dur, 750ms) var(--ease-out);
}

.reveal.is-in {
  transform: none;
}

/* opt-in: add data-reveal-group to a parent, children animate in sequence */
/* --reveal-dist / --reveal-dur / --reveal-stagger are written by
   MT.motion.syncVars() from MT.TUNE — change them at runtime with
   MT.tune({ reveal: { stagger: 40 } }) */
[data-reveal-group] > * {
  opacity: 0;
  transform: translateY(var(--reveal-dist, 28px)) scale(0.985);
  transition: opacity var(--reveal-dur, 750ms) var(--ease-out),
    transform var(--reveal-dur, 750ms) var(--ease-out);
}

[data-reveal-group].is-in > * {
  opacity: 1;
  transform: none;
}

[data-reveal-group].is-in > *:nth-child(1) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 0);
}
[data-reveal-group].is-in > *:nth-child(2) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 1);
}
[data-reveal-group].is-in > *:nth-child(3) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 2);
}
[data-reveal-group].is-in > *:nth-child(4) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 3);
}
[data-reveal-group].is-in > *:nth-child(5) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 4);
}
[data-reveal-group].is-in > *:nth-child(6) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 5);
}
[data-reveal-group].is-in > *:nth-child(7) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 6);
}
[data-reveal-group].is-in > *:nth-child(8) {
  transition-delay: calc(var(--reveal-stagger, 70ms) * 7);
}

/* ---------- 9. 3D tilt card (report §2 cards hover) ---------- */
.tilt {
  will-change: transform;
  transition: transform 0.5s var(--ease-out), box-shadow 0.5s var(--ease-out);
  transform-style: preserve-3d;
}

.tilt.is-tilting {
  transition: transform 0.08s linear;
}

.tilt__shine {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  background: radial-gradient(
    420px circle at var(--mx, 50%) var(--my, 50%),
    rgba(255, 255, 255, 0.16),
    transparent 62%
  );
}

.tilt:hover .tilt__shine {
  opacity: 1;
}

/* ---------- 10. Section-number eyebrow (report §2.5) ---------- */
.sec-num {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.sec-num::after {
  content: "";
  width: 46px;
  height: 1px;
  background: var(--border-strong);
}

/* ---------- 11. Marquee pause on hover (micro-interaction polish) ---------- */
.marquee:hover .marquee__track {
  animation-play-state: paused;
}

/* ---------- 12. Link underline sweep ---------- */
.sweep {
  position: relative;
  display: inline-block;
}

.sweep::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 100%;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: 100% 50%;
  transition: transform 0.5s var(--ease-out);
}

.sweep:hover::after {
  transform: scaleX(1);
  transform-origin: 0 50%;
}

/* ---------- 13. Scroll stage (pin + scrub) ---------- */
.stage {
  position: relative;
}

.stage__pin {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  align-items: center;
  overflow: hidden;
}

/* stage progress dots — filled by MT.stage consumers */
.stage__dots {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 2rem;
}

.stage__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: transform 0.4s var(--ease-out), background-color 0.4s ease;
}

.stage__dot.is-on {
  background: var(--accent);
  transform: scale(1.6);
}

/* step rows inside a pinned narrative */
.stage-step {
  padding: 0.85rem 0;
  opacity: 0.32;
  transform: translateX(-8px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out);
  border-left: 2px solid transparent;
  padding-left: 1rem;
}

.stage-step.is-on {
  opacity: 1;
  transform: none;
  border-left-color: var(--accent);
}

/* ---------- 14. 3D balloon word (report §1.1, SVG interpretation) ---------- */
:root {
  --balloon-top: #eaf5dd;
  --balloon-mid: #8fc06a;
  --balloon-bottom: #3f6b32;
  --balloon-edge: #24401f;
}

[data-theme="dark"] {
  --balloon-top: #f4f8ea;
  --balloon-mid: #a8cf84;
  --balloon-bottom: #4d7d3c;
  --balloon-edge: #16281a;
}

.balloon {
  position: relative;
  pointer-events: none;
  user-select: none;
}

.balloon svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  transform: perspective(900px) rotateX(-6deg) rotateY(3deg);
  transform-origin: 50% 60%;
  filter: drop-shadow(0 18px 26px rgba(20, 35, 15, 0.26));
  animation: balloon-float var(--balloon-dur, 9s) ease-in-out infinite;
  will-change: transform;
}

[data-theme="dark"] .balloon svg {
  filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.7));
}

/* hero placement: sits behind the tin, overlapping it on purpose */
.hero__balloon {
  position: absolute;
  left: -10%;
  right: -10%;
  top: 2%;
  z-index: 0;
}

@keyframes balloon-float {
  0%,
  100% {
    transform: perspective(900px) rotateX(-6deg) rotateY(3deg)
      translateY(0) rotate(0deg);
  }
  50% {
    transform: perspective(900px) rotateX(-3deg) rotateY(-2deg)
      translateY(-10px) rotate(1.6deg);
  }
}

/* ---------- 15. Fluid gradient host (report §2.3) ---------- */
.fluid {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.fluid > *:not(canvas) {
  position: relative;
  z-index: 1;
}

/* CSS fallback when WebGL is unavailable */
.fluid-css {
  background-image: radial-gradient(
      42% 60% at 22% 28%,
      var(--f1, #5c8540),
      transparent 62%
    ),
    radial-gradient(38% 55% at 74% 38%, var(--f2, #8fb268), transparent 62%),
    radial-gradient(46% 62% at 48% 78%, var(--f3, #c9a227), transparent 64%);
  background-size: 180% 180%;
  animation: fluid-drift 18s ease-in-out infinite alternate;
}

@keyframes fluid-drift {
  0% {
    background-position: 0% 0%, 100% 30%, 50% 100%;
  }
  100% {
    background-position: 40% 40%, 30% 80%, 90% 20%;
  }
}

/* ---------- 16. Lightfall backdrop ---------- */
/* ---------- Hinge fold (motion-hinge.js) ----------
   The spine stays put while both neighbouring pages roll toward it along
   arcs, so it has to out-stack them — the pages slide under the opaque
   crease band, which alone would leave the seam looking recessed rather
   than raised. */
[data-hinge="axis"] {
  position: relative;
  z-index: 4;
  /* `overflow: visible` takes the marquee's own `hidden` back off and moves
     the clipping job one level in — see the viewport rule just below.

     The strip cannot do both jobs at once. `hidden` crops every descendant
     flush at its border box, and a descendant's OUTER box-shadow is part of
     that descendant's paint, so the crease shadow — which by definition has
     to fall OUTSIDE the strip — was clipped away completely. Splitting the
     two keeps the track clipped and lets the crease spill. */
  overflow: visible;
}

/* The crease band: the strip's own box, made opaque while the fold is live.
   The two rigid pages travel exactly 28px toward the crease (CFG.arcTravel),
   so at the apex the upper page's bottom edge and the lower page's top edge
   both sit at the spine's centre line — they meet UNDER the strip and slide
   no further. The strip's own box (56px, centred on the spine) covers exactly
   that meeting region, so an opaque strip is all the occlusion the fold ever
   needs: no ±40px extension, no white sandwich — at rest the band is fully
   transparent (the lightfall shows through the seam exactly as before) and it
   goes opaque only while the fold is live, driven by the same --hinge-crease
   opacity the crease shadow uses. A cylinder gradient (darker toward its
   centre line) makes it read as the roller the sheet wraps. z-index:-1 keeps
   it inside the marquee's own stacking context (the marquee is z-index:4,
   above the panels) but below the strip's text and crease shadow. */
[data-hinge="axis"]::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--bg);
  background-image: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0) 16%,
    rgba(0, 0, 0, 0.2) 50%,
    rgba(0, 0, 0, 0) 84%,
    rgba(0, 0, 0, 0) 100%
  );
  opacity: var(--hinge-crease, 0);
  pointer-events: none;
}

/* The track is far wider than the screen and must stay clipped; the spine's
   own edges must not be. Clipping one level in instead of at the border box
   is visually identical — a line of centred text has no vertical overflow
   to lose — but it frees the seam. */
[data-hinge="axis"] > .marquee__viewport {
  overflow: hidden;
}

/* Without this the panels' own backgrounds can bleed through the seam
   while they are mid-fold. */
[data-hinge="top"],
[data-hinge="bottom"] {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  position: relative;
  /* Compositor-level smoothing for the scroll-linked fold: the paint
     loop writes a new translate3d every frame, and each write RESTARTS
     this short transition from the currently interpolated value — the net
     effect is a ~100ms low-pass filter on the path. Fast wheel steps
     (100px+/frame) arrive as a smooth chase instead of position pops, and
     release() clears the transform with a quick eased flatten rather than
     a one-frame snap. Pure GPU interpolation: it never repaints, which is
     why it does not reopen the paint-cost hole the loop closed. */
  transition: transform 0.1s cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Layering for the arc fold: the incoming page rides over the outgoing
   one, and the marquee sits on top of both so the crease stays a single
   unbroken strip while the two arcs slide across it. */
[data-hinge="top"] {
  z-index: 1;
}

[data-hinge="bottom"] {
  z-index: 2;
}

/* Only the INCOMING panel needs to be opaque, and only while it moves.

   The hero sits at z-index 1, the incoming section at 2, the marquee at 4
   — so the section slides up OVER the hero. Both boxes are transparent
   by design (the fixed lightfall backdrop shows through them), and that
   transparency made the hero's text readable straight through the
   incoming section's cards: both pages legible at once, which is the
   "two screens colliding" look rather than a fold.

   So the incoming panel grows an opaque backing layer whose opacity is
   the fold progress: it is fully transparent at rest (the lightfall
   streaks keep showing through exactly as before) and solidifies only
   while it is actually travelling over the hero. */
[data-hinge="bottom"]::before {
  content: "";
  position: absolute;
  inset: 0;
  /* z-index 0, NOT −1. The section itself is transparent, so a backing
     layer pushed behind it fell straight through to the lightfall
     backdrop and the hero stayed visible through the cards — the layer
     has to sit at the bottom of the section's own content, above its
     background, which is exactly z-index 0 before the children. */
  z-index: 0;
  background: var(--hinge-base, var(--bg));
  opacity: var(--hinge-cover, 0);
  pointer-events: none;
}

/* Promoting this layer is the single biggest win in the fold.

   Its opacity is driven from --hinge-cover every frame, and an opacity
   change on a layer the compositor does not own repaints the whole
   section — measured at 63 full-section repaints in one pass over the
   crease, dwarfing everything else put together. Handing it to the
   compositor turns each of those into a layer property the GPU applies on
   the next frame with nothing redrawn.

   Added only while the fold is live and taken away again at rest (JS adds
   `.hinge-veil`), so a screen-tall layer is not parked on the GPU for the
   whole page just to sit at opacity 0. */
[data-hinge="bottom"].hinge-veil::before {
  will-change: opacity;
}

/* …and everything inside the section has to sit above that backing,
   otherwise the cards themselves go behind it. */
[data-hinge="bottom"] > * {
  position: relative;
  z-index: 1;
}

/* Cylinder shading on each page: a gradient that darkens toward the crease,
   opacity ramped by the fold (--hinge-shade, 0…1, written from JS). A rigid
   panel painted with a curve reads as a curved surface — this is what sells
   the "bend" WITHOUT ever rotating the type, so the text stays perfectly
   upright and undeformed. Pinned to the seam-facing half so the darkest part
   sits exactly at the crease (which the opaque band hides anyway); the
   gradient fades to transparent away from the seam, so it never pokes out the
   wrong side of the spine. opacity only — composited, never repaints. */
[data-hinge="top"]::after,
[data-hinge="bottom"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  opacity: var(--hinge-shade, 0);
  will-change: opacity;
}
[data-hinge="top"]::after {
  bottom: 0;
  height: 42%;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.18) 100%);
}
[data-hinge="bottom"]::after {
  top: 0;
  height: 42%;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.18) 100%);
}

/* The outgoing hero's crease shade has to stay INSIDE the hero's own
   stacking context. Its panels sit at z-index 1 vs the incoming
   section's 2, so anything the hero paints — including its ::after —
   lands above the section's opaque backing, and the hero's stats stayed
   faintly readable through the cards. Clipping the shade to the panel's
   own edge does it without disturbing the panel's position. */
[data-hinge="top"] {
  isolation: isolate;
}

/* The outgoing hero needs NO backing layer of its own, and must not be
   given one.

   An earlier version added a 220px opaque strip along the hero's bottom
   edge (`::before`, z-index 50) to hide the stats row. It was wrong twice
   over:

   1. It hid nothing that needed hiding. The stats row is the hero's LAST
      content — `hero__proof`'s bottom edge is exactly the hero box's
      bottom edge — so as the fold deepens it is carried straight under
      the marquee and under the incoming section's opaque backing
      (z-index 2, cover = 1). Verified by hit-testing the whole overlap:
      every sampled row resolves to SECTION.section, never to the hero.
      The strip was covering content that was already covered.

   2. It cost the lightfall. The hero is transparent on purpose so the
      backdrop streaks read through it. An opaque strip spanning the
      bottom quarter of the hero (26% of it on a short viewport) replaced
      that with flat --bg and left a hard horizontal seam across the page
      — a stripe, not a fold. And because the strip was a FIXED height
      chasing content that MOVES with the fold, it covered half of the
      stats row (148–201 in) while leaving the other half (233–285) bare:
      a half-masked row looks worse than an unmasked one.

   Occlusion is the incoming panel's job alone. The hero just needs its
   own stacking context so its crease shade cannot reach over that
   backing. */

/* The arc fold translates the panels by at most CFG.arcTravel (28px) toward
   the crease, and the opaque crease band (above) is sized to swallow exactly
   that — so nothing ever pokes past the viewport edge and no bleed padding is
   needed; the panels keep their authored layout box exactly. */

/* ---------- The spine reads as the roller the sheet wraps ----------
   A static vertical gradient — darker top and bottom edges, brighter
   middle — turns the flat strip into a cylinder. Painted once by CSS;
   the fold only ever moves opacities, never this. */
[data-hinge="axis"] {
  background-image: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.1) 0%,
    rgba(0, 0, 0, 0) 32%,
    rgba(0, 0, 0, 0) 62%,
    rgba(0, 0, 0, 0.14) 100%
  );
}

/* ---------- The crease ----------
   Carried by its own layer pinned to the spine, never by the panels.

   The panels used to carry an ::after gradient for four rounds, at four
   widths (46% of the hero → 120px → 60px → 14px), and every width was
   rejected as a grey band. Tinting the pseudo-elements red/blue finally
   exposed why NO width could work: the panels' boxes EXTEND PAST the
   marquee (they overlap it by up to 127px so the seam closes), so anything
   pinned to a panel's top/bottom edge pokes out on the wrong side of the
   spine — the incoming panel's crease line showed ABOVE the marquee as a
   grey strip between the hero's stats row and the seam, exactly where no
   crease exists. A shadow pinned to a moving panel cannot know where the
   seam is; a layer pinned to the spine is the seam by construction.

   Why a layer and not an inline shadow on the spine itself:

   box-shadow is a PAINT property. Rewriting it every frame repaints the
   whole full-width strip on every frame of the fold — measured at 56
   repainted frames per pass. This layer carries the strongest shadow the
   fold will ever need, painted once, and motion-hinge.js only moves its
   OPACITY, which the compositor applies without repainting anything.

   It has to be allowed to spill past the strip, so the clipping lives one
   level in (see the marquee viewport note above the spine rule). */
[data-hinge="axis"]::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1; /* under the strip's own opaque background — only the part
                  that spills outside it is ever visible, which is exactly
                  what a crease shadow is */
  pointer-events: none;
  box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.22), 0 4px 12px rgba(0, 0, 0, 0.22);
  opacity: var(--hinge-crease, 0);
  will-change: opacity;
}

@media (prefers-reduced-motion: reduce) {
  [data-hinge="axis"]::after {
    opacity: 0 !important;
  }
}

/* z-index: -1 keeps it under the normal flow — so sections that
   declare their own --bg-alt / --bg-elev occlude it, and the
   transparent ones let it through. That contrast gives the page
   its light/dark rhythm without touching any existing z-index.

   The element carries --bg itself: folded sections shrink and let the
   page background show in the gaps, and without this base layer those
   gaps would fall through to the UA's default white. */
.lightfall-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background: var(--bg);
}

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

/* On a phone the same streak count is squeezed into a third of the width,
   so the lightfall turns into dense scratches behind the body copy. Dim it
   (and slightly in dark, where the streaks read brighter against the black). */
@media (max-width: 760px) {
  .lightfall-canvas {
    opacity: 0.55;
  }
}
[data-theme="dark"] .lightfall-canvas {
  opacity: 0.75;
}

body.has-lightfall {
  background: transparent;
}

/* per-element mount host */
.lightfall-host {
  position: relative;
  overflow: hidden;
}

/* CSS fallback when WebGL is unavailable */
.lightfall-css {
  background-color: var(--bg);
  background-image: radial-gradient(
      38% 55% at 20% 25%,
      var(--lf1, #b9d294),
      transparent 60%
    ),
    radial-gradient(34% 50% at 72% 32%, var(--lf2, #5c8540), transparent 62%),
    radial-gradient(42% 58% at 48% 80%, var(--lf3, #e0c46a), transparent 64%);
  background-size: 200% 200%;
  animation: lf-drift 22s ease-in-out infinite alternate;
}

@keyframes lf-drift {
  0% {
    background-position: 0% 0%, 100% 25%, 50% 100%;
  }
  100% {
    background-position: 45% 35%, 25% 75%, 85% 15%;
  }
}

/* ---------- 17. Live tuning panel (Shift+M / corner gear) ---------- */
.mt-tuner {
  position: fixed;
  right: 1rem;
  bottom: 4.5rem;
  z-index: 9998;
  width: 288px;
  max-height: min(68vh, 560px);
  overflow: auto;
  padding: 0.9rem 1rem 1rem;
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-mono);
  font-size: 11px;
  display: none;
}

.mt-tuner.is-open {
  display: block;
}

.mt-tuner__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--text-muted);
}

.mt-tuner__list {
  display: grid;
  gap: 0.55rem;
}

.mt-tuner__row {
  display: grid;
  grid-template-columns: 1fr 96px 34px;
  align-items: center;
  gap: 0.5rem;
}

.mt-tuner__name {
  color: var(--text-muted);
  line-height: 1.25;
}

.mt-tuner__row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.mt-tuner__val {
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

.mt-tuner__foot {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.9rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}

.mt-tuner__foot button {
  flex: 1;
  padding: 0.4rem 0.2rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 10px;
  cursor: pointer;
  transition: background-color 0.25s ease;
}

.mt-tuner__foot button:hover {
  background: var(--bg-alt);
}

.mt-tuner__diag {
  margin: 0.7rem 0 0;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-alt);
  color: var(--text);
  font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 190px;
  overflow: auto;
}

.mt-tuner__gear {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 9998;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.3s ease, transform 0.3s var(--ease-out);
}

.mt-tuner__gear:hover {
  opacity: 1;
  transform: rotate(45deg) scale(1.08);
}

/* hide the tuning affordance on touch devices */
@media (hover: none) {
  .mt-tuner__gear {
    display: none;
  }
}

/* ---------- Responsive: dial effects down on small screens ---------- */
@media (max-width: 900px) {
  .floaties {
    display: none;
  }
  .ghost-word {
    opacity: 0.03;
  }
  /* unpin: let the stage behave like an ordinary block */
  .stage {
    min-height: 0 !important;
  }
  .stage__pin {
    position: static !important;
    height: auto !important;
  }
  .stage-step {
    opacity: 1;
    transform: none;
  }
}

@media (hover: none) {
  .cursor-dot,
  .cursor-ring {
    display: none;
  }
}

/* ---------- Reduced motion: everything stills ---------- */
@media (prefers-reduced-motion: reduce) {
  .floaties {
    display: none;
  }
  .floatie {
    animation: none !important;
  }
  .cursor-dot,
  .cursor-ring {
    display: none !important;
  }
  [data-reveal-group] > * {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .tilt {
    transform: none !important;
  }
  .magnetic {
    transform: none !important;
  }
  .balloon svg {
    animation: none !important;
  }
  .fluid-css {
    animation: none !important;
  }
  .stage__pin {
    position: static !important;
    height: auto !important;
  }
  .stage {
    min-height: 0 !important;
  }
  .stage-step {
    opacity: 1;
    transform: none;
  }
}
