/* CSS reset based on from https://www.joshwcomeau.com/css/custom-css-reset/ */

/* 1. Use a more-intuitive box-sizing model */
*,
*::before,
*::after {
	box-sizing: border-box;
}

/* 2. Remove default margin */
*:not(dialog) {
	margin: 0;
}

/* 3. Enable keyword animations */
@media (prefers-reduced-motion: no-preference) {
	html {
		interpolate-size: allow-keywords;
	}
}

body {
	/* 4. Increase line-height */
	line-height: 1.5;
	/* 5. Improve text rendering */
	-webkit-font-smoothing: antialiased;
}

/* 6. Improve media defaults */
img,
picture,
video,
canvas,
svg {
	display: block;
	max-width: 100%;
}

/* 7. Inherit fonts for form controls */
input,
button,
textarea,
select {
	font: inherit;
}

/* 8. Avoid text overflows */
p,
h1,
h2,
h3,
h4,
h5,
h6 {
	overflow-wrap: break-word;
}

/* 9. Improve line wrapping */
p {
	text-wrap: pretty;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	text-wrap: balance;
}


/* Color Themes */
/* from https://github.com/folke/tokyonight.nvim */
:root {
	--bg: #24283b;
	--bg_dark: #1f2335;
	--bg_dark1: #1b1e2d;
	--bg_highlight: #292e42;
	--blue: #7aa2f7;
	--blue0: #3d59a1;
	--blue1: #2ac3de;
	--blue2: #0db9d7;
	--blue5: #89ddff;
	--blue6: #b4f9f8;
	--blue7: #394b70;
	--comment: #565f89;
	--cyan: #7dcfff;
	--dark3: #545c7e;
	--dark5: #737aa2;
	--fg: #c0caf5;
	--fg_dark: #a9b1d6;
	--fg_gutter: #3b4261;
	--green: #9ece6a;
	--green1: #73daca;
	--green2: #41a6b5;
	--magenta: #bb9af7;
	--magenta2: #ff007c;
	--orange: #ff9e64;
	--purple: #9d7cd8;
	--red: #f7768e;
	--red1: #db4b4b;
	--teal: #1abc9c;
	--terminal_black: #414868;
	--yellow: #e0af68;
	--git-add: #449dab;
	--git-change: #6183bb;
	--git-delete: #914c54;

	color-scheme: dark;
}

@media (prefers-color-scheme: light) {
	:root {
		--bg: #e1e2e7;
		--bg_dark: #d0d5e3;
		--bg_dark1: #c1c9df;
		--bg_highlight: #c4c8da;
		--blue: #2e7de9;
		--blue0: #7890dd;
		--blue1: #188092;
		--blue2: #07879d;
		--blue5: #006a83;
		--blue6: #2e5857;
		--blue7: #92a6d5;
		--comment: #848cb5;
		--cyan: #007197;
		--dark3: #8990b3;
		--dark5: #68709a;
		--fg: #3760bf;
		--fg_dark: #6172b0;
		--fg_gutter: #a8aecb;
		--green: #587539;
		--green1: #387068;
		--green2: #38919f;
		--magenta: #9854f1;
		--magenta2: #d20065;
		--orange: #b15c00;
		--purple: #7847bd;
		--red: #f52a65;
		--red1: #c64343;
		--teal: #118c74;
		--terminal_black: #a1a6c5;
		--yellow: #8c6c3;
		--git_add: #4197a4;
		--git_change: #506d9c;
		--git_delete: #c4798;

		color-scheme: light;
	}
}

@media print {
	:root {
		--bg: #ffffff;
		--bg_dark: #ffffff;
		--bg_dark1: #ffffff;
		--bg_highlight: #ffffff;
		--fg_gutter: #808080;
		--fg: #000000;
		--fg_dark: #303030;

		color-scheme: light;
	}
}


/* Icons */
/* https://erikarow.land/notes/how-to-embed-svg-in-css */
:root {
	--icon-external-link: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%23a9b1d6' d='M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16zM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1'/></svg>");
}

@media (prefers-color-scheme: light) {
	:root {
		--icon-external-link: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%236172b0' d='M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16zM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1'/></svg>");
	}
}


/* Fonts */
@font-face {
	font-family: hyperlegible;
	src: url("/fonts/AtkinsonHyperlegibleNextVF-Variable.woff2");
}

@font-face {
	font-family: commitmono;
	src: url("/fonts/CommitMono-400-Regular.woff2");
}

:root {
	background-color: var(--bg);
	color: var(--fg);
	font-family: hyperlegible, sans-serif;
}

p code,
pre {
	font-family: commitmono, monospace;
	background-color: var(--bg_highlight);
	padding: 0.15em 0.3em;
	border: 1px solid var(--fg_dark);
	border-radius: 0.4em;
}


@media screen {
	body {
		margin-inline: auto;
		max-width: 80rem;

		display: grid;

		grid-template-columns: 1fr;
		grid-template-areas:
			"about"
			"nav"
			"main"
			"footer";

		gap: 4px;

		background-color: var(--fg_gutter);
	}
}

@media screen and (max-width: 60rem) {
	body {
		padding: 1rem;
	}
}

@media screen and (min-width: 60rem) {
	body {

		grid-template-columns: 25rem 1fr;
		grid-template-areas:
			"about nav"
			"about main"
			"footer footer";
	}
}

body>* {
	background-color: var(--bg);
	padding: 2rem;
}

body>aside {
	grid-area: about;
}

body>nav {
	grid-area: nav;
	font-size: 1.25rem;
}

body>nav ul {
	padding: 0;

	display: flex;
	flex-wrap: wrap;
}

body>nav li {
	display: inline;
}

body>nav li:not(:last-child):after {
	content: '';
	margin-inline: 1rem;
	border-left: 2px solid var(--fg_gutter);
}

@media print {
	body {
		display: block;
	}

	body>* {
		padding: 0;
	}

	body>nav {
		display: none;
	}
}

body>main {
	grid-area: main;
}

body>footer {
	grid-area: footer;
	text-align: center;
	padding-block: 1rem;
}

a {
	color: var(--fg);

	main &:visited {
		color: var(--fg_dark);
	}
}


/* Margins */
h1 {
	margin-top: 2rem;
}

h2,
h3,
h4,
h5,
h6 {
	margin-top: 1rem;
}

/* No margin on first header */
/* TODO: Is there a better way to do this? */
:is(aside, main)> :is(h1, h2, h3, h4, h5, h6):first-child {
	margin-top: 0;
}

section:first-child {

	:is(aside, main)>&>:is(h1, h2, h3, h4, h5, h6):first-child,
	:is(aside, main)>&>&>:is(h1, h2, h3, h4, h5, h6):first-child,
	:is(aside, main)>&>&>&>:is(h1, h2, h3, h4, h5, h6):first-child,
	:is(aside, main)>&>&>&>&>:is(h1, h2, h3, h4, h5, h6):first-child,
	:is(aside, main)>&>&>&>&>&>:is(h1, h2, h3, h4, h5, h6):first-child,
	:is(aside, main)>&>&>&>&>&>&>:is(h1, h2, h3, h4, h5, h6):first-child {
		margin-top: 0;
	}
}

p,
pre {
	margin-top: 1rem;
}


h1.title {
	font-size: 3em;
}

.subtitle {
	margin-top: 0;
	color: var(--fg_dark);
}


/* Stolen from wikipedia */
a.external {
	/* background-image: url("/icons/external_link.svg"); */
	background-image: var(--icon-external-link);
	background-position: center right;
	background-repeat: no-repeat;
	background-size: 0.857em;
	padding-right: 1em;
}
