@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&family=Source+Serif+4:wght@400;600&display=swap");

:root {
  --bg: #f3efe8;
  --ink: #1e1c16;
  --accent: #d65a31;
  --panel: #f1edf6;
  --muted: #6c655d;
  --map-border: #c7bfd2;
  --shadow: 0 18px 40px rgba(37, 33, 28, 0.18);
  --route-mint-dark: #7cbab1;
  --route-mint-base: #94c8c1;
  --route-mint-light: #d5ebe7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #f9f4ea 0%, #efe6d7 45%, #f2ebe1 100%);
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  min-height: 100vh;
  height: 100vh;
}

.panel {
  padding: 36px 28px;
  background: var(--panel);
  border-right: 1px solid #d1cbdb;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-height: 100vh;
  overflow-y: auto;
}

.panel-header {
  display: grid;
  gap: 8px;
}

.panel-brand {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  min-width: 0;
}

.panel-header h1 {
  font-family: "Source Serif 4", serif;
  font-size: 2.2rem;
  margin: 0 0 8px;
}

.brand-logo {
  display: none;
  width: 84px;
  height: auto;
  margin: 0;
  object-fit: contain;
  align-self: start;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.7rem;
  color: var(--muted);
  align-self: center;
}

.subhead {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.mode-btn {
  padding: 9px 8px;
  font-size: 0.76rem;
}

.mode-btn.active {
  background: #b9a7d5;
  border-color: #8569b4;
  color: #1f1430;
}

.mode-btn.active:hover {
  border-color: #744aa8;
}

.radius-control {
  display: grid;
  gap: 8px;
}

.radius-control.is-disabled {
  opacity: 0.62;
}

label {
  font-weight: 600;
  font-size: 0.9rem;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.label-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.help-pop {
  position: relative;
}

.help-pop summary {
  list-style: none;
  width: 20px;
  height: 20px;
  border: 1px solid #ccbbaa;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  background: #fff;
}

.help-pop summary::-webkit-details-marker {
  display: none;
}

.help-pop[open] summary {
  border-color: #c29872;
  color: #6d3f1f;
}

.help-text {
  position: absolute;
  top: 26px;
  right: 0;
  z-index: 4;
  width: 210px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d6c5b4;
  background: #fff8f0;
  box-shadow: 0 8px 20px rgba(33, 27, 20, 0.14);
  font-size: 0.76rem;
  line-height: 1.35;
  color: #5e564f;
}

select,
input[type="date"] {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--map-border);
  font-family: inherit;
  background: #fff;
}

input[type="range"] {
  width: 100%;
}

.city-search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.date-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 400;
}

