:root {
  color-scheme: dark;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  --bg: #07090c;
  --surface: #111418;
  --surface-raised: #1a1f26;
  --surface-soft: #0d1014;
  --ink: #f7f9fc;
  --muted: #9ba4b2;
  --line: #29313a;
  --accent: #2f8cff;
  --home: #25d366;
  --work: #c764ff;
  --good: #35d46a;
  --warn: #f2b544;
  --bad: #ff5b6b;
  --shadow: 0 18px 50px rgb(0 0 0 / 26%);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-soft: #e9eef4;
  --ink: #111827;
  --muted: #64748b;
  --line: #d9e0e8;
  --accent: #0f6bff;
  --home: #0f9d58;
  --work: #8b42d6;
  --good: #108a42;
  --warn: #a66500;
  --bad: #cc2638;
  --shadow: 0 18px 48px rgb(15 23 42 / 12%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  filter: brightness(0.97);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.05;
}

h2 {
  font-size: 20px;
  line-height: 1.15;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--ink);
}

input[type="search"] {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--ink);
  font: inherit;
}

input[type="search"]::placeholder {
  color: var(--muted);
}

.appFrame {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 100vh;
  max-width: 1180px;
  margin: 0 auto;
  background: var(--bg);
}

.appHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 10px;
}

.brandLockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.routeBadge {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 24px;
  font-weight: 950;
}

#statusLine {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.iconButton {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 20px;
}

.tabMenu {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin: 0 18px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tabButton {
  min-height: 38px;
  background: transparent;
  color: var(--muted);
}

.tabButton.active {
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow);
}

main {
  min-height: 0;
}

.screen {
  display: none;
  padding: 18px;
}

.activeScreen {
  display: grid;
  gap: 16px;
}

.screenTitle,
.sectionHeader,
.mapToolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.journeyRail {
  display: grid;
  grid-auto-columns: minmax(210px, 1fr);
  grid-auto-flow: column;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.journeyRail::-webkit-scrollbar {
  display: none;
}

.journeyCard {
  display: flex;
  align-items: center;
  min-height: 116px;
  gap: 14px;
  border: 1px solid var(--line);
  padding: 18px;
  background: var(--surface-raised);
  color: var(--ink);
  text-align: left;
}

.journeyCard.active {
  border-color: currentColor;
  box-shadow: 0 0 0 1px currentColor inset, var(--shadow);
}

.homeCard {
  color: var(--home);
}

.workCard {
  color: var(--work);
}

.journeyCard strong {
  display: block;
  color: var(--ink);
  font-size: 23px;
  line-height: 1.1;
}

.journeyCard small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.journeyIcon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 8px;
  background: color-mix(in srgb, currentColor 20%, transparent);
  color: currentColor;
  font-size: 28px;
}

.contentBlock {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.softPill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.stackList {
  display: grid;
  gap: 10px;
}

.emptyState {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--muted);
  background: var(--surface-soft);
}

.departureCard {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-raised);
}

.serviceBlock {
  display: grid;
  place-items: center;
  min-height: 78px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.serviceBlock strong {
  font-size: 32px;
  line-height: 1;
}

.serviceBlock span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.serviceBlock.good {
  background: color-mix(in srgb, var(--good) 15%, transparent);
  color: var(--good);
}

.serviceBlock.warn {
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  color: var(--warn);
}

.serviceBlock.bad {
  background: color-mix(in srgb, var(--bad) 16%, transparent);
  color: var(--bad);
}

.departureMain {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.departureMain strong {
  font-size: 20px;
}

.departureMain span {
  color: var(--ink);
  font-size: 14px;
}

.departureMain small {
  font-size: 14px;
  font-weight: 900;
}

.good {
  color: var(--good);
}

.warn {
  color: var(--warn);
}

.bad {
  color: var(--bad);
}

.neutral {
  color: var(--muted);
}

.favouriteGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.favouriteStop {
  display: grid;
  gap: 7px;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-raised);
}

.favouriteStop span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.favouriteStop strong {
  align-self: end;
  font-size: 17px;
  line-height: 1.2;
}

.favouriteStop small {
  color: var(--muted);
  font-size: 12px;
}

.favouriteStop.home {
  border-color: color-mix(in srgb, var(--home) 45%, var(--line));
}

.favouriteStop.work {
  border-color: color-mix(in srgb, var(--work) 45%, var(--line));
}

.mapScreen.activeScreen {
  grid-template-rows: auto minmax(440px, calc(100vh - 174px));
}

.mapPanel {
  position: relative;
  min-height: 440px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: var(--shadow);
}

#map {
  width: 100%;
  height: 100%;
}

