/* Reset */

* {
	box-sizing: border-box;
}

blockquote,
dd,
dl,
figure,
h1,
h2,
h3,
h4,
h5,
h6,
hr,
p,
pre {
	margin: 0;
}

a {
	text-decoration: none;
}

/* Variables */

:root {
	--bold: 700;

	--shade-0: rgb(250, 250, 249);
	--shade-1: rgb(245, 245, 244);
	--shade-2: rgb(231, 229, 228);
	--shade-3: rgb(214, 211, 209);
	--shade-4: rgb(166, 160, 155);
	--shade-5: rgb(121, 113, 107);
	--shade-6: rgb(87, 83, 77);
	--shade-7: rgb(68, 64, 59);
	--shade-8: rgb(41, 37, 36);
	--shade-9: rgb(28, 25, 23);

	/* TODO: darken for light theme. */
	--bright-orange: rgb(194, 88, 1);
	--neutral-aqua: rgb(72, 111, 73);
	--pale-aqua: rgb(89, 136, 81);
	--pale-blue: rgb(80, 129, 118);
	--pale-orange: rgb(190, 90, 26);
	/* --pale-purple: transparent; /\* TODO: not found *\/ */
	--pale-red: rgb(205, 37, 27);
	--pale-yellow: rgb(172, 121, 40);
	--pale-purple: rgb(100, 44, 79); /* TODO: not found, also darken */
}

@media screen and (prefers-color-scheme: dark) {
	:root {
		--shade-0: rgb(28, 25, 23);
		--shade-1: rgb(41, 37, 36);
		--shade-2: rgb(68, 64, 59);
		--shade-3: rgb(87, 83, 77);
		--shade-4: rgb(121, 113, 107);
		--shade-5: rgb(166, 160, 155);
		--shade-6: rgb(214, 211, 209);
		--shade-7: rgb(231, 229, 228);
		--shade-8: rgb(245, 245, 244);
		--shade-9: rgb(250, 250, 249);

		--bright-orange: rgb(254 128 25);
		--neutral-aqua: rgb(104 157 106);
		--pale-aqua: rgb(137 180 130);
		--pale-blue: rgb(125 174 163);
		--pale-orange: rgb(231 138 78);
		--pale-purple: transparent; /* TODO: not found */
		--pale-red: rgb(234 105 98);
		--pale-yellow: rgb(216 166 87);
	}
}

@media screen and (prefers-reduced-motion: reduce) {
	html {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		/* Transitions are already very subtle. */
	}
}

@media screen and (prefers-reduced-motion: none) {
	html {
		scroll-behaviour: smooth;
	}
}

/* Writing help */

.drawer.alt {
	color: red;
}

/* Styles */

@keyframes appear {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

html {
	background: var(--shade-0);
	tab-size: 3;
}

body {
	background: var(--shade-0);
	color: var(--shade-9);
	line-height: 1.625;
	font-size: 1.25em;
	font-family:
		JetBrains Mono,
		Consolas,
		Monaco,
		Liberation Mono,
		Lucida Console,
		monospace;
	text-rendering: optimizeLegibility;
	display: flex;
	flex-direction: column;
	height: 100vh;
	margin: 0;
	opacity: 1;
	visibility: visible;
	animation: appear 0.3s ease-out;
}

figure {
	max-width: max-content;
}

main#content h2 a {
	text-decoration: none;
}

a {
	color: var(--shade-6);
	transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

a:hover {
	color: var(--shade-9);
}

.visually-hidden:not(:focus):not(:active) {
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	height: 1px;
	overflow: hidden;
	position: absolute;
	white-space: nowrap;
	width: 1px;
}

#jump-to-content {
	position: absolute;
	top: 0;
	left: 0;
}

#preamble {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 0 1ex 1ex 1ex;
	margin-bottom: 1.5rem;
	border-bottom: 0.3ex solid var(--shade-7);
}

@media screen and (min-width: 640px) {
	#preamble {
		flex-direction: row;
		align-items: flex-start;
		align-content: flex-start;
		justify-content: space-between;
		margin: 4rem auto 1.5rem auto;
		width: 100%;
		max-width: 64rem;
	}
}

/* @media screen and (min-width: 64rem) { */
/* @media screen and (min-width: 780px) { */
@media screen and (min-width: 50rem) {
	article#content > * {
		width: 70%;
	}
}

@media screen and (min-width: 65rem) {
	#preamble {
		padding: 0 0 1ex 0;
	}
}

header h1 {
	display: flex;
	justify-content: space-between;
	font-size: 1.75rem;
	font-weight: normal;
	line-height: 2rem;
	margin: 0;
}

#preamble div:last-of-type {
	display: flex;
	flex-direction: column;
	align-items: center;
}

#preamble nav {
	display: flex;
	align-items: baseline;
	gap: 1.5ex;
	order: 1;
}

#preamble nav a {
	font-size: 1.15rem;
	/* margin: 0 1ex; */
	text-transform: uppercase;
}

#preamble nav img {
	width: 0.85rem;
	height: 0.85rem;
}

