:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1eee7;
  --ink: #18202e;
  --ink-2: #4a5263;
  --ink-3: #7b8191;
  --line: #e4dfd4;
  --line-2: #d6cfbf;
  --brand: #162033;
  --accent: #b0832f;
  --accent-ink: #8a6420;
  --accent-soft: #f5ecd9;
  --link: #8a6420;
  --code-bg: #f3f0e9;
  --code-ink: #2b3242;
  --pre-bg: #1b2333;
  --pre-ink: #e3e6ee;
  --shadow: 0 1px 2px rgba(22, 32, 51, .05), 0 8px 24px rgba(22, 32, 51, .06);
  --shadow-lg: 0 24px 64px rgba(22, 32, 51, .22);
  --hl-k: #e2b86b; --hl-s: #a6d3a0; --hl-n: #f0a989; --hl-c: #7d879b; --hl-t: #8fc3e8; --hl-f: #c9b1f0;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --topbar: 60px;
  --sidebar: 296px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141d; --surface: #151b26; --surface-2: #1b2230; --ink: #e8eaf0; --ink-2: #b2b8c6; --ink-3: #7d8496;
    --line: #252d3c; --line-2: #313a4b; --brand: #0b1018; --accent: #d4a85a; --accent-ink: #e2bd78; --accent-soft: #2a2416;
    --link: #e2bd78; --code-bg: #1e2634; --code-ink: #e3e6ee; --pre-bg: #0b1018; --pre-ink: #e3e6ee;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); --shadow-lg: 0 24px 64px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141d; --surface: #151b26; --surface-2: #1b2230; --ink: #e8eaf0; --ink-2: #b2b8c6; --ink-3: #7d8496;
  --line: #252d3c; --line-2: #313a4b; --brand: #0b1018; --accent: #d4a85a; --accent-ink: #e2bd78; --accent-soft: #2a2416;
  --link: #e2bd78; --code-bg: #1e2634; --code-ink: #e3e6ee; --pre-bg: #0b1018; --pre-ink: #e3e6ee;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); --shadow-lg: 0 24px 64px rgba(0,0,0,.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar) + 20px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15.5px/1.7 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
kbd {
  font: 500 11px var(--mono); padding: 2px 6px; border-radius: 5px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink-3);
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar); z-index: 30;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--brand); color: #f3efe6;
  border-bottom: 1px solid rgba(212, 168, 90, .35);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; flex-shrink: 0; }
.mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(145deg, #d9b26a, #a77a2c); color: #162033;
  font: 600 14px/1 var(--serif); letter-spacing: -.02em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.mark span { font-style: italic; font-weight: 500; margin: 0 1px; }
.brand-text { display: flex; align-items: baseline; gap: 7px; }
.brand-text strong { font: 600 19px/1 var(--serif); letter-spacing: -.01em; }
.brand-text em {
  font: 600 10.5px/1 var(--sans); font-style: normal; letter-spacing: .14em;
  color: #d4a85a; border: 1px solid rgba(212,168,90,.5); border-radius: 4px; padding: 3px 5px;
}
.search-trigger {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  width: min(380px, 40vw); height: 38px; padding: 0 10px 0 12px; border-radius: 9px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12);
  color: rgba(243,239,230,.7); font: 14px var(--sans); cursor: pointer; transition: background .15s, border-color .15s;
}
.search-trigger:hover { background: rgba(255,255,255,.11); border-color: rgba(212,168,90,.5); }
.search-trigger span { flex: 1; text-align: left; }
.search-trigger kbd { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.15); color: rgba(243,239,230,.6); }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
  background: transparent; border: 1px solid transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.08); }
.menu-btn { display: none; }
.moon { display: none; }
:root[data-theme="dark"] .sun { display: none; }
:root[data-theme="dark"] .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sun { display: none; }
  :root:not([data-theme="light"]) .moon { display: block; }
}

/* ---------- Layout ---------- */
.layout { padding-top: var(--topbar); }
.sidebar {
  position: fixed; top: var(--topbar); bottom: 0; left: 0; width: var(--sidebar);
  display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); z-index: 20;
}
.filter-wrap { padding: 16px 16px 8px; }
#filter {
  width: 100%; height: 34px; padding: 0 12px; border-radius: 8px; font: 13.5px var(--sans);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); outline: none;
}
#filter:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
nav { flex: 1; overflow-y: auto; padding: 4px 10px 24px; scrollbar-width: thin; }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }

