/* =========================================================
   XTREMEX — cyber glitch page transitions
   ========================================================= */

.glitch-transition {
  position: fixed;
  inset: 0;
  z-index: 9400;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  isolation: isolate;
}

.glitch-transition.is-active {
  visibility: visible;
  animation: glitchShell 780ms steps(1, end) both;
}

.glitch-transition__noise {
  position: absolute;
  inset: -16%;
  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.16) 0 1px,
      transparent 1px 4px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(216, 255, 63, 0.12) 0 1px,
      transparent 1px 3px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 73, 50, 0.1) 0 18px,
      transparent 18px 47px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(102, 92, 255, 0.12) 0 9px,
      transparent 9px 61px
    );
  background-size: 4px 100%, 100% 3px, 47px 100%, 100% 61px;
  mix-blend-mode: screen;
  opacity: 0.42;
  backdrop-filter: saturate(1.7) contrast(1.22) brightness(1.04);
  -webkit-backdrop-filter: saturate(1.7) contrast(1.22) brightness(1.04);
  animation: glitchNoise 140ms steps(2, end) infinite;
}

.glitch-transition__scan {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.11) 0 1px,
    transparent 1px 4px
  );
  mix-blend-mode: overlay;
  opacity: 0.48;
  animation: glitchScan 520ms linear infinite;
}

.glitch-transition__bands {
  position: absolute;
  inset: 0;
}

.glitch-transition__bands i {
  position: absolute;
  top: var(--y);
  left: -8%;
  width: 116%;
  height: var(--h);
  opacity: 0;
  background:
    linear-gradient(
      90deg,
      transparent 0%,
      rgba(216, 255, 63, 0.85) 6%,
      rgba(255, 255, 255, 0.98) 18%,
      rgba(255, 255, 255, 0.35) 24%,
      rgba(102, 92, 255, 0.9) 44%,
      rgba(255, 73, 50, 0.8) 62%,
      rgba(255, 255, 255, 0.6) 78%,
      transparent 100%
    );
  border-top: 1px solid rgba(255, 255, 255, 0.55);
  border-bottom: 1px solid rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px) hue-rotate(140deg) saturate(2.6) contrast(1.4);
  -webkit-backdrop-filter: blur(3px) hue-rotate(140deg) saturate(2.6) contrast(1.4);
  mix-blend-mode: screen;
  transform-origin: 50% 50%;
  will-change: transform, opacity;
}

.glitch-transition.is-active .glitch-transition__bands i {
  animation: glitchBand 780ms steps(1, end) var(--delay) both;
}

.glitch-transition__bands i:nth-child(2n) {
  mix-blend-mode: overlay;
  backdrop-filter: blur(1.5px) hue-rotate(-70deg) saturate(2.2);
  -webkit-backdrop-filter: blur(1.5px) hue-rotate(-70deg) saturate(2.2);
}

.glitch-transition__word {
  position: absolute;
  top: 50%;
  left: 50%;
  font-family: var(--display);
  font-size: clamp(70px, 16vw, 250px);
  line-height: 0.78;
  letter-spacing: -0.025em;
  text-transform: uppercase;
  white-space: nowrap;
  color: rgba(216, 255, 63, 0.14);
  -webkit-text-stroke: 2px rgba(216, 255, 63, 0.95);
  text-shadow:
    8px 0 0 rgba(102, 92, 255, 0.85),
    -8px 0 0 rgba(255, 73, 50, 0.8),
    0 0 60px rgba(216, 255, 63, 0.45);
  mix-blend-mode: screen;
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
}

.glitch-transition.is-active .glitch-transition__word {
  animation: glitchWord 780ms steps(1, end) both;
}

.glitch-transition__frame {
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(216, 255, 63, 0.2);
  clip-path: polygon(
    0 0,
    calc(100% - 26px) 0,
    100% 26px,
    100% 100%,
    26px 100%,
    0 calc(100% - 26px)
  );
  box-shadow:
    inset 0 0 90px rgba(102, 92, 255, 0.09),
    inset 0 0 20px rgba(216, 255, 63, 0.05);
}

.glitch-transition__frame::before,
.glitch-transition__frame::after {
  content: "";
  position: absolute;
  width: 74px;
  height: 74px;
  border-color: var(--acid);
  border-style: solid;
  opacity: 0.62;
}

.glitch-transition__frame::before {
  top: 10px;
  left: 10px;
  border-width: 1px 0 0 1px;
}

.glitch-transition__frame::after {
  right: 10px;
  bottom: 10px;
  border-width: 0 1px 1px 0;
}

.glitch-transition__hud {
  position: absolute;
  right: clamp(22px, 4vw, 58px);
  bottom: clamp(22px, 4vw, 48px);
  left: clamp(22px, 4vw, 58px);
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--acid);
  text-transform: uppercase;
  text-shadow:
    2px 0 0 rgba(255, 73, 50, 0.75),
    -2px 0 0 rgba(102, 92, 255, 0.75);
  animation: glitchHud 110ms steps(2, end) infinite;
}

.glitch-transition__hud::before,
.glitch-transition__hud::after {
  content: "";
  height: 1px;
  background: currentColor;
  opacity: 0.36;
}

.glitch-transition__hud::before {
  flex: 1;
}

.glitch-transition__hud::after {
  width: 50px;
}

.glitch-transition__hud b {
  font-weight: 400;
  color: var(--bone);
}

.glitch-transition__flash {
  position: absolute;
  inset: 0;
  background: var(--acid);
  mix-blend-mode: color-dodge;
  opacity: 0;
}

.glitch-transition.is-active .glitch-transition__flash {
  animation: glitchFlash 780ms steps(1, end) both;
}

