/* OpenProgram Docs: the one shared style foundation.
   Pages add content only. A new look is a new token here, never page CSS. */

:root {
  color-scheme: light;

  /* colour: neutrals plus one accent; --no is reserved for refusals */
  --bg: #ffffff;
  --panel: #f4f6fa;
  --tx: #1d2330;
  --soft: #5d6675;
  --line: #cfd5df;
  --hair: #e4e8ef;
  --acc: #2f5fd0;
  --tint: #eaf0fd;
  --no: #b3392f;
  --no-tint: #fbeceb;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);

  /* type: one family, four sizes */
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-title: 1.875rem;
  --fs-head: 1.25rem;
  --fs-body: 1rem;
  --fs-note: 0.875rem;
  --w-normal: 400;
  --w-strong: 600;

  /* space: one scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;

  --radius: 6px;
  --measure: 40em;   /* about 40 Chinese characters, 75 Latin */
  --doc-width: 852px; /* figures are drawn 1:1 at this width */
  --quick: 150ms ease;

  /* names used by the site chrome and pages not yet moved to HTML */
  --bg-side: var(--panel);
  --bg-code: var(--panel);
  --bg-card: var(--bg);
  --tx-soft: var(--soft);
  --tx-faint: var(--soft);
  --acc-soft: var(--tint);
  --bd: var(--line);
  --bd-soft: var(--hair);
  --sel: var(--tint);
  --sans: var(--font);

  --nav-w: 270px;
  --toc-w: 256px;
  --maxw:  820px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15181e;
    --panel: #1d2128;
    --tx: #e4e7ec;
    --soft: #a2abb9;
    --line: #3a414d;
    --hair: #2a2f38;
    --acc: #86a8f5;
    --tint: #1f2a42;
    --no: #ec8a80;
    --no-tint: #3a2124;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15181e;
  --panel: #1d2128;
  --tx: #e4e7ec;
  --soft: #a2abb9;
  --line: #3a414d;
  --hair: #2a2f38;
  --acc: #86a8f5;
  --tint: #1f2a42;
  --no: #ec8a80;
  --no-tint: #3a2124;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font: var(--fs-body)/1.75 var(--font);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--sel); }

.skip {
  position: absolute; left: -999px; top: var(--s2); z-index: 300;
  background: var(--bg); padding: var(--s1) var(--s3);
}
.skip:focus { left: var(--s2); }

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

/* ── top bar ── */
header.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 100;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--bd);
}
.topbar .brand {
  font-weight: 700; font-size: 15px; letter-spacing: .01em;
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
.topbar .brand .mark { width: 20px; height: 20px; border-radius: 5px; display: block; }
.topbar .spacer { flex: 1; }
.topbar .search-trigger {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--bg-side); border: 1px solid var(--bd); color: var(--tx-faint);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; min-width: 180px;
}
.topbar .search-trigger kbd {
  margin-left: auto; font: 11px var(--mono); background: var(--bg);
  border: 1px solid var(--bd); border-radius: 4px; padding: 1px 5px;
}
.topbar button.icon {
  background: none; border: 1px solid var(--bd); color: var(--tx-soft);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}
.topbar button.icon:hover { background: var(--bg-side); color: var(--tx); }
/* hamburger shows on all widths: wide = collapse the sidebar, narrow = drawer */

/* Theme icon shows the selected preference, including automatic system mode. */
#theme-toggle svg { display: none; }
html[data-theme-mode="system"] #theme-toggle .ic-system,
html[data-theme-mode="light"] #theme-toggle .ic-sun,
html[data-theme-mode="dark"] #theme-toggle .ic-moon { display: block; }

/* language dropdown */
.lang-wrap, .theme-wrap { position: relative; }
.topbar button.lang-trigger {
  width: auto; padding: 0 10px; gap: 6px;
  font-size: 12.5px; font-weight: 600; font-family: var(--sans);
}
.lang-trigger .chev { transition: transform .15s ease; }
.lang-wrap.open .lang-trigger .chev { transform: rotate(180deg); }
.lang-menu, .theme-menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 160px;
  background: var(--bg-card); border: 1px solid var(--bd); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; display: none; z-index: 200;
}
.lang-wrap.open .lang-menu, .theme-wrap.open .theme-menu { display: block; }
.lang-opt, .theme-opt {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  gap: 18px; padding: 7px 10px; border: none; background: none; cursor: pointer;
  color: var(--tx); font: 600 13.5px var(--sans); border-radius: 7px; text-align: left;
}
.lang-opt:hover, .theme-opt:hover { background: var(--bd-soft); }
.lang-opt .check, .theme-opt .check { visibility: hidden; color: var(--acc); flex: none; }
.lang-opt.active, .theme-opt.active { color: var(--acc); }
.lang-opt.active .check, .theme-opt.active .check { visibility: visible; }

/* ── tabbar (top-level sections, below the topbar) ── */
nav.tabbar {
  position: fixed; top: 56px; left: 0; right: 0; height: 40px; z-index: 99;
  display: flex; align-items: stretch; gap: 2px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--bd);
  overflow-x: auto; white-space: nowrap; scrollbar-width: none;
}
nav.tabbar::-webkit-scrollbar { display: none; }
.tablink {
  color: var(--tx-soft); font-size: 13.5px; font-weight: 500;
  padding: 0 12px; display: inline-flex; align-items: center;
  border-bottom: 2px solid transparent;
}
.tablink:hover { color: var(--tx); }
/* active state must not change font-weight — bold text is wider and would
   shift the whole row on every tab switch */
.tablink.active { color: var(--acc); border-bottom-color: var(--acc); }

/* ── layout ── */
.layout { display: flex; padding-top: 96px; min-width: 0; }
.layout > *, main.content, article, article > * { min-width: 0; }

