/* ==========================================================================
   motion.css - "Motion and flair" layer (loaded after features.css). See DESIGN.md > Motion and flair.
   Rules: animate transform / translate / rotate / scale / opacity / filter only; every motion says something (arrival, press, grade, route);
   ambient loops are slow and pause off-screen; prefers-reduced-motion OR Settings > Reduce motion (html.reduce-motion) switches ALL of it
   off (see the last block) and every state stays visible. Decorative gradients (halftone dots, hard stripes) are non-text only.
   ========================================================================== */
:root { --spring:cubic-bezier(.34,1.56,.64,1); --snap:cubic-bezier(.2,.8,.3,1); }

/* ---------- 1. one orchestrated entrance per page: stickers/cards pop in a staggered row, with a little overshoot ---------- */
@keyframes pop-in { from { opacity:0; transform:translateY(16px) scale(.93) rotate(-2.5deg); } }
@keyframes pop-in-sticker { from { opacity:0; transform:scale(.4) rotate(-14deg); } }
:is(.page:not(.study):not(.sounds) > *:not(.grid):not(.home-grid):not(.progress-grid):not(.ticker):not(.hero),
    .page > :is(.grid, .grid-2, .grid-3) > *, .home-grid > *, .progress-grid > *, .sounds:not(.lang-swap) > *, .hero > *) {
  animation:pop-in .38s var(--spring) backwards; animation-delay:calc(var(--i,0) * 60ms);
}
:is(.page:not(.study):not(.sounds), .home-grid, .progress-grid, .page > :is(.grid, .grid-2, .grid-3), .sounds:not(.lang-swap), .hero) > :nth-child(2) { --i:1; }
:is(.page:not(.study):not(.sounds), .home-grid, .progress-grid, .page > :is(.grid, .grid-2, .grid-3), .sounds:not(.lang-swap), .hero) > :nth-child(3) { --i:2; }
:is(.page:not(.study):not(.sounds), .home-grid, .progress-grid, .page > :is(.grid, .grid-2, .grid-3), .sounds:not(.lang-swap), .hero) > :nth-child(4) { --i:3; }
:is(.page:not(.study):not(.sounds), .home-grid, .progress-grid, .page > :is(.grid, .grid-2, .grid-3), .sounds:not(.lang-swap), .hero) > :nth-child(5) { --i:4; }
:is(.page:not(.study):not(.sounds), .home-grid, .progress-grid, .page > :is(.grid, .grid-2, .grid-3), .sounds:not(.lang-swap), .hero) > :nth-child(6) { --i:5; }
:is(.page:not(.study):not(.sounds), .home-grid, .progress-grid, .page > :is(.grid, .grid-2, .grid-3), .sounds:not(.lang-swap), .hero) > :nth-child(7) { --i:6; }
:is(.page:not(.study):not(.sounds), .home-grid, .progress-grid, .page > :is(.grid, .grid-2, .grid-3), .sounds:not(.lang-swap), .hero) > :nth-child(n+8) { --i:7; }
.hero > .sticker { animation-name:pop-in-sticker; }

/* oversize headings with a hard stripe that is struck in under them */
h1.page-title, .page-title { font-size:clamp(2.2rem,9vw,3.9rem); letter-spacing:-.035em; }
.page-title::after { content:""; display:block; width:min(220px,46%); height:10px; margin-top:10px; border:2px solid var(--ink); border-radius:999px;
  background-image:repeating-linear-gradient(-45deg, var(--ink) 0 5px, transparent 5px 10px); transform-origin:left center; animation:strike .5s var(--snap) .12s backwards; }
@keyframes strike { from { transform:scaleX(0); } }

/* ---------- 2. nav: sliding ink pill + logo that reacts ---------- */
@media (min-width:860px) { #nav { position:relative; } }   /* mobile: app.css already makes the bar position:fixed (a containing block for the pill) */
#nav .nav-pill { position:absolute; left:0; top:0; z-index:0; pointer-events:none; background:var(--ink); border-radius:999px; box-shadow:3px 3px 0 var(--pink);
  transition:transform .36s var(--spring), opacity .2s; }
