/* ==========================================================================
   Documentation pages (/docs/*) — issue #23.

   These pages are plain static HTML emitted by scripts/build-docs.mjs into
   public/docs/, so this stylesheet is NOT processed by Vite: it must stand on
   its own, which is why it pulls the shared palette with a browser-native
   @import rather than a bundler one. Same tokens as the marketing page, a
   reading-first layout on top.
   ========================================================================== */
@import './tokens.css';

* {
	box-sizing: border-box;
}
html {
	scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}
}
body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font-family: var(--sans);
	font-size: 16px;
	line-height: 1.65;
	-webkit-font-smoothing: antialiased;
}
::selection {
	background: var(--sel);
}
code,
pre {
	font-family: var(--mono);
}

/* ------------------------------------------------------------------ chrome */
.dnav {
	position: sticky;
	top: 0;
	z-index: 20;
	background: color-mix(in srgb, var(--paper) 92%, transparent);
	backdrop-filter: blur(8px);
	border-bottom: 1px solid var(--hair);
}
.dnav-in {
	max-width: 1320px;
	margin: 0 auto;
	padding: 0 24px;
	height: 56px;
	display: flex;
	align-items: center;
	gap: 18px;
}
.dbrand {
	font-weight: 680;
	letter-spacing: -0.02em;
	color: var(--ink);
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	gap: 8px;
}
.dbrand .glyph {
	color: var(--sprout);
}
.dnav .spacer {
	flex: 1;
}
.dnav a.plain {
	color: var(--ink-soft);
	text-decoration: none;
	font-size: 14px;
}
.dnav a.plain:hover {
	color: var(--sprout);
}
.tbtn {
	background: none;
	border: 1px solid var(--hair-strong);
	color: var(--ink-soft);
	border-radius: 7px;
	width: 30px;
	height: 30px;
	cursor: pointer;
	font-size: 14px;
}
.tbtn:hover {
	border-color: var(--sprout);
	color: var(--sprout);
}

/* ------------------------------------------------------------------ layout */
.dlayout {
	max-width: 1320px;
	margin: 0 auto;
	padding: 0 24px;
	display: grid;
	grid-template-columns: 264px minmax(0, 1fr) 200px;
	gap: 44px;
	align-items: start;
}
@media (max-width: 1080px) {
	.dlayout {
		grid-template-columns: 240px minmax(0, 1fr);
	}
	.dtoc {
		display: none;
	}
}
@media (max-width: 780px) {
	.dlayout {
		grid-template-columns: minmax(0, 1fr);
		gap: 0;
	}
}

/* ----------------------------------------------------------------- sidebar */
.dside {
	position: sticky;
	top: 56px;
	max-height: calc(100vh - 56px);
	overflow-y: auto;
	padding: 32px 18px 64px 0;
	border-right: 1px solid var(--hair);
	font-size: 14px;
}
/* Must come AFTER the base rule above: same specificity, so source order is
   what decides. Stacked above the article, the sidebar stops being sticky —
   otherwise it floats over the prose as you scroll. */
@media (max-width: 780px) {
	.dside {
		position: static;
		max-height: none;
		overflow: visible;
		border-right: none;
		padding: 24px 0 0;
	}
	/* The rule under the nav only earns its place when the nav is showing. */
	.dside:has(.dmenu[open]) {
		border-bottom: 1px solid var(--hair);
		padding-bottom: 20px;
		margin-bottom: 24px;
	}
}
.dside h4 {
	font-family: var(--mono);
	font-size: 11px;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--muted);
	margin: 26px 0 10px;
	font-weight: 600;
}
.dside h4:first-child {
	margin-top: 0;
}
/* Labels are the doc's own H1, so a few are longer than a 264px rail. Two lines
   then an ellipsis: the list stays scannable, and every link carries its full
   title as a tooltip (see renderSidebar in build-docs.mjs) so nothing is lost. */
.dside a {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	overflow: hidden;
	padding: 5px 10px;
	margin-left: -10px;
	border-radius: 6px;
	color: var(--ink-soft);
	text-decoration: none;
	line-height: 1.4;
}
.dside a:hover {
	background: var(--panel);
	color: var(--ink);
}
.dside a.here {
	background: var(--panel);
	color: var(--sprout);
	font-weight: 600;
	box-shadow: inset 2px 0 0 var(--sprout);
}
/* The whole-sidebar disclosure. Open and chrome-less on wide screens; a real
   toggle only once the sidebar stacks above the article (see build-docs.mjs). */
