/* Solarized Color Variables */
:root {
	/* Light theme colors */
	--base03: #002b36;
	--base02: #073642;
	--base01: #586e75;
	--base00: #657b83;
	--base0: #839496;
	--base1: #93a1a1;
	--base2: #eee8d5;
	--base3: #fdf6e3;
	--yellow: #b58900;
	--orange: #cb4b16;
	--red: #dc322f;
	--magenta: #d33682;
	--violet: #6c71c4;
	--blue: #268bd2;
	--cyan: #2aa198;
	--green: #859900;

	/* Semantic mappings for light mode */
	--bg-primary: var(--base3);
	--bg-secondary: var(--base2);
	--bg-tertiary: var(--base02);
	--fg-primary: var(--base00);
	--fg-secondary: var(--base0);
	--fg-emphasis: var(--base01);
	--fg-deemphasis: var(--base1);
	--accent-primary: var(--blue);
	--accent-secondary: var(--cyan);
}

/* Dark mode color remapping */
@media (prefers-color-scheme: dark) {
	:root {
		--bg-primary: var(--base03);
		--bg-secondary: var(--base02);
		--bg-tertiary: var(--base2);
		--fg-primary: var(--base0);
		--fg-secondary: var(--base00);
		--fg-emphasis: var(--base1);
		--fg-deemphasis: var(--base01);
		--accent-primary: var(--blue);
		--accent-secondary: var(--cyan);
	}
}

/* Fonts */
@font-face {
	font-family: "Brygada 1918";
	src: url("fonts/Brygada1918-VariableFont_wght.ttf") format("truetype");
	font-weight: 400 700;
	font-style: normal;
}

@font-face {
	font-family: "Brygada 1918";
	src: url("fonts/Brygada1918-Italic-VariableFont_wght.ttf") format("truetype");
	font-weight: 400 700;
	font-style: italic;
}

body {
	font-family: "Brygada 1918", serif;
	font-weight: 400;
	color: var(--fg-primary);
	background-color: var(--bg-primary);
	counter-reset: section;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	font-family: "Brygada 1918", serif;
	font-weight: 550;
}

h2 {
	counter-reset: theorem;
	counter-increment: section;
}

code,
pre,
kbd,
samp,
tt {
	font-family:
		ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
		"DejaVu Sans Mono", monospace;
}

/* Base elements */
hr {
	border-color: var(--blue);
}

a {
	color: var(--blue);
}
a:visited {
	color: var(--violet);
}
a:hover {
	color: var(--cyan);
	border-bottom: 2px solid var(--fg-primary);
}

blockquote {
	border-left: 5px solid var(--blue);
	background-color: var(--bg-secondary);
}

pre {
	background-color: var(--bg-secondary);
}

code,
kbd,
samp {
	background-color: var(--bg-secondary);
}

input,
textarea,
select {
	color: var(--fg-primary);
	background-color: var(--bg-secondary);
	border: 1px solid var(--fg-deemphasis);
}

input:focus,
textarea:focus {
	border: 1px solid var(--blue);
}

.button,
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {
	background-color: var(--blue);
	border: 1px solid var(--blue);
}

.button:hover,
button:hover,
input[type="submit"]:hover,
input[type="reset"]:hover,
input[type="button"]:hover {
	background-color: var(--cyan);
}

td,
th {
	border-bottom: 1px solid var(--bg-secondary);
}

/* Header */
.header {
	display: flex;
	justify-content: space-between;
	margin-bottom: 2rem;
}

.header-left,
.header-right {
	display: flex;
	gap: 0;
}

.header a {
	padding: 0 1em;
	border-bottom: 2px solid transparent;
}

.header-left a:first-child {
	padding-left: 0;
}

/* Links */
a.broken-link,
a.broken-link:visited,
a.broken-link:hover,
a.broken-link:active,
a.broken-link:link {
	color: #cc0000 !important;
	font-style: italic;
}

