/* =============================================================================
   INSIGHT EDITORIAL DARK — Animations & Motion
   Ohio School Insight
   =============================================================================
   All keyframe animations, scroll reveal, transition utilities, stagger
   helpers, and reduced-motion overrides. Import last — after all other files.

   Motion philosophy: purposeful, editorial. Animation reveals hierarchy and
   guides attention; it never distracts. All durations use tokens from
   tokens.css. Reduced-motion compliance is mandatory.
   ============================================================================= */


/* =============================================================================
   SCROLL REVEAL
   JS adds .visible when element enters viewport (IntersectionObserver).
   ============================================================================= */

.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity   var(--duration-slow) var(--ease-editorial),
    transform var(--duration-slow) var(--ease-editorial);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Reveal from left */
.reveal-left {
  opacity: 0;
  transform: translateX(-24px);
  transition:
    opacity   var(--duration-slow) var(--ease-editorial),
    transform var(--duration-slow) var(--ease-editorial);
}

.reveal-left.visible {
  opacity: 1;
  transform: translateX(0);
}

/* Reveal from right */
.reveal-right {
  opacity: 0;
  transform: translateX(24px);
  transition:
    opacity   var(--duration-slow) var(--ease-editorial),
    transform var(--duration-slow) var(--ease-editorial);
}

.reveal-right.visible {
  opacity: 1;
  transform: translateX(0);
}

/* Fade only (no movement) */
.reveal-fade {
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease-editorial);
}

.reveal-fade.visible {
  opacity: 1;
}

/* Scale reveal — for stat cards and highlights */
.reveal-scale {
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity   var(--duration-slow) var(--ease-editorial),
    transform var(--duration-slow) var(--ease-spring);
}

.reveal-scale.visible {
  opacity: 1;
  transform: scale(1);
}


/* =============================================================================
   STAGGER CHILDREN
   JS sets --stagger-index on each child, or use :nth-child() for pure CSS.
   ============================================================================= */

/* Parent container — children inherit stagger timing */
.reveal-stagger > * {
  transition-delay: calc(var(--stagger-index, 0) * 100ms);
}

/* Pure CSS stagger (up to 8 items) — no JS required */
.reveal-stagger > *:nth-child(1)  { --stagger-index: 0; }
.reveal-stagger > *:nth-child(2)  { --stagger-index: 1; }
.reveal-stagger > *:nth-child(3)  { --stagger-index: 2; }
.reveal-stagger > *:nth-child(4)  { --stagger-index: 3; }
.reveal-stagger > *:nth-child(5)  { --stagger-index: 4; }
.reveal-stagger > *:nth-child(6)  { --stagger-index: 5; }
.reveal-stagger > *:nth-child(7)  { --stagger-index: 6; }
.reveal-stagger > *:nth-child(8)  { --stagger-index: 7; }

/* Fast stagger — 60ms per item */
.reveal-stagger-fast > * {
  transition-delay: calc(var(--stagger-index, 0) * 60ms);
}

/* Slow stagger — 150ms per item */
.reveal-stagger-slow > * {
  transition-delay: calc(var(--stagger-index, 0) * 150ms);
}


/* =============================================================================
   COUNT-UP ANIMATION HELPER
   JS animates the numeric value. CSS handles the number formatting only.
   ============================================================================= */

.count-up {
  /* No CSS transition — JS drives the value directly (requestAnimationFrame) */
  transition: none;
  font-variant-numeric: tabular-nums;
  display: inline-block;
}


/* =============================================================================
   SVG LINE DRAW
   Set stroke-dasharray = stroke-dashoffset = path total length in JS,
   then add .drawing class to animate to dashoffset: 0.
   ============================================================================= */

.draw-line {
  transition: stroke-dashoffset 1200ms var(--ease-editorial);
}

/* Triggered by JS after element is visible */
.draw-line.drawing {
  stroke-dashoffset: 0;
}

