/* v7 motion (spec §4). Motion EXPLAINS -- sequence, progress, state change, success -- and never
   decorates. Rules:
   - every animated start state is scoped under html.motion (set by motion-init.js only when the
     visitor has not asked for reduced motion), so without JS or with reduced motion every element
     simply sits in its final frame;
   - UI entrances run ONCE (iteration count 1, fill-mode both). The four journey explainers
     (B4: landing «چطور کار می‌کند», the comment->DM demo, the bank coin, the buyer guide) LOOP
     forever: a marked START («شروع»), steps advancing over a track that fills in the reading
     direction, an END held ~1.5s (final step + check), then a short visible reset -- 6-9s a
     cycle, every step's own text readable throughout. ui.js pauses a loop that leaves the
     viewport or whose tab is hidden (class toggles only); apart from those and the loading
     spinner, nothing else iterates infinitely;
   - only opacity, transform and background-color animate (plus stroke-dashoffset for checks).
   Explainers start when ui.js adds .play (on load, or when scrolled into view: .pending until then). */

@keyframes rise-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
@keyframes step-in{from{opacity:0;transform:translateX(-12px)}to{opacity:1;transform:none}}
@keyframes fill-bar{from{transform:scaleX(var(--from))}to{transform:scaleX(var(--to))}}
@keyframes check-pop{0%{transform:scale(.6);opacity:0}70%{transform:scale(1.08);opacity:1}100%{transform:scale(1);opacity:1}}
@keyframes check-draw{from{stroke-dashoffset:24}to{stroke-dashoffset:0}}
/* IGB board: a pair just made -- its line draws in from the post's side (RTL: the right), once. */
html.motion .pair.is-new .pair__line{transform-origin:right;animation:fill-bar .24s var(--ease-out,ease-out) 1 both;--from:0;--to:1}
html.motion .tray{animation:rise-in .15s ease-out 1 both}
@keyframes celebrate-burst{from{transform:rotate(var(--a)) translateY(0);opacity:1}to{transform:rotate(var(--a)) translateY(-32px);opacity:0}}
@keyframes seq-light{0%{background-color:var(--surface)}40%{background-color:var(--primary-tint);transform:scale(1.04)}100%{background-color:var(--primary-tint);transform:none}}
@keyframes bar-grow{from{transform:scaleX(0)}to{transform:scaleX(1)}}
@keyframes loop-tap{0%,3%{transform:scale(0);opacity:.35}14%,100%{transform:scale(1.6);opacity:0}}

/* --- the B4 loops (6-9s, infinite): every keyframe's percentages are cycle-relative; an element
   that joins the cycle late carries a NEGATIVE animation-delay, which phase-shifts an infinite
   animation without desynchronising it. Timings per component:
   landing #how (9s):  steps light at 0/19/38/57% of the cycle, the connector fills to 57%, the
                       final step rests to 95% (check from ~77%), the line rewinds 95-100%;
   demo (7s):          post lights at 0, bubbles at 3/24%, the buy tap at 36%, the checkout bar
                       at 50%, its check at 72%, the whole conversation fades 88-94%;
   bank coin (6.5s):   shop lights 0-14%, the coin travels 14-50% as the path fills, the bank and
                       its check hold to 88%, the path empties and the coin is back at 94-100%;
   buy-guide (6.5s):   tiles light at 0/20/40%, the last rests to 88%, «سفارش ثبت شد» from 58%
                       (dimmed, never gone, the rest of the cycle -- buyer UI audit #6), the
                       track rewinds 88-94%. ------------------------------------------------- */
