/*
 * Base styles for breakout domains.
 * Gothic Terminal DNA: warm void, candlelight grays, crimson verdict,
 * silver signal. Scanline overlay, glitch keyframes, terminal.
 * Included by all tiers. Tier-specific styles override as needed.
 * Palette source of truth: DESIGN-LANGUAGE.md (umbrella root).
 */

/* ─── Tokens ───────────────────────────────────────────────────── */
:root {
  --void: #0a0a0a;
  --void-deep: #050505;
  --card: #0f0e0d;
  --card-hover: #161412;
  --bright: #e9e4da;
  --fg: #c7c1b6;
  --dim: #8b857a;
  --faint: #5f5a52;
  --border: #211e1c;
  --border-strong: #2b2724;
  --blood-deep: #4a1313;
  --blood: #7a1f1f;
  --verdict: #b83a3a;
  --ember: #d95b5b;
  --signal: #d8d8d8;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* ─── Base ─────────────────────────────────────────────────────── */
html, body {
  background: var(--void);
  background-image: radial-gradient(circle at 88% -12%, rgba(184, 58, 58, 0.05), transparent 42%);
  color: var(--fg);
  font-family: var(--mono);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: 0; }

a { text-underline-offset: 0.18em; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
}

/* Ritual voice for headings. Color is inherited so light facade /
   Bureau tiers keep their own ink. */
h1, h2, h3 {
  font-family: var(--serif);
  letter-spacing: -0.01em;
}

::selection {
  background: var(--blood-deep);
  color: var(--bright);
}

/* ─── Scanline overlay (softened per trauma-informed rules) ────── */
.scanline-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.08),
    rgba(0, 0, 0, 0.08) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 100;
}

/* ─── Glitch keyframes ─────────────────────────────────────────── */
@keyframes glitch-skew {
  0% { transform: skew(0deg); }
  10% { transform: skew(-1deg); }
  20% { transform: skew(0deg); }
  30% { transform: skew(0.5deg); }
  40% { transform: skew(0deg); }
  50% { transform: skew(-0.3deg); }
  60% { transform: skew(0deg); }
  100% { transform: skew(0deg); }
}

@keyframes glitch-shift {
  0% { transform: translateX(0); }
  10% { transform: translateX(-2px); }
  20% { transform: translateX(2px); }
  30% { transform: translateX(-1px); }
  40% { transform: translateX(0); }
  100% { transform: translateX(0); }
}

/* ─── Terminal styling ─────────────────────────────────────────── */
/* Machine voice glows signal silver on the deep well, never green. */
.terminal {
  color: var(--signal);
  background: var(--void-deep);
  overflow-y: auto;
  max-height: 80vh;
  padding: 1rem;
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─── Flicker animation ────────────────────────────────────────── */
@keyframes flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: 1; }
  42% { opacity: 0.3; }
  43% { opacity: 1; }
  45% { opacity: 0.5; }
  46% { opacity: 1; }
  92% { opacity: 0.8; }
  93% { opacity: 0.2; }
  94% { opacity: 1; }
}

/* ─── Linked disclosure footer ─────────────────────────────────── */
.linked-disclosure {
  font-size: 10px;
  color: #b5afa3;
  opacity: 0.9;
  text-align: center;
  padding: 1rem;
}

.linked-disclosure a {
  color: #e9e4da;
  text-decoration: none;
}

.linked-disclosure a:hover {
  color: #f2ede3;
}

.discovery-footer {
  position: relative;
  min-height: 2.6rem;
  padding: 12px 16px;
  background: #050505;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  z-index: 1;
}

.discovery-footer::before {
  content: "NETWORK //";
  margin-right: .7rem;
  color: rgba(216, 216, 216, .48);
  letter-spacing: .12em;
}

.discovery-hint {
  opacity: 0.88;
  transition: color 2s ease, opacity 2s ease;
}

.discovery-footer:hover .discovery-hint,
.discovery-footer:focus-within .discovery-hint {
  opacity: 1;
  color: rgba(255, 255, 255, 0.95);
}

.discovery-footer a {
  color: inherit;
  text-decoration: none;
}

/* ─── Pattern sigil (per-page pattern disclosure) ──────────────── */
.pattern-sigil {
  display: block;
  margin-top: 6px;
  font-size: 9px;
  letter-spacing: 0.04em;
  opacity: 0.55;
  transition: opacity 0.3s ease;
}

