/* ============================================================================
   NDEB OSCE STUDY COMPANION — REFINED DESIGN SYSTEM
   v2 · Editorial study-journal aesthetic with three reading modes.
   ============================================================================ */

/* ─── 1. TOKENS ─────────────────────────────────────────────────────────── */

:root {
  /* Default theme = "paper" (warm cream) */
  --paper:        #faf6ee;
  --paper-2:      #f3ede0;
  --paper-3:      #e9e1d0;
  --paper-4:      #ddd4be;
  --ink:          #1a1a1a;
  --ink-2:        #44403c;
  --ink-3:        #78716c;
  --ink-4:        #a8a29e;
  --line:         #d6d3d1;
  --line-soft:    #e7e5e4;
  --surface:      rgba(255, 255, 255, 0.55);
  --surface-2:    rgba(255, 255, 255, 0.75);
  --surface-3:    rgba(255, 255, 255, 0.92);
  --shadow-sm:    0 1px 2px rgba(26, 26, 26, 0.04);
  --shadow-md:    0 4px 16px -2px rgba(26, 26, 26, 0.08);
  --grain-opacity: 0.025;

  /* Subject palette — editorial saturation */
  --c-endo:       #d63384;  --c-endo-d:    #831843;  --c-endo-tint:    #fce7f3;
  --c-perio:      #0d9488;  --c-perio-d:   #134e4a;  --c-perio-tint:   #ccfbf1;
  --c-pharm:      #d97706;  --c-pharm-d:   #78350f;  --c-pharm-tint:   #fef3c7;
  --c-surg:       #dc2626;  --c-surg-d:    #7f1d1d;  --c-surg-tint:    #fee2e2;
  --c-pm:         #1d4ed8;  --c-pm-d:      #1e3a8a;  --c-pm-tint:      #dbeafe;
  --c-ortho:      #7c3aed;  --c-ortho-d:   #4c1d95;  --c-ortho-tint:   #ede9fe;
  --c-prostho:    #c026d3;  --c-prostho-d: #701a75;  --c-prostho-tint: #fae8ff;
  --c-anat:       #0891b2;  --c-anat-d:    #155e75;  --c-anat-tint:    #cffafe;
  --c-path:       #b91c1c;  --c-path-d:    #7f1d1d;  --c-path-tint:    #fecaca;

  /* Functional */
  --good:    #15803d;
  --bad:     #b91c1c;
  --warn:    #b45309;
  --info:    #1e40af;

  /* Typography */
  --font-display: 'Instrument Serif', 'Playfair Display', Georgia, serif;
  --font-body:    'Geist', 'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'Geist Mono', 'JetBrains Mono', ui-monospace, monospace;

  /* Geometry — 8px rhythm */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --header-h: 64px;

  color-scheme: light;
}

/* "Lamp" — warm dim sepia mode for evening reading */
[data-theme="lamp"] {
  --paper:        #2a241c;
  --paper-2:      #211c15;
  --paper-3:      #1a1611;
  --paper-4:      #14110d;
  --ink:          #f1e9d2;
  --ink-2:        #d8cfb8;
  --ink-3:        #a39888;
  --ink-4:        #7a715f;
  --line:         #443a2c;
  --line-soft:    #362e23;
  --surface:      rgba(255, 246, 220, 0.045);
  --surface-2:    rgba(255, 246, 220, 0.07);
  --surface-3:    rgba(255, 246, 220, 0.1);
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md:    0 4px 16px -2px rgba(0, 0, 0, 0.4);
  --grain-opacity: 0.04;

  --c-endo-tint:    rgba(214, 51, 132, 0.16);
  --c-perio-tint:   rgba(13, 148, 136, 0.18);
  --c-pharm-tint:   rgba(217, 119, 6, 0.18);
  --c-surg-tint:    rgba(220, 38, 38, 0.18);
  --c-pm-tint:      rgba(29, 78, 216, 0.22);
  --c-ortho-tint:   rgba(124, 58, 237, 0.2);
  --c-prostho-tint: rgba(192, 38, 211, 0.18);
  --c-anat-tint:    rgba(8, 145, 178, 0.2);
  --c-path-tint:    rgba(185, 28, 28, 0.18);

  --c-endo-d:    #f9a8d4;
  --c-perio-d:   #5eead4;
  --c-pharm-d:   #fcd34d;
  --c-surg-d:    #fca5a5;
  --c-pm-d:      #93c5fd;
  --c-ortho-d:   #c4b5fd;
  --c-prostho-d: #f0abfc;
  --c-anat-d:    #67e8f9;
  --c-path-d:    #fca5a5;

  color-scheme: dark;
}

