:root {
  --ink: #12314D;
  --ink-soft: #4A6070;
  --teal: #2E8F8C;
  --teal-dark: #26766f;
  --teal-light: #6FC2BE;
  --foam: #EEF7F6;
  --wood: #8B6B4A;
  --wood-light: #EFE6D9;
  --paper: #FFFFFF;
  --gold: #c4a35a;
  --brick: #8b3a2a;
  --muted: #5c6b7a;
  --restaurant: #F4EFE6;
  --restaurant-ink: #12314D;
  --shadow: 0 8px 24px rgba(18, 49, 77, 0.14);
  --radius: 10px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html {
  height: 100%;
  height: 100vh;
  height: 100dvh;
}
body {
  height: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--foam);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: "Trebuchet MS", "Segoe UI Rounded", ui-rounded, system-ui, sans-serif;
  margin: 0;
  line-height: 1.15;
  color: var(--ink);
}

a { color: var(--teal-dark); }
a:focus-visible, button:focus-visible {
  outline: 3px solid var(--teal-light);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 8px 12px;
  z-index: 4000;
}
.skip:focus { left: 8px; top: 8px; }

/* ---------- Header ---------- */
header.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-height: var(--header-h);
  padding: 6px 10px;
  padding-top: max(6px, var(--safe-top));
  background: var(--foam);
  border-bottom: 1px solid #d5e3e2;
  z-index: 20;
}
header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  text-decoration: none;
  color: inherit;
}
header .brand img {
  height: 42px;
  width: auto;
  max-width: 46vw;
  display: block;
}
header .brand .titles { min-width: 0; }
header .brand h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
header .brand p {
  margin: 1px 0 0;
  font-size: 0.68rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 520px) {
  header .brand img { height: 44px; max-width: 58vw; }
  header .brand .titles h1 {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
  }
}
header .header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
header button {
  appearance: none;
  border: 1px solid #c9d6df;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
}
header button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
header button[aria-expanded="true"].primary {
  background: var(--ink);
  border-color: var(--ink);
}

/* ---------- Map ---------- */
#map {
  flex: 1 1 auto;
  min-height: 200px;
  background: #d7dde3;
  position: relative;
  z-index: 1;
}
.leaflet-container { font-family: inherit; background: #d7dde3; }
.leaflet-control-attribution {
  font-size: 9px;
  max-width: 70vw;
  background: rgba(255,255,255,0.8);
}

/* Pins */
.pin {
  position: relative;
  display: grid;
  place-items: center;
  font-family: "Trebuchet MS", "Segoe UI Rounded", ui-rounded, system-ui, sans-serif;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 6px rgba(18, 49, 77, 0.35);
  border: 2px solid #fff;
  cursor: pointer;
  user-select: none;
}
.pin::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
}
.pin-stop {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--teal);
  font-size: 14px;
}
.pin-stop::after { border-top: 7px solid var(--teal); }
.pin-bar {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--wood);
  font-size: 11px;
  letter-spacing: 0;
}
.pin-bar::after { border-top: 7px solid var(--wood); }
.pin-bar .glyph { font-size: 13px; line-height: 1; }
.pin-restaurant {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--restaurant);
  border-color: var(--ink);
  color: var(--ink);
  font-size: 11px;
}
.pin-restaurant::after { border-top: 6px solid var(--ink); bottom: -5px; }
.pin.is-closed {
  opacity: 0.38;
  filter: grayscale(0.4);
}
.leaflet-marker-pane .pin-wrap { background: transparent; border: 0; }

/* Popups */
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.leaflet-popup-content {
  margin: 12px 14px 14px;
  min-width: 200px;
  max-width: 260px;
  font-size: 0.88rem;
}
.popup-card h3 {
  font-size: 1.02rem;
  font-weight: 800;
  margin: 0 0 2px;
}
.popup-card .type {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--teal-dark);
  text-transform: none;
}
.popup-card .addr,
.popup-card .walk,
.popup-card .hours-note {
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.popup-card .hours {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  font-size: 0.8rem;
}
.popup-card .hours li {
  display: grid;
  grid-template-columns: 4.6em 1fr;
  gap: 6px;
  padding: 2px 0;
}
.popup-card .hours li.is-today {
  font-weight: 700;
  color: var(--ink);
  background: var(--foam);
  margin: 0 -6px;
  padding: 3px 6px;
  border-radius: 6px;
}
.popup-card .hours .day { color: var(--ink-soft); font-weight: 650; }
.popup-card .blurb {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--ink);
}
.popup-card .links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.popup-card .links a {
  font-size: 0.8rem;
  font-weight: 700;
}
.popup-card .warn {
  margin: 0 0 8px;
  font-size: 0.75rem;
  color: var(--brick);
  font-weight: 700;
}
.popup-card .hours-note { font-size: 0.72rem; }

