/* ===== DESIGN TOKENS ===== */
:root {
  /* Colors */
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --primary-light: #e8f0fe;
  --primary-dark: #0d47a1;
  --accent: #34a853;
  --accent-light: #e6f4ea;
  --warning: #fbbc04;
  --warning-light: #fef7e0;
  --danger: #ea4335;
  --danger-light: #fce8e6;
  --info: #4285f4;
  --info-light: #e8f0fe;

  /* Surfaces */
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f1f3f4;
  --surface: #ffffff;
  --surface-hover: #f8f9fa;

  /* Text */
  --text: #1f2937;
  --text-secondary: #5f6368;
  --text-tertiary: #9aa0a6;
  --text-inverse: #ffffff;
  --link: #1a73e8;
  --link-visited: #7b1fa2;

  /* Sidebar */
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: #334155;
  --sidebar-active: rgba(26,115,232,0.2);
  --sidebar-width: 280px;

  /* Borders */
  --border: #dadce0;
  --border-light: #e8eaed;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 6px 10px rgba(0,0,0,0.06);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.12);

  /* Typography */
  --font-sans: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-size-xs: .75rem;
  --font-size-sm: .8125rem;
  --font-size-base: .9375rem;
  --font-size-lg: 1.0625rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;
  --line-height: 1.75;
  --line-height-heading: 1.3;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;

  /* Layout */
  --container-max: 820px;
  --header-height: 56px;
  --toc-width: 220px;
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --surface: #1e293b;
  --surface-hover: #334155;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --border: #334155;
  --border-light: #475569;
  --primary-light: rgba(26,115,232,0.15);
  --accent-light: rgba(52,168,83,0.15);
  --warning-light: rgba(251,188,4,0.15);
  --danger-light: rgba(234,67,53,0.15);
  --info-light: rgba(66,133,244,0.15);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.4), 0 6px 10px rgba(0,0,0,0.3);
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: var(--line-height);
  font-size: var(--font-size-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
a { color: var(--link); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; height: auto; display: block; }
::selection { background: var(--primary-light); color: var(--primary); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4, h5, h6 {
  line-height: var(--line-height-heading);
  color: var(--text);
  font-weight: 700;
}
h1 { font-size: var(--font-size-4xl); letter-spacing: -.02em; margin-bottom: var(--space-4); }
h2 { font-size: var(--font-size-3xl); letter-spacing: -.01em; margin-top: var(--space-12); margin-bottom: var(--space-4); padding-bottom: var(--space-3); border-bottom: 2px solid var(--primary); }
h3 { font-size: var(--font-size-2xl); margin-top: var(--space-10); margin-bottom: var(--space-3); }
h4 { font-size: var(--font-size-xl); margin-top: var(--space-8); margin-bottom: var(--space-2); color: var(--text-secondary); }
h5 { font-size: var(--font-size-lg); margin-top: var(--space-6); margin-bottom: var(--space-2); font-weight: 600; }
p { margin-bottom: var(--space-4); }
ul, ol { margin-bottom: var(--space-4); padding-left: var(--space-6); }
li { margin-bottom: var(--space-1); }
li > ul, li > ol { margin-bottom: 0; margin-top: var(--space-1); }
strong { font-weight: 600; color: var(--text); }
small { font-size: var(--font-size-sm); color: var(--text-secondary); }

/* ===== LAYOUT ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition-base);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-header h1 {
  font-size: var(--font-size-lg);
  color: #fff;
  font-weight: 700;
  margin: 0;
  border: none;
  padding: 0;
}
.sidebar-header h1 a {
  color: inherit;
  text-decoration: none;
}
.sidebar-header h1 a:hover { color: #bfdbfe; }
.sidebar-header .subtitle {
  font-size: var(--font-size-xs);
  color: var(--sidebar-text);
  margin-top: var(--space-1);
  opacity: .7;
}
.sidebar-search {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-search input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.3);
  color: #e2e8f0;
  font-size: var(--font-size-sm);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition-fast);
}
.sidebar-search input:focus { border-color: var(--primary); }
.sidebar-search input::placeholder { color: var(--text-tertiary); }
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}
.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  text-align: center;
  flex-shrink: 0;
}
.sidebar-overlay {
  display: none;
}

/* Nav items */
.nav-item { margin: 0; }
.nav-divider {
  padding: var(--space-4) var(--space-4) var(--space-2);
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.nav-chapter {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--sidebar-text);
  transition: all var(--transition-fast);
  user-select: none;
  border-left: 3px solid transparent;
}
.nav-chapter:hover { background: var(--sidebar-hover); color: #fff; }
.nav-chapter.active { border-left-color: var(--primary); background: rgba(26,115,232,0.1); color: #fff; }
.nav-chapter .ch-num {
  font-size: 10px;
  background: var(--primary);
  color: #fff;
  border-radius: 3px;
  padding: 0 5px;
  height: 18px;
  line-height: 18px;
  flex-shrink: 0;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}
.nav-chapter .ch-arrow {
  font-size: 10px;
  color: var(--text-tertiary);
  transition: transform var(--transition-fast);
  margin-left: auto;
  flex-shrink: 0;
}
.nav-chapter .ch-arrow.open { transform: rotate(90deg); }
.nav-sections { display: none; }
.nav-sections.open { display: block; }
.nav-section {
  display: block;
  padding: var(--space-1) var(--space-4) var(--space-1) 52px;
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  line-height: 1.6;
  position: relative;
}
.nav-section::before {
  content: '';
  position: absolute;
  left: 36px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255,255,255,0.06);
}
.nav-section:hover { color: #e2e8f0; background: var(--sidebar-hover); }
.nav-section.active { color: var(--primary); background: rgba(26,115,232,0.08); }
.nav-section.highlight { color: #fff; background: rgba(26,115,232,0.15); }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ===== TOP HEADER ===== */
.top-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
}
[data-theme="dark"] .top-header { background: rgba(15,23,42,0.92); }
.top-header-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-8);
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.top-header .mobile-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.top-header .mobile-toggle:hover { background: var(--bg-secondary); }
.breadcrumb {
  flex: 1;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .current { color: var(--text); font-weight: 500; }
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--bg-secondary); border-color: var(--primary); }

/* ===== CONTENT AREA ===== */
.content-area {
  display: flex;
  flex: 1;
  position: relative;
}
.content-body {
  flex: 1;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-10) var(--space-8) var(--space-16);
  min-width: 0;
}

/* ===== RIGHT TOC ===== */
.right-toc {
  width: var(--toc-width);
  min-width: var(--toc-width);
  position: sticky;
  top: var(--header-height);
  align-self: flex-start;
  max-height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: var(--space-6) var(--space-4) var(--space-6) 0;
  display: none;
}
.right-toc.show { display: block; }
.right-toc-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}
.right-toc-item {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-2);
  border-left: 2px solid var(--border);
  margin-bottom: var(--space-1);
  transition: all var(--transition-fast);
  text-decoration: none;
  line-height: 1.4;
}
.right-toc-item:hover { color: var(--primary); border-left-color: var(--primary); }
.right-toc-item.active { color: var(--primary); border-left-color: var(--primary); font-weight: 500; }
.right-toc-item.h3 { padding-left: var(--space-4); }
.right-toc-item.h4 { padding-left: var(--space-7); font-size: 11px; }

