:root {
  --bg: #ffffff; --bg-side: #f6f8fa; --fg: #1f2328; --muted: #656d76;
  --border: #d0d7de; --hover: #eaeef2; --active: #ddf4ff; --active-fg: #0969da;
  --topbar-h: 48px;
}
:root[data-theme="dark"] {
  --bg: #0d1117; --bg-side: #161b22; --fg: #e6edf3; --muted: #8d96a0;
  --border: #30363d; --hover: #1f2630; --active: #1f3048; --active-fg: #58a6ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", Roboto, sans-serif; }

.topbar { position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); display: flex; align-items: center;
  gap: 10px; padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--bg-side); z-index: 20; }
.brand { font-weight: 600; color: var(--fg); text-decoration: none; white-space: nowrap; }
.crumbs { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.spacer { flex: 1; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--fg); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.icon-btn:hover { background: var(--hover); }

.layout { display: flex; padding-top: var(--topbar-h); height: 100%; }
.sidebar { width: 290px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--bg-side);
  overflow-y: auto; height: calc(100vh - var(--topbar-h)); position: sticky; top: var(--topbar-h); }
body.side-collapsed .sidebar { display: none; }
.content { flex: 1; min-width: 0; overflow-y: auto; height: calc(100vh - var(--topbar-h)); }
.markdown-body { max-width: 980px; margin: 0 auto; padding: 32px 40px 80px; background: transparent; }
.toc { width: 240px; flex-shrink: 0; border-left: 1px solid var(--border); overflow-y: auto;
  height: calc(100vh - var(--topbar-h)); padding: 16px 12px; font-size: 13px; }
body.toc-hidden .toc { display: none; }
.toc a { display: block; color: var(--muted); text-decoration: none; padding: 3px 0; line-height: 1.35; }
.toc a:hover, .toc a.current { color: var(--active-fg); }
.toc .d3 { padding-left: 12px; } .toc .d4 { padding-left: 24px; }
.toc-title { font-weight: 600; margin-bottom: 8px; color: var(--fg); }

.search-box { padding: 10px; position: sticky; top: 0; background: var(--bg-side); border-bottom: 1px solid var(--border); }
.search-box input { width: 100%; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font-size: 14px; }

.tree { padding: 6px 0 24px; font-size: 14px; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree li > ul { padding-left: 14px; }
.tree .row { display: flex; align-items: center; gap: 6px; padding: 4px 10px; cursor: pointer;
  color: var(--fg); text-decoration: none; border-radius: 4px; margin: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree .row:hover { background: var(--hover); }
.tree .row.active { background: var(--active); color: var(--active-fg); font-weight: 600; }
.tree .caret { width: 12px; display: inline-block; color: var(--muted); transition: transform .12s; flex-shrink: 0; }
.tree li.collapsed > .row .caret { transform: rotate(-90deg); }
.tree li.collapsed > ul { display: none; }
.tree .ico { flex-shrink: 0; }
.tree .hidden { display: none; }

.search-results { padding: 8px 10px; font-size: 13px; border-bottom: 1px solid var(--border); }
.search-results .res { display: block; padding: 6px; border-radius: 4px; color: var(--fg); text-decoration: none; }
.search-results .res:hover { background: var(--hover); }
.search-results .res b { color: var(--active-fg); font-weight: 600; }
.search-results .hit { color: var(--muted); padding-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results mark { background: #fff8c5; color: inherit; }
:root[data-theme="dark"] .search-results mark { background: #5a4a00; }

.muted { color: var(--muted); }
.markdown-body .anchor { float: left; margin-left: -20px; padding-right: 4px; opacity: 0; text-decoration: none; color: var(--muted); }
.markdown-body h1:hover .anchor, .markdown-body h2:hover .anchor, .markdown-body h3:hover .anchor,
.markdown-body h4:hover .anchor { opacity: 1; }
.markdown-body pre.mermaid { background: transparent; text-align: center; }
.markdown-body table { display: block; width: max-content; max-width: 100%; overflow-x: auto; }
.markdown-body { color: var(--fg); }
.markdown-body table.frontmatter { font-size: 12px; color: var(--muted); margin-bottom: 20px; }
.markdown-body table.frontmatter th { text-align: left; white-space: nowrap; font-weight: 600; }

/* HTML documents: full-size iframe, no TOC */
body.html-mode .content { overflow: hidden; }
body.html-mode .markdown-body { max-width: none; height: 100%; padding: 0; }
body.html-mode .toc { display: none !important; }
body.html-mode #toc-btn { display: none; }
iframe.html-doc { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

@media (max-width: 1200px) { .toc { display: none; } body.toc-open .toc { display: block; position: fixed; right: 0;
  top: var(--topbar-h); background: var(--bg-side); z-index: 15; box-shadow: -4px 0 12px rgba(0,0,0,.15); } }
@media (max-width: 800px) {
  .sidebar { position: fixed; left: 0; top: var(--topbar-h); z-index: 15; box-shadow: 4px 0 12px rgba(0,0,0,.15); width: 85vw; max-width: 320px; }
  body:not(.side-open) .sidebar { display: none; }
  .markdown-body { padding: 20px 16px 60px; }
  .crumbs { display: none; }
}
