html {
	--col-page: #fbfbf9;
	--col-back: #ffffff;
	--col-text: #444444;
	--col-link: #4466aa;
	--col-link-hover: #6699bb;
	--col-outline: #000000;
	--col-border: #cccccc;
	--col-border-hover: #888888;

	--col-h-comment: #999988;
	--col-h-error: #a61717;
	--col-h-error-back: transparent;
	--col-h-builtin: #000099;
	--col-h-number: #009999;
	--col-h-string: #dd1144;
	--col-h-name: #445588;
	--col-h-variable: #008080;
	--col-h-property: #800080;

	@media (prefers-color-scheme: dark) {
		--col-page: #111111;
		--col-back: #000000;
		--col-text: #eeeeee;
		--col-link: #4499ee;
		--col-link-hover: #aaccee;
		--col-outline: #f8f8f8;
		--col-border: #555555;
		--col-border-hover: #aaaaaa;

		--col-h-comment: #bbbbaa;
		--col-h-error: #ff0000;
		--col-h-error-back: transparent;
		--col-h-builtin: #88bbee;
		--col-h-number: #22cccc;
		--col-h-string: #dd8899;
		--col-h-name: #aaaacc;
		--col-h-variable: #77aaaa;
		--col-h-property: #dd88dd;
	}

	@media (prefers-contrast: more) {
		--col-page: Canvas;
		--col-back: Canvas;
		--col-text: CanvasText;
		--col-link: LinkText;
		--col-link-hover: LinkText;
		--col-outline: CanvasText;
		--col-border: ButtonBorder;
		--col-border-hover: ButtonBorder;

		--col-h-comment: GrayText;
		--col-h-error: MarkText;
		--col-h-error-back: Mark;
		--col-h-builtin: CanvasText;
		--col-h-number: CanvasText;
		--col-h-string: CanvasText;
		--col-h-name: CanvasText;
		--col-h-variable: CanvasText;
		--col-h-property: CanvasText;
	}
}

html,
h1,
h2,
h3,
h4,
h5,
h6,
nav,
article,
section {
	margin: 0;
	padding: 0;
	font: inherit;
	line-height: inherit;
	color: inherit;
}

body {
	margin: 0;
	padding: 10px 20px 80vh;
	font: 1.2em sans-serif;
	line-height: 1.8;
	color: var(--col-text);
	background: var(--col-page);
}

main {
	max-width: 75ch;
	margin: 0 auto;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	margin: 3em 0 0.9em;
	line-height: 1.4;
	text-rendering: optimizeLegibility;
}

header {
	margin: 2em 0 3em;
	display: grid;
	grid-template-columns: 1fr auto;
	grid-template-rows: auto auto auto;

	h1 {
		grid-column: 1 / 2;
		margin: 0;
	}

	.qr {
		grid-area: 1 / 2 / 5 / 3;
		width: 6em;
		height: 6em;
		margin: -8px -8px 0 8px;

		img {
			display: block;
			width: 100%;
			filter: invert(0.2);

			@media (prefers-color-scheme: dark) {
				filter: invert(0.95);
			}
		}
	}

	p {
		grid-column: 1 / 2;
		margin: 16px 0 0;
		font-size: 0.8em;
		text-align: left;
	}

	& .tags {
		grid-column: 1 / 2;
		margin: 4px 0 0;
		font-size: 0.7em;
	}
}

h1 {
	font-size: 2em;
}

h2 {
	font-size: 1.5em;
}

h3 {
	margin-bottom: 1em;
	font-size: 1.3em;
}

h4 {
	margin-bottom: 1em;
	font-size: 1.15em;
}

p {
	margin: 20px 0 0;
	text-align: justify;
}

sup {
	/* use custom vertical alignment to avoid changing the line height */
	vertical-align: baseline;
	position: relative;
	top: -0.5em;
}

sub {
	/* use custom vertical alignment to avoid changing the line height */
	vertical-align: baseline;
	position: relative;
	top: 0.5em;
}

hr {
	margin: 20px 0 30px;
	padding: 0;
	border: none;
	border-bottom: 1px solid var(--col-border);
}