/* ===== CHAPTER HEADER ===== */
.chapter-header {
  margin-bottom: var(--space-8);
}
.chapter-header .ch-tag {
  display: inline-block;
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  padding: 2px 10px;
  border-radius: 4px;
  margin-bottom: var(--space-2);
  letter-spacing: .02em;
}
.chapter-header h1 {
  font-size: var(--font-size-4xl);
  font-weight: 800;
  margin: 0 0 var(--space-3);
  border: none;
  padding: 0;
  line-height: 1.2;
}
.chapter-header .ch-desc {
  font-size: var(--font-size-lg);
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== CONTENT ELEMENTS ===== */
.content-body h2 .anchor,
.content-body h3 .anchor,
.content-body h4 .anchor {
  margin-left: var(--space-2);
  opacity: 0;
  transition: opacity var(--transition-fast);
  color: var(--text-tertiary);
  font-size: .8em;
}
.content-body h2:hover .anchor,
.content-body h3:hover .anchor,
.content-body h4:hover .anchor { opacity: 1; }

/* Code */
code {
  font-family: var(--font-mono);
  font-size: .85em;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--primary);
  word-break: break-word;
}
pre {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: #1e293b;
  color: #e2e8f0;
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-md);
  overflow-x: auto;
  line-height: 1.7;
  margin-bottom: var(--space-5);
  position: relative;
}
[data-theme="dark"] pre { background: #0f172a; border: 1px solid var(--border); }
pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.copy-btn {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  background: rgba(255,255,255,0.1);
  border: none;
  color: #94a3b8;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}
.copy-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* Blockquotes */
blockquote {
  border-left: 3px solid var(--primary);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-5);
  background: var(--primary-light);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text);
}
blockquote p:last-child { margin-bottom: 0; }

