/* ===================================================
   LinguaQuest — Animations CSS
   Keyframes, transitions, and animation utilities
   =================================================== */

/* --- ENTRANCE ANIMATIONS (triggered by .animate-in via IntersectionObserver) --- */
.animate-in {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.animate-in.visible {
  opacity: 1;
  transform: translateY(0);
}

.animate-fade-in {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.animate-fade-in.visible { opacity: 1; }

.animate-scale-in {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.animate-scale-in.visible {
  opacity: 1;
  transform: scale(1);
}

.animate-slide-left {
  opacity: 0;
  transform: translateX(-32px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.animate-slide-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.animate-slide-right {
  opacity: 0;
  transform: translateX(32px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.animate-slide-right.visible {
  opacity: 1;
  transform: translateX(0);
}

/* Stagger children */
.stagger-children > *:nth-child(1) { transition-delay: 0ms; }
.stagger-children > *:nth-child(2) { transition-delay: 100ms; }
.stagger-children > *:nth-child(3) { transition-delay: 200ms; }
.stagger-children > *:nth-child(4) { transition-delay: 300ms; }
.stagger-children > *:nth-child(5) { transition-delay: 400ms; }
.stagger-children > *:nth-child(6) { transition-delay: 500ms; }
.stagger-children > *:nth-child(7) { transition-delay: 600ms; }
.stagger-children > *:nth-child(8) { transition-delay: 700ms; }

/* --- HOVER EFFECTS --- */
.hover-lift {
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.hover-scale {
  transition: transform var(--transition-base);
}

.hover-scale:hover {
  transform: scale(1.02);
}

.hover-glow {
  transition: box-shadow var(--transition-base);
}

.hover-glow:hover {
  box-shadow: 0 0 0 4px rgba(98, 182, 203, 0.25),
              0 4px 20px rgba(98, 182, 203, 0.2);
}

/* --- QUIZ-SPECIFIC ANIMATIONS --- */
@keyframes correct-flash {
  0% { box-shadow: 0 0 0 0 rgba(45, 106, 79, 0.5); }
  50% { box-shadow: 0 0 0 12px rgba(45, 106, 79, 0); transform: scale(1.03); }
  100% { box-shadow: 0 0 0 0 rgba(45, 106, 79, 0); transform: scale(1); }
}

@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-8px); box-shadow: 0 0 0 0 rgba(193, 18, 31, 0.4); }
  30% { transform: translateX(8px); }
  45% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
  90% { transform: translateX(3px); }
}

.option-correct {
  animation: correct-flash 0.4s ease forwards;
}

.option-wrong {
  animation: wrong-shake 0.5s ease forwards;
}

/* Score counter animation */
@keyframes score-count {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

.score-count-up {
  animation: score-count 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Timer warning pulse */
@keyframes timer-warning-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.timer-warning {
  animation: timer-warning-pulse 0.8s ease-in-out infinite;
}

/* Option reveal stagger */
@keyframes option-appear {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.option-reveal-1 { animation: option-appear 0.3s ease forwards; animation-delay: 0ms; opacity: 0; }
.option-reveal-2 { animation: option-appear 0.3s ease forwards; animation-delay: 75ms; opacity: 0; }
.option-reveal-3 { animation: option-appear 0.3s ease forwards; animation-delay: 150ms; opacity: 0; }
.option-reveal-4 { animation: option-appear 0.3s ease forwards; animation-delay: 225ms; opacity: 0; }

/* Result screen animations */
@keyframes result-reveal {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

.result-reveal {
  animation: result-reveal 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes score-fill {
  from { stroke-dashoffset: 502; }
}

.score-fill-animate {
  animation: score-fill 1.5s ease-out forwards;
}

/* --- CULTURAL ANIMATIONS --- */

/* Sakura (Cherry Blossom) falling — Japanese theme */
@keyframes sakura-fall-1 {
  0% {
    transform: translate(0, -20px) rotate(0deg);
    opacity: 0;
  }
  5% { opacity: 0.9; }
  90% { opacity: 0.7; }
  100% {
    transform: translate(60px, 110vh) rotate(360deg);
    opacity: 0;
  }
}

@keyframes sakura-fall-2 {
  0% {
    transform: translate(0, -20px) rotate(0deg);
    opacity: 0;
  }
  5% { opacity: 0.8; }
  90% { opacity: 0.5; }
  100% {
    transform: translate(-80px, 110vh) rotate(-270deg);
    opacity: 0;
  }
}

@keyframes sakura-fall-3 {
  0% {
    transform: translate(0, -20px) rotate(45deg);
    opacity: 0;
  }
  8% { opacity: 0.85; }
  85% { opacity: 0.6; }
  100% {
    transform: translate(40px, 110vh) rotate(420deg);
    opacity: 0;
  }
}

@keyframes sakura-fall-4 {
  0% {
    transform: translate(0, -20px) rotate(-20deg);
    opacity: 0;
  }
  6% { opacity: 0.75; }
  95% { opacity: 0.4; }
  100% {
    transform: translate(-50px, 110vh) rotate(-320deg);
    opacity: 0;
  }
}

.sakura-petal {
  position: fixed;
  top: -20px;
  width: 14px;
  height: 14px;
  pointer-events: none;
  z-index: 50;
}

.sakura-petal svg {
  width: 100%;
  height: 100%;
}

.sakura-petal:nth-child(1) { left: 15%; animation: sakura-fall-1 8s linear infinite; animation-delay: 0s; }
.sakura-petal:nth-child(2) { left: 45%; animation: sakura-fall-2 10s linear infinite; animation-delay: 2s; }
.sakura-petal:nth-child(3) { left: 70%; animation: sakura-fall-3 7s linear infinite; animation-delay: 5s; }
.sakura-petal:nth-child(4) { left: 85%; animation: sakura-fall-4 9s linear infinite; animation-delay: 3s; }

/* Lantern sway — Korean/Chinese theme */
@keyframes lantern-sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

.lantern-sway {
  transform-origin: top center;
  animation: lantern-sway 4s ease-in-out infinite;
}

/* Ink brush stroke reveal */
@keyframes ink-draw {
  from { stroke-dashoffset: 1000; }
  to { stroke-dashoffset: 0; }
}

.ink-draw {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: ink-draw 1.5s ease-out forwards;
}

/* Wave pattern subtle movement */
@keyframes wave-drift {
  0%, 100% { background-position: 0 0; }
  50% { background-position: 40px 20px; }
}

.wave-pattern-animate {
  animation: wave-drift 12s ease-in-out infinite;
}

/* --- LOADING + SKELETON --- */
@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes spinner-rotate {
  to { transform: rotate(360deg); }
}

/* Floating animation (hero cards) */
@keyframes float-bob {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-12px); }
}

.float-bob {
  animation: float-bob 3s ease-in-out infinite;
}

.float-bob-delay-1 { animation-delay: 0.5s; }
.float-bob-delay-2 { animation-delay: 1s; }

/* Pulse ring */
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}

.pulse-ring::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--brand-secondary);
  animation: pulse-ring 1.5s ease-out infinite;
}

/* Typewriter */
@keyframes typewriter-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--brand-primary);
  margin-left: 2px;
  animation: typewriter-cursor 0.8s step-end infinite;
  vertical-align: text-bottom;
}

/* --- UTILITY TRANSITION CLASSES --- */
.transition-fast { transition: all var(--transition-fast) !important; }
.transition-base { transition: all var(--transition-base) !important; }
.transition-slow { transition: all var(--transition-slow) !important; }
.transition-none * { transition: none !important; }

/* Page transition */
.page-enter {
  animation: page-fade-in 0.3s ease forwards;
}

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

/* Fade out */
.fade-out {
  animation: fade-out 0.3s ease forwards;
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* --- COUNTER ANIMATION (for stats) --- */
@keyframes count-up {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.count-up-animate {
  animation: count-up 0.4s ease forwards;
}

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

  .animate-in {
    opacity: 1;
    transform: none;
  }

  .animate-fade-in,
  .animate-scale-in,
  .animate-slide-left,
  .animate-slide-right {
    opacity: 1;
    transform: none;
  }

  .stagger-children > * {
    transition-delay: 0ms !important;
  }

  .sakura-petal { animation: none !important; }
  .float-bob { animation: none !important; }
  .lantern-sway { animation: none !important; }
}