@keyframes loop-step{0%{background-color:var(--primary-tint);transform:scale(1.06)}6%{transform:none}19%{background-color:var(--primary-tint)}24%,100%{background-color:var(--surface)}}
@keyframes loop-step-end{0%{background-color:var(--primary-tint);transform:scale(1.06)}6%{transform:none}38%{background-color:var(--primary-tint)}43%,100%{background-color:var(--surface)}}
@keyframes loop-line{0%{transform:scaleY(0)}57%{transform:scaleY(1)}95%{transform:scaleY(1)}100%{transform:scaleY(0)}}
@keyframes loop-check{0%,10%{transform:scale(.6);opacity:0}16%{transform:scale(1.08);opacity:1}20%,38%{transform:scale(1);opacity:1}44%,100%{transform:scale(.6);opacity:0}}
@keyframes loop-post{0%{background-color:var(--primary-tint)}14%{background-color:var(--primary-tint)}20%,100%{background-color:var(--surface-well)}}
@keyframes loop-in{0%,3%{opacity:0;transform:translateY(6px) scale(.96)}10%{opacity:1;transform:none}100%{opacity:1;transform:none}}
@keyframes loop-fade{0%,88%{opacity:1}94%,100%{opacity:0}}
@keyframes loop-track{0%{transform:scaleX(0)}72%{transform:scaleX(1)}88%{transform:scaleX(1)}94%,100%{transform:scaleX(0)}}
@keyframes loop-pop{0%{transform:scale(.6);opacity:0}6%{transform:scale(1.08);opacity:1}10%,100%{transform:scale(1);opacity:1}}
@keyframes loop-pop-out{0%{transform:scale(.6);opacity:0}6%{transform:scale(1.08);opacity:1}10%,30%{transform:scale(1);opacity:1}38%,100%{transform:scale(.6);opacity:0}}
@keyframes loop-end{0%{transform:none;opacity:.35}6%{transform:scale(1.06);opacity:1}10%,30%{transform:none;opacity:1}38%,100%{transform:none;opacity:.35}}
@keyframes loop-node-a{0%{background-color:var(--primary-tint)}14%{background-color:var(--primary-tint)}20%,100%{background-color:var(--surface)}}
@keyframes loop-node-b{0%,50%{background-color:var(--surface)}56%,88%{background-color:var(--primary-tint)}94%,100%{background-color:var(--surface)}}
@keyframes loop-coin{0%,14%{transform:translateX(100%);opacity:1}50%{transform:none;opacity:1}86%{transform:none;opacity:1}92%{transform:none;opacity:0}100%{transform:translateX(100%);opacity:0}}   /* shop (inline-start, right) -> bank (inline-end, left) in RTL: V7-24 */
@keyframes loop-fill{0%,14%{transform:scaleX(0)}50%{transform:scaleX(1)}88%{transform:scaleX(1)}94%,100%{transform:scaleX(0)}}
@keyframes loop-tile{0%{background-color:var(--primary-tint)}20%{background-color:var(--primary-tint)}25%,100%{background-color:var(--surface-well)}}
@keyframes loop-tile-end{0%{background-color:var(--primary-tint)}48%{background-color:var(--primary-tint)}54%,100%{background-color:var(--surface-well)}}
@keyframes nudge{0%,100%{transform:none}25%,75%{transform:translateY(-4px)}}
@keyframes slot-in{from{opacity:0;transform:translateY(-16px)}to{opacity:1;transform:none}}
@keyframes field-shake{25%{transform:translateX(-4px)}50%{transform:translateX(4px)}75%{transform:translateX(-2px)}}
@keyframes lock-close{from{transform:translateY(-4px)}to{transform:none}}
@keyframes collapse{to{opacity:0;transform:scaleY(.9)}}
@keyframes ring-fill{from{stroke-dashoffset:113.1}}
@keyframes spin{to{transform:rotate(360deg)}}

/* the loading spinner: infinite (a submit is in flight), and the only loop that lives outside
   html.motion -- it must spin from the moment ui.js marks the button busy */
.is-loading::before{animation:spin 800ms linear infinite}

