:root {
  --ink: #f6fbff;
  --muted: #a8b7c8;
  --panel: rgba(8, 15, 25, 0.82);
  --panel-strong: rgba(9, 18, 31, 0.94);
  --line: rgba(255, 255, 255, 0.16);
  --cyan: #58d8ff;
  --green: #78e08f;
  --amber: #ffd166;
  --coral: #ff6b6b;
  --violet: #a78bfa;
  --black: #05080d;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 20%, rgba(88, 216, 255, 0.14), transparent 24rem),
    radial-gradient(circle at 82% 78%, rgba(255, 107, 107, 0.12), transparent 22rem),
    #07101b;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 620px;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #07101b;
}

.leaflet-control-attribution {
  color: rgba(224, 238, 255, 0.78);
  background: rgba(4, 8, 13, 0.72);
  backdrop-filter: blur(8px);
}

.leaflet-control-attribution a {
  color: var(--cyan);
}

.control-panel,
.rank-panel,
.legend,
.source-strip {
  position: absolute;
  z-index: 500;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px) saturate(130%);
}

.control-panel {
  top: 20px;
  left: 20px;
  width: min(390px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  padding: 18px;
  overflow: auto;
}

.brand-block {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.panel-kicker,
.field-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
  text-transform: uppercase;
}

.brand-block h1 {
  margin: 4px 0 0;
  max-width: 14ch;
  font-size: clamp(2rem, 5vw, 3.35rem);
  line-height: 0.92;
}

.field-label {
  display: block;
  margin: 18px 0 8px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

.search-box svg {
  width: 18px;
  height: 18px;
  margin-left: 13px;
  color: var(--cyan);
  flex: 0 0 auto;
}

.search-box input {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  padding: 0 14px 0 10px;
  color: var(--ink);
  background: transparent;
}

.suggestions {
  display: none;
  margin-top: 6px;
  max-height: 210px;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.suggestions.is-open {
  display: block;
}

.suggestion {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 9px 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.suggestion:hover,
.suggestion:focus-visible {
  outline: 0;
  background: rgba(88, 216, 255, 0.12);
}

.suggestion span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.mode-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  cursor: pointer;
}

.mode-toggle svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.mode-toggle input:checked + span {
  border-color: rgba(88, 216, 255, 0.62);
  color: var(--ink);
  background: rgba(88, 216, 255, 0.17);
}

.range-block {
  margin-top: 18px;
}

.range-block > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.range-block .field-label {
  margin: 0;
}

output {
  color: var(--amber);
  font-size: 0.9rem;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  margin-top: 12px;
  accent-color: var(--cyan);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.stats-grid div {
  min-height: 78px;
  padding: 12px 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
}

.stats-grid span {
  display: block;
  color: var(--green);
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}

.stats-grid small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.25;
}

.detail-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(88, 216, 255, 0.16), transparent 45%),
    rgba(255, 255, 255, 0.06);
}

.detail-panel h2,
.rank-heading h2 {
  margin: 4px 0 0;
  font-size: 1.08rem;
  line-height: 1.2;
}

.detail-panel p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.route-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 9px;
  color: var(--black);
  background: var(--amber);
  font-size: 0.78rem;
  font-weight: 900;
}

.rank-panel {
  right: 20px;
  bottom: 20px;
  width: min(360px, calc(100vw - 40px));
  max-height: min(500px, calc(100vh - 40px));
  padding: 16px;
  overflow: hidden;
}

.rank-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  outline: 0;
  border-color: rgba(88, 216, 255, 0.7);
  background: rgba(88, 216, 255, 0.16);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.city-ranking {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 400px;
  overflow: auto;
}

.city-ranking li + li {
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.rank-button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  border: 0;
  padding: 10px 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.rank-button:hover,
.rank-button:focus-visible {
  outline: 0;
  color: var(--cyan);
}

.rank-button strong {
  display: block;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.rank-button small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.rank-time {
  align-self: center;
  color: var(--amber);
  font-weight: 900;
  white-space: nowrap;
}

.legend {
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.legend span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

#legendSwatches {
  display: flex;
  gap: 7px;
}

.swatch {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 800;
}

.swatch::before {
  content: "";
  display: block;
  width: 18px;
  height: 10px;
  background: var(--swatch);
}

.source-strip {
  left: 20px;
  bottom: 20px;
  max-width: min(720px, calc(100vw - 420px));
  padding: 9px 12px;
  color: rgba(230, 239, 255, 0.74);
  font-size: 0.75rem;
}

.city-dot {
  border: 0;
  border-radius: 999px;
  box-shadow:
    0 0 0 1px rgba(5, 8, 13, 0.7),
    0 0 18px var(--dot-glow);
}

.origin-pulse {
  width: 18px;
  height: 18px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow:
    0 0 0 8px rgba(88, 216, 255, 0.18),
    0 0 28px rgba(88, 216, 255, 0.9);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  color: var(--ink);
  background: var(--panel-strong);
}

.leaflet-popup-content {
  margin: 12px;
}

.leaflet-popup-content strong {
  display: block;
  margin-bottom: 4px;
}

@media (max-width: 920px) {
  .app-shell {
    min-height: 760px;
  }

  .control-panel {
    top: 12px;
    left: 12px;
    width: calc(100vw - 24px);
    max-height: 45vh;
    padding: 14px;
  }

  .brand-block h1 {
    max-width: none;
    font-size: 2rem;
  }

  .rank-panel {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
    max-height: 30vh;
  }

  .legend {
    top: auto;
    right: 12px;
    bottom: calc(30vh + 26px);
  }

  .source-strip {
    display: none;
  }
}

@media (max-width: 560px) {
  .mode-row,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .legend {
    display: none;
  }
}
