:root {
  --ink: #142126;
  --ink-soft: #3d4f56;
  --paper: #f3efe6;
  --harbour: #0f4c5c;
  --harbour-deep: #08323d;
  --signal: #d97706;
  --signal-soft: #f6d7a8;
  --online: #1f7a4d;
  --offline: #8a4b3a;
  --glass: rgba(243, 239, 230, 0.88);
  /* Cards that float over the map need to stay legible against any tile. */
  --glass-solid: rgba(243, 239, 230, 0.97);
  --line: rgba(20, 33, 38, 0.12);
  --shadow: 0 18px 40px rgba(8, 50, 61, 0.18);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Sora', 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

/* Several overlays set display:flex, which otherwise beats the attribute. */
[hidden] {
  display: none !important;
}

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

body {
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--harbour-deep);
  overflow-x: hidden;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: #d8e2e0;
}

/* Everything above the map is a floating card; the map keeps the pointer
   except where a card actually sits. */
.panel,
.map-controls {
  position: absolute;
  /* Leaflet's own control corners sit at z-index 1000. */
  z-index: 1100;
}

/* One panel holds the header, the tracked bus and the fleet list. */
.panel {
  top: 1rem;
  left: 1rem;
  width: min(22rem, calc(100% - 2rem));
  /* Stops short of the speed readout in the bottom-left corner. */
  max-height: calc(100% - 7rem);
  display: flex;
  flex-direction: column;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 700ms ease-out both;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: none;
  border: 0;
  color: var(--ink);
  font-family: var(--font-body);
  text-align: left;
  cursor: pointer;
}

.panel-heading {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-right: auto;
  white-space: nowrap;
}

.header-live {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  flex-shrink: 0;
}

.next-update {
  min-width: 7.1rem;
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.next-update[data-burst='true'] {
  color: var(--online);
  font-weight: 600;
}

.app[data-polling='paused'] .next-update {
  color: var(--offline);
}

.resume-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.85rem 0.85rem;
}