button {
  border: 1px solid var(--map-border);
  border-radius: 10px;
  background: #fff;
  font-family: inherit;
  font-weight: 600;
  padding: 10px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  color: #888;
  border-color: #d5d5d5;
  background: #f3f3f3;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.result-list,
.example-list {
  display: grid;
  gap: 8px;
}

.example-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.example-list button {
  width: 100%;
}

.example-list button.active {
  background: #b9a7d5;
  border-color: #8569b4;
  color: #1f1430;
}

.example-list button.compare-selected {
  background: #c6b7df;
  border-color: #8569b4;
  color: #1f1430;
}

.compare-toggle-hint {
  margin-top: 2px;
  font-size: 0.75rem;
}

.toggle-guidance {
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid rgba(124, 186, 177, 0.65);
  border-radius: 8px;
  background: rgba(124, 186, 177, 0.18);
  color: #2f6d66;
  font-weight: 600;
  line-height: 1.35;
}

.quick-examples-loading {
  font-size: 0.75rem;
  font-weight: 600;
  color: #5f6d6a;
}

.service-date-loading {
  font-size: 0.75rem;
  font-weight: 600;
  color: #5f6d6a;
  white-space: nowrap;
}

.result-card {
  border: 1px solid var(--map-border);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.result-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.result-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.result-badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
  border: 1px solid transparent;
}

.result-badge.good {
  background: #eaf7ed;
  border-color: #8bcf99;
  color: #226534;
}

.result-badge.bad {
  background: #fff1ef;
  border-color: #e4a69c;
  color: #8f2f21;
}

.result-badge.pending {
  background: #f4f4ee;
  border-color: #c7c7ba;
  color: #54544d;
}

.result-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.result-card button {
  width: 100%;
}

.result-card button.map-loaded {
  background: #b9a7d5;
  border-color: #8569b4;
  color: #1f1430;
}

.result-card button.map-loaded:hover {
  border-color: #744aa8;
}

.result-card button.compare-active {
  background: #ece7f5;
  border-color: #a08cc8;
  color: #3d2f5a;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.range-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.85rem;
}

.range-meta .muted {
  color: var(--muted);
}

.legend {
  display: grid;
  gap: 8px;
}

.legend-title {
  font-weight: 600;
  margin-right: auto;
  font-size: 0.78rem;
}

.legend-units {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.72rem;
}

.legend-range {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.legend-scale {
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-scale.bus {
  background: linear-gradient(90deg, #f5d4a8 0%, #f2a65a 35%, #e85d3f 70%, #7b1f1f 100%);
}

.legend-scale.rail {
  background: linear-gradient(90deg, #c8ddff 0%, #8bb6ff 35%, #4f7ad7 70%, #1d3f8b 100%);
}

.legend-scale.population {
  background: linear-gradient(
    90deg,
    #ece7f2 1%,
    #dcd2e9 2.5%,
    #cabddf 5%,
    #b9a7d5 10%,
    #a993ca 20%,
    #977ec0 30%,
    #8569b4 50%,
    #744aa8 60%,
    #62329a 75%,
    #51248d 85%,
    #451882 90%,
    #3f007d 95%,
    #320065 98%,
    #26004d 100%
  );
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.66rem;
  color: var(--muted);
}

.legend-header .card-collapse {
  margin-left: auto;
}

.stats-header .card-collapse {
  margin-left: auto;
}

.legend-scale-header {
  margin-top: 2px;
}

.legend-ticks {
  letter-spacing: 0.01em;
}

.panel-footer {
  margin-top: auto;
  font-size: 0.85rem;
  color: var(--muted);
}

.map-wrap {
  position: relative;
  padding: 8px;
  height: 100vh;
}

.main-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(243, 239, 232, 0.6);
  pointer-events: none;
}

.main-loading-overlay[hidden] {
  display: none !important;
}

.main-loading-text {
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #3d3948;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #cabfd8;
  border-radius: 12px;
  padding: 12px 18px;
  box-shadow: 0 10px 20px rgba(35, 28, 20, 0.14);
}

.view-tabs {
  position: absolute;
  top: 20px;
  left: 74px;
  z-index: 3;
  display: inline-flex;
  gap: 8px;
  background: rgba(241, 242, 244, 0.9);
  border: 1px solid #d5c5b5;
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 8px 18px rgba(35, 28, 20, 0.12);
}

.view-tab {
  border: 1px solid transparent;
  background: transparent;
  color: #4b4742;
  padding: 7px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.view-tab.active {
  background: #b9a7d5;
  border-color: #8569b4;
  color: #1f1430;
}

.compare-panel {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 14px;
  border: none;
  background: rgba(241, 242, 244, 0.95);
  box-shadow: var(--shadow);
  padding: 74px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* The panel now scrolls vertically — chart on top, custom table beneath.
     Previously this was a 2-row grid with overflow: hidden, which clipped
     anything beyond the chart. */
  overflow-y: auto;
}

.compare-panel[hidden] {
  display: none !important;
}

/* Map cards (stats, legend, sources, recenter button) need to disappear
   when we switch into the compare view — otherwise they sit on top of the
   comparePanel and overlap the explorer card. The original CSS has higher
   specificity than the [hidden] attribute, so force display: none. */
.stats-card[hidden],
.map-legend[hidden],
.map-sources[hidden],
.map-recenter[hidden] {
  display: none !important;
}

.compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compare-head-left {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.compare-status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.compare-status-wrap .toggle-guidance {
  margin-top: 0;
  white-space: nowrap;
  flex: 0 0 auto;
}

.compare-clear {
  font-size: 0.75rem;
  padding: 6px 10px;
}

.compare-status {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compare-charts {
  /* No inner scroll — the parent .compare-panel scrolls now so the chart
     and the table-below appear in one continuous flow. */
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 10px;
  align-content: start;
  padding-right: 2px;
}

/* City filter bar sits between the header and the charts. Two-row layout:
   quick-select buttons + the per-city pill grid. */
.city-filter-bar {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: rgba(185, 167, 213, 0.08);
  border: 1px solid rgba(185, 167, 213, 0.35);
  border-radius: 8px;
}
.city-filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.city-filter-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #4a3e5b;
  margin-right: 8px;
}
.city-filter-quick {
  padding: 3px 9px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #4a3e5b;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid #cbc4d5;
  border-radius: 999px;
  cursor: pointer;
  transition: background 100ms, color 100ms;
}
.city-filter-quick:hover {
  background: #b9a7d5;
  color: #1f1430;
}
.city-filter-quick.is-on {
  background: #6b4f9f;
  color: #f6f1eb;
  border-color: #6b4f9f;
}
.city-filter-quick.is-on:hover {
  background: #5a3d8e;
}
.city-filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.city-filter-pill {
  padding: 3px 9px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  color: #4a3e5b;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid #d2cadc;
  border-radius: 999px;
  cursor: pointer;
  transition: background 100ms, color 100ms, border-color 100ms, opacity 100ms;
}
.city-filter-pill.is-on {
  background: #6b4f9f;
  color: #f6f1eb;
  border-color: #6b4f9f;
  font-weight: 600;
}
.city-filter-pill:not(.is-on) {
  opacity: 0.6;
}
.city-filter-pill:hover { opacity: 1; }

/* Custom table block — lives directly under the chart in the Compare tab.
   Shares the chart's city filter (state.cityIncluded) so changing the
   filter pills above the chart updates both the chart and the table. */
.custom-table-block {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(185, 167, 213, 0.35);
  display: grid;
  gap: 10px;
}
.custom-table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.city-filter-hint {
  margin-left: 6px;
  font-size: 0.7rem;
  color: #6a6573;
  font-style: italic;
}
.table-control-block {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(185, 167, 213, 0.08);
  border: 1px solid rgba(185, 167, 213, 0.35);
  border-radius: 8px;
}
.table-control-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #4a3e5b;
}
.table-col-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 140px;
  overflow-y: auto;
}
.table-col-pill {
  padding: 3px 9px;
  font-family: inherit;
  font-size: 0.72rem;
  color: #4a3e5b;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid #d2cadc;
  border-radius: 999px;
  cursor: pointer;
}
.table-col-pill.is-on {
  background: #6b4f9f;
  color: #f6f1eb;
  border-color: #6b4f9f;
  font-weight: 600;
}
.table-copy-btn {
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #f6f1eb;
  background: #6b4f9f;
  border: 1px solid #6b4f9f;
  border-radius: 6px;
  cursor: pointer;
}
.table-copy-btn:hover { background: #5a3d8e; }
.custom-table-wrap {
  /* No internal scroll — the parent .compare-panel handles vertical scroll
     so chart + table read as one continuous page. Horizontal overflow stays
     on for wide tables (many columns). */
  overflow-x: auto;
}
.custom-table {
  border-collapse: collapse;
  font-family: inherit;
  font-size: 0.82rem;
  width: 100%;
}
.custom-table th,
.custom-table td {
  padding: 6px 12px;
  text-align: right;
  border-bottom: 1px solid rgba(185, 167, 213, 0.25);
  white-space: nowrap;
}
.custom-table th {
  background: rgba(185, 167, 213, 0.18);
  font-weight: 600;
  color: #1f1430;
  position: sticky;
  top: 0;
  text-align: right;
}
.custom-table th:first-child,
.custom-table td:first-child {
  text-align: left;
  font-weight: 500;
}
.custom-table tr.is-selected td { background: rgba(107, 79, 159, 0.10); font-weight: 600; }
.custom-table tr:hover td { background: rgba(185, 167, 213, 0.08); }

.compare-card {
  border: 1px solid #d2cadc;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.82);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.compare-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.compare-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.compare-help .help-text {
  right: 0;
  left: auto;
  width: 230px;
}

.compare-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(120px, 2fr) minmax(50px, auto);
  align-items: center;
  gap: 8px;
}

.compare-city {
  font-size: 0.74rem;
  color: #3f3f46;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compare-track {
  height: 10px;
  border-radius: 999px;
  background: #ece7f2;
  overflow: hidden;
}

.compare-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #dedfe3 0%, #b4a590 58%, #bb6f34 100%);
}

.compare-value {
  text-align: right;
  font-size: 0.72rem;
  color: #3f3f46;
  white-space: nowrap;
}

.compare-scatter-card {
  grid-column: 1 / -1;
  gap: 12px;
}

.explorer-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.explorer-mode-btn {
  border: 1px solid #d3c9df;
  background: #faf7ff;
  color: #4f4a5b;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.explorer-mode-btn.active {
  background: #e9dff9;
  border-color: #b9a5d8;
  color: #463b59;
}

.explorer-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.explorer-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  color: #4f4a5b;
  cursor: pointer;
  user-select: none;
}

.explorer-checkbox input[type="checkbox"] {
  accent-color: #b9a5d8;
  cursor: pointer;
  margin: 0;
}

.explorer-clear-btn {
  border: 1px solid #d3c9df;
  background: #faf7ff;
  color: #4f4a5b;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.explorer-clear-btn:hover {
  background: #f0e8fa;
  border-color: #b9a5d8;
}

.explorer-group-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  color: #4f4a5b;
  user-select: none;
}

.explorer-group-select {
  border: 1px solid #d3c9df;
  background: #faf7ff;
  color: #4f4a5b;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.explorer-group-select:hover {
  border-color: #b9a5d8;
}

.compare-coverage-split-card {
  grid-column: 1 / -1;
  gap: 10px;
}

.coverage-split-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  font-size: 0.72rem;
  color: #625d6d;
}

