/* Shared design tokens. Every stylesheet on the site uses these and defines no colors of its own. */
:root {
  color-scheme: light dark;

  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --ink: #1b1c1e;
  --ink-2: #4a4d52;
  --ink-3: #777b82;
  --line: #dedbd3;
  --line-strong: #bdb9ae;
  --accent: #b4441a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4da;
  --focus: #1f6fd1;

  /* Methods: the paper's figure colors. One method, one color, everywhere. */
  --m-ancestral: #1f77b4;
  --m-kmeans: #9467bd;
  --m-naive: #2ca02c;
  --m-samp: #ff7f0e;
  --m-map: #d62728;

  /* Sequential ramp for similarity cells and probabilities, low to high. */
  --seq-0: #f3f1ec;
  --seq-1: #f3d9c4;
  --seq-2: #eda977;
  --seq-3: #dc6e33;
  --seq-4: #a83a12;

  /* Word highlights in the samples figure, one per repeated word. */
  --hl-1: #fee79d;
  --hl-2: #c4ecc9;
  --hl-3: #e0d6f6;
  --hl-4: #c8ece6;
  --hl-5: #f8d3e3;
  --hl-6: #cfe2f7;
  --hl-7: #fbd9bc;
  --hl-8: #e3ecb5;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text: 1.0625rem;
  --text-s: 0.9375rem;
  --text-xs: 0.8125rem;
  --lh: 1.6;

  --w-prose: 44rem;
  --w-wide: 66rem;
  --gutter: 1rem;
  --radius: 10px;
  --radius-s: 6px;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.06), 0 6px 24px rgba(20, 20, 20, 0.06);
  --backdrop: rgba(20, 20, 20, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131415;
    --surface: #1b1c1e;
    --surface-2: #242628;
    --ink: #ecebe7;
    --ink-2: #b9b8b2;
    --ink-3: #8b8a85;
    --line: #33353a;
    --line-strong: #4b4e55;
    --accent: #f08a56;
    --accent-ink: #1b1c1e;
    --accent-soft: #3a261b;
    --focus: #6aa9ff;
    --m-ancestral: #5aa7de;
    --m-kmeans: #b595dc;
    --m-naive: #5fc45f;
    --m-samp: #ff9a3d;
    --m-map: #f0605f;
    --seq-0: #242628;
    --seq-1: #4a3022;
    --seq-2: #8a4a23;
    --seq-3: #d2702f;
    --seq-4: #ffb27a;
    --hl-1: #5a4a14;
    --hl-2: #244729;
    --hl-3: #3d2f5c;
    --hl-4: #17453f;
    --hl-5: #55263c;
    --hl-6: #1f3a5a;
    --hl-7: #5a3418;
    --hl-8: #3e4716;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
    --backdrop: rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #131415;
  --surface: #1b1c1e;
  --surface-2: #242628;
  --ink: #ecebe7;
  --ink-2: #b9b8b2;
  --ink-3: #8b8a85;
  --line: #33353a;
  --line-strong: #4b4e55;
  --accent: #f08a56;
  --accent-ink: #1b1c1e;
  --accent-soft: #3a261b;
  --focus: #6aa9ff;
  --m-ancestral: #5aa7de;
  --m-kmeans: #b595dc;
  --m-naive: #5fc45f;
  --m-samp: #ff9a3d;
  --m-map: #f0605f;
  --seq-0: #242628;
  --seq-1: #4a3022;
  --seq-2: #8a4a23;
  --seq-3: #d2702f;
  --seq-4: #ffb27a;
  --hl-1: #5a4a14;
  --hl-2: #244729;
  --hl-3: #3d2f5c;
  --hl-4: #17453f;
  --hl-5: #55263c;
  --hl-6: #1f3a5a;
  --hl-7: #5a3418;
  --hl-8: #3e4716;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
  --backdrop: rgba(0, 0, 0, 0.6);
}