/* Fast line draw variant */
.draw-line-fast {
  transition: stroke-dashoffset 600ms var(--ease-editorial);
}

.draw-line-fast.drawing {
  stroke-dashoffset: 0;
}


/* =============================================================================
   KEYFRAME DEFINITIONS
   ============================================================================= */

/* ---------------------------------------------------------------------------
   Glow Pulse — for active/featured elements
   --------------------------------------------------------------------------- */

@keyframes glowPulse {
  0%,
  100% { box-shadow: 0 0 15px rgba(60, 221, 199, 0.4); }
  50%  { box-shadow: 0 0 30px rgba(60, 221, 199, 0.8); }
}

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

/* Gold glow variant */
@keyframes glowPulseGold {
  0%,
  100% { box-shadow: 0 0 12px rgba(255, 198, 64, 0.3); }
  50%  { box-shadow: 0 0 24px rgba(255, 198, 64, 0.7); }
}

.glow-pulse-gold {
  animation: glowPulseGold 2s ease-in-out infinite;
}

/* SVG drop-shadow glow (for chart dots and lines) */
@keyframes glowPulseSvg {
  0%,
  100% { filter: drop-shadow(0 0 3px rgba(60, 221, 199, 0.5)); }
  50%  { filter: drop-shadow(0 0 8px rgba(60, 221, 199, 0.9)); }
}

.glow-pulse-svg {
  animation: glowPulseSvg 2s ease-in-out infinite;
}


/* ---------------------------------------------------------------------------
   Fade Slide Up — entrance animation
   --------------------------------------------------------------------------- */

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

.fade-slide-up {
  animation: fadeSlideUp var(--duration-slow) var(--ease-editorial) forwards;
}

/* Staggered children using CSS custom property delays */
.fade-slide-up-1 { animation: fadeSlideUp var(--duration-slow) var(--ease-editorial) 0ms    forwards; }
.fade-slide-up-2 { animation: fadeSlideUp var(--duration-slow) var(--ease-editorial) 100ms  forwards; }
.fade-slide-up-3 { animation: fadeSlideUp var(--duration-slow) var(--ease-editorial) 200ms  forwards; }
.fade-slide-up-4 { animation: fadeSlideUp var(--duration-slow) var(--ease-editorial) 300ms  forwards; }
.fade-slide-up-5 { animation: fadeSlideUp var(--duration-slow) var(--ease-editorial) 400ms  forwards; }


/* ---------------------------------------------------------------------------
   Fade In (no movement)
   --------------------------------------------------------------------------- */

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

.fade-in {
  animation: fadeIn var(--duration-standard) var(--ease-editorial) forwards;
}


/* ---------------------------------------------------------------------------
   Ping — scatter dot highlight ring
   --------------------------------------------------------------------------- */

@keyframes ping {
  75%,
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

.animate-ping {
  animation: ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}

/* Slower ping for emphasis */
.animate-ping-slow {
  animation: ping 2.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}


/* ---------------------------------------------------------------------------
   Skeleton Shimmer
   --------------------------------------------------------------------------- */

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* Override .skeleton from components.css with animation */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-container)      25%,
    var(--surface-container-high) 50%,
    var(--surface-container)      75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}


/* ---------------------------------------------------------------------------
   Star Fill Stagger — left to right reveal
   --------------------------------------------------------------------------- */

@keyframes starFill {
  from {
    opacity: 0;
    transform: scale(0.5);
    color: var(--outline-variant);
  }
  60% {
    transform: scale(1.25);
  }
  to {
    opacity: 1;
    transform: scale(1);
    color: var(--secondary);
  }
}

/* Assign to each .star-filled inside .star-rating-animate */
.star-rating-animate .star-filled {
  animation: starFill 400ms var(--ease-spring) both;
}