.coverage-split-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.coverage-split-legend-item .swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.coverage-split-legend-item .swatch.full {
  background: #d6cdea;
}

.coverage-split-legend-item .swatch.frequent {
  background: #d9975f;
}

.coverage-split-overlay-row {
  display: grid;
  grid-template-columns: minmax(110px, auto) minmax(240px, 1fr);
  align-items: center;
  gap: 10px;
}

.coverage-split-city {
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.75rem;
  color: #3f3b48;
  font-weight: 700;
}

.coverage-split-track {
  position: relative;
  height: 13px;
  border-radius: 999px;
  background: transparent;
  border: none;
  overflow: visible;
}

.coverage-split-track.overlay {
  height: 13px;
}

.coverage-split-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

.coverage-split-fill.full {
  background: #d6cdea;
  opacity: 1;
  z-index: 1;
}

.coverage-split-fill.frequent {
  background: linear-gradient(90deg, #f7ddb9 0%, #e8a867 58%, #cf7a3b 100%);
  top: 0;
  bottom: 0;
  box-shadow: 0 0 0 1px rgba(158, 93, 47, 0.16) inset;
  z-index: 2;
}

.coverage-split-fill.frequent::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 1px;
  background: #d6cdea;
  border-top-left-radius: 999px;
  border-top-right-radius: 999px;
}

