/* C-LAB module documentation. Standalone: no fonts, no libraries. */
/* Palette copied from assets/css/style.css so the docs match the main site. */
:root {
  color-scheme: dark;
  --bg: rgb(18, 18, 18);
  --bg-end: #071019;
  --panel: rgba(255, 255, 255, .02);
  --card: rgb(38, 38, 38);
  --code-bg: rgba(0, 0, 0, .28);
  --text: #e6eef3;
  --text-2: #b4bfc9;
  --muted: #9aa6b2;
  --accent: #ffa000;
  --accent-soft: rgba(255, 160, 0, .10);
  --border: rgba(255, 255, 255, .07);
  --arg: #c9d2da;
  --radius: 12px;
  --bar: 52px;
  --side: 300px;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  /* The main site's gradient spans a taller-than-viewport page, so the viewport's bottom
     edge only reaches ~45% of it (rgb(13,17,21)). 220% reproduces that on a fixed layer. */
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-end) 220%) fixed var(--bg);
  color: var(--text-2);
  font: 16px/1.65 var(--sans);
  -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: 4px; }

/* ---- top bar ---------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 50;
  height: var(--bar);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: rgba(18, 18, 18, .82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.bar .brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; }
.bar .brand:hover { text-decoration: none; }
.bar .crumb { color: var(--muted); }
.bar .crumb::before { content: "/"; margin-right: 14px; opacity: .5; }
.bar .grow { flex: 1; }
.bar .ver {
  font: 600 12px var(--mono);
  padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.bar .back { color: var(--muted); }
.bar .back:hover { color: var(--accent); text-decoration: none; }
#menuBtn { display: none; background: none; border: 0; color: var(--text); padding: 6px; margin-left: -6px; cursor: pointer; border-radius: 8px; }

/* ---- layout ----------------------------------------------------------- */
.layout { display: flex; align-items: flex-start; }

#side {
  position: sticky; top: var(--bar);
  flex: 0 0 var(--side); width: var(--side);
  height: calc(100vh - var(--bar));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 12px 40px 20px;
  border-right: 1px solid var(--border);
  font-size: 13.5px;
  scrollbar-width: thin;
}

.search { position: relative; margin-bottom: 14px; }
.search input {
  width: 100%; padding: 9px 34px 9px 12px;
  font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font: 11px var(--mono); color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px;
  pointer-events: none;
}
.search input:focus + kbd { display: none; }

#toc ol { list-style: none; margin: 0; padding: 0; }
#toc a { display: block; padding: 4px 8px; border-radius: 6px; color: var(--muted); line-height: 1.4; }
#toc a:hover { color: var(--text); background: var(--accent-soft); text-decoration: none; }
#toc a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
#toc .n { display: inline-block; min-width: 2.2em; color: var(--muted); opacity: .8; font-variant-numeric: tabular-nums; }
#toc .l1 > li { margin-bottom: 2px; }
#toc .l1 > li > a { color: var(--text); font-weight: 650; padding-top: 6px; }
#toc .l2, #toc .l3 { display: none; }
#toc li.open > ol { display: block; }
#toc .l2 { margin: 2px 0 6px 10px; padding-left: 8px; border-left: 1px solid var(--border); }
#toc .l3 { margin: 0 0 4px 8px; padding-left: 6px; border-left: 1px solid var(--border); font-size: 12.5px; }
#toc .l3 .n { min-width: 3.2em; }

#results a { display: block; padding: 7px 8px; border-radius: 8px; color: var(--text); }
#results a:hover { background: var(--accent-soft); text-decoration: none; }
#results small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 2px; }
#results p { color: var(--muted); padding: 0 8px; }

main { flex: 1; min-width: 0; padding: 44px clamp(20px, 5vw, 64px) 120px; max-width: 920px; margin: 0 auto; }

/* ---- headings --------------------------------------------------------- */
.hero { margin-bottom: 36px; padding-bottom: 28px; border-bottom: 1px solid var(--border); }
.hero h1 { margin: 0 0 6px; color: var(--text); font-size: clamp(30px, 4vw, 40px); line-height: 1.15; letter-spacing: -.02em; }
.hero p { margin: 0; color: var(--muted); }
.hero strong { color: var(--accent); font-weight: 650; }

h2, h3, h4, h5 { color: var(--text); line-height: 1.3; scroll-margin-top: calc(var(--bar) + 16px); }
section[id], h4[id] { scroll-margin-top: calc(var(--bar) + 16px); }
h2 { font-size: 28px; letter-spacing: -.015em; margin: 0 0 18px; }
section.sec { padding-top: 40px; margin-top: 24px; border-top: 1px solid var(--border); }
section.sec:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
h3 { font-size: 21px; margin: 44px 0 14px; }
section.sec > h2 + p, section.sec > h2 + .desc { margin-top: 0; }
h2 .num, h3 .num, h4 .num { color: var(--accent); font-weight: 600; margin-right: .6em; font-variant-numeric: tabular-nums; }
.anchor { margin-left: .5em; font-weight: 400; color: var(--muted); opacity: 0; transition: opacity .15s; }
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor, .anchor:focus { opacity: .7; text-decoration: none; }

