/* ==========================================================================
   AiReadCodeBooks - Self-Contained Interactive Multi-column Web Reader Stylesheet
   Theme: Obsidian Cyber Dark (Default) & Clean Light Adaptive
   Zero External CDN Lock · 100% Standalone
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Outfit:wght@500;600;700;800&display=swap');

:root {
  /* Color Palette - Obsidian Dark */
  --bg-primary: #080a10;
  --bg-secondary: #0e121c;
  --bg-tertiary: #141926;
  --surface-card: rgba(20, 26, 40, 0.72);
  --surface-card-hover: rgba(28, 36, 56, 0.85);
  --surface-elevated: rgba(30, 41, 59, 0.6);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(99, 102, 241, 0.35);
  --border-glow: rgba(59, 130, 246, 0.5);

  /* Brand Accents & Gradients */
  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-purple: #8b5cf6;
  --accent-indigo: #6366f1;
  --accent-pink: #ec4899;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;

  --gradient-brand: linear-gradient(135deg, #38bdf8 0%, #6366f1 50%, #a855f7 100%);
  --gradient-card-border: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.02) 100%);
  --gradient-glow: radial-gradient(circle, rgba(99, 102, 241, 0.22) 0%, rgba(8, 10, 16, 0) 70%);

  /* Text Colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-highlight: #e2e8f0;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --font-heading: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, Menlo, Monaco, monospace;

  /* Layout */
  --max-width: 1360px;
  --nav-height: 64px;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  /* Code Pane Specific */
  --code-bg: #0b0f19;
  --code-highlight-bg: rgba(6, 182, 212, 0.14);
  --code-highlight-border: #00e5ff;
  --code-line-text: #cbd5e1;
  --code-ln-text: #475569;
}

html[data-theme='light'] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --surface-card: #ffffff;
  --surface-card-hover: #f8fafc;
  --surface-elevated: #ffffff;
  --border-subtle: #e2e8f0;
  --border-hover: rgba(99, 102, 241, 0.4);
  --border-glow: rgba(59, 130, 246, 0.3);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-highlight: #0284c7;

  --code-bg: #f8fafc;
  --code-highlight-bg: rgba(6, 182, 212, 0.16);
  --code-highlight-border: #0284c7;
  --code-line-text: #1e293b;
  --code-ln-text: #94a3b8;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.22);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.4);
}

/* Header & Navbar */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--nav-height);
  background: rgba(8, 10, 16, 0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
}
html[data-theme='light'] .site-header {
  background: rgba(255, 255, 255, 0.92);
}

.header-container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.logo-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.logo-text {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.4px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-version {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
  list-style: none;
}

.nav-link {
  font-size: 13.5px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}
.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12.5px;
}
.btn-primary {
  background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.3);
}
.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--surface-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.btn-secondary:hover {
  border-color: var(--border-hover);
  background: var(--surface-card-hover);
}

.theme-toggle-btn {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.theme-toggle-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.icon-sun, .icon-moon {
  width: 17px;
  height: 17px;
}
html[data-theme='light'] .icon-sun { display: none; }
html[data-theme='light'] .icon-moon { display: block; }
html[data-theme='dark'] .icon-sun { display: block; }
html[data-theme='dark'] .icon-moon { display: none; }

/* Language Dropdown */
.lang-dropdown {
  position: relative;
  display: inline-block;
  user-select: none;
}

.lang-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  user-select: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.lang-dropdown-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.chevron-icon {
  transition: transform 0.2s ease;
}

.lang-dropdown.open .chevron-icon {
  transform: rotate(180deg);
}

.lang-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 175px;
  max-height: 400px;
  overflow-y: auto;
  background: #111520;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  z-index: 10001;
  flex-direction: column;
  gap: 2px;
}

.lang-dropdown-menu::-webkit-scrollbar {
  width: 5px;
}
.lang-dropdown-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}
html[data-theme='light'] .lang-dropdown-menu::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
}