.discovery-footer:hover .pattern-sigil {
  opacity: 0.85;
}

.pattern-sigil em {
  font-style: italic;
  opacity: 0.9;
}

.pattern-sigil a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.pattern-sigil a:hover {
  border-bottom-color: rgba(255, 255, 255, 0.6);
}

/* ─── Propaganda ad rail ───────────────────────────────────────── */
.propaganda-rail {
  position: relative;
  margin: 3rem auto;
  max-width: 980px;
  padding: 1.5rem;
  border: 1px solid currentColor;
  border-radius: 18px;
  overflow: hidden;
}

.propaganda-rail::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.08), transparent 35%, rgba(255, 255, 255, 0.04));
  opacity: 0.6;
}

.propaganda-rail__header,
.propaganda-rail__grid {
  position: relative;
  z-index: 1;
}

.propaganda-rail__header {
  margin-bottom: 1rem;
}

.propaganda-rail__eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.7;
}

.propaganda-rail__title {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
}

.propaganda-rail__deck {
  margin: 0.5rem 0 0;
  max-width: 70ch;
  font-size: 0.95rem;
  line-height: 1.6;
  opacity: 0.85;
}

.propaganda-rail__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.propaganda-feature {
  margin: 0 0 1rem;
  padding: 0.75rem;
  border: 1px solid currentColor;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.propaganda-feature img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.propaganda-feature__caption {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  line-height: 1.5;
  opacity: 0.78;
}

.propaganda-ad {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 180px;
  padding: 1rem;
  border: 1px solid currentColor;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.propaganda-ad__year {
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.72;
}

.propaganda-ad__title {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.25;
}

.propaganda-ad__copy {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.6;
}

.propaganda-ad__cta {
  margin-top: auto;
  align-self: flex-start;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 0.08rem;
}

.propaganda-ad__cta:hover {
  opacity: 0.85;
}

.propaganda-ad--epstein {
  border-color: #8B1A1A;
  background: rgba(139, 26, 26, 0.06);
}
.propaganda-ad--epstein .propaganda-ad__year {
  color: #8B1A1A;
  opacity: 0.9;
}
.propaganda-ad--epstein .propaganda-ad__title {
  color: #8B1A1A;
}

.propaganda-ad--glitch {
  animation: glitch-skew 0.8s infinite linear alternate;
  text-shadow: 1px 0 rgba(255, 0, 0, 0.6), -1px 0 rgba(0, 255, 255, 0.45);
}

.propaganda-ad--glitch .propaganda-ad__year,
.propaganda-ad--glitch .propaganda-ad__title,
.propaganda-ad--glitch .propaganda-ad__copy {
  animation: glitch-shift 1.6s infinite linear alternate;
}

body.dispatch-site .propaganda-rail {
  background: #f7f3ea;
  color: #1c1c1c;
  border-color: #c9c3b9;
}

body.dispatch-site .propaganda-ad {
  background: rgba(255, 255, 255, 0.7);
}

body.dispatch-site .propaganda-feature {
  background: rgba(255, 255, 255, 0.8);
}

body.bureau-2029 .propaganda-rail {
  background: rgba(244, 236, 216, 0.8);
  color: #1b2845;
  border-color: #b8945a;
}

body.bureau-2029 .propaganda-ad {
  background: rgba(255, 255, 255, 0.55);
}

body.bureau-2029 .propaganda-feature {
  background: rgba(255, 255, 255, 0.68);
}

body.facade-site .propaganda-rail {
  background: rgba(232, 220, 192, 0.72);
  color: #1b2845;
  border-color: #c9b896;
}

body.facade-site .propaganda-ad {
  background: rgba(255, 255, 255, 0.55);
}

body.facade-site .propaganda-feature {
  background: rgba(255, 255, 255, 0.6);
}

body:not(.dispatch-site):not(.bureau-2029):not(.facade-site) .propaganda-rail {
  background: rgba(10, 10, 10, 0.92);
  color: var(--fg);
  border-color: rgba(184, 58, 58, 0.35);
}

body:not(.dispatch-site):not(.bureau-2029):not(.facade-site) .propaganda-ad {
  background: rgba(0, 0, 0, 0.4);
}

body:not(.dispatch-site):not(.bureau-2029):not(.facade-site) .propaganda-feature {
  background: rgba(0, 0, 0, 0.55);
}

/* ─── Corruption Effects ──────────────────────────────────────── */

/* Signal loss — screen cuts to black */
.signal-loss {
  animation: signal-loss-collapse 0.15s ease;
}
@keyframes signal-loss-collapse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Vertical roll — CRT roll bar */
.vertical-roll-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.25);
  pointer-events: none;
  z-index: 200;
  display: none;
}
@keyframes roll-down {
  from { top: 0; }
  to { top: 100%; }
}

