/* =========================================================================
   KODA docs — site chrome + dark-theme layer + responsive layer

   Loaded AFTER the manual's own <style> block, so plain selectors here win
   on source order. Everything additive is namespaced `kd-`; the bare
   selectors below deliberately override the manual's own rules.

   The manuals are authored as standalone light "paper" documents with a
   272px fixed sidebar and no breakpoints. This file:

     1. retunes their design tokens to the site's dark design system
        (slate surfaces, gold accent, mono fact-labels — src/app.css is
        the reference), plus per-component fixes where a manual hardcodes
        a light-mode colour;
     2. adds the site's shared header and footer (the static replica of
        LandingHeader/LandingFooter — keep them in step by hand);
     3. makes the sidebar an off-canvas drawer on small screens and stops
        wide API tables from being clipped;
     4. restores print to ink-on-paper.
   ========================================================================= */

:root {
	--kd-topbar-h: 70px;
	--kd-nav-bp: 900px;

	/* Chrome-only tokens (mirror app.css .theme-dark) */
	--kd-line: rgba(255, 255, 255, 0.06);
	--kd-line-strong: rgba(255, 255, 255, 0.14);
	--kd-ink: #241d0e; /* legend on gold fills */

	/* ---- Dark remap of the manuals' own tokens -------------------------
	   The manuals are fully token-driven, so most of the retheme is this
	   block. Values come from the site DS: slate-950/900 surfaces, gold-500
	   accent (text-safe on dark), slate-300/400 text. */
	--bg: #16171a;
	--surface: #1e2124;
	--surface-2: #26292e;
	--border: rgba(255, 255, 255, 0.09);
	--text: #e9eef5;
	--body: #98a3b3;
	--muted: #7e8794;
	--accent: #ccaa66;
	--accent-lt: rgba(204, 170, 102, 0.09);
	--accent-dk: #d5b981; /* "emphasis gold" flips lighter on dark */
	--code-bg: #0f1012;
	--th-bg: #101114;
	--row-alt: #1a1d21;

	/* Scripting-reference syntax palette (light originals fail on dark).
	   All ≥ 4.5:1 on --code-block-bg. */
	--code-block-bg: #0f1012;
	--code-block-fg: #dfe5ec;
	--code-comment: #707a8c;
	--code-keyword: #d5b981;
	--code-type: #82a4c4;
	--code-string: #9dbb7a;
	--code-number: #cf8f6a;
	--code-fn: #e2c58c;

	color-scheme: dark;
}

::selection {
	background: #bf9540;
	color: #0f1012;
}

:focus-visible {
	outline: 2px solid rgba(204, 170, 102, 0.5);
	outline-offset: 2px;
}

/* Anchor jumps must clear the fixed header ------------------------------- */

html {
	scroll-padding-top: calc(var(--kd-topbar-h) + 16px);
}

/* override: manual sets `scroll-margin-top: 24px`, which sits under the bar */
.section {
	scroll-margin-top: calc(var(--kd-topbar-h) + 24px);
}

/* Skip link -------------------------------------------------------------- */

.kd-skip {
	position: absolute;
	left: -9999px;
	top: 0;
	z-index: 60;
	padding: 10px 16px;
	background: var(--surface);
	color: var(--text);
	font-size: 13px;
	font-weight: 600;
	border: 1px solid var(--kd-line-strong);
	border-radius: 0 0 6px 0;
}

.kd-skip:focus {
	left: 0;
}

/* Top bar — static replica of LandingHeader ------------------------------ */

.kd-topbar {
	position: fixed;
	inset: 0 0 auto 0;
	height: var(--kd-topbar-h);
	z-index: 40;
	background: rgba(22, 23, 26, 0.85);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	border-bottom: 1px solid var(--kd-line);
}

.kd-topbar-inner {
	position: relative;
	width: min(1200px, 100% - 3rem);
	height: 100%;
	margin-inline: auto;
	display: flex;
	align-items: center;
	gap: 14px;
}

/* Wordmark — gold bars + KODA in Krona One */
.kd-wordmark {
	display: inline-flex;
	align-items: center;
	gap: 0.6rem;
	line-height: 20px;
	text-decoration: none;
	flex-shrink: 0;
}

.kd-wordmark img {
	width: 29px;
	height: 12px;
}

.kd-wordmark span {
	font-family: var(--display);
	font-size: 18px;
	line-height: 20px;
	letter-spacing: 0.06em;
	color: var(--text);
}

.kd-sitenav {
	display: flex;
	align-items: center;
	gap: 1.9rem;
	margin-left: auto;
}

.kd-sitenav a {
	font-family: var(--sans);
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--body);
	text-decoration: none;
	transition: color 140ms ease;
}

.kd-sitenav a:hover,
.kd-sitenav a[aria-current] {
	color: var(--text);
}

