:root {
  --ink: #0e0d0c;
  --paper: #f1ede4;
  --accent: #c8141c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--ink);
  color: var(--paper);
}

body {
  font-family: 'PT Serif', Georgia, serif;
  overflow-x: hidden;
}

#loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: 'Oswald', sans-serif;
  letter-spacing: .2em;
  text-transform: uppercase;
  z-index: 100;
  background: var(--ink);
  transition: opacity .5s;
}
#loader.done { opacity: 0; pointer-events: none; }
#loader.error { color: var(--accent); text-transform: none; letter-spacing: 0; padding: 24px; text-align: center; }

/* ---------- Сцена: длинная секция + липкая сцена на весь экран ---------- */

.scene { position: relative; }

.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}

.frame { position: absolute; inset: 0; }

.camera {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}
.camera img {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.camera .page { width: 100%; height: 100%; }

/* Вырезанный слой переднего плана (2.5D) */
.camera .layer {
  position: absolute;
  transform-origin: 0 0;
  pointer-events: none;
}
.debug .camera .layer { outline: 3px dashed #ff3d8b; }

/* Живая панель: WebGL-холст поверх своей панели, виден только пока она «дышит» */
.camera .living {
  position: absolute;
  pointer-events: none;
  visibility: hidden;
}

/* Дым и блёстки поверх страницы */
.camera .particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Красный тон: белое становится красным, чёрное остаётся чёрным. Цвет шага — tone в story.js */
.tint {
  position: absolute;
  inset: 0;
  background: var(--tone, var(--accent));
  mix-blend-mode: multiply;
  opacity: 0;
  pointer-events: none;
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, .55));
}

.fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

/* ---------- Игровое окно (hud) ----------
   Страницы белые, поэтому строки развёртки и полоса ложатся умножением, а свечение рамки — поверх */