/* Widget frame shared by all interactive pieces. */
.widget {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  font-family: var(--font);
  font-size: var(--text-s);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.widget :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (max-width: 640px) { .widget { padding: 0.875rem; } }
@media (prefers-reduced-motion: reduce) { .widget * { transition: none !important; animation: none !important; } }

/* Shared figure components. Every figure builds its controls, legends, notes and headings from these classes. */
.widget [hidden] { display: none !important; }

/* Ghost button. Opt out with .btn-plain (rows, links, legend toggles) and style the element in the figure's own sheet. */
.widget button:not(.btn-plain), .widget .seg > label {
  box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 32px; padding: 0.25rem 0.75rem; margin: 0;
  font: inherit; font-size: var(--text-s); line-height: 1.2; text-align: center; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  cursor: pointer; transition: background-color 0.12s, border-color 0.12s;
}
.widget button:not(.btn-plain):hover:not(:disabled), .widget .seg > label:hover { background: var(--surface-2); }
.widget button:not(.btn-plain):is([aria-pressed="true"], [aria-selected="true"], .is-on),
.widget .seg > input:checked + label {
  background: var(--accent-soft); border-color: var(--accent); color: var(--ink);
}
.widget button:disabled { opacity: 0.45; cursor: default; }
.widget .btn-plain { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: left; }
.widget .btn-icon { width: 32px; min-width: 32px; padding: 0; }

/* Segmented control: adjacent buttons (or radio labels) share borders. */
.widget .seg { display: inline-flex; max-width: 100%; vertical-align: top; }
.widget .seg > :is(button, label) { flex: 1 1 auto; border-radius: 0; margin-left: -1px; position: relative; }
.widget .seg > :is(button, label):first-of-type { margin-left: 0; border-radius: var(--radius-s) 0 0 var(--radius-s); }
.widget .seg > :is(button, label):last-of-type { border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.widget .seg > :is(button, label):only-of-type { border-radius: var(--radius-s); }
.widget .seg > :is(button, label):is([aria-pressed="true"], [aria-selected="true"], .is-on), .widget .seg > input:checked + label { z-index: 1; }
.widget .seg > input { position: absolute; opacity: 0; pointer-events: none; }
.widget .seg > input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }
.widget .seg-fill { display: flex; width: 100%; }
.widget .seg-fill > button { flex: 1 1 0; min-width: 0; }
/* Separate ghost buttons that wrap, such as prompt choices. */
.widget .chips { display: flex; flex-wrap: wrap; gap: 0.375rem; }

/* Range slider. A figure whose slider belongs to one method sets --range-color on it. --fill (0 to 1) is set by js/ui-range.js for WebKit. */
.widget input[type="range"] {
  --range-color: var(--accent);
  -webkit-appearance: none; appearance: none; box-sizing: border-box;
  display: block; width: 100%; height: 20px; margin: 0.25rem 0; padding: 0; background: transparent; cursor: pointer;
}
.widget input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--range-color) calc(8px + var(--fill, 0) * (100% - 16px)), var(--line) 0);
}
.widget input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; margin-top: -6px;
  border: 0; border-radius: 50%; background: var(--range-color); box-shadow: 0 0 0 2px var(--surface);
}
.widget input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); border: 0; }
.widget input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--range-color); }
.widget input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--range-color); box-shadow: 0 0 0 2px var(--surface); }
.widget input[type="range"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.widget input[type="checkbox"] { accent-color: var(--accent); width: 1rem; height: 1rem; margin: 0; }

/* Text: headings, control labels, notes, readouts, legends. */
.widget .fig-h { margin: 0; font-size: var(--text-s); font-weight: 600; line-height: 1.3; color: var(--ink); }
.widget .fig-label { margin: 0; padding: 0; font-size: var(--text-xs); font-weight: 600; line-height: 1.3; color: var(--ink-2); }
.widget .fig-note { margin: 0; font-size: var(--text-xs); line-height: 1.45; color: var(--ink-3); }
.widget .fig-num { font-size: var(--text-s); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.widget .legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; font-size: var(--text-xs); line-height: 1.3; color: var(--ink-2); }
.widget .legend-item { display: inline-flex; align-items: center; gap: 0.4rem; font-size: var(--text-xs); color: var(--ink-2); }
.widget button.legend-item { min-height: 32px; padding: 0.25rem 0.5rem; border-radius: var(--radius-s); }
.widget button.legend-item:hover { background: var(--surface-2); }
.widget button.legend-item[aria-pressed="false"] { opacity: 0.4; }

@media (pointer: coarse) {
  .widget button:not(.btn-plain), .widget .seg > label, .widget button.legend-item { min-height: 44px; }
  .widget .btn-icon { width: 44px; min-width: 44px; }
  .widget input[type="range"] { height: 44px; margin: 0; }
  .widget input[type="range"]::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--range-color) calc(14px + var(--fill, 0) * (100% - 28px)), var(--line) 0); }
  .widget input[type="range"]::-webkit-slider-thumb { width: 28px; height: 28px; margin-top: -12px; }
  .widget input[type="range"]::-moz-range-thumb { width: 28px; height: 28px; }
  .widget input[type="checkbox"] { width: 1.5rem; height: 1.5rem; }
}
