/**
 * PROMPT Band - Glitch Effects System
 * Digital, unstable, alive - like hardware running hot
 */

/* ==========================================================================
   CSS Variables for Effects
   ========================================================================== */
:root {
  --glitch-color-1: #ff00ff;
  --glitch-color-2: #00ffff;
  --glitch-color-3: #ffff00;
  --scanline-opacity: 0.03;
  --scanline-spacing: 4px;
  --trail-color: rgba(255, 139, 245, 0.6);
  --error-bg: rgba(255, 0, 60, 0.9);
  --vhs-band-color: rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Chromatic Aberration
   ========================================================================== */
.chromatic-aberration {
  position: relative;
}

.chromatic-aberration::before,
.chromatic-aberration::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.chromatic-aberration::before {
  color: var(--glitch-color-2);
  animation: chromatic-shift-cyan 0.3s ease-out;
  clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
  transform: translateX(-2px);
  opacity: 0.8;
  mix-blend-mode: screen;
}

.chromatic-aberration::after {
  color: var(--glitch-color-1);
  animation: chromatic-shift-magenta 0.3s ease-out;
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
  transform: translateX(2px);
  opacity: 0.8;
  mix-blend-mode: screen;
}

/* Chromatic aberration for images */
.chromatic-aberration-img {
  position: relative;
  filter: url(#chromatic-filter);
}

.chromatic-aberration-img.active {
  animation: chromatic-image 0.15s ease-out;
}

@keyframes chromatic-shift-cyan {
  0% { transform: translateX(0); opacity: 0; }
  50% { transform: translateX(-4px); opacity: 1; }
  100% { transform: translateX(-2px); opacity: 0.8; }
}

@keyframes chromatic-shift-magenta {
  0% { transform: translateX(0); opacity: 0; }
  50% { transform: translateX(4px); opacity: 1; }
  100% { transform: translateX(2px); opacity: 0.8; }
}

@keyframes chromatic-image {
  0%, 100% { filter: none; }
  25% { filter: drop-shadow(-3px 0 var(--glitch-color-2)) drop-shadow(3px 0 var(--glitch-color-1)); }
  50% { filter: drop-shadow(-5px 0 var(--glitch-color-2)) drop-shadow(5px 0 var(--glitch-color-1)); }
  75% { filter: drop-shadow(-2px 0 var(--glitch-color-2)) drop-shadow(2px 0 var(--glitch-color-1)); }
}

/* ==========================================================================
   Glitch Text Effect
   ========================================================================== */
.glitch-text {
  position: relative;
  display: inline-block;
}

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

/* Subtle glitch */
.glitch-text[data-intensity="subtle"]::before,
.glitch-text[data-intensity="subtle"]::after {
  animation: glitch-subtle 4s infinite linear;
}

.glitch-text[data-intensity="subtle"]::before {
  color: var(--glitch-color-2);
  animation-delay: 0.05s;
}

.glitch-text[data-intensity="subtle"]::after {
  color: var(--glitch-color-1);
}

/* Medium glitch */
.glitch-text[data-intensity="medium"]::before,
.glitch-text[data-intensity="medium"]::after {
  animation: glitch-medium 2s infinite linear;
}

.glitch-text[data-intensity="medium"]::before {
  color: var(--glitch-color-2);
  animation-delay: 0.03s;
}

.glitch-text[data-intensity="medium"]::after {
  color: var(--glitch-color-1);
}

/* Heavy glitch */
.glitch-text[data-intensity="heavy"]::before,
.glitch-text[data-intensity="heavy"]::after {
  animation: glitch-heavy 0.5s infinite linear;
}

.glitch-text[data-intensity="heavy"]::before {
  color: var(--glitch-color-2);
  animation-delay: 0.02s;
}

.glitch-text[data-intensity="heavy"]::after {
  color: var(--glitch-color-1);
}

/* Active state (manual trigger) */
.glitch-text.glitch-active::before,
.glitch-text.glitch-active::after {
  animation: glitch-burst 0.3s linear forwards;
  opacity: 1;
}

@keyframes glitch-subtle {
  0%, 90%, 100% {
    opacity: 0;
    transform: translate(0);
  }
  92% {
    opacity: 0.5;
    transform: translate(-1px, 1px);
    clip-path: polygon(0 20%, 100% 20%, 100% 30%, 0 30%);
  }
  94% {
    opacity: 0.5;
    transform: translate(1px, -1px);
    clip-path: polygon(0 60%, 100% 60%, 100% 70%, 0 70%);
  }
}

@keyframes glitch-medium {
  0%, 80%, 100% {
    opacity: 0;
    transform: translate(0);
  }
  82% {
    opacity: 0.7;
    transform: translate(-2px, 1px);
    clip-path: polygon(0 15%, 100% 15%, 100% 35%, 0 35%);
  }
  84% {
    opacity: 0;
  }
  86% {
    opacity: 0.7;
    transform: translate(2px, -1px);
    clip-path: polygon(0 55%, 100% 55%, 100% 75%, 0 75%);
  }
  88% {
    opacity: 0.5;
    transform: translate(-1px, 2px);
    clip-path: polygon(0 80%, 100% 80%, 100% 90%, 0 90%);
  }
}

@keyframes glitch-heavy {
  0%, 100% {
    opacity: 0.8;
    transform: translate(0);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
  }
  10% {
    transform: translate(-3px, 2px);
    clip-path: polygon(0 5%, 100% 5%, 100% 20%, 0 20%);
  }
  20% {
    transform: translate(3px, -2px);
    clip-path: polygon(0 40%, 100% 40%, 100% 55%, 0 55%);
  }
  30% {
    transform: translate(-2px, 1px);
    clip-path: polygon(0 70%, 100% 70%, 100% 85%, 0 85%);
  }
  40% {
    transform: translate(2px, -1px);
    clip-path: polygon(0 25%, 100% 25%, 100% 35%, 0 35%);
  }
  50% {
    transform: translate(-4px, 2px);
    clip-path: polygon(0 60%, 100% 60%, 100% 70%, 0 70%);
  }
  60% {
    transform: translate(4px, -2px);
    clip-path: polygon(0 10%, 100% 10%, 100% 25%, 0 25%);
  }
  70% {
    transform: translate(-1px, 3px);
    clip-path: polygon(0 45%, 100% 45%, 100% 60%, 0 60%);
  }
  80% {
    transform: translate(1px, -3px);
    clip-path: polygon(0 75%, 100% 75%, 100% 95%, 0 95%);
  }
  90% {
    transform: translate(-2px, 1px);
    clip-path: polygon(0 30%, 100% 30%, 100% 45%, 0 45%);
  }
}

@keyframes glitch-burst {
  0% {
    opacity: 1;
    transform: translate(0);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
  }
  20% {
    transform: translate(-5px, 2px);
    clip-path: polygon(0 10%, 100% 10%, 100% 30%, 0 30%);
  }
  40% {
    transform: translate(5px, -3px);
    clip-path: polygon(0 50%, 100% 50%, 100% 70%, 0 70%);
  }
  60% {
    transform: translate(-3px, 1px);
    clip-path: polygon(0 20%, 100% 20%, 100% 40%, 0 40%);
  }
  80% {
    transform: translate(3px, -1px);
    clip-path: polygon(0 70%, 100% 70%, 100% 90%, 0 90%);
  }
  100% {
    opacity: 0;
    transform: translate(0);
  }
}

/* ==========================================================================
   Scan Lines Overlay
   ========================================================================== */
.scanlines {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.scanlines::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 200%;
  background: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(var(--scanline-spacing) - 1px),
    rgba(0, 0, 0, var(--scanline-opacity)) calc(var(--scanline-spacing) - 1px),
    rgba(0, 0, 0, var(--scanline-opacity)) var(--scanline-spacing)
  );
  animation: scanlines-move 8s linear infinite;
}

.scanlines.active::before {
  animation: scanlines-move 8s linear infinite, scanlines-flicker 0.1s step-end infinite;
}

@keyframes scanlines-move {
  0% { transform: translateY(0); }
  100% { transform: translateY(-50%); }
}

@keyframes scanlines-flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.95; }
}