/* "Slate" — true clean dark */
[data-theme="slate"] {
  --paper:        #0f1115;
  --paper-2:      #161922;
  --paper-3:      #1f2330;
  --paper-4:      #2a2f3e;
  --ink:          #e6e8ee;
  --ink-2:        #c8ccd8;
  --ink-3:        #8a91a3;
  --ink-4:        #5c6378;
  --line:         #2d3242;
  --line-soft:    #232735;
  --surface:      rgba(255, 255, 255, 0.03);
  --surface-2:    rgba(255, 255, 255, 0.06);
  --surface-3:    rgba(255, 255, 255, 0.08);
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:    0 6px 20px -4px rgba(0, 0, 0, 0.6);
  --grain-opacity: 0;

  --c-endo-tint:    rgba(214, 51, 132, 0.14);
  --c-perio-tint:   rgba(13, 148, 136, 0.16);
  --c-pharm-tint:   rgba(217, 119, 6, 0.16);
  --c-surg-tint:    rgba(220, 38, 38, 0.16);
  --c-pm-tint:      rgba(29, 78, 216, 0.2);
  --c-ortho-tint:   rgba(124, 58, 237, 0.18);
  --c-prostho-tint: rgba(192, 38, 211, 0.16);
  --c-anat-tint:    rgba(8, 145, 178, 0.18);
  --c-path-tint:    rgba(185, 28, 28, 0.16);

  --c-endo-d:    #f9a8d4;
  --c-perio-d:   #5eead4;
  --c-pharm-d:   #fcd34d;
  --c-surg-d:    #fca5a5;
  --c-pm-d:      #93c5fd;
  --c-ortho-d:   #c4b5fd;
  --c-prostho-d: #f0abfc;
  --c-anat-d:    #67e8f9;
  --c-path-d:    #fca5a5;

  color-scheme: dark;
}

/* ─── 2. RESET & BASE ───────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-feature-settings: "ss01", "cv11";
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-image:
    radial-gradient(circle at 12% 8%, rgba(180,83,9,0.05), transparent 35%),
    radial-gradient(circle at 88% 92%, rgba(13,148,136,0.05), transparent 40%);
  background-attachment: fixed;
  transition: background-color 0.3s ease, color 0.3s ease;
}

[data-theme="lamp"] body,
[data-theme="slate"] body {
  background-image:
    radial-gradient(circle at 12% 8%, rgba(252,211,77,0.04), transparent 35%),
    radial-gradient(circle at 88% 92%, rgba(94,234,212,0.04), transparent 40%);
}

/* Subtle grain texture */
body::before {
  content: "";
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='1'/></svg>");
  opacity: var(--grain-opacity);
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: multiply;
}
[data-theme="lamp"] body::before,
[data-theme="slate"] body::before { mix-blend-mode: overlay; }

main, header, section, article, footer, .modal { position: relative; z-index: 2; }

::selection { background: var(--accent, var(--c-perio)); color: white; }

/* ─── 3. TYPOGRAPHY ─────────────────────────────────────────────────────── */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.012em;
  line-height: 1.08;
  color: var(--ink);
}
h1 { font-size: clamp(2.4rem, 5.5vw, 4.6rem); margin: 0 0 0.4em; }
h2 { font-size: clamp(1.8rem, 3.5vw, 2.6rem); margin: 0 0 0.4em; }
h3 { font-size: 1.4rem; margin: 1.6em 0 0.5em; }
h4 { font-size: 1.05rem; margin: 1em 0 0.4em; font-weight: 500; }

p { margin: 0 0 1em; }

