/* ============================================================
   ABRAJ RUNNERS - animations.css
   Shared animation keyframes & utility animation classes
   ============================================================ */

/* ── @keyframes: bobble ───────────────────────────────────── */
/* Subtle head-bob for runner avatars */
@keyframes bobble {
  0%   { transform: translateY(0)   rotate(0deg)   scale(1); }
  20%  { transform: translateY(-5px) rotate(-3deg) scale(1.04); }
  40%  { transform: translateY(-8px) rotate(3deg)  scale(1.06); }
  60%  { transform: translateY(-5px) rotate(-2deg) scale(1.04); }
  80%  { transform: translateY(-2px) rotate(1deg)  scale(1.01); }
  100% { transform: translateY(0)   rotate(0deg)   scale(1); }
}

/* ── @keyframes: bobble-idle ──────────────────────────────── */
/* Very subtle breathing for idle state */
@keyframes bobble-idle {
  0%, 100% { transform: translateY(0)    scale(1); }
  50%       { transform: translateY(-2px) scale(1.015); }
}

/* ── @keyframes: streak-pulse ─────────────────────────────── */
/* Scale throb for active streak counter */
@keyframes streak-pulse {
  0%, 100% { transform: scale(1);    opacity: 1; }
  40%       { transform: scale(1.12); opacity: .9; }
  70%       { transform: scale(1.06); opacity: .95; }
}

/* ── @keyframes: medal-shine ──────────────────────────────── */
/* Shimmer sweep across medal surface */
@keyframes medal-shine {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}

/* ── @keyframes: confetti-fall ────────────────────────────── */
/* Realistic falling + swaying */
@keyframes confetti-fall {
  0%   { transform: translateY(-24px) translateX(0)    rotate(0deg)   scaleX(1);    opacity: 1; }
  15%  { transform: translateY(15vh)  translateX(12px)  rotate(70deg)  scaleX(.85); }
  30%  { transform: translateY(30vh)  translateX(-10px) rotate(140deg) scaleX(1.1); }
  45%  { transform: translateY(45vh)  translateX(15px)  rotate(210deg) scaleX(.9);  opacity: .9; }
  60%  { transform: translateY(60vh)  translateX(-8px)  rotate(280deg) scaleX(1);   }
  75%  { transform: translateY(75vh)  translateX(10px)  rotate(340deg) scaleX(.95); opacity: .75; }
  90%  { transform: translateY(90vh)  translateX(-5px)  rotate(380deg) scaleX(1.05); opacity: .4; }
  100% { transform: translateY(110vh) translateX(0)    rotate(420deg) scaleX(1);    opacity: 0; }
}

/* ── @keyframes: glow-pulse ───────────────────────────────── */
/* Box-shadow intensity pulse (generic glow) */
@keyframes glow-pulse {
  0%, 100% {
    box-shadow:
      0 0  8px rgba(99,102,241,.4),
      0 0 16px rgba(99,102,241,.2);
  }
  50% {
    box-shadow:
      0 0 16px rgba(99,102,241,.7),
      0 0 32px rgba(99,102,241,.4),
      0 0 48px rgba(99,102,241,.15);
  }
}

