/* Dynamic Animations & Motion FX */

/* Animal Sprint Off-Screen and Fetch Return */
@keyframes sprintOffScreen {
  0% {
    transform: translateX(0) scaleX(1);
    opacity: 1;
  }
  30% {
    transform: translateX(30px) scaleX(1.1) rotate(5deg);
  }
  60% {
    transform: translateX(600px) scaleX(1.3);
    opacity: 0.8;
  }
  100% {
    transform: translateX(1200px) scaleX(1.5);
    opacity: 0;
  }
}

@keyframes sprintReturnScreen {
  0% {
    transform: translateX(-1000px) scaleX(-1.3);
    opacity: 0;
  }
  60% {
    transform: translateX(20px) scaleX(-1.1) rotate(-5deg);
    opacity: 1;
  }
  80% {
    transform: translateX(-10px) scaleX(1);
  }
  100% {
    transform: translateX(0) scaleX(1);
    opacity: 1;
  }
}

.anim-sprint-off {
  animation: sprintOffScreen 0.7s forwards ease-in;
}

.anim-sprint-return {
  animation: sprintReturnScreen 0.8s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Mechanical Tool Operator Drop-in */
@keyframes toolDropIn {
  0% {
    transform: translateY(-80px) rotate(-20deg) scale(0.4);
    opacity: 0;
  }
  70% {
    transform: translateY(8px) rotate(5deg) scale(1.1);
    opacity: 1;
  }
  100% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 1;
  }
}

/* Error Shake Animation for Incorrect Digit Placements */
@keyframes digitShake {
  0%, 100% {
    transform: translateX(0);
  }
  15%, 45%, 75% {
    transform: translateX(-10px) rotate(-4deg);
    border-color: var(--error-coral);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.8);
  }
  30%, 60%, 90% {
    transform: translateX(10px) rotate(4deg);
    border-color: var(--error-coral);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.8);
  }
}

.anim-shake {
  animation: digitShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* Victory Screen / Round Cleared Modal */
.victory-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(14px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.3s ease;
}

.victory-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.victory-card {
  max-width: 500px;
  width: 100%;
  background: var(--bg-card-elevated);
  border: 3px solid var(--lego-green);
  border-radius: var(--radius-xl);
  padding: 36px 28px;
  text-align: center;
  box-shadow: 0 0 60px var(--lego-green-glow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: victoryPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes victoryPop {
  0% {
    transform: scale(0.5) translateY(50px);
    opacity: 0;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.victory-card h2 {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--lego-green-bright);
}

.victory-stats-summary {
  display: flex;
  gap: 16px;
  justify-content: center;
  width: 100%;
}

.victory-stat-box {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.victory-stat-box .label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.victory-stat-box .val {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-white);
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 150;
}

/* ==========================================================================
   Celestial Moon & Rocket Flight to the Moon Victory System
   ========================================================================== */

/* Glowing Moon in Top-Left Corner */
.celestial-moon-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: radial-gradient(circle at 35% 35%, rgba(255, 235, 150, 0.15), rgba(15, 23, 42, 0.7) 70%);
  border: 1.5px solid rgba(255, 215, 0, 0.4);
  border-radius: var(--radius-full);
  padding: 4px 12px 4px 6px;
  box-shadow: 0 0 18px rgba(255, 215, 0, 0.25), inset 0 0 10px rgba(255, 215, 0, 0.15);
  animation: moonGlowPulse 4s ease-in-out infinite;
  user-select: none;
  position: relative;
  z-index: 10;
}

.moon-orb {
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFFDE0 0%, #FFE680 40%, #E6B800 80%, #997A00 100%);
  box-shadow: 0 0 15px #FFD700, 0 0 30px rgba(255, 215, 0, 0.6);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.moon-crater-1 {
  position: absolute;
  top: 8px;
  left: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(184, 134, 11, 0.35);
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.moon-crater-2 {
  position: absolute;
  bottom: 10px;
  right: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(184, 134, 11, 0.35);
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.4);
}

.moon-crater-3 {
  position: absolute;
  top: 18px;
  right: 14px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(184, 134, 11, 0.3);
  box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.4);
}

.moon-label {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #FFE680;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.moon-label .sub {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-weight: 600;
}

@keyframes moonGlowPulse {
  0%, 100% {
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.25), inset 0 0 10px rgba(255, 215, 0, 0.15);
    border-color: rgba(255, 215, 0, 0.4);
  }
  50% {
    box-shadow: 0 0 28px rgba(255, 215, 0, 0.55), inset 0 0 16px rgba(255, 215, 0, 0.3);
    border-color: #FFD700;
  }
}

/* Flying LEGO Rocket Ship */
.flying-rocket-ship {
  position: fixed;
  z-index: 180;
  pointer-events: none;
  width: 72px;
  height: 110px;
  margin-left: -36px;
  margin-top: -55px;
  transform-origin: center center;
  transition: transform 1.6s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.3s ease;
  filter: drop-shadow(0 10px 25px rgba(0, 0, 0, 0.8));
}

.rocket-body-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

.rocket-svg-layer {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

/* Bubble Cockpit containing the animal passenger */
.rocket-passenger-bubble {
  position: absolute;
  top: 32px;
  left: 50%;
  transform: translateX(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.8), rgba(0, 210, 255, 0.4) 60%, rgba(0, 85, 191, 0.3) 100%);
  border: 2px solid #FFFFFF;
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.8), inset 0 0 6px rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 5;
}

