/* ═══════════════════════════════════════════════════════════════════════════════════════════════
   Scroll animations - reusable, global. Usage: <div data-animate="fade-up">…</div>
   Docs: docs/SCROLL_ANIMATION.md   Behaviour: public/js/scroll-animate.js

   • Only transform-class properties are animated (translate / scale / opacity): no layout work, no layout shift.
   • Uses the INDIVIDUAL properties `translate` and `scale` (not `transform`), so an element's own transform / hover effect keeps working.
   • Everything below is gated by `html.sa-js` (set by a tiny inline script in <head>): without JavaScript, or if the script fails to
     load (a failsafe removes the class), every element is simply visible.
   • Add a new animation type = add one block in the "TYPES" section. No JavaScript change.
   ═══════════════════════════════════════════════════════════════════════════════════════════════ */

/* ── Defaults (override per element with data-animate-* attributes, or globally on :root) ───── */
:root {
    --sa-duration: 800ms;
    --sa-distance: 80px;
    --sa-ease: cubic-bezier(.22, .61, .36, 1);
    --sa-zoom-in: .82;      /* start scale of zoom-in  */
    --sa-zoom-out: 1.18;    /* start scale of zoom-out */
    --sa-m: 1;              /* distance multiplier: smaller on phones (below) */
}
@media (max-width: 640px) { :root { --sa-m: .5; } }

/* ── Targets: a data-animate element, or an item inside a data-animate-stagger group ───────────
   (the group element itself is never animated; its items are)                                    */
html.sa-js [data-animate]:not([data-animate-stagger]),
html.sa-js [data-animate-stagger] [data-animate-item] {
    --sa-d: calc(var(--sa-dist, var(--sa-distance)) * var(--sa-m));
    --sa-x: 0px; --sa-y: 0px; --sa-s: 1; --sa-o: 1;
    translate: var(--sa-x) var(--sa-y);
    scale: var(--sa-s);
    opacity: var(--sa-o);
}

/* ── TYPES: the hidden (start) state of each animation ───────────────────────────────────────── */
/* slide only */
html.sa-js :is([data-animate="left"]:not([data-animate-stagger]),   [data-animate="left"][data-animate-stagger]   [data-animate-item]) { --sa-x: calc(var(--sa-d) * -1); }
html.sa-js :is([data-animate="right"]:not([data-animate-stagger]),  [data-animate="right"][data-animate-stagger]  [data-animate-item]) { --sa-x: var(--sa-d); }
html.sa-js :is([data-animate="top"]:not([data-animate-stagger]),    [data-animate="top"][data-animate-stagger]    [data-animate-item]) { --sa-y: calc(var(--sa-d) * -1); }
html.sa-js :is([data-animate="bottom"]:not([data-animate-stagger]), [data-animate="bottom"][data-animate-stagger] [data-animate-item]) { --sa-y: var(--sa-d); }
/* fade */
html.sa-js :is([data-animate="fade"]:not([data-animate-stagger]),   [data-animate="fade"][data-animate-stagger]   [data-animate-item]) { --sa-o: 0; }
/* zoom (with fade) */
html.sa-js :is([data-animate="zoom-in"]:not([data-animate-stagger]),  [data-animate="zoom-in"][data-animate-stagger]  [data-animate-item]) { --sa-s: var(--sa-zoom-in);  --sa-o: 0; }
html.sa-js :is([data-animate="zoom-out"]:not([data-animate-stagger]), [data-animate="zoom-out"][data-animate-stagger] [data-animate-item]) { --sa-s: var(--sa-zoom-out); --sa-o: 0; }
/* fade + slide */
html.sa-js :is([data-animate="fade-left"]:not([data-animate-stagger]),  [data-animate="fade-left"][data-animate-stagger]  [data-animate-item]) { --sa-x: calc(var(--sa-d) * -1); --sa-o: 0; }
html.sa-js :is([data-animate="fade-right"]:not([data-animate-stagger]), [data-animate="fade-right"][data-animate-stagger] [data-animate-item]) { --sa-x: var(--sa-d); --sa-o: 0; }
html.sa-js :is([data-animate="fade-up"]:not([data-animate-stagger]),    [data-animate="fade-up"][data-animate-stagger]    [data-animate-item]) { --sa-y: var(--sa-d); --sa-o: 0; }
html.sa-js :is([data-animate="fade-down"]:not([data-animate-stagger]),  [data-animate="fade-down"][data-animate-stagger]  [data-animate-item]) { --sa-y: calc(var(--sa-d) * -1); --sa-o: 0; }

/* ── Visible state (the script adds .sa-in while the element is in view, removes it when it has left) ── */
html.sa-js [data-animate].sa-in,
html.sa-js [data-animate-item].sa-in {
    translate: 0 0;
    scale: 1;
    opacity: 1;
}

/* ── The transition only exists WHILE animating (.sa-run, removed by the script afterwards), so an element's own
      transitions (hover effects etc.) are untouched the rest of the time ───────────────────────────────────── */
html.sa-js .sa-run {
    transition: opacity var(--sa-dur, var(--sa-duration)) var(--sa-easing, var(--sa-ease)) var(--sa-dl, 0ms),
                translate var(--sa-dur, var(--sa-duration)) var(--sa-easing, var(--sa-ease)) var(--sa-dl, 0ms),
                scale var(--sa-dur, var(--sa-duration)) var(--sa-easing, var(--sa-ease)) var(--sa-dl, 0ms);
    will-change: translate, scale, opacity;
}

/* ── Sideways slides must never create a horizontal scrollbar. `clip` (unlike `hidden`) does not create a scroll container,
      so position:sticky (the header) keeps working. Only on pages that actually use the animations. ───────────────────── */
html.sa-js body:has([data-animate], [data-animate-item]) { overflow-x: clip; }

/* ── Reduced motion: everything is shown at once, nothing moves ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    html.sa-js [data-animate]:not([data-animate-stagger]),
    html.sa-js [data-animate-stagger] [data-animate-item],
    html.sa-js .sa-run {
        translate: none !important;
        scale: none !important;
        opacity: 1 !important;
        transition: none !important;
        will-change: auto !important;
    }
}

/* ── Printing: show everything ─────────────────────────────────────────────────────────────────────────────────── */
@media print {
    html.sa-js [data-animate]:not([data-animate-stagger]),
    html.sa-js [data-animate-stagger] [data-animate-item] { translate: none !important; scale: none !important; opacity: 1 !important; transition: none !important; }
}
