/* ==========================================================================
   Animations
   ========================================================================== */

/* ==========================================================================
   Theme Transition
   ========================================================================== */

* {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-duration: 0ms;
  transition-timing-function: ease;
}

.theme-transitioning * {
  transition-duration: 200ms !important;
}

/* ==========================================================================
   Page Load Animation
   ========================================================================== */

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

.animate-fade-in-up {
  animation: fadeInUp var(--transition-slower) var(--ease-out-expo) forwards;
  opacity: 0;
}

.animate-delay-1 { animation-delay: 100ms; }
.animate-delay-2 { animation-delay: 200ms; }
.animate-delay-3 { animation-delay: 300ms; }
.animate-delay-4 { animation-delay: 400ms; }
.animate-delay-5 { animation-delay: 500ms; }
.animate-delay-6 { animation-delay: 600ms; }

/* ==========================================================================
   Scroll Reveal Animation
   ========================================================================== */

.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--transition-slower) var(--ease-out-expo),
              transform var(--transition-slower) var(--ease-out-expo);
}

.reveal.is-revealed {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered reveals for lists */
.reveal-stagger > .reveal:nth-child(1) { transition-delay: 0ms; }
.reveal-stagger > .reveal:nth-child(2) { transition-delay: 100ms; }
.reveal-stagger > .reveal:nth-child(3) { transition-delay: 200ms; }
.reveal-stagger > .reveal:nth-child(4) { transition-delay: 300ms; }
.reveal-stagger > .reveal:nth-child(5) { transition-delay: 400ms; }
.reveal-stagger > .reveal:nth-child(6) { transition-delay: 500ms; }
.reveal-stagger > .reveal:nth-child(7) { transition-delay: 600ms; }
.reveal-stagger > .reveal:nth-child(8) { transition-delay: 700ms; }

/* ==========================================================================
   Card Hover Effects
   ========================================================================== */

.card {
  transition: transform var(--transition-base) ease,
              box-shadow var(--transition-base) ease,
              border-color var(--transition-base) ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px var(--glow-color);
  border-color: var(--accent-primary);
}

/* ==========================================================================
   Link Underline Animation
   ========================================================================== */

.link-animated {
  position: relative;
  display: inline-block;
}

.link-animated::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent-primary);
  transition: width var(--transition-base) ease;
}

.link-animated:hover::after {
  width: 100%;
}

/* ==========================================================================
   Button Press Animation
   ========================================================================== */

.btn {
  transition: transform var(--transition-fast),
              background-color var(--transition-fast),
              border-color var(--transition-fast),
              color var(--transition-fast);
}

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

/* ==========================================================================
   Hero Scroll Indicator
   ========================================================================== */

@keyframes scrollBounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateX(-50%) translateY(0);
  }
  40% {
    transform: translateX(-50%) translateY(-10px);
  }
  60% {
    transform: translateX(-50%) translateY(-5px);
  }
}

.hero__scroll {
  animation: scrollBounce 2s infinite;
}

/* ==========================================================================
   Icon Rotation (Theme Toggle)
   ========================================================================== */

@keyframes iconRotate {
  from {
    transform: rotate(0deg);
    opacity: 0;
  }
  to {
    transform: rotate(360deg);
    opacity: 1;
  }
}

.theme-toggle svg {
  transition: transform var(--transition-base) ease;
}

.theme-toggle:hover svg {
  transform: rotate(15deg);
}

/* ==========================================================================
   External Link Arrow
   ========================================================================== */

.link-external svg {
  transition: transform var(--transition-fast) ease;
}

.link-external:hover svg {
  transform: translate(2px, -2px);
}

/* ==========================================================================
   Pulse Animation (for highlights)
   ========================================================================== */

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

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

/* ==========================================================================
   RL-Themed Animations
   ========================================================================== */

/* Reward glow pulse - like receiving a reward signal */
@keyframes rewardPulse {
  0%, 100% {
    box-shadow: 0 0 20px var(--accent-reward-dim);
  }
  50% {
    box-shadow: 0 0 40px var(--accent-reward-glow), 0 0 60px var(--accent-reward-dim);
  }
}

