/**
 * Amount Celebration Animations
 *
 * Playful animations for when users tally receipts and return to the homepage.
 * Includes count-up, scale, glow, sparkles, and confetti effects.
 * Optimized for 60fps with GPU-accelerated properties.
 */

/* ==========================================================================
   Scale Animation (using exponential easing for natural feel)
   ========================================================================== */
.amount-celebration-bounce {
  animation: celebration-scale 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

@keyframes celebration-scale {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

/* ==========================================================================
   Glow Pulse Animation (optimized without filter)
   ========================================================================== */
.amount-celebration-glow {
  animation: celebration-glow 1.2s ease-out;
  will-change: text-shadow;
}

@keyframes celebration-glow {
  0% {
    text-shadow: 0 0 0 transparent;
    color: rgb(22, 163, 74);
  }
  15% {
    text-shadow:
      0 0 20px rgba(34, 197, 94, 0.6),
      0 0 30px rgba(34, 197, 94, 0.4);
    color: rgb(21, 128, 61);
  }
  100% {
    text-shadow: 0 0 0 transparent;
    color: rgb(22, 163, 74);
  }
}

/* ==========================================================================
   Sparkle Particles (GPU-accelerated)
   ========================================================================== */
.amount-sparkle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: radial-gradient(circle, #22c55e 0%, #4ade80 50%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
  animation: sparkle-burst 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: var(--sparkle-delay, 0ms);
  opacity: 0;
  transform: translate(0, 0) scale(0);
  will-change: transform, opacity;
}

@keyframes sparkle-burst {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0);
  }
  20% {
    opacity: 1;
    transform: translate(
      calc(var(--sparkle-x, 0px) * 0.3),
      calc(var(--sparkle-y, 0px) * 0.3)
    ) scale(calc(var(--sparkle-scale, 1) * 1.4));
  }
  100% {
    opacity: 0;
    transform: translate(
      var(--sparkle-x, 0px),
      var(--sparkle-y, 0px)
    ) scale(0);
  }
}

/* Star-shaped sparkles for variety */
.amount-sparkle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 12px;
  background: linear-gradient(to bottom, transparent, #fbbf24, transparent);
  transform: translate(-50%, -50%);
  border-radius: 1px;
}

.amount-sparkle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 2px;
  background: linear-gradient(to right, transparent, #fbbf24, transparent);
  transform: translate(-50%, -50%);
  border-radius: 1px;
}

/* ==========================================================================
   Confetti Particles (for larger amounts)
   ========================================================================== */
.amount-confetti {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  background: var(--confetti-color, #22c55e);
  pointer-events: none;
  animation: confetti-fall 1.2s ease-out forwards;
  animation-delay: var(--confetti-delay, 0ms);
  opacity: 0;
  border-radius: 2px;
}

.amount-confetti:nth-child(even) {
  width: 8px;
  height: 6px;
  border-radius: 50%;
}

.amount-confetti:nth-child(3n) {
  width: 6px;
  height: 10px;
}

@keyframes confetti-fall {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(0deg) scale(0);
  }
  10% {
    opacity: 1;
    transform: translate(0, -20px) rotate(45deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(
      var(--confetti-x, 0px),
      80px
    ) rotate(var(--confetti-rotation, 360deg)) scale(0.5);
  }
}

/* ==========================================================================
   Year Dot Pending Animation
   Pulsing indicator when there's a pending animation for a different year
   ========================================================================== */
.year-dot-pending-animation {
  animation: year-dot-pulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
}

@keyframes year-dot-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    background-color: #22c55e;
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    background-color: #4ade80;
    transform: scale(1.2);
  }
}

/* ==========================================================================
   Celebration Container
   Provides positioning context for sparkles and confetti
   ========================================================================== */
.celebration-container {
  position: relative;
  display: inline-block;
}

/* ==========================================================================
   Amount Increase Indicator
   Shows a +$XX.XX badge that floats up
   ========================================================================== */
.amount-increase-badge {
  position: absolute;
  top: -10px;
  right: -20px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #16a34a;
  animation: float-up-fade 1.5s ease-out forwards;
  pointer-events: none;
  white-space: nowrap;
}

@keyframes float-up-fade {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  20% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
    transform: translateY(-20px);
  }
  100% {
    opacity: 0;
    transform: translateY(-30px);
  }
}

/* ==========================================================================
   Year Update Hint Animation
   Pulsing hint when expense was tallied for a different year
   ========================================================================== */
.year-update-hint {
  animation: hint-pulse 2s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% {
    opacity: 0.8;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.02);
  }
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */
@media (max-width: 640px) {
  .amount-sparkle {
    width: 6px;
    height: 6px;
  }

  .amount-confetti {
    width: 8px;
    height: 8px;
  }

  @keyframes celebration-bounce {
    0% {
      transform: scale(1);
    }
    30% {
      transform: scale(1.1);
    }
    50% {
      transform: scale(0.97);
    }
    70% {
      transform: scale(1.03);
    }
    100% {
      transform: scale(1);
    }
  }
}

/* ==========================================================================
   Reduced Motion Support
   Respects user preference for reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .amount-celebration-bounce,
  .amount-celebration-glow,
  .amount-sparkle,
  .amount-confetti,
  .year-dot-pending-animation,
  .amount-increase-badge,
  .year-update-hint {
    animation: none;
  }

  .amount-celebration-glow {
    text-shadow:
      0 0 10px rgba(34, 197, 94, 0.6),
      0 0 20px rgba(34, 197, 94, 0.4);
    transition: text-shadow 0.3s ease;
  }

  .year-dot-pending-animation {
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.5);
    background-color: #22c55e;
  }
}
