:root {
  --bg: #fbfaf6; --fg: #2b2b2b; --muted: #6b6b6b; --link: #3a4fb8; --accent: #c00000;
  --side: #f2f0e8; --border: #dcd8cb; --codebg: #efece3; --codefg: #2b2b2b; --inline: #b00000;
  --hl: #e4e8fb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b; --fg: #dcdcdc; --muted: #9a9a9a; --link: #8fa4ff; --accent: #ff6b6b;
    --side: #1e2024; --border: #33363c; --codebg: #23252a; --codefg: #e2e2e2; --inline: #ff8c8c;
    --hl: #2a3050;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 70px; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Cantarell, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  height: 54px; padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); font-weight: 700; white-space: nowrap; }
.brand span { color: var(--accent); font-size: 1.25em; }
.brand em { font-style: normal; color: var(--accent); font-weight: 600; }
.brand:hover { text-decoration: none; }
#menu { display: none; background: none; border: 1px solid var(--border); color: var(--fg);
  border-radius: 6px; font-size: 20px; line-height: 1; padding: 6px 10px; cursor: pointer; }
.search { position: relative; margin-left: auto; width: min(320px, 45vw); }
.search input { width: 100%; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--side); color: var(--fg); font: inherit; font-size: 14px; }
#results { position: absolute; right: 0; top: 40px; width: min(460px, 92vw); max-height: 70vh; overflow: auto;
  margin: 0; padding: 4px; list-style: none; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
#results li a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--fg); font-size: 14px; line-height: 1.35; }
#results li a small { display: block; color: var(--muted); }
#results li a:hover, #results li a.sel { background: var(--hl); text-decoration: none; }
#results .none { padding: 8px 10px; color: var(--muted); font-size: 14px; }

.layout { display: flex; align-items: flex-start; max-width: 1400px; margin: 0 auto; }
#sidebar { position: sticky; top: 54px; flex: 0 0 280px; height: calc(100vh - 54px); overflow-y: auto;
  padding: 14px 8px 40px 16px; border-right: 1px solid var(--border); background: var(--side); font-size: 14.5px; line-height: 1.4; }
#sidebar ul { list-style: none; margin: 0; padding: 0; }
#sidebar ul ul { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 6px; }
#sidebar li { margin: 1px 0; }
#sidebar summary { cursor: pointer; padding: 3px 4px; border-radius: 5px; }
#sidebar summary a, #sidebar li > a, .nolink { display: inline-block; padding: 1px 4px; border-radius: 5px; }
#sidebar summary > .nolink { font-weight: 600; }
#sidebar a { color: var(--fg); }
#sidebar a:hover { color: var(--link); text-decoration: none; }
#sidebar a.cur { background: var(--hl); color: var(--link); font-weight: 600; }
.nolink { color: var(--muted); }
.tbd::after { content: " (TBD)"; }

main { flex: 1 1 auto; min-width: 0; padding: 24px 28px 60px; }
.doc { max-width: 760px; margin: 0 auto; }
.doc h1 { font-size: 2em; line-height: 1.2; margin: .2em 0 .6em; }
.doc h2 { font-size: 1.5em; margin: 1.8em 0 .5em; padding-top: .3em; border-top: 1px solid var(--border); }
.doc h3 { font-size: 1.2em; margin: 1.5em 0 .4em; }
.doc h4 { font-size: 1.05em; margin: 1.3em 0 .3em; }
.doc h2, .doc h3, .doc h4 { line-height: 1.3; }
.anchor { margin-left: .4em; opacity: 0; font-weight: 400; color: var(--muted); }
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor, .anchor:focus { opacity: 1; }
.text p, .text li { overflow-wrap: break-word; }
.text img { max-width: 100%; height: auto; }

pre { tab-size: 4; font: 14px/1.5 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  background: var(--codebg); color: var(--codefg); padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; overflow-x: auto; }
code, .pre { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .92em; color: var(--inline); }
pre .pre, pre code { color: inherit; font-size: inherit; }
table { border-collapse: collapse; display: block; overflow-x: auto; margin: 1em 0; }
th, td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; vertical-align: top; }
th { background: var(--side); }
dl { margin: 1em 0; }
dt { float: left; clear: left; width: 8em; font-weight: 700; }
dd { margin: 0 0 0 9em; padding: 0 0 .5em; }
blockquote { margin: 1em 0; padding: .2em 1em; border-left: 3px solid var(--border); color: var(--muted); }

.toc { margin: 0 0 1.2em; border: 1px solid var(--border); border-radius: 8px; background: var(--side); font-size: 14px; }
.toc summary { cursor: pointer; padding: 8px 12px; font-weight: 600; }
.toc ul { list-style: none; margin: 0; padding: 0 12px 10px; }
.toc li.l3 { margin-left: 14px; }
.toc a { color: var(--fg); }
.toc a:hover, .toc a.active { color: var(--link); }
.toc a.active { font-weight: 600; }

.pn { display: flex; justify-content: space-between; gap: 12px; margin-top: 3em; padding-top: 1.2em; border-top: 1px solid var(--border); }
.pn a { display: block; max-width: 48%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; color: var(--link); }
.pn a:hover { background: var(--hl); text-decoration: none; }
.pn small { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.pn .next { text-align: right; margin-left: auto; }

/* wide: on-this-page list on the right */
@media (min-width: 1240px) {
  .doc { position: relative; max-width: none; padding-right: 250px; }
  .doc > .text, .doc > .pn, .doc > h1 { max-width: 760px; }
  .toc { position: fixed; top: 80px; width: 220px; max-height: calc(100vh - 110px); overflow-y: auto;
    right: max(16px, calc((100vw - 1400px) / 2 + 16px)); }
}
@media (min-width: 1240px) {
  .toc summary { pointer-events: none; } .toc summary::marker, .toc summary::-webkit-details-marker { content: ""; display: none; } }

/* narrow: sidebar behind the menu button */
@media (max-width: 880px) {
  #menu { display: block; }
  .brand em { display: none; }
  #sidebar { position: fixed; top: 54px; left: 0; bottom: 0; z-index: 15; width: min(320px, 86vw); height: auto;
    transform: translateX(-102%); transition: transform .2s; box-shadow: 4px 0 18px rgba(0,0,0,.25); }
  body.nav-open #sidebar { transform: none; }
  main { padding: 18px 16px 48px; }
  dt { float: none; width: auto; } dd { margin-left: 1.2em; }
}
