/*
 * ck-motion-v3 — the store's motion layer, in one place.
 *
 * v3 is v2 with the product grid's skeletons: while a card's picture has not painted yet, its
 * media box carries the shop's skeleton shimmer and the picture fades in when it arrives. The
 * wait state is a class only the script ever puts on, so without JavaScript no picture is
 * hidden. A new filename, not a query string, because the edge holds a stylesheet URL for a week.
 *
 * Loaded after every other sheet so its tokens are the last word, and it owns only what §11 of
 * the brief asks for: durations, easings and the animations themselves. Nothing here changes a
 * layout, a size or a colour, so with this file missing the store is the store it was this morning.
 * The one exception is deliberate: the coupon card's frame is ck-coupon-v1.css, so a shopper with
 * every switch off still reads what they save and until when.
 *
 * Three switches, and they are independent:
 *   html[data-ckm="off"]     the admin's master switch (App\Support\MotionControl) — nothing moves.
 *   html[data-ckm="subtle"]  the same one-shot changes, and none of the repeating loops.
 *   html[data-ckm-off="price ship"]  one animation off on its own, the rest still running (§13).
 *   prefers-reduced-motion   the shopper's own device setting, which outranks both, below.
 * Each ends in the same place for the reader: no transform, no loop, only a short opacity change
 * where a change of state would otherwise be invisible.
 *
 * Everything animates transform or opacity, never width/height/top, so the work stays on the
 * compositor and cannot push a card around while the page is being read (§12, no layout shift).
 *
 * What this file carries is what the storefront really draws: the scroll reveal, the price row, the
 * free-shipping truck, the picture that flies to the cart, the announcement line, the coupon card,
 * and the four effects the motion brief names that no other file owned — the hero headline's
 * entrance, the slow drift behind the hero's gradient, the product card's hover and press, and the
 * entrance the homepage makes as the front-door advertisement hands it back. The price-drop badge
 * (§3), the free-shipping progress line (§1) and the delivery stages (§8) still wait for the waves
 * that have recorded prices, a configured free-delivery minimum and real order events to put in
 * them — until then there is nothing truthful for them to show, and an invented deadline is what
 * §6 forbids.
 */

:root {
    /* §11's bands, one token each so a wave never has to guess a number again. */
    --ckm-micro: 180ms;
    --ckm-card: 300ms;
    --ckm-price: 420ms;
    --ckm-page: 260ms;
    --ckm-loop: 9s;
    --ckm-out: cubic-bezier(.22, .61, .36, 1);
    --ckm-in: cubic-bezier(.16, .84, .44, 1);
}

/*
 * The admin's switches live in the stylesheet as well as the script, because a shopper with
 * JavaScript off still gets what the store asked for. `off` is total: every animation and every
 * transition in this file collapses to nothing, and the store is what it was before this sheet
 * existed. `subtle` keeps the changes that explain what just happened and drops the loops that
 * only ever repeat.
 */
html[data-ckm="off"] * {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
}

html[data-ckm="subtle"] {
    --ckm-card: 200ms;
    --ckm-price: 240ms;
}

html[data-ckm="subtle"] [data-ckm-ship].is-driving .ckm-drive {
    animation: none;
}

/* — scroll reveal ————————————————————————————————————————————————
   Only the script arms a row, and only when it is already below the fold, so a card the shopper
   can see at first paint is never hidden by this file. .ckm-late is the armed state. */
.ckm-late {
    opacity: 0;
    transform: translate3d(0, 14px, 0);
}

.ckm-late.is-in {
    opacity: 1;
    transform: none;
    transition: opacity var(--ckm-card) var(--ckm-out), transform var(--ckm-card) var(--ckm-out);
}

/* — price (§2) —————————————————————————————————————————————————————
   The new figure slides up into the old one's place; the strike is drawn rather than switched so
   the eye follows what changed. Both only ever run when the number on the page actually changed —
   the script compares the text and does nothing when it is the same, so a variant switch that
   lands on the same price produces no movement at all. */
