/* ============================================================
   DIAMOND OS — PLAYBOOK VIEWER v3
   The Enchanted Living Book
   Premium Book Design with magical micro-interactions
   Inspired by Harvard Business Review, McKinsey reports,
   Penguin Classics, premium coffee-table publications
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;0,900;1,400;1,700&family=Inter:wght@300;400;500;600;700;800;900&family=Source+Serif+4:ital,wght@0,300;0,400;0,600;1,300;1,400&family=JetBrains+Mono:wght@400&family=Cormorant+Garamond:ital,wght@0,400;0,700;0,900;1,700&family=Newsreader:wght@300;400;500&family=DM+Serif+Display:ital@0;1&family=DM+Sans:wght@400;500;600;700&display=swap');

/* ── Design Tokens ── */
:root {
  /* Light theme (default) — warm cream book pages */
  --bg-page: #faf8f5;
  --bg-page-deep: #f5f0eb;
  --bg-surface: #f0ebe4;
  --bg-cover: #f7f4f0;

  --text-body: #1a1a18;
  --text-heading: #0f0f0e;
  --text-secondary: #4a4a48;
  --text-tertiary: #7a7a76;
  --text-caption: #8a8a86;

  --accent: #0E9DBF;
  --accent-light: #19C2E4;
  --accent-faint: rgba(14, 157, 191, 0.08);
  --accent-border: rgba(14, 157, 191, 0.2);
  --accent-glow: rgba(14, 157, 191, 0.12);

  --border-rule: #e8e4df;
  --border-light: #eeebe7;
  --border-ornament: #d4cfc8;

  --bg-code: #f0ebe4;
  --bg-blockquote: transparent;

  --highlight-bg: rgba(14, 157, 191, 0.1);
  --highlight-bg-strong: rgba(14, 157, 191, 0.18);

  --shadow-subtle: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-drawer: -4px 0 24px rgba(0,0,0,0.08);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.08);

  /* Typography scale */
  --font-serif: 'Playfair Display', 'Georgia', 'Times New Roman', serif;
  --font-body-serif: 'Source Serif 4', 'Georgia', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  /* Layout */
  --content-max: 1280px;
  --content-reading-max: 1020px;
  --toc-width: 200px;
  --content-padding-x: 3.5rem;
  --content-padding-y: 4rem;
  --reading-progress-height: 2px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --duration: 200ms;
  --duration-slow: 400ms;

  /* Print-friendly margins */
  --margin-page-top: 4rem;
  --margin-page-bottom: 6rem;

  /* Gilded edge */
  --gilded-color: rgba(14, 157, 191, 0.08);

  /* Paper texture */
  --paper-noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.015'/%3E%3C/svg%3E");
}

/* ── Dark Theme ── */
[data-theme="dark"] {
  --bg-page: #1a1a1e;
  --bg-page-deep: #141418;
  --bg-surface: #222226;
  --bg-cover: #1e1e22;

  --text-body: #e8e4df;
  --text-heading: #f0ece7;
  --text-secondary: #a09a92;
  --text-tertiary: #706a62;
  --text-caption: #5a5650;

  --accent: #57C8E7;
  --accent-light: #8EDAEF;
  --accent-faint: rgba(87, 200, 231, 0.1);
  --accent-border: rgba(87, 200, 231, 0.25);
  --accent-glow: rgba(87, 200, 231, 0.15);

  --border-rule: #2a2a2e;
  --border-light: #252528;
  --border-ornament: #3a3a3e;

  --bg-code: #222226;
  --bg-blockquote: transparent;

  --highlight-bg: rgba(87, 200, 231, 0.12);
  --highlight-bg-strong: rgba(87, 200, 231, 0.2);

  --shadow-subtle: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-drawer: -4px 0 24px rgba(0,0,0,0.4);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.4);

  --gilded-color: rgba(87, 200, 231, 0.04);
}

/* ── Sepia / Night Shift Theme ── */
[data-theme="sepia"] {
  --bg-page: #f4e8d1;
  --bg-page-deep: #eedcc2;
  --bg-surface: #e8d4b8;
  --bg-cover: #f0e0c8;

  --text-body: #3d2b1f;
  --text-heading: #2a1a10;
  --text-secondary: #5a4535;
  --text-tertiary: #7a6a5a;
  --text-caption: #8a7a6a;

  --accent: #0A7A96;
  --accent-light: #0E9DBF;
  --accent-faint: rgba(10, 122, 150, 0.1);
  --accent-border: rgba(10, 122, 150, 0.25);
  --accent-glow: rgba(10, 122, 150, 0.12);

  --border-rule: #d4c4a8;
  --border-light: #ddd0b8;
  --border-ornament: #c4b498;

  --bg-code: #e8d4b8;
  --bg-blockquote: transparent;

  --highlight-bg: rgba(10, 122, 150, 0.12);
  --highlight-bg-strong: rgba(10, 122, 150, 0.2);

  --shadow-subtle: 0 1px 3px rgba(60,40,20,0.08);
  --shadow-card: 0 2px 12px rgba(60,40,20,0.1);
  --shadow-drawer: -4px 0 24px rgba(60,40,20,0.12);
  --shadow-float: 0 8px 32px rgba(60,40,20,0.12);

  --gilded-color: rgba(10, 122, 150, 0.06);
}

/* ============================================================
   DESIGN THEMES — 4 premium themes x 2 modes (light/dark)
   Activated via data-design attribute on <html>
   Theme mode is controlled by data-mode attribute
   ============================================================ */

/* ── Global theme transition ── */
html {
  transition: background var(--duration-slow) var(--ease),
              color var(--duration-slow) var(--ease);
}

html *, html *::before, html *::after {
  transition-duration: 300ms;
}

/* ── Theme 1: Obsidian Atelier — Classic Luxury ── */
html[data-design="obsidian"][data-mode="light"] {
  --bg-page: #FAF9F7;
  --bg-page-deep: #F2F0EC;
  --bg-surface: #E8E5DF;
  --bg-cover: #F5F3EF;
  --text-body: #1C1917;
  --text-heading: #0C0A09;
  --text-secondary: #44403C;
  --text-tertiary: #78716C;
  --text-caption: #A8A29E;
  --accent: #B8860B;
  --accent-light: #D4A017;
  --accent-faint: rgba(184, 134, 11, 0.08);
  --accent-border: rgba(184, 134, 11, 0.2);
  --accent-glow: rgba(184, 134, 11, 0.12);
  --border-rule: #E7E5E4;
  --border-light: #F5F5F4;
  --border-ornament: #D6D3D1;
  --bg-code: #F5F5F4;
  --bg-blockquote: transparent;
  --highlight-bg: rgba(184, 134, 11, 0.1);
  --highlight-bg-strong: rgba(184, 134, 11, 0.18);
  --shadow-subtle: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-drawer: -4px 0 24px rgba(0,0,0,0.08);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.08);
  --gilded-color: rgba(184, 134, 11, 0.08);
  --font-serif: 'Cormorant Garamond', 'Georgia', serif;
  --font-body-serif: 'Newsreader', 'Georgia', serif;
}

html[data-design="obsidian"][data-mode="dark"] {
  --bg-page: #0D0D0F;
  --bg-page-deep: #080809;
  --bg-surface: #16161A;
  --bg-cover: #111114;
  --text-body: #D4D0C8;
  --text-heading: #F0EDE5;
  --text-secondary: #A09A90;
  --text-tertiary: #6A645C;
  --text-caption: #504A42;
  --accent: #D4A017;
  --accent-light: #E8C547;
  --accent-faint: rgba(212, 160, 23, 0.1);
  --accent-border: rgba(212, 160, 23, 0.25);
  --accent-glow: rgba(212, 160, 23, 0.15);
  --border-rule: #1E1E22;
  --border-light: #1A1A1E;
  --border-ornament: #2A2A2E;
  --bg-code: #16161A;
  --bg-blockquote: transparent;
  --highlight-bg: rgba(212, 160, 23, 0.12);
  --highlight-bg-strong: rgba(212, 160, 23, 0.2);
  --shadow-subtle: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.4);
  --shadow-drawer: -4px 0 24px rgba(0,0,0,0.5);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.5);
  --gilded-color: rgba(212, 160, 23, 0.04);
  --font-serif: 'Cormorant Garamond', 'Georgia', serif;
  --font-body-serif: 'Newsreader', 'Georgia', serif;
}

