/*
  «Взлом эфира» (логика — js/hijack.js).

  body.is-glitching — помехи: эфир «ломается» (перед видео и когда эфир возвращается)
  body.is-hacked    — в эфире видео: страница выглядит перехваченной

  Помехи сделаны без ярких вспышек на весь экран (только рывки, цветные разрывы и шум),
  чтобы не навредить людям с чувствительностью к мерцанию.
  !important у анимаций нужен, чтобы эффект был виден и при отключённых в системе анимациях:
  это короткое редкое событие, а не постоянное движение.
*/

/* когда страницу дёргает помехами, она не должна показывать горизонтальную прокрутку */
html { overflow-x: clip; }

/* ---------- видео в квадрате обложки ---------- */

.cover-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* ---------- слой помех поверх обложки ---------- */

.glitch {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  /* строки развёртки + «снег» */
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.28) 0 1px, transparent 1px 3px),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* разрывы строк: три цветные полосы, которые скачут по высоте */
.glitch i {
  position: absolute;
  left: -6%;
  width: 112%;
  opacity: 0;
  mix-blend-mode: screen;
}
.glitch i:nth-child(1) { height: 9%; background: rgba(255, 0, 70, 0.55); }
.glitch i:nth-child(2) { height: 5%; background: rgba(0, 255, 230, 0.45); }
.glitch i:nth-child(3) { height: 13%; background: rgba(239, 234, 223, 0.3); }

/* ---------- помехи ---------- */

body.is-glitching .glitch {
  opacity: 0.85;
  animation: glitch-noise 0.24s steps(4) infinite !important;
}
body.is-glitching .glitch i { opacity: 1; }
body.is-glitching .glitch i:nth-child(1) { animation: glitch-bar-a 0.5s steps(1) infinite !important; }
body.is-glitching .glitch i:nth-child(2) { animation: glitch-bar-b 0.37s steps(1) infinite !important; }
body.is-glitching .glitch i:nth-child(3) { animation: glitch-bar-c 0.61s steps(1) infinite !important; }

/* содержимое обложки дёргается и «плывёт» по цвету */
body.is-glitching .cover-img,
body.is-glitching .cover-video,
body.is-glitching .cover-empty,
body.is-glitching .cover-top {
  animation: glitch-jitter 0.32s steps(1) infinite !important;
}

/* остальная страница рвётся рывками */
body.is-glitching .topbar,
body.is-glitching .live-control,
body.is-glitching .chat,
body.is-glitching .mir-mark,
body.is-glitching .side-right,
body.is-glitching .bottom {
  animation: glitch-page 0.9s steps(1) infinite !important;
}
body.is-glitching .chat,
body.is-glitching .bottom { animation-delay: -0.3s !important; }
body.is-glitching .side-right { animation-delay: -0.55s !important; }

/* ---------- в эфире видео ---------- */

body.is-hacked .glitch { opacity: 0.32; }
body.is-hacked.is-glitching .glitch { opacity: 0.85; }

body.is-hacked .cover {
  border-color: var(--live);
  box-shadow: 0 0 0 1px var(--live), 0 0 44px rgba(255, 59, 48, 0.22);
}
body.is-hacked .cover-shade {
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent 34%),
    linear-gradient(to top, rgba(0, 0, 0, 0.3), transparent 24%);
}
/* цветное расслоение текста, как на плохом сигнале */
body.is-hacked .cover-now small,
body.is-hacked .cover-now h1 {
  text-shadow: 2px 0 rgba(255, 0, 70, 0.85), -2px 0 rgba(0, 255, 230, 0.85);
}
body.is-hacked .cover-now small { color: var(--live); text-shadow: none; }
body.is-hacked .live { color: var(--live); }

/* ---------- ключевые кадры ---------- */

@keyframes glitch-noise {
  0% { background-position: 0 0, 0 0; }
  25% { background-position: 0 1px, -37px 61px; }
  50% { background-position: 0 2px, 53px -29px; }
  75% { background-position: 0 0, -71px -47px; }
  100% { background-position: 0 1px, 19px 83px; }
}

@keyframes glitch-bar-a {
  0% { top: 12%; transform: translateX(-3%); }
  25% { top: 61%; transform: translateX(4%); }
  50% { top: 34%; transform: translateX(-1%); }
  75% { top: 80%; transform: translateX(2%); }
}
@keyframes glitch-bar-b {
  0% { top: 70%; transform: translateX(3%); }
  33% { top: 22%; transform: translateX(-4%); }
  66% { top: 49%; transform: translateX(1%); }
}
@keyframes glitch-bar-c {
  0% { top: 40%; transform: translateX(2%); }
  20% { top: 5%; transform: translateX(-3%); }
  40% { top: 66%; transform: translateX(4%); }
  60% { top: 27%; transform: translateX(-2%); }
  80% { top: 86%; transform: translateX(1%); }
}

@keyframes glitch-jitter {
  0% { transform: translate(0, 0); filter: none; }
  14% { transform: translate(-7px, 2px) skewX(-3deg); filter: hue-rotate(70deg) saturate(2); }
  28% { transform: translate(0, 0); filter: none; }
  43% { transform: translate(6px, -3px) skewX(2deg); filter: hue-rotate(-50deg) saturate(1.8); }
  57% { transform: translate(-2px, 0) scaleY(1.03); filter: saturate(2.4) contrast(1.15); }
  71% { transform: translate(0, 0); filter: none; }
  86% { transform: translate(9px, 1px) skewX(-5deg); filter: hue-rotate(140deg); }
}

@keyframes glitch-page {
  0% { transform: none; filter: none; }
  11% { transform: translateX(-8px) skewX(-7deg); }
  14% { transform: none; }
  36% { transform: translate(6px, -2px); filter: hue-rotate(80deg); }
  40% { transform: none; filter: none; }
  62% { transform: translateX(-4px) skewX(5deg) scaleX(1.02); }
  66% { transform: none; }
  84% { transform: translate(10px, 2px) skewX(-3deg); filter: hue-rotate(-60deg) saturate(2); }
  88% { transform: none; filter: none; }
}