.ckm-now {
    display: inline-block;
}

.ckm-now.is-changed {
    animation: ckm-rise var(--ckm-price) var(--ckm-in);
}

@keyframes ckm-rise {
    from { opacity: 0; transform: translate3d(0, .5em, 0); }
    to   { opacity: 1; transform: none; }
}

/*
 * The old price carries a real strike at all times, JavaScript or not, because an unstriked
 * compare-at figure reads as a second price. When the number on the page changes the script adds
 * .is-struck: the text decoration goes and a drawn line takes its place in the same frame,
 * travelling left to right. The drawn line ends exactly where the decoration was, so the reader
 * sees one strike before, during and after — never two, never none.
 */
.ckm-was {
    position: relative;
    display: inline-block;
    text-decoration: line-through;
}

.ckm-was::after {
    content: "";
    position: absolute;
    left: 0;
    top: 52%;
    width: 100%;
    height: 2px;
    background: currentColor;
    transform: scaleX(1);
    transform-origin: left center;
    opacity: 0;
}

.ckm-was.is-struck {
    text-decoration: none;
}

.ckm-was.is-struck::after {
    opacity: 1;
    animation: ckm-strike var(--ckm-price) var(--ckm-out) forwards;
}

@keyframes ckm-strike {
    from { transform: scaleX(0); }
    to   { transform: scaleX(1); }
}

/* — free shipping (§1) ———————————————————————————————————————————————
   [data-ckm-ship] is the behaviour hook and it goes on the shipping line the store already writes
   — Product::freeShippingBadgeText() on a card, the shipping notice on the detail page and in the
   cart. That markup only appears where the goods genuinely qualify, so this adds movement to a
   true statement and never a promise of one. The script watches the hook and holds .is-driving
   only while the line is on screen, and what it animates is .ckm-drive: the storefront's own truck
   glyph, nudged along the row at whatever size the page already measured it into. */
[data-ckm-ship].is-driving .ckm-drive {
    animation: ckm-drive var(--ckm-loop) linear infinite;
}

@keyframes ckm-drive {
    0%, 100% { transform: translate3d(0, 0, 0); }
    45%      { transform: translate3d(3px, 0, 0); }
    50%      { transform: translate3d(3px, -.4px, 0); }
    95%      { transform: translate3d(0, 0, 0); }
}

/* — add to cart (§5) ——————————————————————————————————————————————————
   The clone is made by the script out of the picture already on screen and is gone when it lands.
   It is position:fixed, so it cannot shift a row, and the real add has already finished on the
   server before this starts — an animation never sits in front of a cart write. */
.ckm-fly {
    position: fixed;
    z-index: 60;
    width: 54px;
    height: 54px;
    border-radius: 12px;
    object-fit: cover;
    pointer-events: none;
    will-change: transform, opacity;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .18);
}

/* — the announcement line (§13) ———————————————————————————————————————
   One-shot entrance and no loop: a strip of text scrolling forever on a phone is motion for its
   own sake, which is what §11 warns against, and battery the target device cannot spare. */
.ckm-drop-in {
    animation: ckm-drop-in var(--ckm-page) var(--ckm-out) 1;
}

@keyframes ckm-drop-in {
    from { opacity: 0; transform: translate3d(0, -6px, 0); }
    to   { opacity: 1; transform: none; }
}

/* — coupon cards (§9) and the deadline they carry (§6) ——————————————————
   Two moments are worth moving and neither of them is the clock. The card arrives once, the same way
   a page element does, because it is a promise the shop has just made; and the code gives under the
   finger when it is taken, because a copy that happens silently is a copy nobody believes.
   The countdown itself is never animated: the digits swap inside a box of their own width, which is
   a text change and not motion, and a transition every second would be a timer the shopper pays for
   in battery for no information they did not already have. */
.ck-coupon {
    animation: ckm-coupon-in var(--ckm-page) var(--ckm-out) 1 both;
}

