/* Handbook styles: an mdBook-like layout with light and dark themes. */
:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #59636e;
  --border: #d1d9e0;
  --sidebar-bg: #f6f7f9;
  --sidebar-fg: #2f3a44;
  --active-bg: #e7effa;
  --accent: #0b63ce;
  --link: #0b63ce;
  --code-bg: #f3f5f7;
  --quote-bg: #f5f8fc;
  --table-head: #f3f5f7;
  --shadow: 0 8px 24px rgba(20, 30, 45, 0.14);
  --tok-keyword: #c9204a;
  --tok-string: #0b5394;
  --tok-comment: #6a737d;
  --tok-number: #0550ae;
  --tok-name: #7a3fbf;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #161923;
  --fg: #c6c8d8;
  --muted: #8d91a8;
  --border: #2f3549;
  --sidebar-bg: #1d2130;
  --sidebar-fg: #b9bcd0;
  --active-bg: #262c40;
  --accent: #5ea3e6;
  --link: #6cb3f0;
  --code-bg: #1f2434;
  --quote-bg: #1c2232;
  --table-head: #1f2434;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --tok-keyword: #ff7b94;
  --tok-string: #8cc4ff;
  --tok-comment: #8b93a7;
  --tok-number: #79c0ff;
  --tok-name: #d2a8ff;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161923;
    --fg: #c6c8d8;
    --muted: #8d91a8;
    --border: #2f3549;
    --sidebar-bg: #1d2130;
    --sidebar-fg: #b9bcd0;
    --active-bg: #262c40;
    --accent: #5ea3e6;
    --link: #6cb3f0;
    --code-bg: #1f2434;
    --quote-bg: #1c2232;
    --table-head: #1f2434;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    --tok-keyword: #ff7b94;
    --tok-string: #8cc4ff;
    --tok-comment: #8b93a7;
    --tok-number: #79c0ff;
    --tok-name: #d2a8ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 64px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--link); }

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; width: 300px;
  overflow-y: auto; padding: 18px 0 48px;
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
  transition: transform 0.2s ease; z-index: 20;
}
.book-title {
  display: block; padding: 0 20px 12px; font-weight: 700; font-size: 1.05em;
  color: var(--sidebar-fg); text-decoration: none; line-height: 1.35;
}
.part-title {
  padding: 16px 20px 4px; font-size: 0.72em; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.chapters { list-style: none; margin: 0; padding: 0; }
.chapters a {
  display: block; padding: 5px 20px; font-size: 0.93em; line-height: 1.4;
  color: var(--sidebar-fg); text-decoration: none; border-left: 3px solid transparent;
}
.chapters a:hover { color: var(--accent); }
.chapters a.active {
  color: var(--accent); font-weight: 600;
  background: var(--active-bg); border-left-color: var(--accent);
}

/* ---------- page and top bar ---------- */
.page { margin-left: 300px; min-height: 100vh; transition: margin-left 0.2s ease; }
body.sidebar-hidden .sidebar { transform: translateX(-100%); }
body.sidebar-hidden .page { margin-left: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.icon-btn {
  flex: none; min-width: 38px; height: 36px; padding: 0 10px;
  background: none; color: var(--fg); font-size: 18px; line-height: 1;
  border: 1px solid transparent; border-radius: 6px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--border); }
.source-link { font-size: 14px; text-decoration: none; color: var(--muted); }

/* ---------- search ---------- */
.search { position: relative; flex: 1; max-width: 560px; margin: 0 auto; }
.search input {
  width: 100%; height: 36px; padding: 0 12px; font: inherit; font-size: 15px;
  color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0; max-height: 70vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.search-results a {
  display: block; padding: 10px 14px; color: var(--fg); text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.search-results a:last-child { border-bottom: none; }
.search-results a:hover, .search-results a:focus { background: var(--active-bg); }
.search-results .where { font-size: 0.78em; color: var(--muted); }
.search-results .what { font-weight: 600; }
.search-results .snippet { font-size: 0.86em; color: var(--muted); }
.search-results mark { background: none; color: var(--accent); font-weight: 700; }
.search-results .empty { padding: 12px 14px; color: var(--muted); }

/* ---------- content ---------- */
.content { max-width: 860px; margin: 0 auto; padding: 28px 40px 64px; }
.content h1 { font-size: 2em; line-height: 1.25; margin: 0.2em 0 0.6em; }
.content h2 { font-size: 1.5em; line-height: 1.3; margin-top: 1.8em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.content h3 { font-size: 1.2em; margin-top: 1.5em; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.content img { max-width: 100%; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
.content :not(pre) > code {
  background: var(--code-bg); padding: 0.12em 0.36em; border-radius: 4px; font-size: 0.88em;
}
.content pre {
  background: var(--code-bg); padding: 12px 16px; border-radius: 8px; overflow-x: auto;
  font-size: 0.84em; line-height: 1.5;
}
.content blockquote {
  margin: 1.2em 0; padding: 8px 18px; background: var(--quote-bg);
  border-left: 4px solid var(--accent); border-radius: 0 8px 8px 0;
}
.table-wrap { overflow-x: auto; margin: 1em 0; }
.content table { border-collapse: collapse; width: 100%; font-size: 0.94em; }
.content th, .content td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; vertical-align: top; }
.content thead th { background: var(--table-head); }
.content details {
  margin: 10px 0; padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
}
.content summary { cursor: pointer; font-weight: 600; }
.content details[open] summary { margin-bottom: 8px; }
.math-display { overflow-x: auto; overflow-y: hidden; margin: 1em 0; }

/* ---------- previous / next and footer ---------- */
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 56px; }
.pager a {
  flex: 1; max-width: 48%; padding: 12px 16px; text-decoration: none; color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; line-height: 1.4;
}
.pager a:hover { border-color: var(--accent); }
.pager a span { display: block; font-size: 0.78em; color: var(--muted); }
.pager .nav-next { margin-left: auto; text-align: right; }
footer { margin-top: 48px; font-size: 0.82em; color: var(--muted); }

/* ---------- code highlighting (Pygments classes) ---------- */
.k, .kn, .kd, .kc, .kr, .ow { color: var(--tok-keyword); }
.s, .s1, .s2, .sd, .sa, .se, .si, .sb { color: var(--tok-string); }
.c, .c1, .cm, .ch { color: var(--tok-comment); font-style: italic; }
.mi, .mf, .mh, .il { color: var(--tok-number); }
.nf, .nc, .fm, .nb, .bp, .nd { color: var(--tok-name); }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .page, body.sidebar-hidden .page { margin-left: 0; }
  .content { padding: 20px 16px 48px; }
  .source-link { display: none; }
  .pager { flex-direction: column; }
  .pager a { max-width: 100%; }
}
@media print {
  .sidebar, .topbar, .pager { display: none; }
  .page { margin-left: 0; }
}
