:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.12);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --critical: #d03b3b;
  --best-bg: #e3f1e3;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.12);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --good-ink: #0ca30c;
    --warn-ink: #fab219;
    --best-bg: #13301a;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
}
a { color: var(--accent-ink); }
h1 { font-size: 1.5rem; margin: 0 0 0.25rem; font-weight: 600; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; font-weight: 600; }
h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; font-weight: 600; }
.sub { color: var(--ink-2); margin: 0 0 1rem; }
.muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.9em; }

header.top {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.6rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
header.top .brand { font-weight: 700; color: var(--ink); text-decoration: none; }
header.top nav { display: flex; gap: 1.1rem; flex: 1; flex-wrap: wrap; }
header.top nav a { color: var(--ink-2); text-decoration: none; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
header.top nav a:hover { color: var(--ink); }
header.top nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
header.top form { display: flex; align-items: center; gap: 0.6rem; color: var(--ink-2); }

main { padding: 1.5rem; max-width: 1500px; margin: 0 auto; }
footer { padding: 1rem 1.5rem 2rem; color: var(--muted); font-size: 0.85rem; text-align: center; }

.flash { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--good); padding: 0.6rem 0.9rem; border-radius: 6px; }
.error { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--critical); padding: 0.6rem 0.9rem; border-radius: 6px; }
.once {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--warn);
  padding: 0.9rem 1rem; border-radius: 6px; margin: 1rem 0;
}
.once .secret { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0; }
.once .secret code { background: var(--surface-2); padding: 0.4rem 0.6rem; border-radius: 4px; font-size: 1rem; user-select: all; word-break: break-all; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.25rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.spread { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }

label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--ink-2); }
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis);
  border-radius: 6px; padding: 0.4rem 0.55rem; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button, .button {
  font: inherit; cursor: pointer; border-radius: 6px; padding: 0.42rem 0.9rem;
  border: 1px solid var(--axis); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-block;
}
button:hover, .button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--critical); }
button.link { border: 0; background: none; padding: 0; color: var(--accent-ink); text-decoration: underline; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
form.inline { display: inline; }

.filters { margin-bottom: 1rem; }
.filters input[type=search] { width: 16rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; font-size: 0.82rem; white-space: nowrap; background: var(--surface); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td.test-name { min-width: 13rem; }
td.wide { min-width: 18rem; }
.card > h3:first-child { margin-top: 0; }
.hw { font-weight: 500; }
.hw-sub { color: var(--ink-2); font-size: 0.85rem; }
table.kv { width: auto; }
table.kv th { font-weight: 500; }
table.kv tbody tr:hover td { background: none; }

.chips { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 0.2rem; font-variant-numeric: tabular-nums;
  font-size: 0.8rem; padding: 0.05rem 0.4rem; border-radius: 4px; background: var(--surface-2); color: var(--ink);
}
.chip.warn::before { content: "▼"; color: var(--warn-ink); font-size: 0.65rem; }
.status { white-space: nowrap; }
.status.ok::before { content: "● "; color: var(--good); }
.status.warn::before { content: "▲ "; color: var(--warn-ink); }

.selectbar { display: flex; align-items: center; gap: 0.8rem; margin: 0.75rem 0; flex-wrap: wrap; }

/* compare */
td.best { background: var(--best-bg); font-weight: 600; }
td.best::after { content: " ★"; color: var(--good-ink); font-weight: 400; font-size: 0.8em; }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 0.4rem; }
.key.s1 { background: var(--series-1); } .key.s2 { background: var(--series-2); }
.key.s3 { background: var(--series-3); } .key.s4 { background: var(--series-4); }
.key.s5 { background: var(--series-5); } .key.s6 { background: var(--series-6); }
.key.s7 { background: var(--series-7); } .key.s8 { background: var(--series-8); }

/* charts */
.test-block { margin-top: 2.5rem; }
.test-block > h2 { margin-top: 0; }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 1rem; margin-top: 1rem; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 0.75rem 0.25rem; min-width: 0; }
.chart h4 { margin: 0 0 0.25rem 0.25rem; font-size: 0.9rem; font-weight: 600; }
.chart .unit { color: var(--muted); font-weight: 400; }
.chart-empty { color: var(--muted); font-size: 0.9rem; padding: 1rem 0.25rem; }
.uplot { font-family: inherit; }
.uplot .u-legend { font-size: 0.82rem; color: var(--ink-2); text-align: left; padding: 0.2rem 0.25rem; }
.uplot .u-legend .u-marker { width: 14px; height: 3px; border-radius: 2px; border: 0 !important; }
.uplot .u-legend .u-value { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.uplot .u-legend th { font-weight: 400; color: var(--ink-2); background: none; }
.uplot .u-legend td, .uplot .u-legend th { border: 0; padding: 0.1rem 0.4rem; }
.uplot .u-legend tr:hover td { background: none; }
.uplot .u-cursor-x { border-right: 1px solid var(--muted) !important; }
.uplot .u-cursor-y { display: none; }

.login { max-width: 360px; margin: 10vh auto 0; }
.login form { display: flex; flex-direction: column; gap: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 0.8rem; max-width: 420px; }

@media (max-width: 640px) {
  main { padding: 1rem; }
  header.top { padding: 0.6rem 1rem; }
  .charts { grid-template-columns: 1fr; }
  .filters input[type=search] { width: 100%; }
}