section.entry {
  margin: 22px 0;
  padding: 20px 24px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
section.entry > h4 { margin: 0 0 12px; font-size: 18px; }

h4.group {
  margin: 34px 0 12px; padding-bottom: 8px;
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); border-bottom: 1px solid var(--border);
}
h5.sub { margin: 18px 0 8px; font-size: 11.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

p { margin: 0 0 14px; }
section.entry p:last-child { margin-bottom: 8px; }
strong { color: var(--text); font-weight: 650; }
ul, ol { padding-left: 1.4em; margin: 0 0 14px; }
li { margin: 3px 0; }
li > p:last-child { margin-bottom: 0; }

/* ---- code ------------------------------------------------------------- */
code {
  font: .88em var(--mono);
  padding: .12em .4em; border-radius: 5px;
  background: var(--code-bg); border: 1px solid var(--border);
  color: var(--text);
  overflow-wrap: anywhere;
}
a code { color: inherit; }

.sig, pre.examples { position: relative; }
.sig {
  margin: 14px 0 12px;
  padding: 11px 76px 11px 16px;
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  overflow-x: auto;
}
.sig code { padding: 0; border: 0; background: none; font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.sig .f { color: var(--accent); font-weight: 600; }
.sig .a { color: var(--arg); }

pre.examples {
  margin: 4px 0 14px; padding: 12px 76px 12px 16px;
  background: var(--code-bg); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 4px 10px 10px 4px;
  overflow-x: auto;
}
pre.examples code { display: block; padding: 0; border: 0; background: none; font-size: 13.5px; line-height: 1.7; white-space: pre; overflow-wrap: normal; }

button.copy {
  position: absolute; top: 8px; right: 8px;
  font: 600 11px var(--sans); color: var(--muted);
  background: var(--card); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 9px; cursor: pointer; opacity: 0; transition: opacity .15s;
}
.sig:hover .copy, pre.examples:hover .copy, .copy:focus-visible { opacity: 1; }
.copy:hover { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { button.copy { opacity: .8; } }

/* ---- function documentation ------------------------------------------ */
.fn + .fn, .fn + .var { margin-top: 22px; padding-top: 22px; border-top: 1px dashed var(--border); }
.fn .sig:first-child { margin-top: 4px; }

dl.params, dl.deflist {
  display: grid; grid-template-columns: minmax(84px, max-content) 1fr;
  gap: 10px 22px; margin: 12px 0 14px; padding: 0;
}
dl.params dt, dl.deflist dt { text-align: right; padding-top: 2px; }
dl.params dd, dl.deflist dd { margin: 0; min-width: 0; }
dl.params dd > :last-child, dl.deflist dd > :last-child { margin-bottom: 0; }
dl.params dt code, dl.deflist dt code { color: var(--arg); background: none; border: 0; padding: 0; font-size: 13.5px; font-weight: 600; }
dl.deflist dt { color: var(--text); font-weight: 600; font-size: 14px; }
.req {
  display: block; margin-top: 3px;
  font: 700 10px var(--sans); letter-spacing: .08em; text-transform: uppercase;
}
.req.mandatory { color: var(--accent); }
.req.optional { color: var(--muted); }

.desc { margin: 10px 0 12px; }
.desc > :last-child { margin-bottom: 0; }

.note {
  margin: 14px 0; padding: 10px 16px;
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 4px 10px 10px 4px;
}
.note strong { color: var(--accent); margin-right: .6em; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.note > :first-child { display: inline; }
.note p { display: inline; }

.var { margin: 14px 0; }
.var .vsig { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.var .vsig code { background: none; border: 0; padding: 0; font-size: 14px; color: var(--arg); }
.var .vsig .f { color: var(--accent); font-weight: 600; }
.var .vsig em { color: var(--muted); font-size: 13px; }
.var .vdesc { margin: 4px 0 0 18px; padding-left: 14px; border-left: 2px solid var(--border); }
.var .vdesc > :last-child { margin-bottom: 0; }

.indent { margin-left: 1.2em; }
.center { text-align: center; }
.missing { color: var(--muted); border-bottom: 1px dotted var(--muted); }

/* ---- figures & math --------------------------------------------------- */
figure { margin: 18px 0; text-align: center; }
figure img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 10px; background: rgb(28, 28, 28); }
figure.pair { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
figure.pair img { flex: 1 1 240px; min-width: 0; max-width: calc(50% - 7px); }
figure.diagram { padding: 16px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; color: var(--text); }
figure.diagram svg { width: 100%; max-width: 340px; height: auto; }
figure.diagram svg text { fill: currentColor; }

math { font-size: 1.1em; }
math[display="block"] { display: block math; margin: 14px 0; }
math .tt, math mrow.tt { font-family: var(--mono); }

/* ---- responsive ------------------------------------------------------- */
@media (max-width: 900px) {
  #menuBtn { display: block; }
  .bar { padding: 0 14px; gap: 10px; }
  .bar .crumb, .bar .back { display: none; }
  #side {
    position: fixed; top: var(--bar); left: 0; bottom: 0; z-index: 40;
    width: min(330px, 88vw); flex: none; height: auto;
    background: #0d1218;
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: none;
  }
  #side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); }
  main { padding: 28px 16px 80px; }
  section.entry { padding: 16px 16px 10px; }
  h2 { font-size: 24px; }
  h3 { font-size: 19px; }
}
@media (max-width: 560px) {
  dl.params, dl.deflist { grid-template-columns: 1fr; gap: 2px; }
  dl.params dt, dl.deflist dt { text-align: left; margin-top: 10px; }
  dl.params dt .req { display: inline-block; margin: 0 0 0 8px; }
  dl.params dd, dl.deflist dd { padding-left: 12px; }
  figure.pair img { max-width: 100%; }
  .var .vdesc { margin-left: 4px; }
}
@media (prefers-reduced-motion: reduce) { #side { transition: none; } }

@media print {
  .bar, #side, button.copy { display: none !important; }
  body { background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  section.entry { break-inside: avoid; }
}
