/*
 * Paper and ink.
 *
 * Structure comes from spacing and alignment, not from boxes: every vertical
 * gap is a multiple of --line, everything shares one left edge, and --accent
 * is reserved for things that can be clicked.
 */

@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/source-serif-4-latin-wght-italic.woff2") format("woff2");
}

@font-face {
  font-family: "Source Code Pro";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/source-code-pro-latin-wght-normal.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  --paper: light-dark(#f7f3ea, #1b1815);
  --surface: light-dark(#eee8da, #26221d);
  --ink: light-dark(#221d18, #e6dfd3);
  --muted: light-dark(#6b6257, #a39a8c);
  --rule: light-dark(#d9d0be, #3b352d);
  --accent: light-dark(#9c3a1c, #e0825c);

  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino,
    Georgia, serif;
  --mono: "Source Code Pro", ui-monospace, "SF Mono", Menlo, Consolas,
    monospace;

  --line: 1.6rem;
  --measure: 38rem;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

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

html {
  font-size: 118.75%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  padding: 0 1.25rem;
  max-width: calc(var(--measure) + 2.5rem);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  line-height: var(--line);
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
dl,
figure,
blockquote,
pre,
table {
  margin: 0;
}

/* Site chrome */

.site-header {
  display: flex;
  align-items: baseline;
  gap: 3ch;
  padding-top: calc(var(--line) * 2);
  margin-bottom: calc(var(--line) * 3);
}

.site-header nav,
#theme-toggle,
.tag-list span {
  font-family: var(--mono);
  font-size: 0.75rem;
}

.site-header nav {
  display: flex;
  gap: 2ch;
}

/* A setting, not a destination: it sits apart from the navigation. */
#theme-toggle {
  margin-left: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

#theme-toggle:hover {
  text-decoration-thickness: 2px;
}

.site-title {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.site-footer {
  margin-top: calc(var(--line) * 4);
  padding-bottom: calc(var(--line) * 2);
  font-family: var(--mono);
  font-size: 0.75rem;
}

/* Links: the only coloured text on the page */

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Headings */

h1,
h2,
h3,
h4 {
  font-weight: 600;
  line-height: 1.25;
  text-wrap: balance;
}

h1 {
  font-size: 1.9rem;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1.1rem;
}

h4 {
  font-size: 1rem;
  font-style: italic;
}

/* Metadata: small monospace, always muted */

.meta,
.post-list time,
figcaption,
.footnotes {
  color: var(--muted);
}

.meta,
.post-list time {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5ch;
  margin-top: calc(var(--line) * 0.5);
}

.muted {
  color: var(--muted);
}

/* Home page */

.lede {
  font-size: 1.2rem;
  line-height: 1.5;
  margin-bottom: calc(var(--line) * 2);
}

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

.post-list li {
  display: grid;
  grid-template-columns: 12ch 1fr;
  align-items: baseline;
}

.post-list li + li {
  margin-top: calc(var(--line) * 0.5);
}

.tags {
  display: flex;
  gap: 1ch;
}

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

.tag-list li + li {
  margin-top: calc(var(--line) * 0.5);
}

.tag-list span {
  margin-left: 1ch;
  color: var(--muted);
}

h1 + :is(.post-list, .tag-list, .muted) {
  margin-top: var(--line);
}

.meta + .post-list {
  margin-top: calc(var(--line) * 1.5);
}

/* Article */

.post-header {
  margin-bottom: calc(var(--line) * 2);
}

.prose > * + * {
  margin-top: var(--line);
}

/* A heading belongs to what follows it: wide gap above, narrow gap below. */
.prose > * + h2 {
  margin-top: calc(var(--line) * 2.5);
}

.prose > * + h3,
.prose > * + h4 {
  margin-top: calc(var(--line) * 1.75);
}

.prose > :is(h2, h3, h4) + * {
  margin-top: calc(var(--line) * 0.5);
}

.prose p {
  text-wrap: pretty;
}

.prose ul,
.prose ol {
  padding-left: 1.5rem;
}

.prose li + li,
.prose li > :is(ul, ol) {
  margin-top: calc(var(--line) * 0.25);
}

.prose li::marker {
  color: var(--muted);
}

.prose blockquote {
  padding-left: 1.25rem;
  border-left: 2px solid var(--rule);
  font-style: italic;
}

.prose blockquote > * + * {
  margin-top: var(--line);
}

.prose hr {
  width: 4rem;
  height: 1px;
  margin: calc(var(--line) * 2) 0;
  border: 0;
  background: var(--rule);
}

.prose img,
.prose svg,
.prose video {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.prose figure img {
  width: 100%;
}

/* A figure and its caption are one object: more room around than within. */
.prose > * + figure,
.prose > figure + * {
  margin-top: calc(var(--line) * 1.5);
}

figcaption {
  margin-top: calc(var(--line) * 0.5);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* Code and other enclosed objects sit on the surface layer */

code,
kbd,
pre {
  font-family: var(--mono);
  font-variant-numeric: normal;
}

:not(pre) > code {
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background: var(--surface);
  font-size: 0.82em;
}

/* Beats the background that the highlighter's theme stylesheets set. */
.prose pre,
.prose pre.giallo {
  padding: calc(var(--line) * 0.6) 1rem;
  border-radius: 4px;
  background: var(--surface);
  font-size: 0.74rem;
  line-height: 1.6;
  overflow-x: auto;
  tab-size: 4;
}

.giallo-l {
  display: inline-block;
  min-height: 1lh;
  width: 100%;
}

.giallo-ln {
  display: inline-block;
  user-select: none;
  margin-right: 1.5ch;
  min-width: 2ch;
  text-align: right;
  color: var(--muted);
}

/* Tables */

.prose table {
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums lining-nums;
}

.prose th,
.prose td {
  padding: calc(var(--line) * 0.25) 2rem calc(var(--line) * 0.25) 0;
  text-align: left;
  vertical-align: baseline;
}

.prose th {
  border-bottom: 1px solid var(--ink);
  font-weight: 600;
}

.prose td {
  border-bottom: 1px solid var(--rule);
}

/* Math */

/* KaTeX defaults to 1.21em, sized for Times; these serifs have a larger x-height. */
.katex {
  font-size: 1em;
}

.math-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
}

.math-display > .katex-display {
  margin: 0;
}

/* Footnotes */

.footnotes {
  font-size: 0.85rem;
  line-height: 1.5;
}

.prose > .footnotes {
  margin-top: calc(var(--line) * 3);
}

.footnotes ol {
  padding-left: 1.5rem;
}

.footnote-reference,
sup {
  font-size: 0.75em;
  line-height: 0;
  font-variant-numeric: lining-nums;
}

.footnote-reference a {
  text-decoration: none;
}

@media (max-width: 30rem) {
  html {
    font-size: 106.25%;
  }

  .post-list li {
    grid-template-columns: 1fr;
  }
}
