/* PAINT reproduction guide: a small Sphinx-book-like layout for static pages. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-sidebar: #fafbfc;
  --text: #1f2328;
  --muted: #59636e;
  --border: #d8dee4;
  --accent: #215caf;
  --accent-soft: rgba(33, 92, 175, 0.08);
  --code-bg: #f6f8fa;
  --code-text: #1f2328;
  --inline-code-bg: rgba(175, 184, 193, 0.22);
  --note-bar: #215caf;
  --note-bg: rgba(33, 92, 175, 0.06);
  --warn-bar: #c2410c;
  --warn-bg: rgba(194, 65, 12, 0.07);
  --tip-bar: #15803d;
  --tip-bg: rgba(21, 128, 61, 0.07);
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-number: #0550ae;
  --hl-comment: #6e7781;
  --hl-title: #8250df;
  --hl-attr: #953800;
  --hl-built: #0550ae;
  --diagram-fill: #ffffff;
  --diagram-stroke: #8c959f;
  --topbar-h: 56px;
  --sidebar-w: 280px;
  --toc-w: 230px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --bg-soft: #161b22;
    --bg-sidebar: #12161c;
    --text: #e6e8eb;
    --muted: #9aa4af;
    --border: #2d333b;
    --accent: #79a8ff;
    --accent-soft: rgba(121, 168, 255, 0.12);
    --code-bg: #161b22;
    --code-text: #e6edf3;
    --inline-code-bg: rgba(110, 118, 129, 0.3);
    --note-bar: #79a8ff;
    --note-bg: rgba(121, 168, 255, 0.08);
    --warn-bar: #fb923c;
    --warn-bg: rgba(251, 146, 60, 0.09);
    --tip-bar: #4ade80;
    --tip-bg: rgba(74, 222, 128, 0.08);
    --hl-keyword: #ff7b72;
    --hl-string: #a5d6ff;
    --hl-number: #79c0ff;
    --hl-comment: #8b949e;
    --hl-title: #d2a8ff;
    --hl-attr: #ffa657;
    --hl-built: #79c0ff;
    --diagram-fill: #161b22;
    --diagram-stroke: #6e7781;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --bg-soft: #161b22;
  --bg-sidebar: #12161c;
  --text: #e6e8eb;
  --muted: #9aa4af;
  --border: #2d333b;
  --accent: #79a8ff;
  --accent-soft: rgba(121, 168, 255, 0.12);
  --code-bg: #161b22;
  --code-text: #e6edf3;
  --inline-code-bg: rgba(110, 118, 129, 0.3);
  --note-bar: #79a8ff;
  --note-bg: rgba(121, 168, 255, 0.08);
  --warn-bar: #fb923c;
  --warn-bg: rgba(251, 146, 60, 0.09);
  --tip-bar: #4ade80;
  --tip-bg: rgba(74, 222, 128, 0.08);
  --hl-keyword: #ff7b72;
  --hl-string: #a5d6ff;
  --hl-number: #79c0ff;
  --hl-comment: #8b949e;
  --hl-title: #d2a8ff;
  --hl-attr: #ffa657;
  --hl-built: #79c0ff;
  --diagram-fill: #161b22;
  --diagram-stroke: #6e7781;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

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

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

.topbar .brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.topbar .brand:hover { text-decoration: none; }
.topbar .brand span { font-weight: 400; font-size: 14px; color: var(--muted); letter-spacing: 0; }

.topbar .spacer { flex: 1; }

.topbar .toplinks { display: flex; align-items: center; gap: 4px; }
.topbar .toplinks a,
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
}
.topbar .toplinks a:hover,
.icon-btn:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.icon-btn svg { width: 18px; height: 18px; }

.menu-btn { display: none; }

/* ---------- layout ---------- */

.layout { padding-top: var(--topbar-h); }

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  padding: 24px 16px 40px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.sidebar .caption {
  margin: 20px 8px 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.sidebar .caption:first-child { margin-top: 0; }

.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}
.sidebar li a:hover { background: var(--accent-soft); text-decoration: none; }
.sidebar li a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar .side-foot {
  margin: 28px 8px 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.main {
  margin-left: var(--sidebar-w);
  margin-right: var(--toc-w);
  padding: 40px 48px 64px;
  min-width: 0;
}

.doc { max-width: 820px; margin: 0 auto; }

.toc {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--toc-w);
  overflow-y: auto;
  padding: 40px 16px 40px 8px;
  font-size: 13.5px;
}
.toc .toc-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  font-weight: 600;
  color: var(--muted);
}
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc ul ul { border-left: 0; }
.toc li a {
  display: block;
  padding: 3px 0 3px 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  line-height: 1.4;
}
.toc li li a { padding-left: 24px; }
.toc li a:hover { color: var(--text); text-decoration: none; }
.toc li a.active { color: var(--accent); border-left-color: var(--accent); }

.scrim { display: none; }

/* ---------- article typography ---------- */

