/* 2026-11 round 2, phase B: the rest of the motion. Loaded right after motion.css and uses its tokens
   (--t-quick / --t-settle / --t-turn, --ease-paper / --ease-spring).
   B1 pressing anything clickable pushes the paper down a little; B2 the paper dialogs land on the desk and
   lift off again (logic in core.js, FEIQI.dialog); B3 the toys: drawing again, puzzle pieces travelling,
   a small celebration, paw prints and the beat; switching toys and tools; B4 the viewer turns pages;
   B5 her bubble is written out once and she sways a little.
   Every animation here sits inside prefers-reduced-motion:no-preference and is also off under
   html.feiqi-still. Nothing starts hidden unless an animation is running, so if this file is missing or
   motion is paused the page is simply still. To undo: remove this <link> (the scripts only add classes). */

/* ---------- B1 · press: a slight sink, the shadow pulled in ---------- */
@media(prefers-reduced-motion:no-preference){
 /* Zero specificity: any element that already has its own transition keeps it (those are listed below). */
 :where(html:not(.feiqi-still)) :where(button,a[href],[role=button],summary,.wb-file){transition:translate var(--t-quick) var(--ease-paper),box-shadow var(--t-quick) var(--ease-paper)}
 :where(html:not(.feiqi-still)) :where(button,a[href],[role=button],summary,.wb-file):where(:active:not(:disabled,[aria-disabled=true],.dock-handle)){translate:0 1px}
 /* Controls that already animate something: same transitions, plus the press. */
 .gallery-nav a{transition:background .18s,color .18s,box-shadow .18s,translate var(--t-quick) var(--ease-paper)}
 .gallery-filters button{transition:background .18s,color .18s,translate var(--t-quick) var(--ease-paper)}
 .sketch-dialog-header button{transition:background .18s,translate var(--t-quick) var(--ease-paper)}
 .album-thumbnails button{transition:border-color .15s,translate var(--t-quick) var(--ease-paper)}
 .button{transition:background .2s,transform .2s,translate var(--t-quick) var(--ease-paper)}
 .world-hotspot{transition:background .2s,transform .2s,translate var(--t-quick) var(--ease-paper)}
 .hero-open{transition:background-color .3s ease,transform .3s ease,color .9s ease,translate var(--t-quick) var(--ease-paper)}
 .hero-meet,.contents-open,#gallery-random{transition:color .9s ease,translate var(--t-quick) var(--ease-paper)}
 .gallery-piece:not(.is-lead) .gallery-art{transition:transform .35s cubic-bezier(.22,.7,.25,1),box-shadow .35s ease,translate var(--t-quick) var(--ease-paper)}
 /* Frames are pressed onto the page (the button inside the grid item, never the grid item itself). */
 :where(html:not(.feiqi-still)) .gallery-grid .gallery-piece .gallery-art:active{translate:0 2px;box-shadow:0 2px 8px #5f4a3514}
 :where(html:not(.feiqi-still)) body[data-chapter="黑童话"] .gallery-grid .gallery-piece .gallery-art:active{box-shadow:0 6px 16px #00000080}
 :where(html:not(.feiqi-still)) .chapter-tab:active{box-shadow:0 1px 0 #fff inset,0 1px 1px #5f4a351f,0 3px 8px -6px #5f4a3552}
 :where(html:not(.feiqi-still)) .toy-panel button.puzzle-piece:active{box-shadow:0 0 1px #604d4840}
}

/* ---------- B2 · dialogs: a sheet of paper lands on the desk, and lifts off again ---------- */
@media(prefers-reduced-motion:no-preference){
 /* backwards only: once landed, the open dialog carries no transform of its own. */
 :is(.dialog,.world-dialog,.contents-sheet)[open]{animation:sheet-land var(--t-settle) var(--ease-paper) backwards}
 :is(.dialog,.world-dialog,.contents-sheet)[open]::backdrop{animation:desk-fade-in var(--t-settle) ease backwards}
 :is(.dialog,.world-dialog,.contents-sheet).is-closing{animation:sheet-lift var(--t-settle) var(--ease-paper) forwards}
 :is(.dialog,.world-dialog,.contents-sheet).is-closing::backdrop{animation:desk-fade-out var(--t-settle) ease forwards}
}
@keyframes sheet-land{from{opacity:0;translate:0 -22px;rotate:-2.4deg;scale:.985}55%{opacity:1}75%{rotate:.35deg}to{opacity:1;translate:0 0;rotate:0deg;scale:1}}
@keyframes sheet-lift{from{opacity:1;translate:0 0;rotate:0deg;scale:1}to{opacity:0;translate:0 -16px;rotate:1.8deg;scale:.985}}
/* The backdrop only fades; its blur (style.css / world.css) is left alone. */
@keyframes desk-fade-in{from{opacity:0}}
@keyframes desk-fade-out{to{opacity:0}}
html.feiqi-still :is(.dialog,.world-dialog,.contents-sheet),html.feiqi-still :is(.dialog,.world-dialog,.contents-sheet)::backdrop{animation:none}

/* ---------- B3 · toys ---------- */
/* Switching toys or tools: the new panel settles in (.is-switching from playroom.js / workbench.js). */
@media(prefers-reduced-motion:no-preference){
 .toy-panel.is-switching,.wb-panel.is-switching{animation:panel-settle var(--t-settle) var(--ease-paper)}
}
@keyframes panel-settle{from{opacity:0;translate:0 10px}}

/* Drawing again: the old drawing (a copy, .draw-leaf) is pulled off, the new one turns face up. */
.toy-panel .toy-art-open{position:relative}
.toy-art-open .draw-leaf{position:absolute;left:0;top:0;z-index:1;pointer-events:none}
@media(prefers-reduced-motion:no-preference){
 .toy-art-open.is-drawing .draw-leaf{animation:draw-away var(--t-turn) var(--ease-paper) forwards}
 .toy-art-open.is-drawing #toy-draw-image{animation:draw-flip var(--t-turn) var(--ease-paper) var(--t-quick) backwards}
}
@keyframes draw-away{to{opacity:0;translate:46% -20%;rotate:15deg}}
@keyframes draw-flip{from{opacity:0;transform:perspective(900px) rotateY(-90deg)}45%{opacity:1}to{opacity:1;transform:perspective(900px) rotateY(0deg)}}

/* Puzzle solved: her line (stays until the next shuffle) and a few scraps of tape drifting down. */
.puzzle-cheer{display:flex;align-items:center;gap:10px;width:fit-content;max-width:100%;box-sizing:border-box;margin:10px 0 6px;padding:7px 14px 7px 7px;background:#fffaf2;border:1px solid #d9c9b8;border-radius:14px 14px 14px 3px;box-shadow:0 6px 18px #5f4a3512;font-size:13px;line-height:1.6;color:#5d4a44;rotate:-1.2deg}
.puzzle-cheer img{width:40px;height:40px;flex:none;border-radius:50%;background:#f6ece2}
.puzzle-scraps{position:absolute;inset:0;overflow:hidden;pointer-events:none;z-index:4}
.puzzle-scraps .scrap{position:absolute;top:-20px;left:var(--x);width:15px;height:10px;background:#f1e4d6;box-shadow:0 1px 2px #5f4a3526;opacity:0}
.puzzle-scraps .scrap.is-tape{width:34px;height:11px;background:var(--tape-pink,#e8bfc4c7)}
.puzzle-scraps .scrap:nth-child(4n+2){background:var(--tape-sand,#d6bca3b8)}
@media(prefers-reduced-motion:no-preference){
 .puzzle-cheer{animation:cheer-pop var(--t-settle) var(--ease-spring) backwards}
 .puzzle-scraps .scrap{animation:scrap-fall calc(var(--t-turn) * 2.2) var(--ease-paper) var(--d,0ms) forwards}
}
@keyframes cheer-pop{from{opacity:0;scale:.82;translate:0 6px}}
@keyframes scrap-fall{0%{opacity:0;translate:0 0;rotate:0deg}12%{opacity:1}78%{opacity:1}100%{opacity:0;translate:0 var(--fall,300px);rotate:var(--r,20deg)}}
html.feiqi-still .puzzle-cheer{animation:none}
html.feiqi-still .puzzle-scraps{display:none}

/* Music box: a paw print bounces when it is lit; while playing, each beat's column glows and fades. */
@media(prefers-reduced-motion:no-preference){
 .pawmark.is-pop{animation:paw-pop var(--t-settle) var(--ease-spring)}
 .toy-panel button.music-cell.is-swept,.music-beat-row .is-swept{animation:beat-sweep var(--t-turn) ease-out}
}
@keyframes paw-pop{0%{scale:.55}55%{scale:1.22}100%{scale:1}}
@keyframes beat-sweep{from{background-color:#f4dcae;box-shadow:0 0 0 2px #b58c53,0 0 16px 3px #e6c07c80}}

/* ---------- B4 · the viewer turns a page: the copy of the current drawing lifts away ---------- */
.sketch-dialog .viewer-stage .viewer-leaf{position:absolute;inset:0;z-index:2;filter:drop-shadow(0 16px 26px #5f4a3524)}
.sketch-dialog.is-loading .viewer-stage img.viewer-leaf{opacity:1}
body[data-chapter="黑童话"] .sketch-dialog .viewer-stage .viewer-leaf{filter:drop-shadow(0 18px 30px #000000a6)}

/* ---------- B5 · first look: the bubble is written out, she sways a little ---------- */
@media(prefers-reduced-motion:no-preference){
 .hero-bubble.is-writing .bubble-ch{animation:ink-in var(--t-quick) ease calc(var(--t-settle) + var(--i,0) * 70ms) backwards}
 /* The whole peek sways as one piece: her drawing, the "翻开画册" page over it, the bubble and the button.
    Only translate/rotate (individual properties), so .hero-open:hover's own transform is untouched. */
 .hero-peek{transform-origin:50% 100%;animation:peek-sway 7s ease-in-out infinite}
}
@keyframes ink-in{from{opacity:0}}
@keyframes peek-sway{0%,100%{translate:0 0;rotate:0deg}50%{translate:0 -2px;rotate:-.4deg}}
html.feiqi-still .hero-peek,html.feiqi-still .bubble-ch{animation:none}

@media(forced-colors:active),(prefers-contrast:more){
 .puzzle-cheer{background:Canvas;color:CanvasText;border-color:CanvasText;box-shadow:none}
 .puzzle-scraps,.viewer-leaf{display:none}
}
@media print{.puzzle-scraps,.draw-leaf,.viewer-leaf{display:none}}
