/*
 * Ingredient motion: CSS only, on the browser's scroll-driven animations
 * (animation-timeline), so there is no script, nothing runs on the main
 * thread and nothing is hidden where the browser cannot animate it.
 * Opacity and transform only: no layout shift. Off under
 * prefers-reduced-motion, under "Switch off animations" of the display
 * settings (hoorneboeg-reduce-motion on html) and in print. A section
 * already in view when the page opens is at its end state at once, so the
 * first screen (and its largest image) is never held back.
 *
 * Levels: lively by default; expressive with the class
 * hoorneboeg-motion-expressive on body (inc/motion.php, from theme.json
 * settings.custom.motion); the demo pattern switches between calm, lively
 * and expressive with radio buttons and :has().
 * Blocks: all
 */

@media screen and (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: view()) {
        :root:not(.hoorneboeg-reduce-motion) :is(.wp-block-post-content > :not(:first-child, .hoorneboeg-motion-demo), .hoorneboeg-motion-demo-stage > *) {
            animation: hoorneboeg-motion-reveal linear both;
            animation-timeline: view();
            animation-range: entry 0% entry 60%;
        }

        /* The hero's image moves a little as the page scrolls away from it. */
        :root:not(.hoorneboeg-reduce-motion) .hoorneboeg-hero-image {
            overflow: clip;
        }

        :root:not(.hoorneboeg-reduce-motion) :is(.hoorneboeg-hero-image img, .hoorneboeg-hero .wp-block-cover__image-background) {
            animation: hoorneboeg-motion-drift linear both;
            animation-timeline: view();
            animation-range: exit 0% exit 100%;
        }

        /* Expressive: a longer way in, and section headings that unveil. */
        :root:not(.hoorneboeg-reduce-motion) :is(body.hoorneboeg-motion-expressive .wp-block-post-content, .hoorneboeg-motion-demo:has(input[value="expressive"]:checked) .hoorneboeg-motion-demo-stage) {
            --hoorneboeg-motion-distance: 4rem;
            --hoorneboeg-motion-scale: 0.96;
        }

        :root:not(.hoorneboeg-reduce-motion) :is(body.hoorneboeg-motion-expressive .wp-block-post-content > :not(:first-child, .hoorneboeg-motion-demo), .hoorneboeg-motion-demo:has(input[value="expressive"]:checked) .hoorneboeg-motion-demo-stage > *) h2 {
            animation: hoorneboeg-motion-unveil linear both;
            animation-timeline: view();
            animation-range: entry 10% entry 70%;
        }

        /* Calm, in the demo only: a calm site does not have this ingredient. */
        .hoorneboeg-motion-demo:has(input[value="calm"]:checked) :is(.hoorneboeg-motion-demo-stage > *, .hoorneboeg-motion-demo-stage h2) {
            animation: none;
        }
    }
}

@keyframes hoorneboeg-motion-reveal {
    from {
        opacity: 0;
        transform: translateY(var(--hoorneboeg-motion-distance, 1.5rem)) scale(var(--hoorneboeg-motion-scale, 1));
    }
}

@keyframes hoorneboeg-motion-drift {
    to {
        transform: scale(1.06);
    }
}

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

/* Page transitions of the expressive level (inc/motion.php turns them on): off with the display setting. */
:root.hoorneboeg-reduce-motion::view-transition-group(*),
:root.hoorneboeg-reduce-motion::view-transition-old(*),
:root.hoorneboeg-reduce-motion::view-transition-new(*) {
    animation: none;
}

/* The demo's choice. */
.hoorneboeg-motion-choice {
    display: flex;
    flex-wrap: wrap;
    gap: var(--wp--preset--spacing--30);
    margin: 0 0 var(--wp--preset--spacing--50);
    padding: 0;
    border: 0;
}

.hoorneboeg-motion-choice legend {
    margin-block-end: var(--wp--preset--spacing--20);
    padding: 0;
    font-weight: 600;
}

.hoorneboeg-motion-choice label {
    display: inline-flex;
    gap: var(--wp--preset--spacing--20);
    align-items: center;
    min-block-size: 2.75rem;
    padding-inline: var(--wp--preset--spacing--40);
    border: 1px solid var(--wp--preset--color--contrast);
    border-radius: var(--wp--custom--button-radius, 0.25rem);
    cursor: pointer;
}

.hoorneboeg-motion-choice label:has(input:checked) {
    background: var(--wp--preset--color--primary);
    color: var(--wp--preset--color--on-primary);
    border-color: var(--wp--preset--color--primary);
}

.hoorneboeg-motion-choice input:focus-visible {
    outline: var(--ee-focus-width, 2px) solid currentColor;
    outline-offset: 2px;
}

/* The demo's sections, side by side in width with the text above them. */
.hoorneboeg-motion-demo-stage > * {
    padding-inline: var(--wp--preset--spacing--50);
}