.kd-sitenav a.kd-cta {
	font-size: 0.82rem;
	font-weight: 600;
	padding: 0.6rem 1.1rem;
	border-radius: 6px;
	background: var(--accent);
	color: var(--kd-ink);
	transition: background 160ms ease;
}

.kd-sitenav a.kd-cta:hover {
	background: var(--accent-dk);
	color: var(--kd-ink);
}

.kd-sitenav .kd-discord {
	display: inline-flex;
	color: var(--muted);
}

.kd-sitenav .kd-discord:hover {
	color: var(--text);
}

.kd-sitenav .kd-discord svg {
	width: 18px;
	height: 14px;
}

/* Contents-drawer toggle — hidden until the sidebar collapses. A list
   glyph (dot + line), so it cannot be mistaken for the site menu. */
.kd-nav-toggle {
	display: none;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	padding: 0;
	background: transparent;
	border: 1px solid var(--kd-line-strong);
	border-radius: 6px;
	color: var(--body);
	cursor: pointer;
	flex-shrink: 0;
}

.kd-nav-toggle:hover {
	color: var(--text);
}

.kd-nav-toggle svg {
	width: 16px;
	height: 16px;
}

/* Site-menu toggle — the landing header's hamburger, ≤640px only */
.kd-menu-toggle {
	display: none;
	flex-direction: column;
	justify-content: center;
	gap: 4px;
	width: 2.5rem;
	height: 2.5rem;
	margin-left: auto;
	padding: 0;
	border: 1px solid var(--kd-line);
	border-radius: 6px;
	background: transparent;
	color: var(--text);
	cursor: pointer;
	flex-shrink: 0;
}

.kd-menu-toggle span {
	display: block;
	width: 1rem;
	height: 1px;
	margin: 0 auto;
	background: currentColor;
}

/* Layout offsets --------------------------------------------------------- */

/* override: manual pins the sidebar with `inset: 0 auto 0 0` */
nav.sidebar {
	top: var(--kd-topbar-h);
}

/* override: manual's .content only sets margin-left */
.content {
	margin-top: var(--kd-topbar-h);
}

/* Sidebar ---------------------------------------------------------------- */

/* Brand block — markup normalized by build-docs.mjs (bars + KODA on a row,
   the manual's label underneath); the look is owned here so every manual
   renders it identically, whatever its own stylesheet says. */
.nav-brand {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 0;
	padding: 22px;
	border-bottom: 1px solid var(--border);
}

.nav-brand .brand-top {
	display: flex;
	align-items: center;
	gap: 13px;
}

.nav-brand img {
	width: 29px;
	height: auto;
	border-radius: 0;
}

/* Krona One ships a single weight; anything ≥600 gets a synthesized bold,
   which is exactly the heaviness being avoided here. */
.nav-brand .name {
	font-family: var(--display);
	font-size: 20px;
	font-weight: 500;
	line-height: 1.1;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--text);
}

/* The label under the brand is the DS mono fact-label */
.nav-brand .label {
	font-family: var(--mono);
	font-size: 10px;
	font-weight: 500;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	color: var(--accent);
	margin-top: 8px;
}

/* Injected by build-docs.mjs between the brand and the section links */
.kd-alldocs {
	display: block;
	padding: 12px 22px;
	font-family: var(--mono);
	font-size: 10.5px;
	font-weight: 500;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	color: var(--muted);
	text-decoration: none;
	border-bottom: 1px solid var(--border);
	transition: color 140ms ease;
}

.kd-alldocs:hover {
	color: var(--accent);
}

.nav-links a:hover {
	background: rgba(255, 255, 255, 0.03);
}

/* Cover ------------------------------------------------------------------ */

/* The manuals' sans eyebrows become the DS mono eyebrow, like the index */
.eyebrow,
h4 {
	font-family: var(--mono);
	font-weight: 500;
	letter-spacing: 0.18em;
}

/* Body ------------------------------------------------------------------- */

.prose a {
	color: var(--accent);
}

.prose a:hover {
	text-decoration: underline;
}

/* Callouts --------------------------------------------------------------- */

.callout {
	background: var(--accent-lt);
	border-color: rgba(204, 170, 102, 0.28);
	border-left-color: var(--accent);
}

/* Re-assert the quiet variant: the manuals write it as `.callout
   callout-note`, so the gold override above would win on source order. */
.callout-note {
	background: var(--surface-2);
	border-color: var(--border);
	border-left-color: var(--muted);
}

.callout p,
.callout li,
.callout-note p {
	color: var(--body);
}

/* scripting-reference: dashed "tech note" callout hardcodes warm-grey inks */
.callout-tech {
	border-color: var(--kd-line-strong);
}

.callout-tech .callout-tag {
	color: var(--muted);
}

