:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --text: #1f2933;
  --muted: #627084;
  --border: #e3e7ec;
  --accent: #2459c9;
  --accent-soft: #eaf0fc;
  --mark: #ffe9a8;
  --topbar-h: 56px;
  --sidebar-w: 290px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181d;
    --bg-soft: #1c2026;
    --text: #dfe4ea;
    --muted: #96a1b0;
    --border: #2c323b;
    --accent: #86aaf5;
    --accent-soft: #222c40;
    --mark: #6b5a1c;
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--topbar-h) + 16px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--font);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); }

.brand {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text);
  font-weight: 600;
}
.brand:hover { text-decoration: none; }

.search {
  position: relative;
  flex: 1 1 200px;
  max-width: 340px;
  min-width: 120px;
  margin-left: auto;
}

.search input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  -webkit-appearance: none;
  appearance: none;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--bg); }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(480px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
}

.search-results a {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover,
.search-results a:focus { background: var(--accent-soft); text-decoration: none; outline: none; }

.result-title { font-weight: 600; }
.result-section { margin-left: 8px; color: var(--muted); font-size: 13px; }
.result-excerpt { display: block; color: var(--muted); font-size: 14px; line-height: 1.45; }
.search-empty { margin: 0; padding: 14px; color: var(--muted); font-size: 14px; }
mark { background: var(--mark); color: inherit; border-radius: 2px; }

/* ------------------------------------------------------------------ sidebar */

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  z-index: 20;
  width: var(--sidebar-w);
  padding: 16px 12px 32px;
  overflow-y: auto;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  transition: transform 0.2s ease;
}

.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar ul ul { margin-left: 13px; padding-left: 8px; border-left: 1px solid var(--border); }
.sidebar [hidden] { display: none; }

.nav-row { display: flex; align-items: center; border-radius: 6px; }
.nav-row:hover { background: var(--border); }

.nav-row a,
.nav-label {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}
.nav-row a:hover { text-decoration: none; }
.nav-row a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.nav-list > li > .nav-row > a,
.nav-list > li > .nav-row > .nav-label { font-weight: 600; }
/* Leaf rows line up with rows that have a toggle. */
.nav-row > :only-child { margin-left: 26px; }

.nav-toggle {
  flex: none;
  width: 26px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.nav-toggle::before {
  content: "";
  display: block;
  width: 7px;
  height: 7px;
  margin: 0 auto;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: translateX(-2px) rotate(-45deg);
  transition: transform 0.15s ease;
}
.nav-toggle[aria-expanded="true"]::before { transform: translateY(-2px) rotate(45deg); }

.backdrop { display: none; }

/* ------------------------------------------------------------------ content */

.content {
  margin-left: var(--sidebar-w);
  padding: calc(var(--topbar-h) + 32px) 40px 64px;
  transition: margin-left 0.2s ease;
}

.content > * { max-width: 780px; margin-left: auto; margin-right: auto; }

.nav-collapsed .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform 0.2s ease, visibility 0s 0.2s; }
.nav-collapsed .content { margin-left: 0; }

article h1, article h2, article h3, article h4 { line-height: 1.25; margin: 2em 0 0.6em; }
article h1 { font-size: 2rem; margin-top: 0; }
article h2 { font-size: 1.45rem; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
article h3 { font-size: 1.15rem; }
article p, article ul, article ol, article pre, article blockquote, .table-wrap { margin: 0 0 1.1em; }
article li + li { margin-top: 0.25em; }
article img { max-width: 100%; height: auto; }
article hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }

article code {
  padding: 0.15em 0.35em;
  border-radius: 4px;
  background: var(--bg-soft);
  font: 0.875em var(--mono);
}
article pre {
  padding: 14px 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  line-height: 1.5;
}
article pre code { padding: 0; background: none; }

article blockquote {
  padding: 2px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
}
article blockquote > :first-child { margin-top: 0.6em; }
article blockquote > :last-child { margin-bottom: 0.6em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-weight: 600; white-space: nowrap; }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.pager a { max-width: 48%; font-weight: 600; }
.pager .next { text-align: right; }
.pager a span { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }

/* ------------------------------------------------------------------- mobile */

@media (max-width: 860px) {
  .sidebar,
  .nav-collapsed .sidebar {
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s 0.2s;
  }
  .nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.2s ease; box-shadow: 0 0 32px rgba(0, 0, 0, 0.25); }
  .nav-open .backdrop {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 10;
    background: rgba(0, 0, 0, 0.35);
  }
  .content { margin-left: 0; padding: calc(var(--topbar-h) + 20px) 16px 48px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .search { position: static; }
  .search-results { position: fixed; top: calc(var(--topbar-h) + 6px); left: 8px; right: 8px; width: auto; }
  article h1 { font-size: 1.65rem; }
  article h2 { font-size: 1.3rem; }
}

@media (max-width: 480px) {
  .brand { flex-basis: 40%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .topbar, .sidebar, .pager, .backdrop { display: none; }
  .content { margin: 0; padding: 0; }
}
