/* ============================================
   THE AI VALLEY PODCAST - ANIMATIONS
   Glitch Effects, Scanlines, Cursor, etc.
   ============================================ */

/* ============================================
   SCANLINES OVERLAY
   ============================================ */

.scanlines::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(0deg,
      rgba(0, 0, 0, 0.15),
      rgba(0, 0, 0, 0.15) 1px,
      transparent 1px,
      transparent 2px);
  pointer-events: none;
  z-index: var(--z-scanlines);
  opacity: var(--scanline-opacity);
}

.scanlines::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(to bottom,
      transparent,
      rgba(0, 255, 136, 0.1),
      transparent);
  animation: scanlineMove 8s linear infinite;
  pointer-events: none;
  z-index: var(--z-scanlines);
}

/* Moving scanline beam (separate element needed or reuse if possible) */
/* Re-implementing beam as a separate pseudo-element on body if needed, 
   but since ::after is now used for Vignette, we need a new approach for the beam 
   OR combine them. Let's add a dedicated CRT div in HTML instead of overloading ::after 
   Actually, the previous ::after was the beam. Let's preserve the beam and add vignette to body::after? 
   Or better: add a specific .crt-vignette div.
*/

.crt-vignette {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle,
      rgba(0, 0, 0, 0) 60%,
      rgba(0, 0, 0, 0.6) 100%);
  pointer-events: none;
  z-index: var(--z-scanlines);
  opacity: 0.8;
}

@keyframes scanlineMove {
  0% {
    top: -10px;
  }

  100% {
    top: 100vh;
  }
}

/* ============================================
   GLITCH TEXT EFFECT
   ============================================ */

.glitch-text {
  position: relative;
  display: inline-block;
}

.glitch-text::before,
.glitch-text::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}

.glitch-text::before {
  color: var(--accent-tertiary);
  z-index: -1;
}

.glitch-text::after {
  color: var(--accent-secondary);
  z-index: -2;
}

.glitch-text:hover::before,
.glitch-text:hover::after {
  opacity: 0.8;
}

.glitch-text:hover::before {
  animation: glitchTop 0.3s infinite linear alternate-reverse;
}

.glitch-text:hover::after {
  animation: glitchBottom 0.3s infinite linear alternate-reverse;
}

@keyframes glitchTop {
  0% {
    clip-path: polygon(0 0, 100% 0, 100% 33%, 0 33%);
    transform: translate(-2px, -2px);
  }

  20% {
    clip-path: polygon(0 15%, 100% 15%, 100% 35%, 0 35%);
    transform: translate(2px, 1px);
  }

  40% {
    clip-path: polygon(0 10%, 100% 10%, 100% 25%, 0 25%);
    transform: translate(-1px, 2px);
  }

  60% {
    clip-path: polygon(0 20%, 100% 20%, 100% 40%, 0 40%);
    transform: translate(1px, -1px);
  }

  80% {
    clip-path: polygon(0 5%, 100% 5%, 100% 30%, 0 30%);
    transform: translate(-2px, 1px);
  }

  100% {
    clip-path: polygon(0 0, 100% 0, 100% 33%, 0 33%);
    transform: translate(2px, -2px);
  }
}

@keyframes glitchBottom {
  0% {
    clip-path: polygon(0 67%, 100% 67%, 100% 100%, 0 100%);
    transform: translate(2px, 2px);
  }

  20% {
    clip-path: polygon(0 75%, 100% 75%, 100% 95%, 0 95%);
    transform: translate(-2px, -1px);
  }

  40% {
    clip-path: polygon(0 65%, 100% 65%, 100% 85%, 0 85%);
    transform: translate(1px, -2px);
  }

  60% {
    clip-path: polygon(0 70%, 100% 70%, 100% 90%, 0 90%);
    transform: translate(-1px, 1px);
  }

  80% {
    clip-path: polygon(0 80%, 100% 80%, 100% 100%, 0 100%);
    transform: translate(2px, -1px);
  }

  100% {
    clip-path: polygon(0 67%, 100% 67%, 100% 100%, 0 100%);
    transform: translate(-2px, 2px);
  }
}

