/* ═══════════════════════════════════════════════════════════════
   CyberDocs — styles.css
   Cyber Blue Dark theme — SOC Dashboard aesthetic
   ═══════════════════════════════════════════════════════════════ */

/* ─── DESIGN TOKENS ─── */
:root {
  /* Cyber Blue palette */
  --bg-base:       #0a0e1a;
  --bg-surface:    #0d1321;
  --bg-card:       #111827;
  --bg-sidebar:    #080c17;
  --bg-code:       #090d17;
  --bg-hover:      #1a2235;
  --bg-active:     #0f1e38;
  --bg-input:      #131c30;

  --border:        rgba(0, 200, 255, 0.10);
  --border-strong: rgba(0, 200, 255, 0.22);

  --accent:        #00c8ff;
  --accent-dim:    rgba(0, 200, 255, 0.15);
  --accent-glow:   rgba(0, 200, 255, 0.35);
  --accent2:       #7b61ff;
  --accent3:       #00ffa3;

  --text-primary:  #e2e8f0;
  --text-secondary:#94a3b8;
  --text-muted:    #4a5568;
  --text-inverse:  #0a0e1a;

  /* Callout colors */
  --note-bg:       rgba(0, 200, 255, 0.07);
  --note-border:   #00c8ff;
  --note-icon:     "📌";

  --warn-bg:       rgba(255, 165, 0, 0.08);
  --warn-border:   #f59e0b;
  --warn-icon:     "⚠️";

  --tip-bg:        rgba(0, 255, 163, 0.07);
  --tip-border:    #00ffa3;
  --tip-icon:      "💡";

  --important-bg:  rgba(139, 92, 246, 0.08);
  --important-border: #8b5cf6;
  --important-icon: "🔑";

  /* Typography */
  --font-body:  'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-head:  'Sora', 'Inter', sans-serif;
  --font-code:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  --fs-xs:   0.75rem;
  --fs-sm:   0.875rem;
  --fs-base: 1rem;
  --fs-md:   1.0625rem;
  --fs-lg:   1.25rem;
  --fs-xl:   1.5rem;
  --fs-2xl:  1.875rem;
  --fs-3xl:  2.5rem;

  --line-height: 1.8;
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   16px;

  /* Layout */
  --sidebar-w:    270px;
  --right-toc-w:  230px;
  --topbar-h:     58px;
  --content-max:  820px;

  /* Transitions */
  --t-fast:   0.15s ease;
  --t-med:    0.25s ease;
  --t-slow:   0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── LIGHT THEME ── */
[data-theme="light"] {
  --bg-base:       #f0f4f8;
  --bg-surface:    #ffffff;
  --bg-card:       #ffffff;
  --bg-sidebar:    #f8fafc;
  --bg-code:       #1e293b;
  --bg-hover:      #e8f0fe;
  --bg-active:     #dbeafe;
  --bg-input:      #f1f5f9;

  --border:        rgba(0, 120, 200, 0.12);
  --border-strong: rgba(0, 120, 200, 0.25);

  --accent:        #0066cc;
  --accent-dim:    rgba(0, 102, 204, 0.10);
  --accent-glow:   rgba(0, 102, 204, 0.25);
  --accent2:       #6d28d9;
  --accent3:       #059669;

  --text-primary:  #1a202c;
  --text-secondary:#4a5568;
  --text-muted:    #9ca3af;
  --text-inverse:  #ffffff;

  --note-bg:       rgba(0, 102, 204, 0.06);
  --note-border:   #0066cc;
  --warn-bg:       rgba(245, 158, 11, 0.08);
  --warn-border:   #d97706;
  --tip-bg:        rgba(5, 150, 105, 0.06);
  --tip-border:    #059669;
  --important-bg:  rgba(109, 40, 217, 0.06);
  --important-border: #6d28d9;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  scroll-padding-top: calc(var(--topbar-h) + 24px);
}

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: var(--line-height);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-dim); color: var(--accent); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ─── PROGRESS BAR ─── */
#progress-bar {
  position: fixed; top: 0; left: 0; z-index: 9999;
  height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent3));
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ─── TOPBAR ─── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  gap: 12px;
}