.callout-tech p {
	color: var(--body);
}

.callout-tech code {
	border-color: var(--border);
	color: var(--body);
}

/* Code ------------------------------------------------------------------- */

/* scripting-reference: the copy button hardcodes black-alpha chrome */
.copy-btn {
	background: rgba(255, 255, 255, 0.04);
	border-color: rgba(255, 255, 255, 0.12);
	color: rgba(233, 238, 245, 0.55);
}

.copy-btn:hover {
	background: rgba(255, 255, 255, 0.08);
	border-color: rgba(255, 255, 255, 0.22);
	color: var(--text);
}

.copy-btn.copied {
	background: var(--accent-lt);
	border-color: var(--accent);
	color: var(--accent-dk);
}

/* Keycaps ---------------------------------------------------------------- */

kbd {
	background: #24282e;
	border-color: rgba(255, 255, 255, 0.16);
	border-bottom-color: rgba(255, 255, 255, 0.3);
}

/* Figures ---------------------------------------------------------------- */

.fig-wrap {
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Navigation maps -------------------------------------------------------- */

/* Hotspot labels sit over screenshots; a translucent gold wash fails
   there, so they get an opaque ink chip with a gold key-line. */
.nav-hl::after {
	background: #241d0e;
	border-color: var(--accent);
	color: #e8d9ba;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
}

.nav-hl:hover,
.nav-hl.is-open {
	background: rgba(204, 170, 102, 0.18);
	outline-color: var(--accent-dk);
}

/* Tables ----------------------------------------------------------------- */

/* override: row fills are hardcoded warm whites in every manual */
tbody tr {
	background: #191c20;
}

tbody tr:nth-child(even) {
	background: #16181c;
}

tbody td {
	border-right-color: rgba(255, 255, 255, 0.05);
}

/* scripting-reference API-table inks */
.tbl-wrap.api-tbl .api-name {
	color: var(--text);
}

.nav-links a.stub {
	color: rgba(126, 135, 148, 0.55);
}

/* figma-gui accents ------------------------------------------------------ */

/* Figma's component purple and the verdict colours, relit for dark */
.glyph-sym,
.glyph-inline {
	color: #b78bfa;
}

.pro {
	color: #6fbf8f;
}

.con {
	color: #cf8577;
}

/* Footer — static replica of LandingFooter, on the content column -------- */

.kd-footer {
	border-top: 1px solid var(--kd-line);
	padding: 34px 56px 44px;
}

.kd-footer-inner {
	max-width: 1100px;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 1.5rem;
}

.kd-footer-brand {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.kd-footer-brand .kd-wordmark img {
	width: 24px;
	height: auto;
}

.kd-footer-brand .kd-wordmark span {
	font-size: 0.95rem;
}

.kd-footer-brand p {
	margin: 0;
	font-family: var(--sans);
	font-size: 0.75rem;
	color: var(--muted);
}

.kd-footer-links {
	display: flex;
	flex-wrap: wrap;
	gap: 1.75rem;
}

.kd-footer-links a {
	font-family: var(--sans);
	font-size: 0.8125rem;
	color: var(--muted);
	text-decoration: none;
	transition: color 140ms ease;
}

.kd-footer-links a:hover {
	color: var(--text);
}

/* Overflow containment ---------------------------------------------------
   Flex and grid items default to `min-width: auto`, so a wide table or code
   block inside one of the manuals' side-by-side layouts widens its track
   instead of scrolling within it — pushing the whole page sideways. Capping
   the two scrollable wrappers fixes it wherever they are nested, rather than
   chasing each layout container by name. Applies at every width: the
   two-column layouts blow out on desktop too, given a long enough line. */

.prose .tbl-wrap,
.prose .code-wrap {
	min-width: 0;
	max-width: 100%;
}

.code-compare > * {
	min-width: 0;
}

/* Safety net: not every manual's stylesheet sets this, and a single long line
   in a code block should scroll itself rather than the document. */
.prose pre {
	overflow-x: auto;
	max-width: 100%;
}

/* Pages generated from plain text (the acknowledgements) reuse a manual's
   stylesheet, so their licence blocks land in <pre>. Licence prose is not
   code — wrapping it beats making people scroll sideways through a warranty
   disclaimer on a phone. */
.kd-textdoc pre,
.kd-textdoc pre code {
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	max-width: 100%;
}

/* …and the licence text should read as one quiet panel, not a stack of
   per-line inline-code chips. */
.kd-textdoc pre {
	background: var(--code-bg);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 14px 18px;
}

.kd-textdoc pre code {
	background: transparent;
	border: 0;
	padding: 0;
	font-size: 12.5px;
	line-height: 1.7;
}

/* Licence blocks are full of bare URLs, which are single unbreakable tokens. */
.kd-textdoc p {
	overflow-wrap: anywhere;
}

/* Backdrop --------------------------------------------------------------- */

.kd-backdrop {
	display: none;
	position: fixed;
	inset: var(--kd-topbar-h) 0 0 0;
	z-index: 25;
	background: rgba(0, 0, 0, 0.55);
}

/* Small screens ---------------------------------------------------------- */

@media (max-width: 900px) {
	.kd-nav-toggle {
		display: inline-flex;
	}

	nav.sidebar {
		/* override: the manuals hide the sidebar entirely at ≤860px; it has
		   to exist for the drawer to have anything to slide in. */
		display: flex;
		width: min(84vw, 300px);
		transform: translateX(-100%);
		transition: transform 0.22s ease;
	}

	body.kd-nav-open nav.sidebar {
		transform: none;
		box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.75);
	}

	body.kd-nav-open .kd-backdrop {
		display: block;
	}

	/* override: manual offsets content by the sidebar width unconditionally */
	.content {
		margin-left: 0;
	}

	.prose {
		padding: 40px 20px 96px;
	}

	/* override: manual uses `overflow: hidden` for the rounded corners, which
	   silently clips wide API tables on narrow screens. Reachability wins. */
	.tbl-wrap {
		overflow-x: auto;
		overflow-y: hidden;
		-webkit-overflow-scrolling: touch;
	}

	.tbl-wrap table {
		min-width: 560px;
	}

	/* Genuine content columns stack; there is no room for two abreast. */
	.card-row {
		grid-template-columns: 1fr;
	}

	.kp-side-by-side {
		flex-direction: column;
	}

	/* The Figma properties-panel mock is a picture of a UI — stacking its rows
	   would misrepresent the thing it documents, so let it scroll instead. */
	.kp-embed {
		overflow-x: auto;
	}

	.kd-footer {
		padding: 28px 20px 34px;
	}
}

/* Site menu collapses into a dropdown, mirroring LandingHeader ----------- */

@media (max-width: 640px) {
	.kd-menu-toggle {
		display: flex;
	}

	.kd-sitenav {
		display: none;
		position: absolute;
		top: calc(100% + 10px);
		right: 0;
		z-index: 45;
		flex-direction: column;
		align-items: stretch;
		gap: 0;
		min-width: 12rem;
		padding: 0.5rem;
		border: 1px solid var(--kd-line);
		border-radius: 6px;
		background: rgba(22, 23, 26, 0.98);
		box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
	}

	body.kd-menu-open .kd-sitenav {
		display: flex;
	}

	.kd-sitenav a {
		padding: 0.7rem;
	}

	.kd-sitenav a.kd-cta {
		margin-top: 0.3rem;
		text-align: center;
		justify-content: center;
	}

	.kd-sitenav .kd-discord {
		justify-content: center;
		margin-top: 0.3rem;
	}

	/* The manuals' cover heading bottoms out at 28px, and Krona One is a wide
	   face — "Acknowledgements" alone measures 359px, past the edge of a
	   375px phone. Scale with the viewport, and allow a break as a last
	   resort for any future title with a longer word in it. */
	.cover h1 {
		font-size: clamp(21px, 6vw, 32px);
		overflow-wrap: break-word;
	}
}

@media (prefers-reduced-motion: reduce) {
	nav.sidebar {
		transition: none;
	}
}

/* Print ------------------------------------------------------------------
   Browsers do not print page backgrounds by default, so the dark remap
   above would come out as pale ink on white. Put the paper palette back. */

@media print {
	:root {
		--bg: #ffffff;
		--surface: #ffffff;
		--surface-2: #f2f2f2;
		--border: #d9d9d9;
		--text: #111111;
		--body: #222222;
		--muted: #666666;
		--accent: #8a6d2f;
		--accent-lt: #f5efe0;
		--accent-dk: #6f5722;
		--code-bg: #f4f4f4;
		--th-bg: #111111;
		--code-block-bg: #f6f6f6;
		--code-block-fg: #111111;
		--code-comment: #7a7a7a;
		--code-keyword: #6f5722;
		--code-type: #33566e;
		--code-string: #4a6030;
		--code-number: #8a4a2e;
		--code-fn: #6b4d14;
		color-scheme: light;
	}

	tbody tr,
	tbody tr:nth-child(even) {
		background: #ffffff;
	}

	kbd {
		background: #f2f2f2;
		border-color: #cccccc;
		border-bottom-color: #bbbbbb;
	}

	.kd-topbar,
	.kd-backdrop,
	.kd-skip,
	nav.sidebar {
		display: none;
	}

	.content {
		margin: 0;
	}

	.prose {
		padding: 0;
		max-width: none;
	}

	.kd-footer {
		border: 0;
		padding: 24px 0 0;
	}
}