/* Continuous subtle glitch for hero title */
.hero-title.glitch-text::before,
.hero-title.glitch-text::after {
  opacity: 0.5;
}

.hero-title.glitch-text::before {
  animation: glitchTopSubtle 3s infinite linear;
}

.hero-title.glitch-text::after {
  animation: glitchBottomSubtle 3s infinite linear;
}

@keyframes glitchTopSubtle {

  0%,
  90%,
  100% {
    clip-path: polygon(0 0, 0 0, 0 0, 0 0);
    transform: translate(0);
  }

  92% {
    clip-path: polygon(0 10%, 100% 10%, 100% 30%, 0 30%);
    transform: translate(-2px, 0);
  }

  94% {
    clip-path: polygon(0 15%, 100% 15%, 100% 25%, 0 25%);
    transform: translate(2px, 0);
  }

  96% {
    clip-path: polygon(0 5%, 100% 5%, 100% 20%, 0 20%);
    transform: translate(-1px, 0);
  }

  98% {
    clip-path: polygon(0 20%, 100% 20%, 100% 35%, 0 35%);
    transform: translate(1px, 0);
  }
}

@keyframes glitchBottomSubtle {

  0%,
  90%,
  100% {
    clip-path: polygon(0 0, 0 0, 0 0, 0 0);
    transform: translate(0);
  }

  91% {
    clip-path: polygon(0 70%, 100% 70%, 100% 85%, 0 85%);
    transform: translate(2px, 0);
  }

  93% {
    clip-path: polygon(0 75%, 100% 75%, 100% 90%, 0 90%);
    transform: translate(-2px, 0);
  }

  95% {
    clip-path: polygon(0 65%, 100% 65%, 100% 80%, 0 80%);
    transform: translate(1px, 0);
  }

  97% {
    clip-path: polygon(0 80%, 100% 80%, 100% 95%, 0 95%);
    transform: translate(-1px, 0);
  }
}

/* ============================================
   CURSOR BLINK
   ============================================ */

.cursor {
  display: inline-block;
  animation: cursorBlink 1s step-end infinite;
}

@keyframes cursorBlink {

  0%,
  50% {
    opacity: 1;
  }

  51%,
  100% {
    opacity: 0;
  }
}

/* ============================================
   TYPEWRITER EFFECT
   ============================================ */

.typewriter {
  display: inline-block;
  overflow: hidden;
  border-right: 2px solid var(--accent-primary);
  white-space: nowrap;
  animation:
    typewriter 3s steps(60, end) forwards,
    cursorBlink 1s step-end infinite;
}

@keyframes typewriter {
  from {
    width: 0;
  }

  to {
    width: 100%;
  }
}

/* ============================================
   BUTTON HOVER EFFECTS
   ============================================ */

.btn {
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.3s, height 0.3s;
}

.btn:hover::after {
  width: 300%;
  height: 300%;
}

/* Glitch button effect */
.btn[data-text]::before {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: inherit;
  opacity: 0;
  pointer-events: none;
}

.btn[data-text]:hover::before {
  animation: btnGlitch 0.3s infinite;
}

@keyframes btnGlitch {

  0%,
  100% {
    opacity: 0;
    transform: translate(0);
  }

  10% {
    opacity: 0.5;
    transform: translate(-2px, 2px);
    color: var(--accent-tertiary);
  }

  20% {
    opacity: 0;
  }

  30% {
    opacity: 0.5;
    transform: translate(2px, -2px);
    color: var(--accent-secondary);
  }

  40% {
    opacity: 0;
  }
}

/* ============================================
   CARD HOVER ANIMATIONS
   ============================================ */

.episode-card {
  transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
}

.episode-card:hover {
  animation: cardPulse 2s infinite;
}

@keyframes cardPulse {

  0%,
  100% {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  }

  50% {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 0 20px rgba(0, 255, 136, 0.1);
  }
}