#topbar-left {
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0; min-width: 0;
}

#topbar-center {
  flex: 1; max-width: 480px;
  display: flex; justify-content: center;
}

#topbar-right {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}

/* Hamburger */
#sidebar-toggle {
  background: none; border: none; cursor: pointer; padding: 6px;
  border-radius: var(--radius-sm); color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast);
}
#sidebar-toggle:hover { background: var(--bg-hover); color: var(--accent); }

.hamburger-icon {
  display: flex; flex-direction: column; gap: 4.5px;
  width: 20px;
}
.hamburger-icon span {
  display: block; height: 2px; border-radius: 1px;
  background: currentColor;
  transition: transform var(--t-med), opacity var(--t-fast);
}
body.sidebar-closed .hamburger-icon span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
body.sidebar-closed .hamburger-icon span:nth-child(2) { opacity: 0; }
body.sidebar-closed .hamburger-icon span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

/* Brand */
#brand {
  text-decoration: none; display: flex; align-items: center; gap: 8px;
  color: var(--text-primary);
}
.brand-icon { font-size: 1.3rem; filter: drop-shadow(0 0 6px var(--accent)); }
.brand-text {
  font-family: var(--font-head); font-size: 1.1rem; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.3px;
}

/* Breadcrumb */
#breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--fs-sm); color: var(--text-muted);
}
.bc-sep { color: var(--text-muted); opacity: 0.6; }
#bc-chapter {
  color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 180px;
}

/* Search bar */
#search-wrapper {
  position: relative; width: 100%;
  display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 12px;
  font-size: 14px; pointer-events: none;
}
#search-input {
  width: 100%; height: 36px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 20px; padding: 0 36px 0 36px;
  font-family: var(--font-body); font-size: var(--fs-sm);
  color: var(--text-primary); outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.search-shortcut {
  position: absolute; right: 10px;
  font-family: var(--font-code); font-size: 11px;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  color: var(--text-muted); padding: 2px 5px; border-radius: 4px;
  pointer-events: none;
}

#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius); max-height: 320px; overflow-y: auto;
  z-index: 1100; display: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#search-results.visible { display: block; }
.search-result-item {
  padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.active { background: var(--bg-hover); }
.search-result-title { font-weight: 600; font-size: var(--fs-sm); color: var(--text-primary); }
.search-result-snippet { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.search-result-highlight { color: var(--accent); font-weight: 600; }

/* Reading time */
#reading-time {
  font-size: var(--fs-xs); color: var(--text-muted);
  white-space: nowrap; padding: 4px 8px;
  background: var(--bg-input); border-radius: 12px;
  border: 1px solid var(--border);
}

/* Theme toggle */
#theme-toggle {
  background: none; border: 1px solid var(--border); cursor: pointer;
  padding: 6px 10px; border-radius: var(--radius-sm); font-size: 16px;
  color: var(--text-secondary);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
#theme-toggle:hover { background: var(--bg-hover); border-color: var(--accent); transform: rotate(20deg); }

/* Export dropdown */
#export-wrapper { position: relative; }
#export-btn {
  background: var(--accent-dim); border: 1px solid var(--border-strong);
  color: var(--accent); cursor: pointer; padding: 6px 12px;
  border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 500;
  transition: background var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
}
#export-btn:hover { background: var(--accent-glow); box-shadow: 0 0 12px var(--accent-glow); }
#export-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius); min-width: 190px; z-index: 1100;
  overflow: hidden;
  transform: translateY(-8px) scale(0.96);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-med), transform var(--t-med);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#export-menu.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }
#export-menu button {
  width: 100%; background: none; border: none; cursor: pointer;
  padding: 10px 16px; text-align: left;
  font-size: var(--fs-sm); color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast);
  display: flex; align-items: center; gap: 8px;
}
#export-menu button:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── LAYOUT ─── */
#layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

