/* ============================================
   ANIMATIONS — Micro-interactions & Polish
   ============================================ */

/* === BASE ANIMATIONS === */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

@keyframes popIn {
  0% { opacity: 0; transform: scale(0.8); }
  50% { transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

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

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

@keyframes progressPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
}

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

/* === HABIT-SPECIFIC ANIMATIONS === */

/* Card entrance */
@keyframes cardEnter {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  60% {
    transform: translateY(-2px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Card exit */
@keyframes cardExit {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.9) translateY(10px);
  }
}

/* Counter pop (number change) */
@keyframes counterPop {
  0% { transform: scale(1); }
  30% { transform: scale(1.3); }
  60% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Button bounce */
@keyframes btnBounce {
  0% { transform: scale(1); }
  30% { transform: scale(0.8); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Ring pulse on tap */
@keyframes ringTapPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* Glow pulse for completed habits */
@keyframes glowPulse {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.2; }
}

/* Checkmark draw */
@keyframes drawCheck {
  to { stroke-dashoffset: 0; }
}

/* Checkmark group pop */
@keyframes checkIn {
  0% { opacity: 0; transform: scale(0.5); }
  50% { transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}

/* Fire emoji flicker */
@keyframes fireFlicker {
  0% { transform: scale(1) rotate(-3deg); }
  50% { transform: scale(1.1) rotate(3deg); }
  100% { transform: scale(1) rotate(-3deg); }
}

/* Celebration shake for completed card */
@keyframes celebrateCard {
  0%, 100% { transform: translateY(0); }
  10% { transform: translateY(-3px); }
  20% { transform: translateY(0); }
  30% { transform: translateY(-2px); }
  40% { transform: translateY(0); }
}

/* Completion ring glow burst */
@keyframes ringGlowBurst {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  50% { box-shadow: 0 0 20px 10px rgba(34, 197, 94, 0.2); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Slide counter value up (outgoing) */
@keyframes counterSlideUp {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-100%); opacity: 0; }
}

/* Slide counter value in (incoming) */
@keyframes counterSlideIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

/* Stagger animation for grid items */
.stagger-in {
  animation: cardEnter 0.45s cubic-bezier(.4,0,.2,1) backwards;
}

.stagger-in:nth-child(1) { animation-delay: 0ms; }
.stagger-in:nth-child(2) { animation-delay: 60ms; }
.stagger-in:nth-child(3) { animation-delay: 120ms; }
.stagger-in:nth-child(4) { animation-delay: 180ms; }
.stagger-in:nth-child(5) { animation-delay: 240ms; }
.stagger-in:nth-child(6) { animation-delay: 300ms; }
.stagger-in:nth-child(7) { animation-delay: 360ms; }
.stagger-in:nth-child(8) { animation-delay: 420ms; }
.stagger-in:nth-child(9) { animation-delay: 480ms; }
.stagger-in:nth-child(10) { animation-delay: 540ms; }

/* Old stagger items (backwards compat) */
.stagger-item {
  animation: fadeInUp 0.4s ease backwards;
}

/* Card exit */
.habit-card-exit {
  animation: cardExit 0.3s ease forwards;
  pointer-events: none;
}

/* Counter pop */
.counter-pop {
  animation: counterPop 0.4s cubic-bezier(.4,0,.2,1);
}

/* Button bounce */
.btn-bounce {
  animation: btnBounce 0.4s cubic-bezier(.4,0,.2,1);
}

/* Ring pulse on tap */
.ring-pulse {
  animation: ringTapPulse 0.4s cubic-bezier(.4,0,.2,1);
}

/* Celebrate card */
.habit-celebrate {
  animation: celebrateCard 0.6s ease;
}

/* Just completed — ring glow */
.habit-just-completed .habit-ring-wrap {
  animation: ringGlowBurst 0.8s ease;
}

/* Completion animation */
.habit-complete-pulse {
  animation: progressPulse 0.6s ease;
}

/* General micro-interactions */
.press-scale:active {
  transform: scale(0.97);
  transition: transform 0.1s ease;
}

/* Fade enter */
.fade-enter {
  animation: fadeIn 0.2s ease;
}

.slide-up-enter {
  animation: fadeInUp 0.3s ease;
}

/* Smooth ring transition */
.habit-ring-fill {
  transition: stroke-dashoffset 0.6s cubic-bezier(.4,0,.2,1);
}

/* Ring complete filter */
.habit-ring-fill.ring-complete {
  filter: drop-shadow(0 0 6px currentColor);
  transition: stroke-dashoffset 0.6s cubic-bezier(.4,0,.2,1), filter 0.3s ease;
}

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