a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.15s, background-color 0.15s;
}
a:hover { color: var(--accent-d, var(--c-perio-d)); }

strong, b { font-weight: 600; }
em { font-style: italic; }

.kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  display: inline-block;
}

.wrap         { max-width: 1280px; margin: 0 auto; padding: 0 32px; }
.wrap-tight   { max-width: 920px;  margin: 0 auto; padding: 0 32px; }
.wrap-reading { max-width: 1080px; margin: 0 auto; padding: 0 32px; }

/* ─── 4. READING PROGRESS BAR ───────────────────────────────────────────── */

.reading-progress {
  position: fixed; top: 0; left: 0;
  height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--accent, var(--c-perio)), var(--accent-d, var(--c-perio-d)));
  z-index: 100;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent, var(--c-perio));
}

/* ─── 5. SITE HEADER ────────────────────────────────────────────────────── */

.site-header {
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 60;
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 14px; padding-bottom: 14px;
  gap: 24px;
  min-height: var(--header-h);
}

.brand {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 400;
  text-decoration: none;
  display: flex; align-items: baseline; gap: 8px;
  color: var(--ink);
  white-space: nowrap;
}
.brand:hover { background: transparent; color: var(--ink); }
.brand sup {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.12em;
}

.subject-nav {
  display: flex;
  gap: 4px;
  font-size: 13px;
  flex-wrap: wrap;
  flex: 1;
  justify-content: center;
}
.subject-nav a {
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  position: relative;
  transition: color 0.15s, background-color 0.15s;
}
.subject-nav a:hover {
  background: var(--paper-2);
  color: var(--ink);
}
.subject-nav a.is-active {
  color: var(--ink);
  background: var(--paper-3);
}
.subject-nav a.is-active::after {
  content: "";
  position: absolute;
  bottom: -2px; left: 10px; right: 10px;
  height: 2px;
  background: var(--accent, var(--c-perio));
  border-radius: 2px;
}

/* Header action buttons (search, theme) */
.header-tools {
  display: flex; gap: 6px;
  align-items: center;
}
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 13px;
  transition: all 0.15s;
  padding: 0;
}
.icon-btn:hover {
  background: var(--paper-2);
  color: var(--ink);
  border-color: var(--ink-3);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.search-btn {
  width: auto;
  padding: 0 10px 0 8px;
  gap: 8px;
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.icon-btn.search-btn kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--ink-2);
}
.icon-btn.search-btn span { display: inline; }

.mobile-menu-toggle {
  display: none;
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  cursor: pointer;
  align-items: center; justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
.mobile-menu-toggle svg { width: 18px; height: 18px; }

@media (max-width: 1100px) {
  .subject-nav { display: none; }
  .mobile-menu-toggle { display: inline-flex; }
  .site-header .wrap { padding: 12px 20px; }
}

@media (max-width: 600px) {
  /* Collapse search button to icon-only on small phones */
  .icon-btn.search-btn span,
  .icon-btn.search-btn kbd { display: none; }
  .icon-btn.search-btn { width: 36px; padding: 0; }
  .header-tools { gap: 4px; }
  .brand { font-size: 18px; }
  .brand sup { display: none; }
}

/* Mobile drawer */
.mobile-drawer {
  position: fixed;
  top: var(--header-h);
  right: 0;
  width: min(320px, 90vw);
  height: calc(100vh - var(--header-h));
  background: var(--paper);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 70;
  overflow-y: auto;
  padding: 24px 28px 40px;
  box-shadow: var(--shadow-md);
}
.mobile-drawer.is-open { transform: translateX(0); }
.mobile-drawer .kicker { margin-bottom: 12px; display: block; }
.mobile-drawer nav {
  display: flex; flex-direction: column; gap: 2px;
  margin-bottom: 24px;
}
.mobile-drawer nav a {
  padding: 10px 12px;
  text-decoration: none;
  color: var(--ink-2);
  border-radius: var(--r-sm);
  font-size: 15px;
  border-left: 2px solid transparent;
}
.mobile-drawer nav a:hover,
.mobile-drawer nav a.is-active {
  background: var(--paper-2);
  color: var(--ink);
  border-left-color: var(--accent, var(--c-perio));
}
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s;
  z-index: 65;
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }

