/* B2 穩陣 — motion.
   Follows the shared NEWSET motion spec (D:\Projects\Motion-Spec\MOTION.md), calm variant for stressed users:
   ease-out, no overshoot, exits faster than entrances, one focus at a time, no idle loops.
   Material: water and light. Two authored moments: the water rising on 今日, and a result arriving.
   Everything else is continuity (which way you moved) or acknowledgement (what you just tapped). */

:root{--shift:1;--ease-exit:cubic-bezier(.4,0,1,1)}

/* Shared keyframes. Travel is multiplied by --shift, which is 0 under reduced motion, so the same moments become fades. */
@keyframes fade-in{from{opacity:0}}
@keyframes fade-out{to{opacity:0}}
@keyframes page-in{from{opacity:0;transform:translate3d(calc(var(--dx,0px)*var(--shift)),calc(var(--dy,0px)*var(--shift)),0)}}
@keyframes bar-in{from{opacity:0;transform:translateY(calc(100%*var(--shift)))}}
@keyframes rise-in{from{opacity:0;transform:translateY(calc(10px*var(--shift)))}}
@keyframes pop-in{from{opacity:0;transform:translateY(calc(6px*var(--shift)))}}
@keyframes pop{from{transform:scale(calc(1 - .12*var(--shift)))}}
@keyframes draw{from{stroke-dashoffset:1}}
@keyframes wipe{from{clip-path:inset(0 100% 0 0 round 8px)}}
@keyframes fill{from{transform:translateY(100%)}}
@keyframes roll{from{transform:translateY(calc(var(--f,0)*-1em))}}

/* 1. Between screens. Deeper slides in from the right, back comes from the left, tabs and in-task steps rise a little.
      Only the page's own blocks move: the fixed bars are not inside anything that moves. */
.enter>*{animation:page-in 340ms var(--ease-out) backwards}
.enter[data-dir="fwd"]>*{--dx:28px}
.enter[data-dir="back"]>*{--dx:-28px}
.enter[data-dir="tab"]>*{--dy:10px;animation-duration:280ms}
.enter[data-dir="step"]>*{--dy:16px;animation-duration:320ms}
.enter>.topbar{animation:fade-in 200ms var(--ease-out) backwards}
.enter>.actionbar{animation:bar-in 380ms var(--ease-out) 60ms backwards}
.moves:not([hidden]){animation:bar-in 380ms var(--ease-out) backwards}

/* 2. 今日. The water rises to today's readiness and the figure rolls with it; the part of the figure under the water turns dark.
      The four skills fill one by one after the sphere has settled. First visit of a session, or when readiness has changed. */
@keyframes water{from{transform:translateY(calc(100% - var(--from,0)*1%))}}
@keyframes waterline{from{clip-path:inset(calc(100% - var(--from,0)*1%) 0 0 0)}}
.rise .sphere .water{animation:water 1200ms var(--ease-out) 150ms backwards}
.rise .sphere .read.under{animation:waterline 1200ms var(--ease-out) 150ms backwards}
.rise .sphere .roll .s{animation:roll 800ms var(--ease-out) backwards;animation-delay:calc(150ms + var(--k)*100ms)}
.rise-all .skills .bead::before{animation:fill 800ms var(--ease-out) backwards;animation-delay:calc(1300ms + var(--i,0)*110ms)}

/* 3. A result arrives, one thing at a time: the score rolls in, your bar sweeps towards the reference line,
      the verdict appears (a passing one draws its tick: circle, then tick), then this task's sphere fills. */
.result .score .roll .s{animation:roll 800ms var(--ease-out) backwards;animation-delay:calc(250ms + var(--k)*100ms)}
.result .meter>i{animation:wipe 800ms var(--ease-out) 750ms backwards}
.result .badge{animation:pop-in 300ms var(--ease-out) 1450ms backwards}
.result .tick circle{animation:draw 300ms var(--ease-out) 1550ms backwards}
.result .tick path{animation:draw 170ms var(--ease-out) 1850ms backwards}
.result .bead::before{animation:fill 800ms var(--ease-out) 2000ms backwards}