/* ─── SIDEBAR ─── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  transition: width var(--t-slow), transform var(--t-slow);
  z-index: 100;
}
body.sidebar-closed #sidebar { width: 0; overflow: hidden; }

#sidebar-inner {
  width: var(--sidebar-w);
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column;
  padding-bottom: 40px;
}

#sidebar-header {
  padding: 14px 16px 10px;
  font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Phase groups */
#chapter-nav { padding: 8px 0; }

.phase-group { margin-bottom: 2px; }

.phase-header {
  width: 100%; background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  font-size: var(--fs-sm); font-weight: 600;
  color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast);
  border-radius: 0;
}
.phase-header:hover { background: var(--bg-hover); color: var(--text-primary); }
.phase-header.active-phase { color: var(--accent); }

.phase-icon { font-size: 14px; flex-shrink: 0; }

.phase-chevron {
  margin-left: auto; font-size: 11px;
  transition: transform var(--t-med);
  color: var(--text-muted);
}
.phase-group.collapsed .phase-chevron { transform: rotate(-90deg); }

.phase-items {
  list-style: none;
  overflow: hidden;
  max-height: 1000px;
  transition: max-height var(--t-slow), opacity var(--t-med);
  opacity: 1;
}
.phase-group.collapsed .phase-items { max-height: 0; opacity: 0; }

.chapter-link {
  display: block; padding: 7px 16px 7px 38px;
  font-size: var(--fs-sm); color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chapter-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.chapter-link.active {
  background: var(--bg-active);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* Sidebar TOC */
#toc-wrapper {
  border-top: 1px solid var(--border);
  margin-top: 8px; padding-top: 4px;
  flex-shrink: 0;
}
#toc-header {
  padding: 10px 16px 6px;
  font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted);
}
#toc { padding: 0 0 12px; }
.toc-link {
  display: block; padding: 5px 16px 5px 20px;
  font-size: var(--fs-xs); color: var(--text-muted);
  text-decoration: none; border-left: 2px solid transparent;
  transition: color var(--t-fast), border-color var(--t-fast), padding-left var(--t-fast);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toc-link:hover { color: var(--text-secondary); }
.toc-link.active { color: var(--accent); border-left-color: var(--accent); }
.toc-link[data-level="2"] { padding-left: 20px; }
.toc-link[data-level="3"] { padding-left: 32px; font-size: 11px; }

/* ─── MAIN CONTENT ─── */
#main {
  flex: 1; min-width: 0;
  padding: 40px clamp(16px, 5vw, 48px) 80px;
  max-width: calc(var(--content-max) + 96px);
}

/* ─── CHAPTER COVER ─── */
#chapter-cover {
  text-align: center; padding: 48px 24px 56px;
  animation: fadeInUp 0.5s ease forwards;
}
#cover-badge {
  display: inline-block; margin-bottom: 16px;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--accent);
  border: 1px solid var(--accent-dim); border-radius: 20px;
  padding: 4px 14px; background: var(--accent-dim);
}
#cover-badge::before { content: "⚡ CYBERDOCS GUIDE"; }
#cover-title {
  font-family: var(--font-head); font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800; line-height: 1.2;
  background: linear-gradient(135deg, var(--text-primary) 40%, var(--accent));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; margin-bottom: 16px;
}
#cover-subtitle {
  font-size: var(--fs-md); color: var(--text-secondary); margin-bottom: 28px;
}
#cover-meta {
  display: flex; justify-content: center; gap: 20px; flex-wrap: wrap;
  margin-bottom: 40px;
}
#cover-meta span {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 16px;
  font-size: var(--fs-sm); color: var(--text-secondary);
}
#cover-phases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 16px; max-width: 700px; margin: 0 auto;
}
.cover-phase-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 12px;
  cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color var(--t-med), transform var(--t-med), box-shadow var(--t-med);
}
.cover-phase-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--accent-dim);
}
.cover-phase-card span { font-size: 1.8rem; }
.cover-phase-card strong { font-size: var(--fs-sm); color: var(--text-primary); }
.cover-phase-card small { font-size: var(--fs-xs); color: var(--text-muted); }

/* ─── ARTICLE TYPOGRAPHY ─── */
#content-area {
  max-width: var(--content-max);
  animation: fadeInUp 0.4s ease forwards;
}
#content-area.loading { opacity: 0; }

#content-area img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 16px 0;
}

#content-area h1 {
  font-family: var(--font-head); font-size: var(--fs-3xl); font-weight: 800;
  color: var(--text-primary); margin: 0 0 16px;
  line-height: 1.2; letter-spacing: -0.5px;
}
#content-area h2 {
  font-family: var(--font-head); font-size: var(--fs-xl); font-weight: 700;
  color: var(--text-primary);
  margin: 48px 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
#content-area h2::before {
  content: ""; width: 4px; height: 22px; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  flex-shrink: 0;
}
#content-area h3 {
  font-family: var(--font-head); font-size: var(--fs-lg); font-weight: 600;
  color: var(--text-primary); margin: 32px 0 12px;
}
#content-area h4 {
  font-size: var(--fs-base); font-weight: 600;
  color: var(--text-secondary); margin: 24px 0 8px;
}
#content-area h5, #content-area h6 {
  font-size: var(--fs-sm); font-weight: 600;
  color: var(--text-muted); margin: 16px 0 8px;
}

#content-area p {
  font-size: var(--fs-md); color: var(--text-secondary);
  margin-bottom: 20px; line-height: var(--line-height);
}

#content-area a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid var(--accent-dim);
  transition: border-color var(--t-fast), color var(--t-fast);
}
#content-area a:hover { border-color: var(--accent); color: var(--accent); }

#content-area ul, #content-area ol {
  margin: 0 0 20px 24px; color: var(--text-secondary);
}
#content-area li { margin-bottom: 6px; font-size: var(--fs-md); }

#content-area hr {
  border: none; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
  margin: 40px 0;
}

/* ─── CODE BLOCKS ─── */
#content-area pre {
  position: relative;
  background: var(--bg-code) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 20px 0;
  overflow: hidden;
}
#content-area pre code {
  display: block; padding: 18px 18px 18px 18px;
  font-family: var(--font-code); font-size: 0.875rem;
  line-height: 1.65; overflow-x: auto;
  background: none !important;
}

.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}
.code-lang {
  font-family: var(--font-code); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--accent); opacity: 0.8;
}
.copy-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  padding: 3px 10px; border-radius: 4px;
  font-size: 11px; font-family: var(--font-body);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  display: flex; align-items: center; gap: 4px;
}
.copy-btn:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--accent3); border-color: var(--accent3); }

/* Inline code */
#content-area :not(pre) > code {
  font-family: var(--font-code); font-size: 0.85em;
  background: var(--bg-code); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px;
  color: var(--accent); white-space: nowrap;
}

/* ─── TABLES ─── */
#content-area table {
  width: 100%; border-collapse: collapse;
  margin: 24px 0; font-size: var(--fs-sm);
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
}
#content-area th {
  background: var(--bg-card);
  color: var(--accent); font-weight: 600;
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--border-strong);
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.6px;
}
#content-area td {
  padding: 10px 14px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
#content-area tr:last-child td { border-bottom: none; }
#content-area tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
#content-area tr:hover td { background: var(--bg-hover); }
[data-theme="light"] #content-area tr:nth-child(even) td { background: rgba(0,0,0,0.02); }

/* ─── BLOCKQUOTES / CALLOUTS ─── */
#content-area blockquote {
  margin: 20px 0;
  padding: 14px 18px 14px 20px;
  border-left: 4px solid var(--border-strong);
  background: var(--bg-card);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}

/* Callout detection via first-line bold text */
.callout {
  margin: 20px 0; padding: 16px 18px;
  border-radius: var(--radius); border-left: 4px solid;
  position: relative;
}
.callout-note    { background: var(--note-bg);      border-color: var(--note-border); }
.callout-warning { background: var(--warn-bg);      border-color: var(--warn-border); }
.callout-tip     { background: var(--tip-bg);       border-color: var(--tip-border); }
.callout-important { background: var(--important-bg); border-color: var(--important-border); }