#preamble tt {
	color: var(--shade-2);
	font-size: 0.75rem;
	margin: 0;
	user-select: none;
	order: 0;
}

#preamble p:last-of-type {
	color: var(--shade-7);
	font-size: 0.75rem;
	text-align: center;
}

@media screen and (min-width: 640px) {
	#preamble nav {
		order: 0;
	}

	#preamble tt {
		order: 1;
	}

	#preamble p:last-of-type {
		text-align: left;
		margin-left: 0.3rem;
	}

	#preamble div:last-of-type {
		align-items: flex-end;
	}
}

.back-home {
	font-size: 0.75rem;
	line-height: 1rem;
	max-width: 64rem;
}

#content {
	position: relative;
	width: 100%;
	max-width: 64rem;
	margin: 0 auto auto auto;
	padding: 1rem;
	overflow-wrap: break-word;
	word-break: break-word;
}

@media (min-width: 65rem) {
	#content {
		gap: 2rem;
		padding: 0;
	}
}

#content h1,
#content h2,
#content h3,
#content h4,
#content h5,
#content h6 {
	font-weight: 600;
	line-height: 1.6;
	border-bottom: 1px solid var(--shade-2);
	padding-bottom: 0.25rem;
	margin-top: 1.25rem;
	margin-bottom: 0.5rem;
}

#content h1 {
	font-size: 1.25rem;
	font-weight: var(--bold);
	margin-bottom: 0.75rem;
	margin-top: 1.5rem;
	border-bottom-width: 2px;
}

#content h1.title {
	margin-top: 0;
	border: 0;
}

#content h2 {
	font-size: 1.125rem;
}

#content h3 {
	font-size: 1rem;
	margin-top: 1rem;
	margin-bottom: 0.5rem;
}

#content a {
	text-decoration: underline;
}

#content p,
#content li,
#content dt,
#content dd,
#content p + figure {
	font-size: 0.875rem;
	/* line-height: 1.75; */
	line-height: 1.5;

	/* margin-bottom: 0.75rem; */
	/* margin-top: 0; */
	margin-bottom: 1.5rem;
	margin-top: 1.5rem;
}

#content p + p {
	margin-top: 0.25rem;
}

#content img:not(.org-svg) {
	display: block;
	height: auto;
	max-width: 100%;
	margin: 0.75rem 0 0.75rem 0;
	border-radius: 0.375rem;
	border: 1px solid var(--shade-2);
}

#content img.org-svg {
	vertical-align: middle;
	max-width: 100%;
}

#content p img {
	height: 1em;
}

@media screen and (prefers-color-scheme: dark) {
	#content .org-svg {
		filter: invert(100%);
	}
}

#content ul {
	list-style-type: disc;
}

#content ol {
	list-style-type: decimal;
}

#content ol,
#content ul {
	margin-left: 1.5rem;
	margin-top: 1rem;
	margin-bottom: 1rem;
	padding-left: 0;
}

#content li {
	margin-top: 0rem;
	margin-bottom: 0rem;
	padding-left: 0.25rem;
}

#content ul ul,
#content ol ol,
#content ul ol,
#content ol ul {
	margin-top: 0.5rem;
	margin-bottom: 0.5rem;
}

#content dl {
	margin: 1.25rem 0;
}

#content dt {
	font-weight: 600;
	margin-top: 1.25rem;
}

#content dd {
	margin-top: 0.5rem;
	padding-left: 1.625rem;
}

#content code {
	background: var(--shade-2);
	padding: 0.125rem;
	border: 1px solid var(--shade-1);
	border-radius: 0.25rem;
}

#content pre {
	overflow-x: auto;
	background: var(--shade-1);
	margin-top: 0.75rem;
	margin-bottom: 0.75rem;
	padding: 0.5rem;
	border: 1px solid var(--shade-2);
	border-radius: 0.375rem;
	/* TODO: Maybe not */
	line-height: initial;
}

#content pre.src {
	position: relative;
}

/* TODO */
/* #content pre.src::after { */
/* 	background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGQ9Ik0xNSAyMEg1VjdjMC0uNTUtLjQ1LTEtMS0xcy0xIC40NS0xIDF2MTNjMCAxLjEuOSAyIDIgMmgxMGMuNTUgMCAxLS40NSAxLTFzLS40NS0xLTEtMW01LTRWNGMwLTEuMS0uOS0yLTItMkg5Yy0xLjEgMC0yIC45LTIgMnYxMmMwIDEuMS45IDIgMiAyaDljMS4xIDAgMi0uOSAyLTJtLTIgMEg5VjRoOXoiLz48L3N2Zz4=); */
/* 	content: ""; */
/* 	/\* position: absolute; *\/ */
/* 	position: sticky; */

/* 	top: 0.5rem; */
/* 	right: 0.5rem; */
/* 	/\* width: 24px; *\/ */
/* 	/\* height: 24px; *\/ */
/* 	width: 0.75rem; */
/* 	height: 0.75rem; */
/* 	opacity: 0; */
/* 	transition: 0.15s opacity ease-out; */
/* 	padding: 0.25rem; */
/* } */

#content pre.src:hover::after {
	opacity: 1;
}

