/* ---- design tokens ------------------------------------------------------- */
/* One small scale for everything: spacing, type, radius. No bespoke values
   elsewhere in this file — every measurement below is a token. */
:root {
  /* palette (near-monochrome; one warm colour for highlights) */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --text: #1a1a1a;
  --text-dim: #6b6b70;
  --border: #e3e3e6;
  --accent: #4b3fce;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --hl: rgba(255, 212, 0, 0.38);
  --hl-active: rgba(255, 165, 0, 0.55);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.12);

  /* spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  /* type scale */
  --text-sm: 0.8125rem;
  --text-base: 1rem;
  --text-md: 1.125rem;
  --text-lg: 1.375rem;
  --text-xl: 1.75rem;

  /* one radius, plus a pill for round chips */
  --radius: 6px;
  --radius-pill: 999px;

  /* fixed dimensions */
  --control-h: 40px;
  --topbar-h: 56px;
  --reading: 42rem;
  --sidebar: 360px;

  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1c1c21;
    --surface-2: #26262c;
    --text: #ededf0;
    --text-dim: #9a9aa2;
    --border: #2f2f36;
    --accent: #8b80ff;
    --accent-text: #16161a;
    --danger: #ff6b5e;
    --hl: rgba(255, 212, 0, 0.28);
    --hl-active: rgba(255, 180, 0, 0.5);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
/* The hidden attribute must always win over the display rules below. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-dim); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- buttons (shared pattern, see annotate) ------------------------------- */
.btn {
  font: inherit;
  font-size: var(--text-base);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); }

/* ---- page layout ----------------------------------------------------------- */
.page {
  max-width: 52rem;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}
.page-head h1 { margin: 0 0 var(--space-2); font-size: var(--text-xl); }
.lede { margin: 0; color: var(--text-dim); }
.page-foot { margin-top: var(--space-6); font-size: var(--text-sm); }
.page-foot a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ---- controls row ----------------------------------------------------------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-5);
  margin: var(--space-5) 0;
  padding: 0;
  border: none;
}
.field { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; border: none; }
.field label {
  font-size: var(--text-sm);
  color: var(--text-dim);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.field output { font-variant-numeric: tabular-nums; color: var(--text); }

.colour-input { display: flex; align-items: center; gap: var(--space-2); }
.colour-input input[type="color"] {
  width: var(--control-h);
  height: var(--control-h);
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.colour-input input[type="text"] {
  width: 8rem;
  font: inherit;
  font-size: var(--text-base);
  height: var(--control-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}
.colour-input input[type="text"]:focus-visible,
.colour-input input[type="color"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field input[type="range"] {
  width: 12rem;
  height: var(--control-h);
  accent-color: var(--accent);
}
.field input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* segmented control: hidden native radios + styled sibling labels, so arrow-key
   navigation and screen readers keep working (see the segmented-control fieldset in index.html). */
.segmented-field { align-self: flex-end; }
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.segment { position: relative; display: inline-flex; height: calc(var(--control-h) - 4px); }
.segment input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.segment-label {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  color: var(--text-dim);
  white-space: nowrap;
}
.segment input:checked + .segment-label { background: var(--accent); color: var(--accent-text); }
.segment input:focus-visible + .segment-label { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- colour field ------------------------------------------------------------- */
/* The field is a canvas painted from JS (per-pixel HSL raster + a pass/fail mask +
   a marker reticle) — see app.ts. Layout/chrome only lives here; colour is CSSOM. */
.field-wrap { position: relative; margin: var(--space-5) 0; }
.colour-field {
  display: block;
  width: 100%;
  aspect-ratio: 640 / 288;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  touch-action: none;
}
.colour-field:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field-hint { margin: var(--space-2) 0 0; font-size: var(--text-sm); }

.loupe {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  pointer-events: none;
}
.loupe-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
}
.loupe-chip {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--text-sm);
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.loupe-chip.fail { color: var(--danger); }

/* ---- preview + readout -------------------------------------------------------- */
.result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  align-items: start;
  margin-top: var(--space-5);
}
.preview {
  min-width: 0;
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.preview-heading { margin: 0 0 var(--space-3); font-size: var(--text-xl); font-weight: 700; line-height: 1.25; }
.preview-body { margin: 0 0 var(--space-3); font-size: var(--text-md); line-height: 1.6; }
.preview-small { margin: 0; font-size: var(--text-sm); }

.readout { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.ratio { font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.badges { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
}
.badge.pass { border-color: var(--accent); color: var(--text); }
.badge.fail { border-color: var(--danger); color: var(--danger); }

.hex-row { display: flex; flex-direction: column; gap: var(--space-2); }
.hex-item { display: flex; align-items: center; gap: var(--space-2); }
.hex-label { min-width: 5.5rem; font-size: var(--text-sm); color: var(--text-dim); }
.hex-item code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--text-sm);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  background: var(--surface-2);
}

/* ---- toast (mirrors annotate's #status pattern) -------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translate(-50%, var(--space-6));
  z-index: 70;
  max-width: min(90vw, 30rem);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-sm);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- responsive: mobile ------------------------------------------------------- */
@media (max-width: 640px) {
  .result { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