/* ─── 6. HERO (subject pages) ───────────────────────────────────────────── */

.hero {
  border-bottom: 1px solid var(--line);
  padding: 80px 0 60px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--accent-tint) 0%, transparent 65%);
  z-index: -1;
}
.hero .wrap {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 60px;
  align-items: center;
}
@media (max-width: 900px) {
  .hero { padding: 56px 0 48px; }
  .hero .wrap { grid-template-columns: 1fr; gap: 40px; }
}
.hero-meta { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; flex-wrap: wrap; }
.hero-meta .num {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--ink); color: var(--paper);
  padding: 5px 11px; border-radius: 999px;
  letter-spacing: 0.1em;
  font-weight: 500;
}
.hero h1 { color: var(--accent-d); }
.hero h1 em { font-style: italic; }
.hero .lede {
  font-size: 1.18rem;
  color: var(--ink-2);
  max-width: 54ch;
  font-weight: 300;
  line-height: 1.5;
}

.blueprint-badge {
  border: 2px solid var(--accent);
  border-radius: var(--r-md);
  padding: 28px 24px;
  background: var(--surface-2);
  text-align: center;
  position: relative;
  box-shadow: var(--shadow-md);
}
.blueprint-badge::before {
  content: "";
  position: absolute; top: 10px; right: 10px;
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
}
.blueprint-badge .pct {
  font-family: var(--font-display);
  font-size: clamp(5rem, 12vw, 7.5rem);
  line-height: 0.85;
  color: var(--accent-d);
  font-weight: 400;
  letter-spacing: -0.04em;
}
.blueprint-badge .pct sub {
  font-size: 0.32em;
  vertical-align: baseline;
  opacity: 0.55;
  margin-left: 2px;
}
.blueprint-badge .label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-top: 6px;
}

/* ─── 7. CHAPTER LAYOUT WITH STICKY SIDEBAR TOC ─────────────────────────── */

.chapter-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 60px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 32px;
  align-items: start;
}
@media (max-width: 1080px) {
  .chapter-layout { grid-template-columns: 1fr; gap: 0; }
}

.toc-sidebar {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  padding: 30px 0 30px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  border-left: 2px solid var(--accent);
  padding-left: 18px;
}
@media (max-width: 1080px) {
  .toc-sidebar { position: relative; top: 0; padding: 20px 24px; margin: 24px 0; }
}
.toc-sidebar .toc-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 12px;
  font-weight: 600;
}
.toc-list { display: flex; flex-direction: column; gap: 3px; }
.toc-list a {
  display: flex; align-items: baseline;
  gap: 10px;
  padding: 6px 8px 6px 4px;
  color: var(--ink-3);
  text-decoration: none;
  border-radius: 3px;
  line-height: 1.4;
  transition: all 0.15s;
}
.toc-list a:hover {
  color: var(--ink);
  background: var(--paper-2);
}
.toc-list a.is-active {
  color: var(--accent-d);
  background: var(--accent-tint);
  font-weight: 600;
}
.toc-list a .n {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  width: 18px;
  flex-shrink: 0;
}

.chapter-content { min-width: 0; }

/* Legacy support: original .toc class from existing markup */
.toc {
  border-left: 2px solid var(--accent);
  padding: 4px 0 4px 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  margin: 30px 0;
}
.toc .toc-list { display: flex; flex-direction: column; gap: 6px; }
.toc a { color: var(--ink-2); text-decoration: none; padding: 2px 0; display: block; }
.toc a:hover { color: var(--accent-d); background: transparent; }
.toc .n { color: var(--accent); margin-right: 10px; font-weight: 600; }

/* ─── 8. TOPIC SECTIONS ─────────────────────────────────────────────────── */

section.topic {
  padding: 64px 0 56px;
  border-top: 1px solid var(--line-soft);
}
section.topic:first-of-type { border-top: none; padding-top: 48px; }

.chapter-content section.topic .wrap { padding: 0; max-width: none; }
@media (max-width: 1080px) {
  .chapter-content section.topic .wrap { padding: 0 32px; }
}

