:root {
  --fg: #1a1c20; --muted: #5b6068; --line: #e4e7ec; --bg: #ffffff;
  --panel: #f7f8fa; --accent: #3f51b5; --accent-fg: #ffffff;
  --code-bg: #f4f5f7; --code-fg: #24292f; --shadow: rgba(20, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e6e9ef; --muted: #9aa3b2; --line: #2a2f3a; --bg: #12151b;
    --panel: #181c24; --accent: #8b9bff; --accent-fg: #0e1014;
    --code-bg: #1b2029; --code-fg: #d7dce4; --shadow: rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; color: var(--fg); background: var(--bg);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .9rem;
  height: 56px; padding: 0 1.1rem; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.12rem; color: var(--fg); }
.brand:hover { text-decoration: none; }
.tag { color: var(--muted); font-size: .82rem; }
.searchbox { margin-left: auto; }
.searchbox input {
  width: 220px; padding: .42rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--fg); font-size: .9rem;
}
.searchbox input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.searchbox button { padding: .42rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--accent); color: var(--accent-fg); font-size: .85rem; font-weight: 600; cursor: pointer; }

.layout { display: grid; grid-template-columns: 288px minmax(0, 1fr); max-width: 1280px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px);
  overflow-y: auto; padding: 1.1rem .8rem 3rem; border-right: 1px solid var(--line);
}
.nav { list-style: none; margin: 0; padding: 0; }
.nav li { margin: 1px 0; }
.nav a { display: block; padding: .28rem .55rem; border-radius: 7px; color: var(--fg); font-size: .92rem; }
.nav a:hover { background: var(--panel); text-decoration: none; }
.nav a.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 600; }
.nav .grp {
  margin: 1rem 0 .25rem; padding: 0 .55rem; color: var(--muted);
  font-size: .72rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
}
.nav li:nth-child(3n+1) a, .nav li.grp + li a { /* keep dense; no-op guard */ }

.content { padding: 1.6rem 2.4rem 5rem; min-width: 0; }
.doc { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2rem; }
.doc.home { grid-template-columns: 1fr; }
article { max-width: 76ch; min-width: 0; }
article h1 { font-size: 1.9rem; margin: .1em 0 .7em; line-height: 1.2; }
article h2 { font-size: 1.4rem; margin: 1.8em 0 .5em; padding-bottom: .2em; border-bottom: 1px solid var(--line); }
article h3 { font-size: 1.12rem; margin: 1.5em 0 .4em; }
article p, article li { color: var(--fg); }
article code { background: var(--code-bg); color: var(--code-fg); padding: .12em .38em; border-radius: 5px; font-size: .86em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
article pre { background: var(--code-bg); border: 1px solid var(--line); padding: .9em 1em; border-radius: 10px; overflow-x: auto; line-height: 1.5; }
article pre code { background: none; padding: 0; font-size: .84em; color: var(--code-fg); }
article table { border-collapse: collapse; width: 100%; margin: 1.1em 0; font-size: .93em; display: block; overflow-x: auto; }
article th, article td { border: 1px solid var(--line); padding: .45em .6em; text-align: left; vertical-align: top; }
article th { background: var(--panel); }
article blockquote { margin: 1em 0; padding: .2em 1em; border-left: 3px solid var(--accent); color: var(--muted); }
article img { max-width: 100%; }
.page-list { list-style: none; padding: 0; columns: 2; }
.page-list li { margin: .2em 0; break-inside: avoid; }
.page-footer { margin-top: 2.5em; color: var(--muted); }

.toc {
  position: sticky; top: 76px; align-self: start; width: 220px; padding-top: .4em;
  border-left: 1px solid var(--line); padding-left: 1rem; font-size: .85rem;
}
.toc-h { color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; margin: 0 0 .5em; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: .28em 0; }
.toc a { color: var(--muted); display: block; padding-left: .4em; border-left: 2px solid transparent; }
.toc a:hover { color: var(--accent); text-decoration: none; border-left-color: var(--accent); }

/* syntax highlight (friendly-ish, both themes) */
.kw { color: #8959a8; } .str { color: #718c00; } .num { color: #f5871f; }
.com { color: #8e908c; font-style: italic; } .fn { color: #3971ed; } .op { color: #3971ed; }
@media (prefers-color-scheme: dark) {
  .kw { color: #c792ea; } .str { color: #c3e88d; } .num { color: #f78c6c; }
  .com { color: #676e95; } .fn { color: #82aaff; } .op { color: #89ddff; }
}

.footer { border-top: 1px solid var(--line); padding: 1.2rem; text-align: center; color: var(--muted); font-size: .85rem; }
.search-results .results { list-style: none; padding: 0; }
.search-results .results li { padding: .7em 0; border-bottom: 1px solid var(--line); }
.search-results .results a { font-size: 1.05rem; font-weight: 600; }
.search-results .snippet { color: var(--muted); font-size: .9rem; }
#search-status { color: var(--muted); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .doc { grid-template-columns: 1fr; }
  .toc { display: none; }
  .content { padding: 1.2rem 1.1rem 4rem; }
  .searchbox input { width: 150px; }
}