/* Scanline intensity variants */
.scanlines[data-intensity="subtle"] { --scanline-opacity: 0.02; }
.scanlines[data-intensity="medium"] { --scanline-opacity: 0.05; }
.scanlines[data-intensity="heavy"] { --scanline-opacity: 0.1; }

/* ==========================================================================
   Data Corruption Effect
   ========================================================================== */
.data-corruption {
  position: relative;
  overflow: hidden;
}

.data-corruption.corrupting {
  animation: corrupt-container 0.3s steps(1) forwards;
}

.data-corruption.corrupting::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 2px,
      rgba(255, 0, 255, 0.1) 2px,
      rgba(255, 0, 255, 0.1) 4px
    );
  animation: corrupt-overlay 0.2s steps(4) infinite;
  z-index: 10;
  pointer-events: none;
}

.data-corruption.corrupting > * {
  animation: corrupt-children 0.15s steps(1) infinite;
}

@keyframes corrupt-container {
  0%, 100% { filter: none; }
  25% { filter: saturate(2) hue-rotate(10deg); }
  50% { filter: contrast(1.5) brightness(1.2); }
  75% { filter: saturate(0.5) hue-rotate(-10deg); }
}

@keyframes corrupt-overlay {
  0% { transform: translateX(0); opacity: 0.5; }
  25% { transform: translateX(-10px); opacity: 0.7; }
  50% { transform: translateX(5px); opacity: 0.3; }
  75% { transform: translateX(-5px); opacity: 0.6; }
  100% { transform: translateX(0); opacity: 0.5; }
}