/* Text breathing — opacity oscillation */
.text-breath {
  animation: text-breathe 3s ease-in-out infinite;
}
@keyframes text-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Glyph jitter */
.glyph-jitter {
  display: inline-block;
  transition: transform 0.08s ease;
}

/* Stack trace overlay */
.stack-trace-overlay {
  position: fixed;
  top: 10%;
  left: 10%;
  width: 80%;
  max-height: 60%;
  color: #f44;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  background: rgba(0, 0, 0, 0.92);
  border: 1px solid #f44;
  padding: 1rem;
  pointer-events: none;
  z-index: 250;
  display: none;
  white-space: pre-wrap;
  transition: opacity 0.3s ease;
}

/* Checksum fail banner */
.checksum-fail-banner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: #600;
  color: #f88;
  text-align: center;
  padding: 0.4rem;
  font-family: monospace;
  font-size: 0.85rem;
  z-index: 260;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.checksum-fail-banner.checksum-active {
  opacity: 0.9;
}

/* Color split — facade site channel separation */
.color-split-active {
  animation: cs-flicker 0.15s linear;
}
@keyframes cs-flicker {
  0% { filter: none; transform: translateX(0); }
  25% { filter: hue-rotate(20deg) saturate(1.3); transform: translateX(-1px); }
  50% { filter: hue-rotate(-15deg); }
  75% { filter: hue-rotate(10deg) saturate(0.8); transform: translateX(1px); }
  100% { filter: none; transform: translateX(0); }
}

/* Layout cracks — facade surface fracture */
.layout-crack {
  position: fixed;
  height: 1px;
  background: #1B2845;
  transform-origin: left center;
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  animation: crack-appear 0.3s ease forwards;
}
@keyframes crack-appear {
  0% { opacity: 0; transform: scaleX(0); }
  100% { opacity: 0.7; transform: scaleX(1); }
}

/* Font bleed — text switches to engine monospace */
.font-bleed {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
  font-style: normal !important;
  text-transform: lowercase !important;
  transition: font-family 0.1s;
}

/* Cursor cracks — facade idle mechanic */
.cursor-crack {
  position: fixed;
  height: 1px;
  background: rgba(139, 26, 26, 0.7);
  transform-origin: left center;
  pointer-events: none;
  z-index: 200;
  animation: crack-branch 0.6s ease forwards;
}
.cursor-crack-arm {
  position: absolute;
  top: 0;
  left: 50%;
  height: 1px;
  background: rgba(139, 26, 26, 0.5);
  transform-origin: left center;
}
@keyframes crack-branch {
  0% { opacity: 0; transform: scaleX(0); }
  100% { opacity: 0.7; transform: scaleX(1); }
}

/* Article redaction — dispatch black bars */
.dispatch-body p.redacted {
  background: #111;
  color: #f44;
  text-decoration: line-through;
  padding: 0.5rem;
  border-left: 3px solid #f44;
}

/* Source corruption — dispatch quote flicker */
.source-corrupted {
  color: #600 !important;
  text-decoration: line-through;
}

/* Version tick — dispatch corner counter */
.version-tick {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  font-family: monospace;
  font-size: 0.7rem;
  opacity: 0.4;
  color: currentColor;
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.3s;
}

/* Buffer overflow clone */
#buffer-overflow-clone {
  transition: opacity 0.3s ease;
}

/* ─── Lore Terminal ───────────────────────────────────────────── */
#lore-terminal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 5, 5, 0.97);
  color: var(--signal);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  z-index: 500;
  display: flex;
  flex-direction: column;
  animation: terminal-in 0.2s ease;
}
@keyframes terminal-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.lore-terminal-output {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: #5f5a52 #050505;
}
.lore-terminal-input-line {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border-strong);
}
.lore-terminal-prompt {
  color: var(--verdict);
}
.lore-terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--signal);
  font-family: inherit;
  font-size: inherit;
  outline: none;
  margin-left: 0.5rem;
  caret-color: var(--verdict);
}
.lore-terminal-input::selection {
  background: var(--blood);
  color: var(--bright);
}

