/* The Human Heart — a visual explainer.
   Theme tokens, layout, demo containers, color-coded parts. */

:root {
  /* Light "paper" theme (default) */
  --bg: #f4ecdf;
  --bg-alt: #ece1ca;
  --paper: #fbf6e9;
  --ink: #1a1612;
  --ink-soft: #3b332b;
  --ink-muted: #7a6f5f;
  --ink-faint: #b3a98f;
  --rule: #d9cdb0;
  --rule-soft: #e8dec6;

  /* Anatomy palette — used by SVG demos and inline part labels */
  --deox: #2563eb;        /* deoxygenated blood — blue */
  --deox-soft: #93b8f5;
  --deox-wash: rgba(37, 99, 235, 0.12);
  --ox: #c0223a;          /* oxygenated blood — red */
  --ox-soft: #e88b97;
  --ox-wash: rgba(192, 34, 58, 0.12);
  --muscle: #b35a4a;      /* myocardium — coral pink */
  --muscle-soft: #d99a8c;
  --muscle-wash: rgba(179, 90, 74, 0.12);
  --valve: #c69226;       /* valves — antique gold */
  --valve-soft: #e6c97a;
  --valve-wash: rgba(198, 146, 38, 0.14);
  --spark: #e08a1a;       /* electrical signal — amber */
  --spark-soft: #f3b865;
  --spark-wash: rgba(224, 138, 26, 0.16);
  --vessel: #6f6757;      /* generic vessel wall */
  --tissue: #ddc7a6;      /* surrounding body tissue */
  --o2: #63a37a;          /* oxygen molecules — sage */
  --co2: #8a7396;         /* CO2 — muted plum */

  --serif: 'Source Serif 4', 'IBM Plex Serif', Georgia, serif;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;

  --sidenav-w: 280px;
  --content-max: 720px;
  --content-pad: 32px;
  --demo-radius: 10px;
}

[data-theme="lacquer"] {
  --bg: #0c1310;
  --bg-alt: #131c17;
  --paper: #1a2520;
  --ink: #f1ead4;
  --ink-soft: #d6cdb0;
  --ink-muted: #9b9277;
  --ink-faint: #5a5544;
  --rule: rgba(214, 205, 176, 0.18);
  --rule-soft: rgba(214, 205, 176, 0.08);

  --deox: #6ea3ff;
  --deox-soft: #2a5dc7;
  --deox-wash: rgba(110, 163, 255, 0.14);
  --ox: #ff6b7d;
  --ox-soft: #c53a4d;
  --ox-wash: rgba(255, 107, 125, 0.14);
  --muscle: #e09988;
  --muscle-soft: #a35a4a;
  --muscle-wash: rgba(224, 153, 136, 0.14);
  --valve: #e6c97a;
  --valve-soft: #b08a30;
  --valve-wash: rgba(230, 201, 122, 0.16);
  --spark: #ffb454;
  --spark-soft: #c47e1a;
  --spark-wash: rgba(255, 180, 84, 0.18);
  --vessel: #8a8270;
  --tissue: #2a3128;
  --o2: #8ec4a0;
  --co2: #b29bbf;
}

[data-theme="study"] {
  --bg: #ffffff;
  --bg-alt: #f7f4ef;
  --paper: #ffffff;
  --ink: #15110c;
  --ink-soft: #2f2920;
  --ink-muted: #6f6857;
  --ink-faint: #b8b0a0;
  --rule: #e6dcc4;
  --rule-soft: #f1ead4;

  --deox: #1f4ed1;
  --deox-soft: #88a4e6;
  --deox-wash: rgba(31, 78, 209, 0.10);
  --ox: #b21b32;
  --ox-soft: #df8090;
  --ox-wash: rgba(178, 27, 50, 0.10);
  --muscle: #a44a3b;
  --muscle-soft: #d18b7d;
  --muscle-wash: rgba(164, 74, 59, 0.10);
  --valve: #b88322;
  --valve-soft: #dcbb6d;
  --valve-wash: rgba(184, 131, 34, 0.12);
  --spark: #d27514;
  --spark-soft: #efaa5a;
  --spark-wash: rgba(210, 117, 20, 0.14);
  --vessel: #7a715f;
  --tissue: #ecdfc4;
  --o2: #4f9067;
  --co2: #7a6588;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-feature-settings: 'kern', 'liga';
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
  text-wrap: pretty;
}

