/* AIDEV-NOTE: Konami glitch mode — visual-only effects, no layout shake */

/* ============================================
   Glitch Mode (activated by Konami code)
   ============================================ */
@keyframes scan-line {
  0% { top: -100%; }
  100% { top: 100%; }
}

@keyframes glitch-text {
  0%, 100% {
    text-shadow:
      2px 0 #ff0040,
      -2px 0 #0ff;
  }
  25% {
    text-shadow:
      -2px 0 #ff0040,
      2px 0 #0ff;
  }
  50% {
    text-shadow:
      2px 2px #ff0040,
      -2px -2px #0ff;
  }
  75% {
    text-shadow:
      -2px 2px #ff0040,
      2px -2px #0ff;
  }
}

@keyframes glitch-flicker {
  0%, 100% { opacity: 1; }
  42% { opacity: 0.93; }
  57% { opacity: 0.97; }
  71% { opacity: 0.88; }
  86% { opacity: 1; }
}

@keyframes glitch-hue {
  0%, 100% { filter: hue-rotate(0deg); }
  33% { filter: hue-rotate(5deg) saturate(1.2); }
  66% { filter: hue-rotate(-5deg) saturate(0.9); }
}

@keyframes poem-flicker {
  0%, 100% { opacity: 1; }
  33% { opacity: 0.9; }
  66% { opacity: 0.95; }
}

body.glitch-mode {
  --glitch-intensity: 1;
  animation: glitch-hue 4s ease-in-out infinite;
}

/* Scan-line overlay */
body.glitch-mode::after {
  content: '';
  position: fixed;
  top: -100%;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(
    to right,
    transparent 0%,
    rgba(45, 212, 191, 0.12) 20%,
    rgba(45, 212, 191, 0.2) 50%,
    rgba(45, 212, 191, 0.12) 80%,
    transparent 100%
  );
  box-shadow: 0 0 8px rgba(45, 212, 191, 0.1);
  z-index: 9998;
  animation: scan-line 3s linear infinite;
  pointer-events: none;
}

/* Subtle CRT scanline texture */
body.glitch-mode::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  z-index: 9997;
  pointer-events: none;
  animation: glitch-flicker 5s step-end infinite;
}

/* RGB text-shadow glitch on headings */
body.glitch-mode h1,
body.glitch-mode h2,
body.glitch-mode h3 {
  animation: glitch-text 0.5s infinite;
}

/* Chromatic aberration on images */
body.glitch-mode img {
  animation: glitch-flicker 3s step-end infinite;
  filter: drop-shadow(2px 0 0 rgba(255, 0, 64, 0.15)) drop-shadow(-2px 0 0 rgba(0, 255, 255, 0.15));
}

/* ============================================
   Poem Overlay
   ============================================ */
.glitch-poem {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: rgba(10, 14, 26, 0.95);
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
}

.glitch-poem.is-active {
  display: flex;
}

.glitch-poem__content {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  color: var(--color-accent);
  text-align: center;
  line-height: 2;
  max-width: 32rem;
  animation: poem-flicker 2s infinite, glitch-text 3s infinite;
}

.glitch-poem__content p {
  margin-bottom: var(--space-4);
}

/* Glitch-mode Tools nav link */
.main-nav__link--glitch {
  color: var(--color-accent) !important;
  animation: glitch-text 1.5s infinite, poem-flicker 2s step-end infinite;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: var(--text-xs) !important;
}

.glitch-poem__dismiss {
  position: fixed;
  bottom: var(--space-8);
  left: 50%;
  transform: translateX(-50%);
  color: var(--color-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  animation: poem-flicker 3s infinite;
}