/* Syntax highlighting */
.org-keyword {
	color: var(--green);
}
.org-type {
	color: var(--yellow);
}
.org-function-name {
	color: var(--blue);
}
.org-variable-name {
	color: var(--blue);
}
.org-constant {
	color: var(--cyan);
}
.org-string {
	color: var(--cyan);
}
.org-comment {
	color: var(--fg-deemphasis);
	font-style: italic;
}
.org-comment-delimiter {
	color: var(--fg-deemphasis);
}
.org-doc {
	color: var(--fg-deemphasis);
	font-style: italic;
}
.org-builtin {
	color: var(--green);
}
.org-preprocessor {
	color: var(--orange);
}
.org-warning {
	color: var(--red);
	font-weight: bold;
}

/* Python-specific */
.org-py-object-reference {
	color: var(--blue);
}
.org-py-XXX-tag {
	color: var(--red);
	font-weight: bold;
}

/* TikZJax diagram styling */
.tikzjax {
	display: block;
	margin: 2em auto;
	transform: scale(1.5);
	transform-origin: center;
}

/* LaTeX rendered to SVG (tikz-cd &c. — anything MathJax can't do).
   Each SVG carries its own prefers-color-scheme stylesheet, since an SVG
   in an <img> can't inherit the page's colours. Size is baked in at
   export time via js/blog-svg-scale. */
.latex-svg {
	display: block;
	margin: 1.5em 0;
	overflow-x: auto;
	text-align: center;
}

.latex-svg img {
	display: inline-block;
	max-width: 100%;
	height: auto;
}

/* --- Theorem-style blocks --- */

.theorem,
.proposition,
.lemma,
.corollary,
.definition,
.lexample,
.remark,
.axiom {
	counter-increment: theorem;
}

.definition,
.theorem,
.lemma,
.corollary,
.proposition,
.remark,
.lexample,
.proof,
.axiom {
	margin: 1.5rem 0;
	padding: 0.75rem 1rem 0.75rem 1.25rem;
	background-color: var(--bg-secondary);
	border-left: 3px solid var(--fg-deemphasis);
	border-radius: 0 2px 2px 0;
}

/* Per-environment accent colors */
.theorem {
	border-left-color: var(--blue);
}
.lemma {
	border-left-color: var(--blue);
}
.corollary {
	border-left-color: var(--cyan);
}
.proposition {
	border-left-color: var(--cyan);
}
.definition {
	border-left-color: var(--green);
}
.lexample {
	border-left-color: var(--yellow);
}
.remark {
	border-left-color: var(--fg-deemphasis);
}
.proof {
	border-left-color: var(--violet);
}
.axiom {
	border-left-color: var(--magenta);
}

/* Environment label + shared section.theorem counter */
.theorem::before {
	content: "Theorem " counter(section) "." counter(theorem) ".";
}
.proposition::before {
	content: "Proposition " counter(section) "." counter(theorem) ".";
}
.lemma::before {
	content: "Lemma " counter(section) "." counter(theorem) ".";
}
.corollary::before {
	content: "Corollary " counter(section) "." counter(theorem) ".";
}
.definition::before {
	content: "Definition " counter(section) "." counter(theorem) ".";
}
.lexample::before {
	content: "Example " counter(section) "." counter(theorem) ".";
}
.remark::before {
	content: "Remark " counter(section) "." counter(theorem) ".";
}
.axiom::before {
	content: "Axiom " counter(section) "." counter(theorem) ".";
}
.proof::before {
	content: "Proof.";
}

.theorem::before,
.proposition::before,
.lemma::before,
.corollary::before,
.definition::before,
.lexample::before,
.remark::before,
.axiom::before,
.proof::before {
	display: inline;
	font-weight: 600;
	font-style: normal;
	color: var(--accent-primary);
	margin-right: 0.3em;
}

/* Optional title: shown inline as (Title). */
.block-title {
	display: inline;
	font-weight: 400;
	font-style: italic;
	color: var(--fg-emphasis);
}

.block-title::before {
	content: "(";
}
.block-title::after {
	content: ").";
	margin-right: 0.4em;
}

