/* ============================================================
   motion.css — how the page moves
   ============================================================
   Three mechanisms, and only three. Everything on the page is
   one of them, which is what keeps a page this animated from
   reading as a pile of separate effects:

     REVEAL   content arrives once, rising into place, and then
              stays put. Driven by [data-rise] plus an .in class
              the observer in index.html adds when the element
              first crosses into view. One-way on purpose: a
              block that re-hides itself every time it leaves
              the viewport turns a scroll back up into a second
              performance of something already read.

     SCRUB    the hero's copy and fan move with the scroll,
              written straight onto them by one rAF pass in
              index.html.

     AMBIENT  motion that owes nothing to the reader: the hero's
              drifting light and its bobbing cards. Without it a
              page that has finished revealing is a photograph.

   ARMING. Every start-state below is scoped to `.motion` on
   <html>, set by the head script. Unscoped, a browser that
   never ran the script would render a document of invisible
   boxes — the failure mode of a decoration must be "no
   decoration", never "no page".

   REDUCED MOTION. The block at the foot returns all three to
   their finished state and stops them there. It is one place,
   after everything, so a rule added above cannot miss it.
   ============================================================ */

:root {
  /* How far a revealing block travels, and how long it takes. One pair for
     the whole page: a reveal that is faster or further HERE than THERE reads
     as two different pages spliced together. */
  --rise:      28px;
  --rise-dur:  760ms;
  /* Out-expo's shape: nearly all the distance covered early, the last of it
     unhurried. Things arriving should decelerate into place, never coast. */
  --rise-ease: cubic-bezier(.22, .68, .28, 1);
  /* The one easing allowed to overshoot, and only for things that LAND —
     the pill being stamped, a card being dealt. */
  --settle:    cubic-bezier(.18, .89, .32, 1.06);
}

/* ============================================================
   1. REVEAL
   ============================================================ */

/* --rd is the element's own delay, set either by a rule below or by the
   stagger walk in index.html, which numbers the children of a
   [data-stagger] box. Two transitions rather than one on `all`: `all`
   would also animate whatever else the element changes on reveal. */
.motion [data-rise] {
  opacity: 0;
  transform: translate3d(var(--rx, 0px), var(--ry, var(--rise)), 0) scale(var(--rs, 1));
  transition: opacity   var(--rise-dur) var(--rise-ease) var(--rd, 0ms),
              transform var(--rise-dur) var(--rise-ease) var(--rd, 0ms);
}
/* `none`, not a restatement of the identity transform: it also releases the
   element's containing-block and stacking side effects once it has landed,
   so a revealed block behaves exactly like one that never animated.

   --ro is where it lands, not always 1: this sheet loads after the components
   (see the link order in index.html), so a plain `opacity: 1` here would
   overrule any element the design deliberately holds below full strength and
   brighten it on arrival. The backer credit is the one that does. */
.motion [data-rise].in { opacity: var(--ro, 1); transform: none; }

/* The variants. Only the start-state differs — duration, easing and the
   landed state are shared, so they are all recognisably one gesture. */
.motion [data-rise="left"]  { --rx: -32px; --ry: 0px; }
.motion [data-rise="right"] { --rx:  32px; --ry: 0px; }
.motion [data-rise="fade"]  { --ry: 0px; }
/* For the big composed blocks, like the create demo. They are wide
   enough that a pure lift barely reads; growing the last few percent into
   place is what registers at that size. */
.motion [data-rise="zoom"]  { --ry: 20px; --rs: .965; }

/* ============================================================
   2. THE HERO'S OPENING
   ============================================================
   The one sequence on the page that is timed rather than
   observed: it plays on load, because it is above the fold and
   nothing has to be scrolled to for it to be due. The order is
   the reading order — line, line, subtitle, button, and the
   credit last — and then the deck is dealt. Each step is set as that
   element's own --rd, so the whole score is these few lines
   rather than a queue in the script.
   ============================================================ */

/* --ro: the credit is dimmed as one piece by hero.css and must arrive at
   that dimness, not at full white and then settle. Last of the copy, after
   the button it sits under — it is the footnote, not the opening. */
.motion .hero .backed   { --rd: 560ms; --ro: .6; }
.motion .hero .subtitle { --rd: 360ms; }
.motion .hero .ctas     { --rd: 460ms; }

/* The headline's two lines, each lifting a fraction of its own size — em, so
   the travel scales with the clamped type instead of being a fixed 28px that
   is a lot on a phone and nothing on a desktop. Longer than the page's other
   reveals: it is the first thing said and it can afford the beat.

   inline-block is what makes them transformable at all; the <br> between
   them still decides the break, exactly as before. */
