/* ============================================================================
   HAUNT LAYER — Doom's corruption of synth-report.com (plan T9b, [CA-11]).
   ADD-ONLY. Everything is scoped under html.haunted, which haunt.js adds ONLY
   inside the D9 time window. The site keeps working underneath: every layer
   here is pointer-events:none, nothing hides or replaces the server-rendered
   #feed markup, and removing the class (or the two includes) fully reverts it.
   Visual language follows the Doom storyboard: a skull built from code
   glyphs (bone / crimson / teal), red eyes, code shedding from the cranium,
   crimson routes. No "infected" banners, no security-warning language, no
   prompts, no fields.

   Never put `filter`, `transform` or animated `opacity` on <body>: any of
   them turns body into the containing block for the site's position:fixed
   UI (present chip, help overlay, broadcast stage) and breaks it.
   ============================================================================ */

html.haunted {
  --doom-crimson: #ff1f5a;
  --doom-blood:   #8a0d2e;
  --doom-bone:    #ddd3c9;
  --doom-teal:    #3fd0d4;

  /* Doom repaints the Report's own palette */
  --bg-0:      #050104;
  --bg-1:      #0f0309;
  --bg-2:      #1a0510;
  --fg:        #efe6dd;
  --fg-dim:    #c2b1ab;
  --magenta:   var(--doom-crimson);
  --magenta-2: #ff6b92;
  --cyan:      var(--doom-teal);
  --purple:    #6e0f2e;
  --grid:      rgba(255, 31, 90, 0.10);
}
html.haunted, html.haunted body { background: var(--bg-0); }
/* body as its own stacking context, so the skull and glyph layers (z-index -1)
   paint above the page background but under the content. isolation does not
   change the containing block of fixed elements, unlike filter/transform. */
html.haunted body { isolation: isolate; }

/* the ambient horizon glow turns to a blood-red bleed */
html.haunted body::before {
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%,  rgba(138, 13, 46, 0.35), transparent 62%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(255, 31, 90, 0.14), transparent 60%),
    linear-gradient(180deg, #050104 0%, #12030b 50%, #050104 100%);
}

/* ---------- the skull: fixed, behind the content ---------- */
.doom-skull {
  position: fixed; left: 50%; top: 52vh; z-index: -1; pointer-events: none;
  width: min(92vw, 860px); aspect-ratio: 1;
  transform: translate(-50%, -50%);
  /* --doom-p (0 → 1, set by haunt.js) is how far Doom has spread */
  /* hidden most of the time: haunt.js blinks it in and out (see blinkSkull) */
  opacity: 0; mix-blend-mode: screen;
  animation: doom-breathe 9s ease-in-out infinite;
}
.doom-skull img { width: 100%; height: 100%; display: block; }
.doom-skull .eye {
  position: absolute; top: 40.5%; width: 13%; aspect-ratio: 1; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255,40,90,0.95) 0%, rgba(255,20,70,0.45) 30%, transparent 70%);
  mix-blend-mode: screen; animation: doom-eye 4.2s ease-in-out infinite;
}
.doom-skull .eye.l { left: 39.2%; }
.doom-skull .eye.r { left: 63.1%; }
@keyframes doom-breathe {
  0%,100% { transform: translate(-50%, -50%) scale(1); }
  50%     { transform: translate(-50%, -51%) scale(1.025); }
}
@keyframes doom-eye {
  0%,100% { opacity: 0.75; } 45% { opacity: 1; } 50% { opacity: 0.45; } 55% { opacity: 1; }
}

/* the infection: crimson blooms spreading across the bone, two masked copies
   of the skull whose mask radii grow and recede */
