:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-subtle: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, 0.09);
  --code-bg: #0f172a;
  --code-fg: #e2e8f0;
  --inline-code-bg: #f1f5f9;
  --inline-code-fg: #0f172a;
}
:root[data-theme="dark"] {
  --bg: #0d1016;
  --bg-subtle: #11151d;
  --surface: #131822;
  --surface-alt: #1b2230;
  --border: #232b3a;
  --border-strong: #334155;
  --text: #f8fafc;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.13);
  --code-bg: #080b10;
  --code-fg: #e2e8f0;
  --inline-code-bg: #1c2331;
  --inline-code-fg: #7dd3fc;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky; top: 0; z-index: 40; height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px; background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 12.5px; font-weight: 600; cursor: pointer; text-decoration: none; transition: background-color 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); color: #fff; }
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: 276px minmax(0, 1fr) 224px; max-width: 1440px; margin: 0 auto; min-height: calc(100vh - 56px); }

.sidebar {
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
  padding: 18px 14px 32px; border-right: 1px solid var(--border); background: var(--bg-subtle);
}
.search-input {
  width: 100%; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13px; margin-bottom: 14px;
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.nav-group { margin-bottom: 16px; }
.nav-section-lbl {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 4px 10px 6px;
}
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: block; padding: 7px 10px; border-radius: 7px;
  color: var(--text-2); font-size: 13.5px; font-weight: 500; line-height: 1.35;
  transition: background-color 0.1s ease, color 0.1s ease;
}
.nav-link:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.search-results { display: none; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.search-results.open { display: flex; }
.sr-item { display: flex; flex-direction: column; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); font-size: 12.5px; color: var(--text); }
.sr-item:hover { border-color: var(--accent); text-decoration: none; }
.sr-sub { font-size: 11px; color: var(--muted); }

.content { padding: 34px 48px 80px; min-width: 0; }
.article { max-width: 780px; margin: 0 auto; }
.breadcrumb {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); margin-bottom: 10px;
}
.article h1 { font-size: 32px; line-height: 1.2; margin: 0 0 18px; letter-spacing: -0.025em; }
.article h2 { font-size: 21px; margin: 38px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); scroll-margin-top: 76px; letter-spacing: -0.015em; }
.article h3 { font-size: 16.5px; margin: 26px 0 8px; scroll-margin-top: 76px; }
.article h4 { font-size: 14.5px; margin: 20px 0 6px; scroll-margin-top: 76px; }
.h-anchor { margin-left: 8px; font-weight: 400; opacity: 0; color: var(--muted); }
h1:hover .h-anchor, h2:hover .h-anchor, h3:hover .h-anchor, h4:hover .h-anchor { opacity: 1; }
.article p { margin: 0 0 15px; color: var(--text-2); }
.article ul, .article ol { margin: 0 0 16px; padding-left: 22px; color: var(--text-2); }
.article li { margin-bottom: 6px; }
.article strong { color: var(--text); }
.article hr { border: none; border-top: 1px solid var(--border); margin: 30px 0; }
.article code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.86em;
  padding: 2px 6px; border-radius: 5px; background: var(--inline-code-bg); color: var(--inline-code-fg);
}

.hero-cards {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 22px 0 28px;
}
.hero-card {
  display: flex; flex-direction: column; gap: 5px; padding: 15px 16px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--bg-subtle); color: var(--text-2);
  transition: border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}
