/* src/styles/glitch.css */
/* Chromatic aberration + scanline flicker — "data corruption" style */

.glitch-container {
  position: relative;
}

.glitch-container::before,
.glitch-container::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  padding: inherit;
  background: inherit;
  overflow: hidden;
  pointer-events: none;
}

/* Red channel offset — shifts left */
.glitch-container::before {
  color: rgba(239, 68, 68, 0.7);
  mix-blend-mode: screen;
  animation: glitch-shift-1 3s infinite steps(2);
  clip-path: inset(0 0 0 0);
}

/* Cyan channel offset — shifts right */
.glitch-container::after {
  color: rgba(59, 130, 246, 0.7);
  mix-blend-mode: screen;
  animation: glitch-shift-2 3s infinite steps(2);
  clip-path: inset(0 0 0 0);
}

/* Scanline overlay */
.glitch-scanlines {
  position: relative;
}

.glitch-scanlines::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(0, 0, 0, 0.15) 4px
  );
  pointer-events: none;
  animation: scanline-flicker 4s infinite;
  z-index: 2;
}

@keyframes glitch-shift-1 {
  0%, 100% { transform: translate(-2px, 0); clip-path: inset(20% 0 60% 0); }
  25% { transform: translate(2px, -1px); clip-path: inset(40% 0 30% 0); }
  50% { transform: translate(-1px, 1px); clip-path: inset(60% 0 10% 0); }
  75% { transform: translate(1px, 0); clip-path: inset(10% 0 70% 0); }
}

@keyframes glitch-shift-2 {
  0%, 100% { transform: translate(2px, 0); clip-path: inset(50% 0 20% 0); }
  25% { transform: translate(-2px, 1px); clip-path: inset(10% 0 60% 0); }
  50% { transform: translate(1px, -1px); clip-path: inset(30% 0 40% 0); }
  75% { transform: translate(-1px, 0); clip-path: inset(70% 0 5% 0); }
}

@keyframes scanline-flicker {
  0%, 95%, 100% { opacity: 1; }
  96% { opacity: 0.4; }
  97% { opacity: 0.9; }
  98% { opacity: 0.3; }
  99% { opacity: 1; }
}

/* Short burst variant for game reveals — 0.5s one-shot */
.glitch-burst {
  animation: glitch-burst-shift 0.5s steps(4) forwards;
}

.glitch-burst::before {
  animation: glitch-shift-1 0.5s steps(4) forwards !important;
}

.glitch-burst::after {
  animation: glitch-shift-2 0.5s steps(4) forwards !important;
}

@keyframes glitch-burst-shift {
  0% { transform: translate(-3px, 1px); filter: hue-rotate(90deg); }
  25% { transform: translate(3px, -2px); filter: hue-rotate(180deg); }
  50% { transform: translate(-2px, 2px); filter: hue-rotate(270deg); }
  75% { transform: translate(2px, -1px); filter: hue-rotate(360deg); }
  100% { transform: translate(0, 0); filter: none; }
}

/* Reduced motion: disable all glitch effects */
@media (prefers-reduced-motion: reduce) {
  .glitch-container::before,
  .glitch-container::after,
  .glitch-scanlines::after {
    animation: none;
    opacity: 0;
  }
  .glitch-burst {
    animation: none;
  }
}