/* ============================================
   LOADING ANIMATIONS
   ============================================ */

.loading-spinner {
  animation: spinnerRotate 1s linear infinite;
}

@keyframes spinnerRotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* Terminal loading effect */
.loading-text::after {
  content: '';
  animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {

  0%,
  20% {
    content: '.';
  }

  40% {
    content: '..';
  }

  60%,
  100% {
    content: '...';
  }
}

/* Boot sequence animation */
.boot-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: #000;
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  color: var(--accent-primary);
  font-family: var(--font-pixel);
  padding: 2rem;
}

.boot-content {
  max-width: 800px;
  width: 90%;
  text-align: left;
  /* Ensure terminal text aligns left */
}

.boot-logo {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  margin-bottom: 2rem;
  text-shadow: 0 0 10px var(--accent-primary);
  opacity: 0;
  animation: fadeIn 0.5s forwards;
  text-align: center;
}

.boot-text {
  font-size: clamp(1rem, 3vw, 1.2rem);
  line-height: 1.6;
  white-space: pre-wrap;
  min-height: 150px;
  color: var(--accent-primary);
  text-shadow: 0 0 5px var(--accent-primary);
  display: inline;
  /* Keep it inline with cursor */
}

.boot-cursor {
  display: inline-block;
  animation: blink 1s step-end infinite;
  margin-left: 5px;
  vertical-align: bottom;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Helper to hide scroll during boot */
body.booting {
  overflow: hidden;
}

/* ============================================
   NAVIGATION ANIMATIONS
   ============================================ */

.nav-link {
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent-primary);
  transition: width 0.3s;
}

.nav-link:hover::after,
.nav-link.active::after {
  width: 100%;
}

/* Dropdown animation */
.dropdown-menu {
  animation: dropdownSlide 0.2s ease-out;
}

@keyframes dropdownSlide {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   SCROLL ANIMATIONS
   ============================================ */

.scroll-reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s, transform 0.6s;
}

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

/* ============================================
   PLAYER ANIMATIONS
   ============================================ */

/* Playing state glow */
.global-player.playing {
  border-top-color: var(--accent-primary);
  box-shadow: 0 -5px 30px rgba(0, 255, 136, 0.2);
}

/* Progress bar shimmer */
.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, 0.2),
      transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

/* Waveform animation */
.waveform-bar {
  transition: height 0.2s ease;
}

.playing .waveform-bar {
  animation: waveform 0.5s ease-in-out infinite alternate;
}

@keyframes waveform {
  0% {
    height: 20%;
    opacity: 0.5;
  }

  100% {
    height: 100%;
    opacity: 1;
  }
}

/* ============================================
   HOVER GLOW EFFECTS
   ============================================ */

.glow-on-hover {
  transition: box-shadow 0.3s;
}

.glow-on-hover:hover {
  box-shadow: var(--glow-green);
}

.glow-red-on-hover:hover {
  box-shadow: var(--glow-red);
}

.glow-cyan-on-hover:hover {
  box-shadow: var(--glow-cyan);
}

/* ============================================
   FLICKER EFFECT
   ============================================ */

.flicker {
  animation: flicker 3s infinite;
}

@keyframes flicker {

  0%,
  100% {
    opacity: 1;
  }

  3% {
    opacity: 0.8;
  }

  6% {
    opacity: 1;
  }

  7% {
    opacity: 0.7;
  }

  9% {
    opacity: 1;
  }

  90% {
    opacity: 1;
  }

  92% {
    opacity: 0.9;
  }

  93% {
    opacity: 1;
  }
}

/* ============================================
   NOISE ANIMATION
   ============================================ */

.noise-overlay {
  animation: noiseMove 0.2s steps(10) infinite;
}