/* ---------- Dock ---------- */
.dock {
  background: var(--paper);
  border-top: 3px solid var(--teal);
  padding: 8px 12px 8px;
  z-index: 20;
  font-size: 0.85rem;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.filters, .areas, .legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.filters { margin-bottom: 6px; }
.areas { margin-bottom: 6px; }
.filters .cluster,
.areas .cluster {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}
.group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-right: 2px;
}
.seg {
  display: inline-flex;
  background: var(--foam);
  border: 1px solid #d5e3e2;
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
}
.seg button[aria-pressed="true"] {
  background: var(--teal);
  color: #fff;
}
.seg button:disabled {
  opacity: 0.4;
  cursor: default;
}
.areas button {
  appearance: none;
  border: 1px solid #c9d6df;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 650;
  cursor: pointer;
  min-height: 34px;
}
.legend {
  gap: 10px;
  color: var(--ink-soft);
  font-size: 0.72rem;
}
.legend .key {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.swatch {
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(18,49,77,0.2);
  flex-shrink: 0;
}
.swatch.stop { background: var(--teal); border-radius: 50%; }
.swatch.bar { background: var(--wood); border-radius: 3px; }
.swatch.food { background: var(--restaurant); border-radius: 50%; border-color: var(--ink); }
.swatch.route { background: var(--teal-light); border-radius: 2px; width: 16px; height: 4px; box-shadow: none; border: 0; }

/* ---------- In-view results list ---------- */
.results {
  position: relative;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid #e6eeed;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.results.has-more::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--paper) 90%);
}
.results-head {
  margin: 0 0 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-family: inherit;
}
.results-list {
  max-height: min(30vh, 248px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin: 0 -8px;
  min-height: 0;
}
.results-empty {
  margin: 4px 8px 8px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.result-row {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  border-bottom: 1px solid #e6eeed;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
  line-height: 1.3;
}
.result-row:last-child { border-bottom: 0; }
.result-row:hover,
.result-row:focus-visible {
  background: var(--foam);
}
.result-row.is-active {
  background: var(--foam);
  box-shadow: inset 3px 0 0 var(--teal);
}
.result-row.is-closed {
  opacity: 0.58;
}
.result-pin {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  font-family: "Trebuchet MS", "Segoe UI Rounded", ui-rounded, system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(18, 49, 77, 0.2);
}
.result-pin.stop {
  background: var(--teal);
  border-radius: 50%;
}
.result-pin.bar {
  background: var(--wood);
  border-radius: 4px;
}
.result-pin.food {
  background: var(--restaurant);
  border-radius: 50%;
  border-color: var(--ink);
  box-shadow: none;
}
.result-body { min-width: 0; flex: 1; }
.result-name {
  display: block;
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink);
}
.result-type {
  display: block;
  margin-top: 1px;
  font-size: 0.7rem;
  font-weight: 650;
  color: var(--teal-dark);
}
.result-hours {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.result-hours .hours-seg { display: block; }
.result-hours.is-shut,
.result-hours .is-shut {
  font-weight: 700;
  color: var(--muted);
}
.result-walk {
  display: block;
  margin-top: 1px;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

/* ---------- Footer brands ---------- */
.partners {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
  background: var(--ink);
  color: #fff;
  padding: 8px 12px;
  padding-bottom: max(8px, var(--safe-bottom));
  z-index: 20;
}
.partners .slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  flex: 1;
  text-decoration: none;
  color: #fff;
}
.partners .slot.visit {
  background: #fff;
  border-radius: 8px;
  padding: 4px 6px;
  flex: 1.2;
}
.partners img { display: block; width: auto; }
.partners .slot.loop-mark { padding: 4px 6px; }
.partners .slot.mcm { flex: 0.6; gap: 6px; }
.partners .credit { font-size: 11px; opacity: .8; white-space: nowrap; }
.partners .loop-mark img { height: 30px; max-width: 30vw; }
.partners .visit img { height: 36px; max-width: 38vw; }
.partners .mcm img { height: 30px; max-width: 14vw; }
.partners .sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ---------- Info drawer ---------- */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(18, 49, 77, 0.35);
  z-index: 1500;
}
.drawer-backdrop.open { display: block; }
.drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: min(78vh, 640px);
  background: var(--paper);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(18, 49, 77, 0.2);
  z-index: 2000;
  transform: translateY(110%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
}
.drawer.open { transform: translateY(0); }
.drawer.open.no-anim { transition: none; }
.drawer .handle {
  width: 44px;
  height: 4px;
  background: #c9d6df;
  border-radius: 4px;
  margin: 8px auto 0;
}
.drawer header.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 8px;
  border-bottom: 1px solid #e6eeed;
  flex-shrink: 0;
}
.drawer header.drawer-head h2 { font-size: 1.1rem; font-weight: 800; }
.drawer .close {
  appearance: none;
  border: 0;
  background: var(--foam);
  color: var(--ink);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}
.drawer .body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px 20px;
  -webkit-overflow-scrolling: touch;
}
.drawer h3 {
  font-size: 0.95rem;
  font-weight: 800;
  margin: 14px 0 6px;
}
.drawer p, .drawer li { color: var(--ink-soft); font-size: 0.88rem; }
.drawer .lede { margin: 0 0 10px; color: var(--ink); }
.hours-table, .fare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0 0 8px;
}
.hours-table th, .hours-table td,
.fare-table th, .fare-table td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid #e6eeed;
  vertical-align: top;
}
.hours-table th, .fare-table th { color: var(--ink-soft); font-weight: 650; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.fare-table td:last-child { font-weight: 800; color: var(--ink); white-space: nowrap; }
.drawer .note { font-size: 0.75rem; color: var(--muted); margin: 0 0 10px; }
.btn-link {
  display: inline-block;
  background: var(--teal);
  color: #fff !important;
  font-weight: 700;
  text-decoration: none;
  padding: 12px 18px;
  border-radius: 999px;
  margin: 6px 0 12px;
}
.stop-list { list-style: none; margin: 0; padding: 0; }
.stop-list li button {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  border-bottom: 1px solid #e6eeed;
  padding: 8px 0;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
}
.stop-list .num {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  margin-top: 1px;
}
.stop-list .nm { font-weight: 700; font-size: 0.88rem; }
.stop-list .nm small { display: block; font-weight: 500; color: var(--ink-soft); font-size: 0.75rem; }

.locate-btn {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 1100;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #c9d6df;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(18,49,77,0.15);
  line-height: 1;
}


/* Mobile: footer locked, map at least half the viewport, middle dock scrolls. */
@media (max-width: 719px) {
  #map {
    flex: 0 0 auto;
    height: 50vh;
    height: 50dvh;
    min-height: 50vh;
    min-height: 50dvh;
  }
  .dock {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 5px 10px 6px;
  }
  .filters,
  .areas,
  .legend {
    flex-shrink: 0;
    gap: 4px;
  }
  .filters { margin-bottom: 3px; }
  .areas { margin-bottom: 3px; }
  .filters .cluster,
  .areas .cluster { gap: 4px; }
  .group-label {
    font-size: 0.6rem;
    letter-spacing: 0.04em;
    margin-right: 0;
  }
  .seg { padding: 1px; gap: 1px; }
  .seg button {
    padding: 3px 8px;
    font-size: 0.7rem;
    min-height: 28px;
  }
  .areas button {
    padding: 3px 8px;
    font-size: 0.68rem;
    min-height: 28px;
  }
  .legend {
    gap: 7px;
    font-size: 0.64rem;
  }
  .results {
    flex: 1 1 auto;
    min-height: 4.5rem; /* ~heading + 1.5 rows */
    overflow: hidden;
    margin-top: 4px;
    padding-top: 4px;
  }
  .results-head {
    flex-shrink: 0;
    margin: 0 0 2px;
  }
  .results-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .result-row { padding: 6px 8px; }
}

@media (min-width: 720px) {
  header .brand p { white-space: normal; }
  .leaflet-popup-content { max-width: 300px; }
  .partners img { max-width: none; }
  .drawer {
    left: auto;
    right: 16px;
    bottom: 16px;
    width: 400px;
    max-height: calc(100dvh - 32px);
    border-radius: 16px;
    padding-bottom: 8px;
  }
}
