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

html {
  background: var(--bg);
  color: var(--ink);
  accent-color: var(--accent);
  scrollbar-color: var(--rule-strong) var(--bg);
  text-size-adjust: 100%;
  hanging-punctuation: first allow-end last;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* No background on body: the canvas takes the html background, and the grain sits on top of it. */
body {
  position: relative;
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--step-0);
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  line-height: 1.68;
  text-rendering: optimizelegibility;
}

/* Paper grain: an SVG noise tile, tuned per theme. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: var(--grain-opacity);
  filter: var(--grain-filter);
}

::selection {
  background: var(--selection-bg);
  color: var(--ink);
}

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

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5em;
  font-family: var(--font-display);
  font-weight: 600;
  font-variant-numeric: lining-nums;
  line-height: 1.1;
  letter-spacing: -0.012em;
  color: var(--ink);
  text-wrap: balance;
}

h1 {
  font-size: var(--step-5);
  letter-spacing: -0.025em;
}

h2 {
  font-size: var(--step-3);
}

h3 {
  font-size: var(--step-1);
}

p {
  text-wrap: pretty;
}

p,
ul,
ol,
blockquote,
table,
details {
  margin: 0 0 1.1em;
}

strong {
  font-weight: 700;
  color: var(--ink);
}

a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.2em;
  transition:
    color 0.2s ease,
    text-decoration-color 0.2s ease;
}

a:hover {
  text-decoration-color: currentcolor;
  text-decoration-thickness: 0.1em;
}

mark {
  padding-inline: 0.08em;
  background: linear-gradient(transparent 58%, var(--gilt-soft) 58% 92%, transparent 92%);
  color: inherit;
}

hr {
  height: 2rem;
  margin: var(--space-6) 0;
  border: 0;
  text-align: center;
}

hr::after {
  content: "\2042";
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--accent-2);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

main:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-sans);
  font-weight: 700;
}

.skip-link:focus {
  top: var(--space-4);
}

.wrap {
  width: min(100% - 2 * var(--gutter), var(--wrap));
  margin-inline: auto;
}

/* ---------- Prose ---------- */
.prose {
  max-width: var(--measure);
}

.prose h2 {
  position: relative;
  margin-top: 2.2em;
  padding-top: 0.75em;
  border-top: 1px solid var(--rule);
  font-size: var(--step-2);
  scroll-margin-top: var(--space-6);
}

.prose h2::before {
  content: "\00a7";
  margin-right: 0.35em;
  font-weight: 400;
  color: var(--accent-2);
}

@media (width >= 70rem) {
  .prose h2::before {
    position: absolute;
    top: 0.75em;
    left: -1.15em;
    margin: 0;
  }
}

.prose h3 {
  margin-top: 1.8em;
  font-style: italic;
  scroll-margin-top: var(--space-6);
}

.prose ul {
  padding-left: 1.4em;
  list-style-type: "\2014\2002";
}

.prose ol {
  padding-left: 1.6em;
}

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

.prose ol > li::marker {
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: lining-nums;
}

.prose li + li {
  margin-top: 0.4em;
}

.prose blockquote {
  position: relative;
  margin: 1.8em 0;
  padding: 0.2em 0 0.2em 2.4em;
  font-size: var(--step-1);
  font-style: italic;
  line-height: 1.5;
  color: var(--ink-soft);
}

.prose blockquote::before {
  content: "\201C";
  position: absolute;
  top: -0.2em;
  left: 0;
  font-family: var(--font-display);
  font-size: 3.4em;
  font-style: normal;
  line-height: 1;
  color: var(--accent-2);
}

.prose code {
  padding: 0.08em 0.35em;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--bg-tint);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.prose table {
  width: 100%;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: var(--step--1);
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1.45;
}

.prose th,
.prose td {
  padding: 0.7em 0.85em;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

.prose thead th {
  border-bottom: 1px solid var(--ink);
  font-size: 1.05em;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.08em;
}

.prose tbody th {
  font-family: var(--font-display);
  font-size: 1.1em;
}

.prose tbody tr:nth-child(even) {
  background: var(--rule-faint);
}

@media (width <= 40rem) {
  .prose table {
    display: block;
    overflow-x: auto;
  }
}

/* Essay drop cap */
.article--essay .prose > p:first-of-type::first-letter {
  float: left;
  margin: 0.06em 0.1em 0 -0.02em;
  font-family: var(--font-display);
  font-size: 3.7em;
  font-weight: 600;
  line-height: 0.8;
  color: var(--accent-2);
}

/* Footnotes (markdown-it-footnote) */
.footnotes {
  font-size: var(--step--1);
  color: var(--ink-soft);
}

.footnote-ref a {
  padding-inline: 0.15em;
  font-family: var(--font-sans);
  font-weight: 700;
  text-decoration: none;
  color: var(--accent-2);
}

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

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}