.callout-title {
  font-weight: 700; font-size: var(--fs-sm); margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.callout-note .callout-title      { color: var(--note-border); }
.callout-warning .callout-title   { color: var(--warn-border); }
.callout-tip .callout-title       { color: var(--tip-border); }
.callout-important .callout-title { color: var(--important-border); }

.callout p { margin-bottom: 0; font-size: var(--fs-sm); }

/* ─── MERMAID ─── */
.mermaid {
  background: var(--bg-card) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  margin: 20px 0; text-align: center;
  overflow-x: auto;
}
.mermaid svg { max-width: 100%; height: auto; }

/* ─── CHAPTER HEADER SECTION ─── */
.chapter-header-block {
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(0,200,255,0.06) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 28px 24px;
  margin-bottom: 36px;
}
.chapter-header-block .ch-phase-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-dim); border: 1px solid var(--accent);
  color: var(--accent); border-radius: 20px;
  padding: 3px 12px; font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px;
}
.chapter-header-block h1 {
  font-size: clamp(1.6rem, 3vw, 2.2rem) !important;
  margin-bottom: 10px !important;
}
.chapter-meta-chips {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px;
}
.meta-chip {
  font-size: var(--fs-xs); padding: 4px 10px;
  background: var(--bg-base); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text-muted);
}

/* ─── FOOTER NAV ─── */
#chapter-nav-footer {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 56px; padding-top: 24px;
  border-top: 1px solid var(--border);
  max-width: var(--content-max);
}
.nav-foot-btn {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  cursor: pointer; color: var(--text-primary); flex: 1;
  transition: border-color var(--t-med), box-shadow var(--t-med), transform var(--t-fast);
  text-align: left;
}
.nav-foot-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px var(--accent-dim);
  transform: translateY(-2px);
}
#next-btn { justify-content: flex-end; text-align: right; }
.nav-arrow { font-size: 1.3rem; color: var(--accent); flex-shrink: 0; }
.nav-foot-text { display: flex; flex-direction: column; }
.nav-foot-text small { font-size: var(--fs-xs); color: var(--text-muted); }
.nav-foot-text strong { font-size: var(--fs-sm); color: var(--text-primary); }

/* ─── RIGHT TOC ─── */
#right-toc {
  width: var(--right-toc-w); flex-shrink: 0;
  display: none;
}
@media (min-width: 1280px) { #right-toc { display: block; } }

/* Mobile right TOC drawer */
#right-toc-toggle {
  display: none; position: fixed; bottom: 90px; right: 20px; z-index: 850;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; cursor: pointer; width: 48px; height: 48px; border-radius: 50%;
  color: white; font-size: 18px;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: transform var(--t-med), box-shadow var(--t-med);
}
#right-toc-toggle:hover { transform: scale(1.1); box-shadow: 0 6px 24px var(--accent-glow); }

@media (max-width: 1279px) {
  #right-toc-toggle { display: flex; align-items: center; justify-content: center; }
  #right-toc {
    position: fixed; right: 0; top: var(--topbar-h);
    width: 300px; height: calc(100vh - var(--topbar-h));
    background: var(--bg-sidebar); border-left: 1px solid var(--border);
    transform: translateX(100%); transition: transform var(--t-slow);
    z-index: 850; overflow-y: auto;
  }
  #right-toc.open { transform: translateX(0); }
}

@media (max-width: 560px) {
  #right-toc { width: 100%; }
}

#right-toc-inner {
  position: sticky; top: calc(var(--topbar-h) + 24px);
  padding: 8px 0 0 20px;
}
#right-toc-header {
  font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted); margin-bottom: 10px;
}
.right-toc-link {
  display: block; padding: 4px 0 4px 12px;
  font-size: 12px; color: var(--text-muted);
  text-decoration: none; border-left: 2px solid transparent;
  transition: color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.right-toc-link:hover { color: var(--text-secondary); }
.right-toc-link.active { color: var(--accent); border-left-color: var(--accent); }
.right-toc-link[data-level="3"] { padding-left: 22px; font-size: 11px; }

/* ─── FAB ─── */
#fab-container {
  position: fixed; bottom: 28px; right: 28px; z-index: 900;
  display: flex; flex-direction: column-reverse; align-items: center; gap: 8px;
}
#fab-main {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; cursor: pointer;
  font-size: 20px;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: transform var(--t-med), box-shadow var(--t-med);
  display: flex; align-items: center; justify-content: center;
}
#fab-main:hover { transform: scale(1.1); box-shadow: 0 6px 28px var(--accent-glow); }
#fab-main.open { transform: rotate(45deg); }

