/**
 * Animation Library
 * Reusable animations for transitions, celebrations, and interactions
 *
 * Requires: variables.css for timing values
 */

/* ============================================
   ENTRANCE ANIMATIONS
   ============================================ */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}


/* ============================================
   INTERACTION ANIMATIONS
   ============================================ */

@keyframes glowPulse {
  0%, 100% {
    box-shadow: 0 0 5px var(--glow-color, rgba(212, 165, 116, 0.4));
  }
  50% {
    box-shadow: 0 0 20px var(--glow-color, rgba(212, 165, 116, 0.4));
  }
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes wiggle {
  0%, 100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-5deg);
  }
  75% {
    transform: rotate(5deg);
  }
}

@keyframes heartbeat {
  0%, 100% {
    transform: scale(1);
  }
  15%, 45% {
    transform: scale(1.1);
  }
  30% {
    transform: scale(1);
  }
}


/* ============================================
   LOADING ANIMATIONS
   ============================================ */

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

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes dots {
  0%, 20% {
    content: '.';
  }
  40% {
    content: '..';
  }
  60%, 100% {
    content: '...';
  }
}


/* ============================================
   CELEBRATION ANIMATIONS
   ============================================ */

@keyframes confetti {
  0% {
    transform: translateY(-100%) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

@keyframes sparkle {
  0%, 100% {
    opacity: 0;
    transform: scale(0);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes starBurst {
  0% {
    transform: scale(0) rotate(0deg);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: scale(1.5) rotate(180deg);
    opacity: 0;
  }
}

@keyframes successGlow {
  0% {
    box-shadow: 0 0 0 0 rgba(122, 158, 126, 0.7);
  }
  70% {
    box-shadow: 0 0 0 30px rgba(122, 158, 126, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(122, 158, 126, 0);
  }
}


/* ============================================
   UTILITY ANIMATION CLASSES
   ============================================ */

.animate-fade-in {
  animation: fadeIn var(--transition-slow, 300ms) ease-in;
}

.animate-slide-up {
  animation: slideUp var(--transition-slow, 300ms) ease-out;
}

.animate-slide-down {
  animation: slideDown var(--transition-slow, 300ms) ease-out;
}

.animate-scale-in {
  animation: scaleIn var(--transition-base, 200ms) ease-out;
}

.animate-glow-pulse {
  animation: glowPulse 2s ease-in-out infinite;
}

.animate-bounce {
  animation: bounce 1s ease-in-out infinite;
}

.animate-shake {
  animation: shake 0.5s ease-in-out;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

.animate-pulse {
  animation: pulse 2s ease-in-out infinite;
}

.animate-heartbeat {
  animation: heartbeat 1.5s ease-in-out infinite;
}


/* ============================================
   DELAYED ANIMATIONS
   ============================================ */

.delay-100 { animation-delay: 100ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-500 { animation-delay: 500ms; }
.delay-1000 { animation-delay: 1000ms; }


/* ============================================
   CELEBRATION COMPONENTS
   ============================================ */

/* Confetti particle */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  background-color: var(--color-accent-primary);
  animation: confetti 3s ease-out forwards;
  pointer-events: none;
  z-index: var(--z-tooltip, 500);
}

.confetti-piece:nth-child(2n) {
  background-color: var(--color-festive-red);
}

.confetti-piece:nth-child(3n) {
  background-color: var(--color-festive-green);
}

.confetti-piece:nth-child(4n) {
  background-color: var(--color-accent-secondary);
}

/* Sparkle effect */
.sparkle {
  position: absolute;
  width: 4px;
  height: 4px;
  background-color: var(--color-accent-primary);
  border-radius: 50%;
  animation: sparkle 1s ease-in-out;
  pointer-events: none;
}


/* ============================================
   GAME-SPECIFIC ANIMATIONS
   ============================================ */

/* Card flip animation */
.card-flip {
  transform-style: preserve-3d;
  transition: transform 0.6s;
}

.card-flip.flipped {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.card-back {
  transform: rotateY(180deg);
}

/* Tile match animation */
@keyframes tileMatch {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.tile-match {
  animation: tileMatch 0.3s ease-in-out;
}

/* Wrong answer shake */
.wrong-answer {
  animation: shake 0.5s ease-in-out;
}

/* Correct answer glow */
.correct-answer {
  animation: successGlow 0.8s ease-out;
}


/* ============================================
   COUNTDOWN TIMER ANIMATION
   ============================================ */

@keyframes countdownPulse {
  0%, 100% {
    transform: scale(1);
    color: var(--color-text-primary);
  }
  50% {
    transform: scale(1.05);
    color: var(--color-accent-primary);
  }
}

.countdown-urgent {
  animation: countdownPulse 1s ease-in-out infinite;
}


/* ============================================
   MODAL ANIMATIONS
   ============================================ */

.modal-enter {
  animation: modalEnter var(--transition-slow, 300ms) ease-out;
}

@keyframes modalEnter {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.overlay-enter {
  animation: fadeIn var(--transition-base, 200ms) ease-in;
}


/* ============================================
   STORY TEXT ANIMATIONS
   ============================================ */

/* Typewriter effect (optional for story text) */
@keyframes typewriter {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

.typewriter {
  overflow: hidden;
  white-space: nowrap;
  animation: typewriter 2s steps(40, end);
}

/* Text fade-in by word */
.text-reveal {
  opacity: 0;
  animation: fadeIn 0.5s ease-in forwards;
}


/* ============================================
   HOVER ANIMATIONS
   ============================================ */

.hover-lift {
  transition: transform var(--transition-base, 200ms) ease;
}

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

.hover-glow {
  transition: box-shadow var(--transition-base, 200ms) ease;
}

.hover-glow:hover {
  box-shadow: var(--glow-md, 0 0 10px rgba(212, 165, 116, 0.4));
}

.hover-scale {
  transition: transform var(--transition-base, 200ms) ease;
}

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


/* ============================================
   ACCESSIBILITY: RESPECT REDUCED MOTION
   ============================================ */

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

  /* Disable infinite animations entirely */
  .animate-glow-pulse,
  .animate-bounce,
  .animate-spin,
  .animate-pulse,
  .animate-heartbeat,
  .countdown-urgent {
    animation: none !important;
  }
}