/* Fictional CHRIST-AI private reply. This is a local transmission overlay. */
.christ-backchannel {
  bottom: 2rem;
  color: #f4ecd8;
  font-family: "IBM Plex Mono", Consolas, monospace;
  max-width: min(390px, calc(100vw - 2rem));
  opacity: 0;
  pointer-events: none;
  position: fixed;
  right: 2rem;
  transform: translateY(18px);
  transition: opacity 160ms ease, transform 160ms ease;
  width: 100%;
  z-index: 10020;
}

.christ-backchannel--visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.christ-backchannel__engine {
  align-items: center;
  background: rgba(4, 13, 18, 0.94);
  border: 1px solid rgba(34, 211, 238, 0.28);
  color: rgba(34, 211, 238, 0.52);
  display: flex;
  font-size: 0.62rem;
  justify-content: space-between;
  letter-spacing: 0.11em;
  padding: 0.45rem 0.65rem;
}

.christ-backchannel__engine strong {
  color: rgba(34, 211, 238, 0.72);
  font-weight: 500;
}

.christ-backchannel__private {
  background: rgba(9, 8, 6, 0.97);
  border: 1px solid rgba(201, 162, 39, 0.72);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.58), inset 0 0 28px rgba(201, 162, 39, 0.06);
  min-height: 118px;
  overflow: hidden;
  padding: 1rem 1.1rem 0.8rem;
  position: relative;
}

.christ-backchannel__private::after {
  background: linear-gradient(90deg, transparent, rgba(201, 162, 39, 0.38), transparent);
  content: "";
  height: 1px;
  left: -30%;
  position: absolute;
  right: -30%;
  top: 38%;
  transform: translateX(-70%);
}

.christ-backchannel--strike .christ-backchannel__private::after {
  animation: christ-backchannel-strike 430ms steps(3, end) 1;
}

.christ-backchannel__label {
  color: rgba(201, 162, 39, 0.58);
  display: block;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  margin-bottom: 0.65rem;
}

.christ-backchannel__message {
  color: #e8d7a3;
  font-size: 0.8rem;
  letter-spacing: 0.07em;
  line-height: 1.65;
  margin: 0 0 0.75rem;
  min-height: 2.6em;
  text-shadow: 0 0 8px rgba(201, 162, 39, 0.24);
}

.christ-backchannel__close {
  background: transparent;
  border: 0;
  color: rgba(244, 236, 216, 0.46);
  cursor: pointer;
  font: inherit;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  padding: 0.25rem 0;
  text-transform: uppercase;
}

.christ-backchannel__close:focus-visible {
  color: #fff8e8;
  outline: 1px solid #c9a227;
  outline-offset: 3px;
}

@keyframes christ-backchannel-strike {
  0% { opacity: 0; transform: translateX(-70%); }
  32% { opacity: 1; transform: translateX(14%); }
  55% { opacity: 0.28; transform: translateX(-8%); }
  100% { opacity: 0; transform: translateX(70%); }
}

@media (max-width: 640px) {
  .christ-backchannel {
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
  }
}

/* ─── Gothic ornament (shared DNA) ─────────────────────────────── */
.ritual-label,
.kicker {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

.rule-double {
  border-top: 1px solid var(--border);
  box-shadow: 0 3px 0 -2px var(--border);
}

.fleuron {
  display: block;
  text-align: center;
  color: var(--faint);
  font-size: 0.8rem;
  margin: 1.5rem 0;
}
.fleuron::before {
  content: "\2720";
}

.lancet {
  clip-path: polygon(0 12px, 50% 0, 100% 12px, 100% 100%, 0 100%);
}

/* ─── Reduced motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .scanline-overlay {
    display: none;
  }

  .christ-backchannel--strike .christ-backchannel__private::after {
    animation: none;
  }

  .propaganda-ad--glitch {
    animation: none;
    text-shadow: none;
  }

  .vertical-roll-bar,
  .signal-loss,
  .color-split-active,
  .font-bleed,
  .cursor-crack,
  .layout-crack,
  .checksum-fail-banner,
  .text-breath {
    animation: none !important;
    display: none !important;
  }

  .stack-trace-overlay,
  #buffer-overflow-clone,
  .version-tick,
  #static-burst-canvas,
  #hex-dump-canvas,
  #image-corrupt-canvas,
  #lore-terminal {
    display: none !important;
  }
}