@keyframes ckm-coupon-in {
    from { opacity: 0; transform: translate3d(0, 8px, 0); }
    to   { opacity: 1; transform: none; }
}

.ck-coupon-code.is-copied {
    animation: ckm-copied var(--ckm-micro) var(--ckm-out) 1;
}

@keyframes ckm-copied {
    0%   { transform: none; }
    45%  { transform: scale3d(.94, .94, 1); }
    100% { transform: none; }
}

/* — hero headline entrance (motion brief §1) ————————————————————————————
   Every panel's copy rises once when the panel becomes the active one: x-show flips the panel's
   display, and a display flip restarts a one-shot animation, so the same three rules cover the
   first paint and every swipe, with no second system to keep in step with the carousel. The
   travel is ten pixels and the clock is short, so a return visit with no advertisement still
   reads as one page arriving rather than a slide show warming up. Fill is backwards, not both:
   once an entrance has run it lets go, so the CTA's own :active press keeps working. */
.ck-hero-title,
.ck-hero-sub,
.ck-hero-cta {
    animation: ckm-hero-rise var(--ckm-page) var(--ckm-out) 1 backwards;
}

.ck-hero-sub {
    animation-delay: 60ms;
}

.ck-hero-cta {
    animation-delay: 120ms;
}

@keyframes ckm-hero-rise {
    from { opacity: 0; transform: translate3d(0, 10px, 0); }
    to   { opacity: 1; transform: none; }
}

/* — the drift behind the hero gradient (motion brief §2) —————————————————
   The panels' gradients already paint; what moves is one oversized sheen above them, translating
   and turning on the compositor, and only while the hero is on screen — the same visible-only
   rule the free-shipping truck drives under, with its own observer hook, [data-ckm-ambient], and
   the admin's own switch. Subtle level takes it away entirely, as it does the truck. */
.ck-hero-copy {
    position: relative;
    overflow: hidden;
}

.ck-hero-copy::before {
    content: "";
    position: absolute;
    inset: -45%;
    background: radial-gradient(closest-side, rgba(255, 255, 255, .2), rgba(255, 255, 255, 0) 68%);
    pointer-events: none;
    will-change: transform;
    opacity: 0;
}

[data-ckm-ambient].is-driving .ck-hero-copy::before {
    opacity: 1;
    animation: ckm-drift 13s ease-in-out infinite alternate;
}

@keyframes ckm-drift {
    from { transform: translate3d(-6%, -4%, 0) rotate(0deg); }
    to   { transform: translate3d(7%, 5%, 0) rotate(10deg); }
}

/* The shutoffs carry the same [data-ckm-ambient].is-driving chain the driving rule does, or the
   observer's class would out-rank them at subtle and the loop would keep running — the truck's
   switch above already learned this; the sheen's now matches it. */
html[data-ckm="subtle"] [data-ckm-ambient].is-driving .ck-hero-copy::before,
html[data-ckm-off~="ambient"] [data-ckm-ambient].is-driving .ck-hero-copy::before {
    animation: none;
    opacity: 0;
}

/* — product card hover and press (motion brief §4) ———————————————————————
   A pointer device gets a lift and a longer shadow; every device gets the press, which arrives
   and leaves inside one micro beat. Both are transform and shadow only, so no card changes size
   and a shelf cannot reflow while it is being read. Hover hides nothing and reveals nothing: the
   quick-add door's own rules in ck-card-quick-v1.css decide that. The transition names the same
   three properties the reveal already moves, at the same token, so an armed row and a hovered
   card never fight over who owns the transform. */
@media (hover: hover) and (min-width: 768px) {
    .ck-storefront .ck-card {
        transition: opacity var(--ckm-card) var(--ckm-out),
            transform var(--ckm-card) var(--ckm-out),
            box-shadow var(--ckm-card) var(--ckm-out);
    }

    .ck-storefront .ck-card:hover {
        transform: translate3d(0, -2px, 0);
        box-shadow: 0 10px 24px rgba(15, 23, 42, .10);
    }
}