/* ── Theme 2: Liquid Glass — Translucent Editorial ── */
html[data-design="glass"][data-mode="light"] {
  --bg-page: #F5F5F7;
  --bg-page-deep: #EDEDF0;
  --bg-surface: rgba(255,255,255,0.72);
  --bg-cover: #F0F0F3;
  --text-body: #1D1D1F;
  --text-heading: #000000;
  --text-secondary: #424245;
  --text-tertiary: #6E6E73;
  --text-caption: #86868B;
  --accent: #0071E3;
  --accent-light: #2997FF;
  --accent-faint: rgba(0, 113, 227, 0.08);
  --accent-border: rgba(0, 113, 227, 0.2);
  --accent-glow: rgba(0, 113, 227, 0.12);
  --border-rule: rgba(0,0,0,0.06);
  --border-light: rgba(0,0,0,0.04);
  --border-ornament: rgba(0,0,0,0.1);
  --bg-code: rgba(0,0,0,0.03);
  --bg-blockquote: transparent;
  --highlight-bg: rgba(0, 113, 227, 0.1);
  --highlight-bg-strong: rgba(0, 113, 227, 0.18);
  --shadow-subtle: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-card: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-drawer: -4px 0 32px rgba(0,0,0,0.08);
  --shadow-float: 0 12px 40px rgba(0,0,0,0.1);
  --gilded-color: rgba(0, 113, 227, 0.04);
  --font-serif: 'Inter', -apple-system, sans-serif;
  --font-body-serif: 'Source Serif 4', 'Georgia', serif;
  --glass-blur: blur(40px);
  --glass-radius: 16px;
}

html[data-design="glass"][data-mode="dark"] {
  --bg-page: #111113;
  --bg-page-deep: #0A0A0C;
  --bg-surface: rgba(255,255,255,0.06);
  --bg-cover: #151517;
  --text-body: #E5E5EA;
  --text-heading: #F5F5F7;
  --text-secondary: #A1A1A6;
  --text-tertiary: #6E6E73;
  --text-caption: #48484A;
  --accent: #2997FF;
  --accent-light: #5AC8FA;
  --accent-faint: rgba(41, 151, 255, 0.1);
  --accent-border: rgba(41, 151, 255, 0.2);
  --accent-glow: rgba(41, 151, 255, 0.15);
  --border-rule: rgba(255,255,255,0.06);
  --border-light: rgba(255,255,255,0.04);
  --border-ornament: rgba(255,255,255,0.1);
  --bg-code: rgba(255,255,255,0.04);
  --bg-blockquote: transparent;
  --highlight-bg: rgba(41, 151, 255, 0.12);
  --highlight-bg-strong: rgba(41, 151, 255, 0.2);
  --shadow-subtle: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-card: 0 4px 16px rgba(0,0,0,0.3);
  --shadow-drawer: -4px 0 32px rgba(0,0,0,0.5);
  --shadow-float: 0 12px 40px rgba(0,0,0,0.5);
  --gilded-color: rgba(41, 151, 255, 0.04);
  --font-serif: 'Inter', -apple-system, sans-serif;
  --font-body-serif: 'Source Serif 4', 'Georgia', serif;
  --glass-blur: blur(40px);
  --glass-radius: 16px;
}

/* ── Theme 3: Monochrome Manuscript — Minimalist B&W ── */
html[data-design="monochrome"][data-mode="light"] {
  --bg-page: #FFFFFF;
  --bg-page-deep: #F5F5F5;
  --bg-surface: #F0F0F0;
  --bg-cover: #FAFAFA;
  --text-body: #222222;
  --text-heading: #000000;
  --text-secondary: #555555;
  --text-tertiary: #888888;
  --text-caption: #AAAAAA;
  --accent: #C41E3A;
  --accent-light: #DC3545;
  --accent-faint: rgba(196, 30, 58, 0.06);
  --accent-border: rgba(196, 30, 58, 0.15);
  --accent-glow: rgba(196, 30, 58, 0.08);
  --border-rule: #E0E0E0;
  --border-light: #EEEEEE;
  --border-ornament: #CCCCCC;
  --bg-code: #F5F5F5;
  --bg-blockquote: transparent;
  --highlight-bg: rgba(196, 30, 58, 0.08);
  --highlight-bg-strong: rgba(196, 30, 58, 0.15);
  --shadow-subtle: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-card: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-drawer: -2px 0 12px rgba(0,0,0,0.06);
  --shadow-float: 0 4px 16px rgba(0,0,0,0.06);
  --gilded-color: rgba(0,0,0,0.03);
  --font-serif: 'Playfair Display', 'Georgia', serif;
  --font-body-serif: 'Source Serif 4', 'Georgia', serif;
}

html[data-design="monochrome"][data-mode="dark"] {
  --bg-page: #111111;
  --bg-page-deep: #0A0A0A;
  --bg-surface: #1A1A1A;
  --bg-cover: #141414;
  --text-body: #D0D0D0;
  --text-heading: #FFFFFF;
  --text-secondary: #999999;
  --text-tertiary: #666666;
  --text-caption: #444444;
  --accent: #E63946;
  --accent-light: #FF6B6B;
  --accent-faint: rgba(230, 57, 70, 0.08);
  --accent-border: rgba(230, 57, 70, 0.2);
  --accent-glow: rgba(230, 57, 70, 0.12);
  --border-rule: #222222;
  --border-light: #1A1A1A;
  --border-ornament: #333333;
  --bg-code: #1A1A1A;
  --bg-blockquote: transparent;
  --highlight-bg: rgba(230, 57, 70, 0.1);
  --highlight-bg-strong: rgba(230, 57, 70, 0.18);
  --shadow-subtle: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-card: 0 1px 4px rgba(0,0,0,0.4);
  --shadow-drawer: -2px 0 12px rgba(0,0,0,0.5);
  --shadow-float: 0 4px 16px rgba(0,0,0,0.5);
  --gilded-color: rgba(255,255,255,0.02);
  --font-serif: 'Playfair Display', 'Georgia', serif;
  --font-body-serif: 'Source Serif 4', 'Georgia', serif;
}

/* ── Theme 4: Velvet Noir — Dark Luxury ── */
html[data-design="velvet"][data-mode="light"] {
  --bg-page: #FAFAF9;
  --bg-page-deep: #F0EFEC;
  --bg-surface: #E5E4E0;
  --bg-cover: #F5F4F0;
  --text-body: #1A1918;
  --text-heading: #09090A;
  --text-secondary: #44403C;
  --text-tertiary: #78716C;
  --text-caption: #A8A29E;
  --accent: #6D28D9;
  --accent-light: #8B5CF6;
  --accent-faint: rgba(109, 40, 217, 0.06);
  --accent-border: rgba(109, 40, 217, 0.18);
  --accent-glow: rgba(109, 40, 217, 0.1);
  --border-rule: #E7E5E4;
  --border-light: #F5F5F4;
  --border-ornament: #D6D3D1;
  --bg-code: #F5F5F4;
  --bg-blockquote: transparent;
  --highlight-bg: rgba(109, 40, 217, 0.08);
  --highlight-bg-strong: rgba(109, 40, 217, 0.15);
  --shadow-subtle: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-drawer: -4px 0 24px rgba(0,0,0,0.08);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.08);
  --gilded-color: rgba(109, 40, 217, 0.04);
  --font-serif: 'DM Serif Display', 'Georgia', serif;
  --font-body-serif: 'DM Sans', -apple-system, sans-serif;
}

html[data-design="velvet"][data-mode="dark"] {
  --bg-page: #0E0E12;
  --bg-page-deep: #080810;
  --bg-surface: #18181F;
  --bg-cover: #121218;
  --text-body: #CDCDD0;
  --text-heading: #EDEDF0;
  --text-secondary: #9898A0;
  --text-tertiary: #5C5C66;
  --text-caption: #3E3E48;
  --accent: #A78BFA;
  --accent-light: #C4B5FD;
  --accent-faint: rgba(167, 139, 250, 0.08);
  --accent-border: rgba(167, 139, 250, 0.2);
  --accent-glow: rgba(167, 139, 250, 0.15);
  --border-rule: rgba(167, 139, 250, 0.08);
  --border-light: rgba(167, 139, 250, 0.04);
  --border-ornament: rgba(167, 139, 250, 0.12);
  --bg-code: #18181F;
  --bg-blockquote: transparent;
  --highlight-bg: rgba(167, 139, 250, 0.1);
  --highlight-bg-strong: rgba(167, 139, 250, 0.18);
  --shadow-subtle: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.4);
  --shadow-drawer: -4px 0 24px rgba(0,0,0,0.5);
  --shadow-float: 0 8px 32px rgba(0,0,0,0.5);
  --gilded-color: rgba(167, 139, 250, 0.04);
  --font-serif: 'DM Serif Display', 'Georgia', serif;
  --font-body-serif: 'DM Sans', -apple-system, sans-serif;
}

/* ============================================================
   THEME-SPECIFIC COMPLETE OVERRIDES
   Each theme is a full visual redesign — typography, spacing,
   effects, animations, blockquotes, dividers, progress bars,
   drop caps, FAB, sidebar, search modal, section headers.
   ============================================================ */

/* ────────────────────────────────────────────────────────────
   THEME 1: OBSIDIAN ATELIER — Classic Luxury
   Default mode: DARK
   Fonts: Cormorant Garamond (display), Newsreader (body),
          Inter (UI/meta), JetBrains Mono (code)
   ──────────────────────────────────────────────────────────── */