del {
	text-decoration: line-through 1px;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	del {
		text-decoration: line-through 2px;
	}
}

footer {
	margin-top: 128px;
	font-size: 0.9em;
	text-align: end;
}

a:link,
a:visited {
	color: var(--col-link);
	text-decoration: underline;
}
a:active,
a:hover {
	color: var(--col-link-hover);
	text-decoration: none;
}

a.qr {
	text-decoration: none;
}

.tags {
	display: flex;
	flex-flow: row wrap;
	gap: 4px;
}

a.tag {
	pointer-events: all;
	display: inline-block;
	border: 1px solid var(--col-border);
	background: var(--col-back);
	padding: 0 1em;
	border-radius: 100px;
	text-decoration: none;
}
a.tag:active,
a.tag:hover {
	border-color: var(--col-border-hover);
}

img {
	box-sizing: border-box;
	max-width: 100%;
}

p:has(img:first-child) {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin: 40px max(-200px, calc((100vw - 100%) / -2 + 16px));
	text-align: center;
	font-style: italic;

	img:not(.sequence-diagram) {
		border: 1px solid var(--col-outline);
		border-radius: 4px;
		align-self: center;
	}
}

img.sequence-diagram {
	align-self: center;
	min-width: min(70ch, calc(100vw - 40px));

	@media (prefers-color-scheme: dark) {
		filter: hue-rotate(180deg) invert(0.95) saturate(3);
	}
}

a.feed {
	padding: 2px 0 0 calc(1em + 6px);
	background: center left / 1em 1em no-repeat url('/feed.svg');
}

code {
	white-space: nowrap;
}

pre {
	margin: 16px 0;
	padding: 16px 20px;
	background: var(--col-back);
	overflow: auto;
	tab-size: 4;
	border: 1px solid var(--col-outline);
	border-radius: 4px;

	code {
		white-space: pre;
	}
}

blockquote {
	border-left: 2px solid var(--col-border);
	padding-left: 16px;
	margin: 16px 0 16px 16px;
}

.posts {
	list-style: none;
	margin: 0;
	padding: 0;

	li {
		margin: 32px 0;
		padding: 0;

		& > a {
			display: block;
			position: relative;
			padding: 24px 16px;
			background: var(--col-back);
			border: 1px solid var(--col-border);
			border-radius: 4px;
			text-decoration: none;

			&:active,
			&:hover {
				border-color: var(--col-border-hover);
			}
		}

		time {
			position: absolute;
			top: 4px;
			right: 6px;
			font-size: 0.6em;
		}

		& .post-title {
			font-size: 1.2em;
			line-height: 1.2;
		}

		& .tags {
			pointer-events: none;
			position: relative;
			margin: -12px 16px 0;
			font-size: 0.7em;
			min-height: calc(1em * 1.8 + 2px);
		}
	}
}

.highlight .comment,
.highlight .meta {
	color: var(--col-h-comment);
	font-style: italic;
}
.highlight .error {
	color: var(--col-h-error);
	background: var(--col-h-error-back);
}
.highlight .keyword {
	font-weight: bold;
}
.highlight .selector-tag {
	font-weight: bold;
}
.highlight .built_in,
.highlight .title {
	color: var(--col-h-builtin);
}
.highlight .number {
	color: var(--col-h-number);
}
.highlight .string {
	color: var(--col-h-string);
}
.highlight .name {
	color: var(--col-h-name);
	font-weight: bold;
}
.highlight .variable {
	color: var(--col-h-variable);
}
.highlight .property,
.highlight .literal,
.highlight .attribute,
.highlight .attr {
	color: var(--col-h-property);
}

@media print {
	body {
		--col-page: transparent;
		--col-back: white;
		--col-text: black;
		--col-link: black;
		font-size: 1em;
		padding: 0;
	}

	header p,
	header .tags {
		margin: 0;
	}

	pre {
		padding: 4px 8px;
		font-size: 0.8em;

		code {
			white-space: pre-wrap;
		}
	}

	a.tag {
		border: none;
		padding: 0 8px 0 0;
		background: var(--col-back);
	}
}