/* Table */
.table-wrap {
  overflow-x: auto;
  margin-bottom: var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}
table th, table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}
table th {
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-secondary);
  white-space: nowrap;
}
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--surface-hover); }

/* Lists */
.content-body ul, .content-body ol { margin-bottom: var(--space-5); }
.content-body li { margin-bottom: var(--space-2); }

/* Images */
.content-body img {
  border-radius: var(--radius-md);
  margin: var(--space-6) 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* Horizontal rule */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-10) 0;
}

/* ===== CALLOUTS ===== */
.callout {
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-5);
  border-radius: var(--radius-md);
  border-left: 4px solid;
  font-size: var(--font-size-sm);
}
.callout-tip { background: var(--accent-light); border-color: var(--accent); }
.callout-info { background: var(--info-light); border-color: var(--info); }
.callout-warning { background: var(--warning-light); border-color: var(--warning); }
.callout-danger { background: var(--danger-light); border-color: var(--danger); }
.callout-title {
  font-weight: 600;
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-1);
}
.callout-tip .callout-title { color: var(--accent); }
.callout-info .callout-title { color: var(--info); }
.callout-warning .callout-title { color: #b45309; }
.callout-danger .callout-title { color: var(--danger); }

/* ===== KPI CARDS ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
  transition: all var(--transition-fast);
}
.kpi-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }
.kpi-card .kpi-value {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: var(--space-1);
}
.kpi-card .kpi-label {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ===== GLOSSARY TERMS ===== */
.glossary-term {
  color: var(--primary);
  border-bottom: 1px dashed var(--primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}
.glossary-term:hover {
  background: var(--primary-light);
  border-bottom-color: var(--primary);
}

/* Tooltip */
.glossary-tooltip {
  position: fixed;
  max-width: 380px;
  background: var(--sidebar-bg);
  color: #e2e8f0;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  z-index: 1000;
  box-shadow: var(--shadow-xl);
  display: none;
  pointer-events: none;
}
.glossary-tooltip.show { display: block; }
.glossary-tooltip .term { font-weight: 600; color: #fff; display: block; margin-bottom: var(--space-1); }
.glossary-tooltip .def { color: #cbd5e1; }
.glossary-tooltip .goto {
  display: block;
  margin-top: var(--space-2);
  color: var(--text-tertiary);
  font-size: var(--font-size-xs);
}

/* ===== MOBILE CHAPTER TOC ===== */
.mobile-toc-toggle,
.mobile-toc-sheet,
.mobile-toc-overlay {
  display: none;
}

/* ===== NAVIGATION BUTTONS ===== */
.nav-buttons {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-10);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border);
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  max-width: 45%;
}
.nav-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.nav-btn .dir { font-size: var(--font-size-xs); color: var(--text-secondary); display: block; }
.nav-btn .title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-btn.next { text-align: right; }
.nav-btn.prev { text-align: left; }

/* ===== SEARCH (index page) ===== */
.hero {
  text-align: center;
  padding: var(--space-16) var(--space-8) var(--space-10);
  background: linear-gradient(180deg, var(--primary-light) 0%, var(--bg) 100%);
}
[data-theme="dark"] .hero { background: linear-gradient(180deg, rgba(26,115,232,0.08) 0%, var(--bg) 100%); }
.hero h1 { font-size: 2.75rem; font-weight: 800; margin-bottom: var(--space-3); border: none; padding: 0; }
.hero p { font-size: var(--font-size-lg); color: var(--text-secondary); max-width: 600px; margin: 0 auto var(--space-6); }
.hero-search {
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}
.hero-search input {
  width: 100%;
  padding: var(--space-3) var(--space-4) var(--space-3) 44px;
  border-radius: 50px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: var(--font-size-base);
  font-family: var(--font-sans);
  outline: none;
  transition: all var(--transition-fast);
  color: var(--text);
}
.hero-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }
.hero-search .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 1.1rem;
}
.search-results {
  max-width: 700px;
  margin: var(--space-6) auto 0;
  display: none;
}
.search-results.show { display: block; }
.search-result-group { margin-bottom: var(--space-6); }
.search-result-group .group-title {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-tertiary);
  font-weight: 600;
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--border-light);
}
.search-result-item {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: background var(--transition-fast);
  text-decoration: none;
}
.search-result-item:hover { background: var(--surface-hover); }
.search-result-item .sr-title { font-weight: 500; }
.search-result-item .sr-desc { font-size: var(--font-size-sm); color: var(--text-secondary); }

