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

:root {
  color-scheme: dark light;
  --bg: #111;
  --fg: #d7d7d7;
  --ink: #f5f5f5;
  --muted: #a8a8a8;
  --accent: #b5cfbd;
  --rule: #333;
  --dot: #2e2e2e;
  --dot-strong: #4a4a4a;
  /* Light text on a dark surface reads thinner than it is: it is set in medium where the font has it */
  --weight: 500;
  --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;
}

/* The same page on paper, warm rather than white to rest the eyes: when the system asks for
   light, unless the reader picked dark with the button of the header, and when the reader picked
   light. The two blocks hold the same colours. */

@media (prefers-color-scheme: light) {
  :root:not([data-scheme="dark"]) {
    color-scheme: light;
    --bg: #f3f1ea;
    --fg: #34332e;
    --ink: #161613;
    --muted: #6a6860;
    --accent: #3d6650;
    --rule: #d5d2c7;
    --dot: #dad7cc;
    --dot-strong: #b4b0a3;
    --weight: 400;
  }
}

:root[data-scheme="light"] {
  color-scheme: light;
  --bg: #f3f1ea;
  --fg: #34332e;
  --ink: #161613;
  --muted: #6a6860;
  --accent: #3d6650;
  --rule: #d5d2c7;
  --dot: #dad7cc;
  --dot-strong: #b4b0a3;
  --weight: 400;
}

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

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--weight) 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);
}

/* The switch between dark and light: a disc, half of it filled */

.scheme {
  align-self: center;
  width: 11px;
  height: 11px;
  padding: 0;
  border: 1px solid var(--muted);
  border-radius: 50%;
  background: linear-gradient(90deg, var(--muted) 50%, transparent 50%);
  cursor: pointer;
}

.scheme:hover,
.scheme:focus-visible {
  border-color: var(--accent);
  background: linear-gradient(90deg, var(--accent) 50%, transparent 50%);
}

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

/* 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: 600;
  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: 12px;
  font-weight: var(--weight);
  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: 12px;
}

.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;
}

/* On a page of the series, its own entry is lit and the others step back */

.sequence:has([aria-current]) li::before {
  background: var(--dot-strong);
}

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

.sequence:has([aria-current]) a:hover,
.sequence:has([aria-current]) a:focus-visible {
  color: var(--accent);
}

.sequence li:has([aria-current])::before {
  background: var(--accent);
}

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

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

/* What surrounds an article: references, the notes to see also, the series */

.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: var(--weight) 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;
}

/* The number after a link that leaves the site: its place in the references under the note */

.prose .cite {
  margin-left: 3px;
  font: 0.75em var(--mono);
  text-decoration: none;
}

.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: 600;
  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: var(--weight) 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: 600 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;
  }
}

/* The line under a title that says what the note is about */

article > .lede {
  margin: 0 0 14px;
  max-width: 52ch;
  font: var(--weight) 16px/1.6 var(--sans);
}

/* See also: a short list, each note behind a line of dots that grows with its distance */

.meta-block .nearby {
  margin: 12px 0 0;
}

.nearby li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  line-height: 1.6;
}

.nearby li::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  background: var(--line);
}

.nearby li:nth-child(2)::before {
  width: 12px;
}

.nearby li:nth-child(3)::before {
  width: 18px;
}

.nearby li:nth-child(4)::before {
  width: 24px;
}

.nearby li:nth-child(n + 5)::before {
  width: 30px;
}

.nearby a {
  min-width: 0;
}

/* The headings of a note, folded under one word */

.toc {
  margin: 28px 0 0;
  font-size: 13px;
}

.toc summary {
  cursor: pointer;
}

.toc ol {
  margin: 10px 0 0;
  padding-left: 1.6em;
}

.toc ol ol {
  margin-top: 2px;
}

.toc li {
  margin: 2px 0;
}

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

/* The link of a heading to itself, when the site asks Zola for one: a mark that shows with the
   heading under the pointer, and always where there is no pointer */

