/* CRT treatment: one fixed overlay pair over everything, pointer-events none.
   ::before = scanlines + vignette (vignette stays under reduced motion),
   ::after  = stepped noise (dropped under reduced motion). Off in light theme. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 900;
  opacity: var(--crt-on);
}
body::before {
  background:
    radial-gradient(ellipse 115% 100% at 50% 50%, transparent 50%, rgba(0, 0, 0, .7) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, var(--crt-scan-opacity)) 0 1px, transparent 1px 2px);
  mix-blend-mode: multiply;
}
body::after {
  background: url("../assets/img/noise.svg") repeat;
  background-size: 160px 160px;
  opacity: calc(var(--crt-on) * .06);
  animation: crt-noise 1s steps(6) infinite;
}
@keyframes crt-noise {
  0% { background-position: 0 0; }
  20% { background-position: -40px 20px; }
  40% { background-position: 30px -50px; }
  60% { background-position: -70px -10px; }
  80% { background-position: 50px 60px; }
  100% { background-position: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  body::after { display: none; }
  body::before { background: radial-gradient(ellipse 120% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, .55) 100%); }
}

/* CRT screen frame: a convex, barrel-shaped glass for project media. */
.crt-frame {
  position: relative;
  border-radius: 12% / 16%;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #000;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .05),
    inset 0 0 60px rgba(0, 0, 0, .85),
    0 30px 60px -30px rgba(0, 0, 0, .6);
  isolation: isolate;
}
.crt-frame > img,
.crt-frame > video,
.crt-frame > picture > img,
.crt-frame > svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(.85) contrast(1.05);
  transform: scale(1.04);  /* slight bulge into the curved edge */
}
.crt-frame::before {  /* scanlines inside the glass */
  content: "";
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, .28) 0 1px, transparent 1px 3px);
}
.crt-frame::after {   /* diagonal glare + edge falloff */
  content: "";
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  border-radius: inherit;
  background:
    linear-gradient(125deg, rgba(255, 255, 255, .16) 0%, rgba(255, 255, 255, .04) 22%, transparent 40%),
    radial-gradient(ellipse 90% 80% at 50% 50%, transparent 60%, rgba(0, 0, 0, .55) 100%);
}

/* Chapter glitch cut: 180ms, horizontal slices offset ±8px plus RGB split. */
.glitch-cut {
  animation: glitch-cut 180ms steps(1, end) 1;
}
@keyframes glitch-cut {
  0%   { clip-path: inset(0 0 72% 0); transform: translateX(-8px); text-shadow: 2px 0 #ff2a4f, -2px 0 var(--accent); }
  25%  { clip-path: inset(18% 0 46% 0); transform: translateX(8px); text-shadow: -2px 0 #ff2a4f, 2px 0 var(--accent); }
  50%  { clip-path: inset(48% 0 22% 0); transform: translateX(-5px); text-shadow: 3px 0 #ff2a4f, -3px 0 var(--accent); }
  75%  { clip-path: inset(70% 0 0 0); transform: translateX(6px); text-shadow: -1px 0 #ff2a4f, 1px 0 var(--accent); }
  100% { clip-path: inset(0); transform: none; text-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  .glitch-cut { animation: none; }
}

/* ───────────────────────── Chapter cut (js/glitch.js) */
.cut-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.is-cutting { filter: url(#cut); }
/* The surge: a brief scanline + noise flash over the stages (below the header and its fade). */
.cut-surge {
  position: fixed; inset: 0; z-index: 780; pointer-events: none; opacity: 0;
  background:
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, .14) 0 1px, transparent 1px 3px),
    url("../assets/img/noise.svg") repeat;
  background-size: auto, 120px 120px;
  mix-blend-mode: screen;
}
[data-theme="light"] .cut-surge { mix-blend-mode: multiply; background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, .16) 0 1px, transparent 1px 3px), url("../assets/img/noise.svg") repeat; background-size: auto, 120px 120px; }
.cut-surge.is-on { animation: cut-surge 400ms steps(8, end) 1; }
@keyframes cut-surge {
  0% { opacity: 0; }
  12% { opacity: .4; background-position: 0 0, 30px 10px; }
  37% { opacity: .1; background-position: 0 1px, -20px 40px; }
  62% { opacity: .28; background-position: 0 0, 50px -10px; }
  100% { opacity: 0; }
}
/* Reduced motion: no glitch, only a plain 150ms cross-fade into the new chapter. */
.cut-fade { animation: cut-fade 150ms linear 1 !important; }
@keyframes cut-fade { from { opacity: .35; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .cut-surge, .cut-surge.is-on { display: none; }
  .cut-fade { animation-duration: 150ms !important; }
}
