:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --panel-2: #f0f3f2;
  --line: #dde4e2;
  --text: #0d1a1d;
  --muted: #56706f;
  --accent: #0a8f62;
  --accent-ink: #ffffff;
  --accent-soft: #d9f5ea;
  --amber: #a86500;
  --amber-soft: #fff1d6;
  --red: #c0344a;
  --cyan: #147a93;
  --bar-track: #e6ecea;
  --focus: #0a8f62;
  --shadow: 0 1px 2px rgb(13 26 29 / 0.06), 0 4px 16px rgb(13 26 29 / 0.04);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090f13;
    --panel: #0f181d;
    --panel-2: #13232a;
    --line: #20353c;
    --text: #e3f3ef;
    --muted: #7d9a9f;
    --accent: #62f5b5;
    --accent-ink: #062016;
    --accent-soft: #12382b;
    --amber: #ffce73;
    --amber-soft: #3a2c10;
    --red: #ff7c8c;
    --cyan: #8ad8e9;
    --bar-track: #1a2c33;
    --focus: #62f5b5;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #090f13;
  --panel: #0f181d;
  --panel-2: #13232a;
  --line: #20353c;
  --text: #e3f3ef;
  --muted: #7d9a9f;
  --accent: #62f5b5;
  --accent-ink: #062016;
  --accent-soft: #12382b;
  --amber: #ffce73;
  --amber-soft: #3a2c10;
  --red: #ff7c8c;
  --cyan: #8ad8e9;
  --bar-track: #1a2c33;
  --focus: #62f5b5;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1rem; display: flex; align-items: center; gap: 0.5rem; margin-right: auto; }
p { margin: 0; }
.small { font-size: 0.85rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 6px 10px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px max(16px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: #090f13; color: #62f5b5; font: 700 18px/1 var(--mono);
}
.sub { color: var(--muted); font-size: 0.85rem; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 0.8rem; color: var(--muted); white-space: nowrap;
  max-width: 44vw; overflow: hidden; text-overflow: ellipsis;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.pill.ok::before { background: var(--accent); }
.pill.warn::before { background: var(--amber); }
.pill.bad::before { background: var(--red); }
.pill.sm { padding: 1px 8px 1px 6px; font-size: 0.72rem; max-width: none; }
#server-url { width: 220px; flex: none; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: transparent;
  color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

.banner {
  margin: 16px auto 0; max-width: 1240px; width: calc(100% - 32px);
  padding: 12px 16px; border-radius: var(--radius); background: var(--amber-soft); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent);
}
.banner strong { color: var(--amber); }

.layout {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px;
  max-width: 1240px; margin: 16px auto; padding: 0 16px;
}
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.panel-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel.collapsed { gap: 0; }
.panel.collapsed > *:not(.panel-head) { display: none; }
.collapse-btn {
  margin-left: auto; width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; flex: none;
}
.collapse-btn svg { width: 14px; height: 14px; fill: currentColor; transition: transform 0.15s; }
.panel.collapsed .collapse-btn svg { transform: rotate(-90deg); }
.step {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent); font: 700 12px/1 var(--mono);
}
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 560px) { .cards { grid-template-columns: minmax(0, 1fr); } }
.card {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--panel-2);
  transition: border-color 0.15s;
}
.card input { position: absolute; opacity: 0; pointer-events: none; }
.card:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.card .t { font-weight: 600; }
.card .d { font-size: 0.8rem; color: var(--muted); }
.card .cached { font-size: 0.72rem; color: var(--accent); font-weight: 600; }

.btn {
  font: inherit; font-weight: 600; border-radius: 9px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px;
}
.btn.small { padding: 4px 10px; font-size: 0.85rem; min-height: 30px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn kbd { font: 600 0.75rem var(--mono); opacity: 0.75; }
.linklike { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

.progress-wrap { display: flex; flex-direction: column; gap: 6px; }
progress {
  width: 100%; height: 8px; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--bar-track); appearance: none;
}
progress::-webkit-progress-bar { background: var(--bar-track); }
progress::-webkit-progress-value { background: var(--accent); transition: width 0.2s; }
progress::-moz-progress-bar { background: var(--accent); }

textarea, input[type="text"], select {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; width: 100%; min-width: 0;
}
select { width: auto; max-width: 100%; padding: 5px 8px; font-size: 0.9rem; }
textarea { resize: vertical; font-family: var(--mono); font-size: 0.86rem; line-height: 1.45; }
textarea:focus, input[type="text"]:focus, select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.error { color: var(--red); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 2px; align-self: flex-start; background: var(--panel-2); }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: inline-block; padding: 3px 12px; border-radius: 7px; font-size: 0.85rem; color: var(--muted); }
.seg input:checked + span { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--focus); }

