:root {
  --bg: #ffffff;
  --fg: #202122;
  --muted: #54595d;
  --rule: #c8ccd1;
  --link: #3366cc;
  --panel: #f8f9fa;
}

[data-theme="dark"] {
  --bg: #101418;
  --fg: #e4e6e8;
  --muted: #a2a9b1;
  --rule: #34383d;
  --link: #88a9e6;
  --panel: #181c20;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.65;
}

.layout {
  padding: 2.5rem 1.5rem 6rem;
}

main {
  max-width: 46em;
  margin: 0 auto;
}

/* Contents */

#toc {
  position: fixed;
  top: 2.5rem;
  left: 2rem;
  width: 14rem;
  max-height: calc(100vh - 5rem);
  overflow: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

#toc .home {
  display: block;
  margin-bottom: 1.25rem;
  color: var(--fg);
  font-weight: 600;
}

#toc h2 {
  font: inherit;
  font-weight: 600;
  margin: 0 0 0.5rem;
  border: 0;
}

#toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--rule);
}

#toc a {
  display: block;
  padding: 0.2rem 0.75rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
}

#toc a:hover {
  color: var(--link);
}

#toc a.active {
  color: var(--fg);
  border-left-color: var(--link);
}

#toc .h3 a {
  padding-left: 1.5rem;
}

/* Article */

main :is(h1, h2) {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  line-height: 1.25;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.25rem;
}

h1 {
  font-size: 2.1rem;
  margin: 0;
}

main h2 {
  font-size: 1.5rem;
  margin: 2.25rem 0 0.75rem;
}

main h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.75rem 0 0.5rem;
}

/* Keep heading text and underlines from running beneath a floated figure */
main :is(h2, h3) {
  overflow: hidden;
}

/* Images */

main img {
  max-width: 100%;
  height: auto;
}

figure.right {
  float: right;
  width: 14rem;
  max-width: 40%;
  margin: 0.3rem 0 1rem 1.5rem;
  padding: 0.4rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

figure.right img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

figure.right figcaption {
  padding-top: 0.4rem;
}

@media (max-width: 34rem) {
  figure.right {
    float: none;
    width: auto;
    max-width: 18rem;
    margin: 0 0 1rem;
  }
}

.sub {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  margin: 0.4rem 0 1.5rem;
}

p,
ul {
  margin: 0 0 0.9rem;
}

a {
  color: var(--link);
  text-decoration: none;
}

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

.posts li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--rule);
}

.posts .date {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

a:hover {
  text-decoration: underline;
}

/* Theme toggle */

#theme {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1;
  padding: 0.25rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

/* Not enough room beside the centered article: stack the contents above it */
@media (max-width: 82rem) {
  #toc {
    position: static;
    width: auto;
    max-width: 46em;
    margin: 0 auto 2rem;
  }
}