/* wide-screen sidebar collapse (toggled by the hamburger) */
html[data-nav-collapsed="1"] nav.sidebar { transform: translateX(-100%); }
html[data-nav-collapsed="1"] main.content { margin-left: 0; }

/* left nav */
nav.sidebar {
  position: fixed; top: 96px; bottom: 0; left: 0; width: var(--nav-w);
  overflow-y: auto; padding: 20px 14px 60px; border-right: 1px solid var(--bd);
  background: var(--bg-side); transition: transform .2s ease;
}
nav.sidebar .nav-filter {
  width: 100%; margin-bottom: 12px; padding: 7px 11px; font-size: 13px;
  background: var(--bg); border: 1px solid var(--bd); border-radius: 8px;
  color: var(--tx); outline: none;
}
nav.sidebar .nav-filter:focus { border-color: var(--acc); }
nav.sidebar .nav-filter::placeholder { color: var(--tx-faint); }
nav.sidebar details.group { margin: 1px 0; }
nav.sidebar summary.group-title {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; letter-spacing: 0;
  color: var(--tx); padding: 7px 8px; border-radius: 7px; margin: 1px 0;
}
nav.sidebar summary.group-title::-webkit-details-marker { display: none; }
nav.sidebar summary.group-title::before {
  content: "›"; font-size: 17px; line-height: 1; color: var(--tx-faint);
  transition: transform .15s; display: inline-block; width: 12px; text-align: center;
}
nav.sidebar details[open] > summary.group-title::before { transform: rotate(90deg); }
nav.sidebar summary.group-title:hover { background: var(--bd-soft); color: var(--tx); }
/* nested subgroup headers: a touch lighter than top-level */
nav.sidebar details.group details.group > summary.group-title {
  font-size: 13px; font-weight: 550; color: var(--tx-soft);
}
nav.sidebar .group-body { padding-left: 8px; margin-left: 9px; border-left: 1px solid var(--bd-soft); }
nav.sidebar details.group details.group { margin-left: 2px; }
nav.sidebar a.navlink {
  display: block; padding: 6px 9px 6px 22px; border-radius: 7px; font-size: 14px;
  color: var(--tx-soft); line-height: 1.45;
}
nav.sidebar a.navlink:hover { background: var(--bd-soft); color: var(--tx); text-decoration: none; }
nav.sidebar a.navlink.active { background: var(--acc-soft); color: var(--acc); font-weight: 600; }

/* main column */
main.content {
  margin-left: var(--nav-w); margin-right: var(--toc-w);
  flex: 1; min-width: 0; display: flex; justify-content: center;
  padding: 38px 48px 120px;
  transition: margin-left .2s ease;
}
article { width: 100%; max-width: var(--maxw); }

.layout.no-toc main.content { margin-right: 0; }
.layout.no-toc aside.toc { display: none; }

/* right toc */
aside.toc {
  position: fixed; top: 96px; right: 0; width: var(--toc-w);
  max-height: calc(100vh - 96px - 48px);
  overflow-y: auto; padding: 38px 20px 24px; font-size: 13px;
}
aside.toc .toc-title {
  font-size: 12px; font-weight: 700;
  letter-spacing: .02em; color: var(--tx-soft); margin-bottom: 12px;
}
/* Each heading owns its nested siblings and their guide line. */
aside.toc .toc-list { list-style: none; margin: 0; padding: 0; }
aside.toc .toc-list .toc-list { margin-left: 14px; }
aside.toc a {
  display: block; position: relative; line-height: 1.45;
  padding: 6px 0 6px 16px; font-size: 13.5px; font-weight: 550;
  color: var(--tx-soft); overflow-wrap: anywhere;
}
aside.toc .toc-list .toc-list a {
  padding-top: 4px; padding-bottom: 4px; font-size: 12.5px;
  font-weight: 400; color: var(--tx-faint);
}
aside.toc a:hover { color: var(--tx); text-decoration: none; }
aside.toc a.active, aside.toc a.in-path { color: var(--tx); font-weight: 550; }

/* ── breadcrumb ── */
.breadcrumb { font-size: 13px; color: var(--tx-faint); margin-bottom: 18px; }
.breadcrumb .bc-sep { margin: 0 6px; opacity: .6; }
.breadcrumb .bc-current { color: var(--tx-soft); }

/* ── last-updated ── */
.page-updated { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--bd);
  font-size: 13px; color: var(--tx-faint); }

/* ── prev / next ── */
.prevnext { display: flex; gap: 14px; margin-top: 22px; }
.prevnext .pn-link {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px; border: 1px solid var(--bd); border-radius: 10px;
  color: var(--tx); transition: border-color .15s, background .15s;
}
.prevnext .pn-link:hover { border-color: var(--acc); background: var(--bg-side); text-decoration: none; }
.prevnext .pn-next { text-align: right; }
.prevnext .pn-dir { font-size: 12px; color: var(--tx-faint); }
.prevnext .pn-title { font-weight: 600; font-size: 14px; color: var(--acc); }

/* ── article typography ── */
article:not(.doc) h1 { font-size: 32px; line-height: 1.22; margin: 0 0 4px; letter-spacing: -.022em; font-weight: 720; }
article:not(.doc) h2 {
  font-size: 22px; margin: 44px 0 14px; padding-bottom: 8px;
  border-bottom: 1px solid var(--bd); letter-spacing: -.015em;
}
article:not(.doc) h3 { font-size: 17.5px; margin: 30px 0 10px; letter-spacing: -.008em; }
article:not(.doc) h4 { font-size: 15.5px; margin: 22px 0 8px; color: var(--tx-soft); }
article:not(.doc) h2, article:not(.doc) h3, article:not(.doc) h4 { font-weight: 640; }
article :is(h1, h2, h3, h4, h5, h6) { scroll-margin-top: 116px; }
article .header-anchor {
  opacity: 0; margin-left: 8px; color: var(--tx-faint); font-weight: 400; text-decoration: none;
}
article h1:hover .header-anchor, article h2:hover .header-anchor,
article h3:hover .header-anchor { opacity: 1; }

