/* ═══════════════════════════════════════════════════════════════
   THE PRICE OF BLOOD — Design System v3
   "The Haunted Bureau of Mortality Economics"
   ─── Philip K. Dick's accountant meets Tim Burton's printer ───
═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Special+Elite&family=Archivo+Black&family=Space+Mono:ital,wght@0,400;0,700;1,400&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Caveat:wght@400;700&display=swap');

/* ── Tokens ──────────────────────────────────────────────────── */
:root {
  /* The Void */
  --bg:        #0c0c0c;
  --bg2:       #141414;
  --surface:   #1a1a1a;
  --card:      #111111;
  --border:    #2a2a2a;
  --border-hi: #3a3a3a;

  /* Flesh and Bone */
  --bone:    #e8dcc8;
  --parch:   #d4c8a8;
  --ash:     #888070;
  --smoke:   #605848;
  --shadow:  #3a3530;

  /* The Red Spectrum — arterial to venous */
  --red-black:  #1a0000;
  --red-deep:   #3a0808;
  --red-dark:   #6b0f0f;
  --red:        #a01818;
  --red-mid:    #cc2020;
  --red-bright: #e83828;
  --red-vivid:  #ff4040;
  --red-glow:   #ff6060;

  /* Sickness */
  --bile:     #a8b820;
  --bile-dim: #6a7810;
  --bruise:   #6840a0;
  --bruise-dim:#4a2870;
  --teal:     #208880;
  --teal-dim: #106050;
  --rust:     #b86830;
  --rust-dim: #805020;
  --ink-blue: #283848;

  /* Typography */
  --font-stamp:   'Archivo Black', 'Impact', sans-serif;
  --font-type:    'Special Elite', 'Courier New', monospace;
  --font-mono:    'Space Mono', 'Courier New', monospace;
  --font-book:    'Libre Baskerville', 'Georgia', serif;
  --font-hand:    'Caveat', cursive;

  /* Burton stripes */
  --stripe: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(255,255,255,0.015) 4px,
    rgba(255,255,255,0.015) 5px
  );

  /* Effects */
  --glow-red:  0 0 30px rgba(160,24,24,0.25), 0 0 60px rgba(160,24,24,0.08);
  --glow-bile: 0 0 20px rgba(168,184,32,0.15);
  --shadow-brutal: 4px 4px 0 #000;
  --shadow-float: 0 20px 60px rgba(0,0,0,0.5);

  /* Timing */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Light mode: yellowed paper from a haunted filing cabinet ── */
[data-theme="light"] {
  --bg:        #f2ead8;
  --bg2:       #e8dfc8;
  --surface:   #ddd4b8;
  --card:      #ebe2cc;
  --border:    #c8b898;
  --border-hi: #b0a080;

  --bone:    #1a1410;
  --parch:   #2a2218;
  --ash:     #5a5040;
  --smoke:   #8a7e68;
  --shadow:  #c0b498;

  --red-deep:   #fde8e4;
  --red-dark:   #901010;
  --red:        #801010;
  --red-mid:    #a01818;
  --red-bright: #880808;
  --red-vivid:  #700000;

  --bile:     #506010;
  --bruise:   #5030a0;
  --teal:     #106858;
  --rust:     #905020;

  --stripe: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(0,0,0,0.02) 4px,
    rgba(0,0,0,0.02) 5px
  );

  --glow-red: 0 0 30px rgba(160,24,24,0.08);
  --glow-bile: 0 0 20px rgba(80,96,16,0.1);
  --shadow-brutal: 3px 3px 0 rgba(0,0,0,0.1);
  --shadow-float: 0 20px 60px rgba(0,0,0,0.1);
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg);
  color: var(--bone);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Global film grain ───────────────────────────────────────── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10000;
  opacity: 0.4;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)' opacity='0.035'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

[data-theme="light"] body::after { opacity: 0.2; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--red-dark);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--red); }

/* ── Selection ───────────────────────────────────────────────── */
::selection {
  background: var(--red);
  color: #fff;
}

/* ── Theme Toggle ─────────────────────────────────────────────── */
#theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9500;
  width: 40px;
  height: 40px;
  border: 2px solid var(--red-dark);
  background: var(--bg);
  color: var(--red);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s var(--ease-out);
  font-family: sans-serif;
  line-height: 1;
  padding: 0;
}

#theme-toggle:hover {
  background: var(--red-dark);
  color: var(--bone);
  box-shadow: var(--glow-red);
  transform: rotate(180deg);
}

[data-theme="light"] #theme-toggle {
  border-color: var(--red);
  background: var(--surface);
  color: var(--red);
}