/* Chapter grid on index */
.chapter-grid {
  max-width: 900px;
  margin: var(--space-10) auto;
  padding: 0 var(--space-8);
}
.chapter-grid h2 { text-align: center; border: none; margin-bottom: var(--space-6); }
.ch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}
.ch-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  transition: all var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.ch-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  color: var(--text);
}
.ch-card .ch-num {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: var(--space-2);
}
.ch-card .ch-title {
  font-weight: 600;
  font-size: var(--font-size-base);
  margin-bottom: var(--space-2);
  flex: 1;
}
.ch-card .ch-desc {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}
.ch-card .ch-count {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-3);
}


/* ===== MOBILE IMPROVEMENTS ===== */
@media (max-width: 768px) {
  body { font-size: 1.0625rem; line-height: 1.8; }
  .sidebar { position: fixed; top: 0; bottom: 0; width: min(86vw, 320px); min-width: min(86vw, 320px); left: -100vw; transition: left 0.3s cubic-bezier(0.4,0,0.2,1); }
  .sidebar.open { left: 0; box-shadow: 8px 0 40px rgba(0,0,0,0.3); }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(15,23,42,.55); transition: opacity 0.3s ease; }
  .sidebar-overlay:not(.show) { opacity: 0; pointer-events: none; }
  .sidebar-overlay.show { display: block; opacity: 1; }
  .content-body { padding: var(--space-5) var(--space-4) var(--space-10); }
  .top-header-inner { padding: 0 var(--space-3); }
  .top-header .mobile-toggle { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; min-width: 40px; }
  .top-header-inner .breadcrumb { font-size: 12px; }
  .chapter-header h1 { font-size: var(--font-size-2xl); }
  .chapter-header .ch-desc { font-size: 1rem; line-height: 1.75; }
  p { margin-bottom: 18px; }
  h2 { font-size: 1.375rem; margin-top: var(--space-10); padding-bottom: var(--space-2); }
  h3 { font-size: 1.1875rem; margin-top: var(--space-8); }
  h4 { font-size: 1.125rem; margin-top: 28px; }
  h5 { font-size: 1rem; margin-top: var(--space-5); }
  .hero { padding: var(--space-6) var(--space-3) var(--space-4); }
  .hero h1 { font-size: 1.5rem; }
  .ch-grid { grid-template-columns: 1fr; }
  .ch-card { padding: var(--space-4); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
  .kpi-card { padding: var(--space-3); }
  .kpi-card .kpi-value { font-size: var(--font-size-2xl); }
  .table-wrap { margin: 0 calc(-1 * var(--space-4)) var(--space-4); border-radius: 0; border-left: none; border-right: none; overflow-x: auto; }
  .table-wrap::after { content: '\2192 \62A5\8868\53EF\6C34\5E73\6ED1\52A8'; display: block; text-align: center; font-size: 11px; color: var(--text-tertiary); padding: 4px 0; }
  table { font-size: .875rem; min-width: 560px; }
  table th, table td { padding: var(--space-3); }
  pre { padding: var(--space-4); font-size: 13px; margin: 0 calc(-1 * var(--space-4)) var(--space-4); border-radius: 0; }
  blockquote { margin-left: calc(-1 * var(--space-4)); margin-right: calc(-1 * var(--space-4)); border-radius: 0; }
  .right-toc { display: none !important; }
  .nav-buttons { flex-direction: column; gap: var(--space-2); }
  .nav-btn { max-width: 100%; justify-content: center; padding: var(--space-3); min-height: 48px; }
  .callout { margin-left: calc(-1 * var(--space-4)); margin-right: calc(-1 * var(--space-4)); border-radius: 0; }
  .ch-desc { font-size: 1rem !important; }
  .nav-section { padding: var(--space-2) var(--space-4) var(--space-2) 52px; min-height: 36px; }
  .nav-chapter { min-height: 40px; }
  code { font-size: .8em; }
  .theme-toggle { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
  .nav-btn .dir { font-size: 11px; }
  .nav-btn .title { font-size: var(--font-size-sm); }
  li { margin-bottom: 10px; }
  .sidebar-search input { min-height: 40px; font-size: 14px; }
  .copy-btn { min-width: 44px; min-height: 44px; }
  .glossary-tooltip {
    left: var(--space-4) !important;
    right: var(--space-4);
    top: auto !important;
    bottom: var(--space-4);
    max-width: none;
    padding: var(--space-4);
    pointer-events: auto;
  }
  .mobile-toc-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    position: fixed;
    right: 16px;
    bottom: 68px;
    z-index: 120;
    min-height: 44px;
    padding: 0 var(--space-4);
    border: none;
    border-radius: 22px;
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-lg);
    font-family: var(--font-sans);
    font-size: .875rem;
    font-weight: 600;
  }
  .mobile-toc-overlay {
    position: fixed;
    inset: 0;
    z-index: 180;
    background: rgba(15,23,42,.55);
  }
  .mobile-toc-overlay.show { display: block; }
  .mobile-toc-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 190;
    max-height: min(72vh, 640px);
    overflow-y: auto;
    padding: var(--space-5) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
    background: var(--surface);
    box-shadow: 0 -10px 30px rgba(0,0,0,.18);
  }
  .mobile-toc-sheet.show { display: block; }
  .mobile-toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
    font-weight: 700;
  }
  .mobile-toc-close {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 1.25rem;
  }
  .mobile-toc-item {
    display: block;
    min-height: 44px;
    padding: 10px var(--space-3);
    border-left: 3px solid var(--border);
    color: var(--text);
    font-size: .9375rem;
    line-height: 1.55;
  }
  .mobile-toc-item.h3 { padding-left: var(--space-5); color: var(--text-secondary); }
  .mobile-toc-item.h4 { padding-left: var(--space-8); color: var(--text-secondary); font-size: .875rem; }
}

