/* PIAST-Q emulator front panel. Colours are tokens; dark mode overrides them. */
:root {
  color-scheme: light dark;
  --bg: #f1f1ee;
  --surface: #fcfcfb;
  --inset: #f1f1ee;
  --text: #0b0b0b;
  --muted: #52514e;
  --border: #cfcec8;
  --accent: #1f63b5;        /* links, primary button, focus ring, selected tier */
  --on-accent: #ffffff;
  --noisy: #2a78d6;         /* series 1: the requested tier */
  --ideal: #c9521f;         /* series 2: ideal reference (also hatched) */
  --heat: #174f96;          /* sequential scale, high end */
  --error: #a4261d;
  --error-bg: #fbeceb;
  --warn: #7a4f00;          /* benchmark warnings, active overrides, tier fallback */
  --warn-bg: #fbf3e0;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a19;
    --inset: #242422;
    --text: #f0efec;
    --muted: #c3c2b7;
    --border: #45443f;
    --accent: #6aa6ee;
    --on-accent: #0b0b0b;
    --noisy: #3987e5;
    --ideal: #e8763f;
    --heat: #8fc0ff;
    --error: #ff9d94;
    --error-bg: #3a1c1a;
    --warn: #f2c46d;
    --warn-bg: #33291a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 0.8rem; margin: 0 0 0.9rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
h3 { font-size: 0.9rem; margin: 1.4rem 0 0.3rem; }
p { margin: 0; }
a { color: var(--accent); }
code, pre, textarea, .bits { font-family: var(--mono); }
.muted { color: var(--muted); font-weight: normal; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Layout */
.top {
  display: flex; flex-wrap: wrap; gap: 0.5rem 2rem; justify-content: space-between; align-items: end;
  padding: 1rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.meta { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; font-size: 0.9rem; color: var(--muted); overflow-wrap: anywhere; }
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem;
  max-width: 1280px; margin: 0 auto; padding: 1rem;
}
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) 420px; align-items: start; }
}
.column { display: grid; gap: 1rem; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1rem 1.1rem; min-width: 0; }

/* Form */
.field { margin-bottom: 0.9rem; min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 1rem; }
label, legend { font-weight: 600; font-size: 0.9rem; }
.field > label { display: block; margin-bottom: 0.25rem; }
input[type="number"], select, textarea {
  width: 100%; padding: 0.45rem 0.55rem; font-size: 0.95rem;
  color: var(--text); background: var(--inset); border: 1px solid var(--border); border-radius: 4px;
}
input[type="number"], select { font-family: inherit; font-variant-numeric: tabular-nums; }
input[type="number"].changed { border-color: var(--warn); box-shadow: inset 3px 0 0 var(--warn); }
input[type="file"] { max-width: 100%; font: inherit; font-size: 0.85rem; }
textarea { resize: vertical; font-size: 0.85rem; line-height: 1.45; tab-size: 2; white-space: pre; overflow: auto; }
fieldset { border: 1px solid var(--border); border-radius: 4px; margin: 0 0 0.9rem; padding: 0.5rem 0.8rem 0.6rem; min-width: 0; }
fieldset.plain { border: 0; padding: 0; }
fieldset.plain legend { padding: 0; margin-bottom: 0.25rem; }
legend { padding: 0 0.3rem; }
.check { display: flex; gap: 0.5rem; align-items: baseline; font-weight: normal; padding: 0.2rem 0; }
.check input { accent-color: var(--accent); flex: none; }
.check:has(input:disabled) { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.9rem; }
button {
  font: inherit; font-size: 0.9rem; padding: 0.45rem 0.9rem; cursor: pointer;
  color: var(--text); background: var(--inset); border: 1px solid var(--border); border-radius: 4px;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; min-width: 7rem; }
button:disabled { opacity: 0.55; cursor: progress; }

/* Tier selector: a radio group drawn as a segmented control (arrow keys move within it). */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  border: 1px solid var(--border); border-radius: 4px; background: var(--inset);
}
.segmented label {
  position: relative; display: flex; justify-content: center; align-items: center; text-align: center;
  padding: 0.4rem 0.3rem; cursor: pointer; overflow-wrap: anywhere;
}
.segmented label + label { border-left: 1px solid var(--border); }
.segmented label:first-child { border-radius: 3px 0 0 3px; }
.segmented label:last-child { border-radius: 0 3px 3px 0; }
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segmented label:has(input:checked) { background: var(--accent); color: var(--on-accent); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; z-index: 1; }
#tier-description { margin-bottom: 0.9rem; }
#tier-emulator-note { margin: -0.6rem 0 0.9rem; }