/* ── Back Nav ────────────────────────────────────────────────── */
#back-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: var(--font-type);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ash);
  margin-bottom: 32px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  transition: all 0.2s ease;
}

#back-nav::before {
  content: '←';
  font-size: 14px;
  transition: transform 0.2s var(--ease-bounce);
}

#back-nav:hover {
  color: var(--red);
  border-color: var(--red-dark);
}

#back-nav:hover::before {
  transform: translateX(-6px);
}

/* ══════════════════════════════════════════════════════════════
   COMPONENT LIBRARY
══════════════════════════════════════════════════════════════ */

/* ── Stamp Text ──────────────────────────────────────────────── */
.stamp {
  font-family: var(--font-stamp);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.typewriter {
  font-family: var(--font-type);
}

.handwritten {
  font-family: var(--font-hand);
}

/* ── Redacted / Classified ───────────────────────────────────── */
.classified {
  position: relative;
  display: inline-block;
}

.classified::after {
  content: 'CLASSIFIED';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg);
  font-family: var(--font-stamp);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--red);
  border: 2px solid var(--red);
  padding: 2px 8px;
  pointer-events: none;
  opacity: 0.4;
}

/* ── Burton Stripes Background ───────────────────────────────── */
.striped {
  background-image: var(--stripe);
}

/* ── Ink Stain Decorations ───────────────────────────────────── */
.ink-stain {
  position: relative;
}

.ink-stain::before {
  content: '';
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 40% 40%,
    rgba(160,24,24,0.08) 0%,
    rgba(160,24,24,0.03) 40%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

/* ── Section Dividers ────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 48px 0;
  position: relative;
}

.divider::before {
  content: '†';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  color: var(--red-dark);
  padding: 0 12px;
  font-size: 14px;
}

.divider.plain::before { display: none; }

/* ── Exhibit Label ───────────────────────────────────────────── */
.exhibit {
  font-family: var(--font-stamp);
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--red);
  border: 2px solid var(--red);
  display: inline-block;
  padding: 3px 12px;
  margin-bottom: 16px;
  position: relative;
  transition: all 0.3s ease;
}

.exhibit:hover {
  background: var(--red);
  color: var(--bg);
  box-shadow: var(--glow-red);
}

/* ── Section Headers ─────────────────────────────────────────── */
.section-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 24px;
  margin-top: 64px;
  cursor: default;
}

.section-num {
  font-family: var(--font-stamp);
  font-size: 32px;
  color: var(--red-dark);
  line-height: 1;
  opacity: 0.6;
}

.section-title {
  font-family: var(--font-book);
  font-style: italic;
  font-size: 24px;
  color: var(--bone);
  font-weight: 400;
}

.section-sub {
  font-family: var(--font-type);
  font-size: 10px;
  color: var(--ash);
  margin-left: auto;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: all 0.3s var(--ease-out);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--red);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.5s var(--ease-bounce);
}

.card:hover {
  border-color: var(--border-hi);
  box-shadow: var(--shadow-float);
  transform: translateY(-2px);
}

.card:hover::before {
  transform: scaleX(1);
}

/* ── Table Styles ────────────────────────────────────────────── */
.tbl, .xt {
  width: 100%;
  border-collapse: collapse;
}

.tbl th, .xt th {
  font-family: var(--font-type);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ash);
  text-align: right;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border);
  font-weight: 400;
  white-space: nowrap;
}

.tbl th:first-child, .xt th:first-child { text-align: left; }

.tbl td, .xt td {
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: background 0.15s ease, padding-left 0.2s ease;
}

.tbl td:first-child, .xt td:first-child { text-align: left; }

.tbl tr:hover td, .xt tr:hover td {
  background: var(--surface);
}

.tbl tr:hover td:first-child, .xt tr:hover td:first-child {
  padding-left: 20px;
}

/* ── Chart Container ─────────────────────────────────────────── */
.chart-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--red);
  padding: 28px 24px 20px;
  margin-bottom: 8px;
  position: relative;
  background-image: var(--stripe);
}

.chart-wrap.amber { border-left-color: var(--rust); }
.chart-wrap.teal  { border-left-color: var(--teal); }
.chart-wrap.bile  { border-left-color: var(--bile); }

canvas {
  display: block;
  width: 100% !important;
  cursor: crosshair;
}

/* ── Toggle (collapsible) ────────────────────────────────────── */
.toggle-head {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.toggle-icon {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--red);
  transition: transform 0.3s var(--ease-out);
  display: inline-block;
  width: 12px;
}

.toggle-head.closed .toggle-icon {
  transform: rotate(-90deg);
}

