/*
 * Design system per DESIGN.md (tool-style). Tokens, base styles and all controls.
 * States have a class next to the pseudo-class (.is-hover, .is-focus, …) so the
 * specimen (/specimen/) can show every state statically.
 */

@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/IBMPlexMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/IBMPlexMono-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/IBMPlexMono-Italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: block;
}
/* Alternate style "ocr" only (see end of file); the browser loads it only where it is used */
@font-face {
  font-family: 'OCR A';
  src: url('fonts/OCRA.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  /* Type: one family, size/line height as pairs */
  --font: 'IBM Plex Mono', monospace;
  --t-s: 11px;  --t-s-lh: 16px;
  --t-m: 13px;  --t-m-lh: 20px;
  --t-l: 15px;  --t-l-lh: 20px;
  --t-xl: 24px; --t-xl-lh: 28px;
  --caps: 0.04em;

  /* Colour – signal is the only colour in the interface */
  --paper: #F4F4F2;
  --paper-2: #FFFFFF;
  --ink: #191A1A;
  --ink-2: #6E7070;
  --line: #D8D8D5;
  --signal: #FF4F00; /* provisional, see DESIGN.md "Open points" */

  /* Spacing: base unit 4 */
  --s-4: 4px; --s-8: 8px; --s-12: 12px; --s-16: 16px; --s-24: 24px; --s-32: 32px; --s-48: 48px; --s-64: 64px;

  --row-h: 28px;
  --section-gap: var(--s-24); /* gap between panel sections */
  --masthead-h: 96px;
  --toolbar-h: 72px;
  --bar-h: 56px;
  --panel-w: 360px;
  --ctrl-w: 96px;
  --value-w: 7ch;
  --dur: 100ms;
  --radius-btn: 4px; /* filled buttons only */
  --swatch-line: var(--line); /* swatch border */
  color-scheme: light;
}

/*
 * Dark mode: only the colour tokens change. Follows the system setting unless
 * data-theme="light" / "dark" is set explicitly (LIGHT / DARK toggle).
 */
:root[data-theme="dark"] {
  --paper: #0F1010;
  --paper-2: #161717;
  --ink: #E6E6E3;
  --ink-2: #8C8E8E;
  --line: #2E2F2F;
  --signal: #FF5A14;
  --swatch-line: var(--ink-2); /* otherwise dark colours disappear */
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1010;
    --paper-2: #161717;
    --ink: #E6E6E3;
    --ink-2: #8C8E8E;
    --line: #2E2F2F;
    --signal: #FF5A14;
    --swatch-line: var(--ink-2);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-m);
  line-height: var(--t-m-lh);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
::selection { background: var(--ink); color: var(--paper-2); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; font-size: inherit; font-weight: inherit; }

/* Caps for actions, labels, section titles, status line */
.caps { text-transform: uppercase; letter-spacing: var(--caps); }
.t-s { font-size: var(--t-s); line-height: var(--t-s-lh); }
.t-m { font-size: var(--t-m); line-height: var(--t-m-lh); }
.t-l { font-size: var(--t-l); line-height: var(--t-l-lh); }
.muted { color: var(--ink-2); }
/* File names and user content stay in mixed case, even in caps rows */
.caps .file, .file { text-transform: none; letter-spacing: 0; }
.signal { color: var(--signal); }

/* Custom scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-2); }

/* ---------- Action: what is clickable is underlined ---------- */

.action {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: var(--caps);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--ink-2);
  text-underline-offset: 3px;
  white-space: nowrap;
  transition: text-decoration-color var(--dur);
}
/* Hover: line stays 1px, only changes from grey to ink */
.action:hover, .action.is-hover { text-decoration-color: var(--ink); }
.action:focus-visible, .action.is-focus { outline: 1px solid var(--signal); outline-offset: 3px; }
.action:disabled, .action.is-disabled { color: var(--ink-2); text-decoration: none; cursor: default; }
/* Destructive action after the first click: asks for a second one */
.action.is-armed { color: var(--signal); text-decoration-color: var(--signal); }

