/*
 * The documentation theme.
 *
 * One set of role tokens, two palettes: the values are the browser kit's, from
 * `lib/web/tokens.ts`, so the site and the served pages read as one product — the same
 * slate canvas and indigo accent. A token the kit does not carry is a mix of two that it
 * does, never a hand-picked colour. `test/theme.test.ts` holds both, so this file cannot
 * drift onto a palette of its own. Components reference a role, never a value.
 */

:root {
	color-scheme: light;

	--canvas: #ffffff;
	--canvas-subtle: #f6f8fa;
	--canvas-inset: #f0f2f4;
	--text: #1f2328;
	--muted: #57606a;
	--dim: #646d76;
	--border: #e6e7e7;
	--border-soft: color-mix(in srgb, var(--border) 55%, var(--canvas));
	--border-strong: #d2d3d4;
	--accent: #0969da;
	--accent-soft: rgba(9, 105, 218, 0.06);
	--success: #1a7f37;
	--success-soft: #e9f6ed;
	--warning: #9a6700;
	--warning-soft: #fff8c5;
	--danger: #cf222e;
	--danger-soft: #fcf0f1;
	--purple: #8250df;
	--code-text: #bf3989;
	--selection: color-mix(in srgb, var(--accent) 32%, var(--canvas));
	--scrim: rgba(15, 23, 42, 0.32);

	--header-height: 3.5rem;
	--sidebar-width: 15.5rem;
	--toc-width: 14rem;
	--measure: 46rem;
	--font-sans:
		-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji",
		"Segoe UI Emoji";
	--font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
	--radius: 6px;
	--radius-large: 10px;
	--shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 2px 8px rgba(16, 24, 40, 0.08);
}

:root[data-theme="dark"] {
	color-scheme: dark;

	--canvas: #0d1117;
	--canvas-subtle: #161b22;
	--canvas-inset: #21262d;
	--text: #c9d1d9;
	--muted: #8b949e;
	--dim: #868f99;
	--border: #2b3036;
	--border-soft: color-mix(in srgb, var(--border) 55%, var(--canvas));
	--border-strong: #3e4349;
	--accent: #58a6ff;
	--accent-soft: rgba(88, 166, 255, 0.08);
	--success: #3fb950;
	--success-soft: #12271a;
	--warning: #d29922;
	--warning-soft: #2a2519;
	--danger: #f85149;
	--danger-soft: #3d1a21;
	--purple: #bc8cff;
	--code-text: #f778ba;
	--selection: color-mix(in srgb, var(--accent) 32%, var(--canvas));
	--scrim: rgba(3, 6, 12, 0.62);
	--shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
	scroll-behavior: smooth;
	scroll-padding-top: calc(var(--header-height) + 1rem);
}

@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}
}

body {
	margin: 0;
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	background: var(--canvas);
	color: var(--text);
	font-family: var(--font-sans);
	font-size: 1rem;
	line-height: 1.65;
	-webkit-font-smoothing: antialiased;
}

::selection {
	background: var(--selection);
}

a {
	color: var(--accent);
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
	border-radius: 3px;
}

.skip-link {
	position: absolute;
	top: 0;
	left: 0.75rem;
	transform: translateY(-150%);
	padding: 0.5rem 1rem;
	background: var(--canvas-subtle);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	z-index: 20;
}

.skip-link:focus {
	transform: translateY(0.5rem);
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* Header ---------------------------------------------------------------- */

.header {
	position: sticky;
	top: 0;
	z-index: 10;
	background: var(--canvas);
	border-bottom: 1px solid var(--border);
}

/*
 * The band paints edge to edge; this row is the box the pages are drawn in, so the
 * brand sits on the sidebar's edge and the actions close the rail's. Viewport-wide,
 * the two drift apart on every screen past 1248px.
 */
.header-inner {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	height: var(--header-height);
	max-width: 78rem;
	margin: 0 auto;
	padding: 0 1.25rem;
}

.brand {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	flex: 0 0 auto;
	color: var(--text);
	font-weight: 650;
	letter-spacing: -0.01em;
}

.brand:hover {
	text-decoration: none;
}

.brand-mark {
	color: var(--accent);
	font-family: var(--font-mono);
	font-weight: 700;
}

.brand-name {
	font-size: 0.95rem;
}

.search {
	position: relative;
	flex: 1 1 24rem;
	min-width: 0;
	max-width: 32rem;
}

/*
 * The glyph is a mask filled by a role, so it follows the palette. As a stroke baked
 * into the field's background it froze one theme's grey.
 */
.search::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 0.55rem;
	width: 1rem;
	height: 1rem;
	transform: translateY(-50%);
	background-color: var(--dim);
	-webkit-mask:
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E")
		no-repeat center / contain;
	mask:
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E")
		no-repeat center / contain;
	pointer-events: none;
}