.dmenu > summary {
	display: none;
}
@media (max-width: 780px) {
	.dmenu > summary {
		display: block;
		cursor: pointer;
		list-style: none;
		padding: 9px 14px;
		border: 1px solid var(--hair-strong);
		border-radius: 8px;
		background: var(--panel);
		color: var(--ink);
		font-size: 14px;
		font-weight: 600;
	}
	.dmenu > summary::-webkit-details-marker {
		display: none;
	}
	.dmenu > summary::before {
		content: "☰ ";
		color: var(--muted);
	}
	.dmenu[open] > summary::before {
		content: "✕ ";
	}
	.dmenu-in {
		padding-top: 14px;
	}
	/* With the menu shut there is nothing to divide from the article. */
	.dmenu:not([open]) {
		margin-bottom: 4px;
	}
}

.dside details {
	margin: 2px 0;
}
.dside summary {
	cursor: pointer;
	padding: 5px 10px;
	margin-left: -10px;
	border-radius: 6px;
	color: var(--ink-soft);
	list-style: none;
}
.dside summary::-webkit-details-marker {
	display: none;
}
.dside summary::before {
	content: "▸ ";
	color: var(--muted);
}
.dside details[open] > summary::before {
	content: "▾ ";
}
.dside summary:hover {
	background: var(--panel);
	color: var(--ink);
}

/* --------------------------------------------------------- article + prose */
.dmain {
	min-width: 0;
	padding: 44px 0 96px;
}
.dcrumb {
	font-family: var(--mono);
	font-size: 12px;
	color: var(--muted);
	margin-bottom: 18px;
}
.dgen {
	border: 1px solid var(--hair-strong);
	background: var(--panel);
	border-radius: 8px;
	padding: 10px 14px;
	font-size: 13px;
	color: var(--ink-soft);
	margin-bottom: 26px;
}
.dgen b {
	color: var(--ink);
}

.prose {
	max-width: 76ch;
}
.prose h1 {
	font-size: clamp(30px, 4vw, 40px);
	letter-spacing: -0.025em;
	line-height: 1.14;
	margin: 0 0 22px;
	font-weight: 680;
}
.prose h2 {
	font-size: 25px;
	letter-spacing: -0.02em;
	margin: 52px 0 16px;
	padding-top: 14px;
	border-top: 1px solid var(--hair);
	font-weight: 660;
}
.prose h3 {
	font-size: 19px;
	margin: 34px 0 12px;
	font-weight: 660;
}
.prose h4 {
	font-size: 16px;
	margin: 26px 0 10px;
	font-weight: 660;
}
.prose p,
.prose li {
	color: var(--ink-soft);
}
.prose p {
	margin: 0 0 16px;
}
.prose ul,
.prose ol {
	margin: 0 0 16px;
	padding-left: 24px;
}
.prose li {
	margin: 6px 0;
}
.prose li > ul,
.prose li > ol {
	margin: 6px 0;
}
.prose a {
	color: var(--sprout);
	text-decoration: none;
	border-bottom: 1px solid color-mix(in srgb, var(--sprout) 35%, transparent);
}
.prose a:hover {
	border-bottom-color: var(--sprout);
}
.prose strong {
	color: var(--ink);
	font-weight: 650;
}
.prose hr {
	border: none;
	border-top: 1px solid var(--hair);
	margin: 40px 0;
}
.prose blockquote {
	margin: 0 0 16px;
	padding: 2px 0 2px 18px;
	border-left: 3px solid var(--hair-strong);
	color: var(--muted);
}

.prose :not(pre) > code {
	background: var(--panel);
	border: 1px solid var(--hair);
	border-radius: 5px;
	padding: 1px 5px;
	font-size: 0.88em;
	color: var(--ink);
}
/* ------------------------------------------------------------- code blocks
   A block is a chrome bar (language + copy) over the <pre>. The bar is always
   present so the copy affordance never shifts the layout on hover. */
