.glitch {
  position: relative;
  font-size: 80px;
  font-weight: bold;
  color: white;
  letter-spacing: 5px;
}

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

.glitch::before {
  left: 2px;
  text-shadow: -1px 0 red;
  clip-path: inset(44% 0 61% 0);
  animation: glitch-anim-1 2.5s infinite linear alternate-reverse;
}

.glitch::after {
  left: -2px;
  text-shadow: -1px 0 blue;
  clip-path: inset(54% 0 10% 0);
  animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

@keyframes glitch-anim-1 {
  0% { clip-path: inset(20% 0 80% 0); }
  20% { clip-path: inset(60% 0 10% 0); }
  40% { clip-path: inset(40% 0 50% 0); }
  60% { clip-path: inset(80% 0 5% 0); }
  80% { clip-path: inset(10% 0 70% 0); }
  100% { clip-path: inset(30% 0 20% 0); }
}

@keyframes glitch-anim-2 {
  0% { clip-path: inset(10% 0 60% 0); }
  20% { clip-path: inset(30% 0 10% 0); }
  40% { clip-path: inset(50% 0 30% 0); }
  60% { clip-path: inset(10% 0 80% 0); }
  80% { clip-path: inset(70% 0 10% 0); }
  100% { clip-path: inset(20% 0 40% 0); }
}

/* --- Layout / Full Page Glitch --- */

.layout-glitch {
    animation: layout-shake 0.2s infinite, layout-rgb 0.5s infinite;
    position: relative;
    /* Ensure it can be moved slightly without causing scrollbars */
    overflow: hidden; 
}

@keyframes layout-shake {
    0% { transform: translate(0, 0) skew(0deg); }
    20% { transform: translate(-2px, 2px) skew(0.5deg); }
    40% { transform: translate(2px, -2px) skew(-0.5deg); }
    60% { transform: translate(-2px, -2px) skew(0deg); }
    80% { transform: translate(2px, 2px) skew(0.5deg); }
    100% { transform: translate(0, 0) skew(0deg); }
}

@keyframes layout-rgb {
    0% { filter: drop-shadow(2px 0 red) drop-shadow(-2px 0 blue); }
    50% { filter: drop-shadow(-2px 0 red) drop-shadow(2px 0 blue); }
    100% { filter: drop-shadow(2px 0 red) drop-shadow(-2px 0 blue); }
}

/* --- CRT Scanlines Overlay --- */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(
        to bottom,
        rgba(255,255,255,0),
        rgba(255,255,255,0) 50%,
        rgba(0,0,0,0.2) 50%,
        rgba(0,0,0,0.2)
    );
    background-size: 100% 4px;
    z-index: 9999;
    pointer-events: none; /* Let clicks pass through */
    animation: scanline-scroll 0.2s linear infinite;
    opacity: 0.3;
    transition: opacity 1s ease-out;
}

.scanlines.fade-out {
    opacity: 0;
}

@keyframes scanline-scroll {
    0% { background-position: 0 0; }
    100% { background-position: 0 4px; }
}