.search-input {
	width: 100%;
	height: 2.25rem;
	padding: 0 1.85rem 0 2rem;
	color: var(--text);
	background: var(--canvas-subtle);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font: inherit;
	font-size: 0.9rem;
}

/*
 * The shortcut's hint, so the key is discoverable without a click. It leaves while the reader
 * is in the field: there it covers the caret's line, and a reader already typing needs no
 * telling.
 */
.search-hint {
	position: absolute;
	top: 50%;
	right: 0.55rem;
	transform: translateY(-50%);
	padding: 0 0.3rem;
	color: var(--dim);
	background: var(--canvas);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	font-family: var(--font-mono);
	font-size: 0.75rem;
	line-height: 1.5;
	pointer-events: none;
}

.search-input:focus ~ .search-hint,
.search-input:not(:placeholder-shown) ~ .search-hint {
	opacity: 0;
}

@media (max-width: 40rem) {
	/* The field has no room for the hint beside the query once the header narrows. */
	.search-hint {
		display: none;
	}
}

.search-input:focus {
	border-color: var(--accent);
}

.search-results {
	position: absolute;
	top: calc(100% + 0.35rem);
	right: 0;
	left: 0;
	max-height: min(70vh, 28rem);
	margin: 0;
	padding: 0.35rem;
	overflow-y: auto;
	list-style: none;
	background: var(--canvas);
	border: 1px solid var(--border);
	border-radius: var(--radius-large);
	box-shadow: var(--shadow);
}

.search-results li {
	margin: 0;
}

.search-result {
	display: block;
	padding: 0.5rem 0.6rem;
	border-radius: var(--radius);
	color: var(--text);
}

.search-result:hover,
.search-result.is-selected {
	background: var(--canvas-subtle);
	text-decoration: none;
}

.search-result-group {
	display: block;
	color: var(--dim);
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.search-result-title {
	font-weight: 600;
}

.search-result-summary {
	display: block;
	color: var(--muted);
	font-size: 0.85rem;
	line-height: 1.45;
}

.search-empty {
	padding: 0.6rem;
	color: var(--muted);
	font-size: 0.9rem;
}

.header-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	flex: 0 0 auto;
	padding: 0;
	color: var(--muted);
	background: transparent;
	border: 1px solid transparent;
	border-radius: var(--radius);
	font: inherit;
	font-size: 1rem;
	cursor: pointer;
}

.header-button:hover {
	color: var(--text);
	background: var(--canvas-subtle);
	border-color: var(--border);
}

/* The field grows to its cap and the leftover width becomes the gap before the
   actions, which is where a phone already holds them. */
.theme-toggle {
	margin-left: auto;
}

.nav-toggle {
	display: none;
}

/* Shell and sidebar ----------------------------------------------------- */

.shell {
	display: grid;
	grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
	gap: 2.5rem;
	flex: 1;
	width: 100%;
	max-width: 78rem;
	margin: 0 auto;
	padding: 0 1.25rem;
}

.nav {
	position: sticky;
	top: var(--header-height);
	align-self: start;
	max-height: calc(100vh - var(--header-height));
	padding: 1.75rem 0.75rem 2rem 0;
	overflow-y: auto;
	border-right: 1px solid var(--border);
}

.nav-scrim {
	display: none;
}

body.is-nav-open {
	overflow: hidden;
}

.nav-group + .nav-group {
	margin-top: 1.35rem;
}

.nav-group-title {
	margin: 0 0 0.4rem;
	color: var(--dim);
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.07em;
	text-transform: uppercase;
}

.nav-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.nav-link {
	display: block;
	margin: 0 -0.5rem;
	padding: 0.28rem 0.5rem;
	border-radius: var(--radius);
	color: var(--muted);
	font-size: 0.925rem;
}

.nav-link:hover {
	color: var(--text);
	background: var(--canvas-subtle);
	text-decoration: none;
}

.nav-link.is-active {
	color: var(--text);
	background: var(--accent-soft);
	font-weight: 600;
}

/* Content --------------------------------------------------------------- */

.content {
	min-width: 0;
	padding: 2.25rem 0 3rem;
}

.page {
	max-width: var(--measure);
}

.prose {
	overflow-wrap: break-word;
}

.prose > :first-child {
	margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
	margin: 2.2em 0 0.7em;
	line-height: 1.25;
	letter-spacing: -0.01em;
	scroll-margin-top: calc(var(--header-height) + 1rem);
}

.prose h1 {
	margin-top: 0;
	font-size: clamp(1.85rem, 1.4rem + 1.6vw, 2.4rem);
	font-weight: 720;
}

