/* Shared default stylesheet for all RELIW-served sites.
 *
 * Targets the RELIW page skeleton:
 *   <header><section class="page|login|error" id="title">Title</section></header>
 *   ...rendered markdown (bare <section> per h2+ heading)...
 * plus the markdown renderer's extensions: fenced divs (::: name),
 * inline attribute classes on code/links/images, task lists, footnotes.
 *
 * System fonts only. Light/dark follows the OS via prefers-color-scheme.
 */

:root {
	--bg: #ffffff;
	--fg: #24292f;
	--muted: #57606a;
	--accent: #0a5fa8;
	--border: #d0d7de;
	--code-bg: #f6f8fa;
	--warn-border: #4b8b3b;
	--warn-bg: #f4f9f0;
	--warn-label-bg: #dcedd3;
	--warn-label-fg: #2c5e22;
	--caution-border: #a83232;
	--caution-bg: #fbf2f2;
	--caution-label-bg: #f3d9d9;
	--caution-label-fg: #7d1f1f;
	--t-str: #1a7f37;
	--t-num: #953800;
	--t-bool: #8250df;
	--t-tbl: #9a6700;
	--t-func: #bf3989;
	--t-file: #0969da;
	--t-dir: #0a5fa8;
	--t-err: #cf222e;
	--t-arg: #4b8b3b;
	--t-multi: #b35900;
	--t-udata: #0e7490;
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #14171a;
		--fg: #d4dae0;
		--muted: #8b949e;
		--accent: #58a6ff;
		--border: #30363d;
		--code-bg: #1d2126;
		--warn-border: #3f6f33;
		--warn-bg: #182117;
		--warn-label-bg: #2c4726;
		--warn-label-fg: #a4d99a;
		--caution-border: #8a3b3b;
		--caution-bg: #241717;
		--caution-label-bg: #4a2525;
		--caution-label-fg: #f0a8a8;
		--t-str: #7ee2a8;
		--t-num: #ffa657;
		--t-bool: #d2a8ff;
		--t-tbl: #e3b341;
		--t-func: #ff9bce;
		--t-file: #79c0ff;
		--t-dir: #58a6ff;
		--t-err: #ff7b72;
		--t-arg: #9ad89a;
		--t-multi: #f0883e;
		--t-udata: #76c7dd;
	}
}

* { box-sizing: border-box; }

html {
	/* ~16px on phones, capped at ~19px on wide screens. */
	font-size: clamp(1rem, 0.92rem + 0.4vw, 1.2rem);
}

/* RELIW emits no <main>; the body itself is the reading column. */
body {
	max-width: 48em;
	margin: 0 auto;
	padding: 0 1em 3em;
	background: var(--bg);
	color: var(--fg);
	font-family: system-ui, sans-serif;
	line-height: 1.6;
}

::selection {
	background: var(--accent);
	color: var(--bg);
}

/* Header: the title bar RELIW injects (first h1 is hoisted here) */
header {
	border-bottom: 1px solid var(--border);
	padding: 1.2em 0 0.5em;
	margin-bottom: 1.5em;
}
#title {
	font-size: 1.4em;
	font-weight: 600;
	line-height: 1.25;
}
#title.login { text-align: center; }
#title.error { color: var(--muted); }

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

h1, h2, h3, h4, h5, h6 {
	line-height: 1.25;
	margin: 1.4em 0 0.5em;
}
h1 { font-size: 1.6em; }
h2 { font-size: 1.35em; }
h3 { font-size: 1.15em; }
h4, h5, h6 { font-size: 1em; }

p { margin: 0 0 1em; }

hr {
	border: none;
	border-top: 1px solid var(--border);
	margin: 1.5em 0;
}

/* Lists */
ul, ol { padding-left: 1.5em; margin: 0 0 1em; }
li { margin: 0.2em 0; }
li > p { margin: 0.3em 0; }
li::marker { color: var(--muted); }

ul:has(li.task-item) {
	list-style: none;
	padding-left: 0.5em;
}
li.task-item {
	display: flex;
	align-items: baseline;
	gap: 0.5em;
}
li.task-item p { margin: 0; }

/* Definition lists */
dl { margin: 0 0 1em; }
dt { font-weight: 600; }
dd { margin: 0 0 0.7em 1.5em; }