#content blockquote {
	margin: 1.5rem;
	padding: 0.75rem 1rem;

	color: var(--shade-6);
	font-style: italic;

	border-left: 3px solid var(--shade-2);
	border-radius: 0 0.375rem 0.375rem 0;
}

#content blockquote p {
	width: 100%;
}

#content blockquote p:first-child {
	margin-top: 0;
}

#content blockquote p:last-child {
	margin-bottom: 0;
}

aside {
	flex-shrink: 0;
	width: 14rem;
}

footer {
	border-top: solid 1px var(--shade-2);
	margin-top: 3rem;
}

footer .container {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;

	max-width: 64rem;
	margin: auto;
	padding: 1rem;
	gap: 0.75rem;
}

footer .container p {
	color: var(--shade-5);
	font-size: 0.75rem;
	line-height: 1rem;
}

#footnotes {
	display: inline-block;
}

@media (min-width: 64rem) {
	#footnotes {
		display: none;
	}
}

.footdef {
	display: flex;
	font-size: 0.75rem;
	gap: 1rem;
}

#content .footdef p {
	margin-top: 0;
}

/* ---------------- */

.margin-note,
.side-note {
	display: none;
}

#content .side-note-number {
	font-size: 0.75rem;
}

#content .side-note-number a {
	text-decoration: none;
}

#content .margin {
	padding: 0.5rem;
	background-color: var(--shade-1);
	border-radius: 0.375rem;

	& > p {
		margin-top: 0;
	}
}

#content .margin :first-child {
	margin-top: 0;
}
#content .margin :last-child {
	margin-bottom: 0;
}

@media screen and (min-width: 800px) {
	.margin-note,
	.side-note {
		display: initial;
		clear: right;
		float: right;

		width: 35.7%;
		margin-right: -42.9%;
		font-size: 0.75rem;
		font-style: normal;
		line-height: 1.5;
		color: var(--shade-9);
		/* TODO: Maybe remove, see if styling is consistent */
		/* padding: 0 0.5rem; */
		/* background-color: var(--shade-1); */
		border-radius: 0.375rem;
		/* padding: 0.5rem; */

		position: relative;
		vertical-align: baseline;
	}

	.margin {
		display: none;
	}
}

.tag {
	float: right;
	clear: right;

	color: var(--shade-6);
	background: var(--shade-2);

	border-radius: 999px;
	padding: 0.125rem 0.5rem;

	font-size: 0.75rem;
	line-height: 1rem;
	text-decoration: none !important; /* TODO: workaround !important */
}

.tag:nth-of-type(5n + 1),
.rainbow:nth-of-type(5n + 1) {
	color: var(--pale-orange);
}

.tag:nth-of-type(5n + 2),
.rainbow:nth-of-type(5n + 2) {
	color: var(--pale-blue);
}

.tag:nth-of-type(5n + 3),
.rainbow:nth-of-type(5n + 3) {
	color: var(--pale-red);
}

.tag:nth-of-type(5n + 4),
.rainbow:nth-of-type(5n + 4) {
	color: var(--pale-yellow);
}

.page-meta > .tag {
	float: none;
}

.page-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: center;

	color: var(--shade-5);
	font-size: 0.75rem;
	line-height: 1rem;

	margin-bottom: 0.5rem;
}

main h1:has(+ .page-meta) {
	margin-bottom: 0;
}

#content .preview-ellipsis {
	display: inline-block;
	background: var(--shade-1);
	padding: 0.125rem 0.25rem;
	border: 1px solid var(--shade-2);
	border-radius: 0.25rem;
	font-size: 0.75rem;
	line-height: 0.75rem;
	text-decoration: none;
}

/* Sitemap specific */

.page-preview h2 a {
	text-decoration: none;
}

/* Source Block Fontification */

.hl-keyword,
.hl-string {
	font-style: italic;
}

.hl-function-call {
	font-weight: bold;
}

.hl-comment,
.hl-comment-delimiter,
.hl-doc {
	color: var(--shade-4);
}

.hl-constant,
.hl-number {
	color: var(--pale-purple);
}

.hl-builtin {
	color: var(--pale-aqua);
}

.hl-delimiter,
.hl-bracket,
.hl-punctuation,
.hl-misc-punctuation,
.hl-operator,
.hl-preprocessor {
	color: var(--neutral-aqua);
}

.hl-keyword {
	color: var(--pale-red);
}

.hl-function-call,
.hl-function-name {
	color: var(--pale-orange);
}

.hl-property-name,
.hl-property-use,
.hl-variable-name,
.hl-variable-use {
	color: var(--pale-blue);
}

.hl-string,
.hl-type {
	color: var(--pale-yellow);
}

.hl-warning {
	color: var(--bright-orange);
}

.org-center,
figure {
	text-align: center;
	margin: auto;
}

/* TODO: Elements */

.verse {
	background: var(--shade-1);
	font-style: italic;
	padding: 1rem;
}

/* Utility classes */

.center {
	margin-left: auto;
	margin-right: auto;
}

.max-w-fit {
	max-width: fit-content;
}
