/* =====================================================================
   EHF — Motion system (motion.css)
   Fluid micro-interactions: spring easings (CSS linear() approximations
   with cubic-bezier fallback), press/pop/stagger utilities, scanner
   result flashes, and cross-document View Transitions.
   Philosophy: animate only state changes the user caused; everything is
   progressive enhancement and fully disabled under reduced motion.
   ===================================================================== */

:root {
    /* Fallback first (all browsers)... */
    --spring-snappy: cubic-bezier(.22, 1, .36, 1);
    --spring-gentle: cubic-bezier(.25, .9, .3, 1.05);
    --spring-bounce: cubic-bezier(.2, 1.2, .3, 1);
}

/* ...then true spring physics where linear() is supported. */
@supports (animation-timing-function: linear(0, 1)) {
    :root {
        /* damped spring: stiffness ~260, damping ~22 */
        --spring-snappy: linear(0, 0.1018 1.8%, 0.3897 5.9%, 0.9151 13.3%, 1.0822 17.2%,
            1.1357 20.2%, 1.1444 22.8%, 1.1187 26.7%, 1.0202 38.2%, 0.9924 44.2%,
            0.9899 50.7%, 1.0014 70.4%, 1 100%);
        /* softer spring: stiffness ~170, damping ~24 */
        --spring-gentle: linear(0, 0.0428 2.6%, 0.1551 5.9%, 0.4978 13.6%, 0.8423 21.6%,
            0.9844 26.4%, 1.0518 31.5%, 1.0701 36.4%, 1.0479 44.6%, 1.0061 56.8%,
            0.9928 64.6%, 0.9979 78.6%, 1 100%);
        /* playful overshoot: stiffness ~320, damping ~16 */
        --spring-bounce: linear(0, 0.1701 2.6%, 0.5887 7%, 1.0816 13%, 1.2042 16.1%,
            1.2491 19%, 1.2306 21.9%, 1.0921 28.8%, 1.0021 33.7%, 0.9577 38.6%,
            0.9636 44%, 1.0089 54.7%, 1.0035 65.7%, 0.9979 78.9%, 1 100%);
    }
}

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

    /* --- Press: tactile push on any actionable element --- */
    .m-press { transition: transform .14s var(--spring-snappy); }
    .m-press:active { transform: scale(.97); }

    /* --- Pop: enter animation for cards / result panels --- */
    .m-pop { animation: m-pop .42s var(--spring-snappy) both; }
    @keyframes m-pop {
        from { opacity: 0; transform: scale(.94) translateY(8px); }
        to   { opacity: 1; transform: scale(1) translateY(0); }
    }

    /* --- Stagger: children cascade in (set --i per child) --- */
    .m-stagger > * { animation: m-pop .38s var(--spring-gentle) both; animation-delay: calc(var(--i, 0) * 55ms); }

    /* --- Spring-vector action feedback (e.g. RSVP / book buttons) --- */
    .m-spring { transition: transform .35s var(--spring-bounce), box-shadow .35s var(--spring-bounce); }
    .m-spring.is-done { transform: scale(1.04); }

    /* --- Scanner result flash --- */
    .m-flash { animation: m-flash .5s var(--spring-snappy) both; }
    @keyframes m-flash {
        0%   { opacity: 0; transform: scale(.92); filter: saturate(1.6) brightness(1.25); }
        60%  { opacity: 1; transform: scale(1.015); }
        100% { opacity: 1; transform: scale(1); filter: none; }
    }

    /* --- Cross-document (MPA) View Transitions — Chromium 126+; ignored elsewhere --- */
    @view-transition { navigation: auto; }
    .topbar { view-transition-name: ehf-topbar; }
    ::view-transition-old(root) { animation: m-vt-out .22s ease both; }
    ::view-transition-new(root) { animation: m-vt-in .28s var(--spring-gentle) both; }
    @keyframes m-vt-out { to { opacity: 0; transform: translateY(-6px); } }
    @keyframes m-vt-in  { from { opacity: 0; transform: translateY(10px); } }
    /* Keep the shared chrome stable across pages. */
    ::view-transition-old(ehf-topbar), ::view-transition-new(ehf-topbar) { animation: none; }
}