/* --- render-time entrances (UI, 150-400ms) ------------------------------------------------------ */
html.motion .rise{animation:rise-in var(--dur-2) var(--ease-out) 1 both}
html.motion .rise--d1{animation-delay:80ms}
html.motion .rise--d2{animation-delay:160ms}
html.motion .rise--d3{animation-delay:240ms}
html.motion .wizard__card{animation:step-in var(--dur-2) var(--ease-out) 1 both}
html.motion .saved-strip,html.motion .banner--success{animation:rise-in var(--dur-2) var(--ease-out) 1 both}
html.motion .field--error:not(.field--error ~ .field--error){animation:field-shake 300ms var(--ease-out) 1}
html.motion .is-copied{animation:check-pop var(--dur-3) var(--ease-pop) 1}

/* wizard progress: from the previous step's share to this one's */
.wizard__fill--s1of2{--from:0;--to:.5}.wizard__fill--s2of2{--from:.5;--to:1}
.wizard__fill--s1of3{--from:0;--to:.3334}.wizard__fill--s2of3{--from:.3334;--to:.6667}.wizard__fill--s3of3{--from:.6667;--to:1}
.wizard__fill--s1of4{--from:0;--to:.25}.wizard__fill--s2of4{--from:.25;--to:.5}
.wizard__fill--s3of4{--from:.5;--to:.75}.wizard__fill--s4of4{--from:.75;--to:1}
html.motion .wizard__fill{animation:fill-bar var(--dur-4) var(--ease-in-out) 120ms 1 both}

/* checklist ring: the arc fills to the value its dashoffset attribute states */
html.motion .ring__val{animation:ring-fill var(--dur-4) var(--ease-in-out) 120ms 1 both}
html.motion .onb-item.just .onb-item__mark{animation:check-pop var(--dur-3) var(--ease-pop) 1 both}

/* products grid: cards rise in with a 40ms stagger (first 8) */
html.motion .product-grid>li{animation:rise-in var(--dur-2) var(--ease-out) 1 both}
html.motion .product-grid>li:nth-child(2){animation-delay:40ms}
html.motion .product-grid>li:nth-child(3){animation-delay:80ms}
html.motion .product-grid>li:nth-child(4){animation-delay:120ms}
html.motion .product-grid>li:nth-child(5){animation-delay:160ms}
html.motion .product-grid>li:nth-child(6){animation-delay:200ms}
html.motion .product-grid>li:nth-child(7){animation-delay:240ms}
html.motion .product-grid>li:nth-child(8){animation-delay:280ms}

/* the FAB nudges once while the merchant has no products */
html.motion .fab[data-nudge]{animation:nudge 600ms var(--ease-in-out) 1200ms 1}

/* --- sequence explainers: the UI ornaments play once (<= 3s); the four journey explainers LOOP
   (B4). The loop rules all live under html.motion + .play, so reduced motion, no JS and print
   all rest on the complete frame: every step visible, its track full, its check shown. -------- */

/* landing «چطور کار می‌کند» (9s loop; three steps since S8a, re-timed over the same cycle):
   «شروع» is static; the steps light in turn while the connector fills, the last step rests with
   its check, then the connector rewinds and the cycle restarts. The steps' text never moves. */
html.motion .how.pending .how__line{transform:scaleY(0)}
html.motion .how.pending .loop-check{opacity:0}
html.motion .how.play .how__line{animation:loop-line 9s linear infinite}
html.motion .how.play .how__dot{animation:loop-step 9s var(--ease-out) infinite}
html.motion .how.play .how__step:nth-of-type(2) .how__dot{animation:loop-step 9s var(--ease-out) -6.435s infinite}
html.motion .how.play .how__step:nth-of-type(3) .how__dot{animation:loop-step-end 9s var(--ease-out) -3.87s infinite}
html.motion .how.play .loop-check{animation:loop-check 9s var(--ease-pop) -3.87s infinite}

/* the products empty row: lit once, in sequence (still a one-shot -- it sits beside an action) */
html.motion .play .seq{animation:seq-light 360ms var(--ease-out) 1 both}
html.motion .play .seq--2{animation-delay:450ms}
html.motion .play .seq--3{animation-delay:900ms}
html.motion .buy-guide.is-collapsing{animation:collapse 200ms var(--ease-out) 1 both}