@keyframes corrupt-children {
  0%, 100% { transform: translateX(0) skewX(0); }
  25% { transform: translateX(-3px) skewX(-0.5deg); }
  50% { transform: translateX(3px) skewX(0.5deg); }
  75% { transform: translateX(-1px) skewX(-0.3deg); }
}

/* Pixelation effect for data corruption */
.data-corruption.pixelating {
  image-rendering: pixelated;
  filter: contrast(1.2);
}

/* ==========================================================================
   Cursor Trail
   ========================================================================== */
.cursor-trail-particle {
  position: fixed;
  pointer-events: none;
  z-index: 9998;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--trail-color);
  box-shadow: 0 0 10px var(--trail-color), 0 0 20px var(--trail-color);
  opacity: 0;
  transform: scale(1);
  animation: trail-fade 0.6s ease-out forwards;
}

.cursor-trail-particle[data-size="small"] {
  width: 4px;
  height: 4px;
}

.cursor-trail-particle[data-size="large"] {
  width: 12px;
  height: 12px;
}

@keyframes trail-fade {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.2);
  }
}

/* ==========================================================================
   Memory Fade Effect
   ========================================================================== */
.memory-fade {
  position: relative;
}

.memory-fade::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(2, 4, 10, 0.95) 0%,
    rgba(2, 4, 10, 0.7) 20%,
    transparent 40%
  );
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease-out;
  z-index: 100;
}

.memory-fade.fading::before {
  opacity: 1;
}

/* Corruption artifacts that appear during memory fade */
.memory-fade.fading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 30%;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 3px,
      rgba(255, 0, 255, 0.03) 3px,
      rgba(255, 0, 255, 0.03) 4px
    );
  animation: memory-corrupt 2s linear infinite;
  pointer-events: none;
  z-index: 101;
}

@keyframes memory-corrupt {
  0%, 100% { opacity: 0.5; transform: translateY(0); }
  50% { opacity: 0.8; transform: translateY(-2px); }
}

/* Progressive fade levels based on scroll distance */
.memory-fade[data-fade-level="1"]::before { opacity: 0.3; }
.memory-fade[data-fade-level="2"]::before { opacity: 0.5; }
.memory-fade[data-fade-level="3"]::before { opacity: 0.7; }
.memory-fade[data-fade-level="4"]::before { opacity: 0.9; }

/* ==========================================================================
   Error Flash Messages
   ========================================================================== */
.error-flash {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 1rem 2rem;
  background: var(--error-bg);
  color: #fff;
  font-family: 'Courier New', monospace;
  font-size: 1.2rem;
  font-weight: bold;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  border: 2px solid #ff0040;
  box-shadow:
    0 0 20px rgba(255, 0, 60, 0.5),
    0 0 40px rgba(255, 0, 60, 0.3),
    inset 0 0 20px rgba(0, 0, 0, 0.3);
}

.error-flash.active {
  animation: error-flash-in 0.8s ease-out forwards;
}

.error-flash::before {
  content: '>';
  margin-right: 0.5rem;
  animation: cursor-blink 0.3s step-end infinite;
}

@keyframes error-flash-in {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  10% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
  20% {
    transform: translate(-50%, -50%) scale(1) skewX(-2deg);
  }
  30% {
    transform: translate(-50%, -50%) scale(1) skewX(2deg);
  }
  40% {
    transform: translate(-50%, -50%) scale(1) skewX(0);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1);
  }
}

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