@keyframes noiseMove {

  0%,
  100% {
    transform: translate(0, 0);
  }

  10% {
    transform: translate(-5%, -10%);
  }

  20% {
    transform: translate(-15%, 5%);
  }

  30% {
    transform: translate(7%, -25%);
  }

  40% {
    transform: translate(-5%, 25%);
  }

  50% {
    transform: translate(-15%, 10%);
  }

  60% {
    transform: translate(15%, 0%);
  }

  70% {
    transform: translate(0%, 15%);
  }

  80% {
    transform: translate(3%, 35%);
  }

  90% {
    transform: translate(-10%, 10%);
  }
}

/* ============================================
   STATUS INDICATORS
   ============================================ */

.status-dot {
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {

  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 5px var(--accent-primary);
  }

  50% {
    opacity: 0.5;
    box-shadow: 0 0 15px var(--accent-primary);
  }
}

/* ============================================
   SCROLL INDICATOR
   ============================================ */

.scroll-line {
  animation: scrollBounce 2s ease-in-out infinite;
}

@keyframes scrollBounce {

  0%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  50% {
    transform: translateY(10px);
    opacity: 1;
  }
}

/* ============================================
   FOCUS RING ANIMATION
   ============================================ */

:focus-visible {
  animation: focusPulse 1s ease-in-out infinite;
}

@keyframes focusPulse {

  0%,
  100% {
    outline-offset: 2px;
  }

  50% {
    outline-offset: 4px;
  }
}

/* ============================================
   IMAGE GLITCH OVERLAY
   ============================================ */

.image-glitch-overlay {
  animation: imageGlitch 8s linear infinite;
}

@keyframes imageGlitch {

  0%,
  100% {
    transform: translateY(-100%);
    opacity: 0.5;
  }

  50% {
    opacity: 0.2;
  }

  100% {
    transform: translateY(100%);
  }
}

/* ============================================
   ENTRANCE ANIMATIONS
   ============================================ */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.fade-in-up {
  animation: fadeInUp 0.6s ease-out forwards;
}

.fade-in-left {
  animation: fadeInLeft 0.6s ease-out forwards;
}

.fade-in-right {
  animation: fadeInRight 0.6s ease-out forwards;
}

/* ============================================
   RETRO CRT EFFECTS
   ============================================ */

/* CRT Turn On Effect */
@keyframes crtTurnOn {
  0% {
    transform: scale(1, 0.01);
    filter: brightness(10);
  }

  50% {
    transform: scale(1, 0.01);
    filter: brightness(10);
  }

  60% {
    transform: scale(1.3, 0.6);
    filter: brightness(2);
  }

  70% {
    transform: scale(0.9, 1.1);
    filter: brightness(1);
  }

  80% {
    transform: scale(1.05, 0.95);
  }

  90% {
    transform: scale(0.98, 1.02);
  }

  100% {
    transform: scale(1);
  }
}

.crt-turn-on {
  animation: crtTurnOn 0.5s ease-out;
}

/* Digital Noise */
@keyframes digitalNoise {

  0%,
  100% {
    background-position: 0% 0%;
  }

  10% {
    background-position: -5% -10%;
  }

  20% {
    background-position: -15% 5%;
  }

  30% {
    background-position: 7% -25%;
  }

  40% {
    background-position: 20% 25%;
  }

  50% {
    background-position: -25% 10%;
  }

  60% {
    background-position: 15% 5%;
  }

  70% {
    background-position: 0% 15%;
  }

  80% {
    background-position: 25% 35%;
  }

  90% {
    background-position: -10% 10%;
  }
}

/* Data Stream Effect */
@keyframes dataStream {
  0% {
    background-position: 0% 0%;
    opacity: 0.1;
  }

  50% {
    opacity: 0.3;
  }

  100% {
    background-position: 0% 100%;
    opacity: 0.1;
  }
}

/* Terminal Typing Cursor */
@keyframes terminalCursor {

  0%,
  49% {
    border-right-color: var(--accent-primary);
    opacity: 1;
  }

  50%,
  100% {
    border-right-color: transparent;
    opacity: 0;
  }
}