#fab-menu {
  display: flex; flex-direction: column; gap: 6px;
  opacity: 0; pointer-events: none;
  transform: translateY(10px) scale(0.95);
  transition: opacity var(--t-med), transform var(--t-med);
}
#fab-menu.open { opacity: 1; pointer-events: all; transform: translateY(0) scale(1); }

#fab-menu button {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  color: var(--text-secondary); cursor: pointer;
  padding: 7px 14px; border-radius: 20px;
  font-size: var(--fs-sm); white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#fab-menu button:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--accent); }

/* ─── MOBILE OVERLAY ─── */
#sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity var(--t-med);
}
#sidebar-overlay.active { opacity: 1; }

/* ─── TOAST ─── */
#toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--bg-card); border: 1px solid var(--border-strong);
  color: var(--text-primary); padding: 10px 20px;
  border-radius: 20px; font-size: var(--fs-sm);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-med), transform var(--t-med);
  z-index: 9999; white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── SEARCH MODAL ─── */
#search-modal {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
  align-items: flex-start; justify-content: center;
  padding-top: 80px;
}
#search-modal.open { display: flex; animation: fadeIn 0.15s ease forwards; }

#search-modal-inner {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); width: min(640px, 94vw);
  overflow: hidden; box-shadow: 0 24px 64px rgba(0,0,0,0.7);
}

#search-modal-input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
#search-modal-input-wrap span { color: var(--text-muted); }
#search-modal-input {
  flex: 1; background: none; border: none; outline: none;
  font-family: var(--font-body); font-size: var(--fs-md);
  color: var(--text-primary);
}
#search-modal-close {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; padding: 4px 8px;
  border-radius: 4px; font-size: 14px;
  transition: background var(--t-fast), color var(--t-fast);
}
#search-modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

#search-modal-results { max-height: 400px; overflow-y: auto; }

.search-modal-item {
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
  display: flex; gap: 12px; align-items: flex-start;
}
.search-modal-item:hover, .search-modal-item.selected { background: var(--bg-hover); }
.search-modal-item:last-child { border-bottom: none; }

.smi-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 2px; }
.smi-body { flex: 1; min-width: 0; }
.smi-title { font-weight: 600; font-size: var(--fs-sm); color: var(--text-primary); }
.smi-snippet {
  font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#search-modal-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  display: flex; gap: 14px;
  font-size: 11px; color: var(--text-muted);
  align-items: center;
}
#search-modal-footer kbd {
  background: var(--bg-base); border: 1px solid var(--border);
  border-radius: 3px; padding: 2px 5px;
  font-family: var(--font-code); font-size: 10px;
}

