:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --border: #d9d9de;
  --text: #1c1c1e;
  --muted: #6b6b72;
  --accent: #3155ab;
  --grid-line: rgba(0, 0, 0, 0.08);
  --zero-line: rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

main {
  padding: 22px 32px 40px 32px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 22px 18px 22px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  max-width: 1880px;
  margin: 0 auto;
}

/* ── Main chart grid ─────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 0.40fr) minmax(0, 0.33fr) minmax(0, 0.27fr);
  gap: 18px;
  align-items: stretch;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.panel-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  text-align: center;
}

.scatter-panel svg {
  width: 100%;
  height: 620px;
  background: #fff;
}
.scatter-zoom {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 0 8px;
}
.scatter-zoom label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.scatter-zoom #zoom-value {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.scatter-zoom input[type="range"] {
  flex: 1 1 auto;
  accent-color: var(--accent);
  max-width: 220px;
}

.metrics-panel {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  min-height: 620px;
}
.metric-subpanel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.metric-subpanel .panel-title {
  margin-bottom: 2px;
  text-align: left;
  padding-left: 55px;
}
.metric-svg {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

/* ── Heatmap ─────────────────────────────────────────────────────── */

.heatmap-panel { justify-content: flex-start; }

#heatmap-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

#heatmap-grid {
  display: grid;
  gap: 0;
  width: 100%;
  aspect-ratio: 1 / 1;
  font-size: 11px;
}
#heatmap-grid .hm-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.7);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: background-color 0.12s ease, color 0.12s ease;
}
#heatmap-grid .hm-label {
  font-size: 10px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 2px 4px;
  white-space: nowrap;
  border: 0;
}
#heatmap-grid .hm-label.col {
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 9.5px;
}

#heatmap-colorbar {
  position: relative;
  display: grid;
  grid-template-columns: 14px auto;
  grid-template-rows: auto 1fr auto;
  column-gap: 4px;
  height: 100%;
  min-height: 260px;
  min-width: 44px;
}
#heatmap-colorbar-title {
  grid-column: 1 / span 2;
  grid-row: 1;
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 2px;
}
#heatmap-colorbar-gradient {
  grid-column: 1;
  grid-row: 2;
  width: 14px;
  background: linear-gradient(
    to bottom,
    rgb(103, 0, 31),
    rgb(178, 24, 43),
    rgb(214, 96, 77),
    rgb(244, 165, 130),
    rgb(253, 219, 199),
    rgb(247, 247, 247),
    rgb(209, 229, 240),
    rgb(146, 197, 222),
    rgb(67, 147, 195),
    rgb(33, 102, 172),
    rgb(5, 48, 97)
  );
  border: 1px solid var(--border);
}
#heatmap-colorbar-ticks {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 9.5px;
  color: var(--muted);
  padding: 1px 0;
}

/* ── SVG element styles ──────────────────────────────────────────── */

.axis-label {
  font-size: 10.5px;
  fill: var(--muted);
}
.axis-title {
  font-size: 11px;
  fill: var(--muted);
  font-weight: 500;
}
.tick-line {
  stroke: var(--grid-line);
  stroke-width: 1;
}
.zero-line {
  stroke: var(--zero-line);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}
.grid-line {
  stroke: var(--grid-line);
  stroke-width: 1;
}
.metric-series {
  fill: none;
  stroke-width: 1.5;
}
.metric-series-marker {
  stroke: none;
}
.cursor-line {
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.stage-band-label {
  font-size: 8.5px;
  font-weight: 600;
  text-anchor: middle;
}

.pair-line {
  stroke-width: 1;
  stroke-dasharray: 4 3;
  opacity: 0.4;
}
.centroid-marker {
  stroke: #000;
  stroke-width: 0.8;
}
.centroid-label {
  font-size: 9.5px;
  pointer-events: none;
}
.origin-star {
  stroke: #000;
  stroke-width: 1;
}

/* ── Controls ────────────────────────────────────────────────────── */

.controls {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}
.slider-row label {
  font-size: 12px;
  color: var(--text);
  min-width: 170px;
  font-weight: 500;
}
.slider-row input[type="range"] {
  flex: 1 1 auto;
  accent-color: var(--accent);
}

.ckpt-slider-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  padding: 0 10px;
}
.ckpt-stage-track {
  display: flex;
  height: 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.ckpt-stage-track .stage-seg {
  height: 100%;
  border-right: 1px solid rgba(0, 0, 0, 0.25);
}
.ckpt-stage-track .stage-seg:last-child { border-right: 0; }

.ckpt-slider-wrap input[type="range"] {
  width: 100%;
  margin: 2px 0 0 0;
  accent-color: var(--accent);
}

.ckpt-stage-labels {
  position: relative;
  height: 34px;
  margin-top: 2px;
}
.stage-tick-label {
  position: absolute;
  top: 2px;
  transform: translateX(-50%) rotate(-35deg);
  transform-origin: center top;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
}
.stage-tick-label::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -8px;
  width: 1px;
  height: 6px;
  background: rgba(0, 0, 0, 0.35);
}
#ckpt-value {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}
.stage-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  background: #eef;
  color: #333;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 4px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding-top: 8px;
  font-size: 11px;
  color: var(--muted);
}
.legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.legend .legend-swatch {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
}
.legend .legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid #000;
}

/* ── Plot explanations ───────────────────────────────────────────── */

.explanations {
  max-width: 1880px;
  margin: 24px auto 0 auto;
  padding: 0 4px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
}
.explanations h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px 0;
  color: var(--text);
}
.explanations h4 {
  font-size: 12.5px;
  font-weight: 600;
  margin: 14px 0 4px 0;
  color: var(--text);
}
.explanations p {
  margin: 0 0 6px 0;
  color: var(--muted);
}
.explanations code {
  background: #eef0f4;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}
