/* ==========================================================================
   Rich Duolingo-Grade Motion & Micro-Animation System
   Rigged SVG Characters, Progress Sparks, Sunbursts, Chest Glow, Floating XP
   ========================================================================== */

/* 1. Rigged SVG Character Animations (Blink, Wing Flap, Talk, Sparkles) */
.svg-blink-eyes {
  transform-box: fill-box;
  transform-origin: center;
  animation: svg-eye-blink 4.2s ease-in-out infinite;
}

@keyframes svg-eye-blink {
  0%, 44%, 48%, 92%, 96%, 100% { transform: scaleY(1); }
  46%, 94% { transform: scaleY(0.08); }
}

.ao-body-group {
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: ao-breathe 3.4s ease-in-out infinite;
}

@keyframes ao-breathe {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.02, 0.985) translateY(1px); }
}

.ao-wing-l.celebrate {
  transform-box: fill-box;
  transform-origin: right center;
  animation: wing-flap-l 0.48s ease-in-out infinite;
}

.ao-wing-r.celebrate {
  transform-box: fill-box;
  transform-origin: left center;
  animation: wing-flap-r 0.48s ease-in-out infinite;
}

.ao-wing-l.wave {
  transform-box: fill-box;
  transform-origin: right center;
  animation: wing-flap-l 0.65s ease-in-out infinite;
}

.ao-wing-l.idle,
.ao-wing-r.idle {
  transform-box: fill-box;
  transform-origin: center top;
  animation: wing-idle 3.4s ease-in-out infinite;
}

@keyframes wing-flap-l {
  0%, 100% { transform: rotate(-44deg); }
  50% { transform: rotate(-72deg) translateY(-3px); }
}

@keyframes wing-flap-r {
  0%, 100% { transform: rotate(44deg); }
  50% { transform: rotate(72deg) translateY(-3px); }
}

@keyframes wing-idle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(3deg); }
}

.ao-ears {
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: ear-twitch 5.5s ease-in-out infinite;
}

@keyframes ear-twitch {
  0%, 86%, 100% { transform: rotate(0deg); }
  90% { transform: rotate(-5deg); }
  94% { transform: rotate(4deg); }
}

.ao-tear {
  transform-box: fill-box;
  transform-origin: center top;
  animation: tear-drop 2.2s ease-in infinite;
}

@keyframes tear-drop {
  0% { transform: translateY(0) scale(0.7); opacity: 0; }
  25% { opacity: 1; transform: translateY(2px) scale(1); }
  85% { opacity: 0.9; transform: translateY(18px) scale(0.9); }
  100% { opacity: 0; transform: translateY(22px) scale(0.5); }
}

.ao-sparkle {
  transform-box: fill-box;
  transform-origin: center;
  animation: twinkle-star 1.4s ease-in-out infinite;
}

.ao-sparkle.s2 {
  animation-delay: 0.55s;
}

@keyframes twinkle-star {
  0%, 100% { transform: scale(0.7) rotate(0deg); opacity: 0.6; }
  50% { transform: scale(1.22) rotate(24deg); opacity: 1; }
}

.char-headphones {
  transform-box: fill-box;
  transform-origin: center;
  animation: music-nod 2.1s ease-in-out infinite;
}

@keyframes music-nod {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* Lip-syncing talking mouth when TTS speaks */
.anim-speaking .svg-talk-mouth {
  transform-box: fill-box;
  transform-origin: center;
  animation: mouth-talk 210ms ease-in-out infinite;
}

@keyframes mouth-talk {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.42) translateY(1px); }
}

/* Character reaction jumps inside lessons */
.char-celebrate-jump {
  animation: char-joy-jump 520ms var(--ease-bounce) both;
}

@keyframes char-joy-jump {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-16px) scale(1.12, 0.94) rotate(-5deg); }
  65% { transform: translateY(2px) scale(0.95, 1.05) rotate(4deg); }
  100% { transform: translateY(0) scale(1) rotate(0deg); }
}

.char-oops-wobble {
  animation: char-wobble 450ms ease both;
}

@keyframes char-wobble {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-10deg) translateX(-4px); }
  45% { transform: rotate(8deg) translateX(4px); }
  70% { transform: rotate(-5deg) translateX(-2px); }
}

/* 2. Learning Path Juice — Active Halo, Chest Glow, Legendary Gold Sheen */
.path-node-btn.is-current-node::after {
  content: '';
  position: absolute;
  top: -11px;
  left: -13px;
  right: -13px;
  bottom: -19px;
  border-radius: 50%;
  border: 3px solid var(--node-color, var(--duo-green));
  opacity: 0;
  pointer-events: none;
  animation: node-pulse-halo 2.2s ease-out infinite;
}

@keyframes node-pulse-halo {
  0% { transform: scale(0.88); opacity: 0.65; }
  75% { transform: scale(1.24); opacity: 0; }
  100% { transform: scale(1.24); opacity: 0; }
}

.path-node-btn.chest-ready {
  animation: chest-wiggle 2.1s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(255, 200, 0, 0.65));
}

