/* =========================================================================
   Reliever website v3/v4 · motion system stylesheet
   Loads on every page AFTER /styles.css and the page's own stylesheet.

   Everything here describes a FINAL state. JS only ever takes over an
   element by flipping its section to [data-state="scrub"], which zeroes the
   start values so GSAP owns them. With JS off, motion off, or below 900px
   the page renders exactly what these rules describe and nothing moves.
   ========================================================================= */

/* --------------------------------------------------------------------------
   1. Masked line reveals — [data-lines]
   The wrappers are built by motion.js after fonts load; until then (and
   forever, without JS) the headline is plain text at its final state.
   -------------------------------------------------------------------------- */
.rl-line {
  display: block;
  overflow: hidden;
  /* descenders would be clipped by the mask, so the box grows and the
     extra space is pulled back out of the flow */
  padding-bottom: 0.14em;
  margin-bottom: -0.14em;
}
.rl-line__i {
  display: block;
  will-change: transform;
}
.rl-line__i .rl-w {
  display: inline;
}
[data-lines].is-drawn .rl-line__i {
  will-change: auto;
}

/* --------------------------------------------------------------------------
   2. Counters — [data-count]
   -------------------------------------------------------------------------- */
[data-count] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* --------------------------------------------------------------------------
   3. Ink strokes — hand-drawn SVG, 2px, round caps
   -------------------------------------------------------------------------- */