.motion .hero h1 .ln {
  display: inline-block;
  opacity: 0;
  transform: translate3d(0, .38em, 0);
  transition: opacity   700ms var(--rise-ease) var(--rd, 0ms),
              transform 940ms var(--rise-ease) var(--rd, 0ms);
}
.motion .hero h1 .ln.in { opacity: 1; transform: none; }
.motion .hero h1 .ln:first-child { --rd: 140ms; }
.motion .hero h1 .ln:last-child  { --rd: 250ms; }

/* The pill is STAMPED, not lifted: it arrives late, oversized and turned the
   wrong way, and snaps down onto the line it belongs to. --settle's overshoot
   is the impact. It lands on hero.css's own resting pose (rotate(1deg)), so
   the two rules agree on where it ends up. */
.motion .hero h1 em {
  opacity: 0;
  transform: rotate(-7deg) scale(1.55);
  transform-origin: 50% 60%;
  transition: opacity   300ms ease-out       var(--rd, 0ms),
              transform 560ms var(--settle)  var(--rd, 0ms);
  --rd: 640ms;
}
.motion .hero h1 em.in { opacity: 1; transform: rotate(1deg) scale(1); }

/* ----- The deck being dealt --------------------------------------
   The fan's cards are described as "dropped on a table" (hero.css), so they
   arrive that way: from below, flat, and each straightening into its own
   rotation as it lands. The counter-rotation is the whole trick — the SLOT
   starts turned by the negative of the card's rest angle, which cancels it,
   so the card reads as square until the slot unwinds to zero and lets the
   card's own tilt show. Nothing about the card is touched, which matters:
   .course's transform is a single shared pipeline (hero.css) that hover and
   the tilt script both feed, and a second hand on it would fight them.

   Then it hands straight over to the bob. Two animations on one property:
   the deal has finished by the time the bob starts, and the bob is later in
   the list, so it wins from that moment on. Both agree on translate(0) at the
   join, so there is no step. */
.motion .fan .fan-slot { opacity: 0; }
.motion .fan .fan-slot.in {
  animation: deal 820ms var(--settle) var(--rd, 0ms) both,
             bob  var(--bob, 7s) ease-in-out calc(var(--rd, 0ms) + 820ms) infinite;
}

@keyframes deal {
  from { opacity: 0;
         transform: translate3d(0, 54px, 0) scale(.9)
                    rotate(calc(var(--rot, 0deg) * -1)); }
  to   { opacity: 1; transform: none; }
}

/* AMBIENT. No two cards share a period or a distance, and none is a multiple
   of another, so the row never resynchronises into a wave — it just breathes.
   A few pixels on purpose: the cards should read as resting, barely breathing. */
@keyframes bob {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50%      { transform: translate3d(0, var(--bobY, -9px), 0); }
}
.motion .fan .fan-slot:nth-child(1) { --rd: 620ms; --bob: 9.4s;  --bobY: -3px; }
.motion .fan .fan-slot:nth-child(2) { --rd: 720ms; --bob: 8.1s;  --bobY: -2px; }
.motion .fan .fan-slot:nth-child(3) { --rd: 820ms; --bob: 10.7s; --bobY: -3px; }
.motion .fan .fan-slot:nth-child(4) { --rd: 920ms; --bob: 8.8s;  --bobY: -2px; }

/* ----- The light on the panel ------------------------------------
   Two soft fields drifting across the orange on unrelated periods, so the
   panel is never quite the flat colour it was a moment ago. Gradients, not a
   blur filter: a filter this size would be repainted every frame of a 30s
   loop for the same result.

   z-index -1 puts them above .hero's own background and below its content
   without any of that content needing a layer of its own (.hero already
   opens a stacking context, so -1 cannot escape it). Bounded well short of
   the panel's foot: below that the ramp is turning white, and a warm field
   drifting over white is a stain rather than light. */
.motion .hero { overflow: clip; }
.motion .hero::before,
.motion .hero::after {
  content: ''; position: absolute; z-index: -1; pointer-events: none;
  inset: -15% -10% 34% -10%;
}
.motion .hero::before {
  background: radial-gradient(42% 52% at 26% 34%,
                rgba(255, 255, 255, .20), transparent 68%);
  animation: driftA 27s ease-in-out infinite alternate;
}
.motion .hero::after {
  background: radial-gradient(38% 46% at 76% 20%,
                rgba(255, 214, 170, .26), transparent 70%);
  animation: driftB 39s ease-in-out infinite alternate;
}
@keyframes driftA {
  from { transform: translate3d(-4%, -3%, 0) scale(1);    }
  to   { transform: translate3d( 5%,  4%, 0) scale(1.18); }
}
@keyframes driftB {
  from { transform: translate3d( 4%,  2%, 0) scale(1.12); }
  to   { transform: translate3d(-5%, -3%, 0) scale(.94);  }
}

/* ============================================================
   3. SCRUB — position as a function of scroll
   ============================================================ */

/* The hero's copy leaves slower than the page and fades as it goes; the fan
   rises a little faster. The script writes their transform and opacity
   directly (a variable on the root would restyle the whole page every
   frame); these only put them on layers of their own. The column moves as
   ONE object, which is why .hero-copy exists (hero.css). */