/* Collapsible headlines */
details > summary {
	cursor: pointer;
	list-style: none;
	display: flex;
	align-items: baseline;
}

details > summary::-webkit-details-marker {
	display: none;
}

details > summary > h2,
details > summary > h3,
details > summary > h4,
details > summary > h5,
details > summary > h6 {
	display: inline;
	margin: 0;
	flex: 1;
}

details > summary::after {
	content: "▶";
	font-size: 0.65em;
	color: var(--fg-deemphasis);
	display: inline-block;
	transition: transform 0.15s ease;
	margin-left: 0.4em;
	align-self: center;
}

details[open] > summary::after {
	transform: rotate(90deg);
}

.js-toggle-headings {
	display: block;
	font-size: 0.75em;
	font-family: ui-monospace, monospace;
	color: var(--fg-deemphasis);
	background: none;
	border: 1px solid var(--fg-deemphasis);
	border-radius: 2px;
	padding: 0.1em 0.5em;
	margin: 0.5em 0 1.5em 0;
	cursor: pointer;
}

.js-toggle-headings:hover {
	color: var(--accent-primary);
	border-color: var(--accent-primary);
	background: none;
}

/* Tables */
.table-wrapper {
	overflow-x: auto;
	margin: 1.5rem 0 2.5rem;

	/* Break out of the narrow prose column: 90vw, centred on the viewport.
	   max() keeps it at least as wide as the column itself, since on a
	   phone 90vw is narrower than the text and the table would otherwise
	   end up inset from the prose. */
	width: max(90vw, 100%);
	position: relative;
	left: 50%;
	transform: translateX(-50%);   /* center on the viewport, no % ambiguity */
}

table {
	width: max-content;
	min-width: 100%;
	border-collapse: collapse;
	font-size: 0.92em;
	text-align: left;
	margin: 0;
}

thead th {
	text-align: left;
	font-weight: 600;
	color: var(--fg-emphasis);
	border-bottom: 2px solid var(--accent-primary);
	padding: 0.45em 0.85em;
	white-space: nowrap;
	letter-spacing: 0.01em;
}

/* Sortable headers (table-sort.js, opt in with #+ATTR_HTML: :class sortable).
   `all: unset` is load-bearing — without it these inherit the blue filled
   button styling further up and every header turns into a blue pill. */
.sortable thead th .sort-btn {
	all: unset;
	cursor: pointer;
	font: inherit;
	color: inherit;
}

.sortable thead th .sort-btn:hover {
	color: var(--accent-primary);
}

.sortable thead th .sort-btn:focus-visible {
	outline: 2px solid var(--accent-primary);
	outline-offset: 2px;
}

/* Direction indicator. The neutral one stays faint until hover, so a wide
   table isn't a row of loud arrows. */
.sortable thead th .sort-btn::after {
	font-size: 0.8em;
	margin-left: 0.4em;
	color: var(--fg-deemphasis);
}

.sortable thead th[aria-sort="none"] .sort-btn::after {
	content: "⇅";
	opacity: 0.3;
}

.sortable thead th[aria-sort="none"] .sort-btn:hover::after {
	opacity: 0.8;
}

.sortable thead th[aria-sort="ascending"] .sort-btn::after {
	content: "▲";
	color: var(--accent-primary);
}

.sortable thead th[aria-sort="descending"] .sort-btn::after {
	content: "▼";
	color: var(--accent-primary);
}

td {
	padding: 0.5em 0.85em;
	border-bottom: 1px solid var(--bg-secondary);
	vertical-align: top;
	text-align: left;
}

tbody tr:nth-child(even) {
	background-color: var(--bg-secondary);
}

/* org alignment cookies: org adds .org-right / .org-center / .org-left */
td.org-right, th.org-right { text-align: right; font-variant-numeric: tabular-nums; }
td.org-center, th.org-center { text-align: center; }

/* caption styling, since real posts will use #+CAPTION: */
table caption {
	caption-side: bottom;
	font-size: 0.85em;
	font-style: italic;
	color: var(--fg-secondary);
	margin-top: 0.5em;
	text-align: left;
}