article:not(.doc) p { margin: 12px 0; }
article:not(.doc) ul, article:not(.doc) ol { margin: 12px 0; padding-left: 26px; }
article:not(.doc) li { margin: 5px 0; }
article:not(.doc) li::marker { color: var(--tx-faint); }
article p, article li, article a { overflow-wrap: anywhere; }
article td, article th { overflow-wrap: break-word; }
article td code, article th code { overflow-wrap: anywhere; }

article:not(.doc) code {
  font: 13px var(--mono); background: var(--bg-code); color: var(--acc);
  padding: 2px 6px; border-radius: 5px; border: 1px solid var(--bd-soft); overflow-wrap: anywhere;
}
article:not(.doc) pre {
  background: var(--bg-code); border: 1px solid var(--bd); border-radius: 10px;
  padding: 16px 18px; max-width: 100%; overflow-x: auto; margin: 16px 0; line-height: 1.6;
}
article:not(.doc) pre code { background: none; border: none; color: var(--tx); padding: 0; font-size: 13px; }
article pre:focus-visible, article .doc-scroll:focus-visible, article .table-wrap:focus-visible,
article .viz-frame:focus-visible { outline: 2px solid var(--acc); outline-offset: 3px; }

/* code-block copy button */
article:not(.doc) pre { position: relative; }
article pre .copy-btn {
  position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity .15s;
  background: var(--bg-card); border: 1px solid var(--bd); color: var(--tx-soft);
  font-size: 12px; padding: 3px 9px; border-radius: 6px; cursor: pointer;
}
article pre:hover .copy-btn { opacity: 1; }
article pre .copy-btn:hover { color: var(--tx); border-color: var(--acc); }
article pre .copy-btn.copied { color: var(--acc); border-color: var(--acc); }

/* callouts */
.callout { margin: 16px 0; border-radius: var(--radius); background: var(--cl-bg); padding: 12px 16px; }
.callout-head {
  display: flex; align-items: center; gap: 7px;
  font-weight: var(--w-strong); font-size: var(--fs-note); color: var(--cl-accent); margin-bottom: 4px;
}
.callout-icon { display: inline-flex; align-items: center; }
.callout-body p { margin: 4px 0; }
.callout-body p:last-child { margin-bottom: 0; }
.callout-note, .callout-tip { --cl-accent: var(--soft); --cl-bg: var(--panel); }
.callout-important, .callout-warning { --cl-accent: var(--acc); --cl-bg: var(--tint); }
.callout-caution { --cl-accent: var(--no); --cl-bg: var(--no-tint); }

article:not(.doc) blockquote {
  margin: 16px 0; padding: 10px 18px; color: var(--tx-soft);
  background: var(--bg-side); border-radius: var(--radius);
}
article:not(.doc) blockquote p { margin: 4px 0; }

article:not(.doc) table { border-collapse: collapse; width: 100%; margin: 18px 0; font-size: 14px; }
article .doc-scroll, article .table-wrap {
  max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain;
}
article:not(.doc) th, article:not(.doc) td { border: 1px solid var(--bd); padding: 8px 12px; text-align: left; vertical-align: top; }
article:not(.doc) th { background: var(--bg-side); font-weight: 650; }
article:not(.doc) tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-side) 50%, transparent); }

article:not(.doc) hr { border: none; border-top: 1px solid var(--bd); margin: 32px 0; }
article:not(.doc) img { max-width: 100%; border-radius: 8px; }
article:not(.doc) strong { color: var(--tx); font-weight: 650; }

/* page meta (status line right under h1) */
.page-meta { color: var(--tx-faint); font-size: 13.5px; margin-bottom: 24px; }
.page-meta kbd {
  font: 11px var(--mono); background: var(--bg-side); border: 1px solid var(--bd);
  border-radius: 4px; padding: 1px 5px;
}

/* landing page card grid */
/* landing page uses the full content width, not the 820px reading column */
article:has(.home-grid) { max-width: none; }
.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px; margin-top: 28px;
}
.home-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px 18px 16px; border: 1px solid var(--bd); border-radius: 12px;
  background: var(--bg-card); transition: border-color .15s, transform .15s;
}
.home-card:hover { border-color: var(--acc); transform: translateY(-2px); text-decoration: none; }
.home-card .hc-title { font-weight: 650; font-size: 15px; color: var(--tx); }
.home-card .hc-count { font-size: 12px; color: var(--tx-faint); font-family: var(--mono); }

/* embedded visualization (hand-written html via isolated iframe) */
.viz-frame {
  width: 100%; height: calc(100vh - 56px - 76px); min-height: 600px; max-width: 100%; overflow: auto;
  border: 1px solid var(--bd); border-radius: 12px; background: var(--bg-card);
}
article:has(.viz-frame) { max-width: none; }

/* ── content fullscreen ──
   CSS overlay rather than the Fullscreen API: the shell keeps its own theme,
   scroll and SPA navigation, an iframe needs no allowfullscreen, and ESC stays
   ours. Sits in the content area's top-right gutter, never over the text. */
.fs-toggle {
  position: fixed; top: 104px; right: calc(var(--toc-w) + 14px); z-index: 95;
  width: 30px; height: 30px; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-card); border: 1px solid var(--bd); color: var(--tx-faint);
  border-radius: 8px; opacity: .6;
  transition: opacity .15s, color .15s, border-color .15s;
}
.fs-toggle:hover { opacity: 1; color: var(--tx); border-color: var(--acc); }
.fs-toggle .ic-collapse { display: none; }
.layout.no-toc .fs-toggle { right: 14px; }

