/* ========== THEME VARIABLES ========== */
:root, [data-theme="dark"] {
  --bg-deep: #0a0a0f;
  --bg-primary: #101018;
  --bg-surface: #16161f;
  --bg-elevated: #1c1c28;
  --bg-hover: #222233;
  --border-subtle: rgba(255,255,255,0.06);
  --border-medium: rgba(255,255,255,0.1);
  --border-accent: rgba(232,167,65,0.3);
  --text-primary: #e8e6e3;
  --text-secondary: rgba(232,230,227,0.7);
  --text-muted: rgba(232,230,227,0.4);
  --accent-gold: #e8a741;
  --accent-gold-dim: rgba(232,167,65,0.15);
  --accent-amber: #d4943a;
  --accent-blue: #5b8def;
  --accent-blue-dim: rgba(91,141,239,0.12);
  --accent-green: #4ec9b0;
  --accent-green-dim: rgba(78,201,176,0.12);
  --accent-red: #f07178;
  --accent-red-dim: rgba(240,113,120,0.12);
  --accent-purple: #c792ea;
  --accent-purple-dim: rgba(199,146,234,0.12);
  --accent-cyan: #89ddff;
  --sidebar-bg: var(--bg-primary);
  --code-bg: var(--bg-deep);
}

[data-theme="light"] {
  --bg-deep: #f4f4f6;
  --bg-primary: #ffffff;
  --bg-surface: #f7f7f9;
  --bg-elevated: #ebebef;
  --bg-hover: #e2e2e8;
  --border-subtle: rgba(0,0,0,0.09);
  --border-medium: rgba(0,0,0,0.16);
  --border-accent: rgba(160,100,20,0.3);
  --text-primary: #111122;
  --text-secondary: #3d3d54;
  --text-muted: #6e6e82;
  --accent-gold: #a87316;
  --accent-gold-dim: rgba(168,115,22,0.12);
  --accent-amber: #946210;
  --accent-blue: #2c5cc0;
  --accent-blue-dim: rgba(44,92,192,0.1);
  --accent-green: #137a60;
  --accent-green-dim: rgba(19,122,96,0.1);
  --accent-red: #c0303e;
  --accent-red-dim: rgba(192,48,62,0.1);
  --accent-purple: #7040a8;
  --accent-purple-dim: rgba(112,64,168,0.1);
  --accent-cyan: #186888;
  --sidebar-bg: #f9f9fb;
  --code-bg: #eeeef2;
}

/* ========== FONT ========== */
:root {
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 150ms cubic-bezier(0.4,0,0.2,1);
  --transition-smooth: 300ms cubic-bezier(0.4,0,0.2,1);
  --sidebar-w: 260px;
  --toc-w: 220px;
  --header-h: 50px;
}