.codeblock {
	background: var(--code-bg);
	border: 1px solid var(--hair);
	border-radius: 10px;
	margin: 0 0 20px;
	overflow: hidden;
}
.cb-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 6px 10px 6px 16px;
	border-bottom: 1px solid #ffffff12;
	background: #ffffff08;
}
.cb-lang {
	font-family: var(--mono);
	font-size: 11px;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--code-dim);
}
.cb-copy {
	font-family: var(--mono);
	font-size: 11px;
	color: var(--code-dim);
	background: none;
	border: 1px solid #ffffff1f;
	border-radius: 6px;
	padding: 3px 10px;
	cursor: pointer;
	transition: 0.15s;
}
.cb-copy:hover {
	color: var(--code-ink);
	border-color: var(--sprout);
}
.cb-copy.ok {
	color: var(--sprout);
	border-color: var(--sprout);
}
.prose .codeblock pre {
	background: none;
	border: none;
	border-radius: 0;
	margin: 0;
	padding: 16px 18px;
}
.prose pre {
	background: var(--code-bg);
	color: var(--code-ink);
	border-radius: 10px;
	padding: 16px 18px;
	overflow-x: auto;
	margin: 0 0 20px;
	font-size: 13.5px;
	line-height: 1.6;
}
.prose pre code {
	background: none;
	border: none;
	padding: 0;
	color: inherit;
}

/* Token palette — deliberately the same one pre.code uses on the marketing
   page (styles.css), so a snippet reads identically on both surfaces. These
   are fixed hues rather than theme tokens: the code background is dark in both
   themes, so they don't need to flip. */
.prose pre .c {
	color: var(--code-dim);
}
.prose pre .k {
	color: #7fb5ff;
}
.prose pre .s {
	color: #8fd9a8;
}
.prose pre .fn2 {
	color: #e0a45c;
}
.prose pre .m {
	color: #c9a6e8;
}
.prose pre .ty {
	color: #7fd6d0;
}
.prose pre .key {
	color: #7fb5ff;
}
.prose pre .v {
	color: #c9a6e8;
}
.prose pre .fl {
	color: #e0a45c;
}
.prose pre .p {
	color: #3dbb8a;
}
.prose pre .add {
	color: #8fd9a8;
}
.prose pre .del {
	color: #e5836c;
}

/* Tables carry most of the reference docs — they must never blow out the page. */
.tablewrap {
	overflow-x: auto;
	margin: 0 0 20px;
}
.prose table {
	border-collapse: collapse;
	width: 100%;
	font-size: 14px;
}
.prose th,
.prose td {
	border: 1px solid var(--hair);
	padding: 8px 12px;
	text-align: left;
	vertical-align: top;
}
.prose th {
	background: var(--panel);
	color: var(--ink);
	font-weight: 650;
	white-space: nowrap;
}
.prose td {
	color: var(--ink-soft);
}

/* anchor affordance on headings */
.prose h2,
.prose h3,
.prose h4 {
	scroll-margin-top: 72px;
}
.prose .anchor {
	color: var(--muted);
	border: none;
	opacity: 0;
	margin-left: 8px;
	font-weight: 400;
}
.prose h2:hover .anchor,
.prose h3:hover .anchor,
.prose h4:hover .anchor {
	opacity: 1;
}

/* --------------------------------------------------------------- right toc */
.dtoc {
	position: sticky;
	top: 56px;
	max-height: calc(100vh - 56px);
	overflow-y: auto;
	padding: 44px 0 64px;
	font-size: 13px;
}
.dtoc h4 {
	font-family: var(--mono);
	font-size: 11px;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--muted);
	margin: 0 0 10px;
	font-weight: 600;
}
.dtoc a {
	display: block;
	padding: 4px 0;
	color: var(--muted);
	text-decoration: none;
	line-height: 1.4;
}
.dtoc a:hover {
	color: var(--sprout);
}
.dtoc a.lvl3 {
	padding-left: 12px;
	font-size: 12.5px;
}
/* Scroll-spy. The rail marks where you are without moving anything — a border
   on a box that already has the space, so nothing reflows as you scroll. */
.dtoc a {
	border-left: 2px solid transparent;
	padding-left: 10px;
	transition: color 0.15s, border-color 0.15s;
}
.dtoc a.lvl3 {
	padding-left: 22px;
}
.dtoc a.active {
	color: var(--sprout);
	border-left-color: var(--sprout);
}

/* ------------------------------------------------------------------ pager */
.dpager {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 14px;
	margin-top: 56px;
}
@media (max-width: 560px) {
	.dpager {
		grid-template-columns: 1fr;
	}
}
.dpage {
	display: flex;
	flex-direction: column;
	gap: 5px;
	border: 1px solid var(--hair);
	border-radius: 11px;
	padding: 14px 18px;
	text-decoration: none;
	transition: 0.16s;
}
.dpage:hover {
	border-color: var(--sprout);
	background: var(--panel);
}
.dpage.next {
	text-align: right;
	align-items: flex-end;
}
.dpage-dir {
	font-family: var(--mono);
	font-size: 11px;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--muted);
}
.dpage-t {
	color: var(--sprout);
	font-weight: 600;
	line-height: 1.35;
}
.dpage-empty {
	display: none;
}
@media (min-width: 561px) {
	/* Keep a lone "Next" on the right where it belongs. */
	.dpage-empty {
		display: block;
	}
}

