/* ============================================
   Animations — Scroll reveals, transitions, effects
   ============================================ */

/* ---- Scroll reveal ---- */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-left {
  opacity: 0;
  transform: translateX(-24px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.reveal-right {
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal-right.visible {
  opacity: 1;
  transform: translateX(0);
}

.reveal-scale {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal-scale.visible {
  opacity: 1;
  transform: scale(1);
}

/* Staggered children */
.stagger > * {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.stagger.visible > *:nth-child(1) { transition-delay: 0ms; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(2) { transition-delay: 80ms; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(3) { transition-delay: 160ms; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(4) { transition-delay: 240ms; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(5) { transition-delay: 320ms; opacity: 1; transform: translateY(0); }
.stagger.visible > *:nth-child(6) { transition-delay: 400ms; opacity: 1; transform: translateY(0); }

/* ---- Hero background animation ---- */
.hero-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

.hero-bg::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  top: -200px;
  right: -100px;
  animation: float-orb 20s ease-in-out infinite;
}

.hero-bg::after {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.08) 0%, transparent 70%);
  bottom: -100px;
  left: -100px;
  animation: float-orb 25s ease-in-out infinite reverse;
}

@keyframes float-orb {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(30px, -40px); }
  50% { transform: translate(-20px, 20px); }
  75% { transform: translate(15px, 30px); }
}

/* ---- Grid pattern overlay ---- */
.grid-pattern {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-color) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity: 0.3;
  mask-image: radial-gradient(ellipse 60% 60% at 50% 50%, black 0%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 60% 60% at 50% 50%, black 0%, transparent 100%);
}

/* ---- Theme toggle animation ---- */
.theme-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-md);
}

.theme-toggle:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  transform: scale(1.05);
}

.theme-toggle svg {
  width: 22px;
  height: 22px;
  transition: transform var(--transition-slow), opacity var(--transition-fast);
}

.theme-toggle .sun-icon {
  display: none;
  color: var(--warning);
}

.theme-toggle .moon-icon {
  display: block;
  color: var(--text-secondary);
}

[data-theme="light"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="light"] .theme-toggle .moon-icon {
  display: none;
}

/* ---- Pulse dot ---- */
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  position: relative;
}

.pulse-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0;
  animation: pulse-ring 2s ease-out infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.4; }
  100% { transform: scale(2.5); opacity: 0; }
}

/* ---- Hover lift ---- */
.hover-lift {
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

/* ---- Shimmer loading ---- */
.shimmer {
  background: linear-gradient(90deg, var(--bg-glass) 25%, var(--bg-glass-hover) 50%, var(--bg-glass) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================
   Celestial Theme Transition
   ============================================ */

/* Overlay container — covers viewport, invisible until active */
#theme-transition-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

#theme-transition-overlay.active {
  opacity: 1;
}

/* ---- Celestial Orb ---- */
.celestial-orb {
  position: fixed;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  left: 0;
  top: 0;
  opacity: 0;
  z-index: 3;
  pointer-events: none;
  will-change: transform, opacity;
}

/* Sun orb (dark to light) */
.to-light .celestial-orb {
  background: radial-gradient(circle at 35% 35%, #fff7b0 0%, #f59e0b 40%, #ea580c 100%);
  box-shadow:
    0 0 40px 15px rgba(245, 158, 11, 0.6),
    0 0 80px 30px rgba(245, 158, 11, 0.3),
    0 0 120px 50px rgba(245, 158, 11, 0.1);
}

/* Moon orb (light to dark) */
.to-dark .celestial-orb {
  background: radial-gradient(circle at 35% 35%, #f0f4ff 0%, #c4c9d4 40%, #8b95a8 100%);
  box-shadow:
    0 0 40px 15px rgba(196, 201, 212, 0.5),
    0 0 80px 30px rgba(139, 149, 168, 0.25),
    0 0 120px 50px rgba(139, 149, 168, 0.1);
}

/* ---- Horizon Sweep ---- */
.celestial-horizon {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0;
  z-index: 1;
  opacity: 0;
}

/* Sunrise horizon (warm) */
.to-light .celestial-horizon {
  background: linear-gradient(
    to top,
    rgba(234, 88, 12, 0.3) 0%,
    rgba(245, 158, 11, 0.2) 20%,
    rgba(251, 191, 36, 0.12) 40%,
    rgba(255, 255, 255, 0.06) 70%,
    transparent 100%
  );
}

/* Sunset horizon (cool) */
.to-dark .celestial-horizon {
  background: linear-gradient(
    to top,
    rgba(30, 27, 75, 0.4) 0%,
    rgba(49, 46, 129, 0.25) 20%,
    rgba(88, 80, 168, 0.15) 40%,
    rgba(139, 149, 168, 0.06) 70%,
    transparent 100%
  );
}

.to-light.active .celestial-horizon,
.to-dark.active .celestial-horizon {
  animation: horizon-sweep 1.3s ease-in-out forwards;
}

@keyframes horizon-sweep {
  0% {
    height: 0;
    opacity: 0;
  }
  20% {
    height: 30vh;
    opacity: 0.8;
  }
  50% {
    height: 100vh;
    opacity: 1;
  }
  80% {
    height: 30vh;
    opacity: 0.6;
  }
  100% {
    height: 0;
    opacity: 0;
  }
}

/* ---- Screen Flash at Apex ---- */
.celestial-flash {
  position: fixed;
  inset: 0;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
}

.to-light .celestial-flash {
  background: radial-gradient(circle at 50% 10%, rgba(255, 250, 220, 0.5) 0%, rgba(255, 255, 255, 0.15) 50%, transparent 80%);
}

.to-dark .celestial-flash {
  background: radial-gradient(circle at 50% 10%, rgba(139, 149, 168, 0.35) 0%, rgba(30, 27, 75, 0.15) 50%, transparent 80%);
}

.celestial-flash.flash {
  animation: apex-flash 0.4s ease-out forwards;
}

@keyframes apex-flash {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- Trailing Particles ---- */
.celestial-particle {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 4;
  animation: particle-fade 0.6s ease-out forwards;
}

@keyframes particle-fade {
  0% {
    opacity: 0.9;
    transform: scale(1) translate(0, 0);
  }
  100% {
    opacity: 0;
    transform: scale(0) translate(var(--drift-x, 0), var(--drift-y, -20px));
  }
}

/* ---- Toggle button pulse during transition ---- */
.theme-transitioning .theme-toggle {
  animation: toggle-pulse 0.6s ease-in-out;
}

@keyframes toggle-pulse {
  0% { transform: scale(1); box-shadow: var(--shadow-md); }
  30% { transform: scale(1.2); box-shadow: var(--shadow-lg), 0 0 30px var(--accent-glow); }
  100% { transform: scale(1); box-shadow: var(--shadow-md); }
}

/* ---- Reduce motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .reveal, .reveal-left, .reveal-right, .reveal-scale {
    opacity: 1;
    transform: none;
  }

  .stagger > * {
    opacity: 1;
    transform: none;
  }
}