/* ========== RESET ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.75;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}
a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-gold-dim); color: var(--accent-gold); }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.25); border-radius: 3px; }

/* ========== HEADER BAR ========== */
.header-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--header-h);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.header-logo {
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 600;
  color: var(--accent-gold);
  text-decoration: none !important;
  white-space: nowrap;
}
.header-logo:hover { text-decoration: none !important; }
.header-logo .dim { color: var(--text-muted); }
.header-spacer { flex: 1; }
.theme-toggle {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.theme-toggle:hover { border-color: var(--border-medium); color: var(--text-primary); }
.github-link {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 50%;
  transition: all var(--transition-fast);
  text-decoration: none !important;
}
.github-link:hover { color: var(--text-primary); transform: scale(1.15); text-decoration: none !important; }
.sidebar-toggle {
  display: none;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer; padding: 4px;
}
.sidebar-toggle svg { width: 22px; height: 22px; }

/* ========== LEFT SIDEBAR ========== */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  padding: 12px 0 24px;
  transform: translateX(0);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar.hidden {
  transform: translateX(calc(-1 * var(--sidebar-w) - 1px));
  pointer-events: none;
}
/* Header toggle button — always visible */
.sidebar-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
}
.sidebar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}
.sidebar-btn svg {
  width: 18px; height: 18px;
  transition: transform 0.3s ease;
}
.sidebar-btn.collapsed svg {
  transform: scaleX(-1);
}
/* Main content follows */
.main-content {
  transition: margin-left 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
body.sidebar-off .main-content {
  margin-left: 0 !important;
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,0.5);
}
.sidebar-group {
  padding: 0 12px;
  margin-bottom: 4px;
}
.sidebar-label {
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 12px 12px 6px;
}
/* ---- Sub-group (3rd level, collapsible) ---- */
.sidebar-sub-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
  margin-top: 2px;
}
.sidebar-sub-label:hover { color: var(--text-secondary); }
.sidebar-sub-label::before {
  content: '\25BE';
  font-size: 11px;
  transition: transform 0.25s ease;
  flex-shrink: 0;
  opacity: 0.5;
  transform: rotate(-90deg);
}
.sidebar-sub-label.open::before { transform: rotate(0deg); opacity: 0.8; }
.sidebar-sub-label.open { color: var(--text-secondary); }
.sidebar-sub-group {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding-left: 6px;
}
.sidebar-sub-group.open {
  max-height: 400px;
}
.sidebar-link.sidebar-link-l3 {
  padding: 4px 10px 4px 18px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.sidebar-link.sidebar-link-l3:hover { color: var(--text-primary); }
.sidebar-link.sidebar-link-l3.active {
  color: var(--accent-gold);
  background: var(--accent-gold-dim);
}
.sidebar-link {
  display: block;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none !important;
  transition: all var(--transition-fast);
  line-height: 1.4;
}
.sidebar-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none !important;
}
.sidebar-link.active {
  background: var(--accent-gold-dim);
  color: var(--accent-gold);
  font-weight: 500;
}
.sidebar-link .badge {
  float: right;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg-elevated);
  color: var(--text-muted);
}
.sidebar-link.active .badge {
  background: rgba(232,167,65,0.2);
  color: var(--accent-gold);
}
.sidebar-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 8px 16px;
}

/* ========== RIGHT TOC ========== */
.right-toc {
  position: fixed;
  top: calc(var(--header-h) + 16px);
  right: 14px;
  width: var(--toc-w);
  max-height: calc(100vh - var(--header-h) - 32px);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 50;
  padding: 8px 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  scroll-behavior: smooth;
  scrollbar-width: none;
  /* Default: subtle, hover: prominent */
  opacity: 0.55;
  transition: opacity 0.3s ease, box-shadow 0.3s ease;
}
.right-toc::-webkit-scrollbar { width: 0; }
.right-toc:hover {
  opacity: 1;
  box-shadow: 0 2px 16px rgba(0,0,0,0.15);
}
.right-toc-title {
  font-family: var(--font-mono);
  font-size: 9px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 2px 12px 6px;
  margin-bottom: 2px;
  opacity: 0.7;
}
.right-toc:hover .right-toc-title { opacity: 1; }
.right-toc a {
  display: block;
  padding: 2px 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  text-decoration: none !important;
  border-left: 2px solid transparent;
  transition: all var(--transition-fast);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.right-toc a:hover {
  color: var(--text-primary);
  text-decoration: none !important;
}
.right-toc a.active {
  color: var(--accent-gold);
  border-left-color: var(--accent-gold);
}
.right-toc a.toc-h3 {
  padding-left: 22px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.8;
}
/* Mobile TOC floating button */
.toc-fab {
  display: none;
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 250;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--accent-gold);
  color: var(--bg-deep);
  border: none;
  font-size: 20px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: transform var(--transition-fast);
  line-height: 48px;
  text-align: center;
}
.toc-fab:hover { transform: scale(1.1); }
/* TOC as bottom drawer on small screens */
.right-toc.as-drawer {
  position: fixed;
  top: auto; right: 0; bottom: 0; left: 0;
  width: 100%;
  max-height: 50vh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border-medium);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.3);
  z-index: 300;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.right-toc.as-drawer.open { transform: translateY(0); }
.toc-drawer-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 299;
  background: rgba(0,0,0,0.4);
}

