/* Design tokens: the Chladni plate and its sand.
 * Every colour comes from the plate and the sand:
 * ink = deepened sand, muted = sand mixed into the plate, accent = the sand.
 * Fonts: Newsreader and Instrument Sans, SIL OFL 1.1 (licences in fonts/). */

@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(fonts/newsreader-latin-opsz-normal.woff2) format("woff2-variations");
}
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-display: swap;
  font-weight: 400 700;
  src: url(fonts/instrument-sans-latin-wght-normal.woff2) format("woff2-variations");
}

/* Light: a pale steel plate with graphite sand.
 * Contrast on the plate (WCAG): ink 13.6, muted 5.2, accent 8.9. */
:root {
  --plate: #ECEEEB;
  --sand: #39414A;
  --sand-alpha: 0.30;
  --ink: #1E2329;
  --muted: #5D646A;
  --accent: #39414A;
  --hair: rgba(57, 65, 74, 0.22);
  --select: rgba(57, 65, 74, 0.18);
  --off-plate: color-mix(in srgb, var(--plate) 90%, var(--sand));   /* beside a smaller plate */
  --plate-shade: rgba(57, 65, 74, 0.26);                            /* soft shade round a smaller plate */
  --veil: color-mix(in srgb, var(--plate) 88%, transparent);        /* behind reading text */

  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  /* type scale (rem = 16 px) */
  --t-kicker: 0.8125rem;                                            /* sans 500, muted */
  --t-lead: 0.9375rem;                                              /* serif, muted */
  --t-focal: clamp(1.1875rem, 0.95rem + 1.1vw, 1.625rem);           /* serif 360, the one line */
  --t-body: 1.0625rem;                                              /* serif reading text */
  --t-h2: 1.375rem;
  --t-small: 0.8125rem;

  /* spacing */
  --gutter: 22px;
  --s1: 0.5rem; --s2: 1rem; --s3: 1.5rem; --s4: 2.5rem; --s5: 4rem;
  --measure: 36em;                                                  /* reading column */
  --tap: 44px;                                                      /* smallest touch target */

  color-scheme: light;
}

/* Dark: a blackened plate with pale sand. ink 14.9, muted 5.4, accent 11.4. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --plate: #13161A;
    --sand: #D9CCAB;
    --sand-alpha: 0.27;
    --ink: #F0E8D4;
    --muted: #948C78;
    --accent: #D9CCAB;
    --hair: rgba(217, 204, 171, 0.22);
    --select: rgba(217, 204, 171, 0.2);
    --off-plate: color-mix(in oklab, var(--plate) 58%, #000);
    --plate-shade: rgba(217, 204, 171, 0.09);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --plate: #13161A;
  --sand: #D9CCAB;
  --sand-alpha: 0.27;
  --ink: #F0E8D4;
  --muted: #948C78;
  --accent: #D9CCAB;
  --hair: rgba(217, 204, 171, 0.22);
  --select: rgba(217, 204, 171, 0.2);
  --off-plate: color-mix(in oklab, var(--plate) 58%, #000);         /* the plate sits a shade lighter than its surroundings */
  --plate-shade: rgba(217, 204, 171, 0.09);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: var(--plate); color: var(--ink); }
::selection { background: var(--select); color: var(--ink); }

/* The plate canvas: fixed, full viewport, never takes pointer events. */
.plate-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  animation: plate-in 2.4s ease-out both;
}
@keyframes plate-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .plate-canvas { animation: none; } }

/* Sand type (CSS contract of design/sandtype.js). */
:root.sandtype .sand-text { opacity: 0; transition: opacity 900ms ease; }
:root.sandtype.sand-settled .sand-text { opacity: var(--sand-text-opacity, 1); }
:root.sandtype.sand-leaving .sand-text { transition-duration: 420ms; }

/* Light / dark switch: a half-filled circle, quiet in the top right corner. */
.theme {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  right: max(6px, env(safe-area-inset-right));
  z-index: 5;
  width: var(--tap);
  height: var(--tap);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 200ms ease;
  -webkit-tap-highlight-color: transparent;
}
.theme:hover { opacity: 1; }
.theme:focus-visible { opacity: 1; outline: 1.5px solid var(--accent); outline-offset: -6px; }
.theme-mark {
  display: block;
  width: 12px;
  height: 12px;
  margin: auto;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}
:root[data-theme="dark"] .theme-mark { transform: rotate(180deg); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-mark { transform: rotate(180deg); }
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ?stats=1 overlay (measurement only) */
.stats {
  position: fixed;
  left: 8px;
  top: 8px;
  z-index: 9;
  margin: 0;
  padding: 6px 8px;
  white-space: pre;
  font: 11px/1.35 var(--mono);
  color: var(--ink);
  background: color-mix(in srgb, var(--plate) 82%, transparent);
  border: 1px solid var(--hair);
  border-radius: 4px;
  pointer-events: none;
}