.animate-reward {
  animation: rewardPulse 2s ease-in-out infinite;
}

/* State transition effect */
@keyframes stateTransition {
  0% {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.animate-state-transition {
  animation: stateTransition 0.5s var(--ease-out-expo) forwards;
}

/* Value function shimmer - like value propagation */
@keyframes valueShimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.animate-value-shimmer {
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent-state-dim) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: valueShimmer 3s ease-in-out infinite;
}

/* Node glow for MDP states */
@keyframes nodeGlow {
  0%, 100% {
    box-shadow: 
      0 0 10px var(--accent-state-dim),
      inset 0 0 10px transparent;
  }
  50% {
    box-shadow: 
      0 0 20px var(--accent-state-glow),
      0 0 40px var(--accent-state-dim),
      inset 0 0 15px var(--accent-state-dim);
  }
}

.animate-node-glow {
  animation: nodeGlow 3s ease-in-out infinite;
}

/* ==========================================================================
   Floating Animation
   ========================================================================== */

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

.animate-float {
  animation: float 3s ease-in-out infinite;
}

/* ==========================================================================
   Gradient Descent Animation
   ========================================================================== */

@keyframes gradientDescent {
  0% {
    transform: translate(0, 0);
    opacity: 1;
  }
  100% {
    transform: translate(var(--descent-x, 20px), var(--descent-y, 30px));
    opacity: 0.3;
  }
}

.animate-descent {
  animation: gradientDescent 2s ease-out infinite;
}

/* ==========================================================================
   Information Flow Animation
   ========================================================================== */

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

.animate-info-flow {
  background: linear-gradient(
    180deg,
    var(--accent-state) 0%,
    var(--accent-value) 50%,
    var(--accent-reward) 100%
  );
  background-size: 100% 200%;
  animation: infoFlow 3s ease-in-out infinite alternate;
}

/* ==========================================================================
   Bellman Backup Animation (value propagation)
   ========================================================================== */

@keyframes bellmanBackup {
  0%, 100% {
    opacity: 0.3;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.animate-bellman {
  animation: bellmanBackup 2s ease-in-out infinite;
}

/* ==========================================================================
   Exploration-Exploitation Animation
   ========================================================================== */

@keyframes explore {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px) rotate(-2deg);
  }
  75% {
    transform: translateX(5px) rotate(2deg);
  }
}

.animate-explore {
  animation: explore 4s ease-in-out infinite;
}

/* ==========================================================================
   Probability Distribution Animation
   ========================================================================== */

@keyframes probWave {
  0%, 100% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(1.2);
  }
}

.prob-distribution__bar {
  animation: probWave 2s ease-in-out infinite;
}

.prob-distribution__bar:nth-child(1) { animation-delay: 0s; }
.prob-distribution__bar:nth-child(2) { animation-delay: 0.1s; }
.prob-distribution__bar:nth-child(3) { animation-delay: 0.2s; }
.prob-distribution__bar:nth-child(4) { animation-delay: 0.3s; }
.prob-distribution__bar:nth-child(5) { animation-delay: 0.4s; }
.prob-distribution__bar:nth-child(6) { animation-delay: 0.5s; }
.prob-distribution__bar:nth-child(7) { animation-delay: 0.6s; }

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@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;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }

  .animate-fade-in-up {
    opacity: 1;
    animation: none;
  }

  .hero__scroll {
    animation: none;
  }

  .typing-cursor {
    display: none;
  }
}

/* ==========================================================================
   Typing Animation Cursor
   ========================================================================== */

.typing-cursor {
  display: inline-block;
  color: var(--accent-primary);
  font-weight: 400;
  margin-left: 2px;
  opacity: 1;
}

.typing-cursor--blink {
  animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0;
  }
}

/* Ensure hero elements are visible for typing */
.hero__name,
.hero__title {
  min-height: 1.2em;
}
