/* ── The site's own measurements ──────────────────────────────────
   Wider than `--ui-container`: documentation reads in two columns —
   a navigation tree and an article — where an application screen is
   one. The three surfaces are named so `_template.md` can retint
   them per theme without touching a rule. */
:root {
	--kb-max-width: 75rem;
	--kb-sidebar-width: 16.25rem;
	--kb-nav-background: var(--ui-surface-raised);
	--kb-sidebar-background: transparent;
	--kb-hero-background: var(--ui-surface-sunken);
	/* what a table widened past the prose measure keeps clear of
	   the content column's right edge (and its scrollbar) */
	--kb-table-gutter: var(--ui-space-large);

	/* Code-block colours (CodeHighlighter's `hl-*` classes), drawn from
	   the system's semantic tokens so both themes and the site's accent
	   come for free; `_template.md`'s `code-*-color` keys retint them.
	   Types are the accent mixed with red, because the system's info
	   blue is the default accent's blue. "Variable" is also a JSON or
	   YAML key and a shell `$VAR`. */
	--kb-code-comment: var(--ui-text-subtle);
	--kb-code-keyword: var(--ui-accent-text);
	--kb-code-type: color-mix(in oklab, var(--ui-accent-text), var(--ui-danger-text));
	--kb-code-string: var(--ui-success-text);
	--kb-code-number: var(--ui-warning-text);
	--kb-code-meta: var(--ui-text-muted);
	--kb-code-variable: var(--ui-info-text);
}

/* ── The frame ────────────────────────────────────────────────────
   The page itself never scrolls: the bar and the footer stay put and
   the two columns scroll independently, so a reader loses neither
   the article they are in nor the tree around it. */
html {
	height: 100vh;
	overflow: hidden;
}