/* Primary action: at most one per view, filled in ink, never underlined */
.action.primary {
  padding: var(--s-4) var(--s-12);
  border-radius: var(--radius-btn);
  background: var(--ink);
  color: var(--paper-2);
  text-decoration: none;
  transition: outline-color var(--dur);
  outline: 1px solid transparent;
  outline-offset: 2px;
}
.action.primary:hover, .action.primary.is-hover { outline-color: var(--ink); }
.action.primary:focus-visible, .action.primary.is-focus { outline-color: var(--signal); }
.action.primary:disabled, .action.primary.is-disabled { background: var(--ink-2); color: var(--paper-2); outline-color: transparent; }

/* Option in a toggle group (e.g. BEFORE / AFTER stacked): active = ink, otherwise ink-2 */
.option {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: var(--caps);
  white-space: nowrap;
  transition: color var(--dur);
}
.option:hover, .option.is-hover { color: var(--ink); }
.option[aria-pressed="true"], .option.is-active { color: var(--ink); cursor: default; }
.option:focus-visible, .option.is-focus { outline: 1px solid var(--signal); outline-offset: 2px; }
.option:disabled { color: var(--ink-2); cursor: default; }

.actions { display: flex; align-items: baseline; gap: var(--s-16); }
/* Destructive action at the end, 24px apart */
.actions .destructive { margin-left: var(--s-8); }

/* ---------- Panel ---------- */

.section { border-bottom: 1px solid var(--line); }
.section-head {
  appearance: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: var(--row-h);
  padding: 0 var(--s-12);
  background: none;
  border: 0;
  cursor: pointer;
  font-size: var(--t-s);
  line-height: var(--t-s-lh);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--caps);
  text-align: left;
}
.section-head:focus-visible { outline: 1px solid var(--signal); outline-offset: -1px; }
.section-head .mark { font-weight: 400; }
.section-body[hidden] { display: none; }

