:root {
  --bg: #0b0e11;
  --bg2: #12161c;
  --bg3: #1a2029;
  --panel: #141a22;
  --border: #243041;
  --border2: #2e3d52;
  --text: #e6edf5;
  --muted: #8b9bb0;
  --dim: #5c6b7f;
  --accent: #3dd6c6;
  --accent2: #5b8cff;
  --warn: #f0b429;
  --danger: #f07178;
  --ok: #6bcb77;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius: 8px;
  --topbar-h: 44px;
  --stats-h: 58px;
  --sidebar-w: 240px;
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 13px;
}
a { color: var(--accent); }
button, select, input {
  font: inherit; color: var(--text);
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 6px; padding: 5px 9px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.active {
  background: rgba(61, 214, 198, 0.15);
  border-color: var(--accent); color: var(--accent);
}

/* ---- First screen: exact viewport ---- */
.viewport {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px; flex-wrap: nowrap;
  padding: 6px 12px;
  min-height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 8px; flex-shrink: 0; }
.brand h1 {
  margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand .tag {
  color: var(--dim); font-family: var(--mono); font-size: 10px;
  white-space: nowrap;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--bg3); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 340px;
}
.pill .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex-shrink: 0;
}
.pill.warn .dot { background: var(--warn); }
.controls {
  display: flex; gap: 6px; flex-wrap: nowrap; margin-left: auto; align-items: center;
  overflow-x: auto;
}
.controls label { color: var(--muted); font-size: 10px; white-space: nowrap; }
.controls button { padding: 4px 8px; font-size: 12px; white-space: nowrap; }

.stats-strip {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 1px; background: var(--border);
  border-bottom: 1px solid var(--border);
  max-height: var(--stats-h);
  overflow: hidden;
}
.stat {
  background: var(--bg2); padding: 6px 10px;
  min-width: 0;
}
.stat .k { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { font-family: var(--mono); font-size: 15px; font-weight: 600; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .u { color: var(--dim); font-size: 10px; margin-left: 3px; font-weight: 400; }
.stat .s { color: var(--dim); font-size: 9px; margin-top: 1px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  overflow: hidden;
}
.sidebar {
  background: var(--bg2); border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
  padding: 6px 0;
  min-height: 0;
}
.sidebar h2 {
  margin: 8px 12px 4px; font-size: 9px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--dim); font-weight: 600;
}
.layer {
  display: flex; align-items: flex-start; gap: 7px;
  padding: 4px 12px; cursor: pointer; user-select: none;
}
.layer:hover { background: rgba(255,255,255,0.03); }
.layer input { margin-top: 2px; accent-color: var(--accent); }
.layer .meta { min-width: 0; }
.layer .name { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.layer .src { color: var(--dim); font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer.unavailable { opacity: 0.45; }
.layer .badge {
  font-size: 8px; padding: 1px 4px; border-radius: 4px;
  background: rgba(240,180,41,0.15); color: var(--warn); border: 1px solid rgba(240,180,41,0.3);
}
.legend-hint { color: var(--dim); font-size: 10px; padding: 0 12px 8px; }

.chart-stage {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  overflow: hidden;
  background: var(--bg);
}
.chart-toolbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.chart-toolbar .hint { color: var(--dim); font-size: 10px; margin-left: auto; }
.chart-toolbar button { font-size: 11px; padding: 3px 8px; }

/* Fullscreen root = chart + optional layer overlay */
.fs-root {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.fs-root:fullscreen,
.fs-root:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background: var(--bg);
}
.fs-root:fullscreen .fs-layers,
.fs-root:-webkit-full-screen .fs-layers {
  display: flex;
}
.fs-layers {
  display: none;
  position: absolute;
  top: 8px; left: 8px;
  z-index: 5;
  max-height: calc(100% - 16px);
  width: 260px;
  flex-direction: column;
  background: rgba(18, 22, 28, 0.96);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
  overflow: hidden;
}
.fs-layers.open { display: flex; }
.fs-layers-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
}
.fs-layers-body {
  overflow-y: auto; padding: 4px 0;
  flex: 1 1 auto;
}
.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}
#mainChart {
  width: 100%;
  height: 100%;
}
.chart-empty {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none;
}

.scroll-cue {
  flex: 0 0 auto;
  text-align: center;
  padding: 3px 8px;
  font-size: 10px;
  color: var(--dim);
  background: var(--bg2);
  border-top: 1px solid var(--border);
}
.scroll-cue a { color: var(--muted); text-decoration: none; }
.scroll-cue a:hover { color: var(--accent); }

@media (max-width: 960px) {
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(140px, 28%) 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .brand .tag { display: none; }
  .pill { max-width: 160px; }
}

/* ---- Below fold: panels + footer (page scroll) ---- */
.below {
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.panels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px; background: var(--border);
}
@media (max-width: 1100px) {
  .panels { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .panels { grid-template-columns: 1fr; }
}
.panel {
  background: var(--panel); padding: 12px 14px; min-height: 160px;
}
.panel h3 {
  margin: 0 0 8px; font-size: 12px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.panel h3 .src { color: var(--dim); font-weight: 400; font-size: 10px; }
.panel .body { color: var(--muted); }
.panel .big {
  font-family: var(--mono); font-size: 28px; color: var(--text); font-weight: 600;
}
.panel .sub { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 4px; }
.panel .row {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 4px 0; border-bottom: 1px solid rgba(36,48,65,0.6);
  font-family: var(--mono); font-size: 12px;
}
.panel .row span:first-child { color: var(--muted); }
.placeholder-box {
  border: 1px dashed var(--border2); border-radius: var(--radius);
  padding: 14px; background: rgba(240,180,41,0.04);
}
.placeholder-box .status { color: var(--warn); font-weight: 600; margin-bottom: 6px; }
.placeholder-box .hint { color: var(--dim); font-size: 11px; line-height: 1.45; }
#seenChart, #spreadChart { width: 100%; height: 140px; }
.footer {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between;
  padding: 8px 16px; background: var(--bg2); border-top: 1px solid var(--border);
  color: var(--dim); font-size: 10px; line-height: 1.4;
}
.footer strong { color: var(--muted); font-weight: 500; }
