/* Documentation pages (docs/), on top of styles.css. */

.docs { --side-w: 280px; --onpage-w: 220px; background: var(--bg); }
.docs .subnav { background: color-mix(in srgb, var(--bg) 85%, transparent); }
.brand-sub {
  font-size: 13px; font-weight: 600; color: var(--accent);
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px;
}

.docs-layout {
  max-width: 1440px; margin: 0 auto;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--onpage-w);
  gap: 0 40px;
  padding: 0 var(--gutter);
  align-items: start;
}

/* ------------------------------------------------------------ sidebar */
.docs-side {
  position: sticky; top: var(--nav-h);
  max-height: calc(100vh - var(--nav-h));
  max-height: calc(100dvh - var(--nav-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 8px 40px 0;
  border-right: 1px solid var(--line);
}
.side-toggle { display: none; }
.toc, .toc ol { list-style: none; margin: 0; padding: 0; }
.toc ol { padding-left: 14px; border-left: 1px solid var(--line); margin: 2px 0 4px 10px; }
.toc a {
  display: block; padding: 5px 10px; border-radius: 8px;
  color: var(--text-2); font-size: 14px; line-height: 1.35;
}
.toc a:hover { color: var(--text); background: var(--bg-alt); text-decoration: none; }
.toc a[aria-current="page"] { color: var(--accent-hover); background: var(--accent-soft); font-weight: 600; }
.toc-part {
  margin: 22px 0 6px; padding: 0 10px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3);
}
.toc-sep { height: 1px; background: var(--line); margin: 14px 10px; }
.toc-draft { display: block; padding: 5px 10px; color: var(--text-3); font-size: 14px; }

/* ------------------------------------------------------------ search */
.search { position: relative; margin: 0 0 8px; }
.search input {
  width: 100%; min-height: 40px; padding: 8px 12px 8px 34px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg-alt) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='8.5' cy='8.5' r='5.5' fill='none' stroke='%23888' stroke-width='1.8'/%3E%3Cpath d='M13 13l4 4' stroke='%23888' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat 10px center / 16px;
  border: 1px solid var(--line); border-radius: 10px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-results {
  margin-top: 8px; max-height: 60vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.search-results a {
  display: block; padding: 10px 12px; border-bottom: 1px solid var(--line);
  color: var(--text); font-size: 14px;
}
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover, .search-results a:focus { background: var(--bg-alt); text-decoration: none; }
.sr-page { display: block; font-size: 12px; color: var(--text-3); }
.sr-head { display: block; font-weight: 600; }
.sr-snip { display: block; color: var(--text-2); font-size: 13px; margin-top: 2px; }
.sr-snip mark { background: color-mix(in srgb, var(--ph2) 35%, transparent); color: inherit; border-radius: 3px; }
.sr-none { padding: 10px 12px; font-size: 14px; color: var(--text-3); }

/* ------------------------------------------------------------ content */
.docs-main { min-width: 0; padding: 40px 0 80px; }
.doc { font-size: 16.5px; line-height: 1.7; }
.doc > :first-child { margin-top: 0; }
.doc h1 { font-size: clamp(32px, 5vw, 46px); font-weight: 700; letter-spacing: -0.035em; line-height: 1.1; margin: 0 0 24px; }
.doc h2 { font-size: 28px; font-weight: 700; letter-spacing: -0.025em; margin: 48px 0 14px; padding-top: 8px; line-height: 1.2; }
.doc h3 { font-size: 21px; font-weight: 700; margin: 34px 0 10px; line-height: 1.3; }
.doc h4, .doc h5, .doc h6 { font-size: 17px; font-weight: 700; margin: 26px 0 8px; }
.doc h1, .doc h2, .doc h3, .doc h4 { scroll-margin-top: calc(var(--nav-h) + 16px); overflow-wrap: anywhere; }
.hanchor { margin-left: 8px; color: var(--text-3); opacity: 0; font-weight: 500; text-decoration: none; }
.doc :is(h1, h2, h3, h4, h5, h6):hover .hanchor, .hanchor:focus { opacity: 1; }
.doc p, .doc ul, .doc ol, .doc blockquote, .doc pre, .doc .table-wrap { margin: 0 0 18px; }
.doc ul, .doc ol { padding-left: 26px; }
.doc li { margin: 4px 0; }
.doc li > p { margin: 0 0 6px; }
.doc a { overflow-wrap: anywhere; }
.doc img { max-width: 100%; border-radius: 12px; border: 1px solid var(--line); margin: 8px 0; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 40px 0; }
.doc blockquote {
  padding: 12px 18px; border-left: 4px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 12px 12px 0; color: var(--text);
}
.doc blockquote > :last-child { margin-bottom: 0; }
.doc code { font-size: .86em; overflow-wrap: anywhere; }
.doc pre {
  position: relative;
  background: var(--bg-alt); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; overflow-x: auto;
  font: 13.5px/1.6 var(--mono);
}
.doc pre code { background: none; padding: 0; font-size: inherit; overflow-wrap: normal; white-space: pre; }
.doc pre code.hljs { background: none; padding: 0; overflow-x: visible; }
/* Code inside links: the darker accent keeps AA contrast on its tint. */
.doc a code, .toc a code { color: var(--accent-hover); }
.copy-code {
  position: absolute; top: 8px; right: 8px;
  font: 500 12px var(--font); color: var(--text-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 9px; cursor: pointer; opacity: 0;
  transition: opacity 200ms ease, transform 160ms var(--ease-out);
}
.copy-code:active { transform: scale(0.96); }
.doc pre:hover .copy-code, .copy-code:focus { opacity: 1; }
@media (hover: none) { .copy-code { opacity: 1; } }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.doc table { border-collapse: collapse; width: 100%; font-size: 14.5px; line-height: 1.5; }
.doc th, .doc td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.doc th { background: var(--bg-alt); font-weight: 600; white-space: nowrap; }
.doc tr:last-child td { border-bottom: 0; }
.doc td code { white-space: nowrap; overflow-wrap: normal; }

.doc .katex { font-size: 1.08em; }
.doc .katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; margin: 10px 0 18px; }

/* ------------------------------------------------------------ pager */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--line);
}
.pager a {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--text);
}
.pager a { transition: transform 160ms var(--ease-out); }
.pager a:active { transform: scale(0.98); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager-next { text-align: right; grid-column: 2; }
.pager-k { font-size: 12px; color: var(--text-3); }
.pager-t { font-weight: 600; color: var(--accent); }
.pager-prev .pager-t::before { content: "‹ "; }
.pager-next .pager-t::after { content: " ›"; }
.doc-src { margin: 24px 0 0; font-size: 13px; }

/* ------------------------------------------------------------ on this page */
.onpage {
  position: sticky; top: var(--nav-h);
  max-height: calc(100vh - var(--nav-h)); overflow-y: auto;
  padding: 40px 0; font-size: 13px;
}
.onpage-t { margin: 0 0 8px; font-weight: 700; color: var(--text); }
.onpage ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.onpage a { display: block; padding: 4px 0 4px 12px; color: var(--text-2); line-height: 1.35; margin-left: -1px; border-left: 2px solid transparent; }
.onpage .l3 a { padding-left: 24px; }
.onpage a:hover { color: var(--text); text-decoration: none; }
.onpage a.active { color: var(--accent); border-left-color: var(--accent); }

.docs .footer { padding: 28px 0; }
.docs .footer-fine { margin: 0; }

/* ------------------------------------------------------------ narrow */
@media (max-width: 1200px) {
  .docs-layout { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .onpage { display: none; }
}
@media (max-width: 860px) {
  .docs-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .docs-side {
    position: sticky; top: var(--nav-h); z-index: 20;
    max-height: none; overflow: visible;
    padding: 0; border-right: 0;
    margin: 0 calc(-1 * var(--gutter));
    background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .side-toggle {
    display: flex; align-items: center; gap: 8px; width: 100%;
    min-height: 44px; padding: 0 var(--gutter);
    font: 600 14px var(--font); color: var(--text); background: none; border: 0; cursor: pointer;
  }
  .side-toggle::after {
    content: ""; margin-left: auto; width: 8px; height: 8px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: rotate(45deg); transition: transform 200ms var(--ease-out);
  }
  .side-toggle[aria-expanded="true"]::after { transform: rotate(-135deg); }
  .docs-side-inner {
    display: none;
    max-height: calc(100vh - var(--nav-h) - 44px); overflow-y: auto; overscroll-behavior: contain;
    padding: 4px var(--gutter) 24px;
  }
  .docs-side-inner.open { display: block; }
  @media (prefers-reduced-motion: no-preference) {
    .docs-side-inner.open { animation: menu-in 180ms var(--ease-out); }
  }
  .docs-main { padding-top: 24px; }
  .doc { font-size: 16px; }
  .doc h2 { font-size: 24px; }
  .pager { grid-template-columns: 1fr; }
  .pager-next { grid-column: 1; }
}
@media (max-width: 1000px) {
  .docs .subnav .brand-sub { display: none; }
}

/* keep wide tables and KaTeX's hidden MathML inside their boxes on phones */
.table-wrap { position: relative; }
.docs-main { overflow-x: clip; }
.doc p .katex, .doc li .katex, .doc td .katex { white-space: normal; }

/* highlight.js colours darkened (light) / lightened (dark) to WCAG AA on the code background. */
@media (prefers-color-scheme: light) {
  .doc .hljs-comment, .doc .hljs-quote { color: #545b63; }
  .doc .hljs-keyword, .doc .hljs-doctag, .doc .hljs-template-tag, .doc .hljs-template-variable,
  .doc .hljs-type, .doc .hljs-variable.language_, .doc .hljs-deletion { color: #b0202e; }
  .doc .hljs-built_in, .doc .hljs-symbol { color: #9a4a00; }
  .doc .hljs-meta, .doc .hljs-bullet { color: #6b5600; }
  .doc .hljs-name, .doc .hljs-selector-tag, .doc .hljs-selector-pseudo, .doc .hljs-addition { color: #1a6b2e; }
}
@media (prefers-color-scheme: dark) {
  .doc .hljs-comment, .doc .hljs-quote { color: #a0aab4; }
  .doc .hljs-section { color: #6ea8ff; }
}
.doc .table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.doc blockquote a { color: var(--accent-hover); }