.resume-text {
  margin: 0;
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.resume-button {
  padding: 0.55rem 0.75rem;
  background: var(--signal);
  border: 1px solid rgba(20, 33, 38, 0.15);
  color: #1b1206;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.resume-button:hover {
  filter: brightness(1.06);
}

.chevron {
  flex-shrink: 0;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: rotate(45deg);
  transition: transform 200ms ease;
}

.app[data-panel='open'] .header-live {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  flex-shrink: 0;
}

.next-update {
  min-width: 7.1rem;
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.next-update[data-burst='true'] {
  color: var(--online);
  font-weight: 600;
}

.app[data-polling='paused'] .next-update {
  color: var(--offline);
}

.resume-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.85rem 0.85rem;
}

.resume-text {
  margin: 0;
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.resume-button {
  padding: 0.55rem 0.75rem;
  background: var(--signal);
  border: 1px solid rgba(20, 33, 38, 0.15);
  color: #1b1206;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.resume-button:hover {
  filter: brightness(1.06);
}

.chevron {
  transform: rotate(-135deg);
}

.panel-body {
  display: none;
  flex-direction: column;
  gap: 0.8rem;
  min-height: 0;
  overflow-y: auto;
  padding: 0 0.85rem 0.85rem;
}

.app[data-panel='open'] .panel-body {
  display: flex;
}

/* The tracked bus's speed stays on screen even with the panel collapsed. */
.speed-readout {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.55rem 0.85rem;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.speed-figure {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}

.speed-value {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--harbour);
}

.speed-readout[data-state='offline'] .speed-value,
.speed-readout[data-state='error'] .speed-value {
  color: var(--offline);
}

.speed-unit {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.speed-note {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.map-controls {
  top: 1rem;
  right: 1rem;
  z-index: 1150;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.eyebrow {
  color: var(--harbour);
}

.eyebrow {
  color: var(--harbour);
  margin: 0 0 0.15rem;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.brand {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0.4rem 0 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.status-pill {
  display: inline-flex;
  flex-shrink: 0;
  min-width: 7.1rem;
  justify-content: center;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--line);
  background: #fffdf8;
  font-size: 0.92rem;
  font-weight: 600;
}

.status-pill[data-state='online'] {
  color: var(--online);
  border-color: rgba(31, 122, 77, 0.35);
}

.status-pill[data-state='offline'],
.status-pill[data-state='error'] {
  color: var(--offline);
  border-color: rgba(138, 75, 58, 0.35);
}

.status-pill[data-state='searching'] {
  color: var(--harbour);
}

.pulse {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  animation: pulse 1.8s ease-out infinite;
}

.status-pill[data-state='offline'] .pulse,
.status-pill[data-state='error'] .pulse {
  animation: none;
  opacity: 0.55;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.5rem;
  margin: 0;
}

.meta div {
  min-width: 5.5rem;
}

.meta dt {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.meta dd {
  margin: 0.2rem 0 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.map-caption {
  margin: 0.55rem 0 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.bus-marker {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--signal);
  border: 2px solid #fffdf8;
  box-shadow: 0 4px 14px rgba(8, 50, 61, 0.35);
}

.bus-marker::after {
  content: '';
  position: absolute;
  inset: 0.28rem;
  border-radius: 50%;
  background: #fffdf8;
}

.leaflet-container {
  font-family: var(--font-body);
}

.map-button {
  padding: 0.5rem 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.82rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.map-button:hover,
.map-button:focus-visible {
  color: var(--ink);
  border-color: rgba(243, 239, 230, 0.45);
}

/* The app's primary action, so it reads as a button rather than a hint. */
#focusButton {
  padding: 0.4rem 0.9rem 0.4rem 0.4rem;
  background: var(--signal);
  border-color: rgba(20, 33, 38, 0.2);
  color: #1b1206;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(8, 50, 61, 0.28);
}

#focusButton:hover,
#focusButton:focus-visible {
  color: #1b1206;
  filter: brightness(1.06);
}

#focusButton[data-sprite='true']::before {
  content: '';
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid #fffdf8;
  background-image: var(--sprite);
  background-size: cover;
  background-position: center;
}

/* ---- the tracked bus, pinned above the list --------------------------- */

.joe-card {
  padding: 0.9rem;
  background: var(--harbour-deep);
  border: 1px solid rgba(243, 239, 230, 0.16);
  color: var(--paper);
}

.joe-eyebrow {
  margin: 0;
  font-size: 0.65rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--signal-soft);
}

.joe-name {
  margin: 0.2rem 0 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.joe-sub {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: rgba(243, 239, 230, 0.72);
  font-variant-numeric: tabular-nums;
}

.joe-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin: 0.85rem 0 0;
}

.joe-meta dt {
  margin: 0;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(243, 239, 230, 0.6);
}

.joe-meta dd {
  margin: 0.15rem 0 0;
  font-size: 0.88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.joe-card[data-state='online'] #joeStatus {
  color: #7fd6a4;
}

.joe-card[data-state='offline'] #joeStatus,
.joe-card[data-state='error'] #joeStatus {
  color: #f0a58f;
}

.joe-focus {
  width: 100%;
  margin-top: 0.9rem;
  padding: 0.5rem 0.75rem;
  background: var(--signal);
  border: 1px solid rgba(243, 239, 230, 0.2);
  color: #1b1206;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s ease;
}

.joe-focus:hover:not(:disabled) {
  filter: brightness(1.08);
}

.joe-focus:disabled {
  background: rgba(243, 239, 230, 0.14);
  color: rgba(243, 239, 230, 0.5);
  cursor: not-allowed;
}

/* ---- list controls ----------------------------------------------------- */

.route-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  background: #fffdf8;
  font-size: 0.8rem;
}

.route-swatch {
  width: 0.85rem;
  height: 0.85rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--harbour);
}

.route-summary-text {
  min-width: 0;
  margin-right: auto;
}

.route-filter-button {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.74rem;
  cursor: pointer;
}

.route-filter-button:hover {
  color: var(--ink);
}

/* The tracked bus wears its own photo; everything else gets a mode glyph. */
.veh {
  display: block;
  width: var(--veh-size, 28px);
  height: var(--veh-size, 28px);
}

.veh svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 1px 2px rgba(8, 50, 61, 0.45));
}

/* The badge carries the route colour; the pictogram inside stays white and
   upright so the mode is readable at any heading. */