html[data-theme='light'] .lang-dropdown-btn {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
}

html[data-theme='light'] .lang-dropdown-btn:hover {
  background: #f8fafc;
  border-color: #0284c7;
  color: #0284c7;
}

html[data-theme='light'] .lang-dropdown-menu {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.06);
}

.lang-dropdown.open .lang-dropdown-menu,
.lang-dropdown:hover .lang-dropdown-menu {
  display: flex;
}

.lang-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: 6px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.lang-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.lang-dropdown-item.active {
  color: #00e5ff;
  font-weight: 600;
  background: rgba(0, 229, 255, 0.1);
}

html[data-theme='light'] .lang-dropdown-item {
  color: #1e293b;
}

html[data-theme='light'] .lang-dropdown-item:hover {
  background: #f1f5f9;
  color: #0284c7;
}

html[data-theme='light'] .lang-dropdown-item.active {
  color: #0284c7;
  font-weight: 600;
  background: rgba(2, 132, 199, 0.08);
}

/* ==========================================================================
   Interactive Web Reader Layout
   ========================================================================== */
.reader-container {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 500px;
  min-height: calc(100vh - var(--nav-height));
  background: var(--bg-primary);
  border-top: 1px solid var(--border-subtle);
}

/* Left Sidebar (TOC) */
.reader-sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  padding: 24px 16px;
  height: calc(100vh - var(--nav-height));
  position: sticky;
  top: var(--nav-height);
  overflow-y: auto;
}

.reader-book-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}

.reader-book-badge {
  font-size: 11px;
  color: var(--accent-cyan);
  font-weight: 700;
  margin-bottom: 4px;
  display: block;
}

.reader-book-title {
  font-family: var(--font-heading);
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
}

.reader-toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
  padding: 0;
}

.toc-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.18s ease;
  line-height: 1.4;
  border-left: 3px solid transparent;
}

.toc-link:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.toc-link.active {
  background: rgba(6, 182, 212, 0.12);
  color: #38bdf8;
  font-weight: 600;
  border-left-color: var(--accent-cyan);
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.toc-link.active .toc-num {
  color: #38bdf8;
}

/* Center Article Content */
.reader-main {
  padding: 40px 48px 96px;
  max-width: 820px;
  margin-inline: auto;
  overflow-y: visible;
  width: 100%;
}

.book-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.book-breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}
.book-breadcrumb a:hover {
  color: var(--accent-cyan);
}

.reader-chapter-section {
  display: none;
}
.reader-chapter-section.active-chapter {
  display: block;
  animation: chapterFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.chapter-header {
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.chapter-badge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 8px;
  display: inline-block;
  letter-spacing: 0.5px;
}

.reader-chapter-title {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.3;
  margin-bottom: 14px;
}

.reader-chapter-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-wrap: wrap;
}

/* Typography Inside Chapter */
.chapter-body h2 {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  margin-top: 36px;
  margin-bottom: 14px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.chapter-body h2::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 18px;
  background: var(--accent-cyan);
  border-radius: 2px;
}

.chapter-body h3 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 26px;
  margin-bottom: 10px;
  color: var(--text-highlight);
}

.chapter-body h4 {
  font-size: 14.5px;
  font-weight: 600;
  margin-top: 18px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.chapter-body p {
  margin-bottom: 16px;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.75;
}

.chapter-body code:not([class*="language-"]) {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 2px 6px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 4px;
  color: #38bdf8;
}

/* FACT Pill */
.fact-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.35);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: #38bdf8;
  cursor: pointer;
  margin: 4px 2px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}
.fact-pill:hover {
  background: rgba(6, 182, 212, 0.22);
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.35);
  transform: translateY(-1px);
}
.fact-pill.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
  box-shadow: 0 0 16px rgba(14, 165, 233, 0.5);
}
.fact-pill code {
  color: inherit !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}

