/* ============================================
   Glitch & Collapse Effects
   ============================================ */

/* === GLITCH TEXT === */
.glitch-text {
  position: relative;
  animation: glitchShift 8s infinite;
}

@keyframes glitchShift {
  0%, 95%, 100% { transform: none; filter: none; }
  96% { transform: translate(-2px, 1px); filter: hue-rotate(90deg); }
  97% { transform: translate(2px, -1px); filter: hue-rotate(-90deg); }
  98% { transform: translate(-1px, -2px); }
  99% { transform: translate(1px, 2px); filter: hue-rotate(180deg); }
}

/* === SCREEN SHAKE === */
.shake {
  animation: shake 0.15s infinite;
}

@keyframes shake {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -3px); }
  100% { transform: translate(2px, 3px); }
}

/* === SCREEN FLICKER === */
.flicker {
  animation: flicker 0.1s infinite;
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

/* === INVERT FLASH === */
.invert-flash {
  animation: invertFlash 0.05s;
}

@keyframes invertFlash {
  0% { filter: invert(1); transform: scaleX(-1); }
  100% { filter: invert(0); transform: scaleX(1); }
}

/* === TEXT CORRUPTION === */
.corrupt {
  animation: corrupt 3s infinite;
}

@keyframes corrupt {
  0%, 90%, 100% { opacity: 1; filter: none; }
  91% { opacity: 0.7; filter: blur(1px); }
  93% { opacity: 1; letter-spacing: 3px; }
  95% { opacity: 0.8; filter: hue-rotate(180deg); }
}

/* === RED NOISE OVERLAY === */
.red-noise {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 0;
  background: linear-gradient(90deg, transparent, rgba(139, 0, 0, 0.3), rgba(139, 0, 0, 0.6));
  z-index: 999;
  pointer-events: none;
  transition: width 3s;
}

.red-noise.active {
  width: 100%;
}

/* === SCANLINES === */
.scanlines::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.05) 2px,
    rgba(0, 0, 0, 0.05) 4px
  );
  pointer-events: none;
  z-index: 998;
}

/* === GHOST SILHOUETTE === */
.ghost-silhouette {
  position: fixed;
  width: 120px;
  height: 200px;
  background: linear-gradient(180deg, rgba(50,50,50,0.15) 0%, transparent 100%);
  border-radius: 60px 60px 0 0;
  pointer-events: none;
  z-index: 997;
  opacity: 0;
  transition: opacity 0.3s;
}

.ghost-silhouette.visible {
  opacity: 1;
  animation: ghostAppear 0.5s ease-out;
}

@keyframes ghostAppear {
  0% { opacity: 0; transform: translateY(20px); }
  30% { opacity: 0.6; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* === COLLAPSE SEQUENCE === */
.collapse-stage-1 body {
  animation: shake 0.2s infinite;
}

.collapse-stage-2 * {
  animation: corrupt 0.5s infinite !important;
}

.collapse-stage-3 body {
  animation: flicker 0.05s infinite, shake 0.1s infinite;
}

.collapse-whiteout {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 2s;
}

.collapse-whiteout.active {
  opacity: 1;
  pointer-events: all;
}

.collapse-whiteout .center-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  color: #1a1a1a;
  opacity: 0;
  font-family: var(--font-serif, serif);
  white-space: nowrap;
  letter-spacing: 0.1em;
}

.collapse-whiteout .center-text.show {
  animation: fadeInSlow 2s forwards;
}

@keyframes fadeInSlow {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === MIRROR CRACK === */
.mirror-crack {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: #fff;
  pointer-events: all;
}

.crack-line {
  position: absolute;
  background: #333;
  transform-origin: center;
}

.mirror-crack .shard {
  position: absolute;
  background: rgba(255,255,255,0.9);
  border: 1px solid #ccc;
  animation: shardFall 2s forwards;
}

@keyframes shardFall {
  0% { transform: none; opacity: 1; }
  100% { transform: translateY(100vh) rotate(45deg); opacity: 0; }
}

/* === FLASH TEXT (for beforeunload etc) === */
.flash-text {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--danger, #8b0000);
  font-size: 14px;
  opacity: 0;
  z-index: 9999;
  pointer-events: none;
  font-family: var(--font-serif, serif);
}

.flash-text.show {
  animation: flashShow 0.3s;
}

@keyframes flashShow {
  0% { opacity: 0; }
  20% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* === WARM GLOW (for ending) === */
.warm-glow {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(ellipse at center, rgba(255,220,150,0.3) 0%, transparent 70%);
  z-index: 9998;
  pointer-events: none;
  opacity: 0;
  transition: opacity 3s;
}

.warm-glow.active {
  opacity: 1;
}