/* Neon Glow Pulse */
@keyframes neonPulse {

  0%,
  100% {
    text-shadow:
      0 0 5px currentColor,
      0 0 10px currentColor,
      0 0 20px currentColor;
  }

  50% {
    text-shadow:
      0 0 10px currentColor,
      0 0 20px currentColor,
      0 0 40px currentColor,
      0 0 60px currentColor;
  }
}

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

/* RGB Split/Chromatic Aberration */
@keyframes rgbSplit {

  0%,
  100% {
    text-shadow:
      -2px 0 var(--accent-secondary),
      2px 0 var(--accent-tertiary);
  }

  25% {
    text-shadow:
      2px 0 var(--accent-secondary),
      -2px 0 var(--accent-tertiary);
  }

  50% {
    text-shadow:
      -2px 2px var(--accent-secondary),
      2px -2px var(--accent-tertiary);
  }

  75% {
    text-shadow:
      2px -2px var(--accent-secondary),
      -2px 2px var(--accent-tertiary);
  }
}

.rgb-split:hover {
  animation: rgbSplit 0.2s linear infinite;
}

/* Matrix Rain Effect */
@keyframes matrixFall {
  0% {
    transform: translateY(-100%);
    opacity: 1;
  }

  100% {
    transform: translateY(100vh);
    opacity: 0;
  }
}

/* Glowing Border Animation */
@keyframes glowBorder {

  0%,
  100% {
    box-shadow:
      0 0 5px var(--accent-primary),
      0 0 10px var(--accent-primary),
      inset 0 0 5px rgba(0, 255, 136, 0.1);
  }

  50% {
    box-shadow:
      0 0 10px var(--accent-primary),
      0 0 20px var(--accent-primary),
      0 0 30px var(--accent-primary),
      inset 0 0 10px rgba(0, 255, 136, 0.2);
  }
}

.glow-border {
  animation: glowBorder 2s ease-in-out infinite;
}

/* Typing Animation */
@keyframes typeEffect {
  from {
    width: 0;
  }

  to {
    width: 100%;
  }
}

.type-effect {
  overflow: hidden;
  white-space: nowrap;
  animation: typeEffect 2s steps(30, end) forwards;
}

/* Retro Button Press */
@keyframes buttonPress {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(3px);
  }

  100% {
    transform: translateY(0);
  }
}

.btn:active {
  animation: buttonPress 0.1s ease-out;
}

/* Screen Flicker */
@keyframes screenFlicker {

  0%,
  100% {
    opacity: 1;
  }

  3% {
    opacity: 0.95;
  }

  6% {
    opacity: 1;
  }

  7% {
    opacity: 0.92;
  }

  9% {
    opacity: 1;
  }

  12% {
    opacity: 0.97;
  }

  15% {
    opacity: 1;
  }

  92% {
    opacity: 1;
  }

  93% {
    opacity: 0.96;
  }

  94% {
    opacity: 1;
  }

  95% {
    opacity: 0.93;
  }

  96% {
    opacity: 1;
  }
}

body {
  animation: screenFlicker 10s infinite;
}

/* Hover Lift Effect */
@keyframes hoverLift {
  0% {
    transform: translateY(0) scale(1);
  }

  100% {
    transform: translateY(-5px) scale(1.02);
  }
}

/* Text Scramble (for JS implementation) */
@keyframes textScramble {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }

  100% {
    opacity: 1;
  }
}

/* ============================================
   REDUCED MOTION PREFERENCES
   ============================================ */

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

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .scanlines::before,
  .scanlines::after,
  .glitch-text::before,
  .glitch-text::after,
  .cursor,
  .typewriter,
  .loading-spinner,
  .noise-overlay,
  .waveform-bar,
  .status-dot,
  .scroll-line,
  .image-glitch-overlay,
  body {
    animation: none !important;
  }

  .typewriter {
    white-space: normal;
    border-right: none;
    width: auto;
  }

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

  .episode-card,
  .hero-content,
  .hero-visual {
    animation: none !important;
    opacity: 1;
    transform: none;
  }
}