/* Code */
code, pre {
	font-family: ui-monospace, monospace;
	font-size: 0.92em;
	background: var(--code-bg);
	border-radius: 4px;
}
code { padding: 0.1em 0.3em; }
pre {
	padding: 0.75em 1em;
	margin: 0 0 1em;
	overflow-x: auto;
	line-height: 1.5;
}
pre code { padding: 0; background: none; font-size: 1em; }

blockquote {
	margin: 0 0 1em;
	padding-left: 1em;
	border-left: 3px solid var(--border);
	color: var(--muted);
}

/* Tables */
table {
	border-collapse: collapse;
	width: 100%;
	margin: 0 0 1em;
}
th, td {
	text-align: left;
	padding: 0.3em 0.75em 0.3em 0;
	border-bottom: 1px solid var(--border);
	vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }

/* Images: centered block, never overflowing the column.
   Size can be tuned from markdown via ![alt](src){.small} etc. */
img {
	display: block;
	max-width: 100%;
	height: auto;
	margin: 1.5em auto;
}
img.small { max-width: 16rem; }
img.medium { max-width: 28rem; }

/* Footnotes */
section.footnotes {
	margin-top: 2.5em;
	font-size: 0.85em;
	color: var(--muted);
}
section.footnotes hr { margin: 0 0 1em; }
sup[id^="fnref-"] { line-height: 1; }
a.footnote-backref { padding-left: 0.3em; }

/* Fenced divs: ::: warning / ::: caution callouts */
div.warning, div.caution {
	position: relative;
	border: 1px solid var(--warn-border);
	border-radius: 6px;
	background: var(--warn-bg);
	padding: 1.2em 1em 0.4em;
	margin: 1.6em 0 1.2em;
}
div.caution {
	border-color: var(--caution-border);
	background: var(--caution-bg);
}
div.warning::before, div.caution::before {
	content: "Nota Bene";
	position: absolute;
	top: -0.8em;
	left: 0.8em;
	background: var(--warn-label-bg);
	color: var(--warn-label-fg);
	border: 1px solid var(--warn-border);
	border-radius: 4px;
	padding: 0.05em 0.5em;
	font-size: 0.8em;
	font-weight: 600;
}
div.caution::before {
	content: "Caveat Emptor";
	background: var(--caution-label-bg);
	color: var(--caution-label-fg);
	border-color: var(--caution-border);
}
div.warning code, div.caution code { background: var(--bg); }

/* Function documentation blocks (::: function, used by the API docs) */
div.function {
	border-left: 3px solid var(--border);
	border-radius: 0 4px 4px 0;
	padding: 0.5em 1em;
	margin: 0 0 1.2em;
}
div.function blockquote {
	font-family: ui-monospace, monospace;
	border-left: none;
	margin: 0 0 0.7em;
	padding: 0.3em 0.6em;
	background: var(--code-bg);
	border-radius: 4px;
	color: var(--fg);
}

/* Wiki routes: the search form, entry listings, outgoing links and
   paging nav RELIW emits for a mounted wikidb. */
form.wiki-search {
	display: flex;
	gap: 0.5em;
	margin: 0 0 1.5em;
}
form.wiki-search input[type="search"] {
	flex: 1;
	min-width: 0;
	font: inherit;
	color: var(--fg);
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 4px;
	padding: 0.4em 0.6em;
}
form.wiki-search button {
	font: inherit;
	color: var(--bg);
	background: var(--accent);
	border: 1px solid var(--accent);
	border-radius: 4px;
	padding: 0.4em 1em;
	cursor: pointer;
}
ul.wiki-list {
	list-style: none;
	padding: 0;
	margin: 0;
	columns: 18rem;
	column-gap: 2em;
}
ul.wiki-list li {
	break-inside: avoid;
	margin: 0 0 0.35em;
}
nav.wiki-links {
	margin-top: 2.5em;
	border-top: 1px solid var(--border);
}
nav.wiki-links ul {
	list-style: none;
	padding: 0;
	columns: 18rem;
	column-gap: 2em;
}
nav.wiki-links li { break-inside: avoid; }
nav.wiki-paging {
	margin-top: 2em;
	padding-top: 1em;
	border-top: 1px solid var(--border);
	text-align: center;
	color: var(--muted);
}

