html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: Arial;
  background: #111;
  color: white;
}

#map {
  height: 100vh;
  height: 100dvh; /* mobile browsers: real visible viewport, updates as chrome shows/hides */
  width: 100%;
}

#map.search-cursor {
  cursor: url('../assets/magnifying.png') 12 12, zoom-in;
}

#topbar {
  position: fixed;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  border-radius: 50px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
  z-index: 9000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 50px;
}

#topbar > * {
  display: flex;
  align-items: center;
  height: 32px;
}

#topbar > .hidden {
  display: none;
}

#topbar input[type="text"],
#topbar input:not([type="checkbox"]) {
  height: 32px;
  box-sizing: border-box;
}

.traffic-label[data-target] {
  cursor: pointer;
}

.icon-toggle {
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.icon-toggle:hover {
  opacity: 0.7;
}

.icon-toggle.active {
  opacity: 1;
}

.traffic-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  gap: 4px;
  color: #333;
}

.traffic-label img,
.toolbar-icon {
  width: 32px;
  height: auto;
}

.traffic-label img {
  margin-right: 16px;
}

#stopSearchWrapper {
  width: 200px;
}

#stopSearchInput {
  width: 100%;
  height: 32px;
  padding: 0 28px 0 10px;
  box-sizing: border-box;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f9f9f9;
  color: #000;
  font-size: 12px;
}

#stopSearchInput:hover {
  border-color: #333;
  background: #f0f0f0;
}

#stopSearchInput::placeholder {
  color: #999;
}

#stopSearchSuggestions:empty {
  display: none;
}

#clearStopSearch {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: none;
}

#clearStopSearch:hover {
  color: #000;
}

.stop-search-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
}

.stop-search-item:last-child {
  border-bottom: none;
}

.stop-search-name {
  font-size: 13px;
  color: #111;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bus-wrapper {
  position: relative;
  width: 151px;
  display: flex;
  align-items: center;
}

#busRoute {
  width: 100%;
  height: 32px;
  padding: 0 28px 0 10px;
  box-sizing: border-box;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f9f9f9;
  color: #000;
  font-size: 13px;
}

#busRoute:hover {
  border-color: #333;
  background: #f0f0f0;
}

#busRoute::placeholder {
  color: #999;
}

#busSuggestions:empty {
  display: none;
}

#clearBus {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: none;
}

#clearBus:hover {
  color: #000;
}

.suggestions {
  margin: 0;
  padding: 0;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #ffffff;
  color: #000000;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  overflow-y: auto;
}

.suggestions div {
  padding: 10px;
  cursor: pointer;
  color: #000000;
  font-size: 13px;
  transition: background 0.15s ease;
}

.suggestions div:hover {
  background: #e5e7eb;
}

#railSuggestions:not(.mobile-sheet) {
  max-height: min(400px, 60vh);
}

.rail-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 6px;
  vertical-align: middle;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: #2C3E50;
  border-radius: 50%;
  animation: rail-spin 0.8s linear infinite;
}

@keyframes rail-spin {
  to { transform: rotate(360deg); }
}

#riverSelect {
  width: 155px;
}

.tube-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.tube-select-box {
  background: #f9f9f9;
  color: #666;
  border: 1px solid #666;
  border-radius: 8px;
  padding: 0 28px 0 10px;
  height: 32px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  width: 185px;
  box-sizing: border-box;
  overflow: hidden;
}

.tube-select-box:hover {
  border-color: #333;
  background: #f0f0f0;
}

#tubeSuggestions div {
  transition: filter 0.15s ease;
}

#tubeSuggestions div:hover {
  filter: brightness(85%);
}

#clearTube,
#clearRiver,
#clearOverground,
#clearRail {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: none;
}

#clearTube:hover,
#clearRiver:hover,
#clearOverground:hover,
#clearRail:hover {
  color: #000;
}