.topic-head {
  display: flex; align-items: baseline; gap: 18px;
  margin-bottom: 30px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}
.topic-head .num {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.06em;
  background: var(--accent-tint);
  padding: 3px 9px;
  border-radius: 3px;
}
.topic-head h2 { margin: 0; }
.topic-intro {
  font-size: 1.05rem;
  max-width: 62ch;
  color: var(--ink-2);
  margin: 0 0 28px 0;
  line-height: 1.55;
}

/* ─── 9. GRID & CARDS ───────────────────────────────────────────────────── */

.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 800px) {
  .g-2, .g-3, .g-4 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 22px 24px;
  position: relative;
  transition: border-color 0.15s, background-color 0.15s;
}
.card:hover { border-color: var(--ink-3); }
.card.bordered-l { border-left: 4px solid var(--accent); }
.card h4 { margin-top: 0; color: var(--accent-d); }

/* ─── 10. CALLOUTS ──────────────────────────────────────────────────────── */

.note {
  border-left: 2px solid var(--accent);
  padding: 14px 20px;
  background: var(--surface-2);
  margin: 20px 0;
  font-size: 0.96em;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.note .tag-mini {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent-d);
  font-weight: 600;
  margin-right: 8px;
}

.callout {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  padding: 16px 20px;
  border-radius: var(--r-md);
  margin: 18px 0;
  font-size: 0.96em;
  line-height: 1.55;
  border: 1px solid transparent;
}
.callout .icon {
  width: 28px; height: 28px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}
