/*
 * Homepage motion layer. Loaded after home.css.
 *
 * Everything lives inside `prefers-reduced-motion: no-preference`, so visitors who ask
 * for less motion get the static page. States that hide content before it animates in
 * also require `html.motion` (set by an inline script in home.html), so the page stays
 * fully visible when JavaScript is off.
 *
 * Note on transforms: entrance animations use the individual `translate` / `scale`
 * properties, while hover and scroll effects use `transform`. The two compose instead
 * of overwriting each other.
 */

.home-page {
    --ease-out: cubic-bezier(.22, 1, .36, 1);
    --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
    /* Colours for the load-in wash, from the semantic token layer. */
    --wash-1: var(--text-brand-display);
    --wash-2: var(--bg-brand);
    --wash-3: var(--border-brand);
    --wash-4: var(--bg-brand-subtle);
}

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

    /* ---------- 1. Load-in colour wash on the hero ---------- */
    /* The wash runs across the header and the hero as one surface. Each gets its own
       pseudo-element, but both are position: fixed with identical gradient and circle,
       so they share viewport coordinates and line up exactly across the seam.
       clip-path: inset(0) clips each copy to its own box (fixed elements ignore overflow). */
    .hero, .site-header { isolation: isolate; }
    .hero { position: relative; overflow: hidden; clip-path: inset(0); }
    /* The header is only clipped while the wash plays. Once the animation ends, clip-path
       falls back to none, so the sticky header's shadow can show below it. */
    .site-header { animation: header-clip 1.8s; }
    @keyframes header-clip { from, to { clip-path: inset(0); } }

    /* Brand gradient that covers the top of the page, shifts hue across its stops, then
       contracts into the schedule mockup and reveals the light background underneath. */
    .hero::before,
    .site-header::before {
        content: "";
        position: fixed;
        inset: 0;
        z-index: -1;
        pointer-events: none;
        background: linear-gradient(120deg, var(--wash-1), var(--wash-2) 35%, var(--wash-3) 65%, var(--wash-4));
        background-size: 250% 250%;
        animation: hero-wash 1.6s var(--ease-out) .1s both;
    }
    @keyframes hero-wash {
        0%   { background-position: 0% 50%;   clip-path: circle(150% at 75% 55%); opacity: 1; }
        55%  { background-position: 100% 50%; clip-path: circle(90% at 75% 55%);  opacity: 1; }
        100% { background-position: 100% 50%; clip-path: circle(0% at 75% 55%);   opacity: 0; }
    }

    /* Soft glow that stays behind the hero after the wash and drifts slowly. */
    .hero::after {
        content: "";
        position: absolute;
        inset: -20%;
        z-index: -2;
        pointer-events: none;
        background:
            /* Centred low enough to fade out before the hero's top edge, so the glow
               doesn't draw a seam against the header. */
            radial-gradient(40% 35% at 78% 55%, var(--wash-4), transparent 70%),
            radial-gradient(30% 30% at 15% 85%, var(--wash-4), transparent 70%);
        opacity: 0;
        animation: hero-glow-in 1.2s ease 1.2s forwards, hero-glow-drift 18s ease-in-out 1.2s infinite alternate;
    }
    @keyframes hero-glow-in { to { opacity: .9; } }
    @keyframes hero-glow-drift {
        from { translate: 0 0; }
        to   { translate: -4% 3%; }
    }

    /* "15 minuten": a light band sweeps through the text, then an underline draws in. */
    .hero__title em {
        position: relative;
        display: inline-block;
        background: linear-gradient(100deg, var(--text-brand-display) 0 40%, var(--wash-3) 50%, var(--text-brand-display) 60% 100%);
        background-size: 250% 100%;
        background-position: 0% 0;
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
        animation: text-sweep 1.4s var(--ease-out) .9s both;
    }
    @keyframes text-sweep {
        from { background-position: 100% 0; }
        to   { background-position: 0% 0; }
    }
    .hero__title em::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: .02em;
        height: .09em;
        border-radius: 999px;
        background: var(--bg-brand);
        transform-origin: left center;
        scale: 0 1;
        animation: underline-draw .7s var(--ease-out) 1.5s forwards;
    }
    @keyframes underline-draw { to { scale: 1 1; } }

    /* ---------- 2. Hero entrance ---------- */
    .motion .hero__copy > * {
        animation: rise-in .7s var(--ease-out) both;
        animation-delay: calc(.35s + var(--i, 0) * 90ms);
    }
    .hero__copy > :nth-child(1) { --i: 0; }
    .hero__copy > :nth-child(2) { --i: 1; }
    .hero__copy > :nth-child(3) { --i: 2; }
    .hero__copy > :nth-child(4) { --i: 3; }
    .hero__copy > :nth-child(5) { --i: 4; }

    .motion .hero__visual .schedule { animation: rise-in .9s var(--ease-out) .55s both; }
    @keyframes rise-in {
        from { opacity: 0; translate: 0 24px; }
        to   { opacity: 1; translate: 0 0; }
    }

    /* Shifts fill in column by column, like the rooster is being generated.
       --col is set per cell by home-motion.js. */
    .motion .schedule .shift:not(.tone-empty) {
        animation: shift-pop .45s var(--ease-spring) both;
        animation-delay: calc(.9s + var(--col, 0) * 70ms);
    }
    @keyframes shift-pop {
        from { opacity: 0; scale: .6; }
        to   { opacity: 1; scale: 1; }
    }

    /* The green status pill and the toast land once the grid is full. */
    .motion .schedule__status { animation: shift-pop .5s var(--ease-spring) 1.55s both; }
    .motion .toast { animation: toast-in .7s var(--ease-spring) 1.75s both; }
    @keyframes toast-in {
        from { opacity: 0; translate: 0 18px; scale: .85; }
        to   { opacity: 1; translate: 0 0; scale: 1; }
    }

    /* ---------- 3. Scroll perspective on the toast ---------- */
    /* home-motion.js writes --scroll-p (about -0.5 … 1) on .hero__visual as it moves
       through the viewport: 0 when centred, 1 as it leaves at the top. */
    .hero__visual { --scroll-p: 0; }
    .toast {
        transform:
            perspective(700px)
            translate3d(calc(var(--scroll-p) * -18px), calc(var(--scroll-p) * -44px), calc(var(--scroll-p) * 70px))
            rotateX(calc(var(--scroll-p) * 22deg))
            rotateY(calc(var(--scroll-p) * -16deg));
        will-change: transform;
    }
    /* The schedule tilts slightly the other way, so the toast seems to float in front of it. */
    .schedule {
        transform:
            perspective(1400px)
            rotateX(calc(var(--scroll-p) * -6deg))
            translate3d(0, calc(var(--scroll-p) * 16px), 0);
    }

    /* ---------- 4. Minor effects ---------- */

    /* Pulsing ring on the hero badge dot. */
    .hero__badge .dot { position: relative; }
    .hero__badge .dot::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: 50%;
        background: currentColor;
        animation: dot-ping 2.4s ease-out 2.2s infinite;
    }
    @keyframes dot-ping {
        0%   { scale: 1;   opacity: .55; }
        70%  { scale: 2.8; opacity: 0; }
        100% { scale: 2.8; opacity: 0; }
    }

    /* Scroll reveal for elements marked data-reveal. --reveal-i staggers siblings. */
    /* The transition list also carries the hover properties (transform, shadow, border)
       without delay, because this rule outranks the cards' own transition. */
    .motion [data-reveal] {
        --reveal-delay: calc(var(--reveal-i, 0) * 110ms);
        opacity: 0;
        translate: 0 28px;
        transition:
            opacity .7s var(--ease-out) var(--reveal-delay),
            translate .7s var(--ease-out) var(--reveal-delay),
            transform .3s var(--ease-out),
            box-shadow .3s var(--ease-out),
            border-color .3s ease;
    }
    .motion [data-reveal].is-visible { opacity: 1; translate: 0 0; }

    /* Step numbers pop once their card is revealed. */
    .motion .step-card .step-card__number { scale: .4; opacity: 0; transition: scale .5s var(--ease-spring), opacity .3s ease; }
    .motion .step-card.is-visible .step-card__number {
        scale: 1;
        opacity: 1;
        transition-delay: calc(var(--reveal-i, 0) * 110ms + .25s);
    }

    /* Card hover lift. */
    .step-card, .benefit-card {
        transition: transform .3s var(--ease-out), box-shadow .3s var(--ease-out), border-color .3s ease;
    }
    .step-card:hover, .benefit-card:hover {
        transform: translateY(-6px);
        box-shadow: var(--shadow-soft);
    }
    .benefit-card:hover { border-color: var(--border-brand); }
    .benefit-card__icon { transition: transform .4s var(--ease-spring); }
    .benefit-card:hover .benefit-card__icon { transform: rotate(-8deg) scale(1.08); }

    /* Blog card arrow nudges on hover. */
    .blog-card__more svg { transition: transform .25s var(--ease-out); }
    .blog-card:hover .blog-card__more svg { transform: translateX(4px); }

    /* Primary buttons lift slightly. */
    .btn { transition: background-color .15s ease, border-color .15s ease, box-shadow .2s ease, transform .2s var(--ease-out); }
    .btn--primary:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 999px rgba(15, 23, 41, 0.06), var(--shadow-soft); }
    .btn:active { transform: translateY(0); }
}