/* Inference Box */
.inference-box {
  margin: 22px 0;
  padding: 16px 20px;
  background: rgba(99, 102, 241, 0.08);
  border-left: 4px solid var(--accent-indigo);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  border-top: 1px solid rgba(99, 102, 241, 0.15);
  border-right: 1px solid rgba(99, 102, 241, 0.15);
  border-bottom: 1px solid rgba(99, 102, 241, 0.15);
}
.inference-tag {
  font-size: 11.5px;
  font-weight: 700;
  color: #a5b4fc;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 6px;
}
.inference-box p {
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 0;
}

/* Quote & Details */
.reader-quote {
  margin: 20px 0;
  padding: 14px 18px;
  background: var(--surface-card);
  border-left: 3px solid var(--accent-cyan);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.reader-details {
  margin: 18px 0;
  padding: 12px 16px;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.reader-summary {
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-highlight);
}

/* Tables */
.table-container {
  overflow-x: auto;
  margin: 24px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.reader-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}
.reader-table th {
  background: var(--bg-secondary);
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
}
.reader-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.reader-table tr:last-child td {
  border-bottom: none;
}
.reader-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Code Blocks in Markdown */
.code-block-wrapper {
  margin: 20px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  overflow: hidden;
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.code-copy-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}
.source-code-block {
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: #cbd5e1;
}

/* Light Mode Overrides for Chapter Content & Code */
html[data-theme='light'] .chapter-body code:not([class*="language-"]) {
  background: rgba(2, 132, 199, 0.08);
  border: 1px solid rgba(2, 132, 199, 0.22);
  color: #0369a1;
  font-weight: 500;
}

html[data-theme='light'] .code-block-wrapper {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

html[data-theme='light'] .code-block-header {
  background: #f1f5f9;
  border-bottom: 1px solid #cbd5e1;
  color: #475569;
}

html[data-theme='light'] .code-copy-btn {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #475569;
}

html[data-theme='light'] .code-copy-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

html[data-theme='light'] .source-code-block {
  color: #0f172a !important;
}

html[data-theme='light'] .fact-pill {
  background: rgba(2, 132, 199, 0.08);
  border-color: rgba(2, 132, 199, 0.35);
  color: #0284c7;
}

html[data-theme='light'] .fact-pill:hover {
  background: rgba(2, 132, 199, 0.16);
  border-color: #0284c7;
  color: #0369a1;
}

html[data-theme='light'] .fact-pill.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #0284c7;
}

html[data-theme='light'] .inference-box {
  background: rgba(99, 102, 241, 0.05);
  border-color: rgba(99, 102, 241, 0.25);
}

html[data-theme='light'] .inference-tag {
  color: #4338ca;
}

html[data-theme='light'] .reader-table th {
  background: #f1f5f9;
  color: #0f172a;
  border-bottom: 1px solid #cbd5e1;
}

html[data-theme='light'] .reader-table td {
  color: #334155;
  border-bottom: 1px solid #e2e8f0;
}

html[data-theme='light'] .reader-table tr:hover td {
  background: #f8fafc;
}

html[data-theme='light'] .code-pane-header {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

html[data-theme='light'] .btn-code-action {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #475569;
}

html[data-theme='light'] .btn-code-action:hover {
  background: #f1f5f9;
  border-color: #0284c7;
  color: #0284c7;
}

html[data-theme='light'] .badge-lines {
  background: rgba(2, 132, 199, 0.1);
  color: #0284c7;
  border-color: rgba(2, 132, 199, 0.3);
}

html[data-theme='light'] .code-line:hover {
  background: rgba(0, 0, 0, 0.03);
}

html[data-theme='light'] .code-pane-footer {
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

/* Chapter Navigation Buttons at Bottom */
.chapter-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border-subtle);
}

/* ==========================================================================
   Right Column: Real In-Situ Source Code Inspector
   ========================================================================== */
.reader-code-pane {
  background: var(--code-bg);
  border-left: 1px solid var(--border-subtle);
  height: calc(100vh - var(--nav-height));
  position: sticky;
  top: var(--nav-height);
  display: flex;
  flex-direction: column;
}

.code-pane-header {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.code-pane-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.code-pane-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-lines {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(6, 182, 212, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(6, 182, 212, 0.3);
  flex-shrink: 0;
}

.code-pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-code-action {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-code-action:hover {
  background: var(--surface-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}
.btn-code-action.copied {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: #10b981;
}

.code-pane-body {
  flex: 1;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}

.code-line {
  display: flex;
  padding: 0 12px;
  min-height: 20px;
}
.code-line:hover {
  background: rgba(255, 255, 255, 0.03);
}

.code-line.highlight {
  background: var(--code-highlight-bg);
  border-left: 3px solid var(--code-highlight-border);
}

.line-no {
  width: 44px;
  color: var(--code-ln-text);
  user-select: none;
  text-align: right;
  padding-right: 14px;
  flex-shrink: 0;
}

.code-text {
  color: var(--code-line-text);
  white-space: pre;
  tab-size: 2;
}

.code-loading-msg {
  padding: 30px 20px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-family: var(--font-mono);
  text-align: center;
}

.flash-highlight {
  animation: flashBg 0.35s ease-out;
}
@keyframes flashBg {
  0% { background: rgba(6, 182, 212, 0.25); }
  100% { background: transparent; }
}

.code-pane-footer {
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.code-pane-status {
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
}

.code-pane-filepath {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

/* Bookshelf Gallery (for root index.html) */
.bookshelf-hero {
  padding: 60px 24px 30px;
  text-align: center;
}
.bookshelf-title {
  font-family: var(--font-heading);
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 12px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.bookshelf-desc {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 680px;
  margin: 0 auto;
}
.bookshelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
  max-width: var(--max-width);
  margin: 40px auto 80px;
  padding: 0 24px;
}
.book-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  display: flex;
  flex-direction: column;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  color: inherit;
}
.book-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}
.book-card-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(6, 182, 212, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(6, 182, 212, 0.25);
  display: inline-block;
  margin-bottom: 10px;
  align-self: flex-start;
}
.book-card-title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.35;
}
.book-card-repo {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.book-card-desc {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
  flex: 1;
}
.book-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}
.book-card-tags span {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}
.book-card-btn {
  font-size: 13px;
  font-weight: 600;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Conversion CTAs */
.btn-nav-cta {
  background: linear-gradient(135deg, #00e5ff 0%, #3b82f6 100%) !important;
  color: #080a10 !important;
  font-weight: 700 !important;
  border: none !important;
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.35) !important;
  white-space: nowrap;
  transition: all 0.2s ease !important;
}
.btn-nav-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.55) !important;
}

.reader-chapter-cta {
  margin: 48px 0 32px;
  padding: 24px 28px;
  background: linear-gradient(135deg, rgba(14, 21, 37, 0.95) 0%, rgba(20, 26, 40, 0.9) 100%);
  border: 1px solid rgba(0, 229, 255, 0.3);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}
.reader-chapter-cta::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(180deg, #00e5ff 0%, #3b82f6 100%);
}
.cta-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.cta-title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 8px;
  line-height: 1.35;
}
.cta-desc {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
  max-width: 680px;
}
.cta-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.cta-btn {
  background: linear-gradient(135deg, #00e5ff 0%, #3b82f6 100%) !important;
  color: #080a10 !important;
  font-weight: 700 !important;
  border: none !important;
  padding: 8px 18px !important;
  border-radius: 6px !important;
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.4);
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.cta-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 28px rgba(0, 229, 255, 0.6);
}
.cta-subtext {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

html[data-theme='light'] .reader-chapter-cta {
  background: linear-gradient(135deg, #f0f9ff 0%, #f8fafc 100%);
  border-color: rgba(2, 132, 199, 0.35);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}
html[data-theme='light'] .cta-title {
  color: #0f172a;
}
html[data-theme='light'] .cta-desc {
  color: #475569;
}
html[data-theme='light'] .cta-btn {
  color: #ffffff !important;
}

.code-pane-cta-link {
  font-size: 11px;
  color: var(--accent-cyan);
  text-decoration: none;
  font-family: var(--font-mono);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.2s;
}
.code-pane-cta-link:hover {
  text-decoration: underline;
  color: #38bdf8;
}

/* Responsive Breakpoints */
@media (max-width: 1280px) {
  .reader-container {
    grid-template-columns: 240px 1fr 420px;
  }
}

@media (max-width: 1024px) {
  .reader-container {
    grid-template-columns: 220px 1fr;
  }
  .reader-code-pane {
    display: none;
  }
}

@media (max-width: 768px) {
  .reader-container {
    grid-template-columns: 1fr;
  }
  .reader-sidebar {
    display: none;
  }
  .reader-main {
    padding: 24px 20px 64px;
  }
}

/* ==========================================================================
   Mermaid Architecture & Flowchart Diagrams Component
   ========================================================================== */
.mermaid-block-wrapper {
  margin: 26px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28);
  transition: border-color 0.22s ease, box-shadow 0.22s ease;
}

.mermaid-block-wrapper:hover {
  border-color: rgba(6, 182, 212, 0.4);
  box-shadow: 0 8px 30px rgba(6, 182, 212, 0.14);
}

.mermaid-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
  user-select: none;
}

.mermaid-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #38bdf8;
  font-family: var(--font-sans);
  letter-spacing: 0.3px;
}

.mermaid-badge svg {
  color: #38bdf8;
  flex-shrink: 0;
}

.mermaid-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mermaid-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: var(--font-sans);
}

