:root {
  /* dark is the default theme */
  --bg: #0d1117; --fg: #e6edf3; --muted: #8b949e;
  --sidebar-bg: #161b22; --border: #30363d;
  --accent: #4493f8; --accent-soft: #1f3a5f;
  --code-bg: #1c2128; --table-border: #30363d;
}
:root[data-theme="light"] {
  --bg: #ffffff; --fg: #1f2328; --muted: #656d76;
  --sidebar-bg: #f6f8fa; --border: #d8dee4;
  --accent: #0969da; --accent-soft: #ddf4ff;
  --code-bg: #eff1f3; --table-border: #d0d7de;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.65 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: var(--fg); }
#nav-toggle { display: none; background: none; border: 1px solid var(--border);
  border-radius: 6px; color: var(--fg); font-size: 18px; padding: 2px 10px; cursor: pointer; }
#search { flex: 1; max-width: 420px; margin-left: auto;
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--fg); font-size: 14px; }
#theme-toggle { background: none; border: 1px solid var(--border);
  border-radius: 6px; color: var(--fg); font-size: 16px; line-height: 1;
  padding: 3px 9px; cursor: pointer; flex: 0 0 auto; }

.layout { display: flex; align-items: stretch; }
.sidebar {
  width: 300px; flex: 0 0 300px; border-right: 1px solid var(--border);
  background: var(--sidebar-bg); max-height: calc(100vh - 49px);
  position: sticky; top: 49px; overflow-y: auto; padding: 12px 10px 40px;
}
.sidebar-brand { display: block; font-weight: 700; margin: 4px 8px 10px; color: var(--fg); }
.tab-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 4px 12px; }
.chip { font-size: 13px; padding: 3px 10px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--bg); color: var(--fg); }
.toc { list-style: none; margin: 0; padding: 0; }
.toc ul { list-style: none; margin: 0; padding-left: 14px; }
.toc-group { margin: 10px 0; }
.toc-tab { font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); display: block; margin: 0 6px 4px; }
.toc-section { display: block; padding: 3px 6px; border-radius: 6px;
  font-size: 14px; color: var(--fg); }
.toc-section:hover { background: var(--accent-soft); text-decoration: none; }
.toc-section.current { background: var(--accent-soft); font-weight: 600; }
.toc-subs a { display: block; padding: 1px 6px; font-size: 13px; color: var(--muted); }
.toc-subs a:hover { color: var(--fg); text-decoration: none; }
.toc-sub.current { color: var(--fg); font-weight: 600; }
.toc a, .toc .toc-tab { display: block; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 100%; }
.toc-item { margin: 0; }
.toc-head { display: flex; align-items: center; gap: 2px; }
.toc-head .toc-section { flex: 1 1 auto; min-width: 0; }
.toc-caret { background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 10px; line-height: 1; padding: 5px 6px; transition: transform .12s ease; }
.toc-caret.open { transform: rotate(90deg); }
.toc-subs { display: none; }
.toc-subs.open { display: block; }
.toc-preview { position: fixed; z-index: 60; pointer-events: none;
  max-width: min(340px, calc(100vw - 32px)); padding: 8px 12px; border-radius: 8px;
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25); font-size: 13px; line-height: 1.45;
  opacity: 0; transform: translateY(3px);
  transition: opacity .1s ease, transform .1s ease; }
.toc-preview.show { opacity: 1; transform: translateY(0); }
.sidebar-foot { margin: 18px 6px 0; font-size: 12px; color: var(--muted); }

.content { flex: 1; min-width: 0; padding: 28px 32px 80px; }
@media (min-width: 1000px) { .content { max-width: 820px; margin: 0 auto; } }

.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
h1 { font-size: 26px; line-height: 1.3; margin: 4px 0 10px; font-weight: 400; }
.meta { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: 10px 14px;
  font-size: 14px; margin: 0 0 26px; }
#search-results { margin: 12px 0; }
#search-results .sr { display: block; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px; background: var(--bg); }
#search-results .sr .t { font-weight: 600; color: var(--fg); }
#search-results .sr .tab { font-size: 12px; color: var(--muted); margin-left: 8px; }
#search-results .sr .sn { font-size: 13px; color: var(--muted); display: block; margin-top: 2px; }

.doc { font-size: 15px; line-height: 1.6; overflow-wrap: break-word; }
.doc h2 { font-size: 20px; margin: 1.6em 0 .6em; padding-top: .3em;
  border-bottom: 1px solid var(--border); font-weight: 600; }
.doc h3 { font-size: 17px; margin: 1.4em 0 .5em; font-weight: 600; }
.doc h4, .doc h5, .doc h6 { font-size: 16px; margin: 1.2em 0 .3em; }
.doc h1.subtitle, .doc h2.subtitle { border-bottom: none; font-weight: 500;
  color: var(--muted); font-size: 18px; }
.doc p { margin: .8em 0; line-height: 1.6; }
.doc ul, .doc ol { padding-left: 1.6em; margin: .6em 0; }
.doc li { margin: .25em 0; }
.doc code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em; background: var(--code-bg); padding: .1em .35em; border-radius: 4px; }
.doc a { color: var(--accent) !important; }
.doc a span { color: inherit !important; }
.doc a code { color: inherit; }
.doc table { border-collapse: collapse; margin: 1em 0; max-width: 100%;
  display: block; overflow-x: auto; }
.doc td, .doc th { border: 1px solid var(--table-border); padding: 6px 10px;
  vertical-align: top; }
.doc img { max-width: 100%; height: auto; }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }
.doc details.toc { border: 1px solid var(--border); border-radius: 8px;
  margin: 1em 0; }
.doc details.toc summary { cursor: pointer; padding: 8px 14px; font-weight: 600;
  user-select: none; }
.doc details.toc ul { list-style: none; margin: 0; padding: 0 18px 12px;
  columns: 2; column-gap: 2em; }
.doc details.toc li { margin: .2em 0; font-size: 14px; }
@media (max-width: 700px) { .doc details.toc ul { columns: 1; } }

.section-list { display: grid; gap: 10px; margin-top: 6px; }
.section-card { display: flex; align-items: baseline; gap: 8px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; color: var(--fg); }
.section-card:hover { border-color: var(--accent); text-decoration: none; }
.section-card .t { flex: 1 1 auto; min-width: 0; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-card .n { flex: 0 0 auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.card-children { padding: 2px 14px 10px; font-size: 13px; color: var(--muted); }
.card-children a { display: block; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; padding: 1px 0; }

.index-link { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.index-link a { color: var(--accent); font-size: 14px; }
.pager { display: flex; justify-content: space-between; gap: 10px;
  margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--border); }
.pager a { border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px;
  color: var(--fg); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager .next { margin-left: auto; }

footer { margin-top: 48px; font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  #nav-toggle { display: block; }
  .sidebar { position: fixed; top: 49px; bottom: 0; left: 0; z-index: 20;
    transform: translateX(-100%); transition: transform .18s ease; max-height: none; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 20px 18px 60px; max-width: none; margin: 0; }
}
@media print {
  .topbar, .sidebar, .pager, .crumbs { display: none !important; }
  .content { max-width: none; padding: 0; margin: 0; }
}
