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

body {
  font-family: sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 20px 24px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

h2 {
  margin: 20px;
  font-size: 40px;
}

select {
  padding: 10px 50px 10px 12px;
  border: 1px solid #e2ebf7;
  border-radius: 8px;
  background-color: rgb(2, 107, 159);
  font-size: 30px;
  color: white;

  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='28' viewBox='0 0 20 20' width='28' xmlns='http://www.w3.org/2000/svg'><path d='M5 7l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

#map {
  flex: 1 1 auto;
  min-height: 0;
}

/* Leaflet icon container */

.bus-leaflet-icon {
  background: transparent !important;
  border: none !important;
}

/* wrapper allowing rotation */

.bus-wrap {
  width: var(--bus-width);
  height: var(--bus-height);
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
}

/* SVG bus */

.bus-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* bus body */

.bus-shadow {
  fill: rgba(0, 0, 0, 0.18);
}

.bus-body {
  fill: var(--bus-color, #2563eb);
  stroke: #ffffff;
  stroke-width: 5;
}

/* windows */

.bus-window {
  fill: rgba(255, 255, 255, 0.9);
}

/* mid detail */

.bus-detail {
  fill: rgba(255, 255, 255, 0.92);
}

/* wheels */

.bus-wheel {
  fill: #1f2937;
}

/* smooth rotation */

.leaflet-marker-pane .leaflet-marker-icon {
  transition: transform 0.35s linear;
}

/* disable transition during zoom animation */

.leaflet-zoom-anim .leaflet-marker-pane .leaflet-marker-icon {
  transition: none;
}

/* nicer map style */

.leaflet-tile-pane {
  filter: brightness(1.15) saturate(0.55) grayscale(0.2);
}

/* ---------- LOADING OVERLAY ---------- */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.6s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  color: #374151;
  font-size: 15px;
  font-weight: 500;
}

.loading-road {
  position: relative;
  width: 260px;
  height: 64px;
  background: #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

/* Solid centre dividing line separating the two lanes */
.loading-road::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  margin-top: -1px;
  background: white;
  z-index: 1;
}


.loading-bus {
  position: absolute;
  width: 16px;
  height: 42px;
  z-index: 2;
}

.loading-bus svg {
  width: 100%;
  height: 100%;
}

/* Blue bus: bottom lane (right-hand traffic), going left → right */
.loading-bus--blue {
  top: 75%;
  transform: translateY(-50%) rotate(90deg);
  animation: bus-drive-right 1.8s linear infinite;
}

/* Green bus: top lane, going right → left, offset so they cross mid-road */
.loading-bus--green {
  top: 25%;
  transform: translateY(-50%) rotate(-90deg);
  animation: bus-drive-left 1.8s linear infinite;
  animation-delay: -0.9s; /* half-period offset so they meet in the middle */
}

@keyframes bus-drive-right {
  from { left: -30px; }
  to   { left: 275px; }
}

@keyframes bus-drive-left {
  from { left: 275px; }
  to   { left: -30px; }
}

.loading-text-wrap {
  width: 260px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 8px 0;
}

.loading-text {
  margin: 0;
  display: inline-block;
  white-space: nowrap;
  padding: 0 260px 0 0;
  animation: text-scroll 8s linear infinite;
}

@keyframes text-scroll {
  from { transform: translateX(260px); }
  to   { transform: translateX(-100%); }
}

/* ---------- LEGEND ---------- */

.bus-legend {
  background: rgba(255, 255, 255, 0.96);
  padding: 12px 14px;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  line-height: 1.4;
  min-width: 110px;
  max-height: 220px;
  overflow-y: auto;
}

@media (max-width: 340px) {
  .loading-road {
    width: 200px;
  }
  .loading-text-wrap {
    width: 200px;
  }
  @keyframes bus-drive-right {
    from { left: -30px; }
    to   { left: 215px; }
  }
  @keyframes bus-drive-left {
    from { left: 215px; }
    to   { left: -30px; }
  }
  @keyframes text-scroll {
    from { transform: translateX(200px); }
    to   { transform: translateX(-100%); }
  }
}

@media (max-width: 600px) {
  .bus-legend {
    font-size: 11px;
    padding: 6px 8px;
    max-height: 120px;
    min-width: 70px;
    opacity: 0.85;
  }

  .legend-row {
    gap: 5px;
    margin-top: 4px;
  }

  .legend-color {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
  }
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

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