/* Malonlin tokens: lemon and charcoal carry the layout; lavender marks focus and state only. */
:root {
  --lemon: #FFE600;
  --lemon-100: #FFF8C2;
  --lavender: #9D5CFF;
  --lavender-100: #F1E8FF;
  --charcoal: #141414;
  --charcoal-800: #1C1C1E;
  --charcoal-600: #4A4A4F;
  --charcoal-400: #8E8E93;
  --paper: #FBFAF5;
  --rule: #E7E5DF;
  --ink: var(--charcoal);
  --muted: var(--charcoal-600);
  --line: var(--rule);
  --bg: var(--paper);
  --code-bg: var(--charcoal-800);
  --topbar: 64px;
}
* { box-sizing: border-box; }
/* Keeps anchored headings clear of the sticky topbar when jumping to a section. */
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px; line-height: 1.7;
}
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; }
/* One focus ring for every control: lavender, offset so it clears the element edge. */
:focus-visible { outline: 3px solid var(--lavender); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar);
  display: flex; align-items: center; gap: 24px; padding: 0 24px;
  background: var(--charcoal); color: var(--paper);
}
/* Site wordmark in the topbar. */
.brand { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 20px; letter-spacing: -0.03em; color: var(--paper); white-space: nowrap; }
.brand span { color: var(--lemon); }
.brand:hover { text-decoration: none; }
/* Mark sits on the charcoal topbar; decorative, so the link text carries the name. */
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.topnav { display: flex; gap: 20px; margin-left: 12px; }
.topnav a { color: var(--paper); font-size: 14px; font-weight: 500; }
.topnav a:hover { color: var(--lemon); text-decoration: none; }
/* Hidden on desktop; only shown inside the mobile breakpoint below. */
.menu-btn { display: none; border: 1px solid var(--paper); border-radius: 6px; background: transparent; color: var(--paper); padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; }
.menu-btn:hover { background: var(--lemon); border-color: var(--lemon); color: var(--charcoal); }

/* The results dropdown is positioned relative to this box. */
.search { position: relative; margin-left: auto; width: 300px; }
.search input {
  width: 100%; padding: 8px 12px; font: inherit; font-size: 14px; border-radius: 6px;
  border: 1px solid var(--paper); background: #fff; color: var(--ink);
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff;
  border: 1px solid var(--rule); border-radius: 10px; box-shadow: 4px 4px 0 var(--charcoal);
  max-height: 380px; overflow: auto;
}
.search-results a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; color: var(--ink); border-bottom: 1px solid var(--line); font-size: 14px; }
.search-results a span { color: var(--muted); font-size: 12px; }
.search-results a:hover, .search-results a.sel { background: var(--lemon-100); text-decoration: none; }
.search-results .empty { padding: 12px; color: var(--muted); font-size: 14px; }

