/*
 * Styles of the generated LaTeX reference pages (see reference/README.md).
 *
 * Colours and the heading font come from src/css/palette.css, which every
 * page loads before this file; the home page (css/site/site.css) maps the
 * same values. Apart from one shadow, this file sets no colour value of its own.
 * A page with a formula field also loads KaTeX's stylesheet before this file.
 */
:root {
	--bg: rgb(var(--pal-light-bg-rgb));
	--surface: var(--pal-light-surface-alt);
	--text: var(--pal-light-text);
	--muted: var(--pal-light-text-secondary);
	--border: var(--pal-light-border);
	/* --brand is a button fill; --accent is the same hue where it is legible as text. */
	--brand: rgb(var(--pal-light-accent-rgb));
	--brand-hover: rgb(var(--pal-light-accent-hover-rgb));
	--on-brand: var(--pal-light-on-accent);
	--accent: var(--pal-light-accent-text);
	--focus: rgb(var(--pal-light-accent-rgb));

	--warn: var(--pal-light-warn);
	--error: var(--pal-light-error);
	--code-key: var(--pal-light-code-key);
	--code-comment: var(--pal-light-code-comment);
	--code-brace: var(--pal-light-code-brace);

	/* A printed page is white in both colour schemes. */
	--paper: var(--pal-paper);

	--font-text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--font-heading: var(--pal-font-brand);
	--font-code: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
	--font-math: "STIX Two Math", "Cambria Math", "Latin Modern Math", "Noto Sans Math", "Times New Roman", serif;

	color-scheme: light dark;
	accent-color: var(--brand);
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: rgb(var(--pal-dark-bg-rgb));
		--surface: var(--pal-dark-surface);
		--text: var(--pal-dark-text);
		--muted: var(--pal-dark-text-secondary);
		--border: var(--pal-dark-border);
		--brand: rgb(var(--pal-dark-accent-rgb));
		--brand-hover: rgb(var(--pal-dark-accent-hover-rgb));
		--on-brand: var(--pal-dark-on-accent);
		--accent: var(--pal-dark-accent-text);
		--focus: var(--pal-dark-accent-text);

		--warn: var(--pal-dark-warn);
		--error: var(--pal-dark-error);
		--code-key: var(--pal-dark-code-key);
		--code-comment: var(--pal-dark-code-comment);
		--code-brace: var(--pal-dark-code-brace);
	}
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 1rem/1.6 var(--font-text);
}

.wrap { max-width: 60rem; margin-inline: auto; padding-inline: 1.25rem; }
main.wrap { max-width: 50rem; padding-block: 1.5rem 3rem; }

a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1, h2, h3 { font-family: var(--font-heading); font-weight: 600; }
h1 { font-size: 2.1rem; line-height: 1.2; margin: 0.5rem 0 1rem; text-wrap: balance; }
h2 { font-size: 1.45rem; line-height: 1.3; margin: 2.2rem 0 0.6rem; }
h1 code { font-size: 0.9em; }
p, ul, ol, dl, table { margin: 0 0 1rem; }
li { margin-bottom: 0.35rem; }
.lead { font-size: 1.12rem; }
.muted { color: var(--muted); font-size: 0.92rem; }

code {
	font-family: var(--font-code);
	font-size: 0.92em;
	background: var(--surface);
	border-radius: 4px;
	padding: 0.1em 0.3em;
	overflow-wrap: anywhere;
}
a code { color: inherit; }

