/* docs.xcaicx.com — same house style as xcaicx.com, laid out for reading.
 *
 * Three columns on a wide screen: navigation, prose held to a readable measure,
 * and an on-this-page rail. The prose column never gets wider than ~72ch no
 * matter how big the window is, because a documentation line you have to track
 * back across is a documentation line nobody reads twice.
 *
 * No external requests: CSP is `default-src 'none'` with `connect-src 'self'`
 * for the search index, and nothing else is fetched.
 */

:root {
  --s1: 4px;  --s2: 8px;   --s3: 12px;  --s4: 16px;  --s5: 24px;
  --s6: 32px; --s7: 48px;  --s8: 64px;  --s9: 96px;
  --r-sm: 8px; --r: 12px; --r-full: 999px;

  --sans: "Inter var", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --fs-body: 16px;
  --fs-sm: 14.5px;
  --fs-xs: 13px;
  --fs-mono: 13px;

  --measure: 72ch;
  --side-w: 262px;
  --toc-w: 220px;
  --top-h: 58px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-elev: #fafafa;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --line: rgba(10, 14, 20, .10);
  --line-strong: rgba(10, 14, 20, .18);
  --text: #13171c;
  --text-2: #525a67;
  --text-3: #848b97;
  --accent: #0e7490;
  --accent-ink: #ecfbff;
  --ok: #0f766e;
  --warn: #b3261e;
  --amber: #92610a;
  --term-bg: #0a0d11;
  --shadow: 0 1px 2px rgba(10, 14, 20, .05), 0 12px 40px rgba(10, 14, 20, .10);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0d11;
  --bg-elev: #0f141a;
  --surface: #11171d;
  --surface-2: #161d25;
  --line: rgba(216, 228, 238, .10);
  --line-strong: rgba(216, 228, 238, .18);
  --text: #e5ecf2;
  --text-2: #a1adba;
  --text-3: #7b8794;
  --accent: #38bdf8;
  --accent-ink: #04202b;
  --ok: #4db6a4;
  --warn: #e8825a;
  --amber: #e0aa4f;
  --term-bg: #05080b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 48px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.skip { position: absolute; left: -9999px; }
.skip:focus {
  left: var(--s4); top: var(--s4); z-index: 100;
  background: var(--surface); padding: var(--s3) var(--s4);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  height: var(--top-h);
}
.topbar-in {
  display: flex; align-items: center; gap: var(--s4);
  height: var(--top-h); padding: 0 var(--s5); max-width: 1500px; margin: 0 auto;
}
.brand {
  display: inline-flex; align-items: center; gap: var(--s2);
  color: var(--text); font-weight: 600; letter-spacing: -.02em; font-size: 15.5px;
  flex: none;
}
.brand:hover { text-decoration: none; }
.brand .mark { width: 20px; height: 20px; color: var(--accent); flex: none; }
.brand-sub { color: var(--text-3); font-weight: 500; }
.topbar-link { color: var(--text-2); font-size: var(--fs-sm); flex: none; }
.topbar-link:hover { color: var(--text); text-decoration: none; }
.icon-btn {
  appearance: none; background: none; border: 1px solid var(--line);
  color: var(--text-2); border-radius: var(--r-full);
  width: 30px; height: 30px; display: grid; place-items: center;
  cursor: pointer; flex: none; font-size: 13px;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.menu-toggle { display: none; }

/* ---------------------------------------------------------------- search */

.search { position: relative; margin-left: auto; width: min(360px, 40vw); }
.search input {
  width: 100%; font-family: var(--sans); font-size: var(--fs-sm);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-full);
  padding: 6px var(--s4);
}
.search input::placeholder { color: var(--text-3); }
.results {
  position: absolute; top: calc(100% + 8px); right: 0; width: min(520px, 78vw);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r); box-shadow: var(--shadow);
  max-height: 62vh; overflow-y: auto; padding: var(--s2); z-index: 60;
}
.results a {
  display: block; padding: var(--s2) var(--s3); border-radius: var(--r-sm);
  color: var(--text);
}
.results a:hover, .results a.sel { background: var(--surface-2); text-decoration: none; }
.results .r-t { font-weight: 500; font-size: var(--fs-sm); }
.results .r-c { color: var(--text-3); font-size: var(--fs-xs); }
.results .r-s { color: var(--text-2); font-size: var(--fs-xs); display: block; }
.results mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 3px; }
.results .empty { padding: var(--s3); color: var(--text-3); font-size: var(--fs-sm); }

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

.layout {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--toc-w);
  max-width: 1500px; margin: 0 auto; gap: var(--s7);
  padding: 0 var(--s5);
  align-items: start;
}
@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .menu-toggle { display: grid; }
  .side-nav {
    display: none; position: fixed; inset: var(--top-h) 0 0 0; z-index: 45;
    background: var(--bg); overflow-y: auto;
    padding: var(--s5) var(--s5) var(--s8); height: auto; max-height: none;
  }
  .side-nav.open { display: block; }
  .search { width: auto; flex: 1; }
  .topbar-link { display: none; }
}

/* ------------------------------------------------------------- side nav */

.side-nav {
  position: sticky; top: var(--top-h);
  max-height: calc(100vh - var(--top-h)); overflow-y: auto;
  padding: var(--s6) 0 var(--s8);
  font-size: var(--fs-sm);
}
.side-group {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-3);
  margin: var(--s5) 0 var(--s2);
}
.side-group:first-child { margin-top: 0; }
.side-nav ul { list-style: none; margin: 0; padding: 0; }
.side-nav li a {
  display: block; padding: 5px var(--s3); margin-left: -var(--s3);
  border-radius: var(--r-sm); color: var(--text-2);
  border-left: 2px solid transparent;
}
.side-nav li a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.side-nav li a.active {
  color: var(--accent); border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-weight: 500;
}

/* ------------------------------------------------------------------ toc */

.toc {
  position: sticky; top: var(--top-h);
  max-height: calc(100vh - var(--top-h)); overflow-y: auto;
  padding: var(--s6) 0 var(--s8); font-size: var(--fs-xs);
}
.toc-title {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-3); margin: 0 0 var(--s3);
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li a {
  display: block; padding: 3px 0 3px var(--s3);
  color: var(--text-2); border-left: 2px solid var(--line);
  line-height: 1.45;
}
.toc li.lvl3 a { padding-left: var(--s5); }
.toc li a:hover { color: var(--text); text-decoration: none; }
.toc li a.active { color: var(--accent); border-left-color: var(--accent); }

/* ----------------------------------------------------------------- prose */

.doc { padding: var(--s7) 0 var(--s9); min-width: 0; }
.doc article { max-width: var(--measure); }

.doc h1 {
  font-size: clamp(28px, 3.6vw, 38px); line-height: 1.12; letter-spacing: -.032em;
  font-weight: 600; margin: 0 0 var(--s4); text-wrap: balance;
}
.doc .summary {
  font-size: 17.5px; color: var(--text-2); margin: 0 0 var(--s6);
  padding-bottom: var(--s5); border-bottom: 1px solid var(--line);
}
.doc h2 {
  font-size: 24px; line-height: 1.25; letter-spacing: -.024em; font-weight: 600;
  margin: var(--s8) 0 var(--s4); padding-top: var(--s2);
  scroll-margin-top: calc(var(--top-h) + 16px);
}
.doc h3 {
  font-size: 18px; line-height: 1.35; letter-spacing: -.015em; font-weight: 600;
  margin: var(--s6) 0 var(--s3);
  scroll-margin-top: calc(var(--top-h) + 16px);
}
.doc h4 {
  font-size: 15.5px; font-weight: 600; margin: var(--s5) 0 var(--s2);
  color: var(--text-2);
  scroll-margin-top: calc(var(--top-h) + 16px);
}
.doc p { margin: 0 0 var(--s4); }
.doc ul, .doc ol { margin: 0 0 var(--s4); padding-left: var(--s5); }
.doc li { margin-bottom: 6px; }
.doc li > ul, .doc li > ol { margin: 6px 0 0; }
.doc strong { color: var(--text); font-weight: 600; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: var(--s7) 0; }