/* --- Obsidian: Typography --- */
html[data-design="obsidian"] .markdown-body h1 {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-weight: 900;
  font-size: 3.5rem;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

html[data-design="obsidian"] .markdown-body h2 {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-weight: 700;
  font-style: italic;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

html[data-design="obsidian"] .markdown-body h3 {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-weight: 600;
  font-size: 1.4rem;
  text-transform: none;
  letter-spacing: normal;
}

html[data-design="obsidian"] .markdown-body {
  font-family: 'Newsreader', 'Georgia', serif;
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.85;
}

html[data-design="obsidian"] .markdown-body h4,
html[data-design="obsidian"] .meta-tag,
html[data-design="obsidian"] .sidebar-subtitle,
html[data-design="obsidian"] .sidebar-section-title,
html[data-design="obsidian"] .lateral-toc-header,
html[data-design="obsidian"] .reading-time {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 400;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

html[data-design="obsidian"] .markdown-body h4 {
  font-size: 0.82rem;
  font-weight: 600;
}

html[data-design="obsidian"] .markdown-body pre code,
html[data-design="obsidian"] .markdown-body code {
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-weight: 400;
  font-size: 0.78rem;
}

/* --- Obsidian: Spacing --- */
html[data-design="obsidian"] .markdown-body p {
  margin: 0 0 1.5rem 0;
}

html[data-design="obsidian"] .section-wrapper {
  margin-top: 4.5rem;
}

html[data-design="obsidian"] .markdown-body h3 {
  margin-top: 3rem;
  margin-bottom: 1.25rem;
}

html[data-design="obsidian"] .markdown-body td,
html[data-design="obsidian"] .markdown-body th {
  padding: 0.75rem 1rem;
}

/* --- Obsidian: Drop Cap — GOLD --- */
html[data-design="obsidian"] .markdown-body h1 + p::first-letter,
html[data-design="obsidian"] .markdown-body .drop-cap::first-letter {
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-weight: 900;
  color: var(--accent);
}

/* --- Obsidian: Section Dividers — Gold Diamond Ornaments --- */
html[data-design="obsidian"] .chapter-divider::before {
  content: '\2666 \2003 \2666 \2003 \2666';
  color: var(--accent);
  opacity: 0.4;
}

html[data-design="obsidian"] .markdown-body hr::before {
  content: '\2666 \2003 \2666 \2003 \2666';
  color: var(--accent);
  opacity: 0.3;
}

html[data-design="obsidian"] .book-cover-ornament {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.3;
}

html[data-design="obsidian"] .markdown-body h1::after {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

/* --- Obsidian: Blockquotes — gold left border + faint gold bg + decorative quote --- */
html[data-design="obsidian"] .markdown-body blockquote {
  border-left: 3px solid var(--accent);
  background: rgba(212, 160, 23, 0.04);
  margin: 3rem 0;
  padding: 1.75rem;
  border-radius: 0 8px 8px 0;
}

html[data-design="obsidian"] .markdown-body blockquote::before {
  content: '\201C';
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: 4rem;
  font-weight: 900;
  color: var(--accent);
  opacity: 0.12;
  position: absolute;
  top: -0.5rem;
  left: -0.1rem;
  line-height: 1;
}

/* --- Obsidian: Progress Bar — gold with glow --- */
html[data-design="obsidian"] .reading-progress-bar {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(212, 160, 23, 0.3);
}

/* --- Obsidian: Content Entry Animation --- */
@keyframes obsidianContentEntry {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

html[data-design="obsidian"] .markdown-body .section-wrapper {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 600ms cubic-bezier(0.16, 1, 0.3, 1),
              transform 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

html[data-design="obsidian"] .markdown-body .section-wrapper.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* --- Obsidian: Section Headers Hover — gold bar on left --- */
html[data-design="obsidian"] .section-header {
  padding-left: 0.75rem;
  border-left: 2px solid transparent;
  transition: border-left-color 200ms ease;
}

html[data-design="obsidian"] .section-header:hover {
  border-left-color: var(--accent);
}

/* --- Obsidian: Floating Action Bar --- */
html[data-design="obsidian"] .floating-action-bar {
  border-color: rgba(212, 160, 23, 0.15);
}


/* ────────────────────────────────────────────────────────────
   THEME 2: LIQUID GLASS — Translucent Editorial
   Default mode: LIGHT
   Fonts: Inter (display/headings), Source Serif 4 (body)
   ──────────────────────────────────────────────────────────── */

/* --- Glass: Typography --- */
html[data-design="glass"] .markdown-body h1 {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 800;
  font-size: 3.2rem;
  letter-spacing: -0.03em;
  line-height: 1.08;
}

html[data-design="glass"] .markdown-body h2 {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 700;
  font-style: normal;
  font-size: 1.85rem;
  letter-spacing: -0.015em;
}

html[data-design="glass"] .markdown-body h3 {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 600;
  font-size: 1.3rem;
}

html[data-design="glass"] .markdown-body {
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.85;
}

/* --- Glass: Spacing --- */
html[data-design="glass"] .markdown-body p {
  margin: 0 0 1.5rem 0;
}

html[data-design="glass"] .section-wrapper {
  margin-top: 4rem;
}

/* --- Glass: ALL surfaces get frosted glass treatment --- */
html[data-design="glass"] .sidebar,
html[data-design="glass"] .floating-action-bar,
html[data-design="glass"] .search-modal,
html[data-design="glass"] .shortcuts-modal,
html[data-design="glass"] .accent-picker-panel,
html[data-design="glass"] .theme-picker-panel,
html[data-design="glass"] .markdown-body blockquote,
html[data-design="glass"] .markdown-body pre code {
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
}

/* --- Glass: ALL corners 12px --- */
html[data-design="glass"] .markdown-body blockquote,
html[data-design="glass"] .markdown-body pre code,
html[data-design="glass"] .search-modal,
html[data-design="glass"] .shortcuts-modal,
html[data-design="glass"] .accent-picker-panel,
html[data-design="glass"] .theme-picker-panel,
html[data-design="glass"] .floating-action-bar {
  border-radius: 12px;
}

html[data-design="glass"] .fab-btn {
  border-radius: 10px;
}

html[data-design="glass"] .sidebar-item {
  border-radius: 10px;
}

/* --- Glass: Surface styling (light mode) --- */
html[data-design="glass"][data-mode="light"] .sidebar,
html[data-design="glass"][data-mode="light"] .floating-action-bar,
html[data-design="glass"][data-mode="light"] .search-modal,
html[data-design="glass"][data-mode="light"] .shortcuts-modal,
html[data-design="glass"][data-mode="light"] .accent-picker-panel,
html[data-design="glass"][data-mode="light"] .theme-picker-panel,
html[data-design="glass"][data-mode="light"] .markdown-body blockquote,
html[data-design="glass"][data-mode="light"] .markdown-body pre code {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
}

/* --- Glass: Surface styling (dark mode) --- */
html[data-design="glass"][data-mode="dark"] .sidebar,
html[data-design="glass"][data-mode="dark"] .floating-action-bar,
html[data-design="glass"][data-mode="dark"] .search-modal,
html[data-design="glass"][data-mode="dark"] .shortcuts-modal,
html[data-design="glass"][data-mode="dark"] .accent-picker-panel,
html[data-design="glass"][data-mode="dark"] .theme-picker-panel,
html[data-design="glass"][data-mode="dark"] .markdown-body blockquote,
html[data-design="glass"][data-mode="dark"] .markdown-body pre code {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* --- Glass: Sidebar — no hard border, only shadow + blur --- */
html[data-design="glass"] .sidebar {
  border-right: none;
}

/* --- Glass: Blockquotes — glass card, NO left border, glass quote icon --- */
html[data-design="glass"] .markdown-body blockquote {
  border-left: none;
  border-radius: 16px;
  position: relative;
  padding: 1.75rem 1.75rem 1.75rem 2.5rem;
}

html[data-design="glass"] .markdown-body blockquote::before {
  content: '\201C';
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
  opacity: 0.15;
  line-height: 1;
}

/* --- Glass: Section Headers Hover — glass bg, 12px radius --- */
html[data-design="glass"] .section-header {
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  transition: background 250ms ease, box-shadow 250ms ease;
}

html[data-design="glass"] .section-header:hover {
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

html[data-design="glass"][data-mode="dark"] .section-header:hover {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* --- Glass: Floating Action Bar — pill shape --- */
html[data-design="glass"] .floating-action-bar {
  border-radius: 999px;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}

/* --- Glass: Search Modal --- */
html[data-design="glass"] .search-modal {
  border-radius: 16px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.12);
}

html[data-design="glass"][data-mode="dark"] .search-modal {
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.35);
}

/* --- Glass: Progress Bar — translucent gradient with blur --- */
html[data-design="glass"] .reading-progress-bar {
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  opacity: 0.5;
}

/* --- Glass: Content Entry Animation --- */
html[data-design="glass"] .markdown-body .section-wrapper {
  opacity: 0;
  transform: scale(0.99) translateY(8px);
  transition: opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
              transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

html[data-design="glass"] .markdown-body .section-wrapper.revealed {
  opacity: 1;
  transform: scale(1) translateY(0);
}

/* --- Glass: Drop Cap --- */
html[data-design="glass"] .markdown-body h1 + p::first-letter,
html[data-design="glass"] .markdown-body .drop-cap::first-letter {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 800;
  color: var(--accent);
}


/* ────────────────────────────────────────────────────────────
   THEME 3: MONOCHROME MANUSCRIPT — Minimalist B&W
   Default mode: LIGHT
   Fonts: Playfair Display (display), Source Serif 4 (body),
          Inter (H3/UI)
   ──────────────────────────────────────────────────────────── */

/* --- Monochrome: Typography --- */
html[data-design="monochrome"] .markdown-body h1 {
  font-family: 'Playfair Display', 'Georgia', serif;
  font-weight: 900;
  font-size: 4rem;
  letter-spacing: -0.04em;
  line-height: 1.0;
}

html[data-design="monochrome"] .markdown-body h2 {
  font-family: 'Playfair Display', 'Georgia', serif;
  font-weight: 700;
  font-style: normal;
  font-size: 2.2rem;
}

html[data-design="monochrome"] .markdown-body h3 {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

html[data-design="monochrome"] .markdown-body {
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 400;
  font-size: 1.05rem;
  line-height: 1.9;
}

html[data-design="monochrome"] .markdown-body h4,
html[data-design="monochrome"] .meta-tag,
html[data-design="monochrome"] .sidebar-subtitle,
html[data-design="monochrome"] .sidebar-section-title,
html[data-design="monochrome"] .lateral-toc-header,
html[data-design="monochrome"] .reading-time {
  font-family: 'Inter', -apple-system, sans-serif;
  font-weight: 500;
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

html[data-design="monochrome"] .markdown-body h4 {
  font-size: 0.82rem;
  font-weight: 600;
}

/* --- Monochrome: Spacing (most generous) --- */
html[data-design="monochrome"] .markdown-body p {
  margin: 0 0 1.6rem 0;
}

html[data-design="monochrome"] .section-wrapper {
  margin-top: 5rem;
}

html[data-design="monochrome"] .markdown-body h3 {
  margin-top: 3.5rem;
  margin-bottom: 1.25rem;
}

/* --- Monochrome: ZERO animations — no translateY, no scale --- */
html[data-design="monochrome"] .markdown-body .section-wrapper {
  transform: none !important;
  transition: opacity 400ms linear;
  opacity: 0;
}

html[data-design="monochrome"] .markdown-body .section-wrapper.revealed {
  opacity: 1;
  transform: none !important;
}

/* Disable stagger animations */
html[data-design="monochrome"] .content .meta-bar,
html[data-design="monochrome"] .content .reading-meta,
html[data-design="monochrome"] .content .markdown-body {
  animation: none;
  opacity: 1;
  transform: none;
}

/* --- Monochrome: Blockquotes — NO bg, 4px BLACK left border, italic serif --- */
html[data-design="monochrome"] .markdown-body blockquote {
  border-left: 4px solid var(--text-heading);
  background: none;
  border-radius: 0;
  padding: 1.25rem 1.5rem 1.25rem 1.75rem;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-style: italic;
}

html[data-design="monochrome"] .markdown-body blockquote::before {
  display: none;
}

/* Only <strong> inside blockquotes gets the red accent */
html[data-design="monochrome"] .markdown-body blockquote strong {
  color: var(--accent);
  background: none;
  padding: 0;
}

/* --- Monochrome: Section Dividers — plain centered 40px line --- */
html[data-design="monochrome"] .chapter-divider {
  letter-spacing: 0;
}

html[data-design="monochrome"] .chapter-divider::before {
  content: '';
  display: block;
  width: 40px;
  height: 1px;
  background: var(--text-heading);
  margin: 0 auto;
  letter-spacing: 0;
}

html[data-design="monochrome"] .markdown-body hr::before {
  content: '';
  display: block;
  width: 40px;
  height: 1px;
  background: var(--text-heading);
  margin: 0 auto;
  letter-spacing: 0;
  font-size: 0;
}

/* --- Monochrome: Drop Cap — BLACK, not accent --- */
html[data-design="monochrome"] .markdown-body h1 + p::first-letter,
html[data-design="monochrome"] .markdown-body .drop-cap::first-letter {
  font-family: 'Playfair Display', 'Georgia', serif;
  font-weight: 900;
  color: var(--text-heading);
}

/* --- Monochrome: Floating Action Bar — no blur, no shadow, no radius --- */
html[data-design="monochrome"] .floating-action-bar {
  border-radius: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
  background: var(--bg-page);
}

html[data-design="monochrome"][data-mode="light"] .floating-action-bar {
  border: 1px solid #000;
}

html[data-design="monochrome"][data-mode="dark"] .floating-action-bar {
  border: 1px solid #fff;
}

/* --- Monochrome: Progress Bar — solid red 2px, no glow --- */
html[data-design="monochrome"] .reading-progress-bar {
  background: var(--accent);
  box-shadow: none;
  opacity: 1;
}

html[data-design="monochrome"] .reading-progress {
  height: 2px;
}

/* --- Monochrome: Hover — underlines grow from 0% to 100% width --- */
html[data-design="monochrome"] .section-header {
  position: relative;
}

html[data-design="monochrome"] .section-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0%;
  height: 1px;
  background: var(--text-heading);
  transition: width 300ms ease-out;
}

html[data-design="monochrome"] .section-header:hover::after {
  width: 100%;
}

/* --- Monochrome: Section Headers Hover — chapter-num gray to RED --- */
html[data-design="monochrome"] .markdown-body h2 .chapter-num {
  transition: color 200ms ease;
}

html[data-design="monochrome"] .section-header:hover .chapter-num {
  color: var(--accent);
  opacity: 1;
}


/* ────────────────────────────────────────────────────────────
   THEME 4: VELVET NOIR — Dark Luxury
   Default mode: DARK
   Fonts: DM Serif Display (display), DM Sans (body/UI)
   ──────────────────────────────────────────────────────────── */

/* --- Velvet: Typography --- */
html[data-design="velvet"] .markdown-body h1 {
  font-family: 'DM Serif Display', 'Georgia', serif;
  font-weight: 400;
  font-size: 3.4rem;
  letter-spacing: -0.025em;
  line-height: 1.08;
}

html[data-design="velvet"] .markdown-body h2 {
  font-family: 'DM Serif Display', 'Georgia', serif;
  font-weight: 400;
  font-style: italic;
  font-size: 1.9rem;
}

html[data-design="velvet"] .markdown-body h3 {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-weight: 600;
  font-size: 1.3rem;
  text-transform: none;
  letter-spacing: normal;
}

html[data-design="velvet"] .markdown-body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.85;
}

html[data-design="velvet"] .markdown-body h4,
html[data-design="velvet"] .meta-tag,
html[data-design="velvet"] .sidebar-subtitle,
html[data-design="velvet"] .sidebar-section-title,
html[data-design="velvet"] .lateral-toc-header,
html[data-design="velvet"] .reading-time {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-weight: 500;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
}

html[data-design="velvet"] .markdown-body h4 {
  font-size: 0.82rem;
  font-weight: 600;
}

/* --- Velvet: Spacing --- */
html[data-design="velvet"] .markdown-body p {
  margin: 0 0 1.5rem 0;
}

html[data-design="velvet"] .section-wrapper {
  margin-top: 4.5rem;
}

/* --- Velvet: Glow Borders on ALL elevated surfaces (dark mode) --- */
html[data-design="velvet"][data-mode="dark"] .sidebar,
html[data-design="velvet"][data-mode="dark"] .floating-action-bar,
html[data-design="velvet"][data-mode="dark"] .search-modal,
html[data-design="velvet"][data-mode="dark"] .shortcuts-modal,
html[data-design="velvet"][data-mode="dark"] .accent-picker-panel,
html[data-design="velvet"][data-mode="dark"] .theme-picker-panel,
html[data-design="velvet"][data-mode="dark"] .markdown-body pre code,
html[data-design="velvet"][data-mode="dark"] .markdown-body blockquote {
  box-shadow: inset 0 0.5px 0 rgba(167, 139, 250, 0.12),
              0 0 0 1px rgba(167, 139, 250, 0.06);
}

/* --- Velvet: Sidebar (dark mode) --- */
html[data-design="velvet"][data-mode="dark"] .sidebar {
  background: #08080B;
  border-right: 1px solid rgba(167, 139, 250, 0.08);
}

html[data-design="velvet"][data-mode="dark"] .sidebar-header {
  box-shadow: 0 1px 0 rgba(167, 139, 250, 0.1);
}

/* --- Velvet: Floating Action Bar (dark mode) --- */
html[data-design="velvet"][data-mode="dark"] .floating-action-bar {
  border-color: rgba(167, 139, 250, 0.1);
  box-shadow: inset 0 0.5px 0 rgba(167, 139, 250, 0.12),
              0 0 0 1px rgba(167, 139, 250, 0.06),
              0 0 20px rgba(167, 139, 250, 0.06),
              0 8px 32px rgba(0, 0, 0, 0.4);
}

/* --- Velvet: Blockquotes — accent left border + gradient bg --- */
html[data-design="velvet"] .markdown-body blockquote {
  border-left: 3px solid var(--accent);
  background: rgba(167, 139, 250, 0.04);
  background-image: linear-gradient(90deg, rgba(167, 139, 250, 0.06), transparent 60%);
}

/* --- Velvet: Progress Bar — violet gradient with glow --- */
html[data-design="velvet"] .reading-progress-bar {
  background: linear-gradient(90deg, #6D28D9, #A78BFA);
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.4);
}

/* --- Velvet: Content Entry Animation — 600ms + stagger 80ms --- */
html[data-design="velvet"] .markdown-body .section-wrapper {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 600ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-design="velvet"] .markdown-body .section-wrapper.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger: each section-wrapper gets 80ms delay via nth-child */
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(2) { transition-delay: 80ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(3) { transition-delay: 160ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(4) { transition-delay: 240ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(5) { transition-delay: 320ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(6) { transition-delay: 400ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(7) { transition-delay: 480ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(8) { transition-delay: 560ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(9) { transition-delay: 640ms; }
html[data-design="velvet"] .markdown-body .section-wrapper:nth-child(10) { transition-delay: 720ms; }

/* --- Velvet: Section Headers Hover — violet highlight --- */
html[data-design="velvet"] .section-header {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  transition: background 200ms ease;
}

html[data-design="velvet"] .section-header:hover {
  background: rgba(167, 139, 250, 0.05);
}

/* --- Velvet: Search Modal (dark mode) — glow border --- */
html[data-design="velvet"][data-mode="dark"] .search-modal {
  border: 1px solid rgba(167, 139, 250, 0.15);
  box-shadow: inset 0 0.5px 0 rgba(167, 139, 250, 0.12),
              0 0 40px rgba(167, 139, 250, 0.06),
              0 20px 60px rgba(0, 0, 0, 0.3);
}

html[data-design="velvet"][data-mode="dark"] .shortcuts-modal {
  border: 1px solid rgba(167, 139, 250, 0.15);
  box-shadow: inset 0 0.5px 0 rgba(167, 139, 250, 0.12),
              0 0 40px rgba(167, 139, 250, 0.06),
              0 20px 60px rgba(0, 0, 0, 0.3);
}

/* --- Velvet: Drop Cap — violet luminous --- */
html[data-design="velvet"] .markdown-body h1 + p::first-letter,
html[data-design="velvet"] .markdown-body .drop-cap::first-letter {
  font-family: 'DM Serif Display', 'Georgia', serif;
  font-weight: 400;
  color: var(--accent);
}

/* --- Velvet: Code blocks (dark mode) — glow border --- */
html[data-design="velvet"][data-mode="dark"] .markdown-body pre code {
  border-color: rgba(167, 139, 250, 0.08);
  box-shadow: inset 0 0.5px 0 rgba(167, 139, 250, 0.12),
              0 0 12px rgba(167, 139, 250, 0.04);
}

/* ── Theme Picker Panel ── */
.theme-picker-panel {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 160;
  background: var(--bg-page-deep);
  border: 1px solid var(--border-rule);
  border-radius: 14px;
  box-shadow: var(--shadow-float);
  padding: 1.25rem 1.5rem;
  min-width: 340px;
  max-width: 420px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.theme-picker-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.theme-picker-title {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 1rem;
  letter-spacing: 0.01em;
}

.theme-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid var(--border-rule);
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  background: transparent;
}

.theme-card:hover {
  border-color: var(--text-tertiary);
  background: var(--accent-faint);
}

.theme-card.active {
  border-color: var(--accent);
  background: var(--accent-faint);
  box-shadow: 0 0 0 1px var(--accent-border);
}

.theme-card-name {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-heading);
  letter-spacing: 0.01em;
}

.theme-card-swatches {
  display: flex;
  gap: 0.3rem;
}

.theme-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

/* Mode toggle row */
.theme-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
}

.theme-mode-label {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.theme-mode-toggle {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-rule);
}

.theme-mode-btn {
  font-family: var(--font-sans);
  font-size: 0.6rem;
  font-weight: 500;
  padding: 0.3rem 0.65rem;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  letter-spacing: 0.02em;
}

.theme-mode-btn:hover {
  color: var(--text-heading);
}

.theme-mode-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── End Design Themes ── */

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

html {
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-body);
  line-height: 1.8;
  min-height: 100vh;
  overflow: hidden;
  transition: background var(--duration-slow) var(--ease),
              color var(--duration-slow) var(--ease);
  position: relative;
}

/* Paper texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--paper-noise);
  background-repeat: repeat;
  pointer-events: none;
  z-index: 1;
  opacity: 0.4;
}

::selection {
  background: var(--accent-faint);
  color: var(--accent);
}

/* ── Reading Progress Bar ── */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--reading-progress-height);
  z-index: 200;
  background: transparent;
}

.reading-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 80ms linear;
  opacity: 0.6;
}

/* ── Reading Pace Indicator ── */
.reading-pace {
  position: fixed;
  top: 6px;
  right: 1.25rem;
  z-index: 201;
  font-family: var(--font-sans);
  font-size: 0.6rem;
  color: var(--text-caption);
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
  letter-spacing: 0.02em;
}

.reading-pace.visible {
  opacity: 0.7;
}

/* ── Breadcrumb ── */
.breadcrumb {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 190;
  font-family: var(--font-sans);
  font-size: 0.6rem;
  color: var(--text-caption);
  padding: 0.4rem 1rem;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border-light);
  border-radius: 0 0 6px 6px;
  white-space: nowrap;
  max-width: 600px;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
  letter-spacing: 0.02em;
}

.breadcrumb.visible {
  opacity: 1;
}

.breadcrumb-sep {
  margin: 0 0.35rem;
  opacity: 0.4;
}

.breadcrumb-current {
  color: var(--accent);
  font-weight: 500;
}

/* ── App Layout ── */
.app {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  position: relative;
}

/* ── Gilded Edge Effect ── */
.app::after {
  content: '';
  position: fixed;
  top: 0;
  right: 0;
  width: 8px;
  height: 100vh;
  background: linear-gradient(to left, var(--gilded-color), transparent);
  z-index: 50;
  pointer-events: none;
}

/* ── Document Drawer ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 340px;
  height: 100vh;
  background: var(--bg-page-deep);
  border-right: 1px solid var(--border-rule);
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--duration-slow) var(--ease);
  box-shadow: var(--shadow-drawer);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease);
}

.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-header {
  padding: 2rem 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border-rule);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: 0.01em;
}

.logo-icon {
  font-size: 1.3rem;
  color: var(--accent);
}

.sidebar-subtitle {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-top: 0.35rem;
}

.sidebar-section-title {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 1.25rem 1.5rem 0.5rem;
}

.sidebar-list {
  list-style: none;
  padding: 0 0.75rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: all var(--duration) var(--ease);
  font-family: var(--font-sans);
  font-weight: 400;
}

.sidebar-item:hover {
  background: var(--accent-faint);
  color: var(--text-heading);
}

.sidebar-item.active {
  background: var(--accent-faint);
  color: var(--accent);
  font-weight: 500;
}

.sidebar-item .item-icon {
  font-size: 0.7rem;
  opacity: 0.5;
}

.sidebar-item.active .item-icon {
  opacity: 1;
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding: 1.25rem 1.5rem;
  font-size: 0.65rem;
  color: var(--text-caption);
  border-top: 1px solid var(--border-rule);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  letter-spacing: 0.03em;
}

.sidebar-footer .dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
}

/* ── Top Controls ── */
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border-rule);
  background: var(--bg-page);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  font-size: 1rem;
  box-shadow: var(--shadow-subtle);
  position: fixed;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 90;
}

.sidebar-toggle:hover {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-faint);
}

/* ── Top-Right Controls Group (hidden, replaced by floating action bar) ── */
.top-right-controls {
  display: none;
}

/* ── Content Wrapper ── */
.content-wrapper {
  width: 100%;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

/* ── Main Content — the book page ── */
.content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--margin-page-top) var(--content-padding-x) var(--margin-page-bottom);
  min-height: 100vh;
}

/* When lateral TOC is visible, shift content slightly left */
.content.has-toc {
  padding-right: calc(var(--content-padding-x) + var(--toc-width) + 2rem);
}

/* Ensure the markdown body content uses comfortable reading width */
.markdown-body {
  max-width: var(--content-reading-max);
}

/* ── Subtle Content Entry (replaces 3D page turn) ── */
@keyframes contentFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.content.page-entering {
  animation: contentFadeIn 0.3s var(--ease) forwards;
}

/* ── Staggered fade-in for content sections ── */
@keyframes staggerFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.content .meta-bar {
  animation: staggerFadeIn 0.5s var(--ease) 0.1s both;
}

.content .reading-meta {
  animation: staggerFadeIn 0.5s var(--ease) 0.15s both;
}

.content .markdown-body {
  animation: staggerFadeIn 0.5s var(--ease) 0.25s both;
}

/* ── Scroll Reveal for sections ── */
.markdown-body .section-wrapper {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}

.markdown-body .section-wrapper.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* ── Section Progress Pulse (left margin line) ── */
.section-wrapper {
  position: relative;
}

.section-progress-line {
  position: absolute;
  left: -1.5rem;
  top: 0;
  width: 2px;
  height: 0%;
  background: var(--accent);
  border-radius: 1px;
  transition: height 0.15s linear, opacity 0.3s var(--ease);
  opacity: 0;
}

.section-wrapper.in-view .section-progress-line {
  opacity: 0.5;
}

/* ── Section Glow on TOC Click ── */
@keyframes sectionGlow {
  0% { border-left-color: var(--accent); }
  50% { border-left-color: var(--accent-light); }
  100% { border-left-color: var(--border-light); }
}

.section-wrapper.glow-target {
  border-left: 3px solid var(--accent);
  animation: sectionGlow 0.6s var(--ease) forwards;
  padding-left: 0.75rem;
  margin-left: -0.75rem;
}

/* ── Book Cover ── */
.book-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
  padding: 4rem 2rem;
}

.empty-diamond {
  margin-bottom: 3rem;
}

.diamond-shape {
  width: 60px;
  height: 60px;
  border: 2px solid var(--border-ornament);
  transform: rotate(45deg);
  position: relative;
}

.diamond-shape::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid var(--border-ornament);
}

.book-cover-ornament {
  width: 40px;
  height: 1px;
  background: var(--border-ornament);
  margin: 1.5rem auto;
}

.book-cover-title {
  font-family: var(--font-serif);
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--text-heading);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.book-cover-subtitle {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-tertiary);
  margin-top: 1.5rem;
}

.book-cover-edition {
  font-family: var(--font-body-serif);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--text-caption);
  margin-top: 2rem;
}

