*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  --color-foreground: #000;
  --color-background: #fff;
  --color-internal-link: #cceab6;
  --color-kbd: #aaa;
  --color-code-background: #f7f7f7;
  --color-code-border: #9f9f9f;
  --color-fl-comment: #696969;
  --color-fl-string: #6b8e23;
  font-size: 16px;
  height: 100%;
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  margin-left: calc(100vw - 100%);
  margin-right: 0;
}

body {
  background-color: var(--color-background);
  color: var(--color-foreground);
  height: 100%;
  padding: 1rem 1rem 0;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  max-width: 56rem;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

nav {
  display: flex;
  flex-direction: column;
  align-items: end;
}

nav > a {
  margin: 0 0.5rem;
}

main {
  flex: 1;
}

article {
  display: grid;
  grid-template-columns: 2fr 1fr;
  column-gap: 2rem;
}

article > * {
  grid-column: 1 / 2;
}

article p {
  font-size: 1.083rem;
}

article > aside {
  grid-column: 2 / 3;
}

article > aside p {
  font-size: 0.917rem;
}

article > * + * {
  margin-top: 1rem;
}

aside p + p {
  margin-top: 1rem;
}

h1 {
  font-size: 1.417rem;
}

section.backlinks + *, section.backlinks + p + aside, h1 + *, h1 + p + aside, h2 + *, h2 + p + aside, h3 + *, h3 + p + aside {
  margin-top: 0.75rem;
}

* + section.backlinks, * + h1, * + h2, * + h3 {
  margin-top: 2rem;
}

section.backlinks + * {
  margin-top: 2rem;
}

h1, h2, h3 {
  font-family: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, serif;
  border-bottom: 1px dotted var(--color-foreground);
}

section.backlinks h1, h2 {
  font-size: 1.333rem;
}

h1, h2 {
  font-weight: 500;
}

h3 {
  font-size: 1.25rem;
  font-weight: bold;
}

/* HACK to work around templating system limitations. */
section.backlinks:has(h1:first-child:last-child) {
  display: none;
}

.modified {
  font-size: 0.917rem;
  padding: 0.667rem 0;
  border-top: 1px dotted var(--color-foreground);
}

footer {
  font-size: 0.917rem;
  padding: 1rem 0;
}

footer ul {
  padding-left: 0;
}

footer ul, footer li {
  display: inline;
}

footer li::before {
  content: "\2022";
  font-size: 0.667em;
  vertical-align: middle;
  display: inline-block;
  margin: 0 0.5em;
}

pre:has(> code) {
  background-color: var(--color-code-background);
  padding: 0.5rem;
  border-radius: 0.167rem;
  font-size: 0.833em;
}

*:not(pre) > code, kbd {
  font-size: 0.833em;
}

aside *:not(pre) > code, aside kbd {
  font-size: 0.75rem;
}

*:not(pre) > code, kbd {
  border-radius: 0.167rem;
}

*:not(pre) > code, kbd {
  padding: 0.083em;
}

*:not(pre) > code {
  background-color: var(--color-code-background);
  border-radius: 0.167rem;
}

kbd {
  border: 1px solid var(--color-kbd);
  word-break: keep-all;
}

.org-comment {
  color: var(--color-fl-comment);
}

.org-comment-delimiter {
  color: --color-fl-comment;
}

.org-doc {
  color: var(--color-fl-comment);
  font-style: italic;
}

.org-keyword {
  font-weight: 600;
}

.org-preprocessor {
  font-style: italic;
}

.org-string {
  color: var(--color-fl-string);
}

.org-type {
  text-decoration: underline;
}

.org-warning {
  color: var(--color-fl-warning);
}

ol {
  list-style-type: lower-roman;
}

article ul {
  list-style-type: "\2192  ";
  padding-left: 2rem;
}

article li {
  padding: 0.083rem 0;
}

section.backlinks ul {
  margin-top: 0.5rem;
}

section.backlinks li {
  list-style-type: "\2190  ";
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
}

a.internal {
  text-decoration-style: solid;
  word-break: keep-all;
}

blockquote p {
  margin-left: 4rem;
  font-style: italic;
}

blockquote p::before {
  content: "\201c";
}

blockquote p::after {
  content: "\201d";
}

blockquote + p {
  text-align: right;
}

pre {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
}

td, th {
  border: 1px solid var(--color-foreground);
  padding: 0.333rem;
}

strong {
  font-weight: 600;
}

.underline {
  text-decoration: underline dashed;
}

@media (max-width: 900px) {
  article {
    display: block;
    margin: auto;
  }
  article > aside {
    margin: 1.5rem 1.5rem 0 !important;
  }
  article, article > aside {
    max-width: 32em;
  }
}

@media (prefers-color-scheme: dark) {
  html {
    --color-foreground: #e1e1e1;
    --color-background: #0c0c0c;
    --color-internal-link: #334a26;
    --color-kbd: #555;
    --color-code-background: #1a1a1a;
    --color-code-border: #646464;
    --color-fl-comment: #b2b2b2;
    --color-fl-string: #a2cd5a;
  }
  .invertible {
    filter: invert(0.95) hue-rotate(180deg);
  }
}

article.blog a {
  text-decoration-style: solid;
}

h1.blog-title {
  border-bottom: 0;
}

h1.blog-title + span {
  margin-top: 0;
  font-size: 0.833rem;
  color: #4a4a4a;
}

h1.blog-title + span .edited {
  font-size: 0.75rem;
}
