/* Reference dataviz palette — light values on :root, dark under the media
   query, so the whole app swaps with the OS setting. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  overflow: hidden;
}
#app { position: relative; }
#map { position: absolute; inset: 0; background: var(--page); }

/* ---------------- top bar ---------------- */
#chrome-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  pointer-events: none;
}
#chrome-top > * { pointer-events: auto; }
#topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: 0.2px; white-space: nowrap; }
.muted { color: var(--muted); font-size: 12px; }
#stats { display: flex; gap: 14px; flex-wrap: wrap; }
#stats .stat { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
#stats .stat b { font-size: 14px; font-weight: 650; color: var(--ink); }

#search {
  font: inherit; font-size: 12px; color: var(--ink);
  background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; width: 130px;
}
#search:focus { outline: none; border-color: var(--accent); }
.seg { display: flex; background: var(--page); border-radius: 8px;
  padding: 3px; gap: 3px; border: 1px solid var(--border); }
.seg button {
  font: inherit; font-size: 12px; color: var(--ink-2);
  background: none; border: none; border-radius: 6px;
  padding: 3px 10px; cursor: pointer;
}
.seg button.active { background: var(--grid); color: var(--ink); }
.seg button:disabled { opacity: 0.4; cursor: default; }
.seg button.loading { opacity: 0.6; cursor: progress;
  background-image: linear-gradient(90deg, transparent 0 40%, var(--grid) 50%, transparent 60% 100%);
  background-size: 200% 100%; animation: seg-loading 1s linear infinite; }
@keyframes seg-loading { from { background-position: 200% 0; } to { background-position: -200% 0; } }
#cluster-run, #layout-run {
  font: inherit; font-size: 12px; color: var(--ink-2);
  background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 8px; max-width: 260px;
}
#cluster-run:focus, #layout-run:focus { outline: none; border-color: var(--accent); }

/* ---------------- legend chip row ---------------- */
#legend {
  list-style: none; margin: 0; padding: 6px 10px;
  display: flex; flex-wrap: wrap; gap: 6px;
  pointer-events: none;
}
#legend li {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 10px; border-radius: 999px; cursor: pointer;
  color: var(--ink-2); font-size: 12px;
  background: var(--surface-1); border: 1px solid var(--border);
}
#legend li:hover { border-color: var(--accent); }
#legend li.off { opacity: 0.4; }
#legend .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; }
#legend .n { color: var(--muted); font-size: 11px;
  font-variant-numeric: tabular-nums; }

/* ---------------- bottom dock ---------------- */
#dock {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
}
#scrubber {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px;
}
#play {
  font: inherit; width: 28px; height: 28px; flex: none; cursor: pointer;
  color: var(--ink); background: none;
  border: 1px solid var(--border); border-radius: 50%;
}
#play:hover { border-color: var(--accent); }
#time { flex: 1; accent-color: var(--accent); }
#time-label {
  font-size: 12px; color: var(--ink-2); min-width: 140px; text-align: right;
  font-variant-numeric: tabular-nums;
}
#credits { font-size: 11px; color: var(--muted); white-space: nowrap; }
#credits a { color: inherit; }
@media (max-width: 760px) { #credits { display: none; } }
#analytics-toggle {
  font: inherit; font-size: 12px; color: var(--ink-2); cursor: pointer;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 12px; white-space: nowrap;
}
#analytics-toggle:hover, #analytics-toggle.open { border-color: var(--accent); color: var(--ink); }

#drawer {
  max-height: 44vh; overflow-y: auto;
  padding: 14px 16px 6px;
  border-bottom: 1px solid var(--border);
}
#drawer[hidden] { display: none; }
#drawer h2 {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--ink-2); margin: 0 0 8px;
}
.chart-sec { margin-bottom: 14px; }
.lists { display: grid; grid-template-columns: 1fr 1.2fr 0.9fr; gap: 24px; }
.lists section { min-width: 0; }

.chart svg { display: block; width: 100%; }
.chart { position: relative; }
.chart .tip {
  position: absolute; pointer-events: none; transform: translate(-50%, -110%);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 8px; font-size: 12px; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.chart .tip b { font-weight: 650; }

.list { width: 100%; border-collapse: collapse; font-size: 13px; }
.list td { padding: 3px 4px; border-top: 1px solid var(--grid); }
.list td.num {
  text-align: right; color: var(--ink-2);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.list td.rank { color: var(--muted); width: 22px;
  font-variant-numeric: tabular-nums; }
.list td.name { max-width: 240px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.list .sub { color: var(--muted); font-size: 11px; }
.list tr.link { cursor: pointer; }
.list tr.link:hover td { background: var(--grid); }

/* ---------------- hover card ---------------- */
#hover-card {
  position: absolute; z-index: 10; pointer-events: none; width: 240px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}
#hover-card .head { display: flex; gap: 10px; align-items: center; }
#hover-card img {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--grid);
}
#hover-card .name { font-weight: 650; }
#hover-card .cluster { font-size: 11px; display: flex; align-items: center;
  gap: 5px; color: var(--ink-2); }
#hover-card .cluster .swatch { width: 8px; height: 8px; border-radius: 50%; }
#hover-card .tags { color: var(--muted); font-size: 11px; margin-top: 6px; }
#hover-card .stats { font-size: 12px; color: var(--ink-2); margin-top: 6px;
  display: flex; justify-content: space-between; }
#hover-card svg { display: block; width: 100%; margin-top: 6px; }
#hover-card .sp-hint { color: var(--muted); font-size: 10px; margin-top: 5px; }

#status {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; z-index: 20; text-align: center;
  color: var(--ink-2); background: var(--page); padding: 0 40px;
}
#status[hidden] { display: none; }
#status code {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px;
}

@media (max-width: 900px) {
  .lists { grid-template-columns: 1fr; }
  #time-label { min-width: 0; }
}