/* ── Meta Bar ── */
.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 1rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-rule);
}

.meta-tag {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--border-rule);
  border-radius: 3px;
  background: transparent;
}

.meta-tag.version {
  color: var(--accent);
  border-color: var(--accent-border);
}

.meta-tag.status {
  color: var(--text-secondary);
}

/* ── Reading Meta (time + controls) ── */
.reading-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-rule);
  font-family: var(--font-sans);
}

.reading-time {
  font-size: 0.72rem;
  color: var(--text-caption);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.reading-time svg {
  width: 14px;
  height: 14px;
  opacity: 0.5;
}

/* ── Floating Lateral TOC ── */
.lateral-toc {
  position: fixed;
  right: max(1rem, calc((100vw - var(--content-reading-max)) / 2 - var(--toc-width) - 2rem));
  top: 50%;
  transform: translateY(-50%);
  width: var(--toc-width);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease);
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.lateral-toc::-webkit-scrollbar {
  display: none;
}

.lateral-toc.visible {
  opacity: 1;
  pointer-events: auto;
}

.lateral-toc-header {
  font-family: var(--font-sans);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-caption);
  margin-bottom: 0.75rem;
  padding-left: 0.75rem;
}

.lateral-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.lateral-toc-item {
  position: relative;
  margin-bottom: 0.15rem;
}