.visually-hidden {
	position: absolute; width: 1px; height: 1px; overflow: hidden;
	clip-path: inset(50%); white-space: nowrap;
}
.skip { position: absolute; left: -999rem; top: 0; background: var(--bg); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

/* Header */
.site-header { border-bottom: 1px solid var(--border); }
.site-header .wrap { max-width: 70rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.2rem; padding-block: 0.7rem; }
.brand {
	display: inline-flex; align-items: center; gap: 0.5rem; color: var(--text); text-decoration: none;
	font-family: var(--font-heading); font-size: 1.25rem; font-weight: 600; white-space: nowrap;
}
/* <picture> picks the logo file by system theme; it must not become a box of its own */
.brand picture { display: contents; }
.brand img { width: 1.75rem; height: 1.75rem; }
.brand-section { color: var(--muted); text-decoration: none; white-space: nowrap; }
.brand-section:hover, .brand-section[aria-current] { color: var(--text); }
.site-nav { display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; }
.site-nav a { color: var(--text); text-decoration: none; padding-block: 0.2rem; }
.site-nav a:hover, .site-nav a[aria-current] { color: var(--accent); }
.site-nav a[aria-current] { box-shadow: inset 0 -2px 0 var(--accent); }

.search { position: relative; flex: 1 1 12rem; min-width: 10rem; margin: 0; }
.search input {
	width: 100%; font: inherit; color: inherit; background: var(--surface);
	border: 1px solid var(--border); border-radius: 6px; padding: 0.4rem 0.7rem;
}
.search-results {
	position: absolute; z-index: 5; inset-inline: 0; top: calc(100% + 4px);
	background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
	box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); max-height: 70vh; overflow: auto; min-width: min(22rem, 90vw);
}
.search-results a { display: block; padding: 0.5rem 0.75rem; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover, .search-results a:focus-visible { background: var(--surface); }
.search-results .result-title { font-weight: 600; }
.search-results .result-text { display: block; color: var(--muted); font-size: 0.88rem; }
.search-results p { margin: 0; padding: 0.6rem 0.75rem; color: var(--muted); }

.button {
	display: inline-block; background: var(--brand); color: var(--on-brand);
	font-weight: 600; text-decoration: none; border-radius: 6px; padding: 0.55rem 1.1rem;
}
.button:hover { background: var(--brand-hover); color: var(--on-brand); }
.button-small { padding: 0.35rem 0.8rem; font-size: 0.95rem; white-space: nowrap; }

/* Breadcrumb */
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.2rem 0.5rem; padding: 0; margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--muted); }
.crumbs li { margin: 0; }
.crumbs li + li::before { content: "›"; margin-inline-end: 0.5rem; }
.crumbs code { background: none; padding: 0; }

/* Tags and messages */
.tag {
	display: inline-block; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
	border: 1px solid var(--border); border-radius: 999px; padding: 0 0.55rem; color: var(--muted);
}
.message { border-inline-start: 4px solid var(--error); background: var(--surface); padding: 0.7rem 1rem; border-radius: 0 6px 6px 0; }
.message code { background: none; padding: 0; font-size: 1rem; }
.message-error .tag { color: var(--error); border-color: currentColor; }
.message-warning { border-inline-start-color: var(--warn); }
.message-warning .tag { color: var(--warn); border-color: currentColor; }
.callout { border: 1px solid var(--warn); border-radius: 6px; padding: 0.7rem 1rem; }

/* Tutorials on the feature pages: contents, numbered steps, screenshots */
.toc { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 0.8rem 1.1rem; margin-block: 1.2rem; }
.toc-title { font-weight: 600; margin: 0 0 0.3rem; }
.toc ol { margin: 0; padding-inline-start: 1.4rem; columns: 2 16rem; column-gap: 2rem; }
.toc li { break-inside: avoid; }
h2[id] { scroll-margin-block-start: 1rem; }
.steps { list-style: none; counter-reset: step; padding: 0; }
.steps > li { counter-increment: step; position: relative; padding-inline-start: 2.6rem; margin-block: 1.1rem; }
.steps > li::before {
	content: counter(step); position: absolute; inset-inline-start: 0; inset-block-start: 0;
	inline-size: 1.8rem; block-size: 1.8rem; border-radius: 50%; display: grid; place-items: center;
	background: var(--brand); color: var(--on-brand); font-weight: 600; font-size: 0.95rem;
}
.steps > li > p { margin-block: 0.15rem 0.6rem; }
.shot { margin: 0.8rem 0 1.2rem; }
.shot a { display: inline-block; max-inline-size: 100%; }
.shot img { display: block; max-inline-size: 100%; block-size: auto; border: 1px solid var(--border); border-radius: 8px; }
.shot figcaption { font-size: 0.9rem; color: var(--muted); margin-block-start: 0.35rem; }
.tips { border-inline-start: 3px solid var(--brand); border-radius: 0 6px 6px 0; background: var(--surface); padding: 0.7rem 1rem; margin-block: 1rem; }
.tips-title { font-weight: 600; margin: 0 0 0.3rem; }
.tips ul { margin: 0; }