body {
	height: 100vh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

/* The two panes scroll with the shared system's `ui-scroll`, which is
   also where their scrollbar treatment comes from — the generator
   puts the class on both, so there is no second opinion here about
   what a scrollbar looks like. */

/* ── Navigation bar ───────────────────────────────────────────────
   The bar is `.ui-navbar` from the shared system; these rules only
   place it and hold the parts the system has no component for.

   Two rules hold for ANY bar, the generated one and a site's own
   `_navbar.html` alike: it sits at the top of the frame, and it takes
   the documentation site's background (and the rule beneath it) — the
   one thing a borrowed bar is expected to change. Everything else here is the GENERATED bar's
   own measurements (it is the bar with `.nav-inner` in it), so a
   custom bar keeps the height, padding and placement it has on the
   site it was borrowed from. */
.ui-navbar {
	background: var(--kb-nav-background);
	/* The rule under the bar is drawn against THIS site's background,
	   so it takes this site's border colour too — a borrowed bar that
	   brings its own rule in its own background's colour (engeene's
	   does) would otherwise vanish against ours. */
	border-block-end-color: var(--ui-border);
	position: sticky;
	top: 0;
	z-index: var(--ui-z-sticky);
}

.ui-navbar:has(> .nav-inner) {
	/* Stated rather than left to the tallest thing in the bar: an
	   application that serves pages of its own beside this site
	   repeats the bar there, and can only match a height that is
	   a number. */
	--ui-navbar-height: 4rem;
	/* The bar spans the window; `.nav-inner` is what holds the
	   content to the page's measure, so the padding belongs there
	   and not on both. */
	padding-inline: 0;
}

.nav-inner {
	max-width: var(--kb-max-width);
	margin: 0 auto;
	width: 100%;
	display: flex;
	align-items: center;
	gap: var(--ui-space-normal);
	padding-inline: var(--ui-space-normal);
}

/* Tone and size are `ui-muted ui-text-sm` on the element itself; only
   its place in the bar is decided here. */
.nav-heading {
	flex: 1;
	text-align: center;
}

/* In the generated bar the heading is also the shared
   `.ui-navbar-collapse` (a flex row): what it holds fills it, so a
   line of text is still centred and a `ui-nav` of tabs still runs
   from its start. */
.nav-heading > * {
	flex: 1 1 auto;
}

.nav-heading p {
	margin-bottom: 0;
	display: inline;
}

.nav-buttons {
	display: flex;
	gap: var(--ui-space-small);
	align-items: center;
}

/* Pushed to the far end of the generated bar. In a custom bar the
   markup's own layout places the slot — a second auto margin there
   would split the free space with the bar's own hamburger. */
.nav-inner > .nav-buttons {
	margin-inline-start: auto;
}

/* In a custom bar the controls are the bar's own flex items: a
   wrapper there would add one more gap even with nothing in it shown
   (the sidebar button is a phone's, the site menu pinned outside the
   bar), and the bar would no longer lay out as on its own site. */
.ui-navbar:not(:has(.nav-inner)) .nav-buttons {
	display: contents;
}

/* ── Site menu ────────────────────────────────────────────────────
   A square, icon-only ghost button (sliders, "settings") opening a panel of
   the site's own settings — the theme and, on a site in several
   languages, the language. It is the last of the bar's controls;
   script.js reveals the theme (written `hidden`, as is a menu holding
   nothing else — the languages are links that need no script) and,
   when the window leaves room right of the bar's content, `pinned`
   takes it out of the bar's flow to the window's right edge, centred
   on the bar (the script sets `top` and `height` to the bar's), so a
   borrowed bar lays out exactly as on its own site. The shared system
   draws every <details> as a card; in the bar it is only the button,
   so the card is taken off again. */
.site-menu {
	position: relative;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	/* its button's width, never a row of the bar's own */
	flex: none;
	width: max-content;
}

.site-menu[hidden] {
	display: none;
}

.site-menu > summary {
	width: 2.5rem;
	height: 2.5rem;
	padding: 0;
	justify-content: center;
	list-style: none;
	cursor: pointer;
}

.site-menu > summary::-webkit-details-marker,
.site-menu > summary::before,
.site-menu > summary::after {
	display: none;
}

.site-menu[open] > summary {
	margin-block-end: 0;
}

.site-menu.pinned {
	position: fixed;
	inset-inline-end: 0;
	display: flex;
	align-items: center;
	padding-inline: var(--ui-space-small);
	z-index: calc(var(--ui-z-sticky) + 1);
}

.site-menu-panel {
	position: absolute;
	inset-inline-end: 0;
	top: 100%;
	z-index: var(--ui-z-popover);
	min-width: 12rem;
	margin: var(--ui-space-1) 0 0;
	padding: var(--ui-space-small);
	background: var(--ui-surface-raised);
	border: 1px solid var(--ui-border);
	border-radius: var(--ui-radius-sm);
	box-shadow: var(--ui-shadow-md);
	/* a site in a dozen languages still fits a short window */
	max-height: 70vh;
	overflow-y: auto;
}

/* the language group under the theme, set apart by a rule */
.theme-choice:not([hidden]) + .language-choice {
	margin-block-start: var(--ui-space-small);
	padding-block-start: var(--ui-space-small);
	border-block-start: 1px solid var(--ui-border);
}

.site-menu.pinned > .site-menu-panel {
	inset-inline-end: var(--ui-space-small);
}

.site-menu-heading {
	margin: 0 0 var(--ui-space-1);
	padding-inline: var(--ui-space-small);
	color: var(--ui-text-muted);
	font-size: var(--ui-text-small);
}

/* one row per choice, a check mark before the one in use */
.site-menu-item {
	width: 100%;
	justify-content: flex-start;
}

.site-menu-item::before {
	content: "";
	width: 1em;
	flex: none;
}

.site-menu-item[aria-pressed="true"],
.site-menu-item[aria-current="true"] {
	--ui-btn-color: var(--ui-accent-text);
}

.site-menu-item[aria-pressed="true"]::before,
.site-menu-item[aria-current="true"]::before {
	content: "\2713";
}

/* ── Search ───────────────────────────────────────────────────────
   The box at the top of the sidebar (written hidden, revealed by
   script.js, so a reader without JavaScript never sees a box that
   does nothing) and its results, dropping below it over the page
   like the site menu's panel — wider than the column, so they
   overlap the article rather than squeezing into the tree. */
.search {
	position: relative;
	flex-shrink: 0;
	margin-block-end: var(--ui-space-normal);
}

.search[hidden],
.search-results[hidden] {
	display: none;
}

.search input {
	width: 100%;
}

.search-results {
	position: absolute;
	inset-inline-start: 0;
	top: 100%;
	z-index: var(--ui-z-popover);
	width: min(32rem, calc(100vw - 2 * var(--ui-space-normal)));
	max-height: 70vh;
	overflow-y: auto;
	margin: var(--ui-space-1) 0 0;
	padding: var(--ui-space-small);
	list-style: none;
	background: var(--ui-surface-raised);
	border: 1px solid var(--ui-border);
	border-radius: var(--ui-radius-sm);
	box-shadow: var(--ui-shadow-lg);
}

.search-results a {
	display: block;
	padding: var(--ui-space-small);
	border-radius: var(--ui-radius-sm);
	color: var(--ui-text);
	text-decoration: none;
}

.search-results a:hover,
.search-results [aria-selected="true"] a {
	background: var(--ui-surface-hover);
}

.search-result-title {
	display: block;
	font-weight: var(--ui-weight-medium);
}

.search-result-snippet,
.search-empty {
	display: block;
	font-size: var(--ui-text-small);
	color: var(--ui-text-muted);
}

.search-empty {
	padding: var(--ui-space-small);
}

.search-results mark {
	background: var(--ui-accent-soft);
	color: inherit;
	border-radius: var(--ui-radius-sm);
}

/* ── The two columns ──────────────────────────────────────────── */
.container {
	max-width: var(--kb-max-width);
	margin: 0 auto;
	padding: var(--ui-space-none) var(--ui-space-normal);
	display: flex;
	gap: var(--ui-space-12);
	flex: 1;
	width: 100%;
	overflow: hidden;
	min-height: 0;
}

/* The column is the search box over the tree. Only the tree
   scrolls: the box stays at the top, and its results may spill
   out of the column over the article instead of being clipped by
   a scrolling parent. */
.sidebar {
	width: var(--kb-sidebar-width);
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	min-height: 0;
	background: var(--kb-sidebar-background);
	padding-block-start: var(--ui-space-normal);
}

.sidebar > nav {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding-block-end: var(--ui-space-large);
}

/* The tree is the shared `ui-tree` (one `ul.ui-tree` per level, a
   section a bare `<details>` in a `ui-tree-item` whose summary is the
   row): the shared system takes the card off a branch, spaces the
   items and keeps an open section's heading on the tree's rhythm
   rather than a card's gap — so none of that is restated here. What
   this site changes is the marker and the step: a section's heading
   starts where an article beside it starts, its marker is a chevron at
   the row's end, and an open section's rows hang off a thin line. */

/* Sentence case, deliberately: the shared design system upper-cases
   nothing, and a knowledgebase ships in languages where upper-casing
   DESTROYS information — Turkish dotted/dotless i, German ß, every
   accented Greek vowel. The tracking went with it; it existed only to
   make the upper-cased run legible. */
.sidebar summary {
	font-size: var(--ui-text-small);
	color: var(--ui-text-muted);
	cursor: pointer;
	padding: 0;
	user-select: none;
}

.sidebar summary:hover {
	color: var(--ui-text);
}

/* Every article link is the shared `ui-nav-link`, including its
   hover and its `[aria-current]` state — so "you are here" looks the
   same in a knowledgebase sidebar as in an application's navigation.
   The one thing added is filling the column: the shared component is
   built for a row of links in a bar. */
.sidebar .ui-nav-link {
	display: block;
}

/* A section's own link is a `ui-nav-link` too, so hovering it fills the
   row with the shared hover surface and never underlines it, and being
   on the section's page marks it current exactly like an article. It
   fills the row up to the chevron, which still folds the section
   without leaving the page. */
.sidebar .section-link {
	flex: 1;
	min-width: 0;
	color: var(--ui-text);
	font-weight: var(--ui-weight-bold);
}

/* The base layer's marker (`summary::before`, a triangle at the
   start) becomes a chevron at the end: moved after the link with
   `order`, so the heading's text lines up with the articles beside it,
   and drawn as two borders of a square turned to point along the line
   (down when open). Logical borders mirror it in a right-to-left
   language; only the turn needs its own sign there. */
.sidebar summary::before {
	order: 1;
	inline-size: 0.4em;
	block-size: 0.4em;
	margin-inline: var(--ui-space-small);
	border: none;
	border-inline-end: 1.5px solid currentColor;
	border-block-end: 1.5px solid currentColor;
	transform: rotate(-45deg);
}

.sidebar details[open] > summary::before {
	transform: rotate(45deg);
}

.sidebar summary:dir(rtl)::before {
	transform: rotate(45deg);
}

.sidebar details[open] > summary:dir(rtl)::before {
	transform: rotate(-45deg);
}

/* An open section's rows hang off a thin line just before the
   heading's text, the line and the gap after it together about the
   one tree step the theme takes. */
.sidebar details[open] > .ui-tree {
	margin-inline-start: var(--ui-space-small);
	padding-inline-start: var(--ui-space-small);
	border-inline-start: 1px solid var(--ui-border);
}

.sidebar a:hover {
	text-decoration: none;
}

.content {
	flex: 1;
	min-width: 0;
	overflow-y: auto;
	padding-block: var(--ui-space-normal) var(--ui-space-large);
	container-type: inline-size;
	/* The strip the table of contents takes (`--kb-toc-room`, set by
	   script.js while the window leaves room for it) is given up by the
	   column, so its scrollbar runs beside the article and never
	   between the article and the contents. */
	margin-inline-end: var(--kb-toc-room, 0px);
}

/* What follows an article in its column — the rating bar, the article
   navigation — stays at the column's bottom when the article is
   shorter than the window: the article takes the room left over. The
   article itself stays a block, so the margins of its text still
   collapse; an `_article-footer.md` is part of it and stays with the
   text. Only an article's column: the hero and not-found columns keep
   their flow. The bottom padding is the space the bar leaves above
   its buttons, so on a short article the bar sits as close to the
   window's edge as to its own line. */
.content:has(> article) {
	display: flex;
	flex-direction: column;
	padding-block-end: var(--ui-space-normal);
}

.content > article {
	flex: 1 0 auto;
}

/* ── Tables ───────────────────────────────────────────────────────
   Every table is written in the shared `.ui-table-scroll`
   (KnowledgebaseMarkdownRenderer.wrapTables). One that needs more
   room than the prose measure takes it from the content column
   (`100cqi`, measured by `.content` above) instead of wrapping every
   cell; only one wider than the column scrolls — on its own, never
   the article. Either stops `--kb-table-gutter` short of the column's
   right edge, so it never runs into the scrollbar — and the column
   ends short of the table of contents, so neither does the table. A narrow table
   still fills the measure, and one in a list or a quote stays inside it. `.content` is a size container,
   so nothing inside it may be `position: fixed` (the term panel
   lives on `<body>`). */
.content article > .ui-table-scroll {
	width: max-content;
	min-width: 100%;
	max-width: calc(100cqi - var(--kb-table-gutter));
}

/* A Markdown column alignment (`---:`, `:---:`) is written as the
   cell's `align` attribute, a presentational hint that the theme's
   `th, td { text-align: start }` would otherwise override — and an
   inline `style` is refused under a `style-src 'self'` policy. */
.content th[align="right"], .content td[align="right"] {
	text-align: end;
}

.content th[align="center"], .content td[align="center"] {
	text-align: center;
}

/* ── Landing page ──────────────────────────────────────────────────
   Only a base with no articles at all has one of its own: the root
   otherwise opens the first article of the navigation.

   The hero carries `ui-surface-sunken`; `--kb-hero-background` is
   here only so a template can retint that one block without
   retinting every sunken surface on the site. */
.hero {
	background: var(--kb-hero-background);
	padding: var(--ui-space-10);
	border-radius: var(--ui-radius-lg);
	margin-bottom: var(--ui-space-10);
}

.hero h1 {
	margin-block: var(--ui-space-none) var(--ui-space-small);
}

.hero p {
	color: var(--ui-text-muted);
	font-size: var(--ui-text-large);
	margin-bottom: 0;
}

/* ── Article ──────────────────────────────────────────────────────
   The article element carries `ui-prose ui-markdown ui-markdown-spacious`:
   the measure is `ui-prose`, and the vertical rhythm of the RENDERED
   markdown — every heading, paragraph, list, quote, `code` and `pre` — is
   `ui-markdown`, opened up by `ui-markdown-spacious` because an article
   is the whole page rather than a note in a card. More or less air above
   a heading, between paragraphs or around a picture is a change to that
   variant in `theme.css`, never a margin here.
   The generator emits those children, so nothing at the call site can
   put a class on them and the rhythm has to be stated by element,
   which is exactly what that component is for. This file used to be
   the third copy of it (beside an application's markdown viz and a
   marketing site's legal pages); it states none of it now.

   Left here: deep-linking only. The `h4`–`h6` continuation this file
   carried as a gap-filler is gone — `ui-theme` scales the whole
   outline now, so keeping a local copy would make this the second
   opinion the paragraph above says it no longer is. */
article h1[id], article h2[id], article h3[id],
article h4[id], article h5[id], article h6[id] {
	scroll-margin-top: var(--ui-space-normal);
}

/* The actions `script.js` appends to every article heading: `#` links to the
   heading and copies that link, the copy icon copies the section. Both show
   a check mark once the clipboard took it. Each sits in a fixed 1em square,
   so the `#`, the copy icon and the check mark are all one size and the
   swap never moves the heading. `.ui-markdown a` underlines every link in
   the article, so the selectors are qualified to outrank it. */
.heading-actions {
	margin-left: var(--ui-space-small);
	font-weight: var(--ui-weight-normal);
	white-space: nowrap;
	opacity: 0;
	transition: opacity var(--ui-transition);
}

.heading-actions .heading-action {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: content-box;
	width: 1em;
	height: 1em;
	vertical-align: middle;
	padding: 0 0.15em;
	border: 0;
	background: none;
	font: inherit;
	color: var(--ui-text-muted);
	text-decoration: none;
	cursor: pointer;
	opacity: 0.6;
}

/* outlines: the shared system fills every button svg */
.heading-actions .heading-action svg {
	flex: none;
	width: 0.8em;
	height: 0.8em;
	fill: none;
}

article h1:hover .heading-actions,
article h2:hover .heading-actions,
article h3:hover .heading-actions,
article h4:hover .heading-actions,
article h5:hover .heading-actions,
article h6:hover .heading-actions,
.heading-actions:focus-within,
.heading-actions .copied {
	opacity: 1;
}

.heading-actions .heading-action:hover,
.heading-actions .heading-action:focus-visible,
.heading-actions .copied {
	opacity: 1;
	color: var(--ui-text);
}

/* ── Sticky headings ──────────────────────────────────────────────
   On a column with `data-sticky-headings` (`sticky-headings: true`)
   every heading of the article sticks at the column's top; script.js
   sets each one's `top` — below the headings it sits under, lowered
   as the next heading of its level or above comes up, so that one
   pushes it off. A deeper heading slides under a shallower one
   (`z-index` by level). Each is painted in the page's background,
   carried past its box by a border image that takes no room: across
   the column, so a wide table never shows beside it, and a small gap
   above and below, which script.js reads as the space it leaves
   between two stacked headings — the article's rhythm is unchanged.
   A window too short for a stack leaves the headings in the flow, and
   script.js lifts the stickiness while it measures where they sit. */
@media (min-height: 30rem) {
	.content[data-sticky-headings] article :is(h1, h2, h3, h4, h5, h6)[id]:not(.article-header *, .article-footer *) {
		position: sticky;
		top: 0;
		border-image: conic-gradient(var(--ui-body-background) 0 0) fill 0 / 0 / var(--ui-space-1) 100vw;
	}

	.content[data-sticky-headings] article h1[id] { z-index: 6; }
	.content[data-sticky-headings] article h2[id] { z-index: 5; }
	.content[data-sticky-headings] article h3[id] { z-index: 4; }
	.content[data-sticky-headings] article h4[id] { z-index: 3; }
	.content[data-sticky-headings] article h5[id] { z-index: 2; }
	.content[data-sticky-headings] article h6[id] { z-index: 1; }

	.content[data-sticky-headings] article.sticky-measuring :is(h1, h2, h3, h4, h5, h6)[id] {
		position: static;
	}
}

/* ── Page and article furniture ─────────────────────────────────── */
.page-header {
	flex: 1;
	text-align: center;
}

.page-footer {
	border-top: 1px solid var(--ui-border);
	padding: var(--ui-space-small) var(--ui-space-normal);
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: var(--ui-space-normal);
}

.page-footer-right {
	text-align: right;
}

.page-header p,
.page-footer p,
.page-footer-right p {
	margin-bottom: 0;
	font-size: var(--ui-text-small);
	color: var(--ui-text-muted);
}

.page-header p {
	display: inline;
}

/* instant navigation moves focus to the article it swapped in, so a screen reader reads on from
   there; the article is a reading position, not a control, and draws no focus ring */
.content article[tabindex="-1"]:focus {
	outline: none;
}

.article-header {
	border-bottom: 1px solid var(--ui-border);
	padding-bottom: var(--ui-space-normal);
	margin-bottom: var(--ui-space-normal);
}

.article-footer {
	border-top: 1px solid var(--ui-border);
	padding-top: var(--ui-space-normal);
	margin-top: var(--ui-space-large);
}

/* ── Article rating ───────────────────────────────────────────────
   One narrow line under the article (ArticleRating): a prompt and a
   button group, one step shown at a time, and the Chat button at the
   line's end once a chat script has announced itself. Written
   `hidden`; the steps' display beats the attribute, so it is restated. */
.article-rating {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--ui-space-small) var(--ui-space-normal);
	max-width: var(--ui-prose);
	margin-top: var(--ui-space-large);
	padding-top: var(--ui-space-normal);
	border-top: 1px solid var(--ui-border);
	font-size: var(--ui-text-small);
}