.lateral-toc-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem;
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  border-radius: 4px;
  transition: all var(--duration) var(--ease);
  border-left: 2px solid transparent;
  line-height: 1.35;
}

.lateral-toc-link:hover {
  color: var(--text-heading);
  background: var(--accent-faint);
}

.lateral-toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-faint);
}

/* Pulsing indicator for active section */
.lateral-toc-link.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s var(--ease) infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-faint); }
  50% { opacity: 0.7; box-shadow: 0 0 0 4px transparent; }
}

.lateral-toc-time {
  font-size: 0.6rem;
  color: var(--text-caption);
  white-space: nowrap;
  opacity: 0.7;
  margin-left: auto;
}

/* Section progress ring in TOC */
.section-progress-ring {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.section-progress-ring circle {
  fill: none;
  stroke-width: 2;
}

.section-progress-ring .ring-bg {
  stroke: var(--border-rule);
}

.section-progress-ring .ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s var(--ease);
  transform: rotate(-90deg);
  transform-origin: center;
}

/* Expand/Collapse all button */
.lateral-toc-actions {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem 0;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-light);
}

.toc-action-btn {
  font-family: var(--font-sans);
  font-size: 0.6rem;
  color: var(--text-caption);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 3px;
  transition: all var(--duration) var(--ease);
  letter-spacing: 0.02em;
}

