/* void: an empty surface drawn with dots. No script, no web font, no motion. */

:root {
  color-scheme: dark;
  --bg: #111;
  --fg: #bcbcbc;
  --ink: #e6e6e6;
  --muted: #858585;
  --accent: #a4b5a9;
  --rule: #333;
  --dot: #2e2e2e;
  --dot-strong: #4a4a4a;
  --width: 640px;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: system-ui, sans-serif;

  /* The two patterns everything is drawn with: a grid of dots and a line of dots */
  --grid: radial-gradient(var(--dot) 0.8px, transparent 1.2px) 0 0 / 12px 12px;
  --line: radial-gradient(var(--dot-strong) 0.8px, transparent 1.2px) 0 50% / 6px 6px repeat-x;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.75 var(--mono);
}

main,
header,
footer {
  max-width: var(--width);
  margin-inline: auto;
  padding-inline: 24px;
}

/* Header: a five pixel square leads home, a line of dots closes it */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 56px;
  padding-bottom: 14px;
  margin-bottom: 56px;
  background: var(--line);
  background-position: 0 100%;
  background-origin: content-box;
  background-clip: content-box;
}

header > * {
  /* Lifts the content off the line of dots drawn at the bottom of the content box */
  margin-bottom: 14px;
}

nav {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.home {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
}

.home::before {
  content: "";
  width: 5px;
  height: 5px;
  background: var(--accent);
}

/* Footer: the grid of dots fades into the page */

footer {
  margin-top: 72px;
  padding-bottom: 60px;
  color: var(--muted);
  font-size: 12px;
}

footer::before {
  content: "";
  display: block;
  height: 60px;
  margin-bottom: 18px;
  background: var(--grid);
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent);
  mask-image: linear-gradient(to bottom, #000, transparent);
}

/* Links */

a {
  color: inherit;
  text-decoration: none;
}

a:hover,
a:focus-visible {
  color: var(--accent);
  text-decoration: underline dotted;
  text-underline-offset: 4px;
}

a:focus-visible {
  outline: 1px dotted var(--accent);
  outline-offset: 5px;
}

/* Text */

.muted,
time,
small,
.label {
  color: var(--muted);
}

.label {
  font-size: 12px;
  font-weight: 400;
}

h1 {
  color: var(--ink);
  font-size: 25px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.04em;
  margin: 12px 0 16px;
}

h2 {
  font-size: 16px;
  font-weight: 500;
  margin-top: 40px;
}

p {
  margin: 0 0 1.4em;
}

/* A label above a title: a cursor, then small capitals */

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  flex: none;
  width: 5px;
  height: 9px;
  background: var(--muted);
}

/* The place in a series: one square per note, the current one lit */

.steps {
  display: inline-flex;
  gap: 4px;
}

.steps i {
  width: 5px;
  height: 5px;
  background: var(--dot-strong);
}

.steps .on {
  background: var(--accent);
}

/* A field: a grid of dots with two corner marks */

.field {
  position: relative;
  padding: 26px 22px;
  background: var(--grid);
}

.field::before,
.field::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border: 0 solid var(--muted);
}

.field::before {
  top: 0;
  left: 0;
  border-width: 1px 0 0 1px;
}

.field::after {
  right: 0;
  bottom: 0;
  border-width: 0 1px 1px 0;
}

/* Homepage */

.hero {
  margin-bottom: 56px;
}

.hero h1 {
  margin: 14px 0 10px;
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: -0.06em;
}

.hero h1 span {
  color: var(--muted);
}

.hero .lede {
  margin: 0;
  max-width: 44ch;
  color: var(--muted);
}

/* Lists: a name, a line of dots, a number */

.entries,
.index {
  list-style: none;
  padding: 0;
  margin: 18px 0 48px;
}

.entries li,
.index li {
  margin: 0 0 18px;
}

.row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.row > a {
  color: var(--ink);
}

.row > a:hover,
.row > a:focus-visible {
  color: var(--accent);
}

.row::after {
  content: "";
  order: 1;
  flex: 1;
  min-width: 24px;
  height: 6px;
  background: var(--line);
}

.row > time,
.row > small {
  order: 2;
  flex: none;
  font-size: 12px;
}

.entries small {
  display: block;
  font-size: 11px;
}

.index a {
  color: var(--accent);
}

.tags {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  color: var(--accent);
  font-size: 12px;
}

/* A series: squares on a dotted line */

.sequence {
  list-style: none;
  padding: 0;
  margin: 30px 0;
}

.sequence li {
  position: relative;
  padding: 0 0 22px 24px;
  border-left: 1px dotted var(--dot-strong);
  margin-left: 4px;
}

.sequence li:last-child {
  border-color: transparent;
}

.sequence li::before {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  background: var(--accent);
  left: -3px;
  top: 10px;
}

.sequence [aria-current] {
  color: var(--muted);
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
}

/* What surrounds an article: references, related notes, backlinks */

.meta-block {
  margin-top: 44px;
  padding-top: 20px;
  font-size: 13px;
  background: var(--line);
  background-position: 0 0;
}

.meta-block h2 {
  margin-top: 0;
}

.meta-block ul,
.meta-block ol:not(.sequence) {
  padding-left: 0;
  list-style: none;
}

.meta-block li {
  margin: 8px 0;
}

.meta-block .sequence li {
  margin: 0 0 0 4px;
}

/* The article itself */

article > time,
article > time + small {
  font-size: 12px;
}

.prose {
  font: 16px/1.85 var(--sans);
  margin-top: 44px;
  overflow-wrap: anywhere;
}

.prose a,
.references a {
  color: var(--accent);
  text-decoration: underline dotted;
  text-underline-offset: 4px;
}

.prose a:hover,
.references a:hover {
  text-decoration-style: solid;
}

.prose h2,
.prose h3,
.prose h4 {
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 500;
  line-height: 1.4;
  margin: 2.4em 0 0.8em;
}

.prose h2 {
  font-size: 18px;
}

.prose h3,
.prose h4 {
  font-size: 15px;
}

.prose ul,
.prose ol {
  padding-left: 1.4em;
  margin: 0 0 1.4em;
}

.prose ul {
  list-style: square;
}

.prose li {
  margin: 0.3em 0;
}

.prose li::marker {
  color: var(--muted);
  font-size: 0.7em;
}

.prose blockquote {
  margin: 0 0 1.4em;
  padding-left: 16px;
  border-left: 1px dotted var(--muted);
  color: var(--muted);
}

.prose hr {
  border: 0;
  height: 6px;
  margin: 2.4em 0;
  background: var(--line);
}

.prose img {
  max-width: 100%;
}

.prose code {
  font: 0.85em var(--mono);
  color: var(--ink);
}

.prose pre {
  overflow: auto;
  font: 13px/1.7 var(--mono);
  padding: 14px 0;
  margin: 0 0 1.4em;
  border-block: 1px dotted var(--dot-strong);
  background: transparent !important;
}

.prose pre code {
  font: inherit;
  color: inherit;
}

.prose table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.4em;
}

.prose td,
.prose th {
  padding: 8px;
  text-align: left;
  border-bottom: 1px dotted var(--dot-strong);
}

.prose th {
  font: 500 12px var(--mono);
  color: var(--muted);
}

.prose .footnotes,
.prose .footnote-definition {
  font-size: 13px;
  color: var(--muted);
}

.prose .footnote-definition p {
  display: inline;
}

/* A figure or an equation on its own is laid on a field */

.prose p:has(> math[display="block"]:only-child),
.prose p:has(> img:only-child) {
  position: relative;
  margin: 2em 0;
  padding: 22px;
  background: var(--grid);
  text-align: center;
}

.prose p:has(> math[display="block"]:only-child)::before,
.prose p:has(> math[display="block"]:only-child)::after,
.prose p:has(> img:only-child)::before,
.prose p:has(> img:only-child)::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border: 0 solid var(--muted);
}

.prose p:has(> math[display="block"]:only-child)::before,
.prose p:has(> img:only-child)::before {
  top: 0;
  left: 0;
  border-width: 1px 0 0 1px;
}

.prose p:has(> math[display="block"]:only-child)::after,
.prose p:has(> img:only-child)::after {
  right: 0;
  bottom: 0;
  border-width: 0 1px 1px 0;
}

/* Math is MathML, drawn by the browser with the math font of the system */

math {
  color: var(--ink);
  font-size: 1.06em;
}

math[display="block"] {
  margin: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-block: 2px;
}

/* What follows is adapted from the stylesheet of Typst's HTML export (Apache-2.0), keeping the
   rules that are scoped by a class: they lay out the aligned and multi-line equations written
   by Typst, and leave the MathML of other sources alone. */

mtable.right-align mtd,
mtable mtd.right-align,
mtable.left-align mtd.right-align,
mtable.aligned mtd:nth-child(odd) {
  justify-items: end;
  text-align: right;
}

mtable.cases mtd,
mtable.left-align mtd,
mtable mtd.left-align,
mtable.aligned mtd:nth-child(even),
math:is(:not([display])) > mtable.multiline-equation mtd {
  justify-items: start;
  text-align: left;
}

mtable.cases mtd,
mtable.aligned mtd,
mtable mtd.flushed,
mtable mtd.left-flush {
  padding-left: 0;
}

mtable.cases mtd,
mtable.aligned mtd,
mtable mtd.flushed,
mtable mtd.right-flush {
  padding-right: 0;
}

mtable.multiline-equation {
  math-style: inherit;
}

mtable.multiline-equation mtd {
  math-depth: inherit;
  math-style: inherit;
  math-shift: inherit;
  padding: 0;
}

math > mtable.multiline-equation mtr:not(:last-child) mtd {
  padding-bottom: 0.5em;
}

/* Small screens */

@media (max-width: 480px) {
  header {
    padding-top: 28px;
    margin-bottom: 40px;
  }

  main,
  header,
  footer {
    padding-inline: 20px;
  }

  .hero h1 {
    font-size: 34px;
  }

  h1 {
    font-size: 23px;
  }

  .field,
  .prose p:has(> math[display="block"]:only-child),
  .prose p:has(> img:only-child) {
    padding: 18px 12px;
  }
}