/* Inline type classes (`x`{.str} etc.), scoped to code elements */
code.str, code.num, code.bool, code.tbl, code.fn, code.func,
code.file, code.dir, code.nil, code.err, code.arg, code.flag,
code.meta, code.neg, code.multi, code.status, code.any, code.udata {
	font-weight: 600;
}
code.str { color: var(--t-str); }
code.num { color: var(--t-num); }
code.bool, code.flag { color: var(--t-bool); }
code.tbl { color: var(--t-tbl); }
code.fn, code.func { color: var(--t-func); }
code.file { color: var(--t-file); }
code.dir { color: var(--t-dir); }
code.nil, code.meta { color: var(--muted); }
code.err, code.neg { color: var(--t-err); }
code.arg, code.status { color: var(--t-arg); }
code.multi { color: var(--t-multi); }
code.udata { color: var(--t-udata); }
code.any { color: var(--muted); font-style: italic; }
code.req { border: 1px solid var(--border); }
code.def {
	color: var(--muted);
	font-size: 0.9em;
}

code.tbl::before, code.tbl::after,
code.fn::before, code.fn::after,
code.func::before, code.func::after,
code.or_nil::after, code.opt::after {
	font-size: 0.85em;
	opacity: 0.65;
	padding: 0 0.05em;
}
code.tbl::before { content: "{"; }
code.tbl::after { content: "}"; }
code.fn::before, code.func::before { content: "ƒ("; }
code.fn::after, code.func::after { content: ")"; }
code.or_nil::after, code.opt::after { content: "?"; }
code.tbl.or_nil::after, code.tbl.opt::after { content: "}?"; }
code.fn.or_nil::after, code.fn.opt::after,
code.func.or_nil::after, code.func.opt::after { content: ")?"; }

/* Poetry: ::: verse fenced divs. Line breaks inside stanzas are
   softbreaks, emitted as newlines and preserved by pre-line. The block
   is centered while the text keeps its left edge. */
div.verse {
	width: fit-content;
	max-width: 100%;
	margin: 1.5em auto;
	line-height: 1.7;
}
div.verse p { white-space: pre-line; }

/* Datelines on poems/stories: `Kyiv, ~2019`{.date} */
code.date {
	display: block;
	text-align: center;
	background: none;
	padding: 0;
	font-family: inherit;
	font-style: italic;
	color: var(--muted);
}

/* Login page */
#login_form {
	text-align: center;
	margin: 3em auto;
}
#login_form div { margin: 0.8em 0; }
#login_form label {
	display: inline-block;
	width: 6em;
	text-align: right;
	margin-right: 0.8em;
	color: var(--muted);
}
#login_form input {
	font: inherit;
	color: var(--fg);
	background: var(--code-bg);
	border: 1px solid var(--border);
	border-radius: 4px;
	padding: 0.25em 0.5em;
}
#login_form button {
	font: inherit;
	font-weight: 600;
	color: var(--bg);
	background: var(--accent);
	border: none;
	border-radius: 4px;
	padding: 0.35em 1.2em;
	margin-top: 0.8em;
	cursor: pointer;
}

/* Error pages */
#error {
	padding: 3em 1em 1em;
	text-align: center;
}
#error h3 {
	font-size: 3em;
	margin: 0;
}
#error h3 ~ h3 {
	transform: scale(1, -1);
	opacity: 0.35;
}
#error img {
	max-width: 12rem;
	margin: 2em auto 0;
}
p.error { padding: 1em; }
#home {
	text-align: center;
	color: var(--muted);
}
footer p.error {
	margin-top: 3em;
	text-align: center;
	font-size: 0.75em;
	color: var(--muted);
}
footer p.error span { font-weight: 600; }

@media (prefers-reduced-motion: no-preference) {
	#error h3, #error p.error {
		animation: error-fade 25s forwards;
	}
	#error h3 ~ h3 { animation-name: error-fade-mirrored; }
	@keyframes error-fade {
		to { opacity: 0.2; transform: scale(0.8); }
	}
	@keyframes error-fade-mirrored {
		from { opacity: 0.35; transform: scale(1, -1); }
		to { opacity: 0.1; transform: scale(0.8, -0.8); }
	}
}
