/* Motion layer, light version: only one-shot effects that are cheap on old devices
   (opacity and small text transforms). No continuous animation, nothing that moves behind or
   with a backdrop-filter glass card, no pointer tracking.
   Everything is gated behind `html.motion` (set by the inline snippet in base.html, never
   under prefers-reduced-motion) and uses only the existing palette tokens.
   Disable per site with `motion: false` in config.yaml. */

@media screen and (prefers-reduced-motion: no-preference) {
    html.motion {
        --motion-ease: cubic-bezier(0.16, 1, 0.3, 1);
    }

    /* ---------- Page transitions (cross-document) ---------- */
    @view-transition {
        navigation: auto;
    }

    ::view-transition-old(root) {
        animation: m-vt-out 0.22s ease both;
    }

    ::view-transition-new(root) {
        animation: m-vt-in 0.4s ease both;
    }

    @keyframes m-vt-out {
        to { opacity: 0; }
    }

    @keyframes m-vt-in {
        from { opacity: 0; }
    }

    html.motion .site-header {
        view-transition-name: site-header;
    }

    /* ---------- Scroll progress bar (thin fixed bar, compositor only) ---------- */
    @supports (animation-timeline: scroll()) {
        html.motion .site-main::before {
            content: "";
            position: fixed;
            inset: 0 0 auto 0;
            height: 3px;
            z-index: 200;
            pointer-events: none;
            transform-origin: 0 50%;
            background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
            animation: m-progress linear both;
            animation-timeline: scroll(root);
        }

        @keyframes m-progress {
            from { transform: scaleX(0); }
            to { transform: scaleX(1); }
        }
    }

    /* ---------- Hero ---------- */
    /* Glass card fades in (opacity only: moving a backdrop-filter card re-blurs it per frame). */
    html.motion .hero-content {
        animation: m-fade 0.8s ease both;
    }

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

    /* Kinetic title: motion.js splits the h1 into .kt-word spans. */
    html.motion .hero-content h1:not(.kt-ready) {
        opacity: 0;
    }

    html.motion .kt-word {
        display: inline-block;
        max-width: 100%;
        transform-origin: 50% 100%;
        animation: m-word 0.85s var(--motion-ease) both;
        animation-delay: calc(0.25s + var(--i, 0) * 60ms);
    }

    @keyframes m-word {
        from {
            opacity: 0;
            transform: perspective(600px) translateY(0.7em) rotateX(-75deg);
        }
    }

    html.motion .hero-content h1.kt-whole {
        animation: m-rise 0.9s var(--motion-ease) 0.3s both;
    }

    html.motion .hero-subtitle {
        animation: m-rise 0.9s var(--motion-ease) 0.7s both;
    }

    @keyframes m-rise {
        from { opacity: 0; translate: 0 0.9rem; }
    }

    /* ---------- Scroll reveal (motion.js adds .is-in) ---------- */
    html.motion .site-main > .container > :is(.content-section, .page-title, .site-overview-page, .contact-section) {
        opacity: 0;
        transition: opacity 0.6s ease var(--reveal-delay, 0ms);
    }

    html.motion .site-main > .container > .is-in:is(.content-section, .page-title, .site-overview-page, .contact-section) {
        opacity: 1;
    }

    html.motion .site-main > .container > .content-section > .section-media {
        opacity: 0;
        transition: opacity 0.8s ease 0.18s;
    }

    html.motion .site-main > .container > .content-section.is-in > .section-media {
        opacity: 1;
    }

    html.motion .site-main > .container > .content-section > .section-inner > .section-list > li {
        /* --stagger is stamped by motion.js (capped). */
        transition: opacity 0.5s ease;
        transition-delay: calc(0.2s + var(--stagger, 0) * 45ms);
    }

    html.motion .site-main > .container > .content-section:not(.is-in) > .section-inner > .section-list > li {
        opacity: 0;
    }

    /* ---------- Menus ---------- */
    html.motion .dropdown:hover > .dropdown-content,
    html.motion .dropdown.is-open > .dropdown-content,
    html.motion .dropdown-item-has-children.is-open > .dropdown-content {
        animation: m-drop 0.24s var(--motion-ease) both;
    }

    @keyframes m-drop {
        from { opacity: 0; translate: 0 -0.45rem; }
    }

    html.motion .mobile-menu-overlay.open .mobile-nav > * {
        animation: m-rise 0.5s var(--motion-ease) both;
        animation-delay: calc(0.05s + var(--stagger, 0) * 35ms);
    }

    /* ---------- Hover (mouse only) ---------- */
    @media (hover: hover) and (pointer: fine) {
        /* Light sweep over call-to-action links. */
        html.motion .section-action-link {
            position: relative;
            overflow: hidden;
        }

        html.motion .section-action-link::after {
            content: "";
            position: absolute;
            inset: 0;
            pointer-events: none;
            background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.6) 50%, transparent 65%);
            translate: -110% 0;
        }

        html.motion .section-action-link:hover::after {
            translate: 110% 0;
            transition: translate 0.7s ease;
        }
    }
}