#nav .nav-pill.no-anim { transition:none; }
#nav.has-pill a { position:relative; z-index:1; background:transparent; transition:color .2s; }
#nav.has-pill a[aria-current] { background:transparent; color:var(--paper); }
#nav.has-pill a:hover:not([aria-current]) { background:var(--yellow); color:var(--on-accent); }
.logo { transition:transform .3s var(--spring), background .1s; }
.logo-zh { transition:transform .5s var(--spring); }
.logo:hover .logo-zh, .logo:focus-visible .logo-zh { transform:rotate(360deg) scale(1.08); }
.logo:active { transform:rotate(-7deg) scale(.95); }
#theme-toggle { transition:transform .25s var(--spring), box-shadow 80ms steps(2); }
#theme-toggle:hover { transform:translate(-2px,-2px) rotate(-3deg); }

/* ---------- 3. buttons: tactile press (kept) + a hard-edged shine sweep; stickers/chips react ---------- */
.btn { position:relative; overflow:hidden; isolation:isolate; }
.btn::after { content:""; position:absolute; z-index:-1; top:-20%; bottom:-20%; left:0; width:26%; background:rgba(255,255,255,.5);
  transform:translateX(-200%) skewX(-22deg); pointer-events:none; }
.btn:hover::after, .btn:focus-visible::after { animation:shine .55s var(--snap); }
.btn[disabled]::after, .btn[aria-disabled="true"]::after, .btn-ghost::after { display:none; }
@keyframes shine { to { transform:translateX(520%) skewX(-22deg); } }
.chip { transition:transform .25s var(--spring), background 80ms, color 80ms; }
.chip:hover { transform:translateY(-3px) rotate(-1.5deg); }
.chip:active { transform:translate(2px,2px); }
@keyframes wiggle { 25% { rotate:7deg; } 50% { rotate:-6deg; } 75% { rotate:3deg; } }
.sticker:hover, .badge-class:hover { animation:wiggle .5s var(--snap); }
@keyframes breathe { 0%,100% { rotate:-2deg; scale:1; } 50% { rotate:2deg; scale:1.07; } }
.wob { animation:breathe 3.4s ease-in-out infinite; }
.wob:nth-child(2) { animation-delay:-1.1s; } .wob:nth-child(3) { animation-delay:-2.2s; }
.is-off, .is-off * { animation-play-state:paused !important; }

/* ---------- 4. Home hero: sticker cluster + class-word ticker ---------- */
.hero { display:flex; flex-wrap:wrap; align-items:center; gap:10px 14px; margin:0 0 6px; }
.hero > .page-title { margin:0 12px 0 0; }
.hero-stickers { display:flex; flex-wrap:wrap; gap:8px 12px; align-items:center; }
.hero .sticker { font-size:14px; }
.ticker { overflow:hidden; border:var(--border); border-radius:var(--radius); background:var(--yellow); color:var(--on-accent); box-shadow:var(--shadow); margin:14px 0 22px; transform:rotate(-.5deg); }
.ticker { animation:pop-in .38s var(--spring) .2s backwards; }
.ticker-track { display:flex; width:max-content; animation:marquee 60s linear infinite; }
.ticker:hover .ticker-track { animation-play-state:paused; }
.ticker-item { display:inline-flex; align-items:baseline; gap:10px; padding:9px 22px; white-space:nowrap; border-right:3px solid var(--on-accent); }
.ticker-item .t-zh { font:700 1.5rem/1.2 var(--font-zh); }
.ticker-item .t-py { font:700 .95rem var(--font-mono); }
.ticker-item .t-en { font:500 .95rem var(--font-ui); }
@keyframes marquee { to { transform:translateX(-50%); } }