/* Three columns: sidebar nav, fluid article, and the per-page TOC on the right. */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr) 230px; max-width: 1480px; margin: 0 auto; }
.sidebar {
  position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto;
  padding: 24px 16px 40px 24px; border-right: 1px solid var(--line);
}
/* Sidebar sections. The current page is a lemon-100 row with a charcoal bar (.nav-group li a.active). */
.nav-group { margin-bottom: 24px; }
.nav-title { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.nav-group ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.nav-group li a { display: block; padding: 4px 12px; margin-left: -1px; border-left: 3px solid transparent; color: var(--muted); font-size: 14px; line-height: 1.5; }
.nav-group li a:hover { color: var(--ink); background: var(--lavender-100); text-decoration: none; }
.nav-group li a.active { color: var(--ink); background: var(--lemon-100); border-left-color: var(--charcoal); font-weight: 500; }

/* min-width: 0 lets the middle column shrink so wide code scrolls, not the page. */
.content { padding: 32px 48px 60px; min-width: 0; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs span { margin: 0 4px; }

article h1, article h2, article h3 { font-family: 'Space Grotesk', sans-serif; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
article h1 { font-size: 40px; margin: 0 0 20px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
article h2 { font-size: 28px; margin: 44px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
article h3 { font-size: 22px; margin: 28px 0 10px; }
/* Heading anchor links stay invisible until the heading is hovered or focused from the keyboard. */
article h2 .anchor, article h3 .anchor { margin-left: 8px; color: var(--charcoal-600); font-weight: 400; opacity: 0; text-decoration: none; }
article h2:hover .anchor, article h3:hover .anchor, article h2 .anchor:focus-visible, article h3 .anchor:focus-visible { opacity: 1; }
article p, article ul, article ol { margin: 0 0 16px; }
article li { margin: 4px 0; }
article a:not(.anchor) { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
article a:not(.anchor):hover { background: var(--lemon-100); }
article code { font-family: 'Roboto Mono', Consolas, monospace; font-size: .88em; background: #fff; border: 1px solid var(--rule); border-radius: 4px; padding: 1px 5px; }
article hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }

/* Dark code panel with a header bar for the language label and copy button. */
.code-block { margin: 0 0 20px; border: 1px solid var(--charcoal); border-radius: 10px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; border-bottom: 1px solid #333; background: var(--charcoal); }
.code-head span { color: var(--charcoal-400); font-family: 'Roboto Mono', monospace; font-size: 12px; text-transform: lowercase; }
.copy-btn { background: transparent; color: var(--paper); border: 1px solid var(--paper); border-radius: 6px; padding: 2px 10px; font: 500 12px 'Roboto', sans-serif; cursor: pointer; }
.copy-btn:hover { background: var(--lemon); border-color: var(--lemon); color: var(--charcoal); }
.copy-btn.copied { background: var(--paper); color: var(--charcoal); }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
/* white-space: pre keeps code lines intact; long lines scroll sideways inside the pre. */
.code-block code { background: none; border: 0; padding: 0; color: #f5f5f5; font-size: 13px; line-height: 1.65; white-space: pre; }

/* Wraps tables (see lib.js) so wide tables scroll inside their own box. */
.table-wrap { overflow-x: auto; margin: 0 0 20px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
th { background: #fff; border-bottom: 2px solid var(--ink); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }

blockquote { margin: 0 0 16px; padding: 4px 16px; border-left: 3px solid var(--ink); color: var(--muted); }
/* Admonition box. Notes and tips use the lavender tint; warnings and important notes use lemon. */
.callout { margin: 0 0 20px; padding: 12px 16px; border: 1px solid var(--line); border-left: 4px solid var(--charcoal); border-radius: 10px; background: var(--lavender-100); }
.callout p { margin: 0 0 8px; } .callout p:last-child { margin-bottom: 0; }
.callout-title { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.callout-warning, .callout-important { background: var(--lemon-100); }

/* Numbered steps: wrapping boxes whose numbers come from CSS counters. */
.flow { list-style: none; counter-reset: step; display: flex; flex-wrap: wrap; gap: 10px 0; padding: 0; margin: 0 0 20px; }
.flow li { counter-increment: step; position: relative; margin: 0 28px 0 0; padding: 8px 14px 8px 38px; border: 1px solid var(--charcoal); border-radius: 6px; background: #fff; font-size: 14px; }
.flow li::before { content: counter(step); position: absolute; left: 0; top: 0; bottom: 0; width: 26px; display: flex; align-items: center; justify-content: center; background: var(--lemon); color: var(--charcoal); font-weight: 700; font-size: 13px; }
/* Connector line drawn to the right of each step; the last step has none. */

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 48px; }
.pager a { display: block; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.pager a:hover { border-color: var(--charcoal); box-shadow: 4px 4px 0 var(--charcoal); text-decoration: none; }
.pager small { display: block; color: var(--muted); font-size: 12px; }
.pager span { color: var(--ink); font-weight: 500; }
/* Pinned to column 2 so the next link stays right even when there is no previous link. */
.pager .next { text-align: right; grid-column: 2; }
.footer { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

/* Right-hand per-page table of contents, sticky under the topbar. Hidden below 1180px. */
.toc { position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto; padding: 32px 24px; font-size: 13px; }
.toc-title { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 10px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc li a { display: block; padding: 3px 12px; margin-left: -1px; border-left: 3px solid transparent; color: var(--muted); line-height: 1.4; }
.toc li.d3 a { padding-left: 24px; }
.toc li a:hover { color: var(--ink); text-decoration: none; }
.toc li a.current { color: var(--ink); background: var(--lemon-100); border-left-color: var(--charcoal); font-weight: 500; }

/* Narrower screens drop the TOC column to give the article more room. */
@media (max-width: 1180px) { .layout { grid-template-columns: 250px minmax(0, 1fr); } .toc { display: none; } }
/* Mobile: single column, with the sidebar turned into an overlay below the topbar. */
@media (max-width: 820px) {
  .topnav { display: none; }
  .menu-btn { display: block; }
  .search { width: 100%; margin-left: 0; }
  .topbar { gap: 12px; padding: 0 12px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; position: fixed; inset: var(--topbar) 0 0 0; z-index: 20; height: auto; background: var(--paper); border-right: 0; }
/* The overlay is hidden by default; app.js adds .open from the menu button. */
  .sidebar.open { display: block; }
  .content { padding: 24px 18px 48px; }
  article h1 { font-size: 28px; }
  .brand { font-size: 17px; }
  .brand-mark { width: 24px; height: 24px; }
}