.anchor {
  margin-left: var(--s2); color: var(--text-3); opacity: 0;
  font-weight: 400; text-decoration: none;
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }

.doc code {
  font-family: var(--mono); font-size: .88em;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 5px; padding: .08em .34em;
}

.code {
  position: relative; margin: 0 0 var(--s5);
  background: var(--term-bg); border: 1px solid rgba(255,255,255,.09);
  border-radius: var(--r); overflow: hidden;
}
.code pre { margin: 0; padding: var(--s4) var(--s5); overflow-x: auto; }
.code code {
  font-family: var(--mono); font-size: var(--fs-mono); line-height: 1.65;
  background: none; border: 0; padding: 0; color: #d7e0ea;
}
.code-lang {
  position: absolute; top: 8px; right: 64px;
  font-family: var(--mono); font-size: 11px; color: #6d7885;
  text-transform: uppercase; letter-spacing: .06em;
}
.code-copy {
  position: absolute; top: 6px; right: 8px;
  font-family: var(--sans); font-size: 11.5px;
  background: rgba(255,255,255,.07); color: #b9c4d0;
  border: 1px solid rgba(255,255,255,.12); border-radius: var(--r-sm);
  padding: 3px 9px; cursor: pointer; opacity: 0; transition: opacity .15s var(--ease);
}
.code:hover .code-copy, .code-copy:focus { opacity: 1; }
.code-copy:hover { color: #fff; }

.table-scroll { overflow-x: auto; margin: 0 0 var(--s5); }
.doc table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.doc th, .doc td {
  text-align: left; padding: 9px var(--s3);
  border-bottom: 1px solid var(--line); vertical-align: top;
}
.doc th {
  font-family: var(--mono); font-size: 11.5px; font-weight: 500;
  color: var(--text-3); text-transform: uppercase; letter-spacing: .06em;
  white-space: nowrap;
}
.doc tbody tr:hover { background: var(--surface-2); }
.doc td code { white-space: nowrap; }

.doc blockquote {
  margin: 0 0 var(--s5); padding: var(--s2) 0 var(--s2) var(--s5);
  border-left: 3px solid var(--line-strong); color: var(--text-2);
}
.doc blockquote p:last-child { margin-bottom: 0; }

.callout {
  margin: 0 0 var(--s5); padding: var(--s4) var(--s5);
  border: 1px solid var(--line); border-left-width: 3px;
  border-radius: var(--r-sm); background: var(--surface-2);
  font-size: var(--fs-sm);
}
.callout p { margin-bottom: var(--s3); }
.callout p:last-child { margin-bottom: 0; }
.callout-title {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .08em;
  text-transform: uppercase; font-weight: 500;
}
.callout--note { border-left-color: var(--accent); }
.callout--note .callout-title { color: var(--accent); }
.callout--tip { border-left-color: var(--ok); }
.callout--tip .callout-title { color: var(--ok); }
.callout--warn { border-left-color: var(--amber); }
.callout--warn .callout-title { color: var(--amber); }
.callout--danger { border-left-color: var(--warn); }
.callout--danger .callout-title { color: var(--warn); }

/* ---------------------------------------------------------------- pager */

.pager {
  display: flex; gap: var(--s4); justify-content: space-between;
  max-width: var(--measure); margin: var(--s8) 0 0;
  border-top: 1px solid var(--line); padding-top: var(--s5);
}
.pager a {
  display: block; padding: var(--s3) var(--s4);
  border: 1px solid var(--line); border-radius: var(--r);
  color: var(--text); font-size: var(--fs-sm); font-weight: 500;
  max-width: 46%;
}
.pager a:hover { border-color: var(--line-strong); text-decoration: none; }
.pager a span {
  display: block; font-family: var(--mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: .08em; color: var(--text-3);
  margin-bottom: 2px; font-weight: 400;
}
.pager-next { text-align: right; margin-left: auto; }

.doc-foot {
  max-width: var(--measure); margin-top: var(--s8);
  padding-top: var(--s5); border-top: 1px solid var(--line);
  color: var(--text-3); font-size: var(--fs-xs);
}
.doc-foot p { margin: 0 0 var(--s2); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: .01ms !important; }
}
