---
// Lenis smooth scroll — synced with GSAP ScrollTrigger
// Skipped entirely when prefers-reduced-motion is active
---
<script>
  import Lenis from '@studio-freight/lenis';
  import gsap from 'gsap';
  import { ScrollTrigger } from 'gsap/ScrollTrigger';

  const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

  if (!prefersReducedMotion) {
    // Disable native smooth scroll — Lenis handles it
    document.documentElement.style.scrollBehavior = 'auto';

    const lenis = new Lenis({
      duration: 0.8,
      easing: (t: number) => 1 - Math.pow(1 - t, 4),
      smoothWheel: true,
      wheelMultiplier: 1,
      touchMultiplier: 1.5,
    });

    // Sync Lenis scroll → ScrollTrigger (critical for scroll-driven animations)
    lenis.on('scroll', ScrollTrigger.update);

    // Drive Lenis via GSAP ticker only — NO separate requestAnimationFrame
    gsap.ticker.add((time: number) => {
      lenis.raf(time * 1000);
    });

    gsap.ticker.lagSmoothing(0);
  }
</script>