.rocket-passenger-bubble svg {
  width: 85%;
  height: 85%;
  max-width: 85%;
  max-height: 85%;
  display: block;
}

/* Animated Rocket Exhaust Flame */
.rocket-flame-exhaust {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 36px;
  background: radial-gradient(ellipse at top, #FFFFFF 0%, #FFF066 25%, #FF8800 65%, #FF2200 90%, transparent 100%);
  border-radius: 50% 50% 60% 60%;
  filter: drop-shadow(0 0 14px #FF8800);
  animation: rocketFlameThrust 0.12s infinite alternate;
  z-index: 2;
}

@keyframes rocketFlameThrust {
  0% {
    transform: translateX(-50%) scaleY(0.85) scaleX(0.9);
    filter: drop-shadow(0 0 10px #FF8800);
  }
  100% {
    transform: translateX(-50%) scaleY(1.25) scaleX(1.1);
    filter: drop-shadow(0 0 22px #FF2200) drop-shadow(0 0 35px #FFD700);
  }
}

/* Starburst Flash upon Moon Touchdown */
.moon-touchdown-burst {
  position: fixed;
  z-index: 185;
  pointer-events: none;
  width: 140px;
  height: 140px;
  margin-left: -70px;
  margin-top: -70px;
  border-radius: 50%;
  background: radial-gradient(circle, #FFFFFF 15%, #FFE680 40%, #00D2FF 70%, transparent 85%);
  animation: touchdownFlash 0.8s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

@keyframes touchdownFlash {
  0% {
    transform: scale(0.2);
    opacity: 1;
  }
  50% {
    transform: scale(1.4);
    opacity: 0.9;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

/* Companion Hop Animation */
.anim-hop-into-rocket {
  animation: hopUpScale 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes hopUpScale {
  0% {
    transform: scale(1) translateY(0);
  }
  50% {
    transform: scale(1.25) translateY(-35px);
  }
  100% {
    transform: scale(0.4) translateY(-15px);
    opacity: 0.2;
  }
}

/* Lifelike SVG Animal Eye Blinking (2x Faster Speed) */
.animal-eyes,
.animal-eye {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transition: transform 0.038s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

.animal-eyes.is-blinking,
.animal-eye.is-blinking {
  transform: scaleY(0.06) !important;
}

