:root {
  color-scheme: light;
  --brand: #29abe2;
  --brand-ink: #0d6f99;
  --page: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eef6fb;
  --border: rgba(11, 11, 11, 0.12);
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --ok: #0a7d0a;
  --warn-bg: #fff1b8;
  --danger: #c62828;
  --chart-surface: #fcfcfb;
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-cell-line: #8aa9bf;
  --chart-select: rgba(42, 120, 214, 0.14);
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --cell-hi: #eb6834;
  --cell-lo: #2a78d6;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand-ink: #6fcbf0;
    --page: #0f1011;
    --surface: #1a1a19;
    --surface-2: #17242c;
    --border: rgba(255, 255, 255, 0.12);
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9b9991;
    --ok: #3cc43c;
    --warn-bg: #4a3d0a;
    --danger: #ff6b6b;
    --chart-surface: #1a1a19;
    --chart-grid: #2c2c2a;
    --chart-axis: #4a4a46;
    --chart-cell-line: #5d7a8f;
    --chart-select: rgba(57, 135, 229, 0.22);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #0ca30c; --series-7: #9085e9; --series-8: #e66767;
    --cell-hi: #ff8a5c;
    --cell-lo: #6fb0ff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-ink: #6fcbf0; --page: #0f1011; --surface: #1a1a19; --surface-2: #17242c; --border: rgba(255, 255, 255, 0.12);
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #9b9991; --ok: #3cc43c; --warn-bg: #4a3d0a; --danger: #ff6b6b;
  --chart-surface: #1a1a19; --chart-grid: #2c2c2a; --chart-axis: #4a4a46; --chart-cell-line: #5d7a8f; --chart-select: rgba(57, 135, 229, 0.22);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #0ca30c; --series-7: #9085e9; --series-8: #e66767;
  --cell-hi: #ff8a5c; --cell-lo: #6fb0ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary); }
body { font-size: 15px; line-height: 1.4; min-height: 100vh; overflow-x: hidden; }
h2 { font-size: 15px; margin: 0 0 8px; }
h3 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; font-weight: normal; }
.hint { color: var(--text-secondary); font-size: 13px; margin: 6px 0; }

.top {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface); border-bottom: 3px solid var(--brand);
  padding-top: max(12px, env(safe-area-inset-top));
}
.logo { height: 16px; width: auto; max-width: 60vw; }
.logo-dark { display: none; font-weight: 800; letter-spacing: 1px; font-size: 20px; }
.logo-dark b { color: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo { display: none; } :root:not([data-theme="light"]) .logo-dark { display: inline; } }
:root[data-theme="dark"] .logo { display: none; }
:root[data-theme="dark"] .logo-dark { display: inline; }
@media (min-width: 700px) { .logo { height: 22px; } }
.pill {
  margin-left: auto; font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw;
}
.pill.on { color: var(--ok); font-weight: 600; }

.tabs {
  display: flex; gap: 2px; padding: 0 8px; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none; position: sticky; top: 0; z-index: 5;
}
.tabs button {
  border: 0; background: none; color: var(--text-secondary); padding: 12px 14px; font: inherit; font-weight: 600;
  border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--brand-ink); border-bottom-color: var(--brand); }

main { padding: 12px 16px 40px; max-width: 1200px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 820px) { .grid2 { grid-template-columns: 1.1fr 1fr; } }

.btn {
  font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 8px; cursor: pointer; min-height: 40px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-primary);
}
.btn:hover:not(:disabled) { border-color: var(--brand); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.warn { background: #b45309; border-color: #b45309; color: #fff; }
.btn.danger { color: var(--danger); }
.btn.active { background: var(--danger); border-color: var(--danger); color: #fff; }

.status { margin: 6px 0; color: var(--text-secondary); font-size: 14px; }
.status.err { color: var(--danger); }
.status.rec { color: var(--danger); font-weight: 600; }
progress { width: 100%; height: 6px; accent-color: var(--brand); }

table.kv { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.kv td { padding: 5px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.kv td:first-child { color: var(--text-secondary); }
table.kv td:last-child { text-align: right; font-weight: 600; word-break: break-word; }

.cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; font-variant-numeric: tabular-nums; }
.cell { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.cell b { font-size: 15px; display: block; }
.cell .d { color: var(--text-muted); font-size: 12px; }
.cell.hi { border-color: var(--cell-hi); box-shadow: inset 3px 0 0 var(--cell-hi); }
.cell.lo { border-color: var(--cell-lo); box-shadow: inset 3px 0 0 var(--cell-lo); }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
label.check { flex-direction: row; align-items: center; gap: 6px; }
input, select { font: inherit; color: var(--text-primary); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px; min-height: 40px; max-width: 100%; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.pair { display: flex; gap: 6px; }
.pair input { width: 80px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 10px; }
.checks label { flex-direction: row; align-items: center; gap: 4px; color: var(--text-primary); font-size: 14px; }
.checks input { min-height: 0; }

details > summary { cursor: pointer; font-weight: 600; }
.series { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; }
.series label { flex-direction: row; align-items: center; gap: 4px; color: var(--text-primary); font-size: 14px; }
.series input { min-height: 0; }

.chart-wrap { position: relative; background: var(--chart-surface); border: 1px solid var(--border); border-radius: var(--radius); }
#chart { display: block; width: 100%; height: min(70vh, 640px); min-height: 320px; touch-action: pan-y; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); max-width: 240px;
  font-variant-numeric: tabular-nums; z-index: 2;
}
.chart-tip .tt-h { display: block; color: var(--text-secondary); margin-top: 6px; font-weight: 600; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.params { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; min-width: 560px; }
table.params th { text-align: left; font-size: 12px; color: var(--text-muted); padding: 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
table.params td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
table.params tr.group td { background: var(--surface-2); font-weight: 700; color: var(--text-primary); }
table.params tr.ro td { color: var(--text-muted); }
table.params tr.edit { cursor: pointer; }
table.params tr.edit:hover td { background: var(--surface-2); }
table.params tr.changed td { background: var(--warn-bg); }
table.params td.new { font-weight: 700; }

.log { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; font: 12px/1.45 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; max-height: 50vh; overflow: auto; }
.log .hit { color: var(--ok); font-weight: 700; }
.log .error { color: var(--danger); }
.log .maybe { color: #b45309; }

dialog { border: 1px solid var(--border); border-radius: 12px; padding: 18px; max-width: min(520px, calc(100vw - 32px)); width: 100%; background: var(--surface); color: var(--text-primary); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
#dlgBody { white-space: pre-wrap; font-size: 14px; color: var(--text-secondary); max-height: 55vh; overflow: auto; }
#dlgInput { width: 100%; margin-top: 12px; font-size: 18px; }
.backup { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
