:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #17201e;
  --muted: #5d6b68;
  --line: #dce3e1;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --live: #16a34a;
  --late: #b45309;
  --early: #2563eb;
  --stop: #0f766e;
  --stop-fav: #d97706;
  --bus: #dc2626;      /* Buses and their routes: red so they stand out on the map */
  --bus-ink: #ffffff;
  --home: #2563eb;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #161d1b;
    --surface-2: #1e2725;
    --text: #e6ecea;
    --muted: #93a29e;
    --line: #2a3533;
    --accent: #2dd4bf;
    --accent-ink: #062320;
    --live: #4ade80;
    --late: #fbbf24;
    --early: #93c5fd;
    --stop: #2dd4bf;
    --stop-fav: #fbbf24;
    --bus: #ef4444;
    --home: #60a5fa;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* Stop phones enlarging text on their own (e.g. iPhone in landscape), which can push the header wider than the screen. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* Belt and braces: nothing in the page may make it scroll sideways. */
/* (clip, not hidden: hidden would stop the phone header staying pinned at the top.) */
body { overflow-x: clip; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
button { font: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
/* The title side may shrink (with "…") so the live badge always fits. */
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand > div { min-width: 0; }
.brand h1, .brand p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo-link { display: block; flex: none; line-height: 0; border-radius: 6px; }
.logo-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.logo { height: 40px; width: auto; display: block; }
.leaflet-popup-content .op { color: #5d6b68; font-size: 12.5px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap; flex: none;
}
.pill .short { display: none; }
.pill.on { color: var(--live); }
.pill.on::before, .dot {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--live); display: inline-block;
  box-shadow: 0 0 0 0 rgba(22,163,74,.5); animation: pulse 2s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }
@media (prefers-reduced-motion: reduce) { .pill.on::before, .dot { animation: none; } }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 420px; min-height: 0; }
#map { min-height: 300px; background: var(--surface-2); }
#panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}
.view { padding: 14px 16px 24px; }