.doc h1 {
  font-size: 2.1rem;
  line-height: 1.25;
  margin: 0 0 1rem;
  letter-spacing: -0.01em;
}
.doc h2 {
  font-size: 1.5rem;
  line-height: 1.3;
  margin: 2.6rem 0 0.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.doc h3 { font-size: 1.18rem; margin: 2rem 0 0.6rem; }
.doc h2, .doc h3 { position: relative; }

.headerlink {
  margin-left: 8px;
  color: var(--muted);
  opacity: 0;
  font-weight: 400;
  transition: opacity 0.15s;
}
.doc h2:hover .headerlink,
.doc h3:hover .headerlink,
.headerlink:focus { opacity: 1; text-decoration: none; }

.doc p, .doc ul, .doc ol { margin: 0 0 1rem; }
.doc li { margin: 0.25rem 0; }
.doc li > ul, .doc li > ol { margin: 0.25rem 0; }

.lead { font-size: 1.08rem; color: var(--muted); }

.doc code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
  padding: 0.12em 0.36em;
  border-radius: 5px;
  background: var(--inline-code-bg);
  overflow-wrap: anywhere;
}

.codeblock { position: relative; margin: 0 0 1.25rem; }
.doc pre {
  margin: 0 0 1.25rem;
  padding: 14px 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  line-height: 1.5;
}
.codeblock pre { margin: 0; }
.doc pre code {
  padding: 0;
  background: none;
  font-size: 13.5px;
  overflow-wrap: normal;
  white-space: pre;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.codeblock:hover .copy-btn,
.copy-btn:focus { opacity: 1; }
.copy-btn.done { color: var(--tip-bar); border-color: var(--tip-bar); }

/* highlight.js tokens, themed with the page */
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-meta .hljs-keyword { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-meta .hljs-string { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-variable, .hljs-template-variable { color: var(--hl-number); }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-title.class_, .hljs-section { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-name, .hljs-tag, .hljs-params { color: var(--hl-attr); }
.hljs-built_in, .hljs-type, .hljs-meta { color: var(--hl-built); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 0 1.25rem; }
.doc table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.doc th, .doc td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.doc th { font-weight: 600; background: var(--bg-soft); border-top: 1px solid var(--border); }
.doc td.num, .doc th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* admonitions */
.admonition {
  margin: 0 0 1.25rem;
  padding: 12px 16px;
  border-left: 4px solid var(--note-bar);
  border-radius: 6px;
  background: var(--note-bg);
}
.admonition > :last-child { margin-bottom: 0; }
.admonition-title { margin: 0 0 0.35rem !important; font-weight: 700; color: var(--note-bar); }
.admonition.attention { border-left-color: var(--warn-bar); background: var(--warn-bg); }
.admonition.attention .admonition-title { color: var(--warn-bar); }
.admonition.tip { border-left-color: var(--tip-bar); background: var(--tip-bg); }
.admonition.tip .admonition-title { color: var(--tip-bar); }

/* math-ish inline formulas */
.math {
  display: block;
  margin: 0 0 1rem;
  padding: 10px 16px;
  overflow-x: auto;
  font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif;
  font-size: 1.05rem;
  text-align: center;
  white-space: nowrap;
}

/* diagram */
.figure { margin: 0.5rem 0 1.5rem; overflow-x: auto; }
.figure svg { display: block; width: 100%; min-width: 640px; height: auto; }
.figure figcaption { margin-top: 0.5rem; font-size: 14px; color: var(--muted); text-align: center; }
.d-box { fill: var(--diagram-fill); stroke: var(--diagram-stroke); stroke-width: 1.4; }
.d-box.hl { stroke: var(--accent); stroke-width: 2; }
.d-dashed { stroke-dasharray: 5 4; }
.d-line { fill: none; stroke: var(--diagram-stroke); stroke-width: 1.4; }
.d-head { fill: var(--diagram-stroke); }
.d-text { fill: var(--text); font-size: 13px; }
.d-label { fill: var(--muted); font-size: 12px; }

/* cards on the overview */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0 0 1.5rem; }
.card {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.card strong { display: block; color: var(--accent); margin-bottom: 2px; }
.card span { font-size: 14px; color: var(--muted); }

/* prev / next */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  max-width: 820px;
  margin: 3rem auto 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.pager a {
  display: block;
  max-width: 48%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a small { display: block; color: var(--muted); font-size: 12.5px; }
.pager a.next { margin-left: auto; text-align: right; }

.doc-footer {
  max-width: 820px;
  margin: 2rem auto 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- responsive ---------- */

@media (max-width: 1200px) {
  .toc { display: none; }
  .main { margin-right: 0; }
}

@media (max-width: 960px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 24px rgba(0, 0, 0, 0.2); }
  body.nav-open .scrim {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 15;
  }
  .main { margin-left: 0; padding: 28px 16px 48px; }
  .topbar .toplinks a.hide-sm { display: none; }
}

@media (max-width: 600px) {
  .doc h1 { font-size: 1.7rem; }
  .cards { grid-template-columns: 1fr; }
  .topbar .brand span { display: none; }
  .pager { flex-direction: column; }
  .pager a { max-width: 100%; }
}