/* ─── ANIMATIONS ─── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Section reveal */
.section-reveal {
  opacity: 0; transform: translateY(12px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.section-reveal.visible { opacity: 1; transform: translateY(0); }

/* ─── SECTION ANCHOR ─── */
.heading-anchor {
  opacity: 0; margin-left: 8px; font-size: 0.75em;
  color: var(--accent); text-decoration: none;
  transition: opacity var(--t-fast);
}
h2:hover .heading-anchor, h3:hover .heading-anchor { opacity: 1; }

/* ─── COLLAPSIBLE SECTIONS ─── */
.collapsible-section { margin: 20px 0; }
.collapsible-toggle {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; color: var(--text-primary); font-weight: 500;
  font-family: var(--font-body); font-size: var(--fs-sm);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.collapsible-toggle:hover { background: var(--bg-hover); border-color: var(--accent); }
.collapsible-arrow { transition: transform var(--t-med); }
.collapsible-toggle.open .collapsible-arrow { transform: rotate(180deg); }
.collapsible-body {
  overflow: hidden; max-height: 0;
  transition: max-height var(--t-slow);
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}
.collapsible-body.open { max-height: 2000px; }
.collapsible-body-inner { padding: 16px; }

/* ─── PRINT STYLES ─── */
@media print {
  #topbar, #sidebar, #right-toc, #fab-container, #progress-bar,
  #chapter-nav-footer, #search-modal, #toast, #sidebar-overlay {
    display: none !important;
  }
  #layout { margin-top: 0; }
  #main { padding: 0; max-width: 100%; }
  #content-area { max-width: 100%; }
  body { background: #fff; color: #111; }
  .mermaid { break-inside: avoid; }
  pre { break-inside: avoid; white-space: pre-wrap; }
  h2, h3 { break-after: avoid; }
  @page { margin: 20mm; }
}

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }

  #sidebar {
    position: fixed; top: var(--topbar-h); left: 0;
    height: calc(100vh - var(--topbar-h));
    transform: translateX(0);
    z-index: 200;
  }
  body.sidebar-closed #sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w);
  }
  #sidebar-overlay { display: block; }
  body.sidebar-open #sidebar-overlay { display: block; }

  #main { padding: 20px 14px 80px; }

  .brand-text { display: none; }
  #bc-chapter { max-width: 120px; }
  .search-shortcut { display: none; }
  #reading-time { display: none; }

  #content-area img { margin: 12px 0; }
  #content-area > * { word-break: break-word; }
}

@media (max-width: 560px) {
  #export-btn span { display: none; }
  #export-btn::after { content: "⬇"; }
  #cover-phases-grid { grid-template-columns: repeat(2, 1fr); }
  #chapter-nav-footer { flex-direction: column; }
  #topbar-right { gap: 6px; }
  .search-shortcut { display: none !important; }
  #reading-time { font-size: 11px; padding: 3px 6px; }
}

/* ─── SKELETON LOADER ─── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── FULL-SCREEN IMAGE/CHART VIEWER ─── */
#fullscreen-viewer {
  display: none; position: fixed; inset: 0; z-index: 9998;
  background: rgba(0, 0, 0, 0.95); backdrop-filter: blur(8px);
  align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; padding: 20px;
}
#fullscreen-viewer.open { display: flex; animation: fadeIn 0.2s ease; }

#fullscreen-viewer-controls {
  position: absolute; top: 16px; right: 16px; z-index: 9999;
  display: flex; gap: 8px; align-items: center;
}

#fullscreen-viewer-controls button,
#fullscreen-viewer-controls span {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  color: var(--text-primary); cursor: pointer; padding: 8px 12px;
  border-radius: var(--radius-sm); font-size: 14px;
  transition: background var(--t-fast), border-color var(--t-fast);
}
#fullscreen-viewer-controls button:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }
#fullscreen-viewer-controls span { cursor: default; color: var(--text-muted); padding: 8px 12px; }

#fullscreen-viewer-content {
  max-width: 90vw; max-height: 80vh;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
}
#fullscreen-viewer-content img,
#fullscreen-viewer-content svg {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
}

.image-fullscreen-btn {
  position: absolute; top: 8px; right: 8px; z-index: 100;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  color: var(--text-secondary); cursor: pointer; padding: 4px 8px;
  border-radius: 4px; font-size: 12px; opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast);
}

figure, .mermaid { position: relative; }
figure:hover .image-fullscreen-btn,
.mermaid:hover .image-fullscreen-btn { opacity: 1; }
.image-fullscreen-btn:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--accent); }

@media (max-width: 560px) {
  #fullscreen-viewer {
    padding: 16px 8px;
  }
  #fullscreen-viewer-controls {
    flex-wrap: wrap; gap: 4px; top: 8px; right: 8px;
  }
  #fullscreen-viewer-controls button,
  #fullscreen-viewer-controls span {
    padding: 6px 10px; font-size: 12px;
  }
  #fullscreen-viewer-content { max-height: 85vh; max-width: 95vw; }
}

/* ─── NO CONTENT STATE ─── */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state p { font-size: var(--fs-md); }