body.is-glitching #main,
body.is-glitching .site-header,
body.is-glitching .mobile-menu {
  animation: pageSignalBreak 780ms steps(1, end) both;
  will-change: transform;
}

body.is-glitching .site-header {
  filter: hue-rotate(28deg) contrast(1.25) saturate(1.4);
}

@keyframes glitchShell {
  0% { opacity: 0; }
  4% { opacity: 1; }
  7% { opacity: 0.44; }
  11% { opacity: 1; }
  63% { opacity: 1; }
  80% { opacity: 0.34; }
  100% { opacity: 0; }
}

@keyframes glitchNoise {
  0% { transform: translate3d(-1.5%, 0.5%, 0) scale(1.04); }
  25% { transform: translate3d(1%, -1%, 0) scale(1.06); }
  50% { transform: translate3d(-0.5%, 1.5%, 0) scale(1.03); }
  75% { transform: translate3d(1.8%, 0.4%, 0) scale(1.07); }
  100% { transform: translate3d(-1%, -1.2%, 0) scale(1.05); }
}

@keyframes glitchScan {
  to { background-position: 0 8px; }
}

@keyframes glitchBand {
  0%, 100% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scaleX(0.82);
  }
  4% {
    opacity: 0.96;
    transform: translate3d(var(--x), 0, 0) scaleX(1);
  }
  8% {
    opacity: 0.58;
    transform: translate3d(calc(var(--x) * -0.55), 1px, 0) scaleX(0.92);
  }
  12% {
    opacity: 0.92;
    transform: translate3d(var(--x), -1px, 0) scaleX(1.04);
  }
  18% {
    opacity: 0.34;
    transform: translate3d(calc(var(--x) * 0.4), 0, 0) scaleX(0.95);
  }
  24% {
    opacity: 0.8;
    transform: translate3d(calc(var(--x) * -0.3), 1px, 0) scaleX(1.02);
  }
  30% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scaleX(0.8);
  }
  44% {
    opacity: 0.82;
    transform: translate3d(calc(var(--x) * 0.35), 0, 0) scaleX(1);
  }
  48% {
    opacity: 0.48;
    transform: translate3d(var(--x), 0, 0) scaleX(1.02);
  }
  52% {
    opacity: 0.9;
    transform: translate3d(calc(var(--x) * -0.6), -1px, 0) scaleX(1.03);
  }
  58% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scaleX(0.8);
  }
  70% {
    opacity: 0.7;
    transform: translate3d(calc(var(--x) * 0.2), 0, 0) scaleX(1);
  }
  76% {
    opacity: 0.32;
    transform: translate3d(var(--x), 0, 0) scaleX(0.96);
  }
  84% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scaleX(0.8);
  }
}

@keyframes glitchWord {
  0% {
    opacity: 0;
    transform: translate(-48%, -50%) skewX(-2deg) scaleX(1.08);
  }
  8% {
    opacity: 0.56;
    transform: translate(-50%, -50%) skewX(10deg) scaleX(1.02);
  }
  12% {
    opacity: 0.22;
    transform: translate(-52%, -50%) skewX(-14deg) scaleX(1.1);
  }
  18% {
    opacity: 0.52;
    transform: translate(-50%, -50%) skewX(2deg) scaleX(1);
  }
  70% { opacity: 0.36; }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) skewX(-6deg) scaleX(1.15);
  }
}

@keyframes glitchHud {
  0%, 100% { transform: translateX(0); opacity: 0.72; }
  50% { transform: translateX(2px); opacity: 1; }
}

@keyframes glitchFlash {
  0%, 100% { opacity: 0; }
  6% { opacity: 0.17; }
  8% { opacity: 0; }
  31% { opacity: 0.1; }
  33% { opacity: 0; }
  61% { opacity: 0.14; }
  63% { opacity: 0; }
}

@keyframes pageSignalBreak {
  0%, 100% { transform: translate3d(0, 0, 0); }
  4% { transform: translate3d(-16px, 0, 0) skewX(1.6deg); }
  6% { transform: translate3d(22px, -2px, 0) skewX(-2.6deg); }
  9% { transform: translate3d(-9px, 2px, 0) skewX(0.9deg); }
  12% { transform: translate3d(6px, 0, 0) skewX(-0.5deg); }
  15% { transform: translate3d(0, 0, 0); }
  42% { transform: translate3d(14px, 0, 0) skewX(-1.2deg); }
  45% { transform: translate3d(-18px, 1px, 0) skewX(1.8deg); }
  48% { transform: translate3d(5px, 0, 0) skewX(-0.6deg); }
  51% { transform: translate3d(0, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .glitch-transition {
    display: none !important;
  }

  body.is-glitching #main,
  body.is-glitching .site-header,
  body.is-glitching .mobile-menu {
    animation: none !important;
  }
}

/* =========================================================
   COMPACT / PHONE — glitch effects stay off so low-end
   devices and slow connections keep a steady frame rate
   ========================================================= */

@media (max-width: 720px) {
  .glitch-transition {
    display: none !important;
  }

  body.is-glitching #main,
  body.is-glitching .site-header,
  body.is-glitching .mobile-menu {
    animation: none !important;
    filter: none !important;
    transform: none !important;
  }

  .hero.is-core-morphing .hero__canvas-wrap {
    animation: none !important;
  }

  .jersey.is-morphing .jersey__scan,
  .jersey.is-morphing .jersey__shards {
    animation: none !important;
    opacity: 0 !important;
  }

  .jersey.is-morphing .jersey__image {
    animation: none !important;
  }

  /* the film-grain overlay stops shuffling every 350ms */
  .grain {
    animation: none !important;
  }
}

