/*
 * Notes: the lab's writing. Builds on styles.css (tokens, the dot-grid ground,
 * Schibsted Grotesk and Geist Mono).
 *
 * Type: titles in Schibsted Grotesk, as the homepage name. Reading text in
 * Literata, a serif drawn for long reading on screens; its sturdy serifs and
 * optical sizes hold up as light text on the dark ground, and it is set a touch
 * lighter than 400 to offset the glow of light-on-dark. Code in Geist Mono only.
 *
 * Each note owns one spark (src/lib/spark.js): a chain of dots in one of the six
 * colours of the old mark. It is the note's only colour.
 */

@font-face {
  font-family: "Literata";
  src: url("/fonts/literata-latin.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("/fonts/literata-italic-latin.woff2") format("woff2");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

:root {
  --serif: "Literata", Georgia, serif;
  --read: #D7D4CD;        /* reading text: a little softer than --ink */
  --note: #979A9F;        /* sidenotes, captions */
  --well: #15171A;        /* behind code */
  --measure: 34em;        /* about 66 characters of Literata */
  --side: 15rem;          /* the margin column for sidenotes */
}

.hue-pipestone  { --h: #973542; }
.hue-adobe      { --h: #874226; }
.hue-eucalyptus { --h: #656E2B; }
.hue-aspen      { --h: #2C6838; }
.hue-turquoise  { --h: #20757E; }
.hue-spruce     { --h: #3A4A88; }
/* The six hues are dark; for text-adjacent use, lift them toward the ink. */
[class*="hue-"] { --h-lift: color-mix(in oklab, var(--h) 62%, var(--ink)); }

.notes-body { height: auto; min-height: 100%; display: flex; flex-direction: column; }

/* ── The frame ─────────────────────────────────────────── */

.top {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 28px;
  align-items: baseline;
  padding: var(--edge) var(--edge) 0;
  font: 500 19px/1 var(--display);
  letter-spacing: -0.01em;
}
.top a { color: var(--ink); text-decoration: none; }
.top .crumb { color: var(--quiet); }
.top a:hover { color: var(--ink); text-decoration: underline; text-decoration-color: var(--quiet); }

.bottom {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  padding: 96px var(--edge) var(--edge);
  font: 13px/1.4 var(--mono);
  color: var(--quiet);
}
.bottom a { color: var(--quiet); text-decoration: none; }
.bottom a:hover { color: var(--ink); }

/* ── The mark, wherever notes draw it ──────────────────── */

.dots path { fill: var(--dot); }
.dots path.lit { fill: var(--h); }
.dots .trail line { stroke: var(--h); stroke-width: 0.6; stroke-linecap: round; opacity: 0.6; }

/* ── The index ─────────────────────────────────────────── */

.index {
  position: relative;
  padding: 0 var(--edge);
}

/* The map: the whole mark, every published note's spark drawn on it as a layer. The
   newest eight show (their sparks never share a dot, src/lib/spark.js); an older one
   appears when its entry is picked. Cut off by the right edge, as on the homepage. */
.map {
  /* The legend of the list: it stays in view while the list scrolls, so pointing at any
     entry lights its spark where you can see it (notes.js). */
  position: fixed;
  top: calc((100vh - min(82vh, 50vw)) / 2);
  right: calc(min(82vh, 50vw) * -0.14);
  width: min(82vh, 50vw);
  height: min(82vh, 50vw);
  z-index: 0;
  pointer-events: none;
}
.map .spark { transition: opacity 0.3s ease; }
.map .spark .trail-line { stroke: var(--h); stroke-width: 0.6; stroke-linecap: round; opacity: 0.6; }
.map .spark.older { opacity: 0; }                    /* beyond the newest eight: drawn when picked */
.map.picking .spark { opacity: 0.18; }
.map.picking .spark.older { opacity: 0; }
.map.picking .spark.picked { opacity: 1; }

.index-head {
  position: relative;
  z-index: 1;
  padding: clamp(96px, 22vh, 220px) 0 clamp(48px, 9vh, 96px);
  display: grid;
  gap: 14px;
}
.index-title {
  margin: 0;
  font-size: clamp(44px, 6.4vw, 96px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.035em;
}
.index-line { margin: 0; font: clamp(14px, 1.2vw, 17px)/1.4 var(--mono); color: var(--quiet); }
.index-about { max-width: 38em; margin: 0.9em 0 0; font: 15px/1.6 var(--serif); color: var(--note); }
.note-origin { margin-top: 3em; padding-top: 1em; border-top: 1px solid var(--rule, rgba(255,255,255,0.08)); font: 13px/1.5 var(--mono); color: var(--note); }
.note-origin a { color: inherit; }

.entries { position: relative; z-index: 1; list-style: none; margin: 0; padding: 0; max-width: 46rem; }
.entry + .entry { margin-top: 18px; }
.entry a {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 26px;
  align-items: start;
  padding: 22px 0;
  color: inherit;
  text-decoration: none;
}
.glyph { width: 64px; height: 64px; margin-top: 4px; }
.entry-text { display: grid; gap: 8px; }
.entry-title {
  font: 500 clamp(24px, 2.4vw, 32px)/1.12 var(--display);
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 5px;
  transition: text-decoration-color 0.2s;
}
.entry a:hover .entry-title, .entry a:focus-visible .entry-title { text-decoration-color: var(--h-lift); }
.entry-desc { font: 380 18px/1.5 var(--serif); color: var(--read); max-width: 34em; }
.entry time, .note-head time { font: 500 14px/1.4 var(--display); color: var(--quiet); }

/* Pointing at a note replays its spark on its glyph, one dot after another. */
@keyframes relight { from { fill: var(--dot); } to { fill: var(--h); } }
.entry a:hover .glyph path.lit { animation: relight 0.35s ease-out both; }
.entry a:hover .glyph path.step-1 { animation-delay: 0.12s; }
.entry a:hover .glyph path.step-2 { animation-delay: 0.24s; }
.entry a:hover .glyph path.step-3 { animation-delay: 0.36s; }

.empty { position: relative; z-index: 1; font: 380 19px/1.5 var(--serif); color: var(--read); }

/* ── A note ────────────────────────────────────────────── */

.note { position: relative; padding: 0 var(--edge); }

.note-head {
  position: relative;
  padding: clamp(80px, 18vh, 180px) 0 clamp(40px, 7vh, 72px);
  display: grid;
  gap: 18px;
}
/* The note's own spark, large and cut off at the right, like the homepage. */
.note-mark {
  position: absolute;
  top: calc(-1 * var(--edge) - 19px);
  right: calc(-1 * var(--edge) - min(64vh, 44vw) * 0.22);
  width: min(64vh, 44vw);
  height: min(64vh, 44vw);
  z-index: 0;
}
.note-title {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 15ch;
  font-size: clamp(40px, 5.4vw, 80px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.032em;
  text-wrap: balance;
}
.note-desc {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 30em;
  font: 380 clamp(19px, 1.6vw, 22px)/1.45 var(--serif);
  color: var(--read);
}
.note-head time { position: relative; z-index: 1; }

/* The note's spark lights once, dot by dot, when the page opens. */
@keyframes spark-in { from { fill: var(--dot); } 40% { fill: color-mix(in oklab, var(--h) 70%, white); } to { fill: var(--h); } }
@keyframes trail-in { from { opacity: 0; } to { opacity: 0.6; } }
.note-mark path.lit { animation: spark-in 0.9s ease-out 0.25s both; }
.note-mark path.step-1 { animation-delay: 0.51s; }
.note-mark path.step-2 { animation-delay: 0.77s; }
.note-mark path.step-3 { animation-delay: 1.03s; }
.note-mark .trail line { animation: trail-in 0.5s ease-out 0.4s both; }
.note-mark .trail line.step-2 { animation-delay: 0.66s; }
.note-mark .trail line.step-3 { animation-delay: 0.92s; }

/* ── Reading ───────────────────────────────────────────── */

.prose {
  position: relative;
  z-index: 1;
  max-width: var(--measure);
  font: 380 clamp(18px, 1.25vw, 20px)/1.65 var(--serif);
  font-optical-sizing: auto;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  hanging-punctuation: first;
  color: var(--read);
}
.prose > * { margin: 0; }
.prose > * + * { margin-top: 1.1em; }
.prose p { text-wrap: pretty; }
.prose strong { font-weight: 600; color: var(--ink); }
.prose em { font-style: italic; }

.prose h2, .prose h3 {
  font-family: var(--display);
  font-weight: 500;
  color: var(--ink);
  text-wrap: balance;
}
.prose h2 { margin-top: 2.2em; font-size: 1.45em; line-height: 1.2; letter-spacing: -0.02em; }
.prose h3 { margin-top: 1.8em; font-size: 1.12em; line-height: 1.3; letter-spacing: -0.01em; }
.prose h2 + *, .prose h3 + * { margin-top: 0.6em; }

.prose a { color: var(--ink); text-decoration-color: var(--h-lift); text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
.prose a:hover { text-decoration-thickness: 2px; }

.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 0.35em; }
.prose li::marker { color: var(--quiet); }

.prose blockquote { margin-left: 0; padding-left: 1.2em; border-left: 2px solid var(--h); color: var(--read); font-style: italic; }

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

/* Tables: plain, aligned, figures in lining tabular numerals. */
.prose table { border-collapse: collapse; width: 100%; font-size: 0.86em; font-variant-numeric: lining-nums tabular-nums; }
.prose th { font: 500 0.95em/1.3 var(--display); color: var(--ink); text-align: left; }
.prose th, .prose td { padding: 0.5em 1em 0.5em 0; border-bottom: 1px solid #26292E; vertical-align: top; }
.prose td:not(:first-child), .prose th:not(:first-child) { text-align: right; }

/* Code */
.prose code { font: 0.84em/1 var(--mono); color: var(--ink); }
.prose :not(pre) > code { padding: 0.1em 0.3em; border-radius: 3px; background: var(--well); }
.prose pre {
  margin-top: 1.4em;
  margin-bottom: 0.3em;
  padding: 1.1em 1.3em;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--well);
  font: 14.5px/1.65 var(--mono);
  tab-size: 2;
}
.prose pre code { font: inherit; }
.token.comment, .token.prolog { color: #6E7177; font-style: normal; }
.token.keyword, .token.builtin, .token.important { color: #B48AA0; }
.token.string, .token.char, .token.attr-value { color: #9DAA78; }
.token.number, .token.boolean, .token.constant { color: #D09A7B; }
.token.function, .token.class-name { color: #8DB6BA; }
.token.operator, .token.punctuation { color: #8E9197; }
.token.property, .token.tag { color: #93A1CF; }

/* Maths: MathML, drawn by the browser in its math font. */
.prose math { font-family: "STIX Two Math", "Cambria Math", math; font-size: 1.08em; }
.prose math[display="block"] { margin: 1.4em 0; overflow-x: auto; }

/* Figures may run wider than the text, into the margin. */
.prose figure { margin: 2em 0; }
.prose figcaption { margin-top: 0.8em; font: 380 0.82em/1.45 var(--serif); color: var(--note); max-width: var(--measure); }
.prose figure svg { display: block; width: 100%; height: auto; }

/* ── Sidenotes (src/lib/sidenotes.js) ──────────────────── */

.prose sup a { text-decoration: none; color: var(--h-lift); font: 500 0.7em/1 var(--display); padding: 0 0.1em; }
.sidenote { display: none; }
.sidenote-n { font: 500 0.85em/1 var(--display); color: var(--h-lift); }

.footnotes { margin-top: 3em; padding-top: 1.4em; border-top: 1px solid var(--dot); font-size: 0.85em; color: var(--note); }
.footnotes ol { padding-left: 1.2em; }
.footnotes a[data-footnote-backref] { text-decoration: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Wide enough for a margin column: notes move beside the line they belong to. */
@media (min-width: 1180px) {
  .note .prose { margin-right: calc(var(--side) + 3rem); }
  .sidenote {
    display: block;
    float: right;
    clear: right;
    width: var(--side);
    margin: 0.3em calc(-1 * (var(--side) + 3rem)) 0.9em 0;
    font: 380 14.5px/1.5 var(--serif);
    color: var(--note);
    text-indent: 0;
  }
  .footnotes { display: none; }
  .prose figure.wide { margin-right: calc(-1 * (var(--side) + 3rem)); }
}

/* ── Phones ────────────────────────────────────────────── */

@media (max-width: 640px) {
  .top { font-size: 17px; }
  .map { position: absolute; top: 40px; right: -30vw; width: 92vw; height: 92vw; }
  .index-head { padding-top: 62vw; }
  .entry a { grid-template-columns: 44px 1fr; gap: 16px; }
  .glyph { width: 44px; height: 44px; }
  .note-mark { top: 30px; right: -34vw; width: 88vw; height: 88vw; }
  .note-head { padding-top: 56vw; }
  .prose pre { margin-left: calc(-1 * var(--edge)); margin-right: calc(-1 * var(--edge)); border-radius: 0; padding-left: var(--edge); }
}

@media (prefers-reduced-motion: reduce) {
  .note-mark path.lit, .note-mark .trail line, .entry a:hover .glyph path.lit { animation: none; }
  .map path, .map line { transition: none; }
}

:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 2px; }

/* Diagrams drawn in a note: the mark's vocabulary of dots and links. */
.fig circle { fill: var(--dot); }
.fig .lit circle { fill: var(--h); }
.fig text { font: 500 15px/1 var(--display); fill: var(--read); text-anchor: middle; }
.fig text.left { text-anchor: start; }
.fig .fig-link { fill: none; stroke: var(--dot); stroke-width: 1.5; stroke-linecap: round; }
.fig .fig-link.lit { stroke: var(--h); }
.fig .fig-link.back { stroke-dasharray: 2 6; }