a { color: inherit; text-decoration: none; border-bottom: 1px solid var(--ink-faint); }
a:hover { color: var(--ox); border-bottom-color: var(--ox); }

/* ───────────── Sidebar ───────────── */

.sidenav {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: var(--sidenav-w);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  z-index: 50;
  border-right: 1px solid var(--rule-soft);
  background: var(--bg);
  overflow-y: auto;
}

.brand {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.2px;
  color: var(--ink-soft);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-pulse {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--ox);
  animation: pulse 1.1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.85); opacity: 0.85; }
  20%      { transform: scale(1.15); opacity: 1; }
  40%      { transform: scale(0.95); opacity: 0.95; }
  55%      { transform: scale(1.10); opacity: 1; }
  75%      { transform: scale(0.85); opacity: 0.85; }
}

.brand-sub {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 28px 22px;
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 9px 12px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink-soft);
  text-decoration: none;
  border: 0;
  border-radius: 6px;
  transition: background .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav a:hover { background: var(--ox-wash); color: var(--ox); border-bottom: 0; }
.nav a.is-active { background: var(--ox-wash); color: var(--ox); font-weight: 500; }
.nav-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 500;
  min-width: 20px;
  flex-shrink: 0;
}
.nav a.is-active .nav-num,
.nav a:hover .nav-num { color: var(--ox); }

.theme-picker {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
}
.theme-label {
  font-family: var(--sans);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-muted);
  font-weight: 600;
  padding: 0 8px 6px;
}
.theme-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 7px 10px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-muted);
  border-radius: 5px;
  text-align: left;
  transition: color .15s, background .15s;
}
.theme-btn:hover { color: var(--ink); background: var(--rule-soft); }
.theme-btn.is-active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* ───────────── Content ───────────── */

.content {
  margin-left: var(--sidenav-w);
  padding: 64px var(--content-pad) 96px;
  max-width: calc(var(--sidenav-w) + var(--content-max) + var(--content-pad) * 2);
}

.hero {
  max-width: var(--content-max);
  margin: 0 auto 56px;
}
.hero-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 18px;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 56px;
  line-height: 1.05;
  letter-spacing: -1.5px;
  margin: 0 0 20px;
  color: var(--ink);
}
.hero .lede {
  font-size: 19px;
  color: var(--ink-soft);
  margin: 0 0 18px;
  font-weight: 400;
  max-width: 56ch;
}
.hero .meta {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 28px;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
.hero .meta span::before {
  content: '·';
  margin-right: 18px;
  color: var(--ink-faint);
}
.hero .meta span:first-child::before { content: ''; margin: 0; }

section {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 56px 0;
  border-top: 1px solid var(--rule-soft);
}
section:first-of-type { border-top: 0; }

.section-num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-muted);
  letter-spacing: 1px;
  margin-bottom: 12px;
}
section h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 36px;
  line-height: 1.15;
  letter-spacing: -0.5px;
  margin: 0 0 18px;
  color: var(--ink);
}
section h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.2px;
  margin: 36px 0 12px;
  color: var(--ink);
}
section p {
  font-size: 17px;
  line-height: 1.65;
  margin: 0 0 16px;
  color: var(--ink-soft);
}
section p em { color: var(--ink); font-style: italic; }
section p strong { color: var(--ink); font-weight: 600; }

.callout {
  border-left: 3px solid var(--valve);
  padding: 6px 16px;
  margin: 22px 0;
  background: var(--valve-wash);
  font-size: 15.5px;
  color: var(--ink-soft);
}
.callout strong { color: var(--ink); }

/* ───────────── Color-coded inline parts ───────────── */

.k-deox    { color: var(--deox);   font-weight: 600; }
.k-ox      { color: var(--ox);     font-weight: 600; }
.k-muscle  { color: var(--muscle); font-weight: 600; }
.k-valve   { color: var(--valve);  font-weight: 600; }
.k-spark   { color: var(--spark);  font-weight: 600; }
.k-o2      { color: var(--o2);     font-weight: 600; }
.k-co2     { color: var(--co2);    font-weight: 600; }

/* ───────────── Demo container ───────────── */

.demo {
  margin: 24px 0 8px;
  background: var(--paper);
  border: 1px solid var(--rule-soft);
  border-radius: var(--demo-radius);
  padding: 18px 18px 14px;
  position: relative;
}
.demo-stage {
  width: 100%;
  display: block;
  border-radius: 6px;
  background: var(--bg-alt);
  overflow: hidden;
}
.demo-stage svg {
  display: block;
  width: 100%;
  height: auto;
}