/* ── @keyframes: slide-in ─────────────────────────────────── */
/* Cards appearing from below */
@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(28px) scale(.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── @keyframes: bounce-in ────────────────────────────────── */
/* Elastic entrance for new data / highlights */
@keyframes bounce-in {
  0%   { opacity: 0; transform: scale(.5)   translateY(20px); }
  55%  { opacity: 1; transform: scale(1.15) translateY(-8px); }
  70%  {             transform: scale(.95)  translateY(4px); }
  80%  {             transform: scale(1.05) translateY(-2px); }
  90%  {             transform: scale(.98)  translateY(1px); }
  100% {             transform: scale(1)    translateY(0); }
}

/* ── @keyframes: shake ────────────────────────────────────── */
/* Bench / warning state agitation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%       { transform: translateX(-6px) rotate(-1deg); }
  20%       { transform: translateX(6px)  rotate(1deg); }
  30%       { transform: translateX(-5px) rotate(-1deg); }
  40%       { transform: translateX(5px)  rotate(.5deg); }
  50%       { transform: translateX(-4px); }
  60%       { transform: translateX(4px); }
  70%       { transform: translateX(-2px); }
  80%       { transform: translateX(2px); }
  90%       { transform: translateX(-1px); }
}

/* ── @keyframes: fire-flicker ─────────────────────────────── */
/* Color-shift for streak fire icon */
@keyframes fire-flicker {
  0%   { color: #FF9A56; filter: drop-shadow(0 0 4px rgba(255,154,86,.7)); }
  25%  { color: #ef4444; filter: drop-shadow(0 0 6px rgba(239,68,68,.8));  }
  50%  { color: #FBBF24; filter: drop-shadow(0 0 5px rgba(251,191,36,.9)); }
  75%  { color: #FF6B35; filter: drop-shadow(0 0 7px rgba(255,107,53,.8)); }
  100% { color: #FF9A56; filter: drop-shadow(0 0 4px rgba(255,154,86,.7)); }
}

/* ── @keyframes: float ────────────────────────────────────── */
/* Gentle floating for decorative elements */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}

/* ── @keyframes: spin-slow ────────────────────────────────── */
/* Slow continuous rotation (badges, decorations) */
@keyframes spin-slow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ── @keyframes: pop ──────────────────────────────────────── */
/* Quick pop for new achievement or milestone */
@keyframes pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.25); }
  70%  { transform: scale(.92); }
  100% { transform: scale(1); }
}

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

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

/* ── @keyframes: number-count ─────────────────────────────── */
/* Used with JS counter — just a color flash */
@keyframes number-count {
  0%, 100% { color: inherit; }
  50%       { color: #FFD700; text-shadow: 0 0 12px rgba(255,215,0,.6); }
}

/* ── @keyframes: rainbow-border-spin ─────────────────────── */
@keyframes rainbow-border-spin {
  0%   { background-position: 0%   50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0%   50%; }
}

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

/* ── .bobblehead ──────────────────────────────────────────── */
/* Default: subtle idle breathing */
.bobblehead {
  animation: bobble-idle 3s ease-in-out infinite;
  transform-origin: bottom center;
}

/* On hover: full bobble */
.bobblehead:hover,
.runner-card:hover .bobblehead {
  animation: bobble .6s ease-in-out;
}

/* ── .animated-in ─────────────────────────────────────────── */
/* Staggered entrance for card grids */
.animated-in {
  animation: slide-in .45s ease both;
}

.animated-in:nth-child(1)  { animation-delay: .00s; }
.animated-in:nth-child(2)  { animation-delay: .06s; }
.animated-in:nth-child(3)  { animation-delay: .12s; }
.animated-in:nth-child(4)  { animation-delay: .18s; }
.animated-in:nth-child(5)  { animation-delay: .24s; }
.animated-in:nth-child(6)  { animation-delay: .30s; }
.animated-in:nth-child(7)  { animation-delay: .36s; }
.animated-in:nth-child(8)  { animation-delay: .42s; }
.animated-in:nth-child(9)  { animation-delay: .48s; }
.animated-in:nth-child(10) { animation-delay: .54s; }
.animated-in:nth-child(n+11) { animation-delay: .60s; }

/* ── .bounce-enter ────────────────────────────────────────── */
/* Single elastic bounce in */
.bounce-enter {
  animation: bounce-in .55s cubic-bezier(.36,.07,.19,.97) both;
}

/* ── .streak-active ───────────────────────────────────────── */
/* Applied to streak counter when streak > 0 */
.streak-active {
  animation: streak-pulse 1.4s ease-in-out infinite;
}

/* ── .streak-fire-active ──────────────────────────────────── */
/* Applied to fire icon */
.streak-fire-active,
.streak-active .streak-fire {
  animation: fire-flicker .6s ease-in-out infinite alternate;
}

/* ── .medal-earned ────────────────────────────────────────── */
/* Shimmer sweep on medal */
.medal-earned {
  background-size: 200% auto;
  animation: medal-shine 2.2s linear infinite;
}

/* ── .medal-earned-pop ────────────────────────────────────── */
/* One-shot pop on medal earn */
.medal-earned-pop {
  animation: pop .4s cubic-bezier(.36,.07,.19,.97) both;
}

/* ── .just-benched ────────────────────────────────────────── */
/* Shake animation for newly benched runner */
.just-benched {
  animation: shake .5s ease-in-out;
}

/* ── .glow-active ─────────────────────────────────────────── */
.glow-active {
  animation: glow-pulse 2s ease-in-out infinite;
}

/* ── .float-anim ──────────────────────────────────────────── */
.float-anim {
  animation: float 3.5s ease-in-out infinite;
}

/* ── .spin-slow-anim ──────────────────────────────────────── */
.spin-slow-anim {
  animation: spin-slow 8s linear infinite;
}

/* ── .fade-in ─────────────────────────────────────────────── */
.fade-in  { animation: fadeIn  .3s ease forwards; }
.fade-out { animation: fadeOut .3s ease forwards; }

/* ── Confetti pieces ──────────────────────────────────────── */
.confetti-piece {
  animation: confetti-fall var(--fall-duration, 3s) ease-in var(--fall-delay, 0s) infinite;
}

/* Variety of sizes */
.confetti-piece:nth-child(odd)  { width: 8px;  height: 8px; }
.confetti-piece:nth-child(even) { width: 12px; height: 5px; }
.confetti-piece:nth-child(3n)   { width: 6px;  height: 14px; border-radius: 50%; }
.confetti-piece:nth-child(5n)   { width: 14px; height: 4px; }

/* Position spread */
.confetti-piece:nth-child(1)  { left:  3%; --fall-duration: 3.2s; --fall-delay: 0.0s; }
.confetti-piece:nth-child(2)  { left:  9%; --fall-duration: 2.8s; --fall-delay: 0.4s; }
.confetti-piece:nth-child(3)  { left: 15%; --fall-duration: 3.6s; --fall-delay: 0.8s; }
.confetti-piece:nth-child(4)  { left: 22%; --fall-duration: 2.5s; --fall-delay: 0.2s; }
.confetti-piece:nth-child(5)  { left: 29%; --fall-duration: 3.1s; --fall-delay: 1.0s; }
.confetti-piece:nth-child(6)  { left: 36%; --fall-duration: 2.9s; --fall-delay: 0.6s; }
.confetti-piece:nth-child(7)  { left: 44%; --fall-duration: 3.4s; --fall-delay: 0.3s; }
.confetti-piece:nth-child(8)  { left: 52%; --fall-duration: 2.7s; --fall-delay: 0.9s; }
.confetti-piece:nth-child(9)  { left: 60%; --fall-duration: 3.0s; --fall-delay: 0.5s; }
.confetti-piece:nth-child(10) { left: 68%; --fall-duration: 3.3s; --fall-delay: 0.1s; }
.confetti-piece:nth-child(11) { left: 75%; --fall-duration: 2.6s; --fall-delay: 0.7s; }
.confetti-piece:nth-child(12) { left: 82%; --fall-duration: 3.5s; --fall-delay: 1.1s; }
.confetti-piece:nth-child(13) { left: 89%; --fall-duration: 2.8s; --fall-delay: 0.4s; }
.confetti-piece:nth-child(14) { left: 95%; --fall-duration: 3.2s; --fall-delay: 0.8s; }

/* ============================================================
   BENCH SPEECH BUBBLES
   ============================================================ */

.bench-bubble {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: rgba(0,0,0,.75);
  color: #fff;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: .65rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 5;
}

.bench-bubble.visible {
  opacity: 1;
}

.bench-bubble::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid rgba(0,0,0,.75);
}

/* Floating Zzz */
.bench-zzz {
  position: absolute;
  top: 10px;
  right: -5px;
  font-size: .7rem;
  opacity: 0;
  animation: float-zzz 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes float-zzz {
  0%   { opacity: 0; transform: translateY(0) scale(.8); }
  20%  { opacity: .7; }
  80%  { opacity: .3; transform: translateY(-20px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-30px) scale(.6); }
}

/* ============================================================
   REDUCED MOTION — ACCESSIBILITY
   Disable all animations for users who prefer it
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration:        0.01ms !important;
    animation-iteration-count: 1      !important;
    transition-duration:       0.01ms !important;
    scroll-behavior:           auto   !important;
  }

  .bobblehead,
  .bobblehead:hover,
  .runner-card:hover .bobblehead {
    animation: none !important;
  }

  .animated-in {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .streak-active,
  .streak-fire-active,
  .streak-active .streak-fire {
    animation: none !important;
  }

  .medal-earned,
  .medal-earned-pop {
    animation: none !important;
  }

  .just-benched {
    animation: none !important;
  }

  .glow-active,
  .float-anim,
  .spin-slow-anim,
  .bounce-enter,
  .fade-in,
  .fade-out {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .confetti-piece {
    display: none !important;
  }

  /* Keep transition states but instant */
  .runner-card:hover,
  .admin-card:hover,
  .btn:hover {
    transition: none !important;
  }
}