/* ===== PROGRESS BAR ===== */
.reading-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 300;
  background: transparent; pointer-events: none;
}
.reading-progress-bar {
  height: 100%; background: var(--primary); width: 0%;
  transition: width 0.1s linear;
}

/* ===== BACK TO TOP ===== */
.back-to-top {
  position: fixed; bottom: 24px; right: 24px; width: 44px; height: 44px;
  border-radius: 50%; background: var(--primary); color: #fff;
  border: none; cursor: pointer; font-size: 1.2rem; line-height: 1;
  display: none; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg); z-index: 100;
  transition: all var(--transition-fast);
}
.back-to-top.show { display: flex; }
.back-to-top:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: var(--shadow-xl); }
@media (max-width: 768px) { .back-to-top { bottom: 16px; right: 16px; width: 40px; height: 40px; } }

/* ===== ACTION CARD ===== */
.action-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-5); margin: var(--space-6) 0; position: relative;
  border-left: 4px solid var(--primary);
}
.action-card-title { font-weight: 700; font-size: var(--font-size-sm); color: var(--primary); margin-bottom: var(--space-3); text-transform: uppercase; letter-spacing: .04em; }
.action-card ul { margin: 0; padding-left: var(--space-5); }
.action-card li { margin-bottom: var(--space-1); font-size: var(--font-size-sm); }