.ink-stroke {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  color: var(--ink);
  pointer-events: none;
}
.ink-stroke path,
.ink-stroke line,
.ink-stroke polyline {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.ink-stroke--purple {
  color: var(--purple);
}
.section--ink .ink-stroke,
.chapter .ink-stroke {
  color: #ffffff;
}

/* --------------------------------------------------------------------------
   4. Grid-paper ground — CSS only, 16px hairline grid at 6% ink
   -------------------------------------------------------------------------- */
.ground-grid {
  background-image:
    linear-gradient(to right, rgba(17, 17, 17, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(17, 17, 17, 0.06) 1px, transparent 1px);
  background-size: 16px 16px;
  background-position: center top;
}
.section--ink.ground-grid,
.chapter.ground-grid {
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
}

/* --------------------------------------------------------------------------
   5. Staggered reveal children — [data-reveal][data-stagger]
   The parent stops moving; its direct children carry the rise, with the
   delay written inline by motion.js.
   -------------------------------------------------------------------------- */
.js [data-reveal][data-stagger] {
  opacity: 1;
  transform: none;
}
.js [data-reveal][data-stagger] > * {
  opacity: 0;
  transform: translateY(14px);
}
.js [data-reveal][data-stagger].is-in > * {
  opacity: 1;
  transform: none;
  transition:
    opacity 560ms var(--ease),
    transform 560ms var(--ease);
}

/* --------------------------------------------------------------------------
   5b. Scale reveal — [data-reveal="scale"] (v4, the closing band prism)
   Same trigger as every reveal; the start state is a 0.96 scale instead of
   the 12px rise, and it settles a touch slower so the mark feels weighty.
   Reduced motion: /styles.css §12 forces the final state.
   -------------------------------------------------------------------------- */
.js [data-reveal="scale"] {
  transform: scale(0.96);
  transform-origin: 50% 50%;
}
.js [data-reveal="scale"].is-in {
  transform: none;
  transition:
    opacity 900ms var(--ease),
    transform 1200ms var(--ease);
}

/* --------------------------------------------------------------------------
   6. Prop field — [data-props] / [data-depth]
   A decorative, absolutely positioned layer. Each prop is placed and sized
   in percent of the field by the page stylesheet; nothing here affects
   document flow, so a prop that is slow to load cannot shift the page.
   -------------------------------------------------------------------------- */
.props {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.prop {
  position: absolute;
  height: auto;
  max-width: none;
  will-change: transform;
}

/* --------------------------------------------------------------------------
   7. Pinned chapter — [data-pin]
   Final state (CSS, always) and the scrub state (JS, desktop only).
   -------------------------------------------------------------------------- */
.chapter {
  position: relative;
  background: var(--ink);
  color: #ffffff;
  overflow: hidden;
  display: flex;
  align-items: center;
  /* reserved height — identical in both states, so pinning costs no CLS
     and the pinned chapter fills the viewport exactly */
  min-height: 100svh;
  padding-block: clamp(64px, 8vw, 112px);
}
.chapter > .wrap {
  position: relative;
  z-index: 2;
  width: 100%;
}
.chapter .eyebrow {
  color: rgba(255, 255, 255, 0.62);
}
.chapter__display {
  font-size: clamp(2.2rem, 6.2vw, 5.5rem);
  font-weight: 800;
  text-transform: uppercase;
  line-height: 0.98;
  letter-spacing: -0.028em;
  margin: 0;
  max-width: none;
  text-wrap: nowrap;
}
.chapter__display > span {
  display: block;
}
.chapter__display .is-purple {
  color: var(--purple-lift, #a56fe0);
}
.chapter__frags {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.frag {
  position: absolute;
  will-change: transform, opacity;
}

/* final: everything already in place */
[data-pin][data-state="final"] [data-pin-line],
[data-pin][data-state="final"] [data-pin-item] {
  opacity: 1;
  transform: none;
}
/* scrub: zeroed so GSAP owns the start values */
[data-pin][data-state="scrub"] [data-pin-line],
[data-pin][data-state="scrub"] [data-pin-item] {
  opacity: 0;
}

@media (max-width: 560px) {
  /* the display lines are authored to fit on one line; at phone widths they
     are allowed to break rather than be clipped */
  .chapter__display {
    text-wrap: wrap;
  }
}

@media (max-width: 899px) {
  .chapter {
    min-height: 0;
  }
  .chapter__frags {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   8. Card stack — [data-stack]
   Final state is the page's own grid. The scrub state stacks the cards on
   top of one another inside a fixed, reserved box.
   -------------------------------------------------------------------------- */
[data-stack][data-state="scrub"] {
  min-height: 100svh;
  display: flex;
  align-items: center;
  /* the pinned box must fit the viewport at 720px tall, so the section's
     own rhythm tightens while it is pinned */
  padding-block: clamp(40px, 5vw, 64px);
}
[data-stack][data-state="scrub"] .stack__inner {
  display: block;
  position: relative;
  width: 100%;
  max-width: 780px;
  height: clamp(272px, 38vh, 380px);
  margin-inline: auto;
}
[data-stack][data-state="scrub"] [data-stack-card] {
  position: absolute;
  inset: 0;
  margin: 0;
  will-change: transform;
}

/* --------------------------------------------------------------------------
   9. Rising sheet / sheet stack — [data-sheet]
   Three offset paper sheets hanging into the ink band below them. CSS
   scroll-driven where it exists, GSAP fallback in motion.js otherwise.
   -------------------------------------------------------------------------- */
.sheet-stack {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 90px;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}
.sheet {
  position: absolute;
  top: -1px;
  display: block;
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
  border-radius: 0 0 var(--radius-l) var(--radius-l);
}
.sheet--3 {
  left: 11%;
  right: 11%;
  height: 74px;
}
.sheet--2 {
  left: 5%;
  right: 5%;
  height: 54px;
}
.sheet--1 {
  left: 0;
  right: 0;
  height: 32px;
  border-radius: 0;
}

@keyframes sheetRise {
  from {
    transform: translateY(42%);
  }
  to {
    transform: translateY(0);
  }
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .sheet {
      animation: sheetRise linear both;
      animation-timeline: view();
      animation-range: entry 6% entry 72%;
    }
    .sheet--2 {
      animation-range: entry 10% entry 78%;
    }
    .sheet--1 {
      animation-range: entry 14% entry 84%;
    }
  }
}

/* --------------------------------------------------------------------------
   9b. Clip-path wipe — [data-wipe]
   A reveal that uncovers the element from its bottom edge upward. Both
   states live here, behind `.js` and behind a motion query, so no-JS and
   reduced motion render the element uncropped and nothing ever moves.
   [data-wipe-radius] carries the element's own border-radius through the
   wipe so the corners never square off mid-animation.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  .js [data-wipe] {
    clip-path: inset(100% 0 0 0 round var(--wipe-radius, 0px));
    will-change: clip-path;
  }
  .js [data-wipe].is-wiped {
    clip-path: inset(0 0 0 0 round var(--wipe-radius, 0px));
    transition: clip-path 900ms var(--ease);
    will-change: auto;
  }
}

/* --------------------------------------------------------------------------
   10. Tab panel mock — 200ms crossfade plus an 8px rise on tab change
   -------------------------------------------------------------------------- */
@keyframes vizRise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.tabpanel.is-shown .viz {
  animation: vizRise 220ms var(--ease) both;
}

/* --------------------------------------------------------------------------
   11. Reduced motion — every module at its final state, nothing moves
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .rl-line {
    overflow: visible;
  }
  .rl-line__i,
  .prop,
  .frag,
  .sheet,
  [data-pin-line],
  [data-pin-item],
  [data-stack-card] {
    animation: none !important;
    transform: none !important;
    opacity: 1 !important;
    will-change: auto !important;
  }
  .js [data-reveal][data-stagger] > *,
  .js [data-reveal][data-stagger].is-in > * {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .tabpanel.is-shown .viz {
    animation: none !important;
  }
  .js [data-wipe],
  .js [data-wipe].is-wiped {
    clip-path: none !important;
  }
}