.toc-action-btn:hover {
  color: var(--accent);
  background: var(--accent-faint);
}

/* ── Legacy floating-toc (dots) — hidden, replaced by lateral-toc ── */
.floating-toc {
  display: none !important;
}

/* ── Collapsible Sections ── */
.section-header {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  user-select: none;
  gap: 0.5rem;
  position: relative;
}

.section-header:hover .section-anchor,
.section-header:hover .section-copy {
  opacity: 1;
}

.section-chevron {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.35rem;
  color: var(--text-caption);
  transition: transform 0.3s var(--ease), color var(--duration) var(--ease);
}

.section-chevron svg {
  width: 14px;
  height: 14px;
}

.section-header:hover .section-chevron {
  color: var(--accent);
}

.section-chevron.collapsed {
  transform: rotate(-90deg);
}

/* Section anchor (deep-link) */
.section-anchor {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  color: var(--text-caption);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: all var(--duration) var(--ease);
  background: none;
  border: none;
  font-size: 0.8rem;
}

.section-anchor:hover {
  color: var(--accent);
  background: var(--accent-faint);
}

/* Copy section button */
.section-copy {
  position: absolute;
  right: 1.75rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  color: var(--text-caption);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: all var(--duration) var(--ease);
  background: none;
  border: none;
  font-size: 0.75rem;
}

.section-copy:hover {
  color: var(--accent);
  background: var(--accent-faint);
}

/* Collapsible content */
.section-content {
  overflow: hidden;
  transition: max-height 0.3s var(--ease), opacity 0.3s var(--ease);
  opacity: 1;
}

.section-content.collapsed {
  max-height: 0 !important;
  opacity: 0;
}

/* ── Chapter Divider Ornaments (varied) ── */
.chapter-divider {
  text-align: center;
  margin: 0.5rem 0 0;
  color: var(--border-ornament);
  font-size: 0.7rem;
  letter-spacing: 0.5em;
  opacity: 0.6;
}

.chapter-divider.style-1::before { content: '\25C7 \2003 \25C7 \2003 \25C7'; }
.chapter-divider.style-2::before { content: '\2736 \2003 \2736 \2003 \2736'; }
.chapter-divider.style-3::before { content: '\2756 \2003 \2756 \2003 \2756'; }
.chapter-divider.style-4::before { content: '\2726 \2003 \2726 \2003 \2726'; }
.chapter-divider.style-5::before { content: '\2767'; font-size: 1rem; }

/* ── Markdown Body — the book interior ── */
.markdown-body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.9;
  color: var(--text-body);
}

/* --- Chapter Title (H1) --- */
.markdown-body h1 {
  font-family: var(--font-serif);
  font-size: 3.2rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin: 0 0 0.5rem 0;
  padding-bottom: 2.5rem;
  text-align: center;
  position: relative;
}

.markdown-body h1::after {
  content: '';
  display: block;
  width: 40px;
  height: 1px;
  background: var(--accent);
  margin: 1.5rem auto 0;
}

/* --- Section Titles (H2) --- */
.markdown-body h2 {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 0;
  padding-top: 0;
  position: relative;
  flex: 1;
}

/* Chapter number before H2 */
.markdown-body h2 .chapter-num {
  display: block;
  font-family: var(--font-sans);
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  opacity: 0.5;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

/* Section wrapper spacing */
.section-wrapper {
  margin-top: 4.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border-light);
}

.section-wrapper:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

/* --- Subsections (H3) --- */
.markdown-body h3 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--accent-light);
  line-height: 1.35;
  margin: 3.5rem 0 1.25rem 0;
}

/* --- H4-H6 --- */
.markdown-body h4 {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  opacity: 0.7;
  margin: 2rem 0 0.75rem 0;
}

.markdown-body h5,
.markdown-body h6 {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 1.5rem 0 0.5rem 0;
}

/* --- Paragraphs --- */
.markdown-body p {
  margin: 0 0 1.5rem 0;
  orphans: 3;
  widows: 3;
  transition: opacity 0.3s var(--ease);
}

/* --- Ambient Reading Focus (hover paragraph brightens, neighbors dim) --- */
.ambient-reading .markdown-body .section-content > p,
.ambient-reading .markdown-body .section-content > ul,
.ambient-reading .markdown-body .section-content > ol,
.ambient-reading .markdown-body .section-content > blockquote {
  transition: opacity 0.4s var(--ease);
}

