/* ==========================================================================
   Rexa shared motion system  (loaded on every page after the main CSS)
   Pairs with assets/motion.js.  Rules of the system:
     - Motion only ever uses opacity + transform/translate (compositor-friendly).
     - Hidden "before" states exist ONLY under `.js` (set by an inline head
       script) or inside a CSS animation's from-keyframe, so a page is never
       left blank if scripts fail, are blocked, or the user prints.
     - prefers-reduced-motion and print show every element in its final state.

   API
     .reveal / .card-reveal / [data-reveal]   scroll reveal (fade + rise, once)
                                              optional  style="--delay:.12s"
     .rise-in                                 CSS-only entrance on load
                                              optional  style="--d:.15s"
     .float-a / .float-b                      gentle infinite float (up / down)
     .animate-float                           legacy alias (kept for old markup)
     .bar-fill                                progress fill:  style="--w:98%"
                                              grows when it (or an ancestor
                                              .reveal / section) gets .in-view
   ========================================================================== */

:root {
  --motion-ease: cubic-bezier(.22, 1, .36, 1);   /* same curve as styles.css fadeUp */
  --motion-rise: 26px;
}

/* ---------- 1. Scroll reveal ---------------------------------------------- */
.js .reveal,
.js .card-reveal,
.js [data-reveal] {
  opacity: 0;
  transform: translateY(var(--motion-rise));
  transition: opacity .85s var(--motion-ease), transform .85s var(--motion-ease);
  transition-delay: var(--delay, 0s);
}
.js .reveal.in-view,    .js .reveal.in,
.js .card-reveal.in-view, .js .card-reveal.in,
.js [data-reveal].in-view, .js [data-reveal].in {
  opacity: 1;
  transform: none;
}

/* ---------- 2. Entrance on load (no JS needed) ----------------------------- */
@keyframes rise-in {
  from { opacity: 0; translate: 0 16px; }
  to   { opacity: 1; translate: 0 0; }
}
.rise-in {
  animation: rise-in .7s ease-out both;
  animation-delay: var(--d, 0s);
}

/* ---------- 3. Float -------------------------------------------------------
   Uses the individual `translate` property so it composes with any Tailwind
   `transform` utilities already on the element (e.g. -translate-y-1/2). */
@keyframes float-a { 0%, 100% { translate: 0 0; } 50% { translate: 0 -8px; } }
@keyframes float-b { 0%, 100% { translate: 0 0; } 50% { translate: 0 8px; } }
.float-a, .float-b { will-change: translate; }
.float-a { animation: float-a 7s ease-in-out infinite; }
.float-b { animation: float-b 9s ease-in-out -3.5s infinite; }

/* Browsers without the `translate` property fall back to transform keyframes. */
@supports not (translate: 0 0) {
  @keyframes rise-in {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes float-a { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
  @keyframes float-b { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(8px); } }
  .float-a, .float-b { will-change: transform; }
}

/* Legacy alias: pages that already use `animate-float` (transform-based on
   purpose, so their existing look is unchanged). Replaces the per-page copies. */
@keyframes float-legacy { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.animate-float { animation: float-legacy 6s ease-in-out infinite; }

/* Revealed without animation because it was already scrolled past (motion.js). */
.is-instant, .is-instant .bar-fill { transition: none !important; }

/* Paused by motion.js while off-screen (saves battery on phones). */
.is-paused { animation-play-state: paused !important; }

/* ---------- 4. Progress fill ----------------------------------------------- */
.bar-fill {
  display: block;
  width: var(--w, 100%);
  transform-origin: left center;
}
.js .bar-fill {
  transform: scaleX(0);
  transition: transform 1s var(--motion-ease) .25s;
}
.js .bar-fill.in-view, .js .bar-fill.in,
.js .in-view .bar-fill, .js .in .bar-fill {
  transform: scaleX(1);
}

/* ---------- 5. Reduced motion: everything static and fully visible ---------- */
@media (prefers-reduced-motion: reduce) {
  .js .reveal, .js .card-reveal, .js [data-reveal] {
    opacity: 1; transform: none; transition: none;
  }
  .rise-in, .float-a, .float-b, .animate-float { animation: none; }
  .js .bar-fill { transform: none; transition: none; }
}

/* ---------- 6. Print: never print an invisible page -------------------------- */
@media print {
  .js .reveal, .js .card-reveal, .js [data-reveal] {
    opacity: 1 !important; transform: none !important; transition: none !important;
  }
  .rise-in, .float-a, .float-b, .animate-float { animation: none !important; }
  .js .bar-fill { transform: none !important; transition: none !important; }
}