.hero-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08); text-decoration: none; }
.hero-card-kicker { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.hero-card strong { font-size: 14.5px; color: var(--text); line-height: 1.3; }
.hero-card span:last-child { font-size: 12.5px; line-height: 1.45; color: var(--muted); }

.code-wrap { margin: 16px 0 20px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border-strong); background: var(--code-bg); }
.code-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 13px; background: rgba(255,255,255,0.04); border-bottom: 1px solid rgba(255,255,255,0.08); }
.code-lang { font-family: ui-monospace, monospace; font-size: 11px; color: #94a3b8; text-transform: uppercase; }
.copy-code-btn { border: 1px solid rgba(255,255,255,0.16); background: transparent; color: #cbd5e1; border-radius: 5px; padding: 2px 9px; font-size: 11px; cursor: pointer; }
.copy-code-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.code-wrap pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-size: 13px; line-height: 1.55; color: var(--code-fg); }
.code-wrap pre code { background: transparent; color: inherit; padding: 0; font-size: inherit; }

.mermaid-wrap { margin: 18px 0 24px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border-strong); background: var(--surface); box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06); }
.mermaid-bar { display: flex; align-items: center; justify-content: space-between; padding: 7px 14px; background: var(--bg-subtle); border-bottom: 1px solid var(--border); }
.mermaid-lang { font-family: ui-monospace, monospace; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.mermaid-wrap .copy-code-btn { border-color: var(--border-strong); color: var(--text-2); }
.mermaid-wrap .copy-code-btn:hover { background: var(--surface-alt); color: var(--text); }
.mermaid-stage { padding: 18px 14px; overflow-x: auto; display: flex; justify-content: center; align-items: center; min-height: 120px; }
.mermaid-stage svg { max-width: 100%; height: auto !important; display: block; }
.mermaid-stage pre.mermaid { margin: 0; font-size: 12px; color: var(--text-2); white-space: pre-wrap; }

/* Auto-Generated Live Annotated Documentation SVG Figures */
.doc-diagram { margin: 20px 0 26px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border-strong); background: var(--surface); box-shadow: 0 3px 14px rgba(15, 23, 42, 0.08); }
.doc-diagram-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 13px; background: var(--bg-subtle); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.doc-diagram-tag { font-family: ui-monospace, monospace; font-size: 10.5px; font-weight: 700; color: var(--accent); letter-spacing: 0.04em; }
.doc-diagram-acts { display: inline-flex; align-items: center; gap: 6px; }
.doc-diagram .copy-code-btn { border-color: var(--border-strong); color: var(--text-2); text-decoration: none; }
.doc-diagram .copy-code-btn:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.doc-diagram-stage { padding: 12px; background: var(--bg); cursor: zoom-in; display: flex; justify-content: center; }
.doc-diagram-img { display: block; width: 100%; height: auto; border-radius: 6px; }
:root[data-theme="dark"] .doc-diagram-img.diagram-light { display: none; }
:root:not([data-theme="dark"]) .doc-diagram-img.diagram-dark { display: none; }
.doc-diagram-cap { padding: 9px 14px; font-size: 12.5px; color: var(--text-2); border-top: 1px solid var(--border); background: var(--bg-subtle); }

.diagram-lightbox { margin: auto; padding: 0; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); color: var(--text); max-width: 96vw; max-height: 94vh; width: min(1280px, 96vw); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.48); overflow: hidden; }
.diagram-lightbox::backdrop { background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(3px); }
.diagram-lightbox[open] { display: flex; flex-direction: column; }
.diagram-lb-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: var(--bg-subtle); border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; }
.diagram-lb-body { flex: 1; min-height: 0; overflow: auto; padding: 14px; background: var(--bg); text-align: center; }
.diagram-lb-body img { max-width: 100%; height: auto; display: inline-block; border-radius: 6px; }

.doc-callout { margin: 18px 0; padding: 14px 18px; border-left: 3.5px solid var(--accent); border-radius: 0 10px 10px 0; background: var(--accent-soft); }
.doc-callout p:last-child, .doc-callout ul:last-child { margin-bottom: 0; }

.table-wrap { width: 100%; overflow-x: auto; margin: 16px 0 22px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 13px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-subtle); font-weight: 700; color: var(--text); white-space: nowrap; }
tr:last-child td { border-bottom: none; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 44px; padding-top: 24px; border-top: 1px solid var(--border); }
.pager-card { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-subtle); }
.pager-card:hover { border-color: var(--accent); text-decoration: none; }
.pager-card.next { text-align: right; }
.pager-lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.pager-title { font-size: 14px; font-weight: 700; color: var(--accent); }

.toc { position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; padding: 26px 16px; }
.toc-title { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.toc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; border-left: 1px solid var(--border); padding-left: 12px; }
.toc-link { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.4; padding: 2px 0; }
.toc-link.lvl-3 { padding-left: 10px; font-size: 12px; }
.toc-link:hover { color: var(--accent); text-decoration: none; }

@media (max-width: 1160px) {
  .layout { grid-template-columns: 256px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 820px) {
  .menu-btn { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; left: 0; top: 56px; bottom: 0; width: 286px; z-index: 50; box-shadow: 0 12px 32px rgba(0,0,0,0.3); }
  .sidebar.open { display: block; }
  .content { padding: 22px 18px 60px; }
  .hero-cards { grid-template-columns: 1fr; }
  .pager { grid-template-columns: 1fr; }
}
