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

:root {
  --bg: #0f1117;
  --bg-card: #181b24;
  --bg-card-hover: #1e2230;
  --text: #d4d7e0;
  --text-muted: #8a8f9e;
  --text-bright: #eef0f6;
  --accent: #4a9eab;
  --accent-dim: #3a7e8b;
  --green: #3daa6d;
  --green-bg: rgba(61, 170, 109, 0.12);
  --amber: #c4913a;
  --amber-bg: rgba(196, 145, 58, 0.12);
  --border: #282c3a;
  --border-light: #333848;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --max-w: 780px;
  --radius: 8px;
  --radius-lg: 12px;
}

html { scroll-behavior: smooth; font-size: 18px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.container { max-width: var(--max-w); margin: 0 auto; padding: 0 1.5rem; }
section { padding: 4rem 0; border-bottom: 1px solid var(--border); }
section:last-of-type { border-bottom: none; }

/* ── Typography ── */
h1 { font-size: 2.4rem; line-height: 1.2; color: var(--text-bright); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.6rem; line-height: 1.3; color: var(--text-bright); font-weight: 600; margin-bottom: 1rem; letter-spacing: -0.01em; }
h3 { font-size: 1.15rem; line-height: 1.4; color: var(--text-bright); font-weight: 600; margin-bottom: 0.5rem; }
h4 { font-size: 0.75rem; color: var(--accent); font-weight: 600; margin-bottom: 0.25rem; text-transform: uppercase; letter-spacing: 0.04em; }

p { margin-bottom: 1rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

strong { color: var(--text-bright); font-weight: 600; }

.subtitle { color: var(--text-muted); font-size: 1.1rem; line-height: 1.5; margin-top: 1rem; }
.section-intro { font-size: 1.05rem; color: var(--text-muted); margin-bottom: 2rem; }
.highlight { color: var(--accent); }
.stat { font-family: var(--font-mono); color: var(--accent); font-weight: 600; }

cite, .cite {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: normal;
  display: inline;
}

/* ── Term Links (subtle glossary links) ── */
a.term {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--border-light);
  transition: border-color 0.2s, color 0.2s;
}
a.term:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
  text-decoration: none;
}

/* ── Sticky Nav ── */
.sticky-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}
.nav-links::-webkit-scrollbar { display: none; }

.nav-links a {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.nav-links a:hover { color: var(--text-bright); background: var(--bg-card); text-decoration: none; }
.nav-links a.active { color: var(--accent); background: rgba(74, 158, 171, 0.1); }

/* ── Nav Divider ── */
.nav-divider {
  width: 1px;
  height: 14px;
  background: var(--border-light);
  flex-shrink: 0;
  margin: 0 0.15rem;
}

/* ── Toggle ── */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.toggle-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color 0.2s;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.toggle-label.active { color: var(--accent); }
.toggle-label.inactive { color: var(--text-muted); }

.toggle-track {
  width: 44px;
  height: 24px;
  background: var(--border-light);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-track.technical { background: var(--accent-dim); }

.toggle-knob {
  width: 20px;
  height: 20px;
  background: var(--text-bright);
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}
.toggle-track.technical .toggle-knob { transform: translateX(0); }
.toggle-track.plain .toggle-knob { transform: translateX(20px); }

/* ── Audience toggle logic ── */
.tech { display: none; }
.plain { display: none; }
body.mode-technical .tech { display: block; }
body.mode-technical .plain { display: none; }
body.mode-plain .tech { display: none; }
body.mode-plain .plain { display: block; }
/* Inline variants */
span.tech, span.plain { display: none; }
body.mode-technical span.tech { display: inline; }
body.mode-plain span.plain { display: inline; }

/* ── Hero ── */
.hero {
  padding: 5rem 0 3rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.hero h1 { margin-bottom: 0; }
.hero .subtitle { max-width: 600px; margin-left: auto; margin-right: auto; }
.hero-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 2rem;
  padding: 0.5rem 1.2rem;
  background: var(--bg-card);
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* ── Page Header (sub-pages) ── */
.page-header {
  padding: 4rem 0 2rem;
  border-bottom: 1px solid var(--border);
}
.page-header h1 { font-size: 2rem; }
.page-header .subtitle { max-width: 600px; }

/* ── Mechanism Cards ── */
.mech-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.mech-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: border-color 0.2s, background 0.2s;
}
.mech-card:hover { border-color: var(--border-light); background: var(--bg-card-hover); }

.mech-card h3 { margin-bottom: 0.15rem; font-size: 1.05rem; }
.mech-card .plain-name { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; margin-bottom: 0.75rem; }
.mech-card p { font-size: 0.88rem; line-height: 1.55; }

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.75rem;
}
.badge-home { background: var(--green-bg); color: var(--green); }
.badge-clinical { background: var(--amber-bg); color: var(--amber); }

.mech-card .finding {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin: 1.5rem 0; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  line-height: 1.5;
}
th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border-light);
  color: var(--text-bright);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(74, 158, 171, 0.04); }