.ck-storefront .ck-card:active {
    transform: scale(.985);
}

/* — section links answer the finger too (motion brief §8) —————————————————
   The CTA on a hero panel and the quick-add disc already press. This adds the one kind of button
   the storefront prints on every rail: the section's own "more" link. */
.ck-storefront .ck-head-more:active {
    transform: scale(.96);
}

/* — the page the advertisement hands back (motion brief §9) ————————————————
   While the overlay holds the door, the first screen's sections sit at opacity 0 behind it, so
   the exit reveals a page rising rather than a page that was already there. When
   ck-advert-v1.js takes the overlay down it swaps the lock for data-ck-adv-left, and the named
   sections run one staggered entrance — backwards fill again, so the handoff never owns the
   elements after it is done. A shopper who never sees the advertisement never sees either
   attribute, and the page is exactly what it always was. */
html[data-ck-adv-open] [data-ckm-enter] {
    opacity: 0;
}

html[data-ck-adv-left] [data-ckm-enter] {
    animation: ckm-enter var(--ckm-card) var(--ckm-out) 1 backwards;
    animation-delay: var(--ckm-d, 0ms);
}

@keyframes ckm-enter {
    from { opacity: 0; transform: translate3d(0, 12px, 0); }
    to   { opacity: 1; transform: none; }
}

/* — the product grid's skeletons ————————————————————————————————————————
   While a card's picture has not painted yet, its media box sweeps the same shimmer the
   quick-add sheet's placeholders use, and the picture fades in over it when it arrives. The
   wait and done states are classes ck-motion-v6.js puts on and takes off — CSS never hides a
   picture on its own, so a shopper without JavaScript never meets a blank square. The sweep is
   a loop, so the subtle level drops it and leaves the tinted box; the fade is a plain opacity
   change, so it stays. */
.ck-card-media.ckm-img-wait::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.72) 55%,
        rgba(255, 255, 255, 0) 100%
    );
    transform: translateX(-100%);
    animation: ckm-imgin 1.05s ease-in-out infinite;
}

@keyframes ckm-imgin {
    to {
        transform: translateX(100%);
    }
}

.ck-card-media.ckm-img-wait .ck-card-img {
    opacity: 0;
}

.ck-card-media.ckm-img-done .ck-card-img {
    opacity: 1;
    transition: opacity var(--ckm-micro) var(--ckm-out);
}

html[data-theme="dark"] .ck-card-media.ckm-img-wait {
    background: #26262b;
}

html[data-ckm="subtle"] .ck-card-media.ckm-img-wait::before {
    animation: none;
}

/* — the shopper's own setting wins —————————————————————————————————————
   Everything above is transform or opacity, so switching to none of it is one rule. State still
   arrives, it simply arrives without travel. The strike itself stays, because a struck compare-at
   price is information; only the drawing of it is dropped. So does the coupon card, because what a
   shopper saves and until when is information too. */
@media (prefers-reduced-motion: reduce) {
    .ckm-late {
        opacity: 1;
        transform: none;
    }

    .ckm-now.is-changed,
    .ckm-was.is-struck::after,
    [data-ckm-ship].is-driving .ckm-drive,
    .ckm-fly,
    .ckm-drop-in,
    .ck-coupon,
    .ck-coupon-code.is-copied,
    .ck-hero-title,
    .ck-hero-sub,
    .ck-hero-cta,
    [data-ckm-ambient].is-driving .ck-hero-copy::before,
    .ck-card-media.ckm-img-wait::before,
    html[data-ck-adv-left] [data-ckm-enter] {
        animation: none !important;
        transition: none !important;
    }

    html[data-ck-adv-open] [data-ckm-enter] {
        opacity: 1;
    }

    .ckm-was.is-struck {
        text-decoration: line-through;
    }

    .ckm-was.is-struck::after {
        opacity: 0;
    }
}
