/* ============================================================================
   LuxeChain - scroll motion layer
   Cinematic, Apple-register scroll animation for MARKETING surfaces only.

   HARD RULES (from the brief, and from how these things usually go wrong):
     * Never animate a dashboard, a form, a billing flow or a data table.
       Motion in a table you are reading costs comprehension; motion in a form
       you are filling in costs accuracy. Those surfaces opt out via body class
       (.admin, .app-shell, [data-no-motion]).
     * Content must be visible without JS. Every rule that hides something
       lives inside `.js-motion` on <html>, which only JavaScript adds. If the
       script fails to load, nothing is hidden and the page is simply static.
     * prefers-reduced-motion wins unconditionally.
     * Only `opacity` and `transform` are animated - both are compositor-only,
       so a 60fps scroll does not repaint. No layout, no width, no top/left.

   HOW IT IS WIRED
     motion.js adds `.js-motion` to <html>, then observes [data-reveal] and
     .reveal elements. Elements get `.in` on entry. Staggering is a CSS custom
     property (--i) set per child by the observer, so a 12-card grid needs no
     hand-written d1..d12 classes.
   ============================================================================ */

/* ---------------------------------------------------------------- tokens */
:root {
  /* One easing curve for the whole site. This is the cubic-bezier Apple's
     product pages use for entrance motion: fast start, long settle, no
     bounce. Anything springier reads as playful, which is wrong here. */
  --motion-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --motion-dur: 700ms;
  --motion-dur-sm: 480ms;
  --motion-lift: 24px;   /* how far a block travels on entry */
  --motion-stagger: 70ms; /* gap between sibling items */
}

/* ======================================================================
   REVEAL
   Base state is applied only when JS is present, so a no-JS visitor or a
   failed script never sees a blank page.
   ====================================================================== */
.js-motion [data-reveal] {
  opacity: 0;
  transform: translate3d(0, var(--motion-lift), 0);
  transition:
    opacity var(--motion-dur) var(--motion-ease),
    transform var(--motion-dur) var(--motion-ease);
  /* Delay comes from --i (index within its group), so stagger is data-driven */
  transition-delay: calc(var(--i, 0) * var(--motion-stagger));
  /* Hint the compositor without pinning a layer for the whole session. */
  will-change: opacity, transform;
}

.js-motion [data-reveal].in {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  /* Drop the hint once the animation has run: leaving will-change on dozens
     of elements permanently is what makes long pages feel heavy. */
  will-change: auto;
}

/* ---- variants ---- */
/* Pure fade, for content that would look odd sliding (images, logos). */
.js-motion [data-reveal="fade"] {
  transform: none;
}

/* Slight scale-up, used sparingly for hero media. */
.js-motion [data-reveal="scale"] {
  transform: translate3d(0, 12px, 0) scale(0.97);
}
.js-motion [data-reveal="scale"].in {
  transform: translate3d(0, 0, 0) scale(1);
}

/* Longer, slower lift for large section headings. */
.js-motion [data-reveal="title"] {
  --motion-lift: 34px;
  --motion-dur: 900ms;
}

/* A section that fades up as a whole, then its children arrive (opt-in). */
.js-motion [data-reveal-group] > * {
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition:
    opacity var(--motion-dur-sm) var(--motion-ease),
    transform var(--motion-dur-sm) var(--motion-ease);
  transition-delay: calc(var(--i, 0) * var(--motion-stagger));
  will-change: opacity, transform;
}
.js-motion [data-reveal-group].in > * {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  will-change: auto;
}

/* ======================================================================
   PROGRESSIVE TEXT REVEAL
   Words lift in from just below their final position, one after another.
   Markup is generated by motion.js (it splits the element's text into
   spans), so the source stays readable:
       <h2 data-text-reveal>Built for builders.</h2>
   The element's own text is preserved for screen readers and search.
   ====================================================================== */
.js-motion [data-text-reveal] .tw {
  display: inline-block;
  opacity: 0;
  transform: translate3d(0, 0.42em, 0);
  transition:
    opacity 620ms var(--motion-ease),
    transform 620ms var(--motion-ease);
  transition-delay: calc(var(--w, 0) * 42ms);
  will-change: opacity, transform;
}
.js-motion [data-text-reveal].in .tw {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  will-change: auto;
}
/* A word breaks across lines badly if it is its own inline-block; keep the
   natural space so line-breaking behaviour is unchanged. */
.js-motion [data-text-reveal] .tw + .tw { margin-left: 0.26em; }

/* ======================================================================
   PARALLAX
   A translation driven by scroll position, capped to a few pixels either
   way so it reads as depth rather than movement. Disabled wholesale below
   the tablet breakpoint and under reduced motion: parallax on a phone
   fightss browser-chrome collapse and jitters.
   ====================================================================== */
.js-motion [data-parallax] {
  transform: translate3d(0, var(--py, 0px), 0);
  will-change: transform;
}

/* ======================================================================
   STICKY STORYTELLING
   A sticky panel beside a column of steps. The panel does not animate on its
   own; the step list does, one step at a time.
   ====================================================================== */
@media (min-width: 900px) {
  .js-motion [data-story] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: clamp(32px, 5vw, 80px);
    align-items: start;
  }
  .js-motion [data-story-sticky] {
    position: sticky;
    top: 96px;               /* clears the fixed header */
    align-self: start;
  }
}
.js-motion [data-story-step] {
  opacity: 0.4;
  transition: opacity 500ms var(--motion-ease);
}
.js-motion [data-story-step].on {
  opacity: 1;
}

/* ======================================================================
   SECTION TRANSITION
   A very short fade as one section hands over to the next, so long pages do
   not have hard seams. Deliberately weak: at 0.5 opacity change it is felt,
   not noticed.
   ====================================================================== */
.js-motion [data-seam] {
  opacity: 0.55;
  transition: opacity 600ms var(--motion-ease);
}
.js-motion [data-seam].in {
  opacity: 1;
}

/* ======================================================================
   OPT-OUTS - these must be absolute.
   ====================================================================== */
/* Dashboards, admin, app shells, checkout and anything explicitly opted out
   never animate, even if a class slips through from a shared partial. */
.js-motion body.admin [data-reveal],
.js-motion body.admin [data-reveal-group] > *,
.js-motion body.admin [data-text-reveal] .tw,
.js-motion body.admin [data-parallax],
.js-motion [data-no-motion] [data-reveal],
.js-motion [data-no-motion] [data-reveal-group] > *,
.js-motion [data-no-motion] [data-text-reveal] .tw,
.js-motion [data-no-motion] [data-parallax],
.js-motion table [data-reveal],
.js-motion form [data-reveal] {
  opacity: 1 !important;
  transform: none !important;
  transition: none !important;
  will-change: auto !important;
}

/* ======================================================================
   REDUCED MOTION - unconditional override, last in the file so it wins.
   ====================================================================== */
@media (prefers-reduced-motion: reduce) {
  .js-motion [data-reveal],
  .js-motion [data-reveal-group] > *,
  .js-motion [data-text-reveal] .tw,
  .js-motion [data-seam],
  .js-motion [data-story-step] {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    will-change: auto !important;
  }
  .js-motion [data-parallax] {
    transform: none !important;
    will-change: auto !important;
  }
}

/* Parallax is desktop-only: on a phone the address bar collapses mid-scroll
   and every parallax offset visibly jumps. */
@media (max-width: 899px) {
  .js-motion [data-parallax] {
    transform: none !important;
    will-change: auto !important;
  }
}