/* ========== MAIN LAYOUT ========== */
.main-content {
  margin-left: var(--sidebar-w);
  margin-right: calc(var(--toc-w) + 40px);
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
}
.page-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 28px 100px;
}

/* ========== TYPOGRAPHY ========== */
h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 400; line-height: 1.15;
  letter-spacing: -0.5px;
  margin-bottom: 12px;
}
h1 em { color: var(--accent-gold); font-style: italic; }
h2 {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 400;
  margin: 44px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
h3 {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 400;
  margin: 28px 0 10px;
}
h4 {
  font-size: 15px; font-weight: 600;
  margin: 16px 0 6px;
  color: var(--accent-gold);
}
.subtitle {
  font-size: 16px; color: var(--text-secondary);
  max-width: 680px; margin-bottom: 28px;
}
.source-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}
.source-tag.official { background: var(--accent-gold-dim); color: var(--accent-gold); }
.source-tag.community { background: var(--accent-blue-dim); color: var(--accent-blue); }
.source-tag.interactive { background: var(--accent-green-dim); color: var(--accent-green); }

/* ========== CALLOUT ========== */
.callout {
  padding: 14px 18px;
  border-left: 3px solid var(--accent-gold);
  background: var(--accent-gold-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 15px; color: var(--text-secondary);
  margin: 18px 0; line-height: 1.7;
}
.callout strong { color: var(--accent-gold); }
.callout.blue { border-left-color: var(--accent-blue); background: var(--accent-blue-dim); }
.callout.blue strong { color: var(--accent-blue); }
.callout.green { border-left-color: var(--accent-green); background: var(--accent-green-dim); }
.callout.green strong { color: var(--accent-green); }
.callout.red { border-left-color: var(--accent-red); background: var(--accent-red-dim); }
.callout.red strong { color: var(--accent-red); }

/* ========== CODE ========== */
code, .ic {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--accent-cyan);
}
pre {
  background: var(--code-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  margin: 12px 0;
  color: var(--text-secondary);
}
pre code { background: none; border: none; padding: 0; color: inherit; }
.kw { color: var(--accent-purple); }
.fn { color: var(--accent-blue); }
.str { color: var(--accent-green); }
.cmt { color: var(--text-muted); font-style: italic; }
.num { color: var(--accent-gold); }

/* ========== TABLE ========== */
.tbl {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 14.5px;
}
.tbl th {
  text-align: left;
  padding: 9px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-medium);
  font-family: var(--font-mono);
  font-size: 11.5px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.tbl td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: top;
}
.tbl tr:hover td { background: rgba(128,128,128,0.04); }

/* ========== CARD ========== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin: 14px 0;
  transition: border-color var(--transition-fast);
}
.card:hover { border-color: var(--border-medium); }
.card-title { font-weight: 600; font-size: 16px; margin-bottom: 6px; }
.card p, .card ul { font-size: 15px; color: var(--text-secondary); }
.card ul { padding-left: 20px; margin-top: 4px; }
.card li { margin-bottom: 3px; }

/* ========== EXPANDABLE (details) ========== */
details {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin: 10px 0;
  transition: border-color var(--transition-fast);
  overflow: hidden;
}
details:hover { border-color: var(--border-medium); }
details[open] { border-color: var(--border-accent); }
summary {
  padding: 12px 18px;
  cursor: pointer;
  background: var(--bg-surface);
  font-size: 15px; font-weight: 500;
  color: var(--text-primary);
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  user-select: none;
  transition: background var(--transition-fast);
}
summary:hover { background: var(--bg-elevated); }
summary::-webkit-details-marker { display: none; }
summary::before {
  content: '\25B6'; font-size: 9px; color: var(--text-muted);
  transition: transform var(--transition-smooth);
  flex-shrink: 0;
}
details[open] > summary::before { transform: rotate(90deg); }
summary .badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 600;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--bg-elevated);
  color: var(--text-muted);
}
.details-body {
  padding: 4px 18px 18px;
  font-size: 15px; color: var(--text-secondary);
  line-height: 1.75;
}
.details-body p { margin: 6px 0; }
.details-body ul { padding-left: 20px; }
.details-body li { margin-bottom: 5px; }