.ambient-reading .markdown-body .section-content.has-hover > p,
.ambient-reading .markdown-body .section-content.has-hover > ul,
.ambient-reading .markdown-body .section-content.has-hover > ol,
.ambient-reading .markdown-body .section-content.has-hover > blockquote {
  opacity: 0.55;
}

.ambient-reading .markdown-body .section-content.has-hover > p:hover,
.ambient-reading .markdown-body .section-content.has-hover > ul:hover,
.ambient-reading .markdown-body .section-content.has-hover > ol:hover,
.ambient-reading .markdown-body .section-content.has-hover > blockquote:hover {
  opacity: 1;
}

/* --- Drop Cap --- */
.markdown-body h1 + p::first-letter,
.markdown-body .drop-cap::first-letter {
  font-family: var(--font-serif);
  font-size: 3.4em;
  font-weight: 900;
  float: left;
  line-height: 0.8;
  margin: 0.06em 0.12em 0 0;
  color: var(--accent);
}

/* --- Links --- */
.markdown-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-border);
  transition: border-color var(--duration) var(--ease);
}

.markdown-body a:hover {
  border-bottom-color: var(--accent);
}

/* --- Strong & Emphasis --- */
.markdown-body strong {
  font-weight: 600;
  color: var(--accent);
}

.markdown-body em {
  font-style: italic;
}

/* --- Smart Highlights: bold in blockquotes gets warm highlight --- */
.markdown-body blockquote strong {
  background: var(--highlight-bg);
  padding: 0.05em 0.25em;
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* --- Blockquotes — editorial pull quotes --- */
.markdown-body blockquote {
  position: relative;
  margin: 3rem 0;
  padding: 1.75rem 1.75rem 1.75rem 2rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-faint);
  border-radius: 0 8px 8px 0;
  font-family: var(--font-body-serif);
  font-style: italic;
  font-size: 1.1rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.markdown-body blockquote::before {
  content: '\201C';
  position: absolute;
  top: -0.5rem;
  left: -0.1rem;
  font-family: var(--font-serif);
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--accent);
  opacity: 0.2;
  line-height: 1;
}

.markdown-body blockquote p {
  margin-bottom: 0.5rem;
}

.markdown-body blockquote p:last-child {
  margin-bottom: 0;
}

/* --- Lists --- */
.markdown-body ul,
.markdown-body ol {
  margin: 0 0 1.25rem 0;
  padding-left: 1.5rem;
}

.markdown-body ul {
  list-style: none;
  padding-left: 1rem;
}

.markdown-body ul > li {
  position: relative;
  padding-left: 1rem;
  margin-bottom: 0.65rem;
}

.markdown-body ul > li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.75em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
}

.markdown-body ol {
  list-style: none;
  counter-reset: ol-counter;
  padding-left: 1rem;
}

.markdown-body ol > li {
  counter-increment: ol-counter;
  position: relative;
  padding-left: 1.5rem;
  margin-bottom: 0.65rem;
}

.markdown-body ol > li::before {
  content: counter(ol-counter);
  position: absolute;
  left: 0;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--accent);
  opacity: 0.7;
}

.markdown-body li > ul,
.markdown-body li > ol {
  margin-top: 0.35rem;
  margin-bottom: 0;
}

/* --- Horizontal Rules — chapter dividers --- */
.markdown-body hr {
  border: none;
  margin: 3rem auto;
  height: auto;
  text-align: center;
  overflow: visible;
}

.markdown-body hr::before {
  content: '\25C7\2003\25C7\2003\25C7';
  display: block;
  font-size: 0.7rem;
  color: var(--border-ornament);
  letter-spacing: 0.5em;
}

/* --- Code — inline --- */
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--bg-code);
  color: var(--accent);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border-light);
}

/* --- Code Blocks --- */
.markdown-body pre {
  margin: 2rem 0;
  padding: 0;
  background: transparent;
  position: relative;
}

.markdown-body pre code {
  display: block;
  padding: 1.25rem 1.5rem;
  background: var(--bg-code);
  border: 1px solid var(--border-rule);
  border-radius: 4px;
  font-size: 0.78rem;
  line-height: 1.7;
  overflow-x: auto;
  color: var(--text-body);
}

/* --- Tables --- */
.markdown-body table {
  width: 100%;
  margin: 2rem 0;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  line-height: 1.5;
}

.markdown-body thead {
  border-bottom: 2px solid var(--text-heading);
}

.markdown-body th {
  font-weight: 600;
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-heading);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.markdown-body td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-body);
  vertical-align: top;
}

.markdown-body tbody tr:last-child td {
  border-bottom: 2px solid var(--text-heading);
}

/* --- Images --- */
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 2rem 0;
  box-shadow: var(--shadow-card);
}

/* --- Footnotes / Sources --- */
.markdown-body .source,
.markdown-body .footnote,
.markdown-body small {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-style: italic;
  color: var(--text-caption);
  line-height: 1.5;
}

/* ── Quote Extraction Floating Button ── */
.quote-copy-btn {
  position: absolute;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg-page);
  border: 1px solid var(--border-rule);
  border-radius: 6px;
  box-shadow: var(--shadow-float);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
  animation: quoteBtnIn 0.15s var(--ease);
}

@keyframes quoteBtnIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.quote-copy-btn:hover {
  background: var(--accent-faint);
  border-color: var(--accent-border);
}

.quote-copy-btn svg {
  width: 12px;
  height: 12px;
}

/* ── Floating Action Bar ── */
.floating-action-bar {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  z-index: 150;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.6rem;
  background: color-mix(in srgb, var(--bg-page) 85%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-rule);
  border-radius: 12px;
  box-shadow: var(--shadow-float);
  transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
  opacity: 0;
  pointer-events: none;
}

.floating-action-bar.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.fab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  position: relative;
}

.fab-btn:hover {
  color: var(--accent);
  background: var(--accent-faint);
}

.fab-btn.active {
  color: var(--accent);
  background: var(--accent-faint);
}

.fab-btn svg {
  width: 16px;
  height: 16px;
}

.fab-divider {
  width: 1px;
  height: 20px;
  background: var(--border-rule);
  margin: 0 0.15rem;
}

/* Small label for font size */
.fab-btn .fab-label {
  font-size: 0.6rem;
  letter-spacing: 0.01em;
}

/* ── Accent Color Picker ── */
.fab-color-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--border-rule);
  cursor: pointer;
  transition: border-color var(--duration) var(--ease), transform var(--duration) var(--ease);
  flex-shrink: 0;
}

.fab-btn:hover .fab-color-swatch {
  border-color: var(--accent-border);
  transform: scale(1.1);
}

.accent-picker-panel {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 160;
  background: var(--bg-page-deep);
  border: 1px solid var(--border-rule);
  border-radius: 12px;
  box-shadow: var(--shadow-float);
  padding: 1.25rem 1.5rem;
  min-width: 280px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.accent-picker-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.accent-picker-title {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 0.85rem;
  letter-spacing: 0.01em;
}

.accent-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.accent-preset {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.accent-preset:hover {
  transform: scale(1.15);
  border-color: var(--text-tertiary);
}

.accent-preset.active {
  border-color: var(--text-heading);
  box-shadow: 0 0 0 2px var(--bg-page-deep), 0 0 0 3px var(--text-heading);
}

.accent-preset .preset-check {
  display: none;
  width: 12px;
  height: 12px;
  color: #fff;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}

.accent-preset.active .preset-check {
  display: block;
}

.accent-custom-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.25rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-light);
}

.accent-custom-label {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.accent-color-input {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}

.accent-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.accent-color-input::-webkit-color-swatch {
  border: 2px solid var(--border-rule);
  border-radius: 6px;
}

.accent-color-input::-moz-color-swatch {
  border: 2px solid var(--border-rule);
  border-radius: 6px;
}

.accent-hex-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-body);
  background: var(--bg-surface);
  border: 1px solid var(--border-rule);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  outline: none;
  transition: border-color var(--duration) var(--ease);
  max-width: 100px;
}

.accent-hex-input:focus {
  border-color: var(--accent-border);
}

/* ── Search Modal (Cmd+K) ── */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  backdrop-filter: blur(4px);
}

.search-overlay.open {
  display: flex;
}

.search-modal {
  width: 560px;
  max-width: 90vw;
  background: var(--bg-page);
  border: 1px solid var(--border-rule);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  overflow: hidden;
  animation: searchSlideIn 0.2s var(--ease);
}

@keyframes searchSlideIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  padding: 0.85rem 1rem;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-rule);
}

.search-input-wrapper svg {
  width: 18px;
  height: 18px;
  color: var(--text-caption);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text-body);
  outline: none;
}

.search-input::placeholder {
  color: var(--text-caption);
}

.search-kbd {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  color: var(--text-caption);
  background: var(--bg-surface);
  border: 1px solid var(--border-rule);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
}