.search { display: flex; gap: 8px; position: sticky; top: 0; background: var(--surface); padding-bottom: 10px; z-index: 2; }
.search input {
  flex: 1; min-width: 0;
  padding: 10px 12px; font: inherit;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 8px 12px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.trip-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.trip-tools .small { color: var(--muted); font-size: 12.5px; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.back { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; margin-bottom: 6px; font-weight: 600; }

.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; font-weight: 700; }
.stop-item {
  display: flex; gap: 10px; align-items: flex-start; width: 100%;
  text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 10px 2px; cursor: pointer; color: inherit;
}
.stop-item:hover { background: var(--surface-2); }
.stop-item .ind { flex: none; min-width: 42px; font-size: 11px; font-weight: 700; text-align: center; padding: 3px 4px; border-radius: 6px; background: var(--surface-2); color: var(--muted); margin-top: 2px; }
.stop-item .main { flex: 1; min-width: 0; }
.stop-item .name { font-weight: 600; }
.stop-item .sub { color: var(--muted); font-size: 13px; }
.stop-item .dist { flex: none; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.routes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.route {
  display: inline-block; min-width: 34px; text-align: center;
  font-weight: 700; font-size: 12.5px; padding: 2px 6px; border-radius: 6px;
  background: var(--accent); color: var(--accent-ink);
}
.route.sm { min-width: 0; font-size: 11.5px; padding: 1px 5px; }
.empty { color: var(--muted); padding: 16px 0; }

.stop-head h2 { margin: 2px 0 2px; font-size: 21px; line-height: 1.2; }
.stop-head .meta { color: var(--muted); font-size: 13.5px; }
.stop-head .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.fav { background: none; border: 0; cursor: pointer; font-size: 24px; line-height: 1; color: var(--muted); padding: 2px; }
.fav.on { color: var(--stop-fav); }

.notice { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; color: var(--muted); margin: 12px 0; }
.loc-msg { position: relative; color: var(--text); margin-top: 0; padding-right: 34px; }
.loc-msg p { margin: 6px 0 0; color: var(--muted); }
.loc-msg ol { margin: 6px 0 0; padding-left: 20px; }
.loc-msg li { margin: 3px 0; }
.loc-msg .close { position: absolute; top: 4px; right: 6px; background: none; border: 0; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 6px; }

.place-marker { background: none; border: 0; font-size: 26px; line-height: 28px; text-align: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.search { margin: 0; }
/* Place search results (towns, streets, postcodes) */
.place-item { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 2px; cursor: pointer; color: inherit; }
.place-item:hover { background: var(--surface-2); }
.place-item .pin { flex: none; width: 26px; text-align: center; font-size: 17px; line-height: 1.3; }
.place-item .name { font-weight: 600; }
.place-item .sub { color: var(--muted); font-size: 13px; }
.find-place { display: block; width: 100%; text-align: left; margin: 4px 0 8px; }
.place-chip { display: inline-flex; align-items: center; gap: 6px; margin-left: 6px; text-transform: none; letter-spacing: 0; font-weight: 600; }
.place-chip button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0 2px; }

.deps { list-style: none; margin: 12px 0 0; padding: 0; }
.dep {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.dep:hover { background: var(--surface-2); }
.dep .route { min-width: 46px; font-size: 15px; padding: 5px 6px; }
.dep .dest { font-weight: 600; line-height: 1.25; }
.dep .info { color: var(--muted); font-size: 12.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.dep .when { text-align: right; }
.dep .big { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.dep .big.live { color: var(--live); }
.dep .small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.late { color: var(--late); font-weight: 600; }
.early { color: var(--early); font-weight: 600; }
.updated { color: var(--muted); font-size: 12.5px; margin-top: 10px; }

.trip-stops { list-style: none; margin: 12px 0 0; padding: 0 0 0 6px; }
.trip-stops li { position: relative; padding: 6px 0 6px 22px; display: flex; justify-content: space-between; gap: 10px; }
.trip-stops li::before { content: ""; position: absolute; left: 4px; top: 0; bottom: 0; width: 3px; background: var(--bus); }
.trip-stops li:first-child::before { top: 50%; }
.trip-stops li:last-child::before { bottom: 50%; }
.trip-stops li::after { content: ""; position: absolute; left: 0; top: 50%; width: 11px; height: 11px; margin-top: -5.5px; border-radius: 50%; background: var(--surface); border: 3px solid var(--bus); }
.trip-stops li.passed { color: var(--muted); }
.trip-stops li.passed::before, .trip-stops li.passed::after { border-color: var(--line); background: var(--line); }
.trip-stops li.here { font-weight: 700; }
.bus-txt { color: var(--bus); }
.route.bus {background: var(--bus); color: var(--bus-ink); }
.trip-stops li.bus-here::after { background: var(--bus); border-color: var(--bus); width: 15px; height: 15px; margin-top: -7.5px; left: -2px; }
.trip-stops a { color: inherit; text-decoration: none; }
.trip-stops a:hover { text-decoration: underline; }
.trip-stops li.toggle::after { display: none; }
.trip-stops li.toggle::before { background: repeating-linear-gradient(to bottom, var(--line) 0 4px, transparent 4px 8px); }
.trip-stops li.toggle button {
  background: none; border: 0; padding: 2px 0; cursor: pointer;
  color: var(--accent); font: inherit; font-size: 13.5px; font-weight: 600;
}
.trip-stops li.toggle button:hover { text-decoration: underline; }
.trip-stops .live { color: var(--live); font-weight: 700; }
.trip-stops .t {font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13.5px; }

.foot { font-size: 12px; color: var(--muted); padding: 8px 16px; border-top: 1px solid var(--line); background: var(--surface); }

/* Map markers */
.bus-marker { background: none; border: 0; }
/* Live bus: one red pill holding the 🚌 and the route number. Everything sits
   inside the pill, so nothing hangs over neighbouring buses. */
.bus-marker .pill {
  position: relative; box-sizing: border-box; height: 24px;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  padding: 0 6px 0 4px; border-radius: 12px;
  background: var(--bus); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
}
.bus-marker .emoji {
  font-size: 14px; line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.bus-marker .num {
  color: var(--bus-ink); font-weight: 800; font-size: 12px; line-height: 1; white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
}
/* Zoomed out: a small red dot per bus. */
.bus-marker .dot {
  width: 14px; height: 14px; box-sizing: border-box; border-radius: 50%;
  background: var(--bus); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.45);
}
.bus-marker .arrow { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.bus-marker .arrow::before {
  content: ""; position: absolute; left: -5px; top: -25px;
  border: 5px solid transparent; border-bottom: 7px solid var(--bus);
}
/* "You are here" (only shown when the visitor's device shares its location). */
.me-marker { background: none; border: 0; }
.me-marker div { width: 18px; height: 18px; border-radius: 50%; background: var(--home); border: 3px solid #fff; box-shadow: 0 0 0 0 rgba(37,99,235,.5), 0 1px 4px rgba(0,0,0,.4); animation: me-pulse 2s infinite; }
@keyframes me-pulse { 70% { box-shadow: 0 0 0 10px rgba(37,99,235,0), 0 1px 4px rgba(0,0,0,.4); } 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0), 0 1px 4px rgba(0,0,0,.4); } }
@media (prefers-reduced-motion: reduce) { .me-marker div { animation: none; } }.leaflet-popup-content { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.leaflet-popup-content .btn { margin-top: 8px; padding: 5px 10px; }

/* Respect notches / rounded corners when installed as a home-screen app. */
.topbar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-top: max(10px, env(safe-area-inset-top)); }
.foot { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.leaflet-control-zoom a { width: 36px !important; height: 36px !important; line-height: 36px !important; }

/* Tablets (portrait iPad etc.): keep map and panel side by side, narrower panel. */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr 360px; }
}

/* Phones: the page scrolls as one, map on top, departures underneath. */
@media (max-width: 680px) {
  html, body { height: auto; }
  body { display: block; }
  .topbar {
    position: sticky; top: 0; z-index: 1100;
    padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px;
  }
  .topbar { gap: 8px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .brand { gap: 8px; }
  .logo { height: 30px; }
  .brand h1 { font-size: 15.5px; }
  .brand p { font-size: 12px; }
  .pill { font-size: 12px; padding: 3px 8px; gap: 5px; }
  .pill .long { display: none; }
  .pill .short { display: inline; }
  .layout { display: block; }
  #map { height: 46vh; height: 46svh; min-height: 260px; }
  #panel { overflow: visible; border-left: 0; border-top: 1px solid var(--line); min-height: 50vh; }
  .view { padding: 12px max(14px, env(safe-area-inset-right)) 20px max(14px, env(safe-area-inset-left)); }
  .search { position: static; }
  /* 16px stops iPhones zooming the page when the search box is tapped. */
  .search input { font-size: 16px; padding: 11px 12px; }
  .btn { padding: 10px 12px; }
  .stop-item { padding: 12px 2px; }
  .dep { padding: 13px 2px; }
  .dep .route { min-width: 42px; }
  .back { padding: 8px 0; font-size: 15px; }
  .fav { font-size: 28px; padding: 4px 6px; }
  .trip-stops li { padding-top: 8px; padding-bottom: 8px; }
  .foot { font-size: 11.5px; }
}