.group { margin-top: 6px; }
.group-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border: 0; border-radius: 7px;
  background: none; color: var(--ink-3); cursor: pointer; text-align: left;
  font: 600 11px/1.2 var(--sans); letter-spacing: .09em; text-transform: uppercase;
}
.group-head:hover { color: var(--ink); background: var(--surface-2); }
.group-head .chev { transition: transform .18s; flex-shrink: 0; }
.group.collapsed > .group-head .chev { transform: rotate(-90deg); }
.group-head .count {
  margin-left: auto; font: 500 10.5px var(--mono); letter-spacing: 0; color: var(--ink-3);
  background: var(--surface-2); padding: 1px 7px; border-radius: 10px;
}
.group-body { padding-left: 6px; }
.group.collapsed > .group-body { display: none; }
.group .group { margin-left: 4px; }
.nav-link {
  display: block; padding: 5px 10px 5px 14px; margin: 1px 0; border-radius: 7px;
  font-size: 13.5px; line-height: 1.45; color: var(--ink-2); text-decoration: none;
  border-left: 2px solid transparent; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-ink); border-left-color: var(--accent); font-weight: 500; }
.nav-link .code { font: 500 11.5px var(--mono); color: var(--ink-3); margin-right: 6px; }
.nav-link.active .code { color: var(--accent-ink); }
.nav-empty { padding: 16px; font-size: 13px; color: var(--ink-3); }

.main { margin-left: var(--sidebar); min-width: 0; }
.content-wrap {
  display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 48px;
  max-width: 1180px; margin: 0 auto; padding: 40px 48px 96px;
}
.toc { position: sticky; top: calc(var(--topbar) + 40px); align-self: start; max-height: calc(100vh - var(--topbar) - 80px); overflow-y: auto; font-size: 13px; scrollbar-width: thin; }
.toc h4 { margin: 0 0 10px; font: 600 11px var(--sans); letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); }
.toc a { display: block; padding: 4px 0 4px 12px; border-left: 1px solid var(--line); color: var(--ink-3); text-decoration: none; line-height: 1.4; }
.toc a.l3 { padding-left: 24px; font-size: 12.5px; }
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--accent-ink); border-left-color: var(--accent); }

/* ---------- Document ---------- */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-3); margin-bottom: 14px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--accent-ink); }
.crumbs .sep { opacity: .5; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: -6px 0 28px; padding-bottom: 20px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--ink-3); }
.doc-meta .pill { padding: 2px 9px; border-radius: 20px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }
.doc-meta a { color: inherit; }