.select-active {
  transform: scale(1.02);
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.35);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.status-focus {
  transform: scale(1.02);
  box-shadow: 0 0 0 2px rgba(0,120,212,0.35);
  border-radius: 6px;
  transition: all 0.2s ease;
}

#info-button {
  position: fixed;
  bottom: 20px;
  left: 15px;
  right: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  color: #333;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  font-size: 18px;
  overflow: hidden;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
}

#info-button:hover {
  background: #f0f0f0;
}

#info-panel {
  color: #000;
  position: fixed;
  bottom: 75px;
  left: 15px;
  right: auto;
  width: 350px;
  max-width: 90vw;
  background: #ffffff;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  z-index: 10000;
}

.hidden {
  display: none;
}

.panel-content {
  padding: 15px;
  color: #444;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.panel-content h3 {
  margin-top: 0;
  font-size: 16px;
  font-weight: 600;
}

.panel-content p {
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0;
}

#close-btn {
  float: right;
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: #666;
}

#close-btn:hover {
  color: #000;
}

#status-button {
  position: fixed;
  bottom: 20px;
  left: 65px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  overflow: hidden;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
}
#status-button:hover { background: #f0f0f0; }

#status-panel {
  color: #000;
  position: fixed;
  bottom: 75px;
  left: 15px;
  width: min(600px, calc(100vw - 30px));
  max-height: 60vh;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  z-index: 10000;
}

#status-close-btn {
  float: right;
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: #666;
}
#status-close-btn:hover { color: #000; }

#status-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.status-tab {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #888;
  padding: 8px 4px 10px 4px;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-tab:hover {
  color: #333;
}

.status-tab.active {
  color: #0078d4;
}

.status-tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: #0078d4;
  border-radius: 2px 2px 0 0;
}

#bus-status-search {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  box-sizing: border-box;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f9f9f9;
  color: #000;
  font-size: 13px;
  margin-bottom: 8px;
}

#bus-status-search:hover {
  border-color: #333;
  background: #f0f0f0;
}

.bus-status-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}

.bus-status-row:hover {
  background: #f7f7f7;
}

.bus-status-badge {
  flex-shrink: 0;
  min-width: 36px;
  max-width: 90px;
  height: auto;
  min-height: 26px;
  border-radius: 3px;
  background: #e31b23;
  color: #fff;
  font-weight: bold;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.15;
  padding: 4px 4px;
  word-break: break-word;
}

#bus-status-list .bus-status-badge {
  font-size: 14px;
  min-width: 42px;
}

.bus-status-empty {
  padding: 20px 12px;
  text-align: center;
  color: #666;
  font-size: 13px;
}

#status-countdown.warning {
  color: #E32017 !important;
  font-weight: 600;
}

#status-countdown.flash {
  animation: flashPulse 0.6s ease;
}

@keyframes flashPulse {
  0%   { opacity: 1; transform: scale(1); }
  50%  { opacity: 0.3; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}

.status-row-highlight {
  animation: statusRowHighlight 1.6s ease;
}

@keyframes statusRowHighlight {
  0%   { background-color: rgba(0, 120, 212, 0.18); }
  100% { background-color: transparent; }
}

.leaflet-tooltip {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 10px;
  width: max-content;
  min-width: 120px;
  max-width: min(400px, 90vw);
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
  text-align: left;
}

.leaflet-tooltip .camera-title {
  font-size: 14px;
  font-weight: 600;
  color: #111;
  margin-bottom: 4px;
}

.leaflet-tooltip .camera-road {
  font-size: 12px;
  color: #555;
}

.leaflet-popup-content-wrapper {
  border: 1px solid #ddd;
  border-radius: 6px;
  max-width: min(600px, 95vw) !important;
}

.leaflet-popup-content {
  margin: 12px;
  max-width: 100% !important;
  overflow-x: hidden;
}

.leaflet-popup-content:has(.bus-stop-popup),
.leaflet-popup-content:has(.station-arrivals-popup),
.leaflet-popup-content:has(.vehicle-journey-popup) {
  margin: 0;
}

.camera-popup {
  width: min(495px, 85vw);
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}

.leaflet-popup-content:has(.camera-popup) {
  overflow: hidden !important;
}

.leaflet-popup-content:has(.camera-popup).leaflet-popup-scrolled {
  overflow: hidden !important;
}

.leaflet-popup-content-wrapper:has(.camera-popup) {
  overflow: hidden;
}

.camera-title {
  font-family: Arial, sans-serif;
  font-size: 15px;
  font-weight: bold;
  color: #111;
  margin-bottom: 4px;
}

.camera-road {
  font-family: Arial, sans-serif;
  font-size: 12px;
  color: #888;
  margin-bottom: 8px;
}

.camera-video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: calc(100vh - 200px);
  object-fit: contain;
  border-radius: 6px;
}