/* Stagger each star 150ms later than previous */
.star-rating-animate .star-filled:nth-child(1) { animation-delay:   0ms; }
.star-rating-animate .star-filled:nth-child(2) { animation-delay: 150ms; }
.star-rating-animate .star-filled:nth-child(3) { animation-delay: 300ms; }
.star-rating-animate .star-filled:nth-child(4) { animation-delay: 450ms; }
.star-rating-animate .star-filled:nth-child(5) { animation-delay: 600ms; }


/* ---------------------------------------------------------------------------
   Donut Slice Entrance — rotation + fade
   --------------------------------------------------------------------------- */

@keyframes donutSliceFill {
  from {
    opacity: 0;
    transform: rotate(-90deg) scale(0.92);
  }
  to {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
}

/* Add .donut-animate to the <g> wrapping your donut slices */
.donut-animate .donut-slice {
  transform-origin: center;
  animation: donutSliceFill 700ms var(--ease-decelerate) forwards;
}

/* Stagger each slice */
.donut-animate .donut-slice:nth-child(1) { animation-delay:   0ms; }
.donut-animate .donut-slice:nth-child(2) { animation-delay: 100ms; }
.donut-animate .donut-slice:nth-child(3) { animation-delay: 200ms; }
.donut-animate .donut-slice:nth-child(4) { animation-delay: 300ms; }
.donut-animate .donut-slice:nth-child(5) { animation-delay: 400ms; }
.donut-animate .donut-slice:nth-child(6) { animation-delay: 500ms; }


/* ---------------------------------------------------------------------------
   Bar Chart Entrance — grow from baseline
   --------------------------------------------------------------------------- */

@keyframes barGrow {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}

.bar-animate {
  transform-origin: bottom;
  animation: barGrow 600ms var(--ease-decelerate) both;
}

/* Stagger bars (up to 12) */
.bars-animate .bar:nth-child(1)  { animation: barGrow 600ms var(--ease-decelerate)   0ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(2)  { animation: barGrow 600ms var(--ease-decelerate)  50ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(3)  { animation: barGrow 600ms var(--ease-decelerate) 100ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(4)  { animation: barGrow 600ms var(--ease-decelerate) 150ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(5)  { animation: barGrow 600ms var(--ease-decelerate) 200ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(6)  { animation: barGrow 600ms var(--ease-decelerate) 250ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(7)  { animation: barGrow 600ms var(--ease-decelerate) 300ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(8)  { animation: barGrow 600ms var(--ease-decelerate) 350ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(9)  { animation: barGrow 600ms var(--ease-decelerate) 400ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(10) { animation: barGrow 600ms var(--ease-decelerate) 450ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(11) { animation: barGrow 600ms var(--ease-decelerate) 500ms  both; transform-origin: bottom; }
.bars-animate .bar:nth-child(12) { animation: barGrow 600ms var(--ease-decelerate) 550ms  both; transform-origin: bottom; }


/* ---------------------------------------------------------------------------
   Map Polygon Reveal — fade in on load
   --------------------------------------------------------------------------- */

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

.polygon-reveal {
  animation: polygonReveal 800ms var(--ease-editorial) forwards;
}


/* ---------------------------------------------------------------------------
   Ticker / Scroll — horizontal infinite scroll for data tickers
   --------------------------------------------------------------------------- */

@keyframes ticker {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

.ticker-track {
  display: flex;
  animation: ticker 30s linear infinite;
  width: max-content;
}

.ticker-track:hover {
  animation-play-state: paused;
}


/* ---------------------------------------------------------------------------
   Spin — loading indicator (also used in charts.css for chart-spinner)
   --------------------------------------------------------------------------- */

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

.animate-spin {
  animation: spin 700ms linear infinite;
}

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


/* =============================================================================
   PRESS INTERACTION
   Subtle scale-down on :active for tactile button/card feedback.
   ============================================================================= */

.press {
  transition: transform var(--duration-instant) var(--ease-editorial);
}

.press:active {
  transform: scale(0.98);
}

/* Stronger press for large interactive elements */
.press-strong {
  transition: transform var(--duration-instant) var(--ease-editorial);
}

.press-strong:active {
  transform: scale(0.96);
}


/* =============================================================================
   TRANSITION UTILITIES
   Standard single-class helpers for common transition patterns.
   ============================================================================= */

/* All properties — standard duration */
.transition-standard {
  transition: all var(--duration-standard) var(--ease-editorial);
}

/* All properties — fast */
.transition-fast {
  transition: all var(--duration-fast) var(--ease-editorial);
}

/* All properties — slow */
.transition-slow {
  transition: all var(--duration-slow) var(--ease-editorial);
}

/* Color only */
.transition-colors {
  transition:
    color           var(--duration-standard) var(--ease-editorial),
    background-color var(--duration-standard) var(--ease-editorial),
    border-color    var(--duration-standard) var(--ease-editorial),
    fill            var(--duration-standard) var(--ease-editorial),
    stroke          var(--duration-standard) var(--ease-editorial);
}

/* Opacity only */
.transition-opacity {
  transition: opacity var(--duration-standard) var(--ease-editorial);
}

/* Transform only */
.transition-transform {
  transition: transform var(--duration-standard) var(--ease-editorial);
}

/* Box shadow only */
.transition-shadow {
  transition: box-shadow var(--duration-standard) var(--ease-editorial);
}

/* No transition — instant state change */
.transition-none {
  transition: none !important;
}


/* =============================================================================
   ENTRANCE UTILITY CLASSES
   Ready-to-use entrance animations without JS required.
   ============================================================================= */

/* Delay utilities for staggered animation sequences */
.delay-0    { animation-delay:   0ms; }
.delay-75   { animation-delay:  75ms; }
.delay-100  { animation-delay: 100ms; }
.delay-150  { animation-delay: 150ms; }
.delay-200  { animation-delay: 200ms; }
.delay-300  { animation-delay: 300ms; }
.delay-400  { animation-delay: 400ms; }
.delay-500  { animation-delay: 500ms; }
.delay-700  { animation-delay: 700ms; }
.delay-1000 { animation-delay: 1000ms; }

/* Duration overrides */
.duration-fast     { animation-duration: var(--duration-fast); }
.duration-standard { animation-duration: var(--duration-standard); }
.duration-slow     { animation-duration: var(--duration-slow); }
.duration-slower   { animation-duration: var(--duration-slower); }


/* =============================================================================
   REDUCED MOTION
   Respect the user's operating system preference. All animations and
   transitions are collapsed to near-instant. Reveal elements become
   immediately visible. This section must stay at the end of the file.
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    /* Collapse animations to a single frame — don't remove them entirely
       as that can cause flash-of-unstyled-content bugs */
    animation-duration:        0.01ms !important;
    animation-iteration-count: 1      !important;
    transition-duration:       0.01ms !important;
    scroll-behavior:           auto   !important;
  }

  /* Ensure scroll-reveal elements are immediately visible */
  .reveal,
  .reveal-left,
  .reveal-right,
  .reveal-fade,
  .reveal-scale {
    opacity: 1;
    transform: none;
    transition: none;
  }

  /* Skeleton uses background-position animation — collapse it */
  .skeleton {
    animation: none;
    background: var(--surface-container-high);
  }

  /* Remove ticker motion */
  .ticker-track {
    animation: none;
  }

  /* Remove glow pulses */
  .glow-pulse,
  .glow-pulse-gold,
  .glow-pulse-svg {
    animation: none;
  }

  /* Remove ping animations */
  .animate-ping,
  .animate-ping-slow {
    animation: none;
  }

  /* Remove star stagger */
  .star-rating-animate .star-filled {
    animation: none;
    opacity: 1;
    color: var(--secondary);
  }

  /* Remove donut entrance */
  .donut-animate .donut-slice {
    animation: none;
    opacity: 1;
    transform: none;
  }

  /* Remove bar entrance */
  .bars-animate .bar,
  .bar-animate {
    animation: none;
    transform: none;
  }
}