/* Disclosures, warnings, badges */
.disclosure { border: 1px solid var(--border); border-radius: 4px; padding: 0.4rem 0.8rem; margin: 0 0 0.9rem; }
.disclosure > summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.disclosure[open] > summary { margin-bottom: 0.5rem; }
.field .disclosure { margin: 0.5rem 0 0; }
.warn, .notes { font-size: 0.85rem; padding: 0.4rem 0.7rem 0.4rem 1.6rem; margin: 0.5rem 0 0; overflow-wrap: anywhere; }
.warn { color: var(--warn); background: var(--warn-bg); border-left: 3px solid var(--warn); border-radius: 0 4px 4px 0; }
.notes { color: var(--muted); padding-left: 1.2rem; }
.notes:empty { display: none; }
.errors-list { margin: 0; font-size: 0.85rem; }
.errors-list dt { font-family: var(--mono); overflow-wrap: anywhere; }
.errors-list dd { margin: 0 0 0.4rem; color: var(--error); overflow-wrap: anywhere; }
.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; line-height: 1.4; padding: 0.05rem 0.5rem;
  color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn); border-radius: 999px;
}
.overrides-grid { margin-top: 0.6rem; align-items: end; }

/* Results */
.status { color: var(--muted); }
progress { display: block; width: 100%; height: 0.5rem; margin-top: 0.5rem; accent-color: var(--accent); }
.error {
  color: var(--error); background: var(--error-bg); border-left: 3px solid var(--error);
  padding: 0.5rem 0.7rem; margin-top: 0.5rem; border-radius: 0 4px 4px 0; overflow-wrap: anywhere; white-space: pre-wrap;
}
#job-form > .error { margin: 0 0 0.9rem; }
.summary { font-size: 0.9rem; color: var(--muted); margin-top: 0.5rem; overflow-wrap: anywhere; }
.summary strong { color: var(--text); }
.metrics { display: flex; flex-wrap: wrap; gap: 0.5rem 2.5rem; margin-top: 0.9rem; }
.metric span { display: block; font-size: 0.8rem; color: var(--muted); }
.metric strong { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; font-size: 0.85rem; margin: 1rem 0 0.5rem; }
.swatch { display: inline-block; width: 1.6rem; height: 0.6rem; margin-right: 0.3rem; }
.histogram { list-style: none; margin: 0; padding: 0; }
.histogram li {
  display: grid; grid-template-columns: minmax(4rem, auto) minmax(0, 1fr); gap: 0 0.75rem; align-items: center;
  padding: 0.3rem 0; border-top: 1px solid var(--border);
}
.bits { font-size: 0.85rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.series { display: grid; grid-template-columns: minmax(0, 1fr) 10rem; gap: 0.5rem; align-items: center; }
.series + .series { margin-top: 2px; }
.track { height: 0.6rem; }
.bar { height: 100%; min-width: 1px; border-radius: 0 3px 3px 0; }
.main { background: var(--noisy); }
.ref {
  border: 1px solid var(--ideal);
  background: repeating-linear-gradient(135deg, var(--ideal) 0 2px, transparent 2px 5px);
}
.value { font-size: 0.8rem; white-space: nowrap; text-align: right; }
@media (max-width: 560px) {
  .histogram li { grid-template-columns: minmax(0, 1fr); }
}
pre {
  margin: 0.6rem 0 0; padding: 0.7rem 0.8rem; font-size: 0.8rem; line-height: 1.45;
  background: var(--inset); border: 1px solid var(--border); border-radius: 4px; overflow-x: auto;
}
#curl-upload-block { margin-top: 1.2rem; }

/* Device */
.numbers { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.5rem 1rem; margin: 0; }
.numbers dt { font-size: 0.8rem; color: var(--muted); }
.numbers dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.axis-x, .axis-y, .xt-legend { font-size: 0.75rem; color: var(--muted); }
.axis-x { text-align: center; margin-top: 0.2rem; }
.axis-y { writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; }
.chart-wrap { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.3rem; margin-top: 0.5rem; }
.bars { display: grid; gap: 2px; border-bottom: 1px solid var(--border); }
.bar-col { display: flex; flex-direction: column; align-items: center; font-size: 0.65rem; min-width: 0; }
.bar-plot { height: 7rem; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar-value { writing-mode: vertical-rl; transform: rotate(180deg); margin-bottom: 2px; }
.bar-fill { width: 100%; min-height: 1px; background: var(--noisy); border-radius: 2px 2px 0 0; }
.bar-ion { color: var(--muted); min-height: 1.5em; }
.xt-grid { display: grid; gap: 1px; cursor: crosshair; }
.xt-axis { font-size: 0.6rem; color: var(--muted); text-align: center; align-self: center; }
.xt-cell { aspect-ratio: 1; background: color-mix(in oklab, var(--heat) var(--v, 0%), var(--inset)); }
.xt-cell.diag { background: none; }
.xt-cell.selected { outline: 2px solid var(--text); outline-offset: 0; position: relative; }
.xt-legend { display: flex; gap: 0.5rem; align-items: center; margin: 0.6rem 0 0 1.5rem; }
.xt-ramp { flex: 0 1 10rem; height: 0.6rem; background: linear-gradient(to right,var(--inset), var(--heat)); border: 1px solid var(--border); }
.readout { font-size: 0.85rem; margin-top: 0.4rem; min-height: 1.5em; }