/* Code blocks and copy buttons */
.code { position: relative; margin: 0 0 1rem; }
.code pre {
	margin: 0; padding: 0.9rem 1rem; padding-inline-end: 3rem; overflow-x: auto;
	background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
	font: 0.9rem/1.55 var(--font-code); tab-size: 2;
}
.code pre code { background: none; padding: 0; font-size: inherit; overflow-wrap: normal; }
.tk-k { color: var(--code-key); }
.tk-c { color: var(--code-comment); font-style: italic; }
.tk-b, .tk-m { color: var(--code-brace); }

.copy { position: relative; display: inline-flex; }
.copy-button {
	min-inline-size: 2rem; min-block-size: 2rem; display: inline-grid; place-items: center;
	background: var(--bg); color: var(--muted); border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.copy-button:hover { color: var(--text); }
.copy-button .icon-check { display: none; color: var(--accent); }
.copy-button[data-copied] .icon-copy { display: none; }
.copy-button[data-copied] .icon-check { display: block; }
.copy-button[data-failed] { color: var(--error); }
.tip {
	position: absolute; inset-block-end: calc(100% + 4px); inset-inline-end: 0; white-space: nowrap;
	background: var(--text); color: var(--bg); font: 0.8rem/1.4 var(--font-text); border-radius: 4px; padding: 0.1rem 0.45rem;
	opacity: 0; transition: opacity 0.15s; pointer-events: none;
}
.tip:empty { padding: 0; }
.copy-button[data-copied] + .tip, .copy-button[data-failed] + .tip { opacity: 1; }

/* Without hover the button stays visible and sits beside the code. */
.code.copyable { display: flex; align-items: start; gap: 0.5rem; }
.code.copyable pre { flex: 1; min-width: 0; padding-inline-end: 1rem; }
.code.copyable .copy { flex: none; order: 1; }
.copyable.inline { display: inline-flex; align-items: center; gap: 0.4rem; }
.copyable.inline .copy-button { min-inline-size: 1.6rem; min-block-size: 1.6rem; }

@media (hover: hover) {
	.code.copyable { display: block; }
	.code.copyable pre { padding-inline-end: 3rem; }
	.code.copyable .copy { position: absolute; inset-block-start: 0.5rem; inset-inline-end: 0.5rem; }
	.copyable .copy-button { opacity: 0; transition: opacity 0.15s; }
	.copyable:hover .copy-button,
	.copyable:focus-within .copy-button,
	.copyable .copy-button:focus-visible,
	.copyable .copy-button[data-copied],
	.copyable .copy-button[data-failed] { opacity: 1; }
	tr:hover .copyable .copy-button { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
	.tip, .copyable .copy-button { transition: none; }
}

/* The line under a code block that opens it in the editor */
.code:has(+ .code-open) { margin-bottom: 0.3rem; }
.code-open { font-size: 0.92rem; }
.code-open a::after { content: " →"; }

/* The compiled result of an example, one picture per page (lib/previews.js).
   The pictures have no background of their own and stand on paper white. */
.output { margin: 0 0 1rem; }
.output figcaption { font-size: 0.92rem; color: var(--muted); margin-bottom: 0.35rem; }
.output-pages { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.6rem; }
.output-page { display: flex; flex-direction: column; gap: 0.2rem; min-inline-size: 0; max-inline-size: 100%; }
.output img { display: block; max-inline-size: 100%; block-size: auto; background: var(--paper); border: 1px solid var(--border); border-radius: 6px; }
.output-label { font-size: 0.85rem; color: var(--muted); }
.code:has(+ .output) { margin-bottom: 0.6rem; }
.output:has(+ .code-open) { margin-bottom: 0.4rem; }

/* Formula field: an editable formula above its rendering (lib/playground.js) */
.formula { border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem; margin: 0 0 1rem; }
.formula-label { display: block; font-size: 0.92rem; color: var(--muted); margin-bottom: 0.35rem; }
.formula-input {
	display: block; inline-size: 100%; resize: vertical; field-sizing: content; min-block-size: 2.4rem; max-block-size: 22rem;
	font: 0.95rem/1.55 var(--font-code); tab-size: 2; color: var(--text); background: var(--surface);
	border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.7rem;
}
/* The line is kept free, so a message does not move the formula below it. */
.formula-status { min-block-size: 1.5em; margin: 0.3rem 0 0; font-size: 0.9rem; color: var(--error); overflow-wrap: anywhere; }
.formula-output {
	font-size: 1.35rem; min-block-size: 4.5rem; display: grid; align-items: center; padding: 0.6rem 0.5rem 0.9rem;
	overflow-x: auto; overflow-y: hidden; transition: opacity 0.15s;
}
.formula-output .katex-display { margin: 0; }
/* The last formula that could be drawn stays visible while the input cannot be. */
.formula[data-stale] .formula-output { opacity: 0.4; }
.formula-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 0; }
.formula-foot .muted { flex: 1 1 16rem; }
details.formula-edit summary { cursor: pointer; color: var(--accent); font-size: 0.95rem; inline-size: fit-content; }
details.formula-edit[open] summary { margin-bottom: 0.5rem; }
details.formula-edit p:last-child { margin: 0; }

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

/* Tables */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: start; vertical-align: top; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--border); }
thead th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.table-scroll { overflow-x: auto; margin-bottom: 1rem; }
.table-scroll table { margin: 0; }
.facts { width: auto; min-width: min(100%, 20rem); }
.facts th { font-weight: 500; color: var(--muted); white-space: nowrap; }
.commands td:first-child { white-space: nowrap; }
.symbol-table td { vertical-align: middle; }