/* the buyer step bar: the current segment lights once on arrival */
html.motion .buyer-steps.play .is-current{animation:rise-in var(--dur-2) var(--ease-out) 1 both}

/* shop «ویترین»: awning drops, the name bar grows, the description lines fade in (~1.24s) */
html.motion .illo--shop.play .illo__awning{animation:rise-in var(--dur-2) var(--ease-out) 1 both}
html.motion .illo--shop.play .illo__bar--name{animation:bar-grow 600ms var(--ease-out) 240ms 1 both}
html.motion .illo--shop.play .illo__bar--line,html.motion .illo--shop.play .illo__bar--short{animation:rise-in var(--dur-2) var(--ease-out) 840ms 1 both}

/* bank «مسیر درآمد» (6.5s loop): the shop lights under its «شروع», the coin travels right-to-left
   (V7-24) while the path fills under it, the bank takes its check and rests, then the path
   empties and the coin stands at the shop again. */
html.motion .illo--bank.pending .illo__mover{transform:translateX(100%)}
html.motion .illo--bank.pending .illo__fill{transform:scaleX(0)}
html.motion .illo--bank.pending .illo__check{opacity:0}
html.motion .illo--bank.play .illo__node--shop{animation:loop-node-a 6.5s var(--ease-out) infinite}
html.motion .illo--bank.play .illo__fill{animation:loop-fill 6.5s linear infinite}
html.motion .illo--bank.play .illo__mover{animation:loop-coin 6.5s var(--ease-in-out) infinite}
html.motion .illo--bank.play .illo__node--bank{animation:loop-node-b 6.5s var(--ease-out) infinite}
html.motion .illo--bank.play .illo__check{animation:loop-pop-out 6.5s var(--ease-pop) -2.73s infinite}

/* buyer sign-in: the padlock closes, then the check pops */
html.motion .illo--lock.play .lock__shackle{animation:lock-close 300ms var(--ease-out) 1 both}
html.motion .illo--lock.play .illo__check{animation:check-pop var(--dur-3) var(--ease-pop) 300ms 1 both}

/* celebration: circle pops, the check draws, eight dots burst once */
html.motion .celebrate.play .celebrate__circle{animation:check-pop var(--dur-3) var(--ease-pop) 1 both}
html.motion .celebrate.play .celebrate__check{animation:check-draw 280ms var(--ease-out) 120ms 1 both}
.celebrate__burst i:nth-child(1){--a:0deg}.celebrate__burst i:nth-child(2){--a:45deg}
.celebrate__burst i:nth-child(3){--a:90deg}.celebrate__burst i:nth-child(4){--a:135deg}
.celebrate__burst i:nth-child(5){--a:180deg}.celebrate__burst i:nth-child(6){--a:225deg}
.celebrate__burst i:nth-child(7){--a:270deg}.celebrate__burst i:nth-child(8){--a:315deg}
html.motion .celebrate.play .celebrate__burst i{animation:celebrate-burst 700ms var(--ease-out) 200ms 1 both}
html.motion .celebrate.play ~ .done-title{animation:rise-in var(--dur-2) var(--ease-out) 320ms 1 both}

/* comment -> DM mini-demo (7s loop): the post lights under its «شروع», the conversation builds
   one message at a time over the track, the checkout bar takes its check and rests, then the
   whole conversation fades back to the lone post -- the visible reset. */
html.motion .demo.pending .demo__anim{opacity:0}
html.motion .demo.pending .demo__track{transform:scaleX(0)}
html.motion .demo.play .demo__post{animation:loop-post 7s var(--ease-out) infinite}
html.motion .demo.play .demo__anim{animation:loop-in 7s var(--ease-out) infinite}
html.motion .demo.play .demo__anim--t1{animation:loop-in 7s var(--ease-out) -6.79s infinite}
html.motion .demo.play .demo__anim--t2{animation:loop-in 7s var(--ease-out) -5.32s infinite}
html.motion .demo.play .demo__anim--t3{animation:loop-in 7s var(--ease-out) -3.5s infinite}
html.motion .demo.play .demo__tap{animation:loop-tap 7s var(--ease-out) -4.48s infinite}
html.motion .demo.play .demo__conv{animation:loop-fade 7s linear infinite}
html.motion .demo.play .demo__track{animation:loop-track 7s linear infinite}
html.motion .demo.play .loop-check{animation:loop-pop 7s var(--ease-pop) -1.96s infinite}

