* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #101418; color: #e8eaed;
  overscroll-behavior: none;
}

#map { position: fixed; inset: 0; background: #1a1e23; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; z-index: 1000;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 10px;
  background: rgba(16,20,24,.92); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px; padding: 10px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
#btn-home {
  background: none; border: none; color: inherit; font-size: 22px;
  width: 44px; height: 44px; margin: -7px 0 -7px -8px; padding: 0;
  display: grid; place-items: center; cursor: pointer;
}
#topbar-title { flex: 1; font-weight: 600; font-size: 16px; }
.topbar-version { margin-left: 4px; color: #aab2bb; font-size: 11px; font-weight: 500; }
.topbar-icon {
  width: 32px; height: 32px; flex: 0 0 32px; padding: 0;
  border: 1px solid rgba(255,255,255,.14); border-radius: 50%;
  background: #262c33; color: #d7dde3; font-size: 15px;
  font-weight: 800; cursor: pointer;
}
#language-select {
  height: 32px; max-width: 58px; padding: 0 5px; border-radius: 9px;
  border: 1px solid rgba(255,255,255,.14); background: #262c33;
  color: #e8eaed; font-size: 12px; font-weight: 700;
}
.topbar-reset {
  height: 32px; padding: 0 9px; border-radius: 9px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.14); background: #262c33;
  color: #d7dde3; font-size: 12px; font-weight: 700; cursor: pointer;
}

.pill { font-size: 12px; padding: 4px 10px; border-radius: 99px; font-weight: 600; }
.pill-on  { background: #16351f; color: #6fd388; }
.pill-off { background: #3a2b13; color: #e8b25a; }

/* ---------- active watches bar ---------- */
#watchbar {
  position: fixed; z-index: 1000;
  top: calc(env(safe-area-inset-top, 0px) + 64px);
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.watch-chip {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  background: rgba(22,53,31,.95); color: #b9ecc4;
  border: 1px solid rgba(111,211,136,.35);
  border-radius: 12px; padding: 8px 12px; font-size: 13px;
}
.watch-chip .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-chip button {
  background: none; border: none; color: #b9ecc4; font-size: 16px; padding: 0 2px; cursor: pointer;
}

/* ---------- bottom sheet ---------- */
#sheet {
  position: fixed; z-index: 1001;
  left: 0; right: 0; bottom: 0;
  background: #171b20;
  border-radius: 18px 18px 0 0;
  border-top: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 -6px 30px rgba(0,0,0,.5);
  max-height: min(74vh, 74dvh);
  display: flex; flex-direction: column;
  transition: transform .25s ease;
}
#sheet.collapsed { transform: translateY(calc(100% - 52px)); }
#sheet-handle {
  flex: 0 0 52px; padding: 8px 16px; cursor: pointer;
  touch-action: none;
  border: 0; border-radius: 18px 18px 0 0;
  background: #252b32; color: #f2f5f7;
  font: inherit; font-size: 13px; font-weight: 700;
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#sheet-handle:focus-visible {
  outline: 3px solid #7fb8ff; outline-offset: -4px;
}
#sheet-content {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px max(16px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom, 0px) + 20px)
    max(16px, env(safe-area-inset-left));
}

@media (max-width: 759px) {
  /* Keep enough of the live map visible while the selection panel is open. */
  #sheet { max-height: min(58vh, 58dvh); }
}