html[data-fs="1"] .fs-toggle { top: 12px; right: 14px; z-index: 160; opacity: 1; box-shadow: var(--shadow); }
html[data-fs="1"] .fs-toggle .ic-expand { display: none; }
html[data-fs="1"] .fs-toggle .ic-collapse { display: inline-flex; }

html[data-fs="1"] body { overflow: hidden; }
html[data-fs="1"] header.topbar,
html[data-fs="1"] nav.tabbar,
html[data-fs="1"] nav.sidebar,
html[data-fs="1"] aside.toc,
html[data-fs="1"] .breadcrumb,
html[data-fs="1"] .page-updated,
html[data-fs="1"] .prevnext { display: none; }
html[data-fs="1"] main.content {
  position: fixed; inset: 0; z-index: 150; margin: 0; overflow-y: auto;
  background: var(--bg); padding: 16px 24px 24px;
}
html[data-fs="1"] article { max-width: none; }
/* the h1 is the one block level with the floating exit button — keep it clear */
html[data-fs="1"] article > h1 { padding-right: 40px; }
html[data-fs="1"] .viz-frame { height: calc(100vh - 40px); }

/* ── search overlay ── */
.search-overlay {
  position: fixed; inset: 0; z-index: 200; display: none;
  background: rgba(0,0,0,.4); backdrop-filter: blur(2px);
  align-items: flex-start; justify-content: center; padding-top: 12vh;
}
.search-overlay.open { display: flex; }
.search-box {
  width: min(620px, 92vw); background: var(--bg-card); border: 1px solid var(--bd);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.search-box input {
  width: 100%; border: none; outline: none; background: none; color: var(--tx);
  font: 16px var(--sans); padding: 18px 20px; border-bottom: 1px solid var(--bd);
}
.search-results { max-height: 56vh; overflow-y: auto; }
.search-results a {
  display: block; padding: 11px 20px; border-bottom: 1px solid var(--bd-soft); color: var(--tx);
}
.search-results a:hover, .search-results a.sel { background: var(--bg-side); text-decoration: none; }
.search-results .r-title { font-weight: 600; font-size: 14px; }
.search-results .r-path { font: 11px var(--mono); color: var(--tx-faint); margin-top: 2px; }
.search-results .r-snippet { font-size: 12.5px; color: var(--tx-soft); margin-top: 3px; }
.search-results mark { background: var(--sel); color: var(--tx); border-radius: 3px; padding: 0 2px; }
.search-empty { padding: 24px 20px; color: var(--tx-faint); text-align: center; }

/* ── responsive ── */
.scrim { display: none; }
@media (max-width: 1100px) {
  aside.toc { display: none; }
  main.content { margin-right: 0; }
  .fs-toggle { right: 14px; }
}
@media (max-width: 860px) {
  .topbar button.hamburger { display: inline-flex; }
  .topbar .search-trigger { min-width: 0; }
  .topbar .search-trigger .label { display: none; }
  nav.sidebar {
    transform: translateX(-100%); transition: transform .22s ease; z-index: 90;
    box-shadow: var(--shadow);
  }
  nav.sidebar.open { transform: translateX(0); }
  /* padding-top clears the fullscreen button (ends at 100+30=130; chrome ends at 96) */
  main.content { margin-left: 0; padding: 38px 22px 100px; }
  .fs-toggle { top: 100px; right: 10px; }
  .scrim.show { display: block; position: fixed; inset: 56px 0 0; background: rgba(0,0,0,.35); z-index: 80; }
}

/* home page: no sidebar, content centered full-width */
.layout.no-side main.content { margin-left: 0; }

/* ── flat sidebar sections (OpenClaw-style, non-collapsible) ── */
.nav-sec { margin: 20px 0 4px; }
.nav-sec:first-of-type { margin-top: 8px; }
.nav-sec-title {
  font-size: 11.5px; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--tx-faint);
  padding: 0 9px; margin-bottom: 4px;
}

/* Reader navigation, informed by Rare UI's grouped navigation and progress.
   Implemented locally; the static reader has no component-library runtime. */
nav.sidebar { background: var(--bg); padding: 24px 18px 72px; }
.nav-sec { position: relative; margin-top: 26px; }
.nav-sec-title { font-size: 12px; letter-spacing: 0; text-transform: none; color: var(--tx); margin-bottom: 8px; }
nav.sidebar a.navlink { position: relative; margin-left: 9px; padding: 7px 10px 7px 18px; border: 0; border-radius: 5px; font-weight: 400; }
nav.sidebar a.navlink.active { background: transparent; color: var(--tx); font-weight: 550; }
nav.sidebar a.navlink:hover { background: transparent; color: var(--tx); }
/* Group-owned indicators preserve continuity across rows and SPA selection.
   Their geometry is measured from real wrapped rows, never from row indices. */
