/* ============ tokens ============ */
:root{
  --bg:#f7f6f2;
  --surface:#ffffff;
  --surface-2:#f0eee6;
  --ink:#1b1d24;
  --ink-muted:#5b606c;
  --ink-faint:#8c8f99;
  --border:#e4e0d4;
  --border-strong:#d3cebb;
  --accent:#a8681a;
  --accent-ink:#7a4c11;
  --accent-soft:#f3e6cf;
  --accent-2:#2f5fd6;
  --code-bg:#efece2;
  --shadow: 0 8px 28px -12px rgba(30,24,10,.18);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#12141a; --surface:#181b23; --surface-2:#1f232d;
    --ink:#edeff3; --ink-muted:#9aa0ae; --ink-faint:#666c7a;
    --border:#282c37; --border-strong:#363c4a;
    --accent:#e2a63b; --accent-ink:#f2c069; --accent-soft:#332b17;
    --accent-2:#7fa2ff;
    --code-bg:#1d212b;
    --shadow: 0 12px 32px -14px rgba(0,0,0,.55);
  }
}
:root[data-theme="dark"]{
  --bg:#12141a; --surface:#181b23; --surface-2:#1f232d;
  --ink:#edeff3; --ink-muted:#9aa0ae; --ink-faint:#666c7a;
  --border:#282c37; --border-strong:#363c4a;
  --accent:#e2a63b; --accent-ink:#f2c069; --accent-soft:#332b17;
  --accent-2:#7fa2ff;
  --code-bg:#1d212b;
  --shadow: 0 12px 32px -14px rgba(0,0,0,.55);
}
:root[data-theme="light"]{
  --bg:#f7f6f2; --surface:#ffffff; --surface-2:#f0eee6;
  --ink:#1b1d24; --ink-muted:#5b606c; --ink-faint:#8c8f99;
  --border:#e4e0d4; --border-strong:#d3cebb;
  --accent:#a8681a; --accent-ink:#7a4c11; --accent-soft:#f3e6cf;
  --accent-2:#2f5fd6;
  --code-bg:#efece2;
  --shadow: 0 8px 28px -12px rgba(30,24,10,.18);
}

*{box-sizing:border-box;}
html{scroll-behavior:smooth;}
body{
  margin:0; background:var(--bg); color:var(--ink); font-family:var(--sans);
  -webkit-font-smoothing:antialiased; min-height:100vh;
}
a{color:var(--accent-2); text-decoration:none;}
a:hover{text-decoration:underline;}
a:focus-visible, button:focus-visible, input:focus-visible{
  outline:2px solid var(--accent-2); outline-offset:2px; border-radius:4px;
}

/* ============ topbar ============ */
.topbar{
  position:sticky; top:0; z-index:40; display:flex; align-items:center; gap:14px;
  height:56px; padding:0 16px; background:var(--surface); border-bottom:1px solid var(--border);
}
.menu-btn, .theme-btn{
  background:none; border:1px solid transparent; color:var(--ink-muted); cursor:pointer;
  width:34px; height:34px; border-radius:8px; display:flex; align-items:center; justify-content:center; flex:none;
}
.menu-btn:hover, .theme-btn:hover{background:var(--surface-2); color:var(--ink);}
.menu-btn{display:none;}
.brand{display:flex; align-items:center; gap:9px; color:var(--ink); flex:none;}
.brand:hover{text-decoration:none;}
.brand-mark{
  width:28px; height:28px; border-radius:7px; background:var(--accent); color:var(--surface);
  display:flex; align-items:center; justify-content:center; font-weight:800; font-size:15px; flex:none;
}
.brand-text{font-weight:700; font-size:14.5px; letter-spacing:-.01em; white-space:nowrap;}
.brand-sub{color:var(--ink-faint); font-weight:500;}
.search-wrap{position:relative; flex:1; max-width:420px; margin-left:8px;}
.search-icon{position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--ink-faint); pointer-events:none;}
#searchInput{
  width:100%; height:34px; border-radius:8px; border:1px solid var(--border); background:var(--surface-2);
  color:var(--ink); font-size:13.5px; padding:0 12px 0 32px; font-family:var(--sans);
}
#searchInput:focus{outline:none; border-color:var(--accent-2); background:var(--surface);}
.search-results{
  position:absolute; top:calc(100% + 6px); left:0; right:0; background:var(--surface);
  border:1px solid var(--border-strong); border-radius:10px; box-shadow:var(--shadow);
  max-height:60vh; overflow-y:auto; display:none; z-index:50;
}
.search-results.open{display:block;}
.search-results a{
  display:block; padding:9px 12px; color:var(--ink); border-bottom:1px solid var(--border); font-size:13px;
}
.search-results a:last-child{border-bottom:none;}
.search-results a:hover{background:var(--surface-2); text-decoration:none;}
.search-results .sr-section{font-family:var(--mono); font-size:10.5px; color:var(--accent); text-transform:uppercase; letter-spacing:.05em; display:block; margin-bottom:2px;}
.search-empty{padding:14px 12px; color:var(--ink-faint); font-size:13px;}
.gh-link{color:var(--ink-muted); display:flex; flex:none;}
.gh-link:hover{color:var(--ink);}