.article-rating-step {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--ui-space-small) var(--ui-space-normal);
}

.article-rating-step:focus {
	outline: none;
}

.article-rating-prompt {
	color: var(--ui-text-muted);
}

/* the reasons, too wide for a phone's column, come apart into separate buttons rather
   than wrapping a joined group with its corners in the wrong places */
@container (max-width: 36rem) {
	[data-rating-step="reason"] [role="group"] {
		flex-wrap: wrap;
		gap: var(--ui-space-1);
	}

	[data-rating-step="reason"] [role="group"] > button {
		margin-inline-start: 0;
		border-radius: var(--ui-radius-md);
	}
}

.article-rating button > svg.article-rating-double {
	width: calc(var(--ui-icon-small) * 1.5);
}

.article-rating-chat {
	margin-inline-start: auto;
}

.article-rating[hidden],
.article-rating [hidden] {
	display: none;
}

.article-nav {
	display: flex;
	justify-content: space-between;
	margin-top: var(--ui-space-12);
	padding-top: var(--ui-space-normal);
	border-top: 1px solid var(--ui-border);
	gap: var(--ui-space-normal);
}

.article-nav a {
	font-weight: var(--ui-weight-medium);
}

.article-nav-next {
	margin-left: auto;
}

/* ── Selection highlight for #text= links ──────────────────────────
   Deliberately not the accent: this marks where the *reader's* link
   pointed, which is a different fact from what the site considers
   current, and it has to stay legible over both themes' ink. */