.coverage-split-value {
  position: absolute;
  font-size: 0.67rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

.coverage-split-value.full {
  top: 50%;
  color: #7058a5;
  transform: translate(4px, -50%);
  z-index: 3;
}

.coverage-split-value.frequent {
  top: 50%;
  color: #7f4f26;
  text-shadow: 0 1px 0 rgba(255, 246, 236, 0.55);
  transform: translate(calc(-100% - 4px), -50%);
  z-index: 3;
}

.coverage-split-value.full.edge-guard {
  transform: translate(calc(-100% - 4px), -50%);
}

.coverage-split-value.frequent.narrow {
  transform: translate(2px, -50%);
}

.scatter-layout {
  display: grid;
  grid-template-columns: minmax(168px, 0.72fr) minmax(440px, 3fr) minmax(168px, 0.72fr);
  grid-template-areas:
    "y plot bubble"
    ". x .";
  gap: 10px;
  align-items: start;
}

.scatter-layout.bar-mode {
  grid-template-columns: minmax(180px, 0.85fr) minmax(440px, 3fr);
  grid-template-areas: "y plot";
}

.scatter-control-slot {
  min-width: 0;
}

.scatter-control-slot.y {
  grid-area: y;
}

.scatter-control-slot.x {
  grid-area: x;
}

.scatter-control-slot.bubble {
  grid-area: bubble;
}

.scatter-control-group {
  margin: 0;
  min-width: 0;
  padding: 8px 10px 10px;
  border: 1px solid #ddd4e6;
  border-radius: 10px;
  background: rgba(253, 252, 255, 0.94);
}

.scatter-control-group legend {
  padding: 0 4px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #504a5c;
}

.scatter-option-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: 246px;
  overflow: auto;
  padding-right: 2px;
}

.scatter-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 0.77rem;
  color: #3f3f46;
}

.scatter-option input {
  margin: 0;
}

.scatter-option span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scatter-control-slot.x .scatter-option-list {
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  max-height: none;
}

.scatter-plot-wrap {
  grid-area: plot;
  min-height: 360px;
  border: 1px solid #ddd4e7;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 8px 4px;
  display: grid;
  gap: 6px;
}

.scatter-layout.bar-mode .scatter-plot-wrap {
  min-height: 0;
}

.scatter-mapping {
  font-size: 0.8rem;
  color: #5a5662;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compare-data-note {
  margin-top: -2px;
  padding: 7px 9px;
  border: 1px solid rgba(185, 167, 213, 0.34);
  border-radius: 7px;
  background: rgba(185, 167, 213, 0.10);
  color: #5a5364;
  font-size: 0.74rem;
  line-height: 1.35;
}

.explorer-bar-rows {
  display: grid;
  gap: 8px;
}

.explorer-bar-row {
  padding-top: 2px;
}

.compare-scatter-svg {
  width: 100%;
  height: auto;
  max-height: 820px;
  display: block;
}
.compare-scatter-svg figure { margin: 0; }
.compare-scatter-svg svg { font-family: inherit; }
/* Observable Plot's built-in tip mark — restyle to match the
   parchment + lavender palette used elsewhere in the app. */