.toggle-body {
  overflow: hidden;
  max-height: 5000px;
  transition: max-height 0.6s var(--ease-out), opacity 0.4s ease;
  opacity: 1;
}

.toggle-body.collapsed {
  max-height: 0;
  opacity: 0;
}

/* ── Pill / Badge ────────────────────────────────────────────── */
.pill {
  font-family: var(--font-type);
  font-size: 8px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 3px 10px;
  border: 1px solid;
  display: inline-block;
}

.pill.red    { color: var(--red); border-color: var(--red-dark); }
.pill.bile   { color: var(--bile); border-color: var(--bile-dim); }
.pill.bruise { color: var(--bruise); border-color: var(--bruise-dim); }
.pill.teal   { color: var(--teal); border-color: var(--teal-dim); }
.pill.rust   { color: var(--rust); border-color: var(--rust-dim); }

/* ── Named color utilities ───────────────────────────────────── */
.c-red       { color: var(--red); }
.c-red-bright{ color: var(--red-bright); }
.c-red-vivid { color: var(--red-vivid); }
.c-bile      { color: var(--bile); }
.c-bruise    { color: var(--bruise); }
.c-teal      { color: var(--teal); }
.c-rust      { color: var(--rust); }
.c-ash       { color: var(--ash); }
.c-bone      { color: var(--bone); }
.c-parch     { color: var(--parch); }
.c-smoke     { color: var(--smoke); }

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.05); }
  28%      { transform: scale(1); }
  42%      { transform: scale(1.03); }
  56%      { transform: scale(1); }
}

@keyframes typeIn {
  from { width: 0; }
  to   { width: 100%; }
}

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}

@keyframes flicker {
  0%, 95%, 100% { opacity: 1; }
  96% { opacity: 0.4; }
  97% { opacity: 0.9; }
  98% { opacity: 0.3; }
}

@keyframes drip {
  0%   { height: 0; }
  70%  { height: 105%; }
  85%  { height: 98%; }
  100% { height: 100%; }
}

@keyframes stampIn {
  0%   { transform: scale(3) rotate(-15deg); opacity: 0; }
  50%  { transform: scale(1.05) rotate(-12deg); opacity: 0.8; }
  70%  { transform: scale(0.98) rotate(-12deg); opacity: 1; }
  100% { transform: scale(1) rotate(-12deg); opacity: 1; }
}

@keyframes bloodFill {
  from { width: 0; }
  to   { width: var(--fill); }
}

/* ── Scroll Reveal ───────────────────────────────────────────── */
.reveal {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}

.reveal.vis {
  opacity: 1;
  transform: translateY(0);
}

/* stagger children */
.reveal-stagger > .reveal:nth-child(1) { transition-delay: 0s; }
.reveal-stagger > .reveal:nth-child(2) { transition-delay: 0.08s; }
.reveal-stagger > .reveal:nth-child(3) { transition-delay: 0.16s; }
.reveal-stagger > .reveal:nth-child(4) { transition-delay: 0.24s; }
.reveal-stagger > .reveal:nth-child(5) { transition-delay: 0.32s; }
.reveal-stagger > .reveal:nth-child(6) { transition-delay: 0.40s; }
.reveal-stagger > .reveal:nth-child(7) { transition-delay: 0.48s; }
.reveal-stagger > .reveal:nth-child(8) { transition-delay: 0.56s; }

/* ── Tooltip ─────────────────────────────────────────────────── */
[data-tip] {
  position: relative;
  cursor: help;
}

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: var(--surface);
  color: var(--bone);
  border: 1px solid var(--red-dark);
  font-family: var(--font-type);
  font-size: 10px;
  padding: 6px 10px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: all 0.2s var(--ease-out);
  z-index: 100;
}

[data-tip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ── Blood Bar ───────────────────────────────────────────────── */
.blood-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.blood-bar-track {
  flex: 1;
  height: 3px;
  background: var(--border);
  position: relative;
  min-width: 30px;
}

.blood-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  transition: width 1s var(--ease-out);
}

.blood-bar-label {
  font-family: var(--font-mono);
  font-size: 8px;
  color: var(--ash);
  min-width: 30px;
  text-align: right;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  body { font-size: 12px; }
  .section-head { flex-wrap: wrap; }
  .section-sub { margin-left: 0; width: 100%; }
}

@media (max-width: 600px) {
  .section-num { font-size: 24px; }
  .section-title { font-size: 18px; }
}

/* ── Print ───────────────────────────────────────────────────── */
@media print {
  #theme-toggle,
  #back-nav,
  body::before,
  body::after { display: none !important; }
  body { background: #fff; color: #000; }
}