/* ===== PREMIER CONNECTION BOX ===== */
.premier-box {
  background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
  border: 1px solid var(--primary); border-radius: var(--radius-md);
  padding: var(--space-5); margin: var(--space-6) 0; position: relative; overflow: hidden;
}
.premier-box::before { content: '\2605'; position: absolute; top: -10px; right: -5px; font-size: 60px; color: var(--primary); opacity: .08; }
.premier-box-title { font-weight: 700; font-size: var(--font-size-sm); color: var(--primary); margin-bottom: var(--space-2); display: flex; align-items: center; gap: var(--space-2); }
.premier-box p { font-size: var(--font-size-sm); margin-bottom: var(--space-2); }
.premier-box p:last-child { margin-bottom: 0; }

/* ===== CHAPTER ACTIONS ===== */
.chapter-actions {
  display: flex; gap: var(--space-2); flex-wrap: wrap; margin: var(--space-6) 0 var(--space-8);
}
.chapter-actions .act-btn {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  font-size: var(--font-size-xs); font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition-fast); text-decoration: none;
}
.chapter-actions .act-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* ===== KEY TAKEAWAYS ===== */
.key-takeaways {
  background: var(--bg-secondary); border-radius: var(--radius-md); padding: var(--space-5);
  margin: var(--space-8) 0;
}
.key-takeaways h3 { font-size: var(--font-size-sm); text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); margin-top: 0; border: none; margin-bottom: var(--space-3); }
.key-takeaways ul { margin: 0; padding-left: var(--space-5); }
.key-takeaways li { margin-bottom: var(--space-1); font-size: var(--font-size-sm); }

/* ===== CHAPTER DIVIDER ===== */
.ch-divider { text-align: center; margin: var(--space-10) 0; position: relative; }
.ch-divider::before { content: ''; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--border); }
.ch-divider span { background: var(--bg); padding: 0 var(--space-4); position: relative; color: var(--text-tertiary); font-size: var(--font-size-sm); }

/* ===== CROSS REFERENCE ===== */
.xref { color: var(--primary); border-bottom: 1px dashed var(--primary); text-decoration: none; cursor: pointer; }
.xref:hover { background: var(--primary-light); }

/* Sidebar nav section - bigger text on hover for mobile */
@media (pointer: coarse) {
  .nav-chapter { min-height: 44px; padding-top: var(--space-3); padding-bottom: var(--space-3); }
  .nav-section { padding-top: var(--space-2); padding-bottom: var(--space-2); min-height: 40px; }
  .sidebar-search input { font-size: 16px; }
  .act-btn { min-height: 40px; padding: var(--space-2) var(--space-4); }
}

/* ===== READING TIME ===== */
.reading-time {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: var(--font-size-xs); color: var(--text-tertiary); margin-bottom: var(--space-4);
}
.reading-time::before { content: '\23F1'; }

/* ===== SECTION HEADER ID ===== */
.section-header { scroll-margin-top: 70px; }
.section-header .anchor-link { opacity: 0; margin-left: var(--space-2); color: var(--text-tertiary); font-size: .8em; text-decoration: none; transition: opacity var(--transition-fast); }
.section-header:hover .anchor-link { opacity: 1; }
.section-header .anchor-link:hover { color: var(--primary); }

/* ===== TIP CALLOUT ICONS ===== */
.callout-icon { font-size: 1.1em; margin-right: var(--space-1); }

/* Ch-Num badge fix */
.ch-card .ch-num { font-size: 11px; }

/* ===== PRINT ===== */
@media print {
  .sidebar, .top-header, .right-toc, .nav-buttons, .theme-toggle, .mobile-toggle, .sidebar-overlay,
  .copy-btn, .glossary-tooltip, .hero-search { display: none !important; }
  body { background: #fff; color: #000; }
  .content-body { max-width: 100%; padding: 0; }
  .main-content { display: block; }
  a { color: #000; }
  pre { background: #f5f5f5; color: #000; border: 1px solid #ddd; }
  blockquote { border-left-color: #333; }
  h2 { border-bottom-color: #333; }
}