.compare-scatter-svg [aria-label="tip"] rect {
  fill: rgba(255, 255, 255, 0.97);
  stroke: rgba(38, 38, 51, 0.22);
  rx: 4;
}
.compare-scatter-svg [aria-label="tip"] text { fill: #1f1430; }

.scatter-grid-line {
  stroke: #e7e2ee;
  stroke-width: 1;
}

.scatter-axis-line {
  stroke: #9d97aa;
  stroke-width: 1.1;
}

.scatter-tick-label {
  fill: #5e5a66;
  font-size: 12px;
  dominant-baseline: middle;
}

.scatter-axis-label {
  fill: #3f3c48;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.scatter-point-label {
  fill: #3f3b48;
  font-size: 11px;
  pointer-events: none;
  paint-order: stroke fill;
  stroke: rgba(246, 241, 235, 0.92);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* Short explanation under the "Color stations by" dropdown — updates per
   selected option (see COLOR_BY_DESCS in app.js). */
.color-by-desc {
  margin-top: 6px;
  padding: 8px 10px;
  background: rgba(185, 167, 213, 0.10);
  border-left: 2px solid #b9a7d5;
  border-radius: 0 4px 4px 0;
  font-size: 0.74rem;
  line-height: 1.4;
  color: #4a3e5b;
}
.color-by-desc:empty { display: none; }
.color-by-desc strong { color: #1f1430; }

/* Shared custom hover tooltip — single element driven by wireChartTooltip().
   Mirrors station-density's .app-tooltip styling for visual consistency
   across the sibling projects. Used on the scatter dots; replaces the OS
   default title= bubble so the chart popup matches the rest of the app. */
.app-tooltip {
  position: fixed;
  z-index: 9999;
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(38, 38, 51, 0.22);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.45;
  color: #1f1430;
  pointer-events: none;
  max-width: 320px;
  white-space: pre-line;
  text-align: left;
  opacity: 0;
  transition: opacity 140ms ease;
}
.app-tooltip:not([hidden]) { opacity: 1; }
.app-tooltip[hidden] { display: none; }
.app-tooltip strong { color: #1f1430; }

.scatter-point-label-selected {
  fill: #1f1430;
  font-weight: 700;
  font-size: 12.5px;
  stroke-width: 3.5px;
}

.scatter-point-selected {
  filter: drop-shadow(0 0 4px rgba(31, 20, 48, 0.45));
}

.scatter-empty {
  align-self: center;
  justify-self: center;
  font-size: 0.78rem;
  color: #5b5764;
  padding: 28px 8px;
}

.map-wrap .map-legend,
.map-wrap .stats-card,
.map-wrap .map-sources {
  pointer-events: auto;
}

#map {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  border: none;
  overflow: hidden;
  box-shadow: var(--shadow);
}


/* Hover tooltip — frosted lavender card. Visual spec adapted from the
   Leaflet `.leaflet-tooltip` style on the user's request. The MapLibre
   tooltip is just a positioned div, so we apply the same look here. */
.tooltip {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -120%);
  border: 1px solid #c7bfd2;
  border-radius: 10px;
  background: rgba(241, 237, 246, 0.95);
  color: #1e1c16;
  box-shadow: 0 12px 24px rgba(35, 28, 20, 0.18);
  padding: 10px 12px;
  font-family: "Space Grotesk", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
  font-size: 12.5px;
  line-height: 1.45;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  max-width: 280px;
}

.popup-name {
  font-size: 13.5px;
  font-weight: 700;
  color: #1e1c16;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(30, 28, 22, 0.08);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0;
}

.popup-row strong {
  font-weight: 400;
  color: #6c655d;
  font-size: 12px;
  letter-spacing: 0.01em;
}

.popup-row span {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.popup-flag {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(30, 28, 22, 0.08);
  color: #b03a2e;
  font-weight: 600;
  font-size: 12px;
}

/* Line popup — small colour swatch beside the line name, a "shared track"
   header when a segment carries two lines, and a divider between the per-line
   blocks. */
.popup-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: baseline;
  border: 1px solid rgba(30, 28, 22, 0.25);
}

.popup-shared {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a6d3b;
  margin-bottom: 6px;
}

.popup-line + .popup-line {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(30, 28, 22, 0.12);
}

.route-popup-wrap .maplibregl-popup-content {
  padding: 0;
  border-radius: 12px;
  background: transparent;
  border: none;
  box-shadow: none;
}

.route-popup-wrap .maplibregl-popup-tip {
  border-top-color: #eef1f4;
}

.route-popup {
  min-width: 300px;
  max-width: 410px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(238, 241, 244, 0.98);
  border: 1px solid #c8d0d8;
  box-shadow: 0 12px 24px rgba(35, 28, 20, 0.18);
  display: grid;
  gap: 8px;
}

.route-popup-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: #2f2e35;
}

.route-popup-sub {
  font-size: 0.72rem;
  color: #5e6570;
}

.route-popup-meta {
  font-size: 0.74rem;
  color: #4d4955;
  line-height: 1.35;
  text-align: center;
  justify-self: center;
  max-width: 100%;
}

.route-popup-meta-label {
  font-weight: 700;
}

.route-popup-empty {
  font-size: 0.72rem;
  color: #5c5864;
}

.route-popup-chart {
  display: grid;
  gap: 6px;
  padding: 4px 6px 2px 6px;
}

.route-popup-chart-body {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: stretch;
}

.route-popup-y-axis {
  height: 96px;
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  align-items: center;
  justify-items: end;
  color: #717a85;
}

.route-popup-y-tick {
  font-size: 0.62rem;
  line-height: 1;
}

.route-popup-bars-area {
  position: relative;
  height: 96px;
  padding: 4px 8px 0 2px;
  box-sizing: border-box;
}

.route-popup-grid {
  display: none;
}

.route-popup-grid-line {
  display: none;
}

.route-popup-bars {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(24, minmax(2px, 1fr));
  align-items: end;
  gap: 2px;
}

.route-popup-bar-col {
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.route-popup-bar {
  width: 100%;
  min-height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--route-mint-dark);
  opacity: 0.95;
}

.route-popup-bar.is-zero {
  opacity: 0.28;
}

.route-popup-axis {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px 0 40px;
  font-size: 0.62rem;
  color: #6d6975;
}

.map-sources {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 2;
  width: auto;
  max-width: min(60vw, 720px);
  padding: 8px 14px;
  font-size: 0.68rem;
  color: #3f3f46;
  gap: 2px;
  line-height: 1.35;
  display: grid;
  justify-items: center;
  text-align: center;
  pointer-events: auto;
  background: rgba(246, 241, 235, 0.82);
  border: 1px solid rgba(185, 167, 213, 0.45);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.map-sources .map-source-feed {
  color: #6a6573;
  font-size: 0.66rem;
}

.stats-card {
  position: absolute;
  right: 20px;
  top: 20px;
  z-index: 2;
  min-width: 210px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #cbc4d5;
  background: rgba(241, 237, 246, 0.95);
  box-shadow: 0 10px 24px rgba(35, 28, 20, 0.16);
  backdrop-filter: none;
  overflow: visible;
  display: grid;
  gap: 6px;
}

/* Distance-from-centre analysis card — bottom-right, mirrors the stats card. */
.center-card {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 2;
  width: 300px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #d9c3b3;
  background: rgba(246, 241, 235, 0.96);
  box-shadow: 0 10px 24px rgba(35, 28, 20, 0.16);
  display: grid;
  gap: 8px;
}
.center-card[hidden] { display: none; }
.center-card .stats-title { color: #b04a1e; }
.center-summary {
  font-size: 12px;
  line-height: 1.45;
  color: #3a322b;
}
.center-summary strong { color: #b04a1e; }
.center-hist { width: 100%; }
.center-hist svg { display: block; width: 100%; height: auto; }
.center-legend {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: #6b6157;
}
.center-legend i.cl-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: -1px;
}

/* Centrality-ring labels drawn as MapLibre HTML markers (km labels + the
   centre dot's city name). Terracotta to match the dashed rings. */
.cbd-ring-text {
  font: 700 10px var(--font-sans, "Space Grotesk", sans-serif);
  letter-spacing: 0.02em;
  color: #b04a1e;
  white-space: nowrap;
  pointer-events: none;
  text-shadow:
    0 0 3px #f6f1eb, 0 0 3px #f6f1eb, 0 0 2px #f6f1eb, 0 0 2px #f6f1eb;
}
.cbd-center-text {
  font: 600 11px var(--font-sans, "Space Grotesk", sans-serif);
  color: #b04a1e;
  white-space: nowrap;
  pointer-events: none;
  padding: 0 4px;
  background: rgba(246, 241, 235, 0.82);
  border-radius: 3px;
  transform: translateX(8px);
}

.map-legend {
  position: absolute;
  left: 20px;
  bottom: 20px;
  z-index: 2;
  width: 360px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #d5c5b5;
  background: rgba(241, 242, 244, 0.95);
  box-shadow: 0 10px 24px rgba(35, 28, 20, 0.16);
  backdrop-filter: blur(2px);
}

/* Scale "yardstick" above the legend — a thin black line with two end ticks
   and a distance label. Width is set live (JS) from the zoom; sits just
   outside/above the legend card. */
.scalebar {
  position: absolute;
  left: 20px;
  z-index: 2;
  pointer-events: none;
  font-family: "Space Grotesk", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
}
.scalebar-label {
  display: block;
  font-size: 11px;
  line-height: 1.2;
  color: #1e1c16;
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}
.scalebar-ruler {
  height: 6px;
  border: 1px solid #000;
  border-top: none;
  box-sizing: border-box;
}

.map-recenter {
  position: absolute;
  left: 20px;
  bottom: 244px;
  z-index: 2;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #cdbfcf;
  background: rgba(241, 237, 246, 0.95);
  color: #606a75;
  box-shadow: 0 8px 16px rgba(35, 28, 20, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.map-recenter::before {
  content: "";
  width: 15px;
  height: 15px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23606a75' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 2L11 13'/%3E%3Cpath d='M22 2L15 22L11 13L2 9L22 2Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.map-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-card-content {
  display: grid;
  gap: 8px;
}

.map-card.is-collapsed .map-card-content {
  display: none;
}

.card-collapse {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1;
}

.stats-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-bottom: 2px;
}

.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
}

.stats-note {
  margin-top: -2px;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid rgba(185, 167, 213, 0.34);
  background: rgba(185, 167, 213, 0.10);
  color: #5a5364;
  font-size: 0.7rem;
  line-height: 1.35;
}

.stats-label {
  white-space: nowrap;
}

.stats-value-help {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-left: auto;
}

.stat-help summary {
  width: 16px;
  height: 16px;
  font-size: 0.65rem;
  line-height: 1;
  padding: 0;
  /* re-state grid centering so the "?" sits dead-center inside the smaller
     box (the parent .help-pop summary uses display: grid; place-items: center,
     but resizing without these can drift the glyph). */
  display: grid;
  place-items: center;
}

.stat-help summary::marker { content: ""; }

.stat-help .help-text {
  right: 0;
  left: auto;
  width: 220px;
  z-index: 12;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .panel {
    border-right: none;
    border-bottom: 2px solid var(--map-border);
    max-height: none;
    overflow-y: visible;
  }

  .map-wrap {
    height: auto;
    padding: 6px;
  }

  .main-loading-text {
    font-size: 1.1rem;
    padding: 10px 14px;
  }

  .view-tabs {
    top: 14px;
    left: 62px;
  }

  .compare-panel {
    inset: 0;
    padding: 62px 14px 14px;
  }

  .compare-head-left {
    display: grid;
    gap: 2px;
  }

  .compare-status {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .compare-status-wrap {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 4px;
  }

  .compare-status-wrap .toggle-guidance {
    white-space: normal;
  }

  .compare-charts {
    grid-template-columns: 1fr;
  }

  .coverage-split-overlay-row {
    grid-template-columns: minmax(86px, auto) minmax(110px, 1fr);
    gap: 8px;
  }

  .coverage-split-city {
    max-width: 86px;
    font-size: 0.72rem;
  }

  .coverage-split-value {
    font-size: 0.65rem;
  }

  .scatter-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "y"
      "plot"
      "x"
      "bubble";
  }

  .scatter-layout.bar-mode {
    grid-template-columns: 1fr;
    grid-template-areas:
      "y"
      "plot";
  }

  .scatter-option-list {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .scatter-control-slot.x .scatter-option-list {
    grid-template-columns: 1fr;
  }

  .scatter-plot-wrap {
    min-height: 300px;
  }

  .compare-scatter-svg {
    height: 300px;
  }

  #map {
    height: 70vh;
    border-radius: 12px;
  }

  .stats-card {
    right: 20px;
    top: 20px;
    min-width: 190px;
  }

  .map-legend {
    left: 20px;
    bottom: 20px;
    width: 290px;
  }

  .map-recenter {
    left: 20px;
    bottom: 224px;
  }

  .map-sources {
    left: 50%;
    bottom: 16px;
    transform: translateX(-12%);
    max-width: 58vw;
  }
}

.ghost {
  background: #f7f1e8;
  border-color: #e0d4c6;
  color: #6c655d;
}

.ghost:hover {
  border-color: #c8b8a8;
}

/* ===== Metro Graph additions ===== */

.city-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #d5c5b5;
  background: #fff;
  font-size: 0.85rem;
  color: #2d2a25;
}

.about-link {
  display: inline-block;
  color: #8569b4;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.about-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ===== Comparison-tab presets + dropdown controls ===== */

.compare-preset-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.compare-preset-label {
  font-size: 0.78rem;
  color: #6c655d;
  font-weight: 600;
}

.compare-preset-select {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #d5c5b5;
  border-radius: 8px;
  background: #fff;
  font-size: 0.85rem;
  color: #2d2a25;
}

.compare-controls-row {
  display: grid;
  /* Four dropdowns: X / Y / Bubble / Color — all equal-width on one row
     so they read as a single control strip. Previously a 3-column grid
     pushed "Color" onto a wrapped second row, breaking visual alignment. */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 4px 0 8px;
}

@media (max-width: 1024px) {
  .compare-controls-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 640px) {
  .compare-controls-row {
    grid-template-columns: 1fr;
  }
}

.compare-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.compare-control-label {
  font-size: 0.72rem;
  color: #6c655d;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.compare-control-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d5c5b5;
  border-radius: 8px;
  background: #fff;
  font-size: 0.82rem;
  color: #2d2a25;
}

.compare-log-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: #5a5364;
  font-size: 0.72rem;
  line-height: 1.2;
  cursor: pointer;
}

.compare-log-toggle[hidden] {
  display: none;
}

.compare-log-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: #8569b4;
}

.compare-class-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #efe7d8;
}

