:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Google Maps default UI palette */
  --blue: #1a73e8;
  --red: #ea4335;
  --text: #202124;
  --text-2: #5f6368;
  --border: #dadce0;
  --hover: #f1f3f4;
  --stopped: #9aa0a6;
  --shadow: 0 1px 2px rgba(60, 64, 67, .3), 0 2px 6px 2px rgba(60, 64, 67, .15);
  /* Height of the collapsed bottom sheet on phones (excluding the safe-area inset). */
  --peek: 64px;
}

* { box-sizing: border-box; }
/* Otherwise rules like `#bus-list li { display: flex }` override the hidden attribute. */
[hidden] { display: none !important; }
/* Form controls don't inherit fonts by default; Google Maps sets Roboto on its own UI. */
button, input, select, textarea, .gm-style, .gm-style .gm-style-iw { font-family: var(--font); }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-size: 14px;
  line-height: 1.4;
  font-family: var(--font);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
#map { position: absolute; inset: 0; }

/* ---- Bus marker ---- */
.bus {
  position: relative;
  width: 26px;
  height: 26px;
  /* AdvancedMarker anchors at bottom-center; shift down so the anchor is the center. */
  transform: translateY(50%);
  cursor: pointer;
}
.bus::before { content: ''; position: absolute; inset: -9px; }  /* bigger tap target */
.bus svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .45));
  transition: transform .4s ease-out;
}
.bus polygon { fill: var(--blue); stroke: #fff; stroke-width: 2; stroke-linejoin: round; }
.bus.stopped polygon { fill: var(--stopped); }
.bus.stopped .label { color: var(--text-2); }
.bus .label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 1px;
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 1px 2px rgba(60, 64, 67, .3);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

/* ---- Bus stop marker ---- */
.stop {
  position: relative;
  width: 12px;
  height: 12px;
  transform: translateY(50%);
  border: 2.5px solid var(--text-2);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}
.stop::before { content: ''; position: absolute; inset: -12px; }  /* bigger tap target */

/* ---- My location (Google-style blue dot) ---- */
.me {
  width: 18px;
  height: 18px;
  transform: translateY(50%);
  border: 3px solid #fff;
  border-radius: 50%;
  background: #4285f4;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

.locate-btn {
  width: 40px;
  height: 40px;
  margin: 10px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 1px 4px -1px rgba(0, 0, 0, .3);
  color: #666;
  cursor: pointer;
}
.locate-btn svg { width: 22px; height: 22px; fill: currentColor; }
.locate-btn.active { color: var(--blue); }
.locate-btn.error { color: var(--red); }

/* ---- Side panel (desktop) / bottom sheet (phone) ---- */
#panel {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 300px;
  max-height: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px 10px 16px;
  cursor: pointer;
  user-select: none;
}
.grabber { display: none; }
.titles { flex: 1; min-width: 0; }
#panel h1 { margin: 0; font-size: 14px; font-weight: 600; text-transform: uppercase; }
#status { color: var(--text-2); font-size: 12px; }
#status.error { color: var(--red); }
#toggle {
  display: grid; place-items: center; width: 32px; height: 32px;
  font-size: 18px; color: var(--text-2); transition: transform .2s;
}
#panel.collapsed #toggle { transform: rotate(-90deg); }
#panel-body { display: flex; flex-direction: column; min-height: 0; }
#panel.collapsed #panel-body { display: none; }

.legend {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text-2); cursor: pointer;
}
.legend input { margin: 0; width: 16px; height: 16px; accent-color: var(--blue); }
.route-swatch {
  width: 22px; height: 5px; border-radius: 3px;
  background: #8ab4f8; box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--border);
}
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }

#bus-list {
  list-style: none; margin: 0; padding: 4px 0;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
#bus-list li {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 6px 16px; cursor: pointer;
}
#bus-list .name { flex: 1; font-weight: 600; }
#bus-list .meta { color: var(--text-2); font-size: 12px; text-align: right; }
#bus-list .stopped .dot { background: var(--stopped); }
#bus-list .stopped .name { color: var(--text-2); }