.callout strong:first-child {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 6px;
  font-weight: 600;
}
.callout.hook  { background: color-mix(in srgb, var(--c-pharm-tint) 70%, var(--surface)); border-color: color-mix(in srgb, var(--c-pharm) 30%, transparent); }
.callout.hook .icon { background: var(--c-pharm); }
.callout.tip   { background: color-mix(in srgb, var(--c-pm-tint) 70%, var(--surface)); border-color: color-mix(in srgb, var(--c-pm) 30%, transparent); }
.callout.tip .icon { background: var(--c-pm); }
.callout.trap  { background: color-mix(in srgb, var(--c-surg-tint) 70%, var(--surface)); border-color: color-mix(in srgb, var(--c-surg) 30%, transparent); }
.callout.trap .icon { background: var(--c-surg); }
.callout.key   { background: color-mix(in srgb, #d1fae5 60%, var(--surface)); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.callout.key .icon { background: var(--good); }
[data-theme="lamp"] .callout.key,
[data-theme="slate"] .callout.key { background: rgba(21, 128, 61, 0.15); }

/* ─── 11. TABLES ────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.5;
  min-width: 480px;
}
table.data thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--ink-3);
  background: var(--surface-2);
  position: sticky; top: 0;
  z-index: 1;
}
table.data tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody td:first-child {
  font-weight: 500;
  color: var(--accent-d);
}
table.data .narrow {
  width: 1%;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-2);
}

/* ─── 12. PILLS / TAGS ──────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  vertical-align: middle;
  font-weight: 500;
}
.pill.acc   { background: var(--accent-tint); color: var(--accent-d); }
.pill.red   { background: var(--c-surg-tint); color: var(--c-surg-d); }
.pill.green { background: #d1fae5; color: #065f46; }
.pill.amber { background: var(--c-pharm-tint); color: var(--c-pharm-d); }
.pill.blue  { background: var(--c-pm-tint); color: var(--c-pm-d); }
.pill.gray  { background: var(--paper-3); color: var(--ink-2); }
[data-theme="lamp"] .pill.green,
[data-theme="slate"] .pill.green { background: rgba(21, 128, 61, 0.18); color: #6ee7b7; }

/* ─── 13. FLOW / DECISION TREE ──────────────────────────────────────────── */

.flow {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface-2);
  padding: 24px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  font-size: 14px;
}
.flow-row {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  align-items: start;
}
.flow-row .step {
  font-family: var(--font-mono);
  background: var(--accent);
  color: white;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.flow-arrow {
  margin-left: 14px; height: 20px;
  display: flex; align-items: center;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
}
.flow-arrow::before { content: "↓"; font-size: 18px; }

.branch {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 14px 0;
}
.branch .opt {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  padding: 14px 16px;
  border-radius: var(--r-sm);
}
.branch .opt h4 { margin: 0 0 6px; color: var(--accent-d); font-size: 0.95em; }
.branch .opt p  { margin: 0; font-size: 0.93em; color: var(--ink-2); }

/* ─── 14. STATS ─────────────────────────────────────────────────────────── */

.stat {
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.stat .v {
  font-family: var(--font-display);
  font-size: 2.6rem; line-height: 1;
  color: var(--accent-d);
  font-weight: 400;
}
.stat .l {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ─── 15. HOMEPAGE — HERO ───────────────────────────────────────────────── */

.home-hero {
  padding: 80px 0 60px;
  border-bottom: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.home-hero::before {
  content: "";
  position: absolute; top: -50%; right: -10%;
  width: 60%; height: 200%;
  background: radial-gradient(ellipse at center, var(--c-perio-tint) 0%, transparent 60%);
  z-index: -1;
  opacity: 0.5;
  pointer-events: none;
}
.home-hero .wrap {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 60px;
  align-items: center;
}
@media (max-width: 980px) {
  .home-hero { padding: 60px 0 50px; }
  .home-hero .wrap { grid-template-columns: 1fr; gap: 50px; }
}
.home-hero h1 {
  font-size: clamp(2.8rem, 8vw, 6.5rem);
  letter-spacing: -0.025em;
  font-weight: 400;
  margin: 0.2em 0 0.3em;
  line-height: 0.96;
}
.home-hero h1 em {
  font-style: italic;
  color: var(--c-perio-d);
}
.home-hero .lede {
  font-size: 1.18rem;
  max-width: 54ch;
  color: var(--ink-2);
  line-height: 1.55;
  font-weight: 300;
}

.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  margin-top: 44px;
}
@media (max-width: 600px) {
  .home-stats { grid-template-columns: 1fr; }
  .home-stats .stat-cell { border-right: none; border-bottom: 1px solid var(--line); }
  .home-stats .stat-cell:last-child { border-bottom: none; }
}
.home-stats .stat-cell {
  padding: 24px 24px;
  border-right: 1px solid var(--line);
}
.home-stats .stat-cell:last-child { border-right: none; }
.home-stats .v {
  font-family: var(--font-display);
  font-size: 2.8rem; line-height: 1;
  color: var(--c-pm-d);
  font-weight: 400;
}
.home-stats .l {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 8px;
}

/* Blueprint pie chart container */
.blueprint-chart { position: relative; }
.blueprint-chart svg { display: block; margin: 0 auto; max-width: 460px; width: 100%; }
.blueprint-chart .legend-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin-top: 24px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.blueprint-chart .legend-list .row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dotted var(--line);
  align-items: center;
  color: var(--ink-2);
}
.blueprint-chart .legend-list .swatch {
  width: 12px; height: 12px;
  border-radius: 2px;
}
.blueprint-chart .legend-list .pct {
  color: var(--ink);
  font-weight: 600;
}

/* Question format strip */
.strip {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 64px 0;
  background: var(--paper-2);
}
.strip .wrap {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr;
  gap: 60px;
}
@media (max-width: 900px) { .strip .wrap { grid-template-columns: 1fr; gap: 36px; } }
.strip h2 { font-size: 2rem; margin: 8px 0 18px; }
.strip .strip-intro {
  font-size: 1rem;
  color: var(--ink-2);
  max-width: 48ch;
  line-height: 1.55;
}
.strip .source {
  margin-top: 18px;
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
}

.qtypes { display: grid; gap: 14px; }
.qtype {
  display: grid;
  grid-template-columns: 70px 1fr 90px;
  gap: 20px;
  align-items: center;
  padding: 18px 22px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: border-color 0.15s, background-color 0.15s;
}
.qtype:hover {
  border-color: var(--ink-3);
  background: var(--surface-3);
}
.qtype .num {
  font-family: var(--font-display);
  font-size: 2.6rem;
  color: var(--c-perio-d);
  line-height: 1;
  font-weight: 400;
}
.qtype .desc h4 {
  margin: 0 0 4px 0;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.qtype .desc p {
  margin: 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.5;
}
.qtype .marks {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
}
.qtype .marks b {
  display: block;
  font-size: 22px;
  color: var(--c-pm-d);
  margin-bottom: 2px;
  font-family: var(--font-display);
  font-weight: 400;
}

.section-head {
  border-top: 1px solid var(--line);
  padding: 60px 0 30px;
}
.section-head .wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}
.section-head h2 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0;
}
.section-head .meta {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

/* Subject grid */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}
@media (max-width: 980px) { .subject-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .subject-grid { grid-template-columns: 1fr; } }

.subject-card {
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 30px 28px 28px;
  text-decoration: none;
  color: var(--ink);
  position: relative;
  transition: background-color 0.2s ease;
  background: var(--surface);
  overflow: hidden;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}
.subject-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.subject-card:hover {
  background: var(--accent-tint);
  color: var(--ink);
}
.subject-card:hover::before { transform: scaleX(1); }

.subject-card .num {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--ink-3);
  margin-bottom: 18px;
}
.subject-card h3 {
  font-family: var(--font-display);
  font-size: 1.85rem;
  margin: 0 0 10px;
  color: var(--accent-d);
  line-height: 1.05;
}
.subject-card p {
  font-size: 14px;
  color: var(--ink-2);
  margin: 0 0 24px;
  flex: 1;
  line-height: 1.55;
}
.subject-card .meta {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}
.subject-card .meta .pct {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}
.subject-card .arrow {
  position: absolute;
  right: 24px; bottom: 24px;
  font-size: 22px;
  color: var(--accent);
  transition: transform 0.2s;
  line-height: 1;
}
.subject-card:hover .arrow { transform: translateX(4px); }

/* ─── 16. FOOTER ────────────────────────────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 50px 0 36px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  margin-top: 40px;
}
.site-footer .wrap {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
}
.site-footer a { color: inherit; text-decoration-color: var(--line); }
.site-footer a:hover { color: var(--ink); }

/* ─── 17. FIGURES / SVG ─────────────────────────────────────────────────── */

.fig {
  margin: 30px 0;
  padding: 28px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--r-md);
  position: relative;
}
.fig figcaption {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.fig .fig-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin: 4px 0 18px;
}

