/* =========================================================
   JUSPIRE — MOTION

   Defines the global Juspire scroll-motion vocabulary and
   progressive behavior for native, fallback, and off modes.

   This is the only global home for Juspire keyframes and
   [data-ja-effect] rules.
   ========================================================= */

@layer ja-motion {
  /* =======================================================
     KEYFRAMES
     ======================================================= */

  @keyframes ja-rise {
    from {
      opacity: 0;
      translate: 0 var(--ja-travel-md);
    }

    to {
      opacity: 1;
      translate: 0 0;
    }
  }

  @keyframes ja-fade {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  @keyframes ja-unveil {
    from {
      clip-path: inset(100% 0 0 0);
    }

    to {
      clip-path: inset(-0.5rem -0.5rem -0.5rem -0.5rem);
    }
  }

  @keyframes ja-grow {
    from {
      scale: 0 1;
    }

    to {
      scale: 1 1;
    }
  }

  @keyframes ja-drift {
    from {
      translate: 0 calc(var(--ja-drift-md) * -1);
    }

    to {
      translate: 0 var(--ja-drift-md);
    }
  }

  @keyframes ja-horizon {
    from {
      clip-path: inset(
        12% 5% 0% 5% round var(--ja-round-lg) var(--ja-round-lg) 0 0
      );
    }

    to {
      clip-path: inset(0% 0% 0% 0% round 0 0 0 0);
    }
  }

  /* =======================================================
     STAGGER POSITION

     Shared by native scroll motion and fallback transitions.
     Steps are only for related siblings that reveal together.
     ======================================================= */

  [data-ja-step="1"] {
    --_step: 1;
  }

  [data-ja-step="2"] {
    --_step: 2;
  }

  [data-ja-step="3"] {
    --_step: 3;
  }

  [data-ja-step="4"] {
    --_step: 4;
  }

  [data-ja-step="5"] {
    --_step: 5;
  }

  [data-ja-step="6"] {
    --_step: 6;
  }

  [data-ja-step="7"] {
    --_step: 7;
  }

  [data-ja-step="8"] {
    --_step: 8;
  }

  /* =======================================================
     NATIVE MODE

     CSS scroll-driven animation is used only when supported,
     motion is explicitly native, and reduced motion is not
     requested.
     ======================================================= */

  @media (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: view()) {
      :root[data-motion="native"] [data-ja-effect] {
        --_from: calc(
          var(--ja-reveal-from) + var(--_step, 0) * var(--ja-stagger)
        );

        --_to: calc(var(--ja-reveal-to) + var(--_step, 0) * var(--ja-stagger));

        animation-timing-function: linear;
        animation-fill-mode: both;

        animation-timeline: view();
        animation-range: entry var(--_from) cover var(--_to);
      }

      :root[data-motion="native"] [data-ja-effect="rise"] {
        animation-name: ja-rise;
      }

      :root[data-motion="native"] [data-ja-effect="fade"] {
        animation-name: ja-fade;
      }

      :root[data-motion="native"] [data-ja-effect="unveil"] {
        animation-name: ja-unveil;
      }

      :root[data-motion="native"] [data-ja-effect="grow"] {
        animation-name: ja-grow;
        transform-origin: 0 50%;

        animation-range: entry 0% cover 50%;
      }

      :root[data-motion="native"] [data-ja-effect="drift"] {
        animation-name: ja-drift;

        animation-range: cover 0% cover 100%;
      }

      :root[data-motion="native"] [data-ja-effect="horizon"] {
        animation-name: ja-horizon;

        animation-range: entry 0% entry 100%;
      }

      /*
       * Scene binding must remain after the individual effect
       * ranges so it can override them.
       */
      :root[data-motion="native"] [data-ja-timeline="scene"] {
        animation-timeline: --ja-tl-scene;
        animation-range: contain 0% contain 100%;
      }
    }
  }

  /* =======================================================
     FALLBACK MODE

     IntersectionObserver writes data-state="in".

     Only rise, fade, and unveil receive fallback motion.
     Grow, drift, horizon, and scenes remain static.
     ======================================================= */

  :root[data-motion="fallback"]
    :is(
      [data-ja-effect="rise"],
      [data-ja-effect="fade"],
      [data-ja-effect="unveil"]
    ) {
    transition-property: opacity, translate, clip-path;

    transition-duration: var(--ja-time-slow);
    transition-timing-function: var(--ja-ease-out);

    transition-delay: calc(var(--_step, 0) * 90ms);
  }

  :root[data-motion="fallback"] [data-ja-effect="rise"]:not([data-state="in"]) {
    opacity: 0;
    translate: 0 var(--ja-travel-md);
  }

  :root[data-motion="fallback"] [data-ja-effect="fade"]:not([data-state="in"]) {
    opacity: 0;
  }

  :root[data-motion="fallback"]
    [data-ja-effect="unveil"]:not([data-state="in"]) {
    clip-path: inset(100% 0 0 0);
  }

  /* =======================================================
     PRINT

     Motion-dependent presentation is neutralized so all
     content prints in its completed state.
     ======================================================= */

  @media print {
    [data-ja-effect] {
      animation: none !important;
      opacity: 1 !important;
      translate: none !important;
      scale: none !important;
      clip-path: none !important;
      transition: none !important;
    }
  }
}