.camera-refresh {
  margin-top: 8px;
  margin-bottom: -5px;
  font-size: 12px;
  color: #888;
}

.countdown {
  font-size: 12px;
  color: #888;
}

/* =====================================================
   Location
   FIX: values below reduced ~25% from the original 32/30/16px
   (wrapper/arrow, pulse, dot) to shrink the marker directly, rather
   than continuing to chase a CSS-override theory — the sister project
   uses IDENTICAL 32/30/16 values yet renders visibly smaller, which
   only makes sense if the two projects were being compared at
   different effective tile zoom/label sizes rather than genuinely
   different marker code. This directly shrinks the marker regardless
   of that. If it still needs to shrink further, adjust the four
   px values below (wrapper/arrow 24, pulse 22, dot 12) AND the
   matching iconSize/iconAnchor in js/location.js's locationIcon
   L.divIcon call — those two must always stay in sync or the icon
   will render off-center.
   ===================================================== */

.user-location-marker {
  pointer-events: none;
}

.location-wrapper {
  position: relative;
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.location-pulse {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(26, 115, 232, 0.15);
  animation: pulse 2.2s infinite ease-out;
  transform-origin: center;
  pointer-events: none;
}

.location-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #1a73e8;
  border: 2px solid white;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px rgba(0,0,0,0.3);
  z-index: 2;
  pointer-events: none;
}

@keyframes pulse {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(4.0);
    opacity: 0;
  }
}

/* Kept at the ORIGINAL 32px size (not shrunk with the dot/pulse/
   wrapper above) — the arrow is a directional glyph that needs to
   stay legible at a glance while navigating; shrinking it along with
   the passive stationary dot made it hard to read at a glance.
   Deliberately sized/centred independently of .location-wrapper's
   now-smaller 24px box: absolute positioning + translate(-50%,-50%)
   still centres it correctly on the same coordinate regardless of the
   wrapper's own dimensions, since the wrapper is just a positioning
   context here, not a clipping box. */
.location-arrow {
  position: absolute;
  width: 32px;
  height: 32px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(0deg);
  transform-origin: center center;
  transition: transform 0.25s ease;
  display: none;
  pointer-events: none;
  z-index: 2;
}

.location-arrow svg {
  display: block;
  width: 32px;
  height: 32px;
}

.location-wrapper.is-navigating .location-dot,
.location-wrapper.is-navigating .location-pulse {
  display: none;
}

.location-wrapper.is-navigating .location-arrow {
  display: block;
}

