:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --fg: #1d2129;
  --muted: #5d6573;
  --border: #e2e5ea;
  --accent: #2f6fdd;
  --accent-soft: #e8f0fd;
  --code-bg: #f3f4f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --bg-soft: #1c1f26;
    --fg: #e4e6eb;
    --muted: #9aa2b1;
    --border: #2c303a;
    --accent: #7aa7f5;
    --accent-soft: #1f2a40;
    --code-bg: #1f222a;
    color-scheme: dark;
  }
  .shiki, .shiki span { color: var(--shiki-dark) !important; background-color: var(--shiki-dark-bg) !important; }
}
@media (prefers-color-scheme: light) {
  .shiki, .shiki span { color: var(--shiki-light); background-color: var(--shiki-light-bg); }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 4.5rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  height: 3.5rem; padding: 0 1rem;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; color: var(--fg); }
.menu { display: none; background: none; border: 0; color: var(--fg); font-size: 1.25rem; cursor: pointer; }
.search {
  margin-left: auto; width: min(22rem, 45vw);
  padding: .4rem .7rem; border: 1px solid var(--border); border-radius: .5rem;
  background: var(--bg-soft); color: var(--fg); font: inherit;
}
.results {
  position: absolute; top: 3.2rem; right: 1rem; width: min(30rem, calc(100vw - 2rem));
  max-height: 70vh; overflow: auto; margin: 0; padding: .4rem; list-style: none;
  background: var(--bg); border: 1px solid var(--border); border-radius: .5rem;
  box-shadow: 0 8px 30px rgb(0 0 0 / .15);
}
.results a { display: block; padding: .45rem .6rem; border-radius: .35rem; color: var(--fg); }
.results a:hover, .results a:focus { background: var(--accent-soft); text-decoration: none; }
.results small { display: block; color: var(--muted); }

.layout { display: grid; grid-template-columns: 16rem minmax(0, 1fr) 13rem; max-width: 90rem; margin: 0 auto; }
.sidebar, .toc { position: sticky; top: 3.5rem; align-self: start; max-height: calc(100vh - 3.5rem); overflow: auto; padding: 1.5rem 1rem; }
.sidebar { border-right: 1px solid var(--border); }
.sidebar h2, .toc h2 { margin: 1.2rem 0 .4rem; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.sidebar h2:first-child, .toc h2:first-child { margin-top: 0; }
.sidebar ul, .toc ul { margin: 0; padding: 0; list-style: none; }
.sidebar a, .toc a { display: block; padding: .2rem .5rem; border-radius: .35rem; color: var(--muted); font-size: .92rem; }
.sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toc .h3 a { padding-left: 1.2rem; }

main { min-width: 0; padding: 2rem 2.5rem 4rem; }
article { max-width: 48rem; }
article h1 { font-size: 2rem; line-height: 1.25; margin: 0 0 1.25rem; }
article h2 { margin-top: 2.4rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 1.4rem; }
article h3 { margin-top: 1.8rem; font-size: 1.12rem; }
article code { font: .88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
article :not(pre) > code { padding: .1em .35em; border-radius: .3rem; background: var(--code-bg); }
article pre { overflow: auto; padding: .9rem 1rem; border-radius: .5rem; border: 1px solid var(--border); }
article table { display: block; overflow: auto; border-collapse: collapse; margin: 1rem 0; }
article th, article td { padding: .45rem .7rem; border: 1px solid var(--border); text-align: left; vertical-align: top; }
article th { background: var(--bg-soft); }
article blockquote { margin: 1rem 0; padding: .2rem 1rem; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 .4rem .4rem 0; }
article img { max-width: 100%; }

.pager { display: flex; justify-content: space-between; gap: 1rem; max-width: 48rem; margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.pager a { display: grid; padding: .6rem .9rem; border: 1px solid var(--border); border-radius: .5rem; }
.pager a[rel="next"] { text-align: right; margin-left: auto; }
.pager small { color: var(--muted); }

@media (max-width: 70rem) {
  .layout { grid-template-columns: 15rem minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 48rem) {
  .menu { display: block; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; position: fixed; inset: 3.5rem 0 0 0; z-index: 5; max-height: none; background: var(--bg); }
  body.nav-open .sidebar { display: block; }
  main { padding: 1.25rem 1rem 3rem; }
  .search { width: 50vw; }
}