.md { min-width: 0; overflow-wrap: break-word; }
.md h1, .md h2, .md h3, .md h4 { color: var(--ink); line-height: 1.25; scroll-margin-top: calc(var(--topbar) + 20px); }
.md h1 { font: 600 clamp(28px, 4vw, 38px)/1.15 var(--serif); letter-spacing: -.02em; margin: 0 0 18px; }
.md h2 { font: 600 24px/1.25 var(--serif); letter-spacing: -.01em; margin: 44px 0 14px; padding-top: 4px; }
.md h3 { font-size: 17.5px; font-weight: 600; margin: 32px 0 10px; }
.md h4 { font-size: 15px; font-weight: 600; margin: 24px 0 8px; }
.md h2 .anchor, .md h3 .anchor { margin-left: 8px; color: var(--accent); opacity: 0; text-decoration: none; font-weight: 400; }
.md h2:hover .anchor, .md h3:hover .anchor { opacity: .8; }
.md p, .md ul, .md ol { margin: 0 0 16px; }
.md ul, .md ol { padding-left: 24px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--accent); }
.md a { color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: var(--link); }
.md strong { font-weight: 600; color: var(--ink); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 36px 0; }
.md blockquote { margin: 0 0 18px; padding: 12px 18px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; color: var(--ink-2); }
.md blockquote > :last-child { margin-bottom: 0; }
.md code { font: 13px/1.5 var(--mono); background: var(--code-bg); color: var(--code-ink); padding: 2px 6px; border-radius: 5px; }
.md pre { position: relative; margin: 0 0 20px; padding: 18px 20px; background: var(--pre-bg); color: var(--pre-ink); border-radius: 10px; overflow-x: auto; box-shadow: var(--shadow); }
.md pre code { background: none; color: inherit; padding: 0; font-size: 13px; line-height: 1.65; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; padding: 4px 10px; border-radius: 6px; cursor: pointer;
  font: 500 11.5px var(--sans); color: #c9cfdc; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12);
  opacity: 0; transition: opacity .15s;
}
.md pre:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.table-wrap { overflow-x: auto; margin: 0 0 22px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.md table { border-collapse: collapse; width: 100%; font-size: 13.5px; line-height: 1.5; }
.md th { text-align: left; font-weight: 600; background: var(--surface-2); color: var(--ink); white-space: nowrap; }
.md th, .md td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.md tr:last-child td { border-bottom: 0; }
.md tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.md input[type="checkbox"] { accent-color: var(--accent); margin-right: 6px; }
.md img { max-width: 100%; border-radius: 8px; }

.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-literal { color: var(--hl-k); }
.hljs-string, .hljs-attr, .hljs-template-tag, .hljs-addition { color: var(--hl-s); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-n); }
.hljs-comment, .hljs-quote, .hljs-meta { color: var(--hl-c); font-style: italic; }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_, .hljs-variable, .hljs-property { color: var(--hl-t); }
.hljs-title, .hljs-title.function_, .hljs-section, .hljs-name { color: var(--hl-f); }
.hljs-deletion { color: var(--hl-n); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 56px; padding-top: 28px; border-top: 1px solid var(--line); }
.pager a { display: block; padding: 14px 18px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; background: var(--surface); transition: border-color .15s, transform .15s; }
.pager a:hover { border-color: var(--accent); transform: translateY(-1px); }
.pager small { display: block; font-size: 11.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; }
.pager span { font-weight: 500; font-size: 14px; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- Home ---------- */
.hero { position: relative; overflow: hidden; padding: 44px 40px; border-radius: 16px; background: var(--brand); color: #f3efe6; margin-bottom: 36px; box-shadow: var(--shadow); }
.hero::after {
  content: ""; position: absolute; right: -80px; top: -80px; width: 320px; height: 320px; border-radius: 50%;
  background: radial-gradient(circle, rgba(212,168,90,.35), transparent 70%);
}
.hero .eyebrow { font: 600 11px var(--sans); letter-spacing: .16em; text-transform: uppercase; color: #d4a85a; }
.hero h1 { font: 600 clamp(30px, 5vw, 46px)/1.08 var(--serif); letter-spacing: -.02em; margin: 10px 0 12px; }
.hero h1 i { color: #d4a85a; font-weight: 500; }
.hero p { max-width: 560px; margin: 0; color: rgba(243,239,230,.75); font-size: 15.5px; }
.stats { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 28px; margin-top: 28px; }
.stats div { font-size: 12px; color: rgba(243,239,230,.6); text-transform: uppercase; letter-spacing: .08em; }
.stats b { display: block; font: 600 26px/1.1 var(--serif); color: #f3efe6; letter-spacing: 0; text-transform: none; }
.section-title { font: 600 20px var(--serif); margin: 0 0 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-bottom: 40px; }
.card {
  display: flex; flex-direction: column; gap: 6px; padding: 20px; border-radius: 12px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .ico { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); margin-bottom: 6px; }
.card h3 { margin: 0; font: 600 16px var(--sans); }
.card p { margin: 0; font-size: 13px; color: var(--ink-3); line-height: 1.5; }
.card .n { margin-top: auto; padding-top: 8px; font: 500 12px var(--mono); color: var(--accent-ink); }
.recent { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.recent li + li { border-top: 1px solid var(--line); }
.recent a { display: flex; gap: 12px; align-items: baseline; padding: 11px 18px; text-decoration: none; font-size: 14px; }
.recent a:hover { background: var(--surface-2); }
.recent small { margin-left: auto; color: var(--ink-3); font: 12px var(--mono); white-space: nowrap; }
.recent .where { color: var(--ink-3); font-size: 12.5px; }

/* ---------- Search palette ---------- */
.palette { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; background: rgba(10, 14, 22, .5); backdrop-filter: blur(3px); }
.palette[hidden] { display: none; }
.palette-box { width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.palette-input { display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); color: var(--ink-3); }
.palette-input input { flex: 1; height: 56px; border: 0; outline: none; background: none; color: var(--ink); font: 16px var(--sans); }
.results { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.results li a { display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none; }
.results li.sel a, .results li a:hover { background: var(--accent-soft); }
.results .r-title { font-weight: 500; font-size: 14px; }
.results .r-path { font: 11.5px var(--mono); color: var(--ink-3); margin-left: 8px; }
.results .r-snip { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.results mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.results .empty { padding: 28px; text-align: center; color: var(--ink-3); font-size: 14px; }

.scrim { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .content-wrap { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .menu-btn { display: grid; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg); width: min(var(--sidebar), 86vw); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--topbar) 0 0 0; background: rgba(10,14,22,.4); z-index: 15; }
  .main { margin-left: 0; }
  .content-wrap { padding: 28px 16px 72px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .search-trigger { width: 40px; padding: 0; justify-content: center; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .hero { padding: 32px 22px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
}
@media (max-width: 420px) {
  .brand-text em { display: none; }
}
