/* Koma design tokens: the one place the palette is defined.
 *
 * Linked from every page, both the static files in public/ and the page
 * templates inside server.js. Before this existed the same :root block was
 * copy-pasted into 23 places and two of them had drifted onto different hex
 * values for the same roles, so a palette change meant 23 edits and a careful
 * reading of each.
 *
 * Deliberately not linked from: the Resend email bodies (mail clients do not
 * load external stylesheets), credential.js and auth-cert.js (canvas), and
 * pdf.js (PDF). Those three draw rather than style, so they carry their own
 * colour constants and always will.
 */

:root {
  /* Paper: the cream grounds, lightest to deepest. */
  --paper: #f4f1ea;
  --paper-deep: #ebe6db;
  --paper-sunk: #e2dcc9;

  /* Ink: text and borders, strongest to faintest. */
  --ink: #1a1815;
  --ink-soft: #4a443c;
  --ink-faint: #6B6560;

  /* The single accent, and the hairline rule. */
  --accent: #b8432a;
  --rule: #d6cfc0;

  /* Role tokens used by one surface each. */
  --seal: #1a1815;
  --ok: #3f7a4a;
}

/* The paper texture: two fixed full-viewport layers that stop the cream
 * reading as flat colour. A pair of soft radial gradients, then an SVG noise
 * field multiplied over the top.
 *
 * On by default, because most pages have it. A page that is meant to be flat
 * (the dense table and list views) opts out with class="no-paper-texture" on
 * its body rather than omitting the rules, so the decision is visible in the
 * markup instead of being an absence.
 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(0,0,0,0.02) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(0,0,0,0.025) 0%, transparent 45%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: multiply;
}

body.no-paper-texture::before,
body.no-paper-texture::after {
  content: none;
}

/* Two pages' worth of deliberate variation, kept rather than flattened.
 *
 * Before these tokens were shared, four different textures were in the tree and
 * nobody could see that from any one file: the ten static pages carried the
 * default above, the collection page and the creator profile used softer, more
 * centred gradients with the noise loaded from /noise.svg, and the record page
 * used those same softer gradients under a coarser, double-strength grain.
 * Collapsing them to one changed three pages, so they are modifiers now: the
 * variation is visible here, in one file, instead of hidden in three.
 *
 * The soft gradients sit closer to centre and about a quarter weaker than the
 * default pair.
 */
body.paper-texture--soft::before,
body.paper-texture--strong::before {
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,0.015) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(0,0,0,0.02) 0%, transparent 40%);
}

/* Same grain as the default, served from the file rather than inlined. */
body.paper-texture--soft::after {
  background-image: url("/noise.svg");
}

/* The record page's grain: coarser (lower frequency, more octaves) and twice
 * the opacity, tiled at a fixed 200px so the scale holds whatever the viewport
 * does. The most-looked-at page on the site, and the one that most wants to
 * read as paper. */
body.paper-texture--strong::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}
