/* ============================================
   CodeLevel — Animations Library
   ============================================ */

/* ---- Keyframes ---- */
@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 slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

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

@keyframes pulse {
  0%, 100% { 
    box-shadow: 0 0 0 0 var(--primary-glow);
  }
  50% { 
    box-shadow: 0 0 0 12px rgba(108, 92, 231, 0);
  }
}

@keyframes correctPulse {
  0% { transform: scale(1); }
  25% { transform: scale(1.02); }
  50% { transform: scale(0.98); }
  100% { transform: scale(1); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  10% { transform: translateX(-8px); }
  20% { transform: translateX(8px); }
  30% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  50% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  70% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.95);
  }
  100% {
    transform: scale(1);
  }
}

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

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

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes xpFloat {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-60px) scale(1.2);
  }
}

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

@keyframes heartBeat {
  0% { transform: scale(1); }
  14% { transform: scale(1.3); }
  28% { transform: scale(1); }
  42% { transform: scale(1.3); }
  70% { transform: scale(1); }
}

@keyframes streakFire {
  0%, 100% { 
    text-shadow: 0 0 10px rgba(255, 154, 0, 0.5);
    transform: scale(1);
  }
  50% { 
    text-shadow: 0 0 20px rgba(255, 107, 0, 0.8);
    transform: scale(1.1);
  }
}

@keyframes typewriter {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes blink {
  50% { border-color: transparent; }
}

@keyframes progressFill {
  from { width: 0; }
}

@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

@keyframes levelUp {
  0% {
    transform: scale(0.5) rotate(-10deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(5deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

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

/* ---- Animation Utility Classes ---- */
.animate-fadeIn { animation: fadeIn 0.3s ease; }
.animate-slideUp { animation: slideUp 0.4s ease; }
.animate-slideDown { animation: slideDown 0.4s ease; }
.animate-slideInRight { animation: slideInRight 0.4s ease; }
.animate-slideInLeft { animation: slideInLeft 0.4s ease; }
.animate-scaleIn { animation: scaleIn 0.3s ease; }
.animate-bounceIn { animation: bounceIn 0.6s ease; }
.animate-float { animation: float 3s ease-in-out infinite; }
.animate-spin { animation: spin 1s linear infinite; }
.animate-pulse { animation: pulse 2s infinite; }
.animate-heartBeat { animation: heartBeat 1.3s ease infinite; }
.animate-streakFire { animation: streakFire 1.5s ease-in-out infinite; }

/* Stagger children */
.stagger-children > * {
  opacity: 0;
  animation: slideUp 0.4s ease forwards;
}

.stagger-children > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-children > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-children > *:nth-child(8) { animation-delay: 0.4s; }
.stagger-children > *:nth-child(9) { animation-delay: 0.45s; }
.stagger-children > *:nth-child(10) { animation-delay: 0.5s; }

/* ---- Transition Helpers ---- */
.transition-all {
  transition: all var(--transition-normal);
}

.transition-fast {
  transition: all var(--transition-fast);
}

.transition-spring {
  transition: all var(--transition-spring);
}

/* ---- Hover Effects ---- */
.hover-lift {
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

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

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

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

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

/* ---- XP Float Animation (in-game) ---- */
.xp-popup {
  position: fixed;
  font-size: var(--fs-lg);
  font-weight: var(--fw-extrabold);
  color: var(--warning);
  pointer-events: none;
  animation: xpFloat 1.2s ease forwards;
  z-index: var(--z-toast);
  text-shadow: 0 0 10px rgba(253, 203, 110, 0.5);
}

/* ---- Confetti Particles ---- */
.confetti-particle {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  pointer-events: none;
  z-index: var(--z-toast);
  animation: confetti 1.5s ease forwards;
}

/* ---- Loading Spinner ---- */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ---- Skeleton Loading ---- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: gradientShift 1.5s ease infinite;
  border-radius: var(--radius-md);
}

.skeleton-text {
  height: 16px;
  margin-bottom: var(--space-sm);
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: var(--space-md);
}

.skeleton-circle {
  border-radius: 50%;
}

/* ---- Ripple Effect ---- */
.ripple-effect {
  position: relative;
  overflow: hidden;
}

.ripple-effect .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(0);
  animation: ripple 0.6s linear;
  pointer-events: none;
}

/* ---- Level Up Celebration ---- */
.level-up-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.level-up-content {
  text-align: center;
  animation: levelUp 0.6s ease;
}

.level-up-badge {
  font-size: 5rem;
  margin-bottom: var(--space-lg);
  animation: float 2s ease-in-out infinite;
}

.level-up-text {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-extrabold);
  background: linear-gradient(135deg, var(--warning), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-md);
}

.level-up-subtitle {
  font-size: var(--fs-lg);
  color: var(--text-secondary);
}