.text-fragment-highlight {
	background: rgba(255, 200, 0, 0.4);
	border-radius: var(--ui-radius-sm);
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .text-fragment-highlight {
		background: rgba(255, 200, 0, 0.25);
	}
}

[data-theme="dark"] .text-fragment-highlight {
	background: rgba(255, 200, 0, 0.25);
}

/* Centred by `ui-center` on the element; this is the room around it. */
.not-found {
	padding: var(--ui-space-16) var(--ui-space-none);
}

.not-found h1 {
	margin-bottom: var(--ui-space-normal);
}

/* ── Code blocks ──────────────────────────────────────────────────
   A fence naming a known language is coloured at build time
   (CodeHighlighter): each token is a span with one of these
   classes. The block around them is the shared system's. */
.hl-comment { color: var(--kb-code-comment); font-style: italic; }
.hl-keyword, .hl-tag { color: var(--kb-code-keyword); }
.hl-type, .hl-attr { color: var(--kb-code-type); }
.hl-string { color: var(--kb-code-string); }
.hl-number { color: var(--kb-code-number); }
.hl-meta { color: var(--kb-code-meta); }
.hl-variable { color: var(--kb-code-variable); }

/* The copy button `script.js` puts over the top right corner of every
   code block, picture and diagram (each wrapped in `.code-block` /
   `.picture-block` so the button stays put while a long line or a wide
   diagram scrolls): shown while the block is hovered or the button
   focused or confirming, and always on a screen that cannot hover.
   It is a fixed square — the shared icon button's aspect ratio loses to
   the line height and draws it tall and narrow — of 2.25rem (36 px), and
   2.75rem (44 px, the usual touch target) under a coarse pointer. */