.prose h2 {
	padding-bottom: 0.3rem;
	border-bottom: 1px solid var(--border-soft);
	font-size: 1.45rem;
	font-weight: 680;
}

.prose h3 {
	font-size: 1.15rem;
	font-weight: 650;
}

.prose h4 {
	color: var(--muted);
	font-size: 1rem;
	font-weight: 650;
}

.prose p,
.prose ul,
.prose ol,
.prose dl {
	margin: 0 0 1rem;
}

.prose ul,
.prose ol {
	padding-left: 1.4rem;
}

.prose li + li {
	margin-top: 0.3rem;
}

.prose li > ul,
.prose li > ol {
	margin: 0.3rem 0 0;
}

.prose strong {
	font-weight: 650;
}

.prose hr {
	height: 1px;
	margin: 2.5rem 0;
	background: var(--border-soft);
	border: 0;
}

.prose img {
	display: block;
	max-width: 100%;
	height: auto;
	margin: 1.5rem 0;
	background: var(--canvas-subtle);
	border: 1px solid var(--border);
	border-radius: var(--radius-large);
}

.prose figure {
	margin: 1.75rem 0;
}

.prose figcaption {
	margin-top: 0.5rem;
	color: var(--muted);
	font-size: 0.85rem;
	text-align: center;
}

.prose blockquote {
	margin: 1.5rem 0;
	padding: 0.75rem 1rem;
	color: var(--muted);
	background: var(--canvas-subtle);
	border-left: 3px solid var(--border-strong);
	border-radius: 0 var(--radius) var(--radius) 0;
}

.prose blockquote > :last-child {
	margin-bottom: 0;
}

.prose kbd {
	padding: 0.1rem 0.4rem;
	background: var(--canvas-subtle);
	border: 1px solid var(--border);
	border-bottom-width: 2px;
	border-radius: 4px;
	font-family: var(--font-mono);
	font-size: 0.82em;
}

.prose code {
	padding: 0.12em 0.35em;
	color: var(--code-text);
	background: var(--canvas-subtle);
	border-radius: 4px;
	font-family: var(--font-mono);
	font-size: 0.875em;
}

.prose pre {
	margin: 1.5rem 0;
	padding: 1rem 1.1rem;
	overflow-x: auto;
	color: var(--text);
	background: var(--canvas-inset);
	border: 1px solid var(--border);
	border-radius: var(--radius-large);
	font-size: 0.85rem;
	line-height: 1.55;
	tab-size: 2;
}

.prose pre code {
	padding: 0;
	color: inherit;
	background: none;
	font-size: inherit;
}

.prose table {
	display: block;
	width: max-content;
	max-width: 100%;
	margin: 1.5rem 0;
	overflow-x: auto;
	border-collapse: collapse;
	font-size: 0.9rem;
}

.prose th,
.prose td {
	padding: 0.5rem 0.75rem;
	text-align: left;
	vertical-align: top;
	border: 1px solid var(--border);
}

.prose th {
	background: var(--canvas-subtle);
	font-weight: 650;
	white-space: nowrap;
}

.prose tbody tr:nth-child(even) {
	background: var(--canvas-subtle);
}

.prose details {
	margin: 1.25rem 0;
	padding: 0.5rem 1rem;
	background: var(--canvas-subtle);
	border: 1px solid var(--border);
	border-radius: var(--radius-large);
}

.prose summary {
	cursor: pointer;
	font-weight: 600;
}

/* Previous and next ----------------------------------------------------- */

.pager {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.75rem;
	max-width: var(--measure);
	margin: 3.5rem 0 0;
	padding-top: 1.5rem;
	border-top: 1px solid var(--border-soft);
}

.pager a {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	padding: 0.75rem 1rem;
	border: 1px solid var(--border);
	border-radius: var(--radius-large);
	color: var(--text);
}

.pager a:hover {
	border-color: var(--border-strong);
	text-decoration: none;
}

.pager-next {
	grid-column: 2;
	text-align: right;
}