.veh svg .badge {
  fill: var(--veh-colour, #1f6f63);
  stroke: #fffdf8;
  stroke-width: 1.6;
}

.veh svg .picto {
  fill: #fffdf8;
}

/* Windows and wheels are punched back out in the badge colour. */
.veh svg .cut {
  fill: var(--veh-colour, #1f6f63);
}

.veh svg .arrow {
  fill: var(--veh-colour, #1f6f63);
  stroke: #fffdf8;
  stroke-width: 1.4;
  stroke-linejoin: round;
}

/* Unknown mode: a plain muted marker, visibly not a claim about the vehicle. */
.veh[data-mode='unknown'] svg .badge {
  fill: #8c9a9d;
  stroke-width: 1.2;
}

.veh[data-mode='unknown'] svg {
  opacity: 0.75;
}

.veh[data-selected='true'] svg .badge {
  stroke: #08323d;
  stroke-width: 2.2;
}

.veh[data-selected='true'] svg {
  filter: drop-shadow(0 2px 7px rgba(8, 50, 61, 0.65));
}

.joe-sprite {
  border-radius: 50%;
  border: 3px solid var(--signal);
  box-shadow: 0 3px 12px rgba(8, 50, 61, 0.45);
  background: #fffdf8;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.panel-count {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.panel-controls {
  display: grid;
  gap: 0.5rem;
}

.panel-search {
  width: 100%;
  padding: 0.5rem 0.65rem;
  background: #fffdf8;
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.85rem;
}

.panel-search:focus-visible {
  outline: 2px solid var(--harbour);
  outline-offset: 1px;
}

.panel-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  cursor: pointer;
}

/* ---- the list itself --------------------------------------------------- */

.fleet-list {
  flex: 1;
  /* Without this the list keeps its content height and pushes the note out. */
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.fleet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.35rem;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
}

.fleet-row:hover,
.fleet-row:focus-visible {
  background: rgba(15, 76, 92, 0.08);
}

.fleet-row[aria-pressed='true'] {
  background: rgba(217, 119, 6, 0.16);
}

.fleet-row-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.fleet-row-route {
  flex-shrink: 0;
  padding: 0.12rem 0.4rem;
  border: 1px solid var(--line);
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.fleet-row-route[data-idle='true'] {
  opacity: 0.55;
}

.panel-build {
  margin: 0;
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.panel-note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

/* OSM standard tiles are more saturated than the pale basemap this page was
   designed around; desaturate and lift them so the bus marker stays dominant. */
.leaflet-tile-pane {
  filter: saturate(0.42) brightness(1.06) contrast(0.92);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(15, 76, 92, 0.45);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(15, 76, 92, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(15, 76, 92, 0);
  }
}

/* ---- narrow screens ---------------------------------------------------- */

@media (max-width: 960px) {
  .panel {
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
    max-height: calc(100% - 6rem);
  }

  .map-controls {
    top: auto;
    right: 0.75rem;
    bottom: 0.75rem;
  }

  /* Keep Leaflet's zoom and the attribution clear of the focus button. */
  .leaflet-bottom {
    margin-bottom: 4.5rem;
  }

  .speed-readout {
    left: 0.75rem;
    bottom: 0.75rem;
    padding: 0.45rem 0.7rem;
  }

  .speed-value {
    font-size: 1.55rem;
  }

  /* Collapsed, the panel is a bar at the top and the map keeps the screen. */
  .app[data-panel='open'] .panel {
    max-height: min(78dvh, calc(100% - 1.5rem));
  }

  .brand {
    font-size: 1.25rem;
  }

  /* Wraps to two lines at phone widths and doubles the collapsed bar. */
  .panel-header .eyebrow {
    display: none;
  }

  /* 16px keeps iOS Safari from zooming in when the filter gets focus. */
  .panel-search {
    font-size: 16px;
  }
}

@media (pointer: coarse) {
  .fleet-row {
    min-height: 2.75rem;
    padding: 0.65rem 0.4rem;
  }

  .map-button,
  .joe-focus,
  .panel-header {
    min-height: 2.75rem;
  }

  .panel-toggle {
    min-height: 2.25rem;
  }
}