.code-block,
.picture-block {
	position: relative;
}

.picture-block {
	width: fit-content;
	max-width: 100%;
}

.picture-block:has(> .diagram) {
	width: auto;
}

.code-block .copy-button,
.picture-block .copy-button {
	position: absolute;
	top: var(--ui-space-small);
	right: var(--ui-space-small);
	width: 2.25rem;
	height: 2.25rem;
	padding: 0;
	opacity: 0;
	transition: opacity var(--ui-transition);
}

/* the shared hover tint (--ui-accent-soft) is translucent, so over a
   picture the image showed through the button; lay it over the
   opaque raised surface instead */
.code-block .copy-button:hover,
.picture-block .copy-button:hover {
	background: linear-gradient(var(--ui-accent-soft), var(--ui-accent-soft)), var(--ui-surface-raised);
}

/* the icons are outlines; the shared system fills every button svg */
.copy-button svg {
	width: 1.25rem;
	height: 1.25rem;
	fill: none;
}

.code-block:hover .copy-button,
.picture-block:hover .copy-button,
.copy-button:focus-visible,
.copy-button.copied {
	opacity: 1;
}

@media (hover: none) {
	.code-block .copy-button,
	.picture-block .copy-button {
		opacity: 1;
	}
}

@media (pointer: coarse) {
	.code-block .copy-button,
	.picture-block .copy-button {
		width: 2.75rem;
		height: 2.75rem;
	}
}

