:root {
  --sheet-peek: 3.25rem;
  --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;
}

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. */
.brand-overlay,
.map-controls,
.fleet-panel {
  position: absolute;
  /* Leaflet's own control corners sit at z-index 1000. */
  z-index: 1100;
}

/* Floating controls stack in the corner and step aside for an open panel. */
.map-controls {
  top: 1rem;
  right: 1rem;
  z-index: 1150;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  transition: right 260ms ease;
}

.brand-overlay {
  top: 1rem;
  left: 1rem;
  max-width: min(24rem, calc(100% - 2rem));
  padding: 0.9rem 1.05rem;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 700ms ease-out both;
}



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

.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  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;
  margin-top: 0.6rem;
  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;
  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 fleet panel: floating card on desktop, sheet on mobile -------- */

.fleet-panel {
  top: 1rem;
  right: 1rem;
  bottom: 1rem;
  width: 21rem;
  transition: transform 260ms ease;
  display: flex;
  flex-direction: column;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 1s ease-out both;
}

.panel-scroll {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 0;
  flex: 1;
  padding: 1rem;
}

/* Only the sheet needs a handle; on desktop the close button dismisses. */
.sheet-handle {
  display: none;
}

.app[data-panel='closed'] .fleet-panel {
  transform: translateX(calc(100% + 1.5rem));
  pointer-events: none;
}

.panel-close {
  margin-left: auto;
  padding: 0 0.35rem;
  background: none;
  border: 0;
  color: var(--ink-soft);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.panel-close:hover {
  color: var(--ink);
}

/* ---- 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 ----------------------------------------------------- */

.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-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);
  }
}

@media (min-width: 961px) {
  /* Attribution must stay readable, so keep it clear of the side panel. */
  .app[data-panel='open'] .leaflet-bottom.leaflet-right {
    margin-right: 22.5rem;
  }

  .app[data-panel='open'] .map-controls {
    right: 22.5rem;
  }
}

/* ---- narrow screens: the panel becomes a bottom sheet ------------------ */

@media (max-width: 960px) {
  .brand-overlay {
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    max-width: none;
    padding: 0.7rem 0.85rem;
  }

  /* Duplicated by the Joe Bus card in the sheet below. */
  .lede,
  .map-caption {
    display: none;
  }

  .map-controls {
    top: auto;
    right: 0.75rem;
    bottom: calc(var(--sheet-peek) + 0.75rem);
  }

  /* The sheet handle is the reopen control here, so this button has no job. */
  #panelOpen {
    display: none;
  }

  .fleet-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: var(--sheet-peek);
    border-width: 1px 0 0;
    transform: none;
    pointer-events: auto;
    transition: height 240ms ease;
  }

  .app[data-panel='open'] .fleet-panel {
    height: min(85dvh, 40rem);
  }

  /* The handle collapses the sheet on mobile. */
  .panel-close {
    display: none;
  }

  .sheet-handle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    min-height: var(--sheet-peek);
    padding: 0 1rem;
    background: none;
    border: 0;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
  }

  .sheet-grip {
    width: 2.25rem;
    height: 0.25rem;
    border-radius: 999px;
    background: rgba(20, 33, 38, 0.35);
  }

  .panel-scroll {
    overflow-y: auto;
    padding-top: 0;
    /* Clear of the home indicator on notched phones. */
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  /* Keep Leaflet's own controls above the collapsed sheet. */
  .leaflet-bottom {
    margin-bottom: var(--sheet-peek);
  }

  /* The sheet itself scrolls, so the list must not be a nested scroller --
     as a flex child inside one it collapses to nothing. */
  .fleet-list {
    flex: none;
    overflow: visible;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .brand {
    font-size: clamp(1.6rem, 7vw, 2.1rem);
  }

  /* 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 {
    min-height: 2.75rem;
  }

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