/* =========================================================================
   Kido — Animation system
   Feedback-first motion. Everything is gated by prefers-reduced-motion /
   the parent "Reduce motion" setting (which adds .reduce-motion to <html>).
   ========================================================================= */

@keyframes pop-in     { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.06); } 100% { transform: scale(1); opacity: 1; } }
@keyframes fade-out   { to { opacity: 0; transform: translateY(-6px); } }
@keyframes bounce     { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes wiggle     { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes shake      { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes float      { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes float-x    { 0% { transform: translateX(-4vw); } 100% { transform: translateX(104vw); } }
@keyframes pulse      { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes jump       { 0% { transform: translateY(0); } 30% { transform: translateY(-40px) scaleY(1.05); } 60% { transform: translateY(0) scaleY(.9); } 100% { transform: translateY(0); } }
@keyframes spin-slow  { to { transform: rotate(360deg); } }
@keyframes confetti-fall { 0% { transform: translateY(-10vh) rotate(0); opacity: 1; } 100% { transform: translateY(110vh) rotate(720deg); opacity: 0; } }
@keyframes sparkle    { 0% { transform: scale(0) rotate(0); opacity: 0; } 40% { transform: scale(1.3) rotate(90deg); opacity: 1; } 100% { transform: scale(0) rotate(180deg); opacity: 0; } }
@keyframes drive-by   { 0% { transform: translateX(-30vw) scaleX(1); } 100% { transform: translateX(120vw) scaleX(1); } }
@keyframes run-cycle  { 0%,100% { transform: translateY(0) rotate(1deg); } 25% { transform: translateY(-4px) rotate(3deg); } 50% { transform: translateY(-7px) rotate(0deg); } 75% { transform: translateY(-3px) rotate(-1.5deg); } }
@keyframes grow-plant { 0% { transform: scaleY(.1); } 100% { transform: scaleY(1); } }
@keyframes rise-in    { 0% { transform: translateY(24px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

/* World-class polish: living mascot, screen entrances, collectible stickers */
@keyframes mascot-pop        { 0% { transform: translateY(16px) scale(.6); opacity: 0; } 60% { transform: translateY(-5px) scale(1.06); opacity: 1; } 100% { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes mascot-bubble-pop { 0% { transform: translateY(6px) scale(.9); opacity: 0; } 100% { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes screen-in         { 0% { transform: translateY(10px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes sticker-pop       { 0% { transform: scale(0) rotate(-18deg); opacity: 0; } 55% { transform: scale(1.18) rotate(6deg); } 100% { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes pop-correct       { 0% { transform: scale(1); } 30% { transform: scale(1.14) rotate(-3deg); } 55% { transform: scale(.96) rotate(2deg); } 100% { transform: scale(1); } }

/* Utility classes the JS toggles on */
.anim-bounce  { animation: bounce .5s ease; }
.anim-wiggle  { animation: wiggle .45s ease; }
.anim-pop     { animation: pop-in .35s ease; }
.anim-shake   { animation: shake .4s ease; }
.anim-jump    { animation: jump .55s ease; }
.anim-pulse   { animation: pulse 1.6s ease-in-out infinite; }
.anim-float   { animation: float 3.4s ease-in-out infinite; }
.anim-spin    { animation: spin-slow 6s linear infinite; }
.anim-drive   { animation: drive-by 1.4s ease-in forwards; }

/* Splash intro */
.splash__mark { animation: pop-in .6s ease; }
.splash__dot  { animation: bounce 1s ease-in-out infinite .3s; }

/* World clouds drift across the sky at different speeds */
.cloud--1 { top: 4%;  animation: float-x 32s linear infinite; }
.cloud--2 { top: 22%; animation: float-x 46s linear infinite 6s; font-size: 34px; }
.cloud--3 { top: 40%; animation: float-x 58s linear infinite 12s; font-size: 54px; opacity: .6; }

/* Bouncy entrance for stops (one orchestrated reveal, staggered) */
.stop { animation: rise-in .5s ease both; }
.stop:nth-child(1) { animation-delay: .02s; }
.stop:nth-child(2) { animation-delay: .10s; }
.stop:nth-child(3) { animation-delay: .18s; }
.stop:nth-child(4) { animation-delay: .26s; }
.stop:nth-child(5) { animation-delay: .34s; }
.stop:nth-child(6) { animation-delay: .42s; }
.stop:nth-child(7) { animation-delay: .50s; }

/* Idle "breathing" for the big showcase object */
.showcase { animation: float 3.6s ease-in-out infinite; }

/* Confetti + sparkle particles created by fx.js */
.confetti { position: fixed; top: -10vh; width: 12px; height: 16px; border-radius: 3px; z-index: 75; animation: confetti-fall linear forwards; }
.sparkle  { position: fixed; z-index: 75; font-size: 26px; animation: sparkle .8s ease forwards; pointer-events: none; }

/* =========================================================================
   Runner heroes: articulated run cycle (Change #28)
   The heroes are rigged (js/activities/wordAdventure.js heroSvg): every thigh, shin, upper arm and forearm
   rotates around its own joint, so the knee folds as the leg swings back and reaches out straight in front,
   and the elbows stay bent like a real runner's. Angles: + swings a limb backward (the hero faces right).
   One stride = 0.5 s; the back leg and front arm run half a stride later.
   ========================================================================= */
.hero-j, .hero-body, .hero-cape, .hero-tail, .hero-shadow, .hero-tiko-lid, .hero-gajju-trunk, .hero-gajju-ear,
.hero-chintu-whistle, .hero-chintu-steam {
  transform-box: view-box;
  will-change: transform;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.4, 1);
}
.hero-j--thigh-front, .hero-j--thigh-back { transform-origin: 52px 66px; }   /* hip */
.hero-j--shin-front,  .hero-j--shin-back  { transform-origin: 52px 81px; }   /* knee */
.hero-j--upper-front, .hero-j--upper-back { transform-origin: 57px 47px; }   /* shoulder */
.hero-j--fore-front,  .hero-j--fore-back  { transform-origin: 57px 57px; }   /* elbow */
.hero-body--torso { transform-origin: 54px 66px; }
.hero-body--head  { transform-origin: 58px 44px; }
.hero-shadow      { transform-origin: 54px 101px; }
.hero-cape   { transform-origin: 50px 44px; }
.hero-tail   { transform-origin: 47px 66px; }
.hero-tiko-lid    { transform-origin: 44.5px 41px; }   /* Tiko's tiffin lid hinges on the side by his back */
.hero-tiko-tiffin { transform-box: view-box; }
.hero-gajju-trunk { transform-origin: 74px 32px; }   /* trunk root, at the face */
.hero-gajju-ear   { transform-origin: 55px 22px; }   /* where the ear joins the head */

/* Running */
.runner__char.running .hero-j, .runner__char.running .hero-body, .runner__char.running .hero-shadow,
.runner__char.running .hero-cape, .runner__char.running .hero-tail { transition: none; }
.runner__char.running .hero-j--thigh-front { animation: hero-thigh 0.5s linear infinite; }
.runner__char.running .hero-j--shin-front  { animation: hero-shin 0.5s linear infinite; }
.runner__char.running .hero-j--thigh-back  { animation: hero-thigh 0.5s linear infinite -0.25s; }
.runner__char.running .hero-j--shin-back   { animation: hero-shin 0.5s linear infinite -0.25s; }
.runner__char.running .hero-j--upper-front { animation: hero-upper 0.5s ease-in-out infinite -0.25s; }
.runner__char.running .hero-j--fore-front  { animation: hero-fore 0.5s ease-in-out infinite -0.25s; }
.runner__char.running .hero-j--upper-back  { animation: hero-upper 0.5s ease-in-out infinite; }
.runner__char.running .hero-j--fore-back   { animation: hero-fore 0.5s ease-in-out infinite; }
.runner__char.running .hero-body--torso { animation: hero-torso-bounce 0.5s ease-in-out infinite; }
.runner__char.running .hero-body--head  { animation: hero-head-bob 0.5s ease-in-out infinite; }
.runner__char.running .hero-shadow      { animation: hero-shadow-pulse 0.5s ease-in-out infinite; }
.runner__char.running .hero-cape   { animation: hero-cape-flutter 0.38s ease-in-out infinite; }
.runner__char.running .hero-tail   { animation: hero-tail-sway 0.5s ease-in-out infinite; }

/* In the air: front knee up, back leg trailing, front arm reaching up for the letter */
.runner__char:not(.running):not(.flipping) .hero-j--thigh-front { transform: rotate(-58deg); }
.runner__char:not(.running):not(.flipping) .hero-j--shin-front  { transform: rotate(72deg); }
.runner__char:not(.running):not(.flipping) .hero-j--thigh-back  { transform: rotate(24deg); }
.runner__char:not(.running):not(.flipping) .hero-j--shin-back   { transform: rotate(82deg); }
.runner__char:not(.running):not(.flipping) .hero-j--upper-front { transform: rotate(-150deg); }
.runner__char:not(.running):not(.flipping) .hero-j--fore-front  { transform: rotate(-20deg); }
.runner__char:not(.running):not(.flipping) .hero-j--upper-back  { transform: rotate(42deg); }
.runner__char:not(.running):not(.flipping) .hero-j--fore-back   { transform: rotate(-60deg); }
.runner__char:not(.running):not(.flipping) .hero-body--torso    { transform: rotate(-4deg) translateY(-2px); }
.runner__char:not(.running):not(.flipping) .hero-shadow         { transform: scale(0.62); opacity: 0.28; }
.runner__char:not(.running):not(.flipping) .hero-cape      { transform: rotate(-16deg) scaleY(1.15); }
.runner__char:not(.running):not(.flipping) .hero-tail      { transform: rotate(-12deg); }

/* Tiko: the tiffin bounces on his back as he runs; mid-jump its lid pops open to catch the letter */
.runner__char.running .hero-tiko-tiffin { animation: tiko-tiffin-bounce 0.25s ease-in-out infinite; }
.runner__char:not(.running):not(.flipping) .hero-tiko-lid { transform: rotate(-80deg); }
@keyframes tiko-tiffin-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.8px) rotate(-1.5deg); } }

/* Gajju: ears flap on every step and the trunk swings; mid-jump the trunk curls up to snatch the letter */
.runner__char.running .hero-gajju-ear   { animation: gajju-ear-flap 0.25s ease-in-out infinite; }
.runner__char.running .hero-gajju-trunk { animation: gajju-trunk-swing 0.5s ease-in-out infinite; }
.runner__char:not(.running):not(.flipping) .hero-gajju-trunk { transform: rotate(-115deg); }
.runner__char:not(.running):not(.flipping) .hero-gajju-ear   { transform: rotate(-14deg); }
@keyframes gajju-ear-flap    { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(13deg); } }
@keyframes gajju-trunk-swing { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(9deg); } }

/* Pari: in the air the kite fills with wind (it lifts and grows) while she glides */
.runner__char:not(.running):not(.flipping) .hero-pari-kite { transform: rotate(-24deg) scale(1.3); }
/* Chintu: in the air the whistle jumps up and a puff of steam blows out ("seeti!") */
.hero-chintu-whistle, .hero-chintu-steam { transform-origin: 62px 10px; }
.hero-chintu-steam { opacity: 0; transform: translateY(4px) scale(0.4); }
.runner__char:not(.running):not(.flipping) .hero-chintu-whistle { transform: translateY(-3px) rotate(-12deg); }
.runner__char:not(.running):not(.flipping) .hero-chintu-steam { opacity: 0.95; transform: translateY(-2px) scale(1.15); }

/* Somersault (Captain Nova, Comet): tucked into a ball */
.runner__char.flipping .hero-j--thigh-front, .runner__char.flipping .hero-j--thigh-back { transform: rotate(-95deg); }
.runner__char.flipping .hero-j--shin-front,  .runner__char.flipping .hero-j--shin-back  { transform: rotate(125deg); }
.runner__char.flipping .hero-j--upper-front, .runner__char.flipping .hero-j--upper-back { transform: rotate(-70deg); }
.runner__char.flipping .hero-j--fore-front,  .runner__char.flipping .hero-j--fore-back  { transform: rotate(-65deg); }
.runner__char.flipping .hero-shadow { transform: scale(0.5); opacity: 0.2; }

/* The hero picker shows them mid-stride */
.runner__pick-art .hero-j--thigh-front { transform: rotate(-32deg); }
.runner__pick-art .hero-j--shin-front  { transform: rotate(14deg); }
.runner__pick-art .hero-j--thigh-back  { transform: rotate(30deg); }
.runner__pick-art .hero-j--shin-back   { transform: rotate(80deg); }
.runner__pick-art .hero-j--upper-front { transform: rotate(38deg); }
.runner__pick-art .hero-j--fore-front  { transform: rotate(-65deg); }
.runner__pick-art .hero-j--upper-back  { transform: rotate(-40deg); }
.runner__pick-art .hero-j--fore-back   { transform: rotate(-85deg); }

/* Gait: contact (leg out in front, nearly straight) → stance → push-off → heel kicks up behind →
   knee drives forward and high → the shin reaches out for the next contact */
@keyframes hero-thigh {
  0%   { transform: rotate(-32deg); }
  15%  { transform: rotate(-8deg); }
  35%  { transform: rotate(30deg); }
  50%  { transform: rotate(26deg); }
  65%  { transform: rotate(-18deg); }
  80%  { transform: rotate(-46deg); }
  92%  { transform: rotate(-40deg); }
  100% { transform: rotate(-32deg); }
}
@keyframes hero-shin {
  0%   { transform: rotate(8deg); }
  15%  { transform: rotate(22deg); }
  35%  { transform: rotate(28deg); }
  50%  { transform: rotate(95deg); }
  65%  { transform: rotate(88deg); }
  80%  { transform: rotate(52deg); }
  92%  { transform: rotate(14deg); }
  100% { transform: rotate(8deg); }
}
/* arms swing from the shoulder against the legs, elbows bent (bending more as the arm comes forward) */
@keyframes hero-upper {
  0%   { transform: rotate(-42deg); }
  50%  { transform: rotate(40deg); }
  100% { transform: rotate(-42deg); }
}
@keyframes hero-fore {
  0%   { transform: rotate(-95deg); }
  50%  { transform: rotate(-55deg); }
  100% { transform: rotate(-95deg); }
}
@keyframes hero-torso-bounce {
  0%, 50%, 100% { transform: translateY(0) rotate(1deg); }
  25%, 75%      { transform: translateY(-2.5px) rotate(2deg); }
}
@keyframes hero-head-bob {
  0%, 50%, 100% { transform: translateY(0) rotate(0deg); }
  25%, 75%      { transform: translateY(-1.5px) rotate(1deg); }
}
@keyframes hero-shadow-pulse {
  0%, 50%, 100% { transform: scaleX(1.06) scaleY(1.04); opacity: 1; }
  25%, 75%      { transform: scaleX(0.9) scaleY(0.9); opacity: 0.72; }
}
@keyframes hero-cape-flutter {
  0%   { transform: rotate(0deg) scaleY(1); }
  25%  { transform: rotate(-9deg) scaleY(1.12); }
  50%  { transform: rotate(5deg) scaleY(0.92); }
  75%  { transform: rotate(-11deg) scaleY(1.16); }
  100% { transform: rotate(0deg) scaleY(1); }
}
@keyframes hero-tail-sway {
  0%   { transform: rotate(-6deg); }
  50%  { transform: rotate(14deg); }
  100% { transform: rotate(-6deg); }
}

@keyframes bubble-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes ground-scroll { from { background-position-x: 0; } to { background-position-x: -80px; } }

/* Ambient environment animations (Kido World's own motion lives in world.css) */
@keyframes sunbeam-shift {
  0%, 100% { opacity: 0.45; transform: scaleX(1); }
  50% { opacity: 0.75; transform: scaleX(1.08); }
}
@keyframes leaf-sway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(4deg); }
}
@keyframes bubble-rise-subtle {
  0% { transform: translateY(18px) scale(0.8); opacity: 0; }
  25% { opacity: 0.65; }
  85% { opacity: 0.65; }
  100% { transform: translateY(-38px) scale(1.1); opacity: 0; }
}
@keyframes star-twinkle {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Tactile button compress */
.anim-tactile:active, .btn:active, .stop__node:active, .journey-step:active {
  transform: scale(0.96) !important;
}

/* Correct-answer celebratory pop on options */
.opt.is-correct { animation: pop-correct .5s cubic-bezier(.34,1.56,.64,1); }

/* Respect reduced motion (system preference OR parent toggle) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
}
html.reduce-motion .cloud, html.reduce-motion .confetti, html.reduce-motion .sparkle { display: none !important; }

/* Change #28: on top of the limb cycle, the whole hero bounces on every footfall and leans into the run, dust kicks up
   behind the feet, take-off stretches and landing squashes. These live on .runner__body, so the jump height
   that paint() writes on .runner__char stays separate. One stride = 0.5 s = two footfalls. */
.runner__body { position: relative; width: 100%; height: 100%; transform-origin: 50% 100%; }
.runner__char.running .runner__body { animation: hero-run-bounce 0.25s ease-in-out infinite; }
.runner__char.takeoff .runner__body { animation: none; transform: scale(0.9, 1.12); }
.runner__char.land .runner__body { animation: hero-land 0.2s ease-out; }
@keyframes hero-run-bounce {
  0%, 100% { transform: translateY(0) rotate(5deg) scale(1.03, 0.97); }
  50%      { transform: translateY(-6%) rotate(7deg) scale(0.98, 1.03); }
}
@keyframes hero-land {
  0%   { transform: scale(1.15, 0.84); }
  60%  { transform: scale(0.96, 1.05); }
  100% { transform: scale(1, 1); }
}
.runner__dust { position: absolute; left: 4%; bottom: 3%; width: 34%; height: 20%; pointer-events: none; opacity: 0; }
.runner__char.running .runner__dust { opacity: 1; }
.runner__dust::before, .runner__dust::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 18%; aspect-ratio: 1; border-radius: 50%;
  background: rgba(226, 232, 240, 0.9); animation: hero-dust 0.5s ease-out infinite;
}
.runner__dust::after { animation-delay: 0.25s; width: 13%; }
@keyframes hero-dust {
  0%   { transform: translate(0, 0) scale(0.35); opacity: 0.9; }
  100% { transform: translate(-260%, -90%) scale(1.5); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .runner__char.running .runner__body, .runner__dust::before, .runner__dust::after { animation: none; }
}