/* Symbols */
.symbol-hero { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; margin-bottom: 1.2rem; }
.glyph {
	display: grid; place-items: center; inline-size: 9rem; block-size: 9rem; flex: none; font-size: 4.5rem;
	background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
/* The SVG previews are sized in em: 1em is the font size of the LaTeX run. */
.glyph svg, .glyph-small svg { fill: currentColor; overflow: visible; max-inline-size: 85%; block-size: auto; max-block-size: 85%; }
.glyph-char { font: 4rem/1 var(--font-math); }
.glyph-small { display: inline-grid; place-items: center; inline-size: 4.5rem; block-size: 2rem; font-size: 1.5rem; }
.glyph-small .glyph-char { font: 1.35rem/1 var(--font-math); }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.chip {
	display: inline-flex; align-items: center; gap: 0.45rem; text-decoration: none; color: var(--text);
	border: 1px solid var(--border); border-radius: 6px; padding: 0.2rem 0.55rem; background: var(--bg);
}
.chip:hover { border-color: var(--accent); }
.chip code { background: none; padding: 0; color: var(--muted); font-size: 0.82rem; }
.chip-glyph { font: 1.2rem/1.2 var(--font-math); min-inline-size: 1.2rem; text-align: center; }

/* Lists of links */
.links { list-style: none; padding: 0; columns: 2 16rem; column-gap: 2rem; }
.links li { break-inside: avoid; }
.package-list dt { font-weight: 600; margin-top: 0.8rem; }
.package-list dd { margin: 0.1rem 0 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; margin-block: 1.5rem; }
.card { border: 1px solid var(--border); border-radius: 10px; padding: 1.1rem 1.2rem; }
.card h2 { margin-top: 0; }
.card .links { columns: 1; }

.cta { margin-top: 2.5rem; border: 1px solid var(--border); border-radius: 10px; padding: 1.2rem 1.3rem; background: var(--surface); }
.cta h2 { margin-top: 0; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.9rem; }
.site-footer .wrap { max-width: 70rem; padding-block: 1.2rem; }
.site-footer p { margin: 0 0 0.3rem; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }
.site-footer-legal { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.3rem 2rem; margin-top: 0.8rem; }
.site-footer-legal nav { display: flex; flex-wrap: wrap; gap: 0.3rem 1.5rem; }