/* ---------- 5. halftone corners on the colour blocks (decorative, behind the text) ---------- */
:is(.today-card, .streak-card, .class-card, .retention-card, .suggest-card, .stats-card) { isolation:isolate; overflow:hidden; }
:is(.today-card, .streak-card, .class-card, .retention-card, .suggest-card, .stats-card)::before {
  content:""; position:absolute; z-index:-1; right:-14px; top:-14px; width:130px; height:130px; pointer-events:none; opacity:.2;
  background-image:radial-gradient(var(--on-accent) 2.2px, transparent 2.6px); background-size:13px 13px;
  -webkit-mask-image:radial-gradient(circle at 70% 30%, #000 0, transparent 70%); mask-image:radial-gradient(circle at 70% 30%, #000 0, transparent 70%); }
.stat-circle { position:relative; }
.today-card .stat-circle { animation:pop-in-sticker .5s var(--spring) .25s backwards; }

/* ---------- 6. progress bars: fill grows in, stripes slide ---------- */
.bar-fill { position:relative; overflow:hidden; background-image:none; transform-origin:left center; animation:grow .8s var(--snap) backwards; animation-delay:calc(var(--i,0) * 45ms + .1s); }
.bar-fill::before { content:""; position:absolute; top:0; bottom:0; left:-17px; right:0; pointer-events:none;
  background-image:repeating-linear-gradient(-45deg, rgba(17,17,17,.28) 0 6px, transparent 6px 12px); animation:stripes .9s linear 3; }
@keyframes grow { from { transform:scaleX(0); } }
@keyframes grow-from { from { transform:scaleX(var(--prev,0)); } }
@keyframes stripes { to { transform:translateX(16.97px); } }
.study .bar-fill { animation:grow-from .5s var(--spring) backwards; }
.study .bar-fill::before { animation-iteration-count:infinite; }
.mastery-row { animation:pop-in .38s var(--spring) backwards; animation-delay:calc(var(--i,0) * 60ms + .2s); }

/* ---------- 7. toasts pop with a bounce, modals scale in ---------- */
@keyframes toast-in { from { opacity:0; transform:translateY(26px) scale(.78) rotate(-3deg); } }
@keyframes toast-out { to { opacity:0; transform:translateY(10px) scale(.92); } }
.toast { animation:toast-in .38s var(--spring) backwards; }
.toast.is-leaving { animation:toast-out .24s ease-in forwards; }
@keyframes fade-in { from { opacity:0; } }
@keyframes modal-in { from { opacity:0; transform:translateY(24px) scale(.86) rotate(-2deg); } }
.modal-backdrop { animation:fade-in .18s ease-out backwards; }
.modal { animation:modal-in .34s var(--spring) backwards; }

/* ---------- 8. study: 3D flashcard, hover tilt, deal-in, stamp, combo ---------- */
.flash { position:relative; --rot:-1deg; --rx:0deg; --ry:0deg; transition:transform .2s ease-out; }
.flash.is-back { --rot:1deg; }
.flash:hover, .flash:focus-within { --rot:0deg; }
:is(.flash, .flash.is-back, .flash:hover, .flash:focus-within) { transform:perspective(1100px) rotate(var(--rot)) rotateX(var(--rx)) rotateY(var(--ry)); }
@keyframes deal { from { opacity:0; transform:perspective(1100px) translateY(34px) rotate(-6deg) scale(.9); } }
.study .flash { animation:deal .36s var(--spring) .05s backwards; }
.flash.fx-ghost { transition:none; z-index:60; pointer-events:none; --rot:-1deg; }
.fx-ghost, .fx-ghost *:not(.fx-stamp) { animation:none !important; }
.fx-stamp { position:absolute; left:50%; top:46%; padding:6px 24px; font:700 clamp(2rem,9vw,3rem)/1 var(--font-ui); letter-spacing:.06em; color:var(--on-accent);
  border:5px solid var(--ink); border-radius:12px; box-shadow:5px 5px 0 var(--ink); transform:translate(-50%,-50%) rotate(-13deg); white-space:nowrap; z-index:3; }
.fx-stamp.g1 { background:var(--orange); } .fx-stamp.g2 { background:var(--yellow); } .fx-stamp.g3 { background:var(--lime); } .fx-stamp.g4 { background:var(--blue); }
.fx-burst { position:fixed; width:0; height:0; z-index:96; pointer-events:none; }
.fx-bit { position:absolute; left:0; top:0; width:10px; height:12px; border:2px solid var(--ink); }
.fx-bit.round { border-radius:50%; width:11px; height:11px; }
.fx-flash-bad { position:absolute; inset:0; z-index:2; pointer-events:none; background:var(--orange); border-radius:inherit; opacity:0; }
.combo { margin-left:auto; background:var(--orange); color:var(--on-accent); }
.combo-flame { display:inline-block; animation:flame .6s var(--spring) infinite alternate; transform-origin:50% 90%; }
.combo-n { display:inline-block; animation:count-pop .45s var(--spring) backwards; }
@keyframes flame { from { transform:translateY(0) scale(1) rotate(-7deg); } to { transform:translateY(-3px) scale(1.2) rotate(7deg); } }
@keyframes count-pop { from { transform:scale(2.2); } }
/* correct / wrong answer feedback: a stamped label with an icon (never colour alone) */
.feedback { position:relative; }
.feedback.ok, .feedback.bad { animation:stamp .4s var(--spring) backwards; }
.feedback.ok::before { content:"\2713\00a0"; content:"\2713\00a0" / ""; }
.feedback.bad::before { content:"\2717\00a0"; content:"\2717\00a0" / ""; }
@keyframes stamp { from { opacity:0; transform:scale(1.7) rotate(-4deg); } }
/* hanzi ink-in and pinyin typewriter (one pop per syllable) on new cards */
@keyframes ink { from { opacity:0; filter:blur(10px); transform:scale(1.16); } }
@keyframes syl { from { opacity:0; transform:translateY(8px) scale(.6); } }
.flash:not(.is-back) .hanzi-xl, .flash-intro .hanzi-xl { animation:ink .42s ease-out .08s backwards; }
.flash.is-back .pinyin > span[class^="tone"] { display:inline-block; animation:syl .34s var(--spring) backwards; animation-delay:.1s; }
.flash.is-back .pinyin > span:nth-child(2) { animation-delay:.18s; } .flash.is-back .pinyin > span:nth-child(3) { animation-delay:.26s; }
.flash.is-back .pinyin > span:nth-child(n+4) { animation-delay:.34s; }
.grade-row .btn-grade { animation:pop-in .3s var(--spring) backwards; }
.grade-row .btn-grade:nth-child(2) { animation-delay:.04s; } .grade-row .btn-grade:nth-child(3) { animation-delay:.08s; } .grade-row .btn-grade:nth-child(4) { animation-delay:.12s; }
.confetti-piece:nth-child(3n) { border-radius:50%; }

/* ---------- 9. route swoosh (js/fx.js routeWipe, <= 250 ms, hard-edged, never blocks clicks) ---------- */
.route-wipe { position:fixed; left:0; top:0; bottom:0; z-index:70; display:flex; pointer-events:none; }
.route-wipe i { flex:1; border-left:3px solid var(--ink); border-right:3px solid var(--ink); }
.route-wipe .b1 { background:var(--pink); } .route-wipe .b2 { background:var(--lime); } .route-wipe .b3 { background:var(--yellow); }

/* ---------- 10. sounds: chips bounce, respellings flip when the language changes ---------- */
.snd-langs .chip:hover { animation:bounce .5s var(--spring); }
@keyframes bounce { 40% { transform:translateY(-8px) scale(1.06); } }
.sounds .say-syl { display:inline-block; transition:transform .25s var(--spring); }
.sounds .say-syl:hover { transform:translateY(-4px) scale(1.12); }
@keyframes syl-swap { from { opacity:0; transform:rotateX(-90deg) translateY(6px); } }
.lang-swap .say-syl { animation:syl-swap .42s var(--spring) backwards; }
.lang-swap .snd-tbl tr:nth-child(3n+2) .say-syl { animation-delay:.05s; } .lang-swap .snd-tbl tr:nth-child(3n) .say-syl { animation-delay:.1s; }
.snd-cell:hover .say-text { text-decoration:underline wavy var(--pink); text-underline-offset:4px; }

/* ---------- 11. floating shapes with slow scroll parallax (desktop only; fixed layers, transform-only) ---------- */
.deco { position:fixed; inset:0; z-index:-1; pointer-events:none; overflow:hidden; display:none; }
.deco svg { position:absolute; stroke:var(--ink); stroke-width:4; stroke-linejoin:round; stroke-linecap:round; overflow:visible; }
.deco-star { width:84px; right:6%; bottom:14%; fill:var(--yellow); --r:12deg; --pz:1.6; }
.deco-squig { width:150px; left:3%; top:26%; fill:none; stroke:var(--pink); stroke-width:9; --r:-8deg; --pz:.8; }
.deco-plus { width:54px; left:5%; top:58%; fill:var(--lilac); --r:0deg; --pz:1.2; }
@media (min-width:700px) { .deco { display:block; } }
@keyframes floaty { 0%,100% { transform:translateY(0) rotate(var(--r,0deg)); } 50% { transform:translateY(-14px) rotate(calc(var(--r,0deg) + 7deg)); } }
@keyframes drift { to { translate:0 calc(var(--pz,1) * -150px); } }
.deco svg { transform:rotate(var(--r,0deg)); animation:floaty 7s ease-in-out infinite; }
.deco-squig { animation-duration:9s; animation-delay:-3s; } .deco-plus { animation-duration:8s; animation-delay:-5s; }
body::before { --r:0deg; --pz:1; } body::after { --r:18deg; --pz:1.4; }
@media (min-width:700px) { body::before, body::after { animation:floaty 10s ease-in-out infinite; } body::after { animation-duration:12s; animation-delay:-4s; } }
@supports (animation-timeline: scroll()) {
  .deco svg { animation:floaty 7s ease-in-out infinite, drift linear both; animation-timeline:auto, scroll(root); }
  .deco-squig { animation-duration:9s, 1s; } .deco-plus { animation-duration:8s, 1s; }
  @media (min-width:700px) { body::before, body::after { animation:floaty 10s ease-in-out infinite, drift linear both; animation-timeline:auto, scroll(root); }
    body::after { animation-duration:12s, 1s; } }
}

/* footer text links were 17px tall: give them a 44px hit area without changing the look */
.footer a { display:inline-block; padding:14px 2px; line-height:1.2; }

/* ---------- 12. footer sticker sheet ---------- */
.sticker-sheet { display:flex; flex-wrap:wrap; gap:10px 14px; margin:0 0 14px; }
.sticker-sheet .sticker { font-size:15px; padding:6px 16px; transition:translate .25s var(--spring), rotate .25s var(--spring); }
.sticker-sheet .sticker:nth-child(1) { rotate:-3deg; } .sticker-sheet .sticker:nth-child(2) { rotate:4deg; } .sticker-sheet .sticker:nth-child(3) { rotate:-2deg; }
.sticker-sheet .sticker:nth-child(4) { rotate:3deg; } .sticker-sheet .sticker:nth-child(5) { rotate:-4deg; } .sticker-sheet .sticker:nth-child(6) { rotate:2deg; }
.sticker-sheet .sticker:hover { translate:0 -5px; rotate:7deg; animation:none; }

/* ==========================================================================
   Reduced motion: the OS setting OR Settings > Reduce motion (html.reduce-motion). Everything above switches off; all content still shows.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .ticker { transform:none; }
  .ticker-track { flex-wrap:wrap; width:auto; max-height:7rem; overflow:hidden; transform:none; }
  .ticker-dup { display:none !important; }
  .route-wipe, .fx-burst, .fx-ghost { display:none !important; }
  .sticker, .badge-class { transform:none !important; } .sticker-sheet .sticker, .wob { rotate:none !important; scale:none !important; }
  .deco svg, body::before, body::after { transform:none !important; translate:none !important; }
  .btn::after { display:none; }
  #nav .nav-pill { transition:none; }
  :is(.flash, .flash.is-back, .flash:hover, .flash:focus-within) { transform:none !important; }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation:none !important; transition:none !important; scroll-behavior:auto !important; }
html.reduce-motion .ticker { transform:none; }
html.reduce-motion .ticker-track { flex-wrap:wrap; width:auto; max-height:7rem; overflow:hidden; transform:none; }
html.reduce-motion .ticker-dup { display:none !important; }
html.reduce-motion :is(.route-wipe, .fx-burst, .fx-ghost) { display:none !important; }
html.reduce-motion :is(.sticker, .badge-class, .logo) { transform:none !important; }
html.reduce-motion :is(.sticker-sheet .sticker, .wob) { rotate:none !important; scale:none !important; }
html.reduce-motion :is(.deco svg, body::before, body::after) { transform:none !important; translate:none !important; }
html.reduce-motion .btn::after { display:none; }
html.reduce-motion :is(.flash, .flash.is-back, .flash:hover, .flash:focus-within) { transform:none !important; }
@media print { .deco, .route-wipe, .fx-burst { display:none !important; } }