/* ============ shell layout ============ */
.shell{display:grid; grid-template-columns:260px minmax(0,1fr) 220px; max-width:1400px; margin:0 auto;}
.scrim{display:none;}

/* ============ sidebar ============ */
.sidebar{
  border-right:1px solid var(--border); padding:20px 12px 60px; height:calc(100vh - 56px);
  position:sticky; top:56px; overflow-y:auto;
}
.sb-group{margin-bottom:4px;}
.sb-group-head{
  display:flex; align-items:center; gap:8px; width:100%; background:none; border:none; cursor:pointer;
  padding:8px 8px; border-radius:7px; color:var(--ink); font-family:var(--sans); text-align:left;
}
.sb-group-head:hover{background:var(--surface-2);}
.sb-num{font-family:var(--mono); font-size:10.5px; color:var(--accent); width:18px; flex:none;}
.sb-group-title{font-size:12.5px; font-weight:700; flex:1;}
.sb-caret{color:var(--ink-faint); transition:transform .15s ease; flex:none;}
.sb-group.open .sb-caret{transform:rotate(90deg);}
.sb-items{list-style:none; margin:2px 0 8px; padding:0 0 0 26px; display:none;}
.sb-group.open .sb-items{display:block;}
.sb-items li{margin:1px 0;}
.sb-items a{
  display:block; padding:6px 10px; border-radius:6px; font-size:13px; color:var(--ink-muted);
  border-left:2px solid transparent;
}
.sb-items a:hover{background:var(--surface-2); color:var(--ink); text-decoration:none;}
.sb-items a.active{color:var(--accent-ink); background:var(--accent-soft); border-left-color:var(--accent); font-weight:600;}

/* ============ content ============ */
.content{padding:36px 48px 80px; min-width:0; max-width:760px;}
.loading{color:var(--ink-faint); padding:40px 0; font-size:14px;}
.crumb{font-family:var(--mono); font-size:11.5px; color:var(--ink-faint); text-transform:uppercase; letter-spacing:.05em; margin-bottom:14px;}
.crumb a{color:var(--ink-faint);}
.crumb a:hover{color:var(--accent-2);}

.md h1{font-size:30px; letter-spacing:-.02em; line-height:1.2; margin:0 0 6px; text-wrap:balance;}
.md > p:first-of-type em{color:var(--ink-muted); font-size:15.5px; display:block; margin-bottom:28px; line-height:1.6;}
.md h2{font-size:19px; font-weight:700; margin:38px 0 14px; padding-top:10px; border-top:1px solid var(--border); letter-spacing:-.005em;}
.md h2:first-of-type{border-top:none; padding-top:0; margin-top:24px;}
.md h3{font-size:15.5px; font-weight:700; margin:24px 0 10px;}
.md p{line-height:1.75; font-size:15px; color:var(--ink); margin:0 0 16px;}
.md ul, .md ol{line-height:1.75; font-size:15px; padding-left:22px; margin:0 0 16px;}
.md li{margin:5px 0;}
.md li > ul, .md li > ol{margin:6px 0 0;}
.md a{font-weight:500;}
.md strong{font-weight:700; color:var(--ink);}
.md code{font-family:var(--mono); font-size:.87em; background:var(--code-bg); padding:2px 5px; border-radius:4px; border:1px solid var(--border);}
.md pre{background:var(--code-bg); border:1px solid var(--border); border-radius:10px; padding:14px 16px; overflow-x:auto; margin:0 0 16px;}
.md pre code{background:none; border:none; padding:0; font-size:13px; line-height:1.6;}
.md blockquote{margin:0 0 16px; padding:2px 16px; border-left:3px solid var(--accent); color:var(--ink-muted); font-style:italic;}
.md hr{border:none; border-top:1px solid var(--border); margin:28px 0;}
.md table{border-collapse:collapse; width:100%; margin:0 0 20px; font-size:13.5px; display:block; overflow-x:auto;}
.md th, .md td{border:1px solid var(--border); padding:8px 12px; text-align:left; vertical-align:top;}
.md th{background:var(--surface-2); font-weight:700; white-space:nowrap;}
.md img{max-width:100%; border-radius:8px;}

