:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #22263a;
  --border: #2a2e3e;
  --text: #e4e4e7;
  --text-muted: #9ca3af;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --max-w: 1200px;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { overflow-x: hidden; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; border-radius: 2px; }

.skip-link { position: absolute; top: -100%; left: 16px; background: var(--accent); color: #fff; padding: 8px 16px; border-radius: 6px; z-index: 1001; font-size: 14px; font-weight: 600; }
.skip-link:focus { top: 12px; }

.container { max-width: var(--max-w); margin: 0 auto; padding: 0 24px; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.site-brand { font-size: 18px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; flex-shrink: 0; }
.site-brand:hover { text-decoration: none; color: var(--accent-light); }
.site-nav { display: flex; gap: 16px; align-items: center; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.site-nav a { color: var(--text-muted); font-size: 14px; font-weight: 500; white-space: nowrap; }
.site-nav a:hover { color: var(--text); text-decoration: none; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 32px 0; margin-top: 64px; color: var(--text-muted); font-size: 13px; text-align: center; }

/* Entity Page — Two-column layout with TOC sidebar */
.entity-page { padding: 32px 0; }
.entity-layout { display: grid; grid-template-columns: 1fr; gap: 48px; margin-top: 8px; }
.entity-content { min-width: 0; }

.entity-breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.entity-breadcrumb a { color: var(--text-muted); }
.entity-breadcrumb a:hover { color: var(--accent-light); }
.entity-breadcrumb .sep { opacity: 0.4; }

.entity-header { margin-bottom: 32px; }
.entity-title { font-size: 28px; font-weight: 700; line-height: 1.3; margin-bottom: 8px; overflow-wrap: break-word; word-break: break-word; }
.entity-desc { color: var(--text-muted); font-size: 15px; max-width: 700px; overflow-wrap: break-word; }

/* Meta pills */
.entity-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; color: var(--text-muted); font-weight: 500; text-decoration: none; }
a.pill:hover { border-color: var(--accent-light); color: var(--text); text-decoration: none; }
.pill-accent { border-color: var(--accent); color: var(--accent-light); }
.pill-green { border-color: var(--green); color: var(--green); }
.pill-orange { border-color: var(--orange); color: var(--orange); }
.pill-blue { border-color: var(--blue); color: var(--blue); }
.pill-reading-time { border-color: var(--border); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* TOC Sidebar */
.toc-sidebar {
  display: none;
}
.toc {
  position: sticky;
  top: 80px;
}
.toc-title { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }
.toc-list { list-style: none; }
.toc-item { margin-bottom: 4px; }
.toc-item a { display: block; padding: 4px 0; font-size: 13px; color: var(--text-muted); line-height: 1.4; border-left: 2px solid transparent; padding-left: 12px; }
.toc-item a:hover { color: var(--text); text-decoration: none; border-left-color: var(--accent-light); }
.toc-level-3 a { padding-left: 24px; }
.toc-level-4 a { padding-left: 36px; }
.toc-level-5 a { padding-left: 48px; }
.toc-level-6 a { padding-left: 60px; }

/* Markdown Body Content */
.entity-body { margin-top: 32px; }
.entity-body h2 { font-size: 22px; font-weight: 700; margin: 32px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.entity-body h3 { font-size: 18px; font-weight: 600; margin: 24px 0 10px; }
.entity-body h4 { font-size: 15px; font-weight: 600; margin: 20px 0 8px; }
.entity-body p { margin-bottom: 12px; font-size: 15px; line-height: 1.7; }
.entity-body ul, .entity-body ol { margin: 0 0 12px 20px; font-size: 15px; line-height: 1.7; }
.entity-body li { margin-bottom: 4px; }
.entity-body strong { font-weight: 600; }
.entity-body code { font-family: var(--mono); font-size: 13px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; }
.entity-body pre { background: #0d0f14; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow-x: auto; margin: 0 0 16px; line-height: 1.5; }
.entity-body pre code { background: none; border: none; padding: 0; font-size: 13px; color: #e4e4e7; white-space: pre; tab-size: 2; }
.entity-body table { width: 100%; border-collapse: collapse; margin: 0 0 16px; font-size: 14px; }
.entity-body th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); font-weight: 600; font-size: 13px; color: var(--text-muted); }
.entity-body td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.entity-body tr:hover td { background: var(--bg-card); }
.entity-body blockquote { border-left: 3px solid var(--accent); padding: 8px 16px; margin: 0 0 16px; background: var(--bg-card); border-radius: 0 var(--radius) var(--radius) 0; }
.entity-body blockquote p { margin-bottom: 0; color: var(--text-muted); }
.entity-body a { color: var(--accent-light); }
.entity-body a:hover { text-decoration: underline; }

/* Heading anchor targets — offset for sticky header */
.entity-body h2[id], .entity-body h3[id], .entity-body h4[id], .entity-body h5[id], .entity-body h6[id] {
  scroll-margin-top: 80px;
}

/* Mermaid diagrams */
.entity-body pre.mermaid { background: transparent; border: none; text-align: center; overflow: visible; padding: 16px 0; }
.entity-body pre.mermaid svg { width: 100%; height: auto; }

/* Related section */
.related-section { margin-top: 48px; padding-top: 48px; border-top: 1px solid var(--border); }

/* Cards grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: border-color 0.2s; }
.card:hover { border-color: var(--accent); text-decoration: none; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; overflow-wrap: break-word; word-break: break-word; }
.card-desc { font-size: 13px; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* Homepage */
.hero { padding: 80px 0 48px; text-align: center; }
.hero h1 { font-size: 40px; font-weight: 700; margin-bottom: 16px; letter-spacing: -0.02em; }
.hero-tagline { color: var(--text-muted); font-size: 18px; max-width: 640px; margin: 0 auto 24px; line-height: 1.6; }
.hero-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.hero-btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 500; background: var(--bg-card); border: 1px solid var(--border); color: var(--text); transition: border-color 0.2s, background 0.2s; }
.hero-btn:hover { border-color: var(--accent); background: var(--bg-hover); text-decoration: none; }
.hero-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.hero-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.hero-btn-primary:hover { background: var(--accent-light); border-color: var(--accent-light); }

.section-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.section-desc { color: var(--text-muted); font-size: 15px; margin-bottom: 20px; }
.section { margin-bottom: 48px; }

/* CTA section */
.section-cta { margin-top: 16px; }
.cta-box { text-align: center; padding: 48px 24px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
.cta-box h2 { font-size: 24px; margin-bottom: 8px; }
.cta-box p { color: var(--text-muted); font-size: 15px; margin-bottom: 20px; }

/* Hub / Taxonomy */
.hub-header { padding: 32px 0; border-bottom: 1px solid var(--border); margin-bottom: 32px; }
.hub-header h1 { font-size: 28px; font-weight: 700; }
.hub-desc { color: var(--text-muted); margin-top: 8px; font-size: 15px; max-width: 700px; }
.hub-meta { color: var(--text-muted); margin-top: 6px; font-size: 13px; }

/* Pagination */
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border); }
.pagination a, .pagination span { padding: 8px 14px; border-radius: 6px; font-size: 14px; font-weight: 500; }
.pagination a { background: var(--bg-card); border: 1px solid var(--border); color: var(--text); }
.pagination a:hover { border-color: var(--accent); text-decoration: none; }
.pagination .current { background: var(--accent); color: white; }

/* Taxonomy Index */
.tax-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tax-entry { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px; font-weight: 500; transition: border-color 0.2s; }
.tax-entry:hover { border-color: var(--accent); text-decoration: none; }
.tax-count { font-size: 12px; color: var(--text-muted); background: var(--bg); padding: 2px 8px; border-radius: 10px; flex-shrink: 0; }

/* Letter Navigation */
.letter-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 24px; }
.letter-link { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-size: 14px; font-weight: 600; }
.letter-link:hover { border-color: var(--accent); text-decoration: none; }
.letter-active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Search toggle */
.search-toggle { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 5px 10px; font-size: 14px; }
.search-toggle:hover { border-color: var(--accent); color: var(--text); }
.search-toggle svg { width: 16px; height: 16px; }
.search-kbd { font-size: 11px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; font-family: inherit; }

/* Search overlay */
.search-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: flex; align-items: flex-start; justify-content: center; padding-top: 15vh; }
.search-overlay[hidden] { display: none; }
.search-modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 640px; max-height: 70vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.search-input-wrap { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.search-icon { width: 20px; height: 20px; flex-shrink: 0; color: var(--text-muted); }
.search-input { flex: 1; background: none; border: none; color: var(--text); font-size: 16px; font-family: inherit; outline: none; }
.search-input::placeholder { color: var(--text-muted); }
.search-esc { font-size: 11px; background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 1px 6px; color: var(--text-muted); }
.search-results { overflow-y: auto; flex: 1; }
.search-result { display: block; padding: 10px 16px; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.search-result:hover, .search-result.active { background: var(--bg); }
.search-result-title { font-weight: 600; font-size: 14px; }
.search-result-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-meta { display: flex; gap: 6px; margin-top: 4px; }
.search-result-meta .pill { font-size: 11px; padding: 1px 6px; }
.search-no-results { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 14px; }
.search-footer { display: flex; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }
.search-footer kbd { font-size: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; }

/* Desktop — show TOC sidebar */
@media (min-width: 1024px) {
  .entity-layout { grid-template-columns: 1fr 220px; }
  .toc-sidebar { display: block; }
}

/* Responsive */
@media (max-width: 768px) {
  .container { padding: 0 16px; }
  .site-header { padding: 12px 0; }
  .site-brand { font-size: 16px; }
  .site-nav { gap: 12px; }
  .site-nav a { font-size: 13px; }
  .hero { padding: 40px 0 32px; }
  .hero h1 { font-size: 26px; }
  .hero-tagline { font-size: 15px; }
  .entity-page { padding: 20px 0; }
  .entity-title { font-size: 20px; }
  .entity-body h2 { font-size: 18px; }
  .entity-body h3 { font-size: 16px; }
  .card-grid { grid-template-columns: 1fr; }
  .tax-grid { grid-template-columns: 1fr; }
  .hub-header h1 { font-size: 22px; }
  .search-kbd { display: none; }
  .search-overlay { padding-top: 0; align-items: stretch; }
  .search-modal { max-width: 100%; max-height: 100vh; border-radius: 0; }
  .search-footer { display: none; }
}
