@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;
  --btn-active-bg: #b9a7d5;
  --btn-active-border: #8569b4;
  --btn-active-text: #1f1430;
  --btn-active-hover-border: #744aa8;
}

* {
  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;
}

.access-mode-toggle {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.mode-btn.active {
  background: var(--btn-active-bg);
  border-color: var(--btn-active-border);
  color: var(--btn-active-text);
}

.mode-btn.active:hover {
  border-color: var(--btn-active-hover-border);
}

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

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

.area-btn.active {
  background: var(--btn-active-bg);
  border-color: var(--btn-active-border);
  color: var(--btn-active-text);
}

.area-btn.active:hover {
  border-color: var(--btn-active-hover-border);
}

.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 auto;
  gap: 8px;
}

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

.accessibility-controls {
  border-top: 1px solid #dfd7e7;
  padding-top: 14px;
}

.access-departure-row {
  grid-template-columns: 1fr auto;
}

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

#accessStatus {
  min-height: 34px;
  line-height: 1.35;
}

.pick-origin-btn {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pick-icon {
  font-size: 1.1em;
}
#accessPickOriginBtn.is-arming {
  background: var(--btn-active-bg);
  border-color: var(--btn-active-border);
  color: var(--btn-active-text);
}

.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: var(--btn-active-bg);
  border-color: var(--btn-active-border);
  color: var(--btn-active-text);
}

.example-list button.compare-selected {
  background: #c6b7df;
  border-color: var(--btn-active-border);
  color: var(--btn-active-text);
}

.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;
}

.accessibility-tip {
  position: absolute;
  top: 62px;
  left: 74px;
  z-index: 3;
  font-size: 0.78rem;
  text-align: left;
  white-space: nowrap;
  padding: 5px 12px;
  pointer-events: none;
  max-width: calc(100% - 148px);
  box-sizing: border-box;
}

.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: var(--btn-active-bg);
  border-color: var(--btn-active-border);
  color: var(--btn-active-text);
}

.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);
}
.about-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  color: #2f6d66;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 6px;
  font-weight: 600;
}
.about-link:hover {
  color: #226534;
}
.about-modal[hidden] { display: none; }

.about-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: aboutFadeIn 180ms ease-out;
}

@keyframes aboutFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.about-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
}
.about-modal-card {
  position: relative;
  width: 520px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  padding: 28px 28px 24px;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.about-modal-card h3 {
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 700;
}
.about-modal-card h4 {
  margin: 16px 0 6px;
  font-size: 0.9rem;
  font-weight: 700;
}
.about-modal-card ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 10px;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--muted);
}
.about-modal-card strong { color: var(--ink); }
.about-modal-card a {
  color: var(--accent);
}
.about-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--map-border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms;
}
.about-modal-close:hover { background: var(--hover); }
.about-contact {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--map-border);
  font-size: 0.78rem;
  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 10px;
  font-size: 0.8rem;
  border-radius: 8px;
  white-space: nowrap;
}

.view-tab.active {
  background: var(--btn-active-bg);
  border-color: var(--btn-active-border);
  color: var(--btn-active-text);
}

.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: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  overflow: hidden;
}

.compare-panel[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 {
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 10px;
  align-content: start;
  padding-right: 2px;
}

.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: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.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;
}

.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;
}

.poi-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.stats-value-bold {
  font-size: 0.78rem;
  font-weight: 600;
}

.access-score {
  font-size: 0.85rem;
  font-weight: 700;
}

.access-score-row {
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding-top: 4px;
  margin-top: 2px;
}

.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;
}

/* === Chart containers (d3-rendered SVG charts) === */
.plot-container {
  width: 100%;
  min-height: 40px;
  margin-top: 4px;
}

.plot-container svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* === d3 dumbbell chart (population coverage: full vs frequent) === */
.coverage-dumbbell-svg {
  font-family: inherit;
  color: #4a4654;
  overflow: visible;
}

.dumbbell-city-label {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 400;
  fill: #6c655d;
}

.dumbbell-tick-label {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.92rem;
  fill: #6e6878;
}

/* Footnote styled like the panel subhead text ("Compare accessibility and
   opportunity indicators across selected cities.") — regular weight, muted
   color, line-height 1.5. Smaller than body but not italic. */
.coverage-dumbbell-footnote {
  margin-top: 10px;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--muted);
  max-width: 720px;
}

.dumbbell-axis-title {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.78rem;
  fill: #6e6878;
}

.dumbbell-value-label {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  pointer-events: none;
}

.dumbbell-value-label.freq {
  fill: #b65f24;
}

.dumbbell-value-label.full {
  fill: #5e4995;
}

/* Legacy vanilla-SVG dumbbell styles (kept for reference until we decide
   whether to keep the Plot version) === */
.coverage-dot-axis {
  position: relative;
  height: 18px;
  margin: 6px 0 8px 130px;
  font-size: 0.78rem;
  color: #6e6878;
}

.coverage-dot-tick {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.coverage-dot-row {
  display: grid;
  grid-template-columns: minmax(110px, auto) minmax(280px, 1fr);
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

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

.coverage-dot-track {
  position: relative;
  height: 30px;
}

.coverage-dot-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: rgba(214, 205, 234, 0.4);
}

.coverage-dot-connector {
  position: absolute;
  top: 50%;
  height: 3px;
  margin-top: -1.5px;
  background: linear-gradient(90deg, #cf7a3b 0%, #9a6da8 100%);
  border-radius: 999px;
  z-index: 1;
}

.coverage-dot {
  position: absolute;
  top: 50%;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.coverage-dot.full {
  background: #7058a5;
  z-index: 2;
}

.coverage-dot.freq {
  background: #cf7a3b;
  z-index: 3;
}

.coverage-dot-value {
  position: absolute;
  top: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
}

/* Frequent label: always to the LEFT of its dot. The INNER_LO/INNER_HI
   remapping in renderCoverageSplitChart guarantees enough room. */
.coverage-dot-value.freq {
  color: #b65f24;
  transform: translate(calc(-100% - 11px), -50%);
}

/* Full label: always to the RIGHT of its dot. */
.coverage-dot-value.full {
  color: #5e4995;
  transform: translate(11px, -50%);
}

/* When the two dots collide, stack labels vertically so numbers stay readable. */
.coverage-dot-value.above {
  transform: translate(-50%, -180%);
}

.coverage-dot-value.below {
  transform: translate(-50%, 80%);
}

.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;
}

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

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

.compare-scatter-svg {
  width: 100%;
  height: 340px;
  display: block;
}

.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: 12px;
  pointer-events: none;
}

.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);
}

.tooltip {
  position: absolute;
  background: rgba(124, 186, 177, 0.92);
  color: #f4fffc;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  pointer-events: none;
  transform: translate(-50%, -120%);
  white-space: pre-line;
  line-height: 1.3;
}

.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: 20px;
  transform: translateX(-10%);
  z-index: 2;
  width: auto;
  max-width: min(42vw, 560px);
  padding: 0;
  font-size: 0.68rem;
  color: #3f3f46;
  gap: 4px;
  line-height: 1.3;
  display: grid;
  text-align: left;
  pointer-events: none;
}

.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;
}

.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);
}

.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-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;
}

.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;
}

.poi-toggle {
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  padding: 2px 4px;
  margin: -2px -4px;
  transition: opacity 0.15s ease;
}

.poi-toggle:hover {
  background: rgba(0, 0, 0, 0.04);
}

.poi-toggle.poi-cat-dimmed {
  opacity: 0.3;
}

.poi-toggle.poi-cat-dimmed .stats-label {
  text-decoration: line-through;
}