.questions { display: flex; flex-direction: column; gap: 10px; }
.q {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px;
  background: var(--panel-2);
}
.q-head { display: grid; grid-template-columns: minmax(0, 9rem) auto minmax(0, 1fr) auto; gap: 8px; align-items: center; }
@media (max-width: 560px) { .q-head { grid-template-columns: minmax(0, 1fr) auto auto; } .q-head .ins { grid-column: 1 / -1; order: 5; } }
.q input[type="text"], .q select { background: var(--panel); }
.q .id { font-family: var(--mono); font-size: 0.85rem; }
.badge {
  font: 600 0.7rem/1 var(--mono); text-transform: uppercase; letter-spacing: 0.04em;
  padding: 4px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
}
.badge.score { background: color-mix(in srgb, var(--cyan) 18%, transparent); color: var(--cyan); }
.badge.noul { background: var(--amber-soft); color: var(--amber); }
.crit { display: flex; flex-direction: column; gap: 6px; padding-left: 8px; border-left: 2px solid var(--line); }
.crit-row { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.crit-row.single { grid-template-columns: 1.6rem minmax(0, 1fr) auto; }
.crit-row .n { font: 600 0.8rem var(--mono); color: var(--muted); text-align: right; }
.crit-row.noul { grid-template-columns: 3.2rem minmax(0, 1fr); }
.crit-row.noul .n { text-align: left; }
.x { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 4px 6px; border-radius: 6px; }
.x:hover { color: var(--red); background: var(--panel); }
.add-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.state-fields { display: flex; flex-direction: column; gap: 8px; }
.sf { display: grid; grid-template-columns: minmax(0, 8rem) auto minmax(0, 1fr) auto; gap: 8px; align-items: center; }
@media (max-width: 560px) { .sf { grid-template-columns: minmax(0, 1fr) auto; } .sf .val, .sf input[type="checkbox"] { grid-column: 1 / -1; } }
.sf input[type="text"], .sf input[type="number"], .sf select { background: var(--panel); }
.sf .id { font-family: var(--mono); font-size: 0.85rem; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
@media (max-width: 460px) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.metrics div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.metrics dt { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.metrics dd { margin: 0; font: 600 1.05rem var(--mono); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* One column per backend: one column in the normal (single-backend) case,
   two side by side in compare mode. */
.results-columns { display: flex; flex-direction: column; gap: 18px; }
.results-columns.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
@media (max-width: 700px) { .results-columns.compare { grid-template-columns: minmax(0, 1fr); } }
.result-column { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.result-column .col-head { font: 600 0.85rem var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.result-column.fastest .col-head { color: var(--accent); }
.result-column.fastest .col-head::after { content: " · fastest"; }

.answers { display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.answer { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.answer-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.answer-head .qid { font: 600 0.85rem var(--mono); color: var(--muted); }
.answer-head .ins { font-size: 0.85rem; color: var(--muted); flex: 1 1 12rem; min-width: 0; }
.verdict { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.verdict small { font-size: 0.8rem; font-weight: 500; color: var(--muted); margin-left: 6px; }
.bars { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.bar { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) 3.4rem; gap: 8px; align-items: center; font-size: 0.85rem; }
.bar .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { display: block; height: 10px; border-radius: 999px; background: var(--bar-track); overflow: hidden; }
.bar .fill { display: block; height: 100%; border-radius: inherit; background: var(--muted); width: 0; transition: width 0.35s ease-out; }
.bar.top .fill { background: var(--accent); }
.bar.top .lab { font-weight: 600; }
.bar .val { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.answer.noul .bar .fill { background: var(--amber); }
.answer.score .bar.top .fill { background: var(--cyan); }
.meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }
.meta b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.scale { position: relative; height: 6px; background: var(--bar-track); border-radius: 999px; margin: 4px 0 2px; }
.scale .dot { position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; background: var(--cyan); transform: translate(-50%, -50%); border: 2px solid var(--panel); transition: left 0.35s ease-out; }
.raw summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.raw pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow: auto; max-height: 320px; font-size: 0.8rem; margin: 8px 0 0; }

.queue { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow: auto; }
.queue-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; }
.queue-view {
  display: grid; grid-template-columns: 5.5rem minmax(0, 1fr) auto; gap: 10px; align-items: center;
  background: transparent; border: 0; text-align: left; padding: 8px 10px; cursor: pointer; color: inherit; font: inherit; min-width: 0;
}
.queue-view:hover { background: var(--panel-2); }
.qe-time { font: 500 0.78rem var(--mono); color: var(--muted); }
.qe-state { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.qe-meta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
@media (max-width: 560px) { .queue-view { grid-template-columns: minmax(0, 1fr); } .qe-time, .qe-meta { grid-column: 1; } }

.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; max-width: 1240px; margin: 8px auto 32px; padding: 0 16px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 520px) {
  .sub { display: none; }
  .bar { grid-template-columns: minmax(0, 6rem) minmax(0, 1fr) 3.4rem; }
}