/* ========== GRID ========== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 18px 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }

/* ========== DIAGRAM ========== */
.diagram {
  background: var(--code-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 14px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
  white-space: pre;
  overflow-x: auto;
}

/* ========== FLOW ========== */
.flow {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 0; margin: 14px 0; padding: 14px;
  background: var(--code-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.flow-node {
  padding: 7px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-secondary);
}
.flow-arrow { padding: 0 5px; color: var(--text-muted); font-size: 13px; }

/* ========== LAYERS ========== */
.layers { display: flex; flex-direction: column; gap: 5px; margin: 14px 0; }
.layer { display: flex; gap: 5px; }
.layer-block {
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 500;
  text-align: center; padding: 9px 10px;
  border: 1px solid transparent;
  cursor: default;
}
.layer-block.gold { background: var(--accent-gold-dim); color: var(--accent-gold); border-color: rgba(232,167,65,0.12); }
.layer-block.blue { background: var(--accent-blue-dim); color: var(--accent-blue); border-color: rgba(91,141,239,0.08); }
.layer-block.green { background: var(--accent-green-dim); color: var(--accent-green); border-color: rgba(78,201,176,0.08); }
.layer-block.purple { background: var(--accent-purple-dim); color: var(--accent-purple); border-color: rgba(199,146,234,0.08); }
.layer-block.red { background: var(--accent-red-dim); color: var(--accent-red); border-color: rgba(240,113,120,0.08); }

/* ========== TAGS ========== */
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.tag {
  padding: 3px 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ========== TOOLTIP ========== */
.tip {
  position: relative;
  border-bottom: 1px dashed var(--accent-gold);
  color: var(--accent-gold);
  cursor: help;
  font-weight: inherit;
}
.tip:hover .tip-text,
.tip:focus .tip-text { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.tip-text {
  position: absolute;
  bottom: calc(100% + 10px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px; font-weight: 400;
  color: var(--text-secondary);
  width: max-content; max-width: 320px;
  line-height: 1.55;
  opacity: 0; visibility: hidden;
  transition: all 0.2s ease;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  pointer-events: none;
}

/* ========== SEARCH BUTTON (Header) ========== */
.search-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.search-btn:hover { border-color: var(--border-medium); color: var(--text-secondary); }

/* ========== SEARCH MODAL ========== */
.search-modal {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  opacity: 0; transition: opacity 0.2s;
}
.search-modal.open { opacity: 1; }
.search-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}
.search-box {
  position: relative; z-index: 1;
  width: 560px; max-width: 92vw;
  background: var(--bg-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  overflow: hidden;
}
.search-box input {
  width: 100%;
  padding: 16px 20px;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
}
.search-box input::placeholder { color: var(--text-muted); }
.search-results {
  max-height: 360px;
  overflow-y: auto;
}
.search-result-item {
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--border-subtle);
}
.search-result-item:hover, .search-result-item.focused {
  background: var(--accent-gold-dim);
  color: var(--text-primary);
}
.sr-type {
  font-family: var(--font-mono);
  font-size: 9px; font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  flex-shrink: 0;
  text-transform: uppercase;
}
.search-empty {
  padding: 24px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.search-hint {
  padding: 8px 20px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}

/* ========== RIGHT TOC — Collapsible Tree ========== */
.right-toc .toc-h2 {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 11.5px;
  padding: 3px 12px;
  cursor: pointer;
  border-left: 2px solid transparent;
}
.right-toc .toc-h2:hover { color: var(--text-primary); }
.right-toc .toc-h2.active { color: var(--accent-gold); border-left-color: var(--accent-gold); }
.right-toc .toc-children {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}
.right-toc .toc-children.expanded {
  max-height: 1200px;
}
.right-toc .toc-h3 {
  padding-left: 24px;
  font-size: 11.5px;
}

/* ========== RESPONSIVE ========== */
/* Wide: sidebar + content + floating TOC (reserved margin) */
@media (min-width: 1400px) {
  .main-content { margin-right: calc(var(--toc-w) + 36px); }
}
@media (max-width: 1399px) {
  .main-content { margin-right: 0; }
}
/* Below 860px: hide fixed TOC, show FAB instead */
@media (max-width: 860px) {
  .right-toc:not(.as-drawer) { display: none; }
  .toc-fab { display: block; }
}
@media (max-width: 860px) {
  .sidebar-toggle { display: block; }
  .sidebar { transform: translateX(-100%); z-index: 150; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; z-index: 140; }
  .main-content { margin-left: 0; }
  .page-wrap { padding: 24px 16px 80px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  h1 { font-size: 26px; }
  h2 { font-size: 22px; }
}

/* ========== LIGHT MODE OVERRIDES ========== */
[data-theme="light"] code, [data-theme="light"] .ic {
  background: #e6e6ec;
  border-color: rgba(0,0,0,0.1);
  color: #186888;
}
[data-theme="light"] pre {
  background: #eeeef2;
  border-color: rgba(0,0,0,0.1);
  color: #3d3d54;
}
[data-theme="light"] .kw { color: #7040a8; }
[data-theme="light"] .fn { color: #2c5cc0; }
[data-theme="light"] .str { color: #137a60; }
[data-theme="light"] .cmt { color: #6e6e82; }
[data-theme="light"] .num { color: #a87316; }
[data-theme="light"] .diagram { color: #4a4a60; }
[data-theme="light"] summary { color: #111122; }
[data-theme="light"] .callout { color: #3d3d54; }
[data-theme="light"] .callout strong { color: #886010; }
[data-theme="light"] .callout.blue strong { color: #2c5cc0; }
[data-theme="light"] .callout.green strong { color: #137a60; }
[data-theme="light"] .callout.red strong { color: #c0303e; }
[data-theme="light"] .sidebar-link { color: #4a4a60; }
[data-theme="light"] .sidebar-link:hover { color: #111122; }
[data-theme="light"] .sidebar-link.active { color: #886010; }
[data-theme="light"] .sidebar-label { color: #8a8a9a; }
[data-theme="light"] .right-toc a { color: #8a8a9a; }
[data-theme="light"] .right-toc a:hover { color: #3d3d54; }
[data-theme="light"] .right-toc a.active { color: #a87316; }
[data-theme="light"] .right-toc:hover { background: #fff; border-color: rgba(0,0,0,0.08); box-shadow: 0 2px 16px rgba(0,0,0,0.06); }
[data-theme="light"] .badge, [data-theme="light"] summary .badge { background: #dddde4; color: #5a5a6e; }
[data-theme="light"] .tbl th { background: #e6e6ec; color: #5a5a6e; border-bottom-color: rgba(0,0,0,0.12); }
[data-theme="light"] .tbl td { color: #3d3d54; }
[data-theme="light"] .tag { background: #e2e2ea; color: #5a5a6e; border-color: rgba(0,0,0,0.08); }
[data-theme="light"] .search-box { box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
[data-theme="light"] .search-backdrop { background: rgba(0,0,0,0.25); }
[data-theme="light"] h2 { border-bottom-color: rgba(0,0,0,0.08); }
[data-theme="light"] h4 { color: #886010; }
[data-theme="light"] .header-bar { background: rgba(255,255,255,0.92); }
[data-theme="light"] a { color: #2c5cc0; }

/* Light mode: gold-bg buttons need white text for contrast */
[data-theme="light"] button[style*="accent-gold"],
[data-theme="light"] .sim-btn.primary,
[data-theme="light"] .toc-fab,
[data-theme="light"] .sidebar-btn.collapsed {
  color: #fff !important;
}
/* Generic: any element using accent-gold as background in light mode */
[data-theme="light"] [style*="background"][style*="gold"] {
  color: #fff;
}
/* Challenge / interactive page buttons */
[data-theme="light"] button {
  color: var(--text-primary);
}
[data-theme="light"] button[style*="gold"],
[data-theme="light"] button[style*="e8a741"],
[data-theme="light"] button[style*="a87316"] {
  color: #fff !important;
}

/* ========== PRINT ========== */
@media print {
  .header-bar, .sidebar, .right-toc { display: none; }
  .main-content { margin: 0; }
  body { background: #fff; color: #111; }
}
