/* M Auto Care - motion layer ("Redline Signal").
   Everything here runs only under prefers-reduced-motion: no-preference; with "reduce" the site only fades (last block).
   Hidden start states exist only under html.motion-ok (motion.js adds it after it has marked what is already on screen), so a failed
   script never hides content (§9.900, §9.1017). Only transform / opacity / clip-path move: layout shift stays 0. */

@media (prefers-reduced-motion: no-preference) {
    /* ── Scroll reveal: per component, staggered by --d; the class is dropped after arrival so hover transforms keep working (§9.1046) ── */
    html.motion-ok .rv:not(.rv-on) { opacity: 0; transform: translateY(24px); }
    html.motion-ok .rv { transition: opacity .7s var(--ease) calc(var(--d, 0) * 90ms), transform .7s var(--ease) calc(var(--d, 0) * 90ms); }

    /* ── Hero load sequence (pre-paint html.js, so nothing flashes): words rise one by one, then the lead, buttons and chips ── */
    html.js .hero .w { animation: word-up .75s cubic-bezier(.2, .8, .2, 1) calc(var(--w, 0) * 75ms + var(--kd, .15s)) backwards; }
    html.js .hero__eyebrow, html.js .hero__lead, html.js .hero .btn-row, html.js .hero__chips, html.js .hero__track { animation: fade-up .8s var(--ease) backwards; }
    html.js .hero__eyebrow { animation-delay: var(--kd, .15s); }
    html.js .hero__lead { animation-delay: calc(var(--kd, .15s) + .45s); }
    html.js .hero .btn-row { animation-delay: calc(var(--kd, .15s) + .6s); }
    html.js .hero__chips { animation-delay: calc(var(--kd, .15s) + .75s); }
    html.js .hero__track { animation-delay: calc(var(--kd, .15s) + .9s); }
    html.js .hero__window { animation: window-in 1s var(--ease) calc(var(--kd, .15s) + .2s) backwards; }
    @keyframes word-up { from { opacity: 0; transform: translateY(.55em) rotate(2deg); } }
    @keyframes fade-up { from { opacity: 0; transform: translateY(18px); } }
    @keyframes window-in { from { opacity: 0; transform: translateY(26px) scale(.97); } }

    /* ── Moment 1: the shop opens. The shutter covers the hero on the first visit of a session, rolls up, the fascia drops away ── */
    html.shutter-play .shutter { display: block; animation: shutter-up 1.1s cubic-bezier(.75, 0, .25, 1) .35s forwards; }
    html.shutter-play .shutter__fascia { animation: fascia-out .5s ease-in 1.35s forwards; }
    html.shutter-play .hero { --kd: 1.35s; --cd: 1.6s; --bd: 2.6s; }
    @keyframes shutter-up { to { transform: translateY(-104%); } }
    @keyframes fascia-out { to { opacity: 0; transform: scaleY(.08); } }

    /* ── The logo's car line draws itself (rear to front), its headlights switch on, a light beam sweeps the window ── */
    html.js .carline--draw { animation: draw 1.6s cubic-bezier(.65, 0, .35, 1) var(--cd, .5s) backwards; }
    @keyframes draw { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
    html.js .hero__beam { animation: beam 2.2s ease-out var(--bd, 1.6s) both; }
    @keyframes beam { 0% { opacity: 0; transform: translateX(-60%) skewX(-18deg); } 25% { opacity: 1; } 100% { opacity: 0; transform: translateX(260%) skewX(-18deg); } }
    .headlight { animation: headlight .5s ease-out calc(var(--bd, 1.6s) - .1s) backwards; }
    @keyframes headlight { from { opacity: 0; } }

    /* ── Hero photo window: each photo drifts slowly (Ken Burns, transform only) while the next one fades in over it; paused off-screen ── */
    .hero__window img.is-on, .hero__window img.is-prev { animation: ken-burns 9s linear both; }
    .hero__window img:nth-child(1) { transform-origin: 30% 65%; }
    .hero__window img:nth-child(2) { transform-origin: 72% 35%; animation-direction: reverse; }
    .hero__window img:nth-child(3) { transform-origin: 50% 20%; }
    .hero__window.is-off img { animation-play-state: paused; }
    @keyframes ken-burns { from { transform: scale(1); } to { transform: scale(1.1); } }

    /* ── Moment 7: ceramic sheen on photo cards, a slight 3D tilt on desktop (motion.js sets --rx / --ry) ── */
    .sheen { position: relative; overflow: hidden; }
    .sheen::after { content: ""; position: absolute; inset: -30% -60%; pointer-events: none; z-index: 1;
        background: linear-gradient(115deg, transparent 42%, color-mix(in srgb, var(--white) 38%, transparent) 50%, transparent 58%);
        transform: translateX(-70%); transition: transform 1s var(--ease); }
    @media (hover: hover) { .sheen:hover::after { transform: translateX(70%); } }
    @media (hover: hover) and (pointer: fine) {
        [data-tilt] { transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform .2s ease-out; }
        [data-magnetic] { transform: translate(var(--mx, 0px), var(--my, 0px)); }
    }

    /* ── Brand marquee: endless, paused on hover / by its button / off-screen ── */
    .marquee__track { animation: marquee 42s linear infinite; }
    .marquee:hover .marquee__track, .marquee.is-paused .marquee__track, .marquee.is-off .marquee__track { animation-play-state: paused; }
    @keyframes marquee { to { transform: translateX(-50%); } }

    /* ── A few soap bubbles rising in the wash band (paused off-screen) ── */
    .bubbles { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
    .bubbles i { position: absolute; bottom: -30px; left: var(--x, 50%); width: var(--s, 18px); height: var(--s, 18px); border-radius: 50%;
        border: 1.5px solid color-mix(in srgb, var(--white) 55%, transparent); background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--white) 45%, transparent), transparent 60%);
        animation: bubble var(--t, 9s) linear var(--dl, 0s) infinite; }
    .bubbles.is-off i { animation-play-state: paused; }
    @keyframes bubble { 0% { transform: translateY(0) scale(.6); opacity: 0; } 15% { opacity: .8; } 100% { transform: translateY(-420px) translateX(20px) scale(1.15); opacity: 0; } }

    /* ── Moment 6: tachometer needles sweep up to their value when the gauge comes into view ── */
    html.motion-ok .gauge:not(.is-on) .gauge__needle { transform: rotate(-120deg); }
    .gauge__needle { transition: transform 1.6s cubic-bezier(.2, .9, .25, 1.08); }

    /* ── The scanner screen: a scan line sweeps the blueprint (transform only; paused off-screen) ── */
    .scanner__line { animation: scan 4.2s ease-in-out infinite alternate; }
    .scanner.is-off .scanner__line { animation-play-state: paused; }
    @keyframes scan { from { transform: translateX(0); } to { transform: translateX(calc(100% - 3px)); } }

    /* ── Hazard lamps (live board, current /track stage): 1 blink a second, well under 3 flashes a second ── */
    .hazard { animation: hazard 1s steps(1, end) infinite; }
    @keyframes hazard { 50% { opacity: .25; } }

    /* ── Moment 3: a gloss glint runs across the shining half while the sponge wipes ── */
    .ba__box.is-wiping .ba__glint { animation: ba-glint .9s ease-out; }
    @keyframes ba-glint { 0% { transform: translateX(-35%); opacity: .2; } 45% { opacity: 1; } 100% { transform: translateX(35%); opacity: .6; } }

    /* ── /track (moment 5): the car drives to its stage, the beam lights on Ready, red and yellow tiles burst on Delivered ── */
    .trk-road__carwrap { animation: trk-drive 1.6s cubic-bezier(.3, .7, .2, 1) .25s backwards; }
    .trk-road__line i { animation: trk-fill 1.6s cubic-bezier(.3, .7, .2, 1) .25s backwards; }
    @keyframes trk-drive { from { transform: translateX(0); } }
    @keyframes trk-fill { from { transform: scaleX(0); } }
    .is-ready .trk-car__beam { animation: trk-beam 2.4s ease-in-out 1.9s infinite alternate; }
    @keyframes trk-beam { from { opacity: 1; } to { opacity: .55; } }
    .trk-burst i { animation: trk-burst 1.1s cubic-bezier(.2, .8, .3, 1) calc(1.8s + var(--i) * 25ms) 1 both; }
    @keyframes trk-burst { 0% { opacity: 1; transform: rotate(calc(var(--i) * 30deg)) translateY(0) scale(.6); } 100% { opacity: 0; transform: rotate(calc(var(--i) * 30deg)) translateY(-64px) scale(1); } }

    /* ── Page changes: a cross-fade, a service photo glides into its page (Chromium; others change page normally) ── */
    @view-transition { navigation: auto; }

    /* ── Scroll progress: CSS scroll timeline where supported, motion.js sets the scale elsewhere ── */
    @supports (animation-timeline: scroll()) {
        .progress { animation: progress linear both; animation-timeline: scroll(root block); }
        @keyframes progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
    .shutter { display: none !important; }
    .hero__window img:not(:first-child) { display: none; }
}