.search-results {
  max-height: 50vh;
  overflow-y: auto;
  padding: 0.5rem;
}

.search-result-item {
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--duration) var(--ease);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-body);
  line-height: 1.5;
}

.search-result-item:hover,
.search-result-item.selected {
  background: var(--accent-faint);
}

.search-result-item mark {
  background: var(--highlight-bg-strong);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

.search-result-section {
  font-size: 0.65rem;
  color: var(--text-caption);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.2rem;
}

.search-no-results {
  padding: 2rem 1rem;
  text-align: center;
  font-family: var(--font-body-serif);
  font-style: italic;
  color: var(--text-caption);
  font-size: 0.85rem;
}

/* Search highlight in document */
.search-highlight {
  background: var(--highlight-bg-strong);
  border-radius: 2px;
  padding: 0 2px;
  scroll-margin-top: 100px;
}

/* ── Keyboard Shortcuts Modal ── */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 310;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.shortcuts-overlay.open {
  display: flex;
}

.shortcuts-modal {
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg-page);
  border: 1px solid var(--border-rule);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  padding: 2.5rem 2rem;
  animation: searchSlideIn 0.2s var(--ease);
}

.shortcuts-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-heading);
  text-align: center;
  margin-bottom: 0.35rem;
}

.shortcuts-subtitle {
  font-family: var(--font-body-serif);
  font-style: italic;
  font-size: 0.8rem;
  color: var(--text-caption);
  text-align: center;
  margin-bottom: 2rem;
}

.shortcuts-ornament {
  width: 30px;
  height: 1px;
  background: var(--border-ornament);
  margin: 0 auto 2rem;
}

.shortcut-group-title {
  font-family: var(--font-sans);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-caption);
  margin-bottom: 0.75rem;
  margin-top: 1.5rem;
}

.shortcut-group-title:first-of-type {
  margin-top: 0;
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border-light);
}

.shortcut-row:last-child {
  border-bottom: none;
}

.shortcut-desc {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.shortcut-keys {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.shortcut-key {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-heading);
  background: var(--bg-surface);
  border: 1px solid var(--border-rule);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  min-width: 1.5rem;
  text-align: center;
}

.shortcut-key-plus {
  font-size: 0.6rem;
  color: var(--text-caption);
}

/* ── Focus Mode ── */
body.focus-mode .markdown-body > *,
body.focus-mode .markdown-body .section-wrapper,
body.focus-mode .markdown-body .section-content > * {
  opacity: 0.15;
  transition: opacity 0.3s var(--ease);
}

body.focus-mode .markdown-body > *:hover,
body.focus-mode .markdown-body .section-wrapper:hover,
body.focus-mode .markdown-body .section-content > *:hover,
body.focus-mode .markdown-body > *.focus-active,
body.focus-mode .markdown-body .section-wrapper.focus-active,
body.focus-mode .markdown-body .section-content > *.focus-active {
  opacity: 1;
}

body.focus-mode .meta-bar,
body.focus-mode .reading-meta {
  opacity: 0.3;
}

/* ── Back to Top Button ── */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 85;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-rule);
  background: var(--bg-page);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-card);
  transition: all var(--duration) var(--ease);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-faint);
}

.back-to-top svg {
  width: 16px;
  height: 16px;
}

/* ── Copied Toast ── */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-heading);
  color: var(--bg-page);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s var(--ease);
  z-index: 500;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Error State ── */
.content-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  text-align: center;
}

.error-icon {
  font-size: 2rem;
  color: var(--text-caption);
  margin-bottom: 1rem;
}

.content-error p {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--text-secondary);
}

.error-detail {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--bg-code);
  border-radius: 4px;
  border: 1px solid var(--border-rule);
}

/* ── Skeleton Loader ── */
.skeleton-loader {
  max-width: var(--content-reading-max);
  margin: 0 auto;
  padding-top: 2rem;
}

.skeleton-line {
  height: 1rem;
  background: var(--border-light);
  border-radius: 2px;
  margin-bottom: 0.75rem;
  opacity: 0;
  animation: skeletonPulse 1.2s var(--ease) infinite;
}

.skeleton-line.title {
  height: 2rem;
  width: 50%;
  margin: 0 auto 1.5rem;
  background: var(--border-rule);
}

.skeleton-line.subtitle {
  height: 0.8rem;
  width: 30%;
  margin: 0 auto 3rem;
}

.skeleton-line.long { width: 95%; }
.skeleton-line.full { width: 100%; }
.skeleton-line.medium { width: 70%; }
.skeleton-line.short { width: 40%; }

.skeleton-block {
  height: 6rem;
  background: var(--border-light);
  border-radius: 4px;
  margin: 1.5rem 0;
  opacity: 0;
  animation: skeletonPulse 1.2s var(--ease) infinite;
}

@keyframes skeletonPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.5; }
}

/* ── Responsive ── */
@media (max-width: 1200px) {
  .lateral-toc {
    right: 1rem;
    width: 200px;
  }

  .content.has-toc {
    padding-right: calc(var(--content-padding-x) + 200px + 1.5rem);
  }
}

@media (max-width: 960px) {
  .lateral-toc {
    display: none !important;
  }

  .content,
  .content.has-toc {
    padding-right: var(--content-padding-x);
  }
}

@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  .content {
    padding: 3rem 1.25rem 4rem;
    padding-right: 1.25rem;
  }

  .markdown-body h1 {
    font-size: 1.8rem;
  }

  .markdown-body h2 {
    font-size: 1.3rem;
  }

  .markdown-body blockquote {
    font-size: 1rem;
  }

  .markdown-body h1 + p::first-letter,
  .markdown-body .drop-cap::first-letter {
    font-size: 2.8em;
  }

  .sidebar {
    width: 300px;
  }

  .sidebar-toggle {
    top: 1rem;
    left: 1rem;
  }

  .back-to-top {
    bottom: 1.5rem;
    right: 1.5rem;
  }

  .breadcrumb {
    display: none;
  }

  .floating-action-bar {
    bottom: 1rem;
  }
}

@media (max-width: 480px) {
  .content {
    padding: 2.5rem 1rem 3rem;
  }

  .markdown-body h1 {
    font-size: 1.5rem;
  }

  .sidebar {
    width: 280px;
  }

  .floating-action-bar {
    gap: 0.15rem;
    padding: 0.3rem 0.5rem;
  }

  .fab-btn {
    width: 30px;
    height: 30px;
  }

  .accent-picker-panel {
    min-width: 240px;
    padding: 1rem 1.25rem;
  }

  .accent-preset {
    width: 26px;
    height: 26px;
  }
}

/* ── Print Styles ── */
@media print {
  @page {
    margin: 2cm 2.5cm;
    size: A4;
  }

  body {
    background: white !important;
    color: #1a1a18 !important;
    font-size: 11pt;
    line-height: 1.6;
  }

  body::before {
    display: none !important;
  }

  .reading-progress,
  .sidebar,
  .sidebar-toggle,
  .sidebar-overlay,
  .floating-toc,
  .lateral-toc,
  .top-right-controls,
  .chapter-nav,
  .content-empty,
  .empty-hint,
  .back-to-top,
  .search-overlay,
  .shortcuts-overlay,
  .toast,
  .section-chevron,
  .section-anchor,
  .section-copy,
  .chapter-divider,
  .lateral-toc-actions,
  .floating-action-bar,
  .breadcrumb,
  .reading-pace,
  .quote-copy-btn,
  .section-progress-line,
  .accent-picker-panel,
  .theme-picker-panel {
    display: none !important;
  }

  .content-wrapper {
    overflow: visible !important;
    height: auto !important;
  }

  .content {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .section-content {
    max-height: none !important;
    opacity: 1 !important;
    overflow: visible !important;
  }

  .markdown-body h1 {
    font-size: 22pt;
    page-break-after: avoid;
  }

  .markdown-body h2 {
    font-size: 16pt;
    page-break-after: avoid;
    margin-top: 24pt;
  }

  .markdown-body h3 {
    font-size: 13pt;
    page-break-after: avoid;
  }

  .markdown-body p {
    orphans: 3;
    widows: 3;
  }

  .markdown-body pre {
    page-break-inside: avoid;
    border: 1px solid #ccc;
  }

  .markdown-body pre code {
    background: #f5f5f5 !important;
    color: #1a1a18 !important;
  }

  .markdown-body table {
    page-break-inside: avoid;
  }

  .markdown-body blockquote {
    border-left-color: #888;
  }

  .markdown-body img {
    max-width: 80%;
    page-break-inside: avoid;
  }

  .meta-bar {
    border-bottom: 1px solid #ccc;
  }

  .markdown-body a {
    color: #1a1a18;
    border-bottom: none;
  }

  .markdown-body a::after {
    content: ' (' attr(href) ')';
    font-size: 0.7em;
    color: #666;
  }

  .markdown-body a[href^="#"]::after {
    content: '';
  }
}
