/* motion.css: ready-made scroll effects from the better-website-designs kit.
   Add data-fx="NAME" to an element. Mix them: no two neighbouring sections
   should use the same one. Everything is visible with JavaScript off, and
   reduced motion shows every final state at once.

   Needs motion.js for: wipe, mask-up, draw, scale-in, words, count-up.
   Pure CSS (scroll-driven, newer browsers; older ones show it still):
   parallax, zoom-out, tint, stack, sticky-steps.

   data-fx="wipe"        a picture is uncovered by a sliding edge (data-from="left|right|up|down")
   data-fx="mask-up"     each line of a heading rises out of a mask
   data-fx="draw"        an SVG's strokes draw themselves
   data-fx="scale-in"    a picture settles from 1.12 to 1 inside its frame
   data-fx="words"       a paragraph's words light up as it scrolls through
   data-fx="parallax"    a picture drifts slower than the page (data-speed="0.1 to 0.3")
   data-fx="zoom-out"    a hero picture zooms out as you scroll away
   data-fx="tint"        a section's background shifts to --fx-tint as it arrives
   class="fx-stack"      sections inside stick and the next one slides over (a curtain)
   class="fx-steps"      a sticky picture on one side, steps scroll past on the other
*/

:root{ --fx-dur:900ms; --fx-ease:cubic-bezier(.23,1,.32,1); }

@media (prefers-reduced-motion:no-preference){

  /* ---- class driven (motion.js adds .fx-in when seen) ---- */
  .js [data-fx="wipe"]{ clip-path:inset(0 100% 0 0); transition:clip-path var(--fx-dur) var(--fx-ease); }
  .js [data-fx="wipe"][data-from="right"]{ clip-path:inset(0 0 0 100%); }
  .js [data-fx="wipe"][data-from="up"]{ clip-path:inset(100% 0 0 0); }
  .js [data-fx="wipe"][data-from="down"]{ clip-path:inset(0 0 100% 0); }
  .js [data-fx="wipe"].fx-in{ clip-path:inset(0 0 0 0); }

  .js [data-fx="mask-up"] .fx-line{ display:block; overflow:hidden; padding-bottom:.08em; }
  .js [data-fx="mask-up"] .fx-line > span{ display:block; transform:translateY(105%);
    transition:transform var(--fx-dur) var(--fx-ease); transition-delay:var(--fx-delay, 0ms); }
  .js [data-fx="mask-up"].fx-in .fx-line > span{ transform:none; }

  .js [data-fx="draw"] :is(path, line, polyline, circle, rect){ stroke-dasharray:var(--fx-len, 2000); stroke-dashoffset:var(--fx-len, 2000);
    transition:stroke-dashoffset 1.6s var(--fx-ease); }
  .js [data-fx="draw"].fx-in :is(path, line, polyline, circle, rect){ stroke-dashoffset:0; }

  .js [data-fx="scale-in"]{ overflow:hidden; }
  .js [data-fx="scale-in"] > :is(img, picture, video){ transform:scale(1.12); transition:transform 1.4s var(--fx-ease); }
  .js [data-fx="scale-in"].fx-in > :is(img, picture, video){ transform:none; }

  /* ---- scroll driven (CSS only, where the browser supports it) ---- */
  @supports (animation-timeline: view()){
    [data-fx="parallax"]{ animation:fx-drift linear both; animation-timeline:view(); }
    @keyframes fx-drift{ from{ transform:translateY(calc(var(--fx-speed, .15) * 30%)); } to{ transform:translateY(calc(var(--fx-speed, .15) * -30%)); } }

    [data-fx="zoom-out"]{ animation:fx-zoom linear both; animation-timeline:view(); animation-range:exit 0% exit 100%; }
    @keyframes fx-zoom{ to{ transform:scale(1.15); opacity:.6; } }

    [data-fx="tint"]{ animation:fx-tint linear both; animation-timeline:view(); animation-range:entry 0% entry 60%; }
    @keyframes fx-tint{ from{ background-color:var(--fx-tint-from, transparent); } to{ background-color:var(--fx-tint, transparent); } }

    .js [data-fx="words"] .fx-w{ animation:fx-word linear both; animation-timeline:view(); animation-range:cover 20% cover 45%; }
    @keyframes fx-word{ from{ opacity:.18; } to{ opacity:1; } }
  }
}