@media (hover: hover) {
  #panel-header:hover #toggle, #bus-list li:hover { background: var(--hover); }
  #toggle { border-radius: 50%; }
  .stop:hover { border-color: var(--text); transform: translateY(50%) scale(1.25); }
  .locate-btn:hover { color: #333; }
}

/* ---- Nearest stop / next bus ---- */
#nearest {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
}
#nearest b { color: var(--text); font-weight: 600; }
#nearest.message { cursor: default; }
.nearest-msg { text-align: center; }
.nearest-detail { margin-top: 2px; font-size: .8em; text-align: center; opacity: .8; }
.nearest-eta { border-collapse: collapse; }
.nearest-stop { margin-top: 4px; font-size: .9em; }
.nearest-eta td { padding: 1px 0; white-space: nowrap; }
.nearest-eta td:nth-child(2) { padding: 1px 10px; text-align: right; }
.nearest-eta b { color: var(--blue); }

/* ---- Info window ---- */
.info-title { margin: 0; padding-top: 2px; font-size: 14px; font-weight: 600; }
.info div { color: var(--text-2); font-size: 13px; }
.arrivals { margin-top: 6px; border-collapse: collapse; font-size: 13px; }
.arrivals th { padding: 6px 0 1px; color: var(--text-2); font-size: 12px; font-weight: 400; text-align: left; }
.arrivals tr:first-child th { padding-top: 0; }
.arrivals td { padding: 2px 0; }
.arrivals td:first-child { padding-right: 16px; font-weight: 600; }
.arrivals td:last-child { color: var(--blue); font-weight: 600; text-align: right; }

#notice {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px); padding: 12px 16px;
  background: #fff; border-radius: 8px; box-shadow: var(--shadow);
}

/* ---- Phone: bottom sheet ---- */
@media (max-width: 600px) {
  :root { --peek: 76px; }
  body { font-size: 16px; }

  /* The map stops above the collapsed sheet so Google's logo and controls stay visible. */
  #map { bottom: calc(var(--peek) + env(safe-area-inset-bottom)); }

  #panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 65%;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 8px rgba(60, 64, 67, .2);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #panel-header {
    position: relative;
    height: var(--peek);
    padding: 14px max(8px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  }
  .grabber {
    display: block; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
    width: 36px; height: 4px; border-radius: 2px; background: var(--border);
  }
  #panel h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #status { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #toggle { font-size: 22px; }
  .legend { font-size: 15px; padding-block: 12px; }
  .legend input { width: 20px; height: 20px; }
  #bus-list { padding-bottom: 8px; }
  #bus-list li { min-height: 56px; }
  #bus-list .name { font-size: 16px; }
  #bus-list .meta { font-size: 14px; }
  .dot { width: 12px; height: 12px; }

  /* Larger map labels and markers for touch. */
  .bus { width: 30px; height: 30px; }
  .bus .label { font-size: 13px; padding: 1px 5px; }
  .stop { width: 14px; height: 14px; }
  .locate-btn { width: 44px; height: 44px; }
  .locate-btn svg { width: 24px; height: 24px; }

  /* Info windows */
  .info-title { font-size: 17px; }
  .info div { font-size: 15px; line-height: 1.4; }
  .arrivals { font-size: 16px; }
  .arrivals th { font-size: 14px; padding-top: 8px; }
  .arrivals td { padding: 3px 0; }

  /* On phones the next-bus card floats at the top of the map so it's always visible. */
  #nearest {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 10px);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 32px);
    padding: 10px 18px;
    border: 0;
    border-radius: 22px;
    background: #fff;
    box-shadow: var(--shadow);
    font-size: 15px;
    line-height: 1.4;
  }
  /* Installed on iOS, the status bar's blur reaches past the safe area; clear it. */
  @media (display-mode: standalone) {
    #nearest { top: calc(env(safe-area-inset-top) + 24px); }
  }
  #nearest .nearest-eta td { padding-block: 2px; }
  .nearest-stop { text-align: center; }
  #nearest .nearest-eta { margin-inline: auto; }
  #notice { bottom: calc(var(--peek) + env(safe-area-inset-bottom) + 16px); font-size: 15px; }
}