svg { max-width: 100%; height: auto; }
.svg-stroke { stroke: var(--ink); fill: none; stroke-width: 1.5; }
.svg-accent { stroke: var(--accent); fill: var(--accent); }

/* Make embedded SVGs (used hard-coded colors) blend better in dark modes */
[data-theme="lamp"] .fig svg text,
[data-theme="slate"] .fig svg text { fill: var(--ink-2); }
[data-theme="lamp"] .fig svg [fill="#1a1a1a"],
[data-theme="slate"] .fig svg [fill="#1a1a1a"] { fill: var(--ink); }
[data-theme="lamp"] .fig svg [fill="#78716c"],
[data-theme="slate"] .fig svg [fill="#78716c"] { fill: var(--ink-3); }
[data-theme="lamp"] .fig svg [fill="#fff"],
[data-theme="slate"] .fig svg [fill="#fff"] { fill: var(--paper); }
[data-theme="lamp"] .fig svg [fill="rgba(255,255,255,0.7)"],
[data-theme="slate"] .fig svg [fill="rgba(255,255,255,0.7)"],
[data-theme="lamp"] .fig svg [fill="rgba(255,255,255,0.5)"],
[data-theme="slate"] .fig svg [fill="rgba(255,255,255,0.5)"] { fill: var(--surface-3); }

/* ─── 18. MNEMONIC BLOCKS ───────────────────────────────────────────────── */

.mnemonic {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0;
  margin: 18px 0;
  border: 1px solid var(--ink);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface);
}
.mnemonic .letter {
  padding: 18px 18px 16px;
  border-right: 1px solid var(--line);
  text-align: left;
  position: relative;
}
.mnemonic .letter:last-child { border-right: none; }
.mnemonic .letter .L {
  font-family: var(--font-display);
  font-size: 3rem;
  color: var(--accent-d);
  line-height: 0.9;
  font-weight: 400;
}
.mnemonic .letter .word {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 4px; margin-bottom: 4px;
}
.mnemonic .letter .body {
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-2);
}