.user-location-marker.location-stale {
  opacity: 0.45;
  filter: grayscale(40%);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.user-location-marker.location-paused {
  opacity: 0.35;
  filter: grayscale(70%);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.geo-btn {
  position: fixed;
  bottom: 20px;
  right: 15px;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  z-index: 9999;
  width: 40px;
  height: 40px;
  background: #fff;
  border: none;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  transition: background-color 0.2s;
}

.geo-btn:hover {
  background: #f0f0f0;
}

.geo-btn img {
  width: 26px;
  height: 26px;
  display: block;
}

.geo-btn.tracking img {
  filter: invert(34%) sepia(87%) saturate(2971%) hue-rotate(205deg) brightness(101%) contrast(105%);
}

.live-status {
  position: fixed;
  right: 15px;
  bottom: 70px;
  bottom: max(70px, calc(env(safe-area-inset-bottom, 20px) + 50px));
  width: auto;
  max-width: 200px;
  z-index: 9999;
  font-size: 13px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-status.hidden {
  display: none;
}

.live-stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.live-stat-row:empty {
  display: none;
  cursor: default;
}

.live-stat-row:hover .live-stat-icon {
  background: #cfe8ff;
}

.live-stat-icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e5f1ff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #007AFF;
}

.live-stat-icon svg {
  width: 15px;
  height: 15px;
}

.live-stat-value {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a1a;
}

@media (max-width: 600px) {
  .live-status {
    max-width: calc(100vw - 32px);
  }
}

.mobile-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10040;
}

.suggestions.mobile-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  width: 100%;
  max-height: 70vh;
  border-radius: 16px 16px 0 0;
  z-index: 10050;
  box-shadow: 0 -6px 18px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.suggestions > .mobile-sheet-header {
  position: sticky;
  top: 0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 15px;
  color: #111;
  border-bottom: 1px solid #eee;
  cursor: default;
  flex-shrink: 0;
}

.suggestions > .mobile-sheet-header:hover {
  background: #fff;
}

.mobile-sheet-close {
  border: none;
  background: none;
  font-size: 20px;
  color: #666;
  cursor: pointer;
  padding: 4px 8px;
}

.mobile-sheet-close:hover {
  color: #000;
}

.suggestions.mobile-sheet div:not(.mobile-sheet-header) {
  padding: 16px;
  font-size: 15px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 600px) {

  #topbar {
    left: 10px;
    right: 10px;
    transform: none;
    max-width: none;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    mask-image: linear-gradient(to right, black 85%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
    height: 46px;
    gap: 4px;
    padding: 0 12px;
  }

  #topbar::-webkit-scrollbar { display: none; }

  #topbar > * { flex-shrink: 0; }

  .traffic-label {
    padding: 6px 4px;
    height: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  .traffic-label img,
  .toolbar-icon {
    width: 28px;
  }

  .traffic-label img {
    margin-right: 8px;
  }

  #stopSearchWrapper {
    width: 150px;
  }

  #stopSearchInput {
    font-size: 16px;
    transform: scale(1);
    transform-origin: left center;
	font-size: 12px;
    width: 100%;
  }
  #busRoute {
    font-size: 16px;
    transform: scale(1);
    transform-origin: left center;
	font-size: 12px;
    width: 100%;
  }

  #bus-status-search {
    font-size: 16px;
    transform: scale(1);
    transform-origin: left center;
    font-size: 12px;
    width: 100%;
  }

  .bus-wrapper {
    width: 120px;
  }

  .tube-select-box {
    min-width: 120px;
    font-size: 12px;
  }

  #riverSelect {
    min-width: 100px;
  }

  .leaflet-popup-content-wrapper {
    max-width: calc(100vw - 20px) !important;
    margin: 0 10px !important;
    overflow-x: hidden;
  }

  .leaflet-popup-content {
    margin: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box;
  }

  .leaflet-popup-content > div {
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }

  .leaflet-popup-content > div > div:last-child {
    flex-wrap: wrap;
    gap: 4px;
  }

  .leaflet-popup-content > div > div:last-child span {
    min-width: 0;
  }

  .camera-popup {
    width: calc(100vw - 40px);
    padding: 10px 12px;
    box-sizing: border-box;
  }

  .incident-popup {
    padding: 10px 12px;
    box-sizing: border-box;
  }

  #status-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 75vh;
    border-radius: 16px 16px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  #info-panel {
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
  }

  #info-button,
  #status-button {
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
  }

  #info-button,
  #status-button {
    width: 44px;
    height: 44px;
  }

  .leaflet-tooltip {
    min-width: 0;
    max-width: calc(100vw - 20px);
    font-size: 12px;
  }
}