.zola-anchor {
  margin-inline: 8px;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
}

.zola-anchor::before {
  content: "#";
}

:is(h1, h2, h3, h4, h5, h6):hover > .zola-anchor,
.zola-anchor:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .zola-anchor {
    opacity: 1;
  }
}

/* An alert, written `> [!NOTE]`: a block marked by a square and the name of its kind */

.prose blockquote[class^="markdown-alert"] {
  padding: 2px 0 2px 16px;
  border-left: 1px solid var(--muted);
  color: var(--fg);
}

.prose blockquote[class^="markdown-alert"]::before {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font: var(--weight) 11px var(--mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.prose blockquote[class^="markdown-alert"] > :last-child {
  margin-bottom: 0;
}

.prose .markdown-alert-note::before {
  content: "■ note";
}

.prose .markdown-alert-tip::before {
  content: "■ tip";
}

.prose .markdown-alert-important::before {
  content: "■ important";
}

.prose .markdown-alert-warning::before {
  content: "■ warning";
}

.prose .markdown-alert-caution::before {
  content: "■ caution";
}

:lang(ko) .prose .markdown-alert-note::before {
  content: "■ 참고";
}

:lang(ko) .prose .markdown-alert-tip::before {
  content: "■ 도움말";
}

:lang(ko) .prose .markdown-alert-important::before {
  content: "■ 중요";
}

:lang(ko) .prose .markdown-alert-warning::before {
  content: "■ 주의";
}

:lang(ko) .prose .markdown-alert-caution::before {
  content: "■ 경고";
}

.prose .markdown-alert-tip,
.prose .markdown-alert-important {
  border-left-color: var(--accent);
}

.prose .markdown-alert-tip::before,
.prose .markdown-alert-important::before {
  color: var(--accent);
}

.prose .markdown-alert-warning,
.prose .markdown-alert-caution {
  border-left-style: dotted;
  border-left-width: 2px;
}

/* Code coloured by Zola. It writes both colours of a token and lets the scheme of the block
   choose: the scheme the reader picked with the switch has to reach the block. */

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

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

:root[data-scheme="light"] pre.giallo {
  color-scheme: light !important;
}

:root[data-scheme="dark"] pre.giallo {
  color-scheme: dark !important;
}

/* A list of terms and what they mean */

.prose dl {
  margin: 0 0 1.4em;
}

.prose dt {
  color: var(--ink);
  font: var(--weight) 14px var(--mono);
}

.prose dd {
  margin: 2px 0 12px 16px;
}

/* The pages of a list cut in pages, and the page that searches */

nav.pager {
  align-items: baseline;
  margin: -18px 0 48px;
  font-size: 13px;
}

.search input {
  width: 100%;
  margin: 8px 0 20px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px dotted var(--muted);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: var(--weight) 16px var(--mono);
}

.search input:focus {
  outline: 0;
  border-bottom-color: var(--accent);
}

.search-results small {
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* On the homepage, the words to look for are asked between the title and the list */

.hero + .search input {
  margin: -28px 0 40px;
  font-size: 14px;
}

/* What a code block can carry besides its language: marked lines, and a name printed above */

.giallo-l[style*="background-color"] {
  background-color: var(--dot) !important;
}

.prose pre code[data-name]::before {
  content: attr(data-name);
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.09em;
}

/* A search form: the field, and a magnifying glass at its right end that sends the words */

form.search {
  position: relative;
}

form.search input {
  padding-right: 28px;
}

form.search input::-webkit-search-cancel-button {
  display: none;
}

form.search button {
  position: absolute;
  right: 0;
  bottom: 20px;
  height: 36px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.hero + form.search button {
  bottom: 40px;
  height: 34px;
}

form.search button:hover,
form.search button:focus-visible {
  color: var(--accent);
}

form.search svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: square;
}

.listing[hidden],
.index li[hidden] {
  display: none;
}