/* ------------------------------------------------------------------ search */
.dsearch-open {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	background: var(--panel);
	border: 1px solid var(--hair-strong);
	border-radius: 8px;
	padding: 5px 10px;
	color: var(--muted);
	font-family: var(--sans);
	font-size: 13px;
	cursor: pointer;
	transition: 0.15s;
	min-width: 210px;
}
.dsearch-open:hover {
	border-color: var(--sprout);
	color: var(--ink);
}
.dsearch-ico {
	font-size: 15px;
	line-height: 1;
}
.dsearch-label {
	flex: 1;
	text-align: left;
}
.dsearch-open kbd {
	font-family: var(--mono);
	font-size: 10.5px;
	border: 1px solid var(--hair-strong);
	border-radius: 4px;
	padding: 1px 5px;
	color: var(--muted);
}
@media (max-width: 680px) {
	.dsearch-label,
	.dsearch-open kbd {
		display: none;
	}
	.dsearch-open {
		min-width: 0;
	}
	.dnav a.hide-sm {
		display: none;
	}
}

.dsearch {
	border: 1px solid var(--hair-strong);
	border-radius: 14px;
	padding: 0;
	width: min(640px, calc(100vw - 32px));
	max-height: min(560px, calc(100vh - 120px));
	background: var(--paper);
	color: var(--ink);
	margin-top: 10vh;
	overflow: hidden;
	box-shadow: 0 30px 80px -30px #000000aa;
}
.dsearch::backdrop {
	background: #0b100ecc;
	backdrop-filter: blur(3px);
}
.dsearch-box {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	border-bottom: 1px solid var(--hair);
}
.dsearch-box input {
	flex: 1;
	background: none;
	border: none;
	outline: none;
	color: var(--ink);
	font-family: var(--sans);
	font-size: 16px;
}
.dsearch-box input::placeholder {
	color: var(--muted);
}
.dsearch-close {
	font-family: var(--mono);
	font-size: 11px;
	color: var(--muted);
	background: none;
	border: 1px solid var(--hair-strong);
	border-radius: 5px;
	padding: 3px 8px;
	cursor: pointer;
}
.dsearch-close:hover {
	color: var(--ink);
	border-color: var(--sprout);
}
.dsearch-results {
	overflow-y: auto;
	max-height: calc(min(560px, 100vh - 120px) - 60px);
	padding: 8px;
}
.dsearch-hint {
	color: var(--muted);
	font-size: 14px;
	padding: 18px 10px;
	margin: 0;
}
.dsearch-hit {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 2px 12px;
	padding: 11px 13px;
	border-radius: 9px;
	text-decoration: none;
	color: inherit;
}
.dsearch-hit:hover,
.dsearch-hit.sel {
	background: var(--panel);
}
.dsearch-hit-t {
	font-weight: 620;
	color: var(--sprout);
	line-height: 1.35;
}
/* The section a hit deep-links at — a breadcrumb one level into the page, so the
   reader can tell "cli-reference" from "cli-reference › maxstack eject". */
.dsearch-hit-s {
	display: block;
	font-family: var(--mono);
	font-size: 11.5px;
	font-weight: 400;
	color: var(--muted);
	margin-top: 3px;
	line-height: 1.3;
}
.dsearch-hit-s::before {
	content: "› ";
	color: var(--hair-strong);
}
.dsearch-hit-g {
	font-family: var(--mono);
	font-size: 10.5px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--muted);
	white-space: nowrap;
	align-self: center;
}
.dsearch-hit-x {
	grid-column: 1 / -1;
	font-size: 13px;
	color: var(--muted);
	line-height: 1.45;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* ------------------------------------------------------------------ footer */
.dfoot {
	border-top: 1px solid var(--hair);
	margin-top: 56px;
	padding-top: 22px;
	font-size: 13px;
	color: var(--muted);
	display: flex;
	gap: 16px;
	flex-wrap: wrap;
}
.dfoot a {
	color: var(--ink-soft);
	text-decoration: none;
}
.dfoot a:hover {
	color: var(--sprout);
}