/* ─── 19. KEY/VALUE & PROGRESS ──────────────────────────────────────────── */

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  font-size: 14px;
}
.kv dt {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  align-self: baseline;
}
.kv dd { margin: 0; color: var(--ink); }

.progress {
  height: 8px;
  background: var(--paper-3);
  border-radius: 4px;
  overflow: hidden;
  margin: 4px 0;
}
.progress > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-d));
}

/* ─── 20. SEARCH MODAL ──────────────────────────────────────────────────── */

.search-modal {
  position: fixed; inset: 0;
  background: rgba(20, 18, 14, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 80;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 0;
}
[data-theme="lamp"] .search-modal,
[data-theme="slate"] .search-modal { background: rgba(0, 0, 0, 0.7); }
.search-modal.is-open { display: flex; }

.search-panel {
  width: min(640px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(0,0,0,0.04);
  overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 70vh;
}
.search-input-row {
  display: flex; align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.search-input-row svg { width: 18px; height: 18px; color: var(--ink-3); flex-shrink: 0; }
.search-input-row input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
}
.search-input-row kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 6px;
  color: var(--ink-3);
}
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.search-results .group-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 12px 12px 6px;
}
.search-results a {
  display: flex; flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--ink);
  border-radius: var(--r-sm);
  border-left: 2px solid transparent;
}
.search-results a:hover,
.search-results a.is-focused {
  background: var(--paper-2);
  border-left-color: var(--c-perio);
}
.search-results .title {
  font-size: 14px;
  font-weight: 500;
}
.search-results .meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}
.search-results .empty {
  padding: 24px;
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
}
.search-footer {
  border-top: 1px solid var(--line);
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  display: flex; gap: 18px;
  background: var(--paper-2);
}
.search-footer kbd {
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  margin-right: 4px;
}

/* ─── 21. STAGE-CARD (Periodontics) ─────────────────────────────────────── */

.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 30px 0;
}
@media (max-width: 800px) { .stage-grid { grid-template-columns: 1fr 1fr; } }
.stage {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  padding: 20px 18px;
  border-radius: var(--r-sm);
  position: relative;
}
.stage[data-stage="I"]   { border-top-color: #6ee7b7; }
.stage[data-stage="II"]  { border-top-color: #14b8a6; }
.stage[data-stage="III"] { border-top-color: #d97706; }
.stage[data-stage="IV"]  { border-top-color: #b91c1c; }
.stage .id {
  font-family: var(--font-display);
  font-size: 3rem;
  line-height: 1;
  color: var(--accent-d);
}
.stage h4 {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 4px 0 14px;
  font-weight: 500;
}
.stage dl { margin: 0; font-size: 13px; }
.stage dt {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 8px;
}
.stage dd { margin: 2px 0 0; color: var(--ink); font-weight: 500; }

/* ─── 22. ACCESSIBILITY & PRINT ─────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--accent, var(--c-perio));
  outline-offset: 2px;
  border-radius: 3px;
}

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

@media print {
  :root { --paper: white; --ink: black; --ink-2: #333; --ink-3: #666; --line: #ccc; }
  body { background: white !important; color: black !important; }
  body::before, .reading-progress { display: none !important; }
  .site-header, .site-footer, .mobile-drawer, .drawer-backdrop, .search-modal, .header-tools, .mobile-menu-toggle { display: none !important; }
  .hero, section.topic { page-break-inside: avoid; padding: 18px 0 !important; border-color: #ccc !important; }
  .hero::before { display: none; }
  .blueprint-badge { box-shadow: none; }
  .chapter-layout { grid-template-columns: 1fr; gap: 0; padding: 0 24px; }
  .toc-sidebar { display: none; }
  .callout { break-inside: avoid; }
  table { break-inside: avoid; }
  a { color: black !important; text-decoration: none; }
  .home-hero, .strip { padding: 20px 0 !important; }
}