/* Error flash variants */
.error-flash[data-type="warning"] {
  background: rgba(255, 180, 0, 0.9);
  border-color: #ffb400;
  box-shadow:
    0 0 20px rgba(255, 180, 0, 0.5),
    0 0 40px rgba(255, 180, 0, 0.3);
}

.error-flash[data-type="info"] {
  background: rgba(0, 180, 255, 0.9);
  border-color: #00b4ff;
  box-shadow:
    0 0 20px rgba(0, 180, 255, 0.5),
    0 0 40px rgba(0, 180, 255, 0.3);
}

/* ==========================================================================
   VHS Tracking Effect
   ========================================================================== */
.vhs-tracking {
  position: relative;
  overflow: hidden;
}

.vhs-tracking::before {
  content: '';
  position: absolute;
  top: -100%;
  left: 0;
  width: 100%;
  height: 20px;
  background: linear-gradient(
    to bottom,
    transparent,
    var(--vhs-band-color) 20%,
    rgba(255, 255, 255, 0.2) 50%,
    var(--vhs-band-color) 80%,
    transparent
  );
  z-index: 50;
  pointer-events: none;
  opacity: 0;
}

.vhs-tracking.active::before {
  opacity: 1;
  animation: vhs-band-move 1.5s linear infinite;
}

/* Multiple tracking bands */
.vhs-tracking::after {
  content: '';
  position: absolute;
  top: -100%;
  left: 0;
  width: 100%;
  height: 8px;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(255, 255, 255, 0.15) 50%,
    transparent
  );
  z-index: 50;
  pointer-events: none;
  opacity: 0;
}

.vhs-tracking.active::after {
  opacity: 1;
  animation: vhs-band-move 2.3s linear infinite;
  animation-delay: 0.7s;
}

@keyframes vhs-band-move {
  0% { top: -20%; }
  100% { top: 120%; }
}

/* VHS noise overlay */
.vhs-tracking.noisy::before {
  background:
    linear-gradient(
      to bottom,
      transparent,
      var(--vhs-band-color) 20%,
      rgba(255, 255, 255, 0.3) 50%,
      var(--vhs-band-color) 80%,
      transparent
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 1px,
      rgba(255, 255, 255, 0.05) 1px,
      rgba(255, 255, 255, 0.05) 2px
    );
  height: 40px;
}

/* Heavy distortion mode */
.vhs-tracking.heavy::before {
  height: 60px;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(255, 0, 255, 0.1) 10%,
    rgba(0, 255, 255, 0.15) 30%,
    rgba(255, 255, 255, 0.3) 50%,
    rgba(0, 255, 255, 0.15) 70%,
    rgba(255, 0, 255, 0.1) 90%,
    transparent
  );
}

/* ==========================================================================
   Global Glitch Levels
   ========================================================================== */
/* Level 0: Off */
[data-glitch-level="0"] .glitch-text::before,
[data-glitch-level="0"] .glitch-text::after {
  display: none;
}

/* Level 1: Subtle */
[data-glitch-level="1"] .scanlines { --scanline-opacity: 0.02; }
[data-glitch-level="1"] .glitch-text { --glitch-frequency: 6s; }

/* Level 2: Medium */
[data-glitch-level="2"] .scanlines { --scanline-opacity: 0.04; }
[data-glitch-level="2"] .glitch-text { --glitch-frequency: 3s; }

/* Level 3: Heavy */
[data-glitch-level="3"] .scanlines { --scanline-opacity: 0.08; }
[data-glitch-level="3"] .glitch-text { --glitch-frequency: 1s; }
[data-glitch-level="3"] .vhs-tracking::before { opacity: 0.3; }

/* ==========================================================================
   Utility Classes
   ========================================================================== */
.effect-hidden {
  opacity: 0;
  visibility: hidden;
}

.effect-visible {
  opacity: 1;
  visibility: visible;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .glitch-text::before,
  .glitch-text::after,
  .scanlines::before,
  .vhs-tracking::before,
  .vhs-tracking::after,
  .cursor-trail-particle,
  .error-flash,
  .data-corruption.corrupting,
  .data-corruption.corrupting > *,
  .chromatic-aberration::before,
  .chromatic-aberration::after {
    animation: none !important;
  }

  .memory-fade::before,
  .memory-fade::after {
    transition: none !important;
    animation: none !important;
  }
}

/* Performance optimizations */
.glitch-text,
.chromatic-aberration,
.vhs-tracking,
.data-corruption,
.scanlines,
.cursor-trail-particle,
.error-flash {
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
}