/* ── Diagrams ─────────────────────────────────────────────────────
   A ```mermaid fence is a figure holding inline SVG
   (KnowledgebaseDiagrams). When the reader's browser draws it, the
   source's code-block chrome comes off once drawn; a diagram wider
   than the article scrolls inside its figure instead of widening
   the page. */
.diagram {
	overflow-x: auto;
	text-align: center;
}

.diagram .mermaid[data-processed] {
	background: none;
	border: none;
	padding: var(--ui-space-none);
	white-space: normal;
}

.diagram svg {
	max-width: 100%;
	height: auto;
	margin-inline: auto;
}

/* A D2 drawing (D2Renderer) opens with a rectangle in its theme's
   background; the page's own surface shows through instead. */
.diagram .d2-svg > rect:first-child {
	fill: transparent;
}

/* The rules a D2 drawing's own <style> carried — dropped from the SVG
   so it draws under style-src 'self' (D2Renderer). Its text is set in
   the article's font, as a Mermaid diagram is. */
.diagram .d2-svg text {
	font-family: var(--ui-font-sans);
}

.diagram .d2-svg .text-bold,
.diagram .d2-svg .text-mono-bold {
	font-weight: var(--ui-weight-bold);
}

.diagram .d2-svg .text-italic,
.diagram .d2-svg .text-mono-italic {
	font-style: italic;
}