.camera .hud { position: absolute; pointer-events: none; opacity: 0; --c: var(--hud, #1fc8f2); }
.hud-pix, .hud-split, .hud-slice, .hud-lines, .hud-glow, .hud-sweep { position: absolute; inset: 0; }
.hud-pix { width: 100%; height: 100%; image-rendering: pixelated; opacity: 0; }
.hud-split { background: #000; isolation: isolate; opacity: 0; }
.hud-r, .hud-gb { position: absolute; inset: 0; background-repeat: no-repeat; mix-blend-mode: screen; }
.hud-r { filter: url(#only-r); }
.hud-gb { filter: url(#only-gb); }
.hud-slice { background-repeat: no-repeat; opacity: 0; }
.hud-lines {
  background: repeating-linear-gradient(to bottom, color-mix(in srgb, var(--c) 30%, transparent) 0 1px, transparent 1px 4px);
  mix-blend-mode: multiply;
}
.hud-glow {
  inset: -1px;
  opacity: 0;
  box-shadow: 0 0 0 2px var(--c), 0 0 18px 4px color-mix(in srgb, var(--c) 70%, transparent), inset 0 0 22px color-mix(in srgb, var(--c) 55%, transparent);
}
.hud.on .hud-glow { animation: hud-breathe 2.4s ease-in-out infinite; }
.hud-sweep {
  bottom: auto;
  height: 22%;
  opacity: 0;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--c) 55%, transparent) 72%, var(--c) 96%, transparent);
  mix-blend-mode: multiply;
}
@keyframes hud-breathe { 50% { opacity: .55; } }

/* ---------- Плашки с текстом ---------- */

.caption {
  position: absolute;
  max-width: min(34ch, 84vw);
  padding: .8em 1.05em;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  font-size: clamp(15px, 1.5vw, 20px);
  line-height: 1.45;
  font-style: italic;
  opacity: 0;
  visibility: hidden;
}
.caption.top-left     { top: 7vh;    left: 5vw; }
.caption.top-right    { top: 7vh;    right: 5vw; }
.caption.bottom-left  { bottom: 8vh; left: 5vw; }
.caption.bottom-right { bottom: 8vh; right: 5vw; }

/* ---------- Титульный экран ---------- */

.stage.paper { background: var(--paper); color: var(--ink); }

.title-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 7vw;
}
.title-wrap h1 {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  font-size: clamp(48px, 10vw, 150px);
  line-height: .92;
  letter-spacing: -.01em;
}
.title-wrap h1 .ch { display: inline-block; }
.title-wrap .kicker,
.title-wrap .hint {
  font-family: 'Oswald', sans-serif;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .25em;
  font-size: 13px;
}
.title-wrap .kicker { margin-bottom: 3vh; color: var(--accent); }
.title-wrap .hint { margin-top: 5vh; opacity: .6; }

.credit {
  position: absolute;
  left: 7vw;
  bottom: 5vh;
  font-family: 'Oswald', sans-serif;
  font-weight: 500;
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  opacity: .55;
}

.end {
  position: relative;
  height: 100vh;
  display: grid;
  place-content: center;
  text-align: center;
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: .25em;
  font-size: 14px;
  opacity: .7;
}

/* ---------- Режим отладки (?debug) ---------- */

.debug-shapes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.debug-shapes polygon {
  fill: rgba(0, 224, 255, .08);
  stroke: #00e0ff;
  stroke-width: 3px;
  vector-effect: non-scaling-stroke;
}
.debug-label {
  position: absolute;
  padding: 4px 10px;
  background: #00e0ff;
  color: #000;
  font: 700 28px/1 'Oswald', sans-serif;
  pointer-events: none;
}

/* ---------- Навигация: на главную, прогресс чтения, назад в конце ---------- */

.home {
  position: fixed;
  top: 14px;
  left: 16px;
  z-index: 50;
  color: #fff;
  mix-blend-mode: difference;
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .25em;
  text-transform: uppercase;
  text-decoration: none;
}

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 50;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 0;
  pointer-events: none;
}

.end .back {
  justify-self: center;
  margin-top: 5vh;
  padding-bottom: 3px;
  border-bottom: 1px solid currentColor;
  color: var(--paper);
  text-decoration: none;
}
.end .back:hover { color: var(--accent); }

.end .next {
  justify-self: center;
  margin-top: 5vh;
  padding: 12px 22px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 16px;
  text-decoration: none;
}
.end .next:hover { background: var(--accent); color: var(--paper); }
.end .next + .back { margin-top: 3vh; }

/* ---------- Вебтун: лента кадров встык (engine/strip.js) ---------- */

.stage.ink { background: var(--ink); color: var(--paper); }

.strip { position: relative; }
.strip-col { width: min(100%, 720px); margin: 0 auto; }

/* Кадры заходят друг на друга на пиксель: иначе на стыках дробных высот просвечивает фон */
.seg { position: relative; overflow: hidden; background: #111; }
.seg + .seg { margin-top: -1px; }
.seg-zoom, .seg-hit { position: absolute; inset: 0; }
.seg img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.seg-label {
  position: absolute; left: 6px; top: 6px; z-index: 5; padding: 2px 8px;
  background: #00e0ff; color: #000; font: 700 16px/1.2 'Oswald', sans-serif;
}

.strip-fx { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.strip-particles, .strip-speed { position: absolute; inset: 0; width: 100%; height: 100%; }
.strip-flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
.strip-blood { position: absolute; inset: 0; background: #b3001b; mix-blend-mode: multiply; opacity: 0; }
.strip-edges {
  position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(120% 85% at 50% 50%, transparent 52%, rgba(190, 0, 24, .8));
}

/* Сбой: копии кадра без одного из каналов складываются «экраном» и разъезжаются */
.glitch, .holo, .tv, .tv-roll, .seg-glow { position: absolute; pointer-events: none; }
.glitch { opacity: 0; }
.glitch-split { position: absolute; inset: 0; background: #000; isolation: isolate; }
.glitch-r, .glitch-gb, .glitch-slice { position: absolute; inset: 0; background-repeat: no-repeat; }
.glitch-r { filter: url(#only-r); mix-blend-mode: screen; }
.glitch-gb { filter: url(#only-gb); mix-blend-mode: screen; }
.channel-filters { position: absolute; width: 0; height: 0; }

/* Системное окно: светящаяся рамка, строки развёртки, полоса сканирования */
.holo { opacity: 0; transition: opacity .5s; --c: #5fd8ff; }
.holo.on { opacity: 1; }
.holo-body {
  position: absolute; inset: 0;
  box-shadow: 0 0 18px 2px color-mix(in srgb, var(--c) 65%, transparent), inset 0 0 22px color-mix(in srgb, var(--c) 45%, transparent);
  background: repeating-linear-gradient(to bottom, color-mix(in srgb, var(--c) 18%, transparent) 0 1px, transparent 1px 4px);
  mix-blend-mode: screen;
  animation: holo-breathe 2.6s ease-in-out infinite;
}
.holo-sweep {
  position: absolute; left: 0; right: 0; top: 0; height: 22%; opacity: 0;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--c) 70%, transparent) 70%, #fff 96%, transparent);
  mix-blend-mode: screen;
}
@keyframes holo-breathe { 50% { opacity: .55; } }
.holo.soft { -webkit-mask-image: radial-gradient(closest-side, #000 55%, transparent); mask-image: radial-gradient(closest-side, #000 55%, transparent); }
.holo.soft .holo-body { box-shadow: none; }

/* Помехи и бегущая полоса */
.tv { opacity: 0; image-rendering: pixelated; mix-blend-mode: screen; }
.tv-roll { overflow: hidden; }
.tv-roll::after {
  content: ''; position: absolute; left: 0; right: 0; height: 14%; top: -14%;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, .14), transparent);
}
.tv-roll.on::after { animation: tv-roll 2.2s linear infinite; }
@keyframes tv-roll { to { top: 100%; } }

/* Мягкий свет: экран телефона, глаз, рога */
.seg-glow { opacity: 0; mix-blend-mode: screen; --c: #fff; }
.seg-glow::before {
  content: ''; position: absolute; inset: -12%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 55%, transparent), transparent);
  animation: glow-pulse 2.4s ease-in-out infinite;
}
@keyframes glow-pulse { 50% { opacity: .45; transform: scale(.96); } }

@media (prefers-reduced-motion: reduce) {
  .hud.on .hud-glow,
  .holo-body, .seg-glow::before, .tv-roll.on::after { animation: none; }
}