.pager-label {
	color: var(--dim);
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.pager-title {
	color: var(--accent);
	font-weight: 600;
}

/* On this page ---------------------------------------------------------- */

.toc {
	position: sticky;
	top: var(--header-height);
	align-self: start;
	max-height: calc(100vh - var(--header-height));
	padding: 2.25rem 0 2rem 0.5rem;
	overflow-y: auto;
	font-size: 0.85rem;
}

.toc-title {
	margin: 0 0 0.5rem;
	color: var(--dim);
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.07em;
	text-transform: uppercase;
}

.toc-links {
	display: flex;
	flex-direction: column;
	gap: 0.1rem;
	border-left: 1px solid var(--border-soft);
}

.toc-link {
	padding: 0.2rem 0 0.2rem 0.75rem;
	margin-left: -1px;
	border-left: 2px solid transparent;
	color: var(--muted);
	line-height: 1.4;
}

.toc-link:hover {
	color: var(--text);
	text-decoration: none;
}

.toc-link.is-active {
	color: var(--accent);
	border-left-color: var(--accent);
}

.toc-link.is-nested {
	padding-left: 1.6rem;
	font-size: 0.8rem;
}

/* Footer ---------------------------------------------------------------- */

/*
 * The band paints edge to edge, like the masthead's; this row is the box the pages
 * are drawn in, so the licence line sits on the sidebar's edge and the links close
 * the rail's. Measured from the viewport they drift apart on every screen past
 * 1288px: 96px at 1440, and 336px at 1920.
 */
.footer {
	margin-top: 2rem;
	border-top: 1px solid var(--border);
	color: var(--muted);
	font-size: 0.85rem;
}

.footer-inner {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem 1.5rem;
	align-items: center;
	justify-content: space-between;
	max-width: 78rem;
	margin: 0 auto;
	padding: 1.5rem 1.25rem 2.5rem;
}

.footer-line {
	margin: 0;
}

.footer-brand {
	color: var(--text);
	font-weight: 600;
}

.footer-links {
	display: flex;
	flex-wrap: wrap;
	gap: 1rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Wide screens get the on-this-page rail -------------------------------- */

@media (min-width: 78rem) {
	.shell {
		grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
	}
}

@media (max-width: 77.99rem) {
	.toc {
		display: none;
	}
}

/* Narrow screens fold the sidebar into a drawer ------------------------- */

@media (max-width: 59.99rem) {
	.header-inner {
		gap: 0.5rem;
		padding: 0 1rem;
	}

	.brand-name {
		font-size: 0.9rem;
	}

	.nav-toggle {
		display: inline-flex;
	}

	.nav-toggle[aria-expanded="true"] {
		color: var(--text);
		background: var(--canvas-subtle);
		border-color: var(--border);
	}

	/* A wide screen anchors the results to the field; a phone's field is a third
	   of the width, so they take the viewport instead of wrapping every summary
	   into a ribbon. The header is sticky at the top, which is where `top` puts
	   them either way the browser resolves the containing block. */
	.search-results {
		position: fixed;
		top: var(--header-height);
		right: 0.75rem;
		left: 0.75rem;
	}

	/* A phone shows no scrollbar over a code block, so an overflowing command is
	   cut with nothing to say it continues; wrap it instead. The two fenced
	   diagrams are laid out in columns, so they keep their shape and scroll. */
	.prose pre {
		white-space: pre-wrap;
		overflow-wrap: anywhere;
	}

	.prose pre code.language-mermaid {
		white-space: pre;
		overflow-wrap: normal;
	}

	.nav-scrim {
		position: fixed;
		inset: var(--header-height) 0 0;
		z-index: 8;
		display: block;
		background: var(--scrim);
	}

	.nav-scrim[hidden] {
		display: none;
	}

	.shell {
		grid-template-columns: minmax(0, 1fr);
		gap: 0;
		padding: 0 1rem;
	}

	.nav {
		position: fixed;
		inset: var(--header-height) auto 0 0;
		z-index: 9;
		display: none;
		width: min(85vw, 20rem);
		max-height: calc(100vh - var(--header-height));
		padding: 1rem 1rem 2rem;
		background: var(--canvas);
		border-right: 1px solid var(--border);
		border-bottom: 1px solid var(--border);
		box-shadow: var(--shadow);
	}

	.nav.is-open {
		display: block;
	}

	.content {
		padding-top: 1.5rem;
	}

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

	.pager-next {
		grid-column: 1;
	}

	.footer-inner {
		padding: 1.5rem 1rem 2.5rem;
	}

	/* The footer's links are the last thing a thumb reaches, and 13.6px of text is
	   a 22px target; the pad grows each one to a touch's height and the row gap
	   keeps them from reading as one. */
	.footer-links {
		gap: 0.25rem 1rem;
	}

	.footer-links a {
		display: inline-block;
		padding: 0.65rem 0;
	}
}

/* A 320px phone has no width to spare and the brand name is the only thing that can
   give way; the mark keeps the link and its aria-label keeps the name. */
@media (max-width: 22rem) {
	.brand-name {
		display: none;
	}
}

@media print {
	.header,
	.nav,
	.toc,
	.pager,
	.footer {
		display: none;
	}

	.shell {
		display: block;
		max-width: none;
		padding: 0;
	}

	.prose pre,
	.prose table {
		white-space: pre-wrap;
	}
}