h2 { font-size: 15px; margin: 14px 0 8px; color: #aab2bb; font-weight: 600; }
small, .muted { color: #8a939d; }

/* ---------- generic controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: #2f6fed; color: #fff; border: none;
  border-radius: 12px; padding: 12px 16px; min-height: 48px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  width: 100%;
}
.btn:active { opacity: .8; }
.btn-ghost { background: #262c33; color: #d7dde3; }
.btn-danger { background: #46242a; color: #ff9aa5; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn:disabled { opacity: .45; }

input[type=text] {
  width: 100%; padding: 12px 14px; font-size: 15px;
  background: #22272e; color: #e8eaed;
  border: 1px solid rgba(255,255,255,.1); border-radius: 12px;
  outline: none;
}
input[type=text]:focus { border-color: #2f6fed; }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }
.input-row .btn { width: auto; }

/* ---------- lists ---------- */
.stop-card { margin-bottom: 14px; }
.stop-name { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.route-stop-list { margin-top: 10px; }
.route-stop-button {
  display: grid; grid-template-columns: 28px minmax(0,1fr) 20px;
  align-items: center; gap: 8px; width: 100%; min-height: 50px;
  padding: 9px 8px; text-align: left; color: #e8eaed;
  background: transparent; border: 0; border-bottom: 1px solid rgba(255,255,255,.07);
  font-size: 14px; cursor: pointer;
}
.route-stop-button:active { background: rgba(47,111,237,.18); }
.route-stop-button span:last-child { color: #8a939d; font-size: 20px; }
.arrival-card {
  margin: 10px 0; padding: 11px 12px; border-radius: 12px;
  background: #182d22; border: 1px solid rgba(111,211,136,.3);
  color: #b9ecc4; font-size: 14px;
}
.arrival-icon { margin-right: 5px; }
.arrival-bus { margin-top: 4px; color: #8fcca0; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.route-chip {
  border: none; border-radius: 10px; padding: 7px 11px;
  font-size: 13px; font-weight: 700; color: #fff; cursor: pointer; min-height: 38px;
  opacity: .95;
}
.route-chip.no-gps { opacity: .35; }

.bus-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 4px; min-height: 58px; border-bottom: 1px solid rgba(255,255,255,.06);
  cursor: pointer;
}
.bus-row.selected { background: rgba(47,111,237,.12); border-radius: 10px; }
.bus-row .plate { font-weight: 700; font-size: 15px; }
.bus-row .sub { font-size: 12px; color: #8a939d; }
.bus-row .grow { flex: 1; min-width: 0; }
.speed-badge {
  font-size: 12px; font-weight: 700; padding: 4px 8px; border-radius: 8px;
  background: #22303f; color: #7fb8ff; white-space: nowrap;
}
.speed-badge.stopped { background: #33272a; color: #d99; }
.speed-badge.slow { background: #3a321d; color: #e8c66a; }
.speed-badge.stale { background: #342b3d; color: #c4a1df; }
.motion { display: inline-block; margin-top: 3px; font-size: 11px; font-weight: 600; }
.motion-toward { color: #6fd388; }
.motion-away { color: #ef8d96; }
.motion-unclear, .motion-measuring { color: #8a939d; }
.service-badge {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 4px;
  color: #aab2bb; font-size: 11px; line-height: 1.35;
}
.service-badge i {
  display: inline-block; width: 9px; height: 9px; flex: 0 0 9px;
  border-radius: 50%; border: 1px solid rgba(255,255,255,.55);
}
.trip-id-line { color: #7fb8ff; font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.route-chip small { color: inherit; opacity: .82; }
.guide-banner {
  margin: 12px 0 4px; padding: 10px 12px; border-radius: 12px;
  background: #1d2940; border: 1px solid rgba(127,184,255,.3);
  color: #b9d7ff; font-size: 14px; scroll-margin-top: 8px;
}
.guide-banner b, .guide-banner span { display: block; }
.guide-banner b { font-weight: 800; }
.guide-banner span { margin-top: 3px; color: #a9bfdc; font-size: 12px; line-height: 1.4; }
.about-copy { line-height: 1.55; color: #cbd1d8; }
.about-copy h2 { color: #e8eaed; font-size: 20px; margin-top: 4px; }
.camera-available {
  display: flex; flex-direction: column; gap: 3px; width: 100%;
  margin: 10px 0; padding: 11px 12px; text-align: left;
  border: 1px solid rgba(232,178,90,.4); border-radius: 12px;
  background: #352c1c; color: #f4d79b; cursor: pointer;
}
.camera-available span { color: #c9b98f; font-size: 12px; }
#camera-section { scroll-margin-top: 8px; }

.detail-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; margin: 10px 0; }
.detail-grid dt { color: #8a939d; }
.detail-grid dd { margin: 0; }

.radius-chips { display: flex; gap: 8px; margin: 10px 0; }
.radius-chips button {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,.12);
  background: #22272e; color: #d7dde3; font-size: 14px; font-weight: 600; cursor: pointer;
}
.radius-chips button.sel { background: #2f6fed; border-color: #2f6fed; color: #fff; }

/* ---------- map markers ---------- */
.bus-marker { position: relative; }
.bus-marker .bus-emoji {
  font-size: 26px; line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.6));
}
.bus-marker .bus-label {
  position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
  background: rgba(16,20,24,.88); color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 6px;
  white-space: nowrap;
}
.bus-marker.sel .bus-emoji { font-size: 34px; }
.bus-marker.sel .bus-label { background: #2f6fed; }

.camera-marker {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 50%; background: #e8b25a; color: #101418;
  border: 2px solid #fff; font-size: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.55);
}

.stop-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; border: 2px solid #555; opacity: .85;
}

/* ---------- alert overlay ---------- */
#alert-overlay {
  position: fixed; inset: 0; z-index: 1100; pointer-events: none;
}
.overlay-hint {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 70px);
  left: 20px; right: 20px; text-align: center;
  background: rgba(47,111,237,.95); color: #fff;
  padding: 12px; border-radius: 14px; font-weight: 600; font-size: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
.overlay-actions {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  left: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px;
  pointer-events: auto;
}

/* ---------- toast ---------- */
#toast {
  position: fixed; z-index: 1200;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
  left: 50%; transform: translateX(-50%);
  background: #e8eaed; color: #101418;
  padding: 10px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600;
  max-width: 85vw; text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  transition: opacity .3s;
}

.hidden { display: none !important; }

/* ---------- first-visit external camera check ---------- */
.preflight-overlay {
  position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background: rgba(8,11,14,.9); backdrop-filter: blur(8px);
}
.preflight-card {
  width: min(100%, 480px); max-height: 90dvh; overflow-y: auto;
  padding: 22px; border: 1px solid rgba(255,255,255,.12); border-radius: 18px;
  background: #171b20; box-shadow: 0 16px 50px rgba(0,0,0,.6);
}
.preflight-card h1 { margin: 0 0 10px; font-size: 21px; }
.browser-warning {
  margin: 12px 0; padding: 12px; border-radius: 12px;
  background: #3a2b13; border: 1px solid rgba(232,178,90,.4); color: #f2cf88;
}
.browser-warning b, .browser-warning span { display: block; }
.browser-warning span { margin-top: 4px; font-size: 13px; line-height: 1.45; color: #d8c69f; }
.preflight-card p { color: #cbd1d8; font-size: 14px; line-height: 1.5; }
.preflight-steps {
  margin: 14px 0; padding-left: 28px; color: #cbd1d8;
  font-size: 14px; line-height: 1.45;
}
.preflight-steps li { margin: 0 0 10px; padding-left: 4px; }
.preflight-steps li::marker { color: #7fb8ff; font-weight: 800; }
.preflight-steps b { color: #e8eaed; }
.preflight-card .btn { margin: 9px 0; text-decoration: none; }
.preflight-card > small { display: block; margin-top: 12px; line-height: 1.45; }
.preflight-help {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  background: #24211a; border: 1px solid rgba(232,178,90,.3);
}
.preflight-help p { margin: 6px 0; }
.preflight-usage {
  margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1);
}
.preflight-usage h2 { margin: 0 0 8px; color: #e8eaed; font-size: 17px; }
.preflight-usage p { margin-bottom: 0; }

/* ---------- camera viewer ---------- */
.cam-box {
  position: relative; border-radius: 12px; overflow: hidden;
  background: #0b0e11; border: 1px solid rgba(255,255,255,.1);
  min-height: 120px;
}
.cam-box img {
  display: block; width: 100%; height: auto; max-height: 34dvh; object-fit: contain;
  background: #0b0e11;
}
.cam-box iframe {
  display: block; width: 100%; aspect-ratio: 352 / 288; border: 0;
  background: #0b0e11;
}
.btn-direct-camera { display: block; margin-top: 7px; text-align: center; }
.onboarding-note {
  margin-bottom: 10px; padding: 11px 12px; border: 1px solid rgba(139,92,246,.55);
  border-radius: 12px; background: rgba(139,92,246,.13);
}
.onboarding-note b, .onboarding-note span { display: block; }
.onboarding-note span { margin-top: 4px; color: #cbd1d8; font-size: 13px; line-height: 1.4; }
.step-two { margin-top: 14px; }
.optional-route { margin: 15px 0 8px; }
.optional-route summary { color: #aab2bb; cursor: pointer; font-size: 13px; }
.optional-route .input-row { margin-top: 9px; }
.app-version { display: block; margin-top: 12px; text-align: center; color: #77818b; }
.civic-tech-label {
  margin-top: 14px; padding: 10px 11px; border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; color: #9da7b1; font-size: 11px; line-height: 1.45;
  background: rgba(16,20,24,.55);
}
.camera-link-info { padding: 10px 0 2px; }
.camera-site-note {
  margin-top: 8px; padding: 9px 10px; border-radius: 9px; background: rgba(47,111,237,.12);
  color: #b9c8df; font-size: 12px; line-height: 1.4;
}
.access-count { display: block; margin-bottom: 9px; color: #aab2bb; }
.camera-link-info b, .camera-link-info small { display: block; }
.camera-link-info small { margin-top: 3px; color: #aab2bb; overflow-wrap: anywhere; }
.cam-box img.cam-err { opacity: .25; }
.cam-status { display: block; min-height: 18px; margin-top: 5px; color: #aab2bb; }
.btn-map-pins { margin-top: 8px; }
.camera-nav .btn { font-size: 13px; padding-left: 8px; padding-right: 8px; }
.cam-label {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.65); color: #d7dde3;
  font-size: 11px; padding: 4px 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
h2 small { font-weight: 400; }

.tg-setup {
  background: #24211a; border: 1px solid rgba(232,178,90,.3);
  border-radius: 12px; padding: 12px 14px; font-size: 13px;
  line-height: 1.5; margin: 10px 0;
}
.tg-setup code { background: #333; padding: 1px 5px; border-radius: 4px; }
.map-pick-hint {
  margin: 8px 0 2px; padding: 9px 11px; border-radius: 10px;
  background: #22272e; color: #aab2bb; font-size: 12px; text-align: center;
}
.btn-clear-cache { margin-top: 24px; font-size: 13px; }
.bus-switcher {
  margin: 8px 0 10px; padding: 9px 10px; border-radius: 10px;
  background: #22272e;
}
.bus-switcher small { display: block; margin-bottom: 7px; }
.bus-switch-chip {
  min-height: 38px; padding: 7px 11px; border-radius: 9px;
  border: 1px solid rgba(255,255,255,.12); background: #303740;
  color: #d7dde3; font-weight: 700; cursor: pointer;
}
.bus-switch-chip.active { background: #2f6fed; border-color: #2f6fed; color: #fff; }
.nearby-stop-open {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border: 0; background: transparent; color: inherit;
  text-align: left; font: inherit; font-weight: 700; cursor: pointer;
}
.nearby-stop-open span { color: #aab2bb; font-size: 12px; font-weight: 500; }
.nearby-routes { display: grid; gap: 7px; }
.nearby-route-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 9px;
  align-items: center; width: 100%; padding: 10px; border-radius: 11px;
  border: 1px solid rgba(255,255,255,.1); background: #22272e; color: #e8edf2;
  text-align: left; cursor: pointer;
}
.nearby-route-number { padding: 6px 8px; border-radius: 7px; font-weight: 800; color: #fff; }
.nearby-route-info { display: grid; gap: 3px; min-width: 0; }
.nearby-route-info b, .nearby-route-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nearby-route-info small { color: #aab2bb; font-weight: 500; }
.nearby-route-info > span { color: #aab2bb; font-size: 12px; }
.nearby-route-card > strong { color: #e8b25a; font-size: 13px; white-space: nowrap; }
.btn-back-stop { margin: 3px 0 9px; }

/* iPhone-sized portrait layout (including iPhone 16/16 Pro). */
@media (max-width: 440px) {
  #topbar { padding: 9px 12px; }
  #topbar-title { font-size: 15px; }
  #sheet { max-height: 58dvh; }
  #sheet-content { font-size: 15px; }
  .detail-grid { grid-template-columns: 92px minmax(0, 1fr); }
  .radius-chips { overflow-x: auto; padding-bottom: 2px; }
  .radius-chips button { flex: 0 0 78px; min-height: 44px; }
  .cam-label { font-size: 12px; padding: 6px 8px; }
  .nearby-route-card { grid-template-columns: auto minmax(0, 1fr); }
  .nearby-route-card > strong { grid-column: 2; }
}

/* Desktop/tablet: keep the map visible and use a floating side sheet. */
@media (min-width: 760px) {
  #topbar {
    width: 430px; left: 16px; right: auto;
  }
  #watchbar {
    width: 430px; left: 16px; right: auto;
  }
  #sheet {
    width: 430px; left: 16px; right: auto; bottom: 16px;
    max-height: calc(100dvh - 94px);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 18px;
    overflow: hidden;
  }
  #sheet-content { padding-bottom: 20px; }
  .cam-box img { max-height: 42dvh; }
}

@media (max-width: 759px) and (orientation: landscape) and (max-height: 500px) {
  #sheet { max-height: 82dvh; left: 42%; border-radius: 18px 0 0 0; }
  .cam-box img { max-height: 44dvh; }
}