.nav-sec, aside.toc .toc-list { position: relative; }
aside.toc .toc-list { border: 0; }
aside.toc .toc-title { font-weight: 600; }
aside.toc a { border: 0; margin-left: 0; }
aside.toc a.active { color: var(--tx); font-weight: 550; }
.nav-sec::before, .nav-sec::after,
aside.toc .toc-list::before, aside.toc .toc-list::after {
  content: ""; position: absolute; pointer-events: none; width: 11px; left: 9px;
  border-left: 1px dashed currentColor; border-bottom: 1px dashed currentColor;
  border-bottom-left-radius: 7px; box-sizing: border-box;
  transition: height 220ms cubic-bezier(.2,.8,.2,1), top 220ms cubic-bezier(.2,.8,.2,1), opacity 120ms;
}
.nav-sec::after, aside.toc .toc-list::after {
  color: var(--acc); top: var(--rail-top, 0px); height: var(--rail-height, 0px); opacity: var(--rail-visible, 0);
}
.nav-sec::before, aside.toc .toc-list::before {
  color: var(--tx-faint); top: var(--preview-top, 0px); height: var(--preview-height, 0px); opacity: var(--preview-visible, 0);
}
aside.toc .toc-list::before, aside.toc .toc-list::after { left: 0; width: 10px; }
/* Child groups remain legible even before a child becomes current. */
aside.toc .toc-list .toc-list {
  background: repeating-linear-gradient(to bottom, var(--bd) 0 3px, transparent 3px 6px)
    0 var(--rail-top, 0px) / 1px var(--guide-height, 0px) no-repeat;
}
aside.toc .toc-list .toc-list a:is(.active, .in-path) { color: var(--tx); font-weight: 550; }
/* A text-level focus treatment remains visible without a full-row orange box. */
nav.sidebar a.navlink:focus-visible, aside.toc a:focus-visible {
  outline: none; color: var(--tx); background: var(--bd-soft);
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px;
}
article:not(.doc) .code-frame { margin: 20px 0; border: 1px solid var(--bd); border-radius: 12px; overflow: hidden; background: var(--bg-code); }
article:not(.doc) .code-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--bd); background: var(--bg-side); color: var(--tx-soft); font: 12px var(--mono); }
article:not(.doc) .code-frame pre { border: 0; border-radius: 0; margin: 0; padding: 18px; }
article:not(.doc) .code-header .copy-btn { position: static; opacity: 1; flex-shrink: 0; padding: 4px 9px; border: 1px solid var(--bd); border-radius: 6px; background: var(--bg-card); color: var(--tx-soft); cursor: pointer; font: 12px var(--sans); }
article:not(.doc) .code-header .copy-btn:hover, article:not(.doc) .code-header .copy-btn.copied { color: var(--acc); border-color: var(--acc); }
.reader-progress { position: fixed; right: 24px; bottom: 24px; z-index: 170; width: 230px; max-width: calc(100vw - 32px); border: 1px solid var(--bd); border-radius: 20px; background: var(--bg-card); box-shadow: var(--shadow); padding: 0; }
.reader-progress summary { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; list-style: none; font-size: 12px; font-weight: 500; border-radius: inherit; }
.reader-progress summary::-webkit-details-marker { display: none; }
.reader-label { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.reader-percent { color: var(--tx-soft); font-variant-numeric: tabular-nums; font-size: 11px; }
.reader-ring { width: 19px; height: 19px; flex: none; border-radius: 50%; background: conic-gradient(var(--acc) var(--read-progress, 0%), var(--bd) 0); position: relative; }
.reader-ring::after { content: ""; position: absolute; inset: 3px; background: var(--bg-card); border-radius: 50%; }
.reader-sections { padding: 6px 8px 10px; max-height: min(52vh, 420px); overflow-y: auto; border-top: 1px solid var(--bd); }
.reader-sections a { display: block; padding: 8px 10px; color: var(--tx-soft); border-radius: 7px; font-size: 13px; line-height: 1.4; }
.reader-sections a:hover { text-decoration: none; background: var(--bd-soft); }
.reader-sections a.active { color: var(--acc); background: var(--acc-soft); }
:where(a, button, input, summary):focus-visible { outline: 2px solid var(--acc); outline-offset: 3px; }
@media (max-width: 860px) {
  header.topbar { gap: 8px; padding: 0 12px; }
  .topbar .brand { font-size: 13px; }
  .topbar .search-trigger { padding: 8px; }
  .topbar .search-trigger kbd { display: none; }
  .topbar button.lang-trigger { padding: 0 7px; white-space: nowrap; flex-shrink: 0; }
  .topbar .brand .mark { width: 18px; height: 18px; }
  html[data-nav-collapsed="1"] nav.sidebar.open { transform: translateX(0); }
  .reader-progress { bottom: 16px; right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
html[data-fs="1"] article :is(h1, h2, h3, h4, h5, h6) { scroll-margin-top: 24px; }

@media (max-width: 420px) { .topbar .lang-trigger svg { display: none; } }

/* Design navigation: compact areas, modules and page rows. */
nav.sidebar details.nav-disclosure { margin: 2px 0; padding: 0; border: 0; }
nav.sidebar .nav-disclosure > summary {
  display: flex; align-items: center; gap: 6px; min-height: 34px;
  padding: 6px; cursor: pointer; list-style: none; border-radius: 5px;
}
nav.sidebar .nav-disclosure > summary::-webkit-details-marker { display: none; }
nav.sidebar .nav-disclosure > summary::before,
aside.toc .toc-disclosure > summary::before {
  content: ""; width: 5px; height: 5px; margin: 0 4px 0 1px;
  /* Include the border when aligning the chevron center to the 1px rail. */
  position: relative; left: -.5px;
  border-right: 1px solid currentColor; border-bottom: 1px solid currentColor;
  transform: rotate(-45deg); flex-shrink: 0; color: var(--tx-soft);
}
nav.sidebar .nav-disclosure[open] > summary::before,
aside.toc .toc-disclosure[open] > summary::before { transform: rotate(45deg); }
nav.sidebar .nav-disclosure > summary:hover { background: transparent; }
nav.sidebar .nav-disclosure .nav-sec-title {
  padding: 0; margin: 0; font-size: 13px; line-height: 1.4; font-weight: 550;
  min-width: 0; overflow-wrap: anywhere;
}
nav.sidebar .nav-count {
  margin-left: auto; padding-left: 4px; color: var(--tx-faint);
  font-size: 10px; font-weight: 400; font-variant-numeric: tabular-nums;
}
nav.sidebar .nav-disclosure:not([open])::before,
nav.sidebar .nav-disclosure:not([open])::after { opacity: 0; }
nav.sidebar .nav-tree > .nav-disclosure { margin-bottom: 8px; }
nav.sidebar .nav-branch > .nav-sec { margin-left: 12px; }
nav.sidebar .nav-branch > .nav-sec > summary { min-height: 30px; }
nav.sidebar .nav-branch > .nav-sec > summary .nav-sec-title { font-size: 12px; font-weight: 500; }
nav.sidebar .nav-branch > .nav-sec > summary .nav-count { display: none; }
nav.sidebar .nav-disclosure a.navlink {
  margin: 1px 0 1px 10px; padding: 6px 8px 6px 14px;
  font-size: 13px; line-height: 1.45; font-weight: 400;
  overflow-wrap: anywhere; text-decoration: none; border-radius: 4px;
}
nav.sidebar .nav-disclosure a.navlink:hover { background: transparent; }
nav.sidebar .nav-disclosure a.navlink.active {
  background: transparent; color: var(--acc); font-weight: 500;
}
nav.sidebar .nav-disclosure a.navlink:focus-visible,
nav.sidebar .nav-disclosure > summary:focus-visible {
  outline: none; box-shadow: inset 0 0 0 2px var(--acc);
  text-decoration: none;
}

/* The same disclosure chevron marks parent headings in both navigation trees. */
aside.toc .toc-disclosure { margin: 0; padding: 0; }
aside.toc .toc-disclosure > summary {
  display: flex; align-items: center; list-style: none; cursor: pointer;
  position: relative; background: var(--bg); z-index: 1;
}
aside.toc .toc-disclosure > summary::-webkit-details-marker { display: none; }
aside.toc .toc-disclosure > summary::before { margin-left: -1.5px; margin-right: 12.5px; }
aside.toc .toc-disclosure > summary > a { flex: 1; min-width: 0; padding-left: 0; }
aside.toc .toc-disclosure > summary:has(> a.in-path)::before { color: var(--acc); }
aside.toc .toc-disclosure > summary:focus-visible { outline: 1px solid var(--acc); outline-offset: 2px; }

/* ── HTML documents ──
   Everything below applies to article.doc only, so the site chrome and pages
   not yet moved to HTML are untouched. Container width, not viewport width,
   decides each layout: the column depends on the sidebar and contents. */
article.doc { max-width: var(--doc-width); container-type: inline-size; }
main.content:has(> article.doc) { padding-left: var(--s5); padding-right: var(--s5); }

/* ---------- reading ---------- */
.doc > h1 {
  font-size: var(--fs-title);
  line-height: 1.3;
  font-weight: var(--w-strong);
  margin: 0 0 var(--s6);
  text-wrap: balance;
}
.doc h2 {
  font-size: var(--fs-head);
  line-height: 1.4;
  font-weight: var(--w-strong);
  margin: var(--s7) 0 var(--s3);
}
.doc p, .doc ul, .doc ol, .doc dl { max-width: var(--measure); margin: 0 0 var(--s4); text-wrap: pretty; }
.doc ul, .doc ol { padding-left: 1.4em; }
.doc a:not(.pn-link) { color: var(--acc); text-decoration: underline; text-underline-offset: 3px; transition: color var(--quick); }
.doc small, .doc .note { font-size: var(--fs-note); color: var(--soft); }
.doc .note { max-width: var(--measure); margin: var(--s2) 0 0; }
.doc .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.doc .nb { white-space: nowrap; }
/* ---------- code ---------- */
.doc code, .doc pre, .doc kbd { font-family: var(--mono); font-size: var(--fs-note); }
.doc h1 code, .doc h2 code { font-size: inherit; }
.doc h2 small { font-weight: var(--w-normal); }
.doc :not(pre) > code {
  overflow-wrap: anywhere;
}
.doc pre {
  margin: 0 0 var(--s4);
  padding: var(--s3) var(--s4);
  background: var(--panel);
  border-radius: var(--radius);
  line-height: 1.6;
  overflow-x: auto;
  tab-size: 2;
}
/* A do / do-not command pair. The words carry the meaning, colour follows. */
.doc .commands { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s2) var(--s4); align-items: baseline; margin: 0 0 var(--s6); max-width: none; }
.doc .commands dt { font-size: var(--fs-note); color: var(--soft); }
.doc .commands dd { margin: 0; }
.doc .commands code { overflow-wrap: normal; }
.doc .commands .struck code { color: var(--soft); text-decoration: line-through; }
/* ---------- figures ----------
   A wide figure is drawn 1:1: viewBox width 852 is the content width of --page.
   Below that it is replaced by an HTML version, never shrunk. */
.doc figure { margin: 0 0 var(--s6); }
.doc svg { display: block; width: 100%; height: auto; }
.doc svg.fig-wide { max-width: 680px; }
.doc .fig-narrow { display: none; }
.doc svg text { font-family: var(--font); font-size: var(--fs-body); fill: var(--tx); }
.doc svg .t-big { font-size: var(--fs-head); font-weight: var(--w-strong); }
.doc svg .t-soft { font-size: var(--fs-note); fill: var(--soft); }
.doc svg .t-note { font-size: var(--fs-note); }
.doc svg .t-cmd { font-family: var(--mono); font-size: var(--fs-note); fill: var(--tx); }
.doc svg .t-no { font-size: var(--fs-note); fill: var(--no); }
.doc svg .mid { text-anchor: middle; }
.doc svg .ln { stroke: var(--soft); fill: none; stroke-width: 1.2; }
.doc svg .ln-faint { stroke: var(--soft); fill: none; stroke-dasharray: 3 3; }
.doc svg .ln-no { stroke: var(--no); fill: none; stroke-dasharray: 4 3; stroke-width: 1.2; }
.doc svg .ln-acc { stroke: var(--acc); fill: none; stroke-width: 1.4; }
.doc svg .head { fill: var(--soft); }
.doc svg .head-no { fill: var(--no); }
.doc svg .tile { fill: var(--tint); }
.doc svg .gate { fill: var(--bg); stroke: var(--acc); stroke-width: 2; }
/* Four tones for a figure whose shapes are different kinds of thing
   (a company, its ways, a key, a sign-in); the plain one is a table drawn in it. */
.doc svg .tone-gray { fill: #f1efe8; stroke: #5f5e5a; stroke-width: .5; }
.doc svg .tone-purple { fill: #eeedfe; stroke: #534ab7; stroke-width: .5; }
.doc svg .tone-teal { fill: #e1f5ee; stroke: #0f6e56; stroke-width: .5; }
.doc svg .tone-coral { fill: #faece7; stroke: #993c1d; stroke-width: .5; }
.doc svg .tone-plain { fill: var(--bg); stroke: var(--line); stroke-width: .5; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .doc svg .tone-gray { fill: #2c2c2a; stroke: #888780; }
  :root:not([data-theme="light"]) .doc svg .tone-purple { fill: #26215c; stroke: #7f77dd; }
  :root:not([data-theme="light"]) .doc svg .tone-teal { fill: #04342c; stroke: #1d9e75; }
  :root:not([data-theme="light"]) .doc svg .tone-coral { fill: #4a1b0c; stroke: #d85a30; }
}
:root[data-theme="dark"] .doc svg .tone-gray { fill: #2c2c2a; stroke: #888780; }
:root[data-theme="dark"] .doc svg .tone-purple { fill: #26215c; stroke: #7f77dd; }
:root[data-theme="dark"] .doc svg .tone-teal { fill: #04342c; stroke: #1d9e75; }
:root[data-theme="dark"] .doc svg .tone-coral { fill: #4a1b0c; stroke: #d85a30; }
/* HTML version of a sequence figure, for widths the SVG would have to shrink at. */
.doc .flow { list-style: none; margin: 0; padding: 0; max-width: none; }
.doc .flow strong { font-size: var(--fs-body); font-weight: var(--w-strong); }
/* Steps with no command between them still read as one sequence. */
.doc .flow > li:not(.via) + li:not(.via) { position: relative; margin-top: calc(var(--s5) + var(--s1)); }
.doc .flow > li:not(.via) + li:not(.via)::before { content: ""; position: absolute; left: var(--s2); top: calc(-1 * (var(--s5) + var(--s1))); height: var(--s5); border-left: 1px solid var(--soft); }
.doc .flow > li:not(.via) + li:not(.via)::after { content: ""; position: absolute; left: calc(var(--s2) - 4px); top: calc(-1 * var(--s1) - 7px); border: 4.5px solid transparent; border-bottom: 0; border-top: 7px solid var(--soft); }
.doc .flow small { display: block; }
.doc .via { position: relative; margin-left: var(--s2); padding: var(--s3) 0 var(--s4) var(--s4); border-left: 1px solid var(--soft); }
.doc .via::after { content: ""; position: absolute; left: -5px; bottom: 0; border: 4.5px solid transparent; border-bottom: 0; border-top: 7px solid var(--soft); }
.doc .via > code { display: block; }
.doc .flow .refused { color: var(--no); font-size: var(--fs-note); margin: var(--s3) 0 0; }
.doc .flow-end { background: var(--tint); border-radius: var(--radius); padding: var(--s3) var(--s4); }
/* Label-and-value list. */
.doc .pairs { margin: 0; max-width: none; }
.doc .pairs dt { font-weight: var(--w-strong); margin-top: var(--s3); }
.doc .pairs dd { margin: 0; color: var(--soft); font-size: var(--fs-note); }
/* ---------- tables ---------- */
.doc table { border-collapse: collapse; width: 100%; font-size: var(--fs-body); line-height: 1.6; margin: 0 0 var(--s6); }
.doc .note + table { margin-top: var(--s6); }
.doc .grid:has(+ .note) { margin-bottom: var(--s3); }
.doc caption { text-align: left; font-size: var(--fs-note); color: var(--soft); padding-bottom: var(--s2); }
.doc th, .doc td { text-align: left; vertical-align: top; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--hair); }
.doc th:first-child, .doc td:first-child { padding-left: 0; }
.doc thead th { font-size: var(--fs-note); font-weight: var(--w-strong); color: var(--soft); border-bottom: 1px solid var(--line); }
.doc tbody th[scope="row"] { font-weight: var(--w-normal); }
.doc tbody th, .doc .grid td { text-wrap: balance; }
.doc .fixed { table-layout: fixed; }
.doc .fixed th:first-child { width: 38%; }
.doc .arg { display: block; color: var(--soft); font-size: var(--fs-note); padding-left: var(--s3); }
.doc td code, .doc th code { overflow-wrap: anywhere; }
.doc dd code { overflow-wrap: anywhere; }
.doc .even { table-layout: fixed; }
@media (min-width: 761px) {
  .doc table:not(.fixed) th code, .doc table:not(.fixed) th a,
  .doc table:not(.fixed) td:first-child code { overflow-wrap: normal; }
}
/* Outcome grid: one short word per cell, tint follows the word. */
.doc .grid { table-layout: fixed; }
.doc .grid thead th, .doc .grid td { text-align: center; }
.doc .grid thead th:first-child, .doc .grid tbody th { text-align: left; }
.doc .grid thead th { color: var(--tx); font-size: var(--fs-body); border-bottom: 0; }
.doc .grid thead small { display: block; font-weight: var(--w-normal); font-family: var(--mono); }
.doc .grid th:first-child { width: 34%; }
.doc .grid td { border: 2px solid var(--bg); border-radius: 0; padding: var(--s3) var(--s1); }
.doc .grid tbody th { border-bottom: 1px solid var(--hair); padding-top: var(--s3); padding-bottom: var(--s3); }
.doc .grid .run { color: var(--soft); }
.doc .grid .review { background: var(--panel); }
.doc .grid .ask { background: var(--tint); color: var(--acc); font-weight: var(--w-strong); }
.doc .grid .deny { background: var(--no-tint); color: var(--no); font-weight: var(--w-strong); }
.doc .grid tbody + tbody tr:first-child > * { border-top: 12px solid var(--bg); }
/* ---------- folding ---------- */
.doc details { margin: 0 0 var(--s3); }
.doc .note + details { margin-top: var(--s6); }
.doc summary {
  cursor: pointer;
  color: var(--soft);
  font-size: var(--fs-note);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 32px;
  transition: color var(--quick);
}
.doc summary::-webkit-details-marker { display: none; }
.doc summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--quick);
}
.doc details[open] > summary::before { transform: rotate(45deg); }
.doc details > :not(summary) { margin-top: var(--s3); }
/* ---------- way forward ---------- */
.doc .next { margin-top: var(--s7); padding-top: var(--s4); border-top: 1px solid var(--hair); font-size: var(--fs-note); max-width: none; }
@media (hover: hover) and (pointer: fine) {
  .doc summary:hover { color: var(--tx); }
}

.doc h3, .doc h4, .doc h5, .doc h6 {
  font-size: var(--fs-body); font-weight: var(--w-strong); line-height: 1.5;
  margin: var(--s6) 0 var(--s2);
}
.doc img { max-width: 100%; height: auto; }
.doc hr { border: 0; border-top: 1px solid var(--hair); margin: var(--s6) 0; }
.doc blockquote { margin: 0 0 var(--s4); max-width: var(--measure); color: var(--soft); }
.doc :is(ul, ol):not(.flow) > li { margin: var(--s1) 0; }
.doc .code-plain { position: relative; margin: 0 0 var(--s4); }
.doc .code-plain pre { margin: 0; }
.doc .code-plain .code-header > span { display: none; }
.doc .code-plain .code-header { position: absolute; top: var(--s1); right: var(--s1); }
.doc .code-plain .copy-btn {
  background: var(--panel); border: 0; color: var(--soft); cursor: pointer;
  font: var(--fs-note) var(--font); padding: 2px var(--s2); border-radius: var(--radius);
  transition: color var(--quick), opacity var(--quick);
}
.doc .code-plain .copy-btn.copied { color: var(--acc); }
@media (hover: hover) and (pointer: fine) {
  .doc .code-plain .copy-btn { opacity: 0; }
  .doc .code-plain:hover .copy-btn, .doc .code-plain .copy-btn:focus-visible, .doc .code-plain .copy-btn.copied { opacity: 1; }
  .doc .code-plain .copy-btn:hover { color: var(--tx); }
}

/* A wide figure is never shrunk: below its drawn width the HTML twin replaces it. */
@container (max-width: 679.98px) {
  .doc .fig-wide { display: none; }
  .doc .fig-narrow { display: block; }
}
@container (max-width: 640px) {
  /* A lookup table becomes one block per row; no sideways scrolling. */
  .doc .stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .doc .stack, .doc .stack tbody, .doc .stack tr, .doc .stack th, .doc .stack td { display: block; width: 100%; }
  .doc .stack { margin-bottom: var(--s5); }
  .doc .stack tr { padding: var(--s2) 0; border-bottom: 1px solid var(--hair); }
  .doc .stack td, .doc .stack th { border: 0; padding: 0; }
  .doc .stack tbody th { text-wrap: wrap; }
  .doc .stack th:first-child, .doc .fixed th:first-child { width: 100%; }
  .doc .stack th[scope="row"] { font-weight: var(--w-strong); }
  .doc .stack th[scope="row"] .arg { font-weight: var(--w-normal); }
  /* The hidden column heading stays beside each value when it matters. */
  .doc .stack td[data-label]::before { content: attr(data-label); display: block; color: var(--soft); font-size: var(--fs-note); }
  .doc .stack td[data-label] + td[data-label] { margin-top: var(--s1); }

  .doc .commands { grid-template-columns: minmax(0, 1fr); }

  /* Outcome grid: the row label takes its own line, the four modes sit under it. */
  .doc .grid, .doc .grid caption, .doc .grid thead, .doc .grid tbody { display: block; }
  .doc .grid tr { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding-bottom: var(--s2); }
  .doc .grid, .doc .grid thead th { font-size: var(--fs-note); }
  .doc .grid thead th:first-child { display: none; }
  .doc .grid thead th { padding: 0 2px; }
  .doc .grid tbody th { grid-column: 1 / -1; width: auto; border: 0; padding: var(--s2) 0 var(--s1); font-weight: var(--w-strong); }
  .doc .grid td { padding: var(--s2) var(--s1); }
  .doc .grid td[colspan="3"] { grid-column: span 3; }
  .doc .grid td[colspan="4"] { grid-column: span 4; }
  .doc .grid tbody + tbody tr:first-child > * { border-top: 0; }
}
@media (max-width: 640px) {
  :root { --fs-title: 1.5rem; }
  .doc .commands code { overflow-wrap: anywhere; }
  main.content, main.content:has(> article.doc) { padding-left: var(--s4); padding-right: var(--s4); }
}
@media print {
  /* Older browsers without ::details-content print closed folds closed. */
  .doc details::details-content { content-visibility: visible; display: block; }
  .doc summary::before { display: none; }
}