.page-nav{display:flex; justify-content:space-between; gap:16px; margin-top:48px; padding-top:20px; border-top:1px solid var(--border);}
.page-nav a{
  flex:1; max-width:48%; border:1px solid var(--border); border-radius:10px; padding:12px 14px; color:var(--ink);
  display:flex; flex-direction:column; gap:3px;
}
.page-nav a:hover{border-color:var(--accent); text-decoration:none;}
.page-nav .pn-label{font-family:var(--mono); font-size:10px; color:var(--ink-faint); text-transform:uppercase; letter-spacing:.05em;}
.page-nav .pn-next{text-align:right; margin-left:auto;}
.page-nav .pn-title{font-size:13.5px; font-weight:600;}

/* ============ right toc ============ */
.toc{padding:24px 20px; position:sticky; top:56px; height:calc(100vh - 56px); overflow-y:auto;}
.toc-title{font-family:var(--mono); font-size:10.5px; text-transform:uppercase; letter-spacing:.07em; color:var(--ink-faint); margin-bottom:10px;}
.toc-list{list-style:none; margin:0; padding:0; border-left:1px solid var(--border);}
.toc-list li{margin:0;}
.toc-list a{
  display:block; padding:5px 0 5px 14px; font-size:12.5px; color:var(--ink-muted); border-left:2px solid transparent; margin-left:-1px;
}
.toc-list a.h3{padding-left:24px; font-size:12px;}
.toc-list a:hover, .toc-list a.active{color:var(--accent-ink); border-left-color:var(--accent); text-decoration:none;}

/* ============ landing (home) ============ */
.landing-hero{margin-bottom:36px;}
.eyebrow{font-family:var(--mono); font-size:12px; letter-spacing:.12em; text-transform:uppercase; color:var(--accent); font-weight:700; margin:0 0 10px;}
.landing-grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(220px,1fr)); gap:12px; margin:24px 0 8px;}
.landing-card{
  border:1px solid var(--border); border-radius:12px; padding:16px 16px 14px; background:var(--surface);
  display:flex; flex-direction:column; gap:6px;
}
.landing-card:hover{border-color:var(--accent); text-decoration:none;}
.landing-card .lc-num{font-family:var(--mono); font-size:11px; color:var(--accent);}
.landing-card .lc-title{font-size:14.5px; font-weight:700; color:var(--ink);}
.landing-card .lc-desc{font-size:12.5px; color:var(--ink-muted); line-height:1.5;}

/* ============ footer ============ */
.site-footer{
  border-top:1px solid var(--border); padding:22px 24px; text-align:center; font-size:12px; color:var(--ink-faint);
}
.site-footer .dot{margin:0 8px;}
.site-footer a{color:var(--ink-faint);}

/* ============ responsive ============ */
@media (max-width:1180px){
  .shell{grid-template-columns:260px minmax(0,1fr);}
  .toc{display:none;}
}
@media (max-width:860px){
  .menu-btn{display:flex;}
  .brand-sub{display:none;}
  .search-wrap{max-width:none;}
  .shell{grid-template-columns:1fr; position:relative;}
  .sidebar{
    position:fixed; left:0; top:56px; bottom:0; width:280px; z-index:45; background:var(--surface);
    transform:translateX(-100%); transition:transform .2s ease; box-shadow:var(--shadow);
  }
  .sidebar.open{transform:translateX(0);}
  .scrim{
    display:none; position:fixed; inset:56px 0 0 0; background:rgba(0,0,0,.35); z-index:44;
  }
  .scrim.open{display:block;}
  .content{padding:24px 20px 60px;}
}
@media (max-width:520px){
  .brand-text{font-size:13px;}
  .content{padding:18px 14px 50px;}
  .md h1{font-size:24px;}
}

@media (prefers-reduced-motion: reduce){
  html{scroll-behavior:auto;}
  .sidebar, .sb-caret{transition:none;}
}