.demo-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.demo-caption {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 10px;
  letter-spacing: 0.2px;
}

.btn-play {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--bg-alt);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  padding: 6px 14px;
  border-radius: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-play:hover { color: var(--ink); border-color: var(--ink-faint); }
.btn-play .glyph {
  width: 0; height: 0;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent currentColor;
}
.btn-play.is-playing .glyph {
  width: 8px; height: 9px;
  border: 0;
  background: linear-gradient(to right, currentColor 0 3px, transparent 3px 5px, currentColor 5px 8px);
}

/* Slider */
.slider {
  -webkit-appearance: none; appearance: none;
  flex: 1;
  height: 4px;
  background: var(--rule);
  border-radius: 2px;
  outline: none;
  min-width: 120px;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--ink-soft);
  cursor: pointer;
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--rule);
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink-soft);
  cursor: pointer;
  border: 2px solid var(--paper);
}
.slider.k-ox::-webkit-slider-thumb     { background: var(--ox); }
.slider.k-deox::-webkit-slider-thumb   { background: var(--deox); }
.slider.k-valve::-webkit-slider-thumb  { background: var(--valve); }
.slider.k-spark::-webkit-slider-thumb  { background: var(--spark); }
.slider.k-muscle::-webkit-slider-thumb { background: var(--muscle); }

.slider-label {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-muted);
  min-width: 60px;
  letter-spacing: 0.2px;
}
.slider-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  min-width: 56px;
  text-align: right;
}

/* Toggle (segmented control) */
.seg {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 18px;
  padding: 2px;
  background: var(--bg-alt);
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-muted);
  padding: 5px 14px;
  cursor: pointer;
  border-radius: 14px;
  font-weight: 500;
  letter-spacing: 0.3px;
}
.seg button.is-on {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* ───────────── Layout helpers ───────────── */

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.row.wrap { flex-wrap: wrap; }

/* Mobile */
@media (max-width: 900px) {
  :root { --sidenav-w: 0px; }
  .sidenav {
    position: static;
    height: auto;
    width: 100%;
    padding: 18px 18px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--rule-soft);
  }
  .sidenav .theme-picker { margin-top: 16px; padding-top: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav a { padding: 6px 10px; font-size: 12.5px; }
  .nav-num { display: none; }
  .content { margin-left: 0; padding: 24px 18px 64px; }
  .hero h1 { font-size: 38px; }
  .hero .lede { font-size: 17px; }
  section h2 { font-size: 28px; }
  section p { font-size: 16px; }
}

/* ───────────── Section-specific tweaks ───────────── */

/* Section 01: diffusion */
.diffusion-readout {
  display: flex;
  gap: 24px;
  margin-top: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.diffusion-readout .k { color: var(--ink-muted); margin-right: 6px; letter-spacing: 0.3px; }

/* Section 04 / 08 readouts */
.readout-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 18px;
  margin-top: 16px;
}
.readout-grid > div {
  border: 1px solid var(--rule-soft);
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--bg-alt);
}
.readout-grid .label {
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 6px;
}
.readout-grid .value {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--ink);
  font-weight: 500;
}
.readout-grid .unit {
  font-size: 12px;
  color: var(--ink-muted);
  margin-left: 4px;
}
@media (max-width: 600px) {
  .readout-grid { grid-template-columns: 1fr; }
}

/* Wiggers panel stack */
.wiggers-stack { display: flex; flex-direction: column; gap: 0; }
.wiggers-stack svg { background: transparent; }

/* Anatomy hover labels */
.anatomy-label {
  font-family: var(--sans);
  font-size: 11px;
  fill: var(--ink-soft);
  pointer-events: none;
}
.anatomy-label.bold { font-weight: 600; }
.anatomy-hit { fill: transparent; cursor: pointer; }
.anatomy-hit:hover ~ .anatomy-label,
.anatomy-hit.is-on ~ .anatomy-label { fill: var(--ink); }

/* Generic SVG defaults */
.svg-bg { fill: var(--bg-alt); }
.svg-paper { fill: var(--paper); }
.svg-ink { fill: var(--ink); }
.svg-stroke { stroke: var(--ink-soft); fill: none; }
.svg-rule { stroke: var(--rule); fill: none; }

/* Footer */
.colophon {
  max-width: var(--content-max);
  margin: 64px auto 0;
  padding-top: 32px;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-muted);
}
.colophon a { border-bottom-color: var(--rule); }