.diagram .d2-svg .text-mono,
.diagram .d2-svg .text-mono-bold,
.diagram .d2-svg .text-mono-italic {
	font-family: var(--ui-font-mono);
}

.diagram .d2-svg .shape {
	shape-rendering: geometricPrecision;
	stroke-linejoin: round;
}

.diagram .d2-svg .connection {
	stroke-linecap: round;
	stroke-linejoin: round;
}

.diagram .d2-svg .blend {
	mix-blend-mode: multiply;
	opacity: 0.5;
}

/* A D2 shape with a link (D2Renderer) reads as a link: its label in
   the link colour (made to read on the accent's own tint, which is
   the box's fill) and underlined, as a link in prose is; its border
   in the accent on hover; a focus ring for the keyboard. */
.diagram a text.text,
.diagram a text.text-bold {
	fill: var(--ui-accent-text);
	text-decoration: underline;
}

.diagram a:hover .shape > *,
.diagram a:focus-visible .shape > * {
	stroke: var(--ui-accent);
}

.diagram a:focus-visible {
	outline: 2px solid var(--ui-accent-ring);
	outline-offset: 2px;
}

/* The hero: the picture under an article's opening paragraph, at
   the column's full width. With a video it is a link that plays it
   (script.js swaps in the player) and carries a play icon in its
   bottom right corner. */
.article-hero {
	margin: var(--ui-space-normal) 0 var(--ui-space-large);
}

.article-hero img {
	display: block;
	max-width: 100%;
	height: auto;
}

.article-hero-play {
	position: relative;
	display: block;
	width: fit-content;
	max-width: 100%;
	border-radius: var(--ui-radius-lg);
}

.article-hero-play:focus-visible {
	outline: 2px solid var(--ui-accent-ring);
	outline-offset: 2px;
}

.article-hero-play-icon {
	position: absolute;
	right: var(--ui-space-normal);
	bottom: var(--ui-space-normal);
	display: flex;
	align-items: center;
	justify-content: center;
	width: calc(var(--ui-icon-large) * 2);
	height: calc(var(--ui-icon-large) * 2);
	border-radius: var(--ui-radius-full);
	background: var(--ui-accent);
	color: var(--ui-accent-contrast);
	box-shadow: var(--ui-shadow-md);
	transition: transform 0.15s ease, background 0.15s ease;
}

.article-hero-play-icon svg {
	width: var(--ui-icon-large);
	height: var(--ui-icon-large);
}

.article-hero-play:hover .article-hero-play-icon,
.article-hero-play:focus-visible .article-hero-play-icon {
	background: var(--ui-accent-hover);
	transform: scale(1.08);
}

.article-hero-player {
	display: block;
	width: 100%;
	aspect-ratio: 16 / 9;
	border: 0;
	border-radius: var(--ui-radius-lg);
	background: var(--ui-surface-sunken);
}

video.article-hero-player {
	aspect-ratio: auto;
	height: auto;
}

/* A diagram drawn at build time carries an SVG per theme
   (DiagramBrowser); only the page's own theme's is shown — the same
   three-way choice as the palette: the toggle's pick, else the
   system's. */
.diagram-dark,
:root[data-theme="dark"] .diagram-light {
	display: none;
}

:root[data-theme="dark"] .diagram-dark {
	display: block;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .diagram-light {
		display: none;
	}

	:root:not([data-theme="light"]) .diagram-dark {
		display: block;
	}
}

/* ── Explained terms ──────────────────────────────────────────────
   A `.term` (KnowledgebaseExplanations) looks like the text around it.
   Selecting text that holds one opens the panel script.js places in
   the empty gutter beside the article — fixed, sized and placed by
   the script, one property at a time, never over the article. */