@property --i1 { syntax: "<percentage>"; inherits: false; initial-value: 8%; }
@property --i2 { syntax: "<percentage>"; inherits: false; initial-value: 6%; }
@property --i3 { syntax: "<percentage>"; inherits: false; initial-value: 4%; }
.doom-skull .infect {
  position: absolute; inset: 0;
  background: url(/doom-skull.webp) center / 100% 100% no-repeat;
  filter: grayscale(1) sepia(1) saturate(12) hue-rotate(-48deg) brightness(1.2) contrast(1.45);
  mix-blend-mode: screen; opacity: calc(0.2 + 0.15 * var(--doom-p, 0));
  -webkit-mask-image:
    radial-gradient(circle at 32% 22%, #000 var(--i1), transparent calc(var(--i1) + 14%)),
    radial-gradient(circle at 70% 30%, #000 var(--i2), transparent calc(var(--i2) + 12%)),
    radial-gradient(circle at 50% 80%, #000 var(--i3), transparent calc(var(--i3) + 12%));
          mask-image:
    radial-gradient(circle at 32% 22%, #000 var(--i1), transparent calc(var(--i1) + 14%)),
    radial-gradient(circle at 70% 30%, #000 var(--i2), transparent calc(var(--i2) + 12%)),
    radial-gradient(circle at 50% 80%, #000 var(--i3), transparent calc(var(--i3) + 12%));
  animation: doom-infect 11s ease-in-out infinite alternate;
}
.doom-skull .infect.b {
  filter: grayscale(1) sepia(1) saturate(14) hue-rotate(-62deg) brightness(1.05) contrast(1.5);
  -webkit-mask-image:
    radial-gradient(circle at 18% 55%, #000 var(--i1), transparent calc(var(--i1) + 12%)),
    radial-gradient(circle at 84% 60%, #000 var(--i2), transparent calc(var(--i2) + 12%)),
    radial-gradient(circle at 55% 6%,  #000 var(--i3), transparent calc(var(--i3) + 14%));
          mask-image:
    radial-gradient(circle at 18% 55%, #000 var(--i1), transparent calc(var(--i1) + 12%)),
    radial-gradient(circle at 84% 60%, #000 var(--i2), transparent calc(var(--i2) + 12%)),
    radial-gradient(circle at 55% 6%,  #000 var(--i3), transparent calc(var(--i3) + 14%));
  animation-duration: 14s; animation-delay: -6s;
}
@keyframes doom-infect {
  0%   { --i1: 6%;  --i2: 4%;  --i3: 2%; }
  50%  { --i1: 20%; --i2: 16%; --i3: 12%; }
  100% { --i1: 18%; --i2: 14%; --i3: 11%; }
}
/* the skull itself tears now and then (haunt.js adds .glitch for a moment).
   `translate` composes with the breathing transform instead of replacing it. */
.doom-skull.glitch {
  animation: doom-breathe 9s ease-in-out infinite, doom-skull-tear 0.34s steps(3) 1;
}
@keyframes doom-skull-tear {
  0%   { translate: -16px 0; clip-path: inset(8% 0 52% 0); }
  33%  { translate: 14px 0;  clip-path: inset(38% 0 22% 0); }
  66%  { translate: -7px 0;  clip-path: inset(62% 0 0 0); }
  100% { translate: 0 0;     clip-path: none; }
}

/* glyphs shed from the cranium (canvas painted by haunt.js) */
.doom-glyphs { position: fixed; inset: 0; z-index: -1; pointer-events: none; }


/* grade on top of everything: crimson vignette + heavier scanlines. A fixed
   overlay, never a filter on body. */
.doom-grade {
  position: fixed; inset: 0; z-index: 9998; pointer-events: none;
  background:
    radial-gradient(130% 95% at 50% 40%, transparent 62%, rgba(40, 0, 10, 0.45) 100%),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.10) 0 1px, transparent 1px 3px);
  animation: doom-flicker 7.3s steps(60) infinite;
}
/* the blood bleed from the top edge deepens as it spreads (edges only, never the reading column) */
.doom-grade::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(120, 6, 30, 0.55) 0, transparent 14vh),
    radial-gradient(120% 90% at 50% 45%, transparent 70%, rgba(70, 0, 16, 0.6) 100%);
  opacity: calc(0.35 * var(--doom-p, 0));
}
@keyframes doom-flicker {
  0%, 95%, 100% { opacity: 1; } 96% { opacity: 0.7; } 97% { opacity: 1; } 98.5% { opacity: 0.8; }
}

/* signature, bottom corner */
.doom-tag {
  position: fixed; right: 12px; bottom: 10px; z-index: 9999; pointer-events: none;
  font: 11px/1 'Share Tech Mono', ui-monospace, monospace; letter-spacing: 0.18em;
  color: var(--doom-crimson); opacity: 0.75; text-shadow: 0 0 8px rgba(255,31,90,0.6);
}

/* ---------- masthead: glyph-eaten, crimson/teal split ---------- */
html.haunted .logo-main {
  color: var(--doom-bone) !important;
  text-shadow: -2px 0 rgba(255,31,90,0.85), 2px 0 rgba(63,208,212,0.6), 0 0 22px rgba(255,31,90,0.45) !important;
  animation: doom-shudder 3.1s ease-in-out infinite;
}
html.haunted .logo-main .dg { display: inline-block; }
html.haunted .logo-main .dg.hit { color: var(--doom-crimson); }
html.haunted .logo-sub { color: var(--doom-teal) !important; text-shadow: 0 0 10px rgba(63,208,212,0.55) !important; }
@keyframes doom-shudder {
  0%,100% { transform: translate(0,0); }
  46% { transform: translate(0.8px,-0.4px); }
  47% { transform: translate(-1.6px,0.6px) skewX(-1.2deg); }
  48% { transform: translate(1.2px,0); }
  49% { transform: translate(0,0); }
}

/* ---------- feed: crimson routes through the rows ---------- */
html.haunted #feed .feed-item, html.haunted #feed .feed-hero {
  border-color: rgba(255, 31, 90, 0.28) !important;
  box-shadow: inset 2px 0 0 rgba(255,31,90,0.55), inset 0 0 0 1px rgba(255,31,90,0.06);
}
html.haunted #feed .feed-item:nth-child(3n+2) { box-shadow: inset 2px 0 0 rgba(63,208,212,0.45), inset 0 0 0 1px rgba(63,208,212,0.05); }
html.haunted #feed .feed-hero { background-color: rgba(26, 5, 16, 0.82) !important; }
html.haunted #feed .feed-item { background-color: rgba(8, 2, 6, 0.8); }

/* a few corrupted headlines — text stays in the DOM and readable */
html.haunted [data-haunt-scramble="1"] {
  position: relative; color: transparent !important;
  text-shadow: -1.5px 0 rgba(255,31,90,0.85), 1.5px 0 rgba(63,208,212,0.7);
  animation: haunt-glitch 1.9s steps(24) infinite;
}
html.haunted [data-haunt-scramble="1"]::before {
  content: attr(data-haunt-text); position: absolute; inset: 0; color: var(--doom-bone);
  clip-path: inset(0 0 55% 0); animation: haunt-slice 2.3s steps(12) infinite;
}
html.haunted [data-haunt-scramble="1"]::after {
  content: attr(data-haunt-text); position: absolute; inset: 0; color: #a99a95;
  clip-path: inset(58% 0 0 0); transform: translateX(-1px);
}
/* row headlines wrap across lines, where an overlay would misalign: they get a
   colour split and a jitter instead, and haunt.js eats a letter now and then */
html.haunted [data-haunt-scramble="soft"] {
  color: var(--doom-bone) !important;
  text-shadow: -2px 0 rgba(255,31,90,0.8), 2px 0 rgba(63,208,212,0.6) !important;
  animation: haunt-jitter 2.7s steps(1) infinite;
}
@keyframes haunt-jitter {
  0%, 88%, 100% { opacity: 1; }
  90% { opacity: 0.8; } 93% { opacity: 1; } 95% { opacity: 0.9; }
}
@keyframes haunt-glitch { 0%,100%{opacity:1} 92%{opacity:.7} 96%{opacity:1} }
@keyframes haunt-slice { 0%,100%{transform:translateX(0)} 50%{transform:translateX(3px)} }

/* labels and buttons that sit straight on the background get a dark backing,
   so they stay readable over the skull */
html.haunted .channel-cta a,
html.haunted .refresh-btn, html.haunted .present-btn,
html.haunted .brand-chips > *, html.haunted .search-wrap input {
  background-color: rgba(8, 2, 6, 0.82) !important;
}
html.haunted .section-label, html.haunted .stat-row, html.haunted .channel-cta {
  text-shadow: 0 0 4px #050104, 0 0 10px #050104, 0 1px 2px #050104;
}

/* source chips pick up the corruption */
html.haunted .source-chips > * { border-color: rgba(255,31,90,0.45) !important; }

/* momentary signal tears, applied by haunt.js for a fraction of a second */
html.haunted .doom-tear { animation: doom-tear 0.26s steps(3) 1; }
@keyframes doom-tear {
  0%   { transform: translateX(-7px); clip-path: inset(0 0 60% 0); filter: hue-rotate(-25deg); }
  34%  { transform: translateX(6px);  clip-path: inset(35% 0 20% 0); }
  67%  { transform: translateX(-3px); clip-path: inset(55% 0 0 0); }
  100% { transform: none; clip-path: none; filter: none; }
}

/* the persistent fiction tell haunt.js appends [CA-14] */
.haunt-fiction {
  margin-top: 14px; padding: 10px 14px; font-size: 12.5px; line-height: 1.5;
  color: #cdbfb8; opacity: 0.9; text-align: center;
  border-top: 1px solid rgba(255,31,90,0.3);
}
.haunt-fiction a { color: var(--doom-crimson, #ff1f5a); text-decoration: underline; text-underline-offset: 2px; }

/* ── Tease level (html.haunt-tease): before the reveal. The site keeps its own
   palette and chrome; only the faint skull, a few code fragments, one jittering
   headline, a rare masthead flicker and the corner tag give it away. ── */
/* no skull in the tease: it is the reveal. The element stays in layout (invisible) because
   the glyph canvas reads its box to know where the fragments come from. */
html.haunt-tease .doom-skull { opacity: 0; animation: none; top: 44vh; }
html.haunt-tease body { isolation: isolate; }
/* the horizon glow goes faintly wrong: a blood tint at the top edge, not the full bleed */
html.haunt-tease body::before {
  background:
    radial-gradient(ellipse 70% 40% at 50% 0%, rgba(138, 13, 46, 0.30), transparent 60%),
    linear-gradient(180deg, #07010f 0%, #0d0210 50%, #07010f 100%);
}
/* the masthead shudders and bleeds crimson at the edges, keeps its magenta */
html.haunt-tease .logo-main {
  text-shadow: -2px 0 rgba(255,31,90,0.8), 2px 0 rgba(63,208,212,0.55), 0 0 22px rgba(255,46,154,0.45) !important;
  animation: doom-shudder 3.1s ease-in-out infinite;   /* the same shake as the final */
}
html.haunt-tease .logo-sub { text-shadow: -1px 0 rgba(255,31,90,0.7), 1px 0 rgba(63,208,212,0.5) !important; }
/* section labels and the stat row pick up the colour split */
html.haunt-tease .section-label, html.haunt-tease .stat-row {
  text-shadow: -1px 0 rgba(255,31,90,0.7), 1px 0 rgba(63,208,212,0.5);
}
/* the Gearnews chip (3rd) flickers like a bad contact; a second chip has gone crimson */
html.haunt-tease .source-chips > :nth-child(3) {
  border-color: rgba(255,31,90,0.75) !important; color: #ff6b92 !important;
  animation: tease-flicker 2.9s steps(1) infinite;
}
html.haunt-tease .source-chips > :nth-child(6) { border-color: rgba(255,31,90,0.55) !important; }
@keyframes tease-flicker {
  0%, 61%, 100% { opacity: 1; }
  62% { opacity: 0.25; } 64% { opacity: 1; } 66% { opacity: 0.4; } 67% { opacity: 1; }
  88% { opacity: 0.3; } 89% { opacity: 1; }
}
html.haunt-tease .doom-tag { color: #c2b1ab; }
html.haunt-tease .doom-glyphs { opacity: 1; }
html.haunt-tease .doom-tag { opacity: 0.6; }
html.haunt-tease .logo-main .dg { display: inline-block; }
html.haunt-tease .logo-main .dg.hit { color: #ff1f5a; }
html.haunt-tease [data-haunt-scramble="soft"] {
  text-shadow: -2px 0 rgba(255,31,90,0.75), 2px 0 rgba(63,208,212,0.55) !important;
  animation: haunt-jitter 3.3s steps(1) infinite;
}
html.haunt-tease .haunt-fiction a { color: #ff1f5a; }
html.haunt-tease .doom-tear { animation: doom-tear 0.26s steps(3) 1; }
/* the hero headline carries the full glitch treatment in the tease too */
html.haunt-tease [data-haunt-scramble="1"] {
  position: relative; color: transparent !important;
  text-shadow: -1.5px 0 rgba(255,31,90,0.85), 1.5px 0 rgba(63,208,212,0.7);
  animation: haunt-glitch 1.9s steps(24) infinite;
}
html.haunt-tease [data-haunt-scramble="1"]::before {
  content: attr(data-haunt-text); position: absolute; inset: 0; color: #efe6dd;
  clip-path: inset(0 0 55% 0); animation: haunt-slice 2.3s steps(12) infinite;
}
html.haunt-tease [data-haunt-scramble="1"]::after {
  content: attr(data-haunt-text); position: absolute; inset: 0; color: #a99a95;
  clip-path: inset(58% 0 0 0); transform: translateX(-1px);
}

@media (max-width: 640px) {
  .doom-skull { top: 46vh; opacity: 0; }
  .doom-tag { font-size: 9.5px; }
}

/* reduced motion: keep the look, drop the movement */
@media (prefers-reduced-motion: reduce) {
  .doom-skull, .doom-skull .eye, .doom-skull .infect, .doom-grade,
  html.haunted .logo-main, html.haunted .doom-tear,
  html.haunted [data-haunt-scramble], html.haunted [data-haunt-scramble="1"]::before {
    animation: none !important;
  }
}