/* 4. 進度, first visit of a session: the four skill bars sweep in top to bottom, then the readiness line draws itself. */
.chart-in .skillmeter .meter>i{animation:wipe 800ms var(--ease-out) backwards;animation-delay:calc(200ms + var(--i,0)*100ms)}
.chart-in #trend .line{animation:draw 1100ms var(--ease-out) 300ms backwards}
.chart-in #trend .end{animation:fade-in 300ms var(--ease-out) 1300ms backwards}

/* 5. Sheets slide up from the bottom and leave faster than they came; toasts rise in and fade out. */
@keyframes sheet-in{from{transform:translateY(calc(100%*var(--shift)));opacity:var(--shift)}}
@keyframes sheet-out{to{transform:translateY(calc(100%*var(--shift)));opacity:var(--shift)}}
dialog.sheet[open]{animation:sheet-in 350ms var(--ease-out)}
dialog.sheet[open]::backdrop{animation:fade-in 350ms var(--ease-out)}
dialog.sheet.out{animation:sheet-out 240ms var(--ease-exit) forwards}
dialog.sheet.out::backdrop{animation:fade-out 240ms var(--ease-exit) forwards}
@keyframes toast-in{from{opacity:0;transform:translate(-50%,calc(12px*var(--shift)))}}
.toast{animation:toast-in 280ms var(--ease-out)}
.toast.out{animation:fade-out 180ms var(--ease-exit) forwards}

/* 6. Speaking. Rings leave the examiner only while the examiner speaks (the one loop, and it stops on its own).
      Each new line in the conversation rises in; the move palette slides up when it is your turn. */
@keyframes ripple{0%{transform:scale(1);opacity:.75}100%{transform:scale(1.75);opacity:0}}
.orb.speaking .ring{animation:ripple 2.4s var(--ease-out) infinite}
.orb.speaking .ring:nth-child(2){animation-delay:.8s}.orb.speaking .ring:nth-child(3){animation-delay:1.6s}
#log .bubble{animation:rise-in 300ms var(--ease-out) backwards}
#hintbox:not([hidden]){animation:rise-in 260ms var(--ease-out)}

/* 7. Acknowledgements: what you picked settles into place. */
.opt[aria-pressed=true] .k,.rater button[aria-pressed=true],.check[aria-pressed=true] .box,.chip.done svg,.tabs a.pop svg{animation:pop 240ms var(--ease-out)}
.timer{transition:color 600ms var(--ease-out),border-color 600ms var(--ease-out)}

/* 8. Folds open fast then slow (spec pattern 05): driven from app.js; the body clips while it moves. */
.fold[data-anim]>.body{overflow:hidden}

/* Reduce Motion (app.js sets html.calm from the phone's setting): the same moments as fades, final numbers at once, no ripple. */
html.calm{--shift:0}
html.calm .rise .sphere .water,html.calm .rise .sphere .read.under,html.calm .rise .sphere .roll .s,html.calm .rise-all .skills .bead::before,
html.calm .result .score .roll .s,html.calm .result .meter>i,html.calm .result .tick circle,html.calm .result .tick path,html.calm .result .bead::before,
html.calm .chart-in .skillmeter .meter>i,html.calm .chart-in #trend .line,html.calm .chart-in #trend .end{animation:none}
html.calm .orb.speaking .ring{animation:none;opacity:.5}
html.calm .orb.speaking .ring+.ring{opacity:0}
html.calm .btn:active,html.calm .mic:active,html.calm button.chip:active{transform:none}

/* ?static=1 freezes motion so a screen can be captured in its final state (overview boards). */
html.static *,html.static *::before,html.static *::after{animation:none!important;transition:none!important}

/* 9. The AI examiner: three dots breathe while it thinks (stops the moment it answers); its comments rise in when they arrive. */
@keyframes wait{0%,100%{opacity:.25}50%{opacity:.9}}
.dots-wait i{animation:wait 1.2s ease-in-out infinite}
.dots-wait i:nth-child(2){animation-delay:.2s}.dots-wait i:nth-child(3){animation-delay:.4s}
#aifb>:not(h2){animation:rise-in 320ms var(--ease-out) backwards}
html.calm .dots-wait i{animation:none;opacity:.6}