/* Curtain: each section sticks, the next slides over it. Give every child a background. */
.fx-stack > *{ position:sticky; top:0; }
@media (prefers-reduced-motion:reduce){ .fx-stack > *{ position:static; } }

/* Sticky steps: picture holds on one side while the steps scroll past. */
.fx-steps{ display:grid; grid-template-columns:1fr 1fr; gap:clamp(1.5rem, 4vw, 4rem); align-items:start; }
.fx-steps__pin{ position:sticky; top:calc(var(--nav-h, 72px) + 2rem); }
.fx-steps__list > *{ min-height:70svh; display:flex; flex-direction:column; justify-content:center; }
@media (max-width:760px){
  .fx-steps{ grid-template-columns:1fr; }
  .fx-steps__pin{ position:relative; top:0; }
  .fx-steps__list > *{ min-height:auto; padding-block:1.5rem; }
}

/* Pinned story (extras/motion/story.js adds .is-story when GSAP runs) */
.is-story [data-story-media], .is-story [data-story-steps]{ display:grid; }
.is-story [data-story-media] > *, .is-story [data-story-steps] > *{ grid-area:1 / 1; }

/* ---- Finishing details (from V2's catalogue). Opt in with a class. ---- */

/* Link underline that draws in: class="link-draw" (single-line links) */
.link-draw{ text-decoration:none; background-image:linear-gradient(currentColor,currentColor);
  background-size:0% 1px; background-position:0 100%; background-repeat:no-repeat;
  transition:background-size 300ms var(--fx-ease); }
.link-draw:hover, .link-draw:focus-visible{ background-size:100% 1px; }

/* Arrow that nudges toward where it goes: <a class="nudge">See the menu <span class="nudge__arrow" aria-hidden="true">→</span></a> */
.nudge__arrow{ display:inline-block; transition:transform 250ms var(--fx-ease); }
.nudge:hover .nudge__arrow, .nudge:focus-visible .nudge__arrow{ transform:translateX(5px); }

/* Photo zooms inside a fixed frame on hover: class="zoom-frame" around the img */
.zoom-frame{ overflow:hidden; }
.zoom-frame img{ transition:transform 600ms var(--fx-ease); }
@media (hover:hover) and (pointer:fine){ a:hover .zoom-frame img, .zoom-frame:hover img{ transform:scale(1.04); } }

/* Before and after: a real range input, so keyboard and screen readers work.
   <div class="ba" style="--pos:50%"><img class="ba__after" ...><img class="ba__before" ...>
   <input class="ba__range" type="range" min="0" max="100" value="50" aria-label="Show before and after"></div> */
.ba{ position:relative; overflow:hidden; }
.ba img{ display:block; width:100%; height:auto; }
.ba__before{ position:absolute; inset:0; height:100%; object-fit:cover; clip-path:inset(0 calc(100% - var(--pos, 50%)) 0 0); }
.ba__range{ position:absolute; inset:auto 1rem 1rem; width:calc(100% - 2rem); accent-color:currentColor; }

/* Fine grain over large colour fields: class="grain" on body or a section. Never animate it. */
.grain{ position:relative; }
.grain::after{ content:""; position:absolute; inset:0; pointer-events:none; opacity:.04;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.8'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }

/* Layered shadow: three small stacked shadows, tinted with the palette's darkest colour (--shadow-tint) */
:root{ --shadow-lift:0 1px 2px rgb(var(--shadow-tint, 0 0 0) / .05), 0 4px 8px rgb(var(--shadow-tint, 0 0 0) / .05), 0 12px 24px rgb(var(--shadow-tint, 0 0 0) / .06); }

/* Header that hides when scrolling down and returns when scrolling up: data-hide-on-scroll on the header */
[data-hide-on-scroll]{ transition:transform 300ms var(--fx-ease); }
[data-hide-on-scroll].is-hidden{ transform:translateY(-100%); }
@media (prefers-reduced-motion:reduce){ [data-hide-on-scroll].is-hidden{ transform:none; } }