/* the buyer's first-open guide (6.5s loop): «شروع» pins the first tile, the tiles light in turn
   over the track, «سفارش ثبت شد» caps the journey, the track rewinds and it starts over. The
   three labels never move or disappear -- and (audit #6) neither does the end row: between its
   turns it rests dimmed, so the card never shows an empty band. */
html.motion .buy-guide.pending .buy-guide__track{transform:scaleX(0)}
html.motion .buy-guide.pending .buy-guide__end{opacity:.35}
html.motion .buy-guide.play .buy-guide__tile{animation:loop-tile 6.5s var(--ease-out) infinite}
html.motion .buy-guide.play .buy-guide__tile--t2{animation:loop-tile 6.5s var(--ease-out) -5.2s infinite}
html.motion .buy-guide.play .buy-guide__tile--t3{animation:loop-tile-end 6.5s var(--ease-out) -3.9s infinite}
html.motion .buy-guide.play .buy-guide__end{animation:loop-end 6.5s var(--ease-pop) -2.73s infinite}
html.motion .buy-guide.play .buy-guide__track{animation:loop-track 6.5s linear infinite}

/* teaching empty states: a ghost order slots in */
html.motion .ghost-card{animation:slot-in var(--dur-4) var(--ease-out) 600ms 1 both}

/* details sheets open softly */
html.motion details[open]>.sheet{animation:rise-in var(--dur-2) var(--ease-out) 1 both}

/* v7 bottom sheets (plan_01 §1.6): the panel slides up over its scrim, once, and rests open;
   the reduced-motion guard below rests it on its final frame */
@keyframes sheet-up{from{transform:translateY(100%)}to{transform:none}}
html.motion .bsheet:target .bsheet__panel{animation:sheet-up var(--dur-2) var(--ease-out) 1 both}

/* DS1 (redesign S1): the agent chip's pulse -- an infinite animation beside the four explainers
   and the spinner, allowed because it states something true: the template renders the dot only
   while the page is connected, not paused and past its warm-up, so the automation is genuinely
   running. Two seconds a beat, ONE element per screen, and it rests on a fully visible dot
   whenever motion is off or reduced (the reduced-motion guard's single 1ms iteration ends on
   the 100% frame). */
@keyframes agent-pulse{0%,100%{opacity:1;transform:none}50%{opacity:.45;transform:scale(.8)}}
html.motion .agent-chip .agent-chip__dot{animation:agent-pulse 2s var(--ease-in-out) infinite}

/* S3 (redesign): the buyer's pending page pulses the timeline's current step -- the gateway
   match -- by the same truth rule: `.is-live` renders only while reconciliation_service is
   genuinely re-reading the payment, and no dot ever pulses for the seller's own work. One
   element per screen, two seconds a beat, resting on the visible dot without motion. */
html.motion .status-track li.is-live .status-track__dot{animation:agent-pulse 2s var(--ease-in-out) infinite}

/* --- guards ---------------------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{animation-duration:1ms!important;animation-delay:0ms!important;
    animation-iteration-count:1!important;transition-duration:1ms!important;scroll-behavior:auto!important}
  /* B4: forcing a loop to one 1ms iteration would freeze it mid-cycle (the conversation faded
     out, the track empty); with reduced motion every explainer sits on its complete frame. */
  [data-loop],[data-loop] *{animation:none!important}
  .celebrate__burst{display:none!important}
  .spin,.is-loading::before{animation:none!important}   /* the «…» in the busy label says it instead */
}
@media print{*{animation:none!important;transition:none!important}}
