:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #fcfcfb;
  --border: #e3e2dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6d6c67;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #c23b3a;
  --series-1: #2a78d6; /* principal — validated pair (light) */
  --series-2: #eb6834; /* interest */
  --grid: #ebeae5;
  --axis: #b9b8b1;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 2px 8px rgb(0 0 0 / 4%);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2d2d2b;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9c9b93;
    --accent: #3987e5;
    --danger: #e66767;
    --series-1: #3987e5; /* validated pair (dark) */
    --series-2: #d95926;
    --grid: #262624;
    --axis: #4a4a47;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h1, h2 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }
.js .nojs-only { display: none; }
html:not(.js) .js-only { display: none; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 16px; }
.account { display: flex; align-items: center; gap: 14px; font-size: .925rem; min-width: 0; }
.account > a { white-space: nowrap; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who img { border-radius: 50%; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14ch; }
form.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
@media (max-width: 560px) { .who-name { display: none; } .account { gap: 10px; } }

/* ---- layout ---- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 8px; }
.page-title { font-size: 1.5rem; margin: 4px 0 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .grid { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); } }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; min-width: 0;
}
.grid > .card { margin-bottom: 0; }
.grid { margin-bottom: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.flash { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); padding: 10px 14px; border-radius: 10px; margin: 0 0 16px; }

/* ---- form ---- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > label, .field > legend { font-weight: 600; font-size: .925rem; padding: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input, select {
  width: 100%; min-width: 0; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-height: 44px;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.affix { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); overflow: hidden; }
.affix:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.affix input { border: 0; border-radius: 0; background: transparent; outline: none; }
.affix-label { display: flex; align-items: center; padding: 0 12px; color: var(--text-2); background: color-mix(in srgb, var(--border) 45%, transparent); white-space: nowrap; font-size: .925rem; }
.hint { margin: 0; min-height: 1.3em; font-size: .85rem; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-ghost { background: transparent; color: var(--accent); }
.btn-small { min-height: 34px; padding: 0 12px; font-size: .875rem; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.save { display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--border); padding-top: 14px; flex-wrap: wrap; }
.save input { flex: 1 1 180px; }
.save p { margin: 0; font-size: .925rem; }

/* ---- results ---- */
.results { display: flex; flex-direction: column; gap: 10px; }
.error { margin: 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--danger); color: var(--danger); }
.stale { opacity: .45; }
.hero-label { margin: 0; color: var(--text-2); font-weight: 600; }
.hero { margin: 0 0 8px; font-size: clamp(2rem, 7vw, 2.75rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; overflow-wrap: anywhere; }
.stats { margin: 0; display: grid; gap: 0; }
.stats > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.stats dt { color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.stats dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.stats .total dd { font-size: 1.1rem; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }
.split { display: flex; gap: 2px; height: 10px; border-radius: 5px; overflow: hidden; margin-top: 4px; }
.split-p { background: var(--series-1); flex: 1 1 0; }
.split-i { background: var(--series-2); flex: 1 1 0; }
.results .small { margin: 0; }

/* ---- chart ---- */
.legend { list-style: none; margin: 0; padding: 0; display: flex; gap: 14px; font-size: .875rem; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.chart { position: relative; width: 100%; min-height: 260px; }
.chart svg { display: block; max-width: 100%; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .col.active .hit { fill: color-mix(in srgb, var(--text) 5%, transparent); }
.chart-tip {
  position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 14%); padding: 8px 10px; font-size: .85rem; min-width: 190px;
  display: flex; flex-direction: column; gap: 3px;
}
.tip-sub { color: var(--muted); font-size: .8rem; margin-bottom: 2px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { margin-left: auto; padding-left: 12px; font-weight: 600; }

/* ---- tables ---- */
.table-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 8px; }
.table-wrap.tall { max-height: none; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 600; z-index: 1; }
tbody tr:last-child td { border-bottom: 0; }
.schedule tbody tr:nth-child(12n) td { border-bottom-color: var(--axis); }
.saved td:first-child { white-space: normal; min-width: 12ch; }
.saved .actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { text-align: center; padding: 40px 18px; }
.empty p { color: var(--text-2); }

.foot { max-width: 1120px; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: .8rem; }