.term-panel {
	position: fixed;
	z-index: var(--ui-z-popover);
	overflow-y: auto;
	padding: var(--ui-space-normal);
	background: var(--ui-surface-raised);
	border: 1px solid var(--ui-border);
	border-radius: var(--ui-radius-sm);
	box-shadow: var(--ui-shadow-md);
	font-size: var(--ui-text-small);
}

.term-panel[hidden] {
	display: none;
}

/* "Selection" with the heading actions' two buttons on its right, always shown */
.term-panel-heading {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--ui-space-small);
	margin: 0 0 var(--ui-space-small);
	color: var(--ui-text-muted);
}

.term-panel .heading-actions {
	margin-left: 0;
	opacity: 1;
}

.term-panel dl {
	margin: 0;
}

.term-panel dt {
	font-weight: var(--ui-weight-bold);
}

.term-panel dd {
	margin: 0 0 var(--ui-space-small);
}

.term-panel dd:last-child {
	margin-bottom: 0;
}

.term-panel dd p {
	margin: 0;
}

/* ── Table of contents ────────────────────────────────────────────
   The article's `##` / `###` headings, which script.js lists in the
   same empty gutter the term panel uses — fixed at the top of the
   column, past its scrollbar (the column gives the strip up, see
   `.content`), sized and placed by the script, hidden when there is no
   room and while the term panel is open. The section being read is
   `aria-current`. */
.toc-panel {
	position: fixed;
	overflow-y: auto;
	font-size: var(--ui-text-small);
}

.toc-panel[hidden] {
	display: none;
}

.toc-panel-heading {
	margin: 0 0 var(--ui-space-small);
	color: var(--ui-text-muted);
	font-weight: var(--ui-weight-bold);
}

.toc-panel ul {
	margin: 0;
	padding: 0;
	list-style: none;
	border-left: 1px solid var(--ui-border);
}

.toc-panel a {
	display: block;
	margin-left: -1px;
	padding: var(--ui-space-1) 0 var(--ui-space-1) var(--ui-space-small);
	border-left: 2px solid transparent;
	color: var(--ui-text-muted);
	text-decoration: none;
}

.toc-panel .toc-level-3 a {
	padding-left: calc(2 * var(--ui-space-small) + var(--ui-space-1));
}

.toc-panel a:hover {
	color: var(--ui-text);
}

.toc-panel a[aria-current] {
	border-left-color: var(--ui-accent);
	color: var(--ui-accent-text);
	font-weight: var(--ui-weight-semibold);
}

/* ── Mobile ───────────────────────────────────────────────────────
   The sidebar button is a shared ghost button that simply does not
   exist on a wide screen. The generated bar's `_heading.md` folds
   behind the shared collapsing navbar's toggle (script-free: a
   checkbox and its label, ui-theme's COMPONENTS.md § Navigation),
   the shape the bot's own screens give the same tabs; the toggle
   stands last, after the bar's buttons. A custom bar folds its own
   links, and its slot's heading stays hidden.

   The breakpoint is the shared system's phone pair, `width < 48rem`
   (`theme.css` § 1) — the query its `.ui-navbar-collapse` folds on.
   It was `max-width: 768px`, which differs at exactly 768 px and at
   any browser default font size other than 16 px, so a custom bar
   could show its desktop links over a phone-layout sidebar. */
.menu-toggle {
	display: none;
}

@media (width < 48rem) {
	html, body {
		height: auto;
		overflow: auto;
	}

	/* The page scrolls as a whole here, and is at least the window's
	   height, so on a short article the column still reaches down and
	   the page footer stays at the bottom. */
	body {
		min-height: 100dvh;
	}

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

	.ui-navbar:not(:has(.nav-inner)) .nav-heading,
	.page-header {
		display: none;
	}

	.nav-inner > .ui-navbar-toggle {
		order: 1;
		margin-inline-start: 0;
	}

	.nav-inner > .nav-heading {
		text-align: start;
	}

	.container {
		flex-direction: column;
		padding: var(--ui-space-normal);
		overflow: visible;
		min-height: 0;
	}

	.sidebar {
		display: none;
		width: 100%;
		border-bottom: 1px solid var(--ui-border);
		padding-bottom: var(--ui-space-normal);
		margin-bottom: var(--ui-space-normal);
		overflow-y: visible;
	}

	.sidebar-open .sidebar {
		display: flex;
	}

	.sidebar > nav {
		overflow-y: visible;
	}

	.content {
		overflow-y: visible;
	}

	/* the container's own padding is the space below the article here */
	.content:has(> article) {
		padding-block-end: 0;
	}

	.hero {
		padding: var(--ui-space-normal);
	}

	.article-nav {
		flex-direction: column;
	}
}