td.num { font-family: var(--font-mono); text-align: right; white-space: nowrap; }
td.accent { color: var(--accent); font-weight: 600; }
.table-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.5rem; }

tr.row-highlight td { background: rgba(74, 158, 171, 0.08); }

/* ── Callout Boxes ── */
.callout {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}
.callout.callout-amber { border-left-color: var(--amber); }
.callout.callout-green { border-left-color: var(--green); }
.callout p { margin-bottom: 0.5rem; }
.callout p:last-child { margin-bottom: 0; }

/* ── Timeline ── */
.timeline { margin: 1.5rem 0; }
.timeline-item {
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-phase {
  flex-shrink: 0;
  width: 90px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  padding-top: 0.1rem;
}
.timeline-content { font-size: 0.88rem; }
.timeline-content strong { display: block; margin-bottom: 0.2rem; }

/* ── Cost Boxes ── */
.cost-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin: 1.5rem 0;
}
.cost-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.cost-box h3 { font-size: 1rem; margin-bottom: 0.75rem; }
.cost-big {
  font-family: var(--font-mono);
  font-size: 2rem;
  color: var(--accent);
  font-weight: 700;
  line-height: 1;
}
.cost-per {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.cost-detail {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  line-height: 1.5;
}

/* ── Comparison mini-table ── */
.cmp-table td:first-child { font-weight: 600; color: var(--text-bright); white-space: nowrap; }

/* ── References ── */
.ref-section { margin-bottom: 1.5rem; }
.ref-section h4 { margin-bottom: 0.5rem; }
.ref-section p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 0.35rem;
}

/* ── Glossary ── */
.glossary-grid { margin: 2rem 0; }
.glossary-entry {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}
.glossary-entry:first-child { padding-top: 0; }
.glossary-entry:last-child { border-bottom: none; }
.glossary-entry h3 {
  font-size: 1.05rem;
  margin-bottom: 0.1rem;
}
.glossary-entry .abbr {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

/* ── Lists ── */
ul.content-list {
  margin: 0.75rem 0 1.5rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ── Footer ── */
footer {
  padding: 3rem 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}
footer p { margin-bottom: 0.3rem; }
footer a { color: var(--text-muted); }
footer a:hover { color: var(--accent); }

/* ── Responsive ── */
@media (max-width: 700px) {
  html { font-size: 16px; }
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.35rem; }
  .mech-grid { grid-template-columns: 1fr; }
  .cost-grid { grid-template-columns: 1fr; }
  .nav-links a { font-size: 0.68rem; padding: 0.25rem 0.4rem; }
  section { padding: 2.5rem 0; }
  .hero { padding: 3rem 0 2rem; }
  .page-header { padding: 3rem 0 1.5rem; }
  .timeline-item { flex-direction: column; gap: 0.25rem; }
  .timeline-phase { width: auto; }
}

@media (max-width: 480px) {
  .nav-links { display: none; }
  .nav-inner { justify-content: center; }
}