.compare-class-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: #4b4742;
}

/* ── Compare-view sidebar / chrome ────────────────────────────────────────
   When the user switches to the Network comparison tab, the body gets
   `.is-compare`. Map-specific control groups hide; the comparison-only
   "What this view shows" block reveals. */
body.is-compare .control-group.map-only { display: none; }
body:not(.is-compare) .control-group.compare-only { display: none; }

.compare-desc-title {
  font-family: "Source Serif 4", "Source Serif Pro", serif;
  font-size: 1rem;
  font-weight: 600;
  color: #1e1c16;
  margin: 4px 0 8px;
  line-height: 1.3;
}
.compare-desc-body {
  font-size: 0.85rem;
  line-height: 1.5;
  color: #3a342d;
  display: grid;
  gap: 8px;
}
.compare-desc-paragraph {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.55;
}
.compare-desc-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px 10px;
  align-items: baseline;
  font-size: 0.82rem;
  line-height: 1.45;
}
.compare-desc-row-label {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #4a3e5b;
  font-size: 0.72rem;
  text-transform: uppercase;
}
.compare-desc-row-body { color: #3a342d; }
.compare-desc-reading {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed #e3dccf;
}
.compare-desc-reading .compare-desc-row-label { color: #6b4f9f; }
.compare-desc-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed #e3dccf;
  font-size: 0.74rem;
  color: #6c655d;
}
.compare-desc-source-label {
  font-weight: 600;
  color: #6c655d;
  margin-right: 2px;
}
.compare-desc-source {
  color: #8569b4;
  text-decoration: none;
  border-bottom: 1px dotted rgba(133, 105, 180, 0.5);
}
.compare-desc-source:hover {
  text-decoration: underline;
  border-bottom-color: transparent;
}

/* ── Compare-card chart title (echoes the preset label above the plot) ── */
.compare-chart-title {
  margin: 8px 0 4px;
  padding: 0;
  font-family: "Source Serif 4", "Source Serif Pro", serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e1c16;
  letter-spacing: 0.005em;
}

/* ── Slightly tighter typography across the compare card ────────────────
   Tones the whole panel down a notch from the default 0.9rem so the chart
   reads as the primary thing. */
.compare-card {
  font-size: 0.78rem;
}
.compare-card .compare-title { font-size: 0.85rem; }
.compare-card .compare-preset-label { font-size: 0.74rem; }
.compare-card .compare-preset-select { font-size: 0.78rem; }
.compare-card .compare-control-label { font-size: 0.7rem; }
.compare-card .compare-control-select { font-size: 0.76rem; }
.compare-card .scatter-mapping { font-size: 0.72rem; }
.compare-card .scatter-tick-label,
.compare-card .scatter-axis-label { font-size: 10px; }
.compare-card .scatter-point-label { font-size: 8.5px; }

/* Move the (X / Y / Bubble / Color) controls row to sit BELOW the chart
   instead of above it. Just margin tuning — DOM order does the work. */
.compare-controls-bottom {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed #e3dccf;
}

/* Continuous color-ramp legend (shown when the user picks a real metric in
   the "Color by" dropdown instead of the topology-class default). */
.compare-color-ramp {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  font-size: 0.74rem;
  color: #4b4742;
}
.compare-ramp-label {
  font-weight: 600;
  color: #2d2a25;
  white-space: nowrap;
}
.compare-ramp-end {
  font-variant-numeric: tabular-nums;
  color: #6c655d;
  white-space: nowrap;
  min-width: 40px;
}
.compare-ramp-end:first-of-type { text-align: right; }
.compare-ramp-bar {
  flex: 1;
  height: 10px;
  border-radius: 4px;
  border: 1px solid rgba(46, 33, 22, 0.10);
  display: block;
  min-width: 80px;
}

/* The scatter-plot-wrap originally lived inside .scatter-layout (a CSS grid
   with grid-area: plot). Now that we lay controls out vertically, drop the
   stale grid-area and stretch the wrap + SVG across the card. */
.scatter-plot-wrap.full-width {
  margin-top: 4px;
  grid-area: auto;
  width: 100%;
  display: block;
  padding: 12px 16px;
}

.scatter-plot-wrap.full-width .compare-scatter-svg {
  width: 100%;
  height: auto;          /* let viewBox 0 0 900 420 dictate aspect ratio */
  display: block;
  margin: 0 auto;
}

.stats-more {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #e5dfd5;
}

.stats-more summary {
  cursor: pointer;
  font-size: 0.72rem;
  color: #6a625a;
  list-style: none;
  padding: 4px 0;
}

.stats-more[open] summary {
  margin-bottom: 6px;
}

.legend-body {
  display: grid;
  gap: 6px;
}

.legend-line-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 4px 8px;
  font-size: 0.72rem;
}

.legend-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.legend-range-inline {
  font-size: 0.72rem;
  color: #6c655d;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.legend-line-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.legend-swatch.tiny {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
}

.legend-swatch.tiny {
  border-color: rgba(0, 0, 0, 0.18);
}
