/* gnostinomicon styling.
 *
 * wirrel copies this directory into the site and links /assets/style.css from
 * every page, after its own /assets/wirrel.css. That base sheet carries the
 * rules the generated HTML depends on — the `.diff` colours on commit pages and
 * the copy button's placement on code blocks — so nothing here is mandatory.
 * The `.diff`, `.copyable` and `.ts-` rules at the bottom only retheme those in
 * this palette, which is what makes them follow dark mode.
 *
 * The generated HTML carries almost no classes, so nearly everything here hangs
 * off element selectors.
 */

:root {
  --ink: #1b1b1f;
  --ink-soft: #5c5c66;
  --paper: #fbfbf9;
  --rule: #e2e1dc;
  --link: #3a5a8c;
  --accent: #8c5a3a;
  --code-bg: #f1f0ec;
  --mark: #f3ecd9;
  --measure: 34rem;

  --add: #2c7a4b;
  --del: #b4453c;
  --hunk: #7a6bb0;

  --syn-comment: #6b6b63;
  --syn-keyword: #8c3a62;
  --syn-string: #2c6a45;
  --syn-constant: #8c5a3a;
  --syn-function: #3a5a8c;
  --syn-type: #6a4f9c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e4e3de;
    --ink-soft: #9a998f;
    --paper: #16161a;
    --rule: #2e2e34;
    --link: #93b3dd;
    --accent: #d0a082;
    --code-bg: #212127;
    --mark: #2b2720;

    --add: #7bc496;
    --del: #e0847c;
    --hunk: #b0a2e0;

    --syn-comment: #8f8e85;
    --syn-keyword: #e09bbd;
    --syn-string: #8fc9a2;
    --syn-constant: #d0a082;
    --syn-function: #93b3dd;
    --syn-type: #bba8e6;
  }
}

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

body {
  margin: 0 auto;
  padding: 3rem 1.25rem 6rem;
  max-width: var(--measure);
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.65 ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  text-wrap: pretty;
}

/* article header: the ways out — the index and the article's own changes —
 * plus its dates */

body > header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--rule);
}

body > header a {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.06em;
  text-decoration: none;
}

body > header a:hover {
  text-decoration: underline;
}

small {
  color: var(--ink-soft);
  font-size: 0.8rem;
}

/* headings */

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

h1 {
  margin: 0 0 1.5rem;
  font-size: 1.9rem;
  letter-spacing: -0.015em;
}

h2 {
  margin: 2.75rem 0 0.9rem;
  font-size: 1.25rem;
}

h3 {
  margin: 2rem 0 0.6rem;
  font-size: 1.05rem;
}

/* body copy */

p {
  margin: 0 0 1.15rem;
}

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

a:hover {
  color: var(--accent);
}

ul, ol {
  margin: 0 0 1.15rem;
  padding-left: 1.35rem;
}

li {
  margin-bottom: 0.4rem;
}

li::marker {
  color: var(--ink-soft);
}

blockquote {
  margin: 1.5rem 0;
  padding-left: 1.1rem;
  border-left: 2px solid var(--rule);
  color: var(--ink-soft);
  font-style: italic;
}

hr {
  margin: 2.5rem 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

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

table {
  width: 100%;
  margin-bottom: 1.15rem;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}

th {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.05em;
}

/* code */

code, pre, kbd {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.85em;
}

code {
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: var(--code-bg);
}

pre {
  margin: 0 0 1.5rem;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border-radius: 4px;
  background: var(--code-bg);
  line-height: 1.5;
}

pre code {
  padding: 0;
  background: none;
}

/* copy button on `copy`-flagged fences — wirrel.css lays the button out in a
 * flex row beside the code. This makes the row the code tray in our palette
 * and swaps in our own clipboard icon (assets/copy.svg; the colour comes from
 * the mask, so it follows dark mode). */

.copyable {
  margin: 0 0 1.5rem;
  padding-right: 0.4rem;
  border-radius: 4px;
  background: var(--code-bg);
}

.copyable pre {
  background: none;
}

.copyable button {
  margin-top: 0.4rem;
  color: var(--ink-soft);
}

.copyable button:hover,
.copyable button:focus-visible {
  color: var(--ink);
}

.copyable button::before {
  mask-image: url(/assets/copy.svg);
}

/* footnotes — wirrel gathers them under a rule at the end of the article,
 * numbered in order of mention, each linking back to where it was mentioned.
 * The rule is short, as on a printed page, and the note or reference just
 * jumped to is tinted so the eye lands on it. */

sup {
  position: relative;
  top: -0.5em;
  vertical-align: baseline;
  font-size: 0.72em;
  line-height: 0;
}

.footnote-reference a {
  padding: 0 0.1em;
  text-decoration: none;
}

.footnotes {
  margin-top: 3.5rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.55;
}

.footnotes hr {
  width: 5rem;
  margin: 0 0 1.25rem;
}

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

.footnotes li {
  margin-bottom: 0.7rem;
  padding-left: 0.2rem;
}

.footnotes li::marker {
  font-variant-numeric: tabular-nums;
}

.footnotes p {
  margin-bottom: 0.5rem;
}

.footnotes li > :last-child {
  margin-bottom: 0;
}

.footnote-backref {
  margin-left: 0.15em;
  color: var(--ink-soft);
  text-decoration: none;
}

.footnote-backref:hover {
  color: var(--accent);
}

.footnotes li,
.footnote-reference {
  scroll-margin-top: 2rem;
}

.footnotes li:target,
.footnote-reference:target {
  border-radius: 2px;
  background: var(--mark);
  box-shadow: 0 0 0 0.3rem var(--mark);
}

/* generated listings: the index, both article listings, the changelog, and one
 * article's changes. Dates, change types and ids annotate the entry — they
 * shouldn't compete with the title for attention. */

h1 + ul li,
h2 + ul li {
  margin-bottom: 0.55rem;
}

li b {
  font-weight: 400;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

/* the id column of /articles/by-id/ */
li > code:first-child {
  padding: 0;
  background: none;
  color: var(--ink-soft);
}

/* commit diffs — wirrel.css already colours them; this puts them in the palette */

.diff {
  padding: 0.9rem 1rem;
  overflow: auto;
  border-radius: 4px;
  background: var(--code-bg);
}

.diff .add { color: var(--add); }
.diff .del { color: var(--del); }
.diff .hunk { color: var(--hunk); }
.diff .file { color: var(--ink-soft); font-weight: 600; }

/* highlighted code — wirrel.css colours the tree-sitter `.ts-` classes for a
 * light background only; this restates every one of them in the palette so
 * none is left light-only in dark mode. */

.ts-comment { color: var(--syn-comment); font-style: italic; }
.ts-keyword,
.ts-punctuation-special,
.ts-tag { color: var(--syn-keyword); }
.ts-string,
.ts-string-special,
.ts-character { color: var(--syn-string); }
.ts-escape { color: var(--syn-string); font-weight: 600; }
.ts-number,
.ts-boolean,
.ts-constant,
.ts-constant-builtin,
.ts-attribute,
.ts-property { color: var(--syn-constant); }
.ts-function,
.ts-function-builtin,
.ts-function-macro,
.ts-function-method,
.ts-constructor { color: var(--syn-function); }
.ts-type,
.ts-type-builtin,
.ts-module,
.ts-label,
.ts-variable-builtin,
.ts-variable-parameter { color: var(--syn-type); }