.mapSelectionPanel {
  position: absolute;
  z-index: 700;
  right: 12px;
  bottom: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgb(17 24 39 / 12%);
  border-radius: 8px;
  padding: 10px 10px 10px 12px;
  background: rgb(255 255 255 / 92%);
  color: #111827;
  box-shadow: 0 14px 36px rgb(15 23 42 / 20%);
  backdrop-filter: blur(10px);
}

.mapSelectionPanel[hidden] {
  display: none;
}

.mapSelectionPanel strong {
  display: block;
  font-size: 15px;
}

.mapSelectionPanel span {
  display: block;
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
}

.mapSelectionPanel button {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid #d9e0e8;
  padding: 0 12px;
  background: #f8fafc;
  color: #111827;
}

.settingsGrid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stopSettingButton {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 86px;
  border: 1px solid var(--line);
  padding: 12px;
  background: var(--surface-raised);
  color: var(--ink);
  text-align: left;
}

.stopSettingButton .settingIcon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  font-size: 24px;
}

.homeSetting .settingIcon {
  background: color-mix(in srgb, var(--home) 18%, transparent);
  color: var(--home);
}

.workSetting .settingIcon {
  background: color-mix(in srgb, var(--work) 18%, transparent);
  color: var(--work);
}

.stopSettingButton small,
.stopSettingButton em {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stopSettingButton strong {
  display: block;
  overflow: hidden;
  margin: 3px 0;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pickerSheet {
  position: fixed;
  z-index: 1200;
  inset: 0;
  display: grid;
  align-items: end;
  padding: 16px;
  background: rgb(0 0 0 / 48%);
}

.pickerSheet[hidden] {
  display: none;
}

.pickerSheetPanel {
  display: grid;
  gap: 12px;
  max-height: min(760px, calc(100vh - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.pickerHeader {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

#stopPickerSubtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

#closeStopPickerButton {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 22px;
}

.stopResults {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.stopResult {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-raised);
  color: var(--ink);
  text-align: left;
}

.stopResult.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.stopSequence {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
}

.stopResultText {
  min-width: 0;
}

.stopResultText strong,
.stopResultText small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stopResultText strong {
  font-size: 15px;
}

.stopResultText small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stopCheck {
  color: var(--accent);
  font-size: 18px;
  font-weight: 950;
  text-align: center;
}

.secondaryButton {
  min-height: 48px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.settingsGrid .secondaryButton {
  grid-column: 1 / -1;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segmented button {
  min-height: 40px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--surface-raised);
  color: var(--ink);
}

.busMarker {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  border: 2px solid white;
  border-radius: 7px;
  padding: 0 6px;
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgb(0 0 0 / 25%);
  font-size: 11px;
  font-weight: 950;
}

.busMarker.selected {
  width: 34px;
  height: 30px;
  background: #25d366;
  color: #062513;
  box-shadow:
    0 0 0 5px rgb(37 211 102 / 24%),
    0 4px 12px rgb(0 0 0 / 25%);
}

.busMarker::after {
  position: absolute;
  left: 50%;
  top: -8px;
  width: 0;
  height: 0;
  border-right: 5px solid transparent;
  border-bottom: 8px solid white;
  border-left: 5px solid transparent;
  content: "";
  transform: translateX(-50%) rotate(var(--bearing));
  transform-origin: 50% 20px;
}

.selectedRouteStop {
  width: 9px;
  height: 9px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #2f8cff;
  box-shadow: 0 1px 4px rgb(15 23 42 / 30%);
}

.leaflet-container {
  position: relative;
  overflow: hidden;
  font: inherit;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
}

.leaflet-tile {
  border: 0;
  visibility: hidden;
}

.leaflet-tile-loaded {
  visibility: inherit;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface-raised);
  color: var(--ink);
}

.leaflet-popup-content {
  line-height: 1.45;
}

.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface-raised) 88%, transparent);
  color: var(--muted);
  font-size: 10px;
}

@media (min-width: 920px) {
  .activeScreen:not(.mapScreen) {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 0.72fr);
    align-items: start;
  }

  .screenTitle,
  .journeyRail {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .appHeader {
    padding: 14px 14px 8px;
  }

  .tabMenu,
  .screen {
    margin-inline: 0;
  }

  .tabMenu {
    margin: 0 14px;
  }

  .screen {
    padding: 14px;
  }

  .favouriteGrid,
  .settingsGrid {
    grid-template-columns: 1fr;
  }

  .journeyRail {
    grid-auto-columns: minmax(230px, 82vw);
  }

  .mapScreen.activeScreen {
    grid-template-rows: auto minmax(420px, calc(100vh - 168px));
  }
}