@keyframes chest-wiggle {
  0%, 60%, 100% { transform: rotate(0deg) scale(1); }
  68% { transform: rotate(-6deg) scale(1.06); }
  76% { transform: rotate(6deg) scale(1.08); }
  84% { transform: rotate(-4deg) scale(1.04); }
  92% { transform: rotate(3deg) scale(1); }
}

/* Diagonal metallic shimmer sweep on Legendary banners & gold nodes */
.unit-banner.is-legendary,
.path-node-btn.legendary {
  overflow: hidden;
}

.unit-banner.is-legendary::after,
.path-node-btn.legendary::after {
  content: '';
  position: absolute;
  top: -20%;
  left: -70%;
  width: 48%;
  height: 150%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-24deg);
  pointer-events: none;
  animation: gold-sheen 3.4s ease-in-out infinite;
}

@keyframes gold-sheen {
  0%, 55% { left: -70%; }
  100% { left: 140%; }
}

/* 3. Lesson Screen — Progress Bar Sparks, Combo Aura & Question Transitions */
.lesson-body-enter {
  animation: exercise-slide-in 260ms var(--ease-out) both;
}

@keyframes exercise-slide-in {
  from { opacity: 0; transform: translateX(22px); }
  to { opacity: 1; transform: translateX(0); }
}

.lesson-progress-track {
  overflow: visible;
}

.lesson-progress-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  overflow: hidden;
}

.lesson-progress-fill.combo-hot {
  box-shadow: 0 0 14px rgba(255, 150, 0, 0.65);
}

.progress-spark {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 10;
  animation: spark-fly 560ms var(--ease-out) forwards;
}

@keyframes spark-fly {
  0% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx, 18px)), calc(-50% + var(--dy, -20px))) scale(0); opacity: 0; }
}

/* Floating +XP / +💎 / Combo Pop Burst */
.floating-burst {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 900;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 2px solid var(--burst-color, var(--duo-green));
  color: var(--burst-color, var(--duo-green-dark));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  z-index: 230;
  animation: burst-rise 950ms var(--ease-out) forwards;
}

@keyframes burst-rise {
  0% { transform: translate(-50%, 8px) scale(0.65); opacity: 0; }
  22% { transform: translate(-50%, -14px) scale(1.12); opacity: 1; }
  75% { transform: translate(-50%, -44px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -70px) scale(0.92); opacity: 0; }
}

/* Match Pairs Emerald Burst Ring */
.match-tile.just-matched {
  animation: match-pop-ring 340ms var(--ease-bounce);
}

@keyframes match-pop-ring {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(88, 204, 2, 0.7); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 10px rgba(88, 204, 2, 0); }
  100% { transform: scale(1); box-shadow: none; }
}

/* 4. Celebration Sunburst Rays & Streak Ignition Shockwave + Embers */
.cele-mascot-stage {
  position: relative;
  width: 176px;
  height: 176px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cele-sunburst {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 200, 0, 0.24) 0deg 16deg,
    transparent 16deg 36deg
  );
  -webkit-mask-image: radial-gradient(circle, black 36%, transparent 72%);
  mask-image: radial-gradient(circle, black 36%, transparent 72%);
  animation: sunburst-spin 14s linear infinite;
  pointer-events: none;
}

@keyframes sunburst-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.streak-stage {
  position: relative;
  width: 164px;
  height: 164px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.streak-shockwave {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 4px solid var(--duo-orange);
  animation: streak-wave 1.5s var(--ease-out) infinite;
  pointer-events: none;
}

@keyframes streak-wave {
  0% { transform: scale(0.65); opacity: 0.85; }
  100% { transform: scale(1.45); opacity: 0; }
}

.streak-ember {
  position: absolute;
  bottom: 34px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--duo-yellow);
  box-shadow: 0 0 8px var(--duo-orange);
  pointer-events: none;
  animation: ember-rise 1.4s ease-out infinite;
}

@keyframes ember-rise {
  0% { transform: translate(0, 0) scale(1); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(var(--ex, 14px), -96px) scale(0.2); opacity: 0; }
}

/* 5. Top-Bar Stat Bump, Smooth Tab Entrance & Multi-Shape Confetti */
.stat-bump {
  animation: stat-counter-bump 420ms var(--ease-bounce);
}

@keyframes stat-counter-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.tab-enter {
  animation: tab-fade-rise 220ms var(--ease-out) both;
}

@keyframes tab-fade-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.confetti-piece.shape-circle {
  border-radius: 50%;
  width: 10px;
  height: 10px;
}

.confetti-piece.shape-star {
  width: 14px;
  height: 14px;
  clip-path: polygon(50% 0%, 63% 36%, 100% 38%, 70% 60%, 81% 96%, 50% 74%, 19% 96%, 30% 60%, 0% 38%, 37% 36%);
}

/* Cloud Sync Status Pill */
.cloud-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
}

.cloud-badge.synced {
  background: var(--duo-green-soft);
  color: var(--duo-green-dark);
}

.cloud-badge.syncing {
  background: var(--duo-blue-soft);
  color: var(--duo-blue-dark);
}

.cloud-badge.offline {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.sync-code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px dashed var(--duo-blue-border);
  background: var(--duo-blue-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--duo-blue-dark);
}

/* Accessibility: Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