.motion .hero-copy  { will-change: transform, opacity; }
.motion .hero .stage { will-change: transform; }


/* ============================================================
   4. THE REST OF THE PAGE
   ============================================================ */

/* The bar gets out of the way going down and comes back the moment you turn
   around — on a page this tall a fixed pill in front of the content for six
   thousand pixels is furniture, not navigation. It keeps its own centring
   translate in every state, since transform is one property and a rule that
   only set Y would drop the -50%. */
.motion header {
  transition: opacity 300ms ease,
              box-shadow 300ms ease;
}
/* It FADES, it does not slide. A bar that spans the whole page sweeping up
   and off is a lot of movement for something the reader did not ask to
   happen, and it pulled the eye back to the top every time they scrolled
   down. Going quiet is enough. pointer-events with it, or an invisible bar
   keeps taking clicks along the top edge of the page. */
.motion header.hide  { opacity: 0; pointer-events: none; }
/* Off the top of the page it is floating over content rather than sitting on
   the hero, and wants to say so. */
/* Nothing. The bar takes its surface from header.css when it passes the hero
   and needs no edge drawn under it; a line here was the white-on-white rule
   that showed up the moment you scrolled. */
.motion header.stuck { box-shadow: none; }

/* Both demos rebuild their block from scratch on every cycle (index.html), so
   an animation declared here simply runs again each time one is inserted — no
   state to reset, nothing to re-trigger. It is the page's only self-repeating
   reveal, and it is right that it repeats: the content underneath is genuinely
   new each time.

   The topics come in behind their card, one after another, which is also the
   order they would fill in. :nth-child is the stagger here rather than the
   script's walk, because these elements are written by innerHTML long after
   that walk has run. */
.motion .make-out .use   { animation: swap 560ms var(--rise-ease) both; }
.motion .make-out .topic { animation: swap 560ms var(--rise-ease) both; }
.motion .make-out .topic:nth-child(1) { animation-delay:  90ms; }
.motion .make-out .topic:nth-child(2) { animation-delay: 170ms; }
.motion .make-out .topic:nth-child(3) { animation-delay: 250ms; }
.motion .make-out .topic:nth-child(4) { animation-delay: 330ms; }
@keyframes swap {
  from { opacity: 0; transform: translate3d(0, 16px, 0); }
  to   { opacity: 1; transform: none; }
}

/* The answer's text slides down out of the question rather than appearing
   already in place — the height is opening anyway (faq.css), and matching the
   copy to it is what makes the row read as unfolding. */
.motion .faq-a p {
  transform: translate3d(0, -8px, 0);
  transition: transform 320ms var(--rise-ease);
}
.motion .faq-item.open .faq-a p { transform: none; }

/* The two calls to action, and nothing else. button.css deliberately gives
   the recipe no transition — hover and press land instantly, as the app's own
   Pressable does — and that stays true of every button on the page but these
   two, which are the page's whole purpose and are allowed to answer. */
.motion .button--cta {
  transition: transform 200ms var(--rise-ease);
}
.motion .button--cta:hover { transform: translateY(-2px); }
/* _pressedScale, restated: button.css sets it on :active, but this sheet
   loads after it and [data-rise].in pins the closing CTA's transform to
   none — which on a touch device is exactly where the press would show. */
@media (hover: none) {
  .motion .button--cta:active { transform: scale(0.97); }
}

/* ============================================================
   5. REDUCED MOTION
   ============================================================
   Everything above, returned to the state it was heading for
   and stopped there. Nothing is left half-arrived: a reader who
   asked for no motion still gets the whole page, laid out
   exactly as the animated one finishes.
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  /* --ro, not a literal 1, for the same reason the reveal itself uses it:
     what a block lands on is not always full strength, and this block has to
     land on exactly what the animated one would have. */
  .motion [data-rise],
  .motion [data-rise].in,
  .motion .hero h1 .ln,
  .motion .fan .fan-slot {
    opacity: var(--ro, 1) !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
  }
  .motion .hero h1 em,
  .motion .hero h1 em.in {
    opacity: 1 !important;
    transform: rotate(1deg) !important;
    transition: none !important;
  }
  .motion .hero-copy,
  .motion .hero .stage {
    transform: none !important;
    opacity: 1 !important;
    will-change: auto;
  }
  .motion .hero::before,
  .motion .hero::after,
  .motion .make-out .use,
  .motion .make-out .topic { animation: none !important; }
  /* The bar stays put rather than sliding away; the shadow may still change,
     since a colour is not motion. */
  .motion header,
  .motion header.hide { opacity: 1 !important; pointer-events: auto;
                        transition: none; }
  .motion .faq-a p,
  .motion .button--cta { transition: none !important; }
  .motion .faq-a p { transform: none !important; }
}