.mermaid-action-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.mermaid-action-btn.active {
  background: rgba(6, 182, 212, 0.18);
  border-color: var(--accent-cyan);
  color: #38bdf8;
}

.mermaid-chart-container {
  padding: 28px 20px;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 140px;
  background: rgba(10, 14, 22, 0.55);
  cursor: zoom-in;
  transition: background-color 0.2s ease;
}

.mermaid-chart-container svg {
  max-width: 100%;
  height: auto;
  display: block;
}

.mermaid-source-container {
  border-top: 1px dashed var(--border-subtle);
  background: var(--code-bg);
  display: none;
}

.mermaid-source-container pre {
  margin: 0;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--code-line-text);
  overflow-x: auto;
}

.mermaid-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 36px 20px;
}

.mermaid-fallback {
  padding: 20px;
  background: rgba(245, 158, 11, 0.08);
  border-left: 3px solid var(--accent-amber);
  color: #fbbf24;
  font-size: 13px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Light Mode Overrides for Mermaid */
html[data-theme='light'] .mermaid-block-wrapper {
  background: #ffffff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.07);
}

html[data-theme='light'] .mermaid-block-header {
  background: #f8fafc;
}

html[data-theme='light'] .mermaid-badge {
  color: #0284c7;
}

html[data-theme='light'] .mermaid-action-btn {
  background: #ffffff;
}

html[data-theme='light'] .mermaid-action-btn:hover {
  background: #f1f5f9;
}

html[data-theme='light'] .mermaid-chart-container {
  background: #fcfcfd;
}

/* Mermaid Lightbox Modal */
.mermaid-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 13, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.mermaid-modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.mermaid-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 95vw;
  max-width: 1280px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  animation: modalScaleUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleUp {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.mermaid-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.02);
}

.mermaid-modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.mermaid-modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mermaid-modal-body {
  padding: 32px 24px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  background: rgba(8, 10, 16, 0.6);
}

.mermaid-modal-body svg {
  max-width: 100%;
  max-height: 75vh;
  height: auto;
}

.mermaid-modal-close-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s;
}

.mermaid-modal-close-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.08);
}

