:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f7f8fa;
  --text: #1c1e21;
  --muted: #5c6570;
  --border: #e6e8ec;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --code-bg: #f3f5f7;
  --pre-bg: #161b22;
  --pre-text: #e8eef5;
  --link: #2457d6;
  --shadow: 0 12px 40px rgba(16, 24, 40, 0.14);
  --sidebar-w: 280px;
  --toc-w: 210px;
  --content: 740px;
  --topbar: 56px;
  --font: "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --sidebar: #171a20;
  --text: #e8eaed;
  --muted: #a0a6b0;
  --border: #2c313a;
  --accent: #8ab4ff;
  --accent-soft: #1c283d;
  --code-bg: #1c2028;
  --pre-bg: #0b0d11;
  --pre-text: #e7ecf1;
  --link: #8ab4ff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--link); }

.skip {
  position: absolute;
  left: 8px;
  top: -40px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  z-index: 50;
}

.skip:focus { top: 8px; }

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

.shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 18px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.02rem;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border-radius: 4px;
  background: var(--accent);
  vertical-align: -1px;
}

.theme-toggle,
.menu {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.theme-toggle {
  font-size: 0.78rem;
  padding: 4px 8px;
}

.search-label { display: block; padding: 0 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.doc-search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.9rem;
}

.noscript {
  margin: 8px 6px 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-results a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
}

.search-results a:hover,
.search-results a:focus { background: var(--accent-soft); }

.search-results small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.nav details summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 8px 6px;
}

.nav details summary::-webkit-details-marker { display: none; }

.nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav a {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  line-height: 1.4;
}

.nav a:hover { background: var(--accent-soft); }

.nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  gap: 12px;
  padding: 16px 8px 0;
  font-size: 0.85rem;
}

.sidebar-foot a { text-decoration: none; }

.page {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  height: var(--topbar);
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 45;
}

body.nav-open { overflow: hidden; }

.menu {
  width: 40px;
  height: 36px;
  padding: 8px;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.menu span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.topbar-title {
  font-weight: 700;
  letter-spacing: -0.02em;
  flex: 1;
}

.topbar-title a {
  color: var(--text);
  text-decoration: none;
}

.page-body {
  display: grid;
  grid-template-columns: minmax(0, var(--content)) var(--toc-w);
  justify-content: center;
  gap: 40px;
  padding: 40px 32px 72px;
}

.content {
  min-width: 0;
  overflow-x: auto;
}

.crumbs {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.crumbs .sep { margin: 0 6px; }

.toc-mobile { display: none; }

.toc {
  position: sticky;
  top: 24px;
  align-self: start;
  font-size: 0.82rem;
  line-height: 1.45;
}

.toc p,
.toc-mobile summary {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.toc a,
.toc-mobile a {
  display: block;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 0;
}

.toc a:hover,
.toc-mobile a:hover { color: var(--text); }

.toc a.depth-3,
.toc-mobile a.depth-3 { padding-left: 12px; }

.content h1,
.content h2,
.content h3,
.content h4 {
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 700;
  scroll-margin-top: 72px;
}

.content h1 {
  margin: 0 0 0.7em;
  font-size: 2rem;
}

.content h2 {
  margin: 1.8em 0 0.55em;
  font-size: 1.35rem;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}

.content h3 {
  margin: 1.4em 0 0.4em;
  font-size: 1.08rem;
}

.content p { margin: 0 0 1em; }

.content ul,
.content ol { margin: 0 0 1em; padding-left: 1.3em; }

.content li { margin: 0.25em 0; }

.content a:hover { text-decoration-thickness: 1px; }

.content strong { font-weight: 600; }

.content blockquote {
  margin: 1em 0;
  padding: 0.2em 0 0.2em 1em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  color: var(--text);
}

.content blockquote p:last-child { margin-bottom: 0; }

.content code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.content pre {
  background: var(--pre-bg);
  color: var(--pre-text);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.55;
  font-size: 0.86rem;
  margin: 0 0 1.2em;
}

.content pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.4em;
  font-size: 0.92rem;
}

.content th,
.content td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.content th {
  background: var(--sidebar);
  font-weight: 600;
}

.content img {
  max-width: 100%;
  height: auto;
}

.content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.pager a {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--text);
  min-height: 72px;
}

.pager a:hover { border-color: var(--accent); }

.pager .next { text-align: right; }

.pager span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.pager strong {
  display: block;
  margin-top: 4px;
  font-weight: 600;
}

.colophon {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.colophon a { color: var(--muted); }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.45);
  z-index: 30;
}

@media (max-width: 1180px) {
  .page-body {
    grid-template-columns: minmax(0, var(--content));
    padding-left: 24px;
    padding-right: 24px;
  }

  .toc { display: none; }

  .toc-mobile {
    display: block;
    margin: 0 0 1.2rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    background: var(--sidebar);
  }

  .toc-mobile summary { cursor: pointer; }
}

@media (max-width: 960px) {
  .shell { flex-direction: column; }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  html.js .topbar { display: flex; }

  html.js .sidebar {
    position: fixed;
    top: var(--topbar);
    left: 0;
    width: min(320px, 88vw);
    height: calc(100vh - var(--topbar));
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    border-right: 1px solid var(--border);
    border-bottom: 0;
  }

  html.js .sidebar.is-open { transform: none; }
}

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