/* Row: label · control (96px) · value (7ch) */
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--ctrl-w) var(--value-w);
  align-items: center;
  column-gap: var(--s-12);
  height: var(--row-h);
  padding: 0 var(--s-12);
  border-top: 1px solid var(--line);
  position: relative;
}
.row[hidden] { display: none; }
.row-label {
  font-size: var(--t-s);
  line-height: var(--t-s-lh);
  text-transform: uppercase;
  letter-spacing: var(--caps);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-label .unit { color: var(--ink-2); margin-left: var(--s-4); }
.row.is-disabled .row-label, .row.is-disabled .num { color: var(--ink-2); }
/* Control and value combined (select, action) */
.row .span-2 { grid-column: 2 / 4; }
.row .col-3 { grid-column: 3; justify-self: end; }

/* Slider: 1px track, 1px ink fill, 2 × 12px handle */
.slider {
  position: relative;
  height: var(--row-h);
  cursor: pointer;
  touch-action: none;
  outline: none;
}
.slider .track, .slider .fill {
  position: absolute;
  left: 0;
  top: 50%;
  height: 1px;
  background: var(--line);
  width: 100%;
}
.slider .fill { background: var(--ink); width: var(--p, 0%); }
.slider .grip {
  position: absolute;
  top: 50%;
  left: var(--p, 0%);
  width: 2px;
  height: 12px;
  margin: -6px 0 0 -1px;
  background: var(--ink);
}
.slider:focus-visible .grip, .slider.is-focus .grip { background: var(--signal); }
.slider:hover .fill, .slider.is-hover .fill { height: 2px; margin-top: -1px; }
.row.is-disabled .slider { cursor: default; }
.row.is-disabled .slider .fill, .row.is-disabled .slider .grip { background: var(--ink-2); }

/* Number field: no border, right-aligned, focus = underline in signal */
.num {
  appearance: none;
  width: 100%;
  height: var(--t-m-lh);
  padding: 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  text-align: right;
  font-size: var(--t-m);
  font-variant-numeric: tabular-nums;
  outline: none;
  border-radius: 0;
}
.num:hover, .num.is-hover { border-bottom-color: var(--line); }
.num:focus, .num.is-focus { border-bottom-color: var(--signal); }
.num.is-error { color: var(--signal); border-bottom-color: var(--signal); }
.num:disabled { color: var(--ink-2); }
/* As type=number (pages without a build): no spin buttons */
.num::-webkit-inner-spin-button, .num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num[type="number"] { -moz-appearance: textfield; }

/* Pages without a build: native element kept as the source of truth behind its control (enhance.js) */
.is-native { display: none !important; }

/* Select: text + ↓, no border; list: paper-2, 1px ink, 28px entries */
.select { position: relative; min-width: 0; }
.select-btn {
  appearance: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-8);
  width: 100%;
  height: var(--row-h);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  font-size: var(--t-m);
}
.select-btn .value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-btn .mark { color: var(--ink-2); }
.select-btn:hover .value, .select-btn.is-hover .value { text-decoration: underline; text-underline-offset: 3px; }
.select-btn:focus-visible, .select-btn.is-focus { outline: none; }
.select-btn:focus-visible .value, .select-btn.is-focus .value { text-decoration: underline; text-decoration-color: var(--signal); text-underline-offset: 3px; }
.select-btn:disabled { color: var(--ink-2); cursor: default; }
.select-list {
  position: absolute;
  z-index: 10;
  top: calc(var(--row-h) - 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--paper-2);
  border: 1px solid var(--ink);
}
.select-list[hidden] { display: none; }
.select-list li {
  height: var(--row-h);
  line-height: var(--row-h);
  padding: 0 var(--s-8);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.select-list li + li { border-top: 1px solid var(--line); }
.select-list li[aria-selected="true"] { font-weight: 600; }
.select-list li.is-hover, .select-list li:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Action menu: action + ↓, opens the select list below (or above with .up) */
.menu { position: relative; display: inline-flex; }
.menu .action .mark { display: inline-block; margin-left: 1ch; color: var(--ink-2); }
.menu .select-list { top: calc(100% + var(--s-8)); right: auto; min-width: 100%; width: max-content; font-size: var(--t-m); line-height: var(--t-m-lh); }
.menu.up .select-list { top: auto; bottom: calc(100% + var(--s-8)); }

/* Switch (on/off): OFF · ON as options, right-aligned in the value column */
.switch { display: flex; gap: var(--s-8); font-size: var(--t-s); line-height: var(--t-s-lh); }
/* In a row, options sit right-aligned (OFF · ON in the value column, longer groups across .span-2) */
.row .switch { justify-self: end; }
.row.is-disabled .option { color: var(--ink-2); cursor: default; }

/* Swatch: 12 × 12px, 1px line; hex in caps, right-aligned */
.swatch {
  appearance: none;
  display: block;
  width: 12px;
  height: 12px;
  padding: 0;
  border: 1px solid var(--swatch-line);
  background: none;
  cursor: pointer;
}
.swatch::-webkit-color-swatch-wrapper { padding: 0; }
.swatch::-webkit-color-swatch { border: 0; }
.swatch::-moz-color-swatch { border: 0; }
.swatch:focus-visible { outline: 1px solid var(--signal); outline-offset: 2px; }
.swatch-cell { display: flex; align-items: center; gap: var(--s-12); }
.hex { text-transform: uppercase; }

/*
 * ---------- Alternate style: OCR (<html data-style="ocr">) ----------
 * OCR-A, one weight, two sizes. OCR-A lacks – × ↓ ← · … ©, these come from IBM Plex Mono.
 * Hierarchy without 600: section title in ink, row labels in ink-2, selected entry marked with ←.
 */
:root[data-style="ocr"] {
  --font: 'OCR A', 'IBM Plex Mono', monospace;
  --t-l: var(--t-m); --t-l-lh: var(--t-m-lh);
  font-synthesis: none; /* no fake bold or italic */
}
:root[data-style="ocr"] .section-head,
:root[data-style="ocr"] .list-title,
:root[data-style="ocr"] .select-list li[aria-selected="true"] { font-weight: 400; }
:root[data-style="ocr"] .row-label { color: var(--ink-2); }
:root[data-style="ocr"] .select-list li[aria-selected="true"]::after { content: '←'; display: inline-block; margin-left: 1ch; color: var(--ink-2); }
