
:root {
  --paper: #eef0ec;
  --plate: #fbfbf9;
  --ink: #15171a;
  --soft: #474c52;
  --mid: #737980;
  --hair: #cdd1cc;
  --damage: #2c57cc;
  --damage-soft: #b7c6f0;
  --broken: #df4526;
  --focus: #2c57cc;
  --display: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0f1113;
    --plate: #171a1d;
    --ink: #e6e7e2;
    --soft: #b8bdc3;
    --mid: #8e949b;
    --hair: #2b3036;
    --damage: #7497ff;
    --damage-soft: #2b3f78;
    --broken: #ff6a4a;
    --focus: #7497ff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0f1113;
  --plate: #171a1d;
  --ink: #e6e7e2;
  --soft: #b8bdc3;
  --mid: #8e949b;
  --hair: #2b3036;
  --damage: #7497ff;
  --damage-soft: #2b3f78;
  --broken: #ff6a4a;
  --focus: #7497ff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1060px; margin: 0 auto; padding-inline: 20px; padding-block: 28px 56px; display: grid; gap: 44px; }
h1, h2 { font-family: var(--display); letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
h1 { font-weight: 800; font-size: clamp(2.3rem, 6vw, 3.9rem); line-height: 0.98; }
h2 { font-weight: 800; font-size: clamp(1.35rem, 3vw, 1.75rem); line-height: 1.1; }
p { margin: 0; max-width: 64ch; }
.lede { font-size: 1.14rem; color: var(--soft); max-width: 58ch; }
.eyebrow { font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--mid); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
header { display: grid; gap: 14px; }
section { display: grid; gap: 18px; }
.prose { display: grid; gap: 12px; }

/* instrument */
.instrument { display: grid; gap: 14px; background: var(--plate); border: 1px solid var(--hair); border-radius: 6px; padding: 16px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.chip {
  font-family: var(--mono); font-size: 0.8rem; color: var(--ink); background: transparent;
  border: 1px solid var(--hair); border-radius: 999px; padding: 5px 11px; cursor: pointer; line-height: 1.2;
}
.chip small { color: var(--mid); margin-left: 5px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--plate); border-color: var(--ink); }
.chip[aria-pressed="true"] small { color: var(--plate); opacity: 0.75; }
.chip:hover { border-color: var(--mid); }
button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.field { display: flex; gap: 8px; align-items: center; font-family: var(--mono); font-size: 0.8rem; color: var(--soft); }
.field input[type="number"] { width: 4.6em; font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--hair); border-radius: 4px; padding: 4px 6px; }
.field input[type="range"] { width: 150px; accent-color: var(--damage); }
.btn { font-family: var(--mono); font-size: 0.8rem; color: var(--ink); background: var(--paper); border: 1px solid var(--hair); border-radius: 4px; padding: 5px 10px; cursor: pointer; }
.btn:hover { border-color: var(--mid); }
.rulebar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between; }
.ruleicon { display: block; height: 52px; width: auto; max-width: 100%; }
.ruleicon .on { fill: var(--ink); }
.ruleicon .off { fill: var(--plate); stroke: var(--mid); stroke-width: 0.8; }
.ruleicon text { font-family: var(--mono); font-size: 11px; fill: var(--mid); }
canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; touch-action: manipulation; }
#world { cursor: crosshair; border-radius: 3px; }
.readout { display: flex; flex-wrap: wrap; gap: 6px 22px; font-family: var(--mono); font-size: 0.8rem; color: var(--soft); font-variant-numeric: tabular-nums; }
.readout b { color: var(--ink); font-weight: 500; }
.key { display: flex; flex-wrap: wrap; gap: 6px 18px; font-family: var(--mono); font-size: 0.74rem; color: var(--mid); }
.key span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 11px; height: 11px; border-radius: 2px; display: inline-block; border: 1px solid var(--hair); }
.sw.ink { background: var(--ink); } .sw.broken { background: var(--broken); border-color: var(--broken); }
.sw.damage { background: var(--damage); border-color: var(--damage); } .sw.damage-soft { background: var(--damage-soft); border-color: var(--damage-soft); }

/* painter */
.triptych { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.panel { display: grid; gap: 6px; align-content: start; }
.panel .label { font-family: var(--mono); font-size: 0.74rem; color: var(--mid); }
.panel canvas { border: 1px solid var(--hair); border-radius: 3px; background: var(--plate); }
.row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.settle { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 520px; }
table { border-collapse: collapse; font-size: 0.92rem; width: 100%; }
th, td { text-align: left; padding: 7px 12px 7px 0; border-bottom: 1px solid var(--hair); vertical-align: top; }
th { font-family: var(--mono); font-weight: 500; font-size: 0.74rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--mid); }
td.n, th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }
#chart { width: 100%; height: auto; display: block; }
#chart text { font-family: var(--mono); font-size: 11px; fill: var(--mid); }
footer { font-family: var(--mono); font-size: 0.74rem; color: var(--mid); display: grid; gap: 6px; border-top: 1px solid var(--hair); padding-top: 16px; }
@media (max-width: 640px) {
  body { font-size: 16px; }
  .instrument { padding: 12px; }
  .triptych { gap: 8px; }
  .field input[type="range"] { width: 120px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
