:root {
  --night: #13212C;   /* base: the IJ after dark */
  --quay: #1C2E3B;    /* raised surfaces */
  --quay-2: #24394A;
  --fog: #E6EDF1;     /* primary text */
  --mist: #8FA3B1;    /* secondary text */
  --rnet: #E4232B;
  --early: #5BB8FF;
  --ontime: #6FD6A0;
  --late: #FFA24C;
  --gone: #FF6B6B;
  /* vehicle types; operators' own line colours win when the timetable has them */
  --bus: #3A5468;
  --tram: #6C7BFF;
  --metro: #E8618C;
  --train: #FFC917;
  --train-ink: #003082;
  --ferry: #19B3C4;
  --radius-l: 22px;
  --radius-s: 8px;
  font-family: "Overpass", system-ui, sans-serif;
  color: var(--fog);
  background: var(--night);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--night); overscroll-behavior: none; overflow: hidden; }
/* The page never scrolls as a whole, so a swipe on the map always pans the map (the sheet scrolls itself) */
body { position: fixed; inset: 0; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--fog); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  height: 100svh;
  display: grid;
  grid-template-rows: var(--map-h, 40svh) minmax(0, 1fr) auto;
  max-width: 560px;
  margin: 0 auto;
}

/* Map */
.map-wrap { position: relative; }
#map { position: absolute; inset: 0; background: #182A36; touch-action: none; }
.maplibregl-ctrl-attrib { display: none; }
.map-status {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 12px;
  padding: 6px 10px 5px; border-radius: 999px;
  background: rgb(19 33 44 / .82); backdrop-filter: blur(8px);
  font-size: 13px; color: var(--mist);
  display: flex; align-items: center; gap: 7px;
}
.map-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--mist); }
.map-status.live::before { background: var(--ontime); animation: pulse 2s infinite; }
.map-status.stale::before { background: var(--late); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(111 214 160 / .6); } 70%, 100% { box-shadow: 0 0 0 7px rgb(111 214 160 / 0); } }

.map-btns { position: absolute; right: 12px; bottom: 30px; display: grid; gap: 8px; }
.map-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: rgb(19 33 44 / .85); backdrop-filter: blur(8px);
  display: grid; place-items: center; cursor: pointer;
}

/* Vehicle markers */
.veh { position: relative; width: 0; height: 0; cursor: pointer; }
.veh .dir {
  position: absolute; left: -16px; top: -16px; width: 32px; height: 32px;
  transition: transform .8s ease-out; color: var(--vbg);
}
.veh .dir::before {
  content: ""; position: absolute; left: 50%; top: -4px; transform: translateX(-50%);
  border: 6px solid transparent; border-bottom: 8px solid currentColor; border-top: 0;
}
.veh b {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  min-width: 28px; height: 22px; padding: 2px 6px 0; border-radius: 6px;
  display: grid; place-items: center; white-space: nowrap;
  font-size: 13px; font-weight: 800; letter-spacing: -.01em;
  background: var(--vbg); color: var(--vfg);
  box-shadow: 0 0 0 2px var(--night);
}
.veh.est b { box-shadow: 0 0 0 2px var(--night); outline: 2px dashed var(--vbg); outline-offset: 2px; }
.veh.focus { z-index: 5; }
.veh.focus b { box-shadow: 0 0 0 2px var(--night), 0 0 0 5px var(--fog); }
.veh.dim b, .veh.dim .dir { opacity: .3; }  /* MapLibre owns the marker element's own opacity */
.home-dot {
  width: 16px; height: 16px; border-radius: 50%; background: #5BB8FF;
  box-shadow: 0 0 0 4px rgb(91 184 255 / .3), 0 0 0 2px #fff inset;
}

/* Sheet */
.sheet {
  position: relative; z-index: 2; margin-top: -18px; min-height: 0;
  background: var(--night);
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 16px 24px;
  box-shadow: 0 -12px 30px rgb(0 0 0 / .35);
}
.grip {
  display: block; position: relative; width: 100%; height: 26px; margin: -8px 0 2px; padding: 0;
  border: 0; background: none; cursor: grab; touch-action: none;
}
.grip::before {
  content: ""; position: absolute; left: 50%; top: 11px; width: 38px; height: 4px; margin-left: -19px;
  border-radius: 2px; background: var(--quay-2);
}
.grip:active { cursor: grabbing; }

/* Tab bar */
.tabs {
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--quay); border-top: 1px solid var(--quay-2);
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
  position: relative; z-index: 3;
}
.tabs a {
  display: grid; justify-items: center; gap: 2px; padding: 4px 0;
  color: var(--mist); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabs svg { width: 24px; height: 24px; }
.tabs a[aria-current="page"] { color: var(--fog); }

/* Shared bits */
.badge {
  display: inline-grid; place-items: center; min-width: 40px; height: 26px; padding: 3px 6px 0;
  border-radius: 6px; background: var(--vbg, var(--bus)); color: var(--vfg, var(--fog));
  font-weight: 800; font-size: 15px; white-space: nowrap;
}
.chips { display: flex; gap: 6px; margin: 0 -16px; padding: 0 16px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; white-space: nowrap; cursor: pointer;
  border: 1px solid var(--quay-2); background: transparent; color: var(--mist);
  padding: 7px 12px 5px; border-radius: 999px; font-size: 14px; text-decoration: none;
}
.chip[aria-pressed="true"], .chip[aria-checked="true"] { border-color: var(--fog); color: var(--fog); }
.chip.solid[aria-pressed="true"] { background: var(--fog); color: var(--night); }
.back {
  border: 0; background: none; color: var(--mist); padding: 4px 0 8px; cursor: pointer;
  font-size: 15px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center;
}
.empty { color: var(--mist); font-size: 15px; line-height: 1.5; padding: 24px 2px; }
.h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin: 0; line-height: 1.15; }
.sub { color: var(--mist); font-size: 14px; margin: 3px 0 0; }
.modes { display: inline-flex; gap: 10px; flex-wrap: wrap; }
.mode { display: inline-flex; align-items: center; gap: 5px; }
.mode::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--m); }

/* Board */
.board-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-top: 12px; }
.star {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--quay); color: var(--mist); display: grid; place-items: center;
}
.star[aria-pressed="true"] { color: var(--train); }
.star svg { width: 22px; height: 22px; }

.hero { padding: 16px 2px 8px; }
.hero-label { font-size: 17px; font-weight: 600; color: var(--mist); }
.hero-num {
  display: flex; align-items: baseline; gap: 8px;
  font-weight: 900; font-size: clamp(92px, 32vw, 140px); line-height: .82;
  letter-spacing: -.055em; font-variant-numeric: tabular-nums; margin: 6px 0 10px -4px;
}
.hero-unit { font-size: 28px; font-weight: 800; letter-spacing: -.01em; color: var(--mist); }
.hero.now .hero-num { color: var(--ontime); font-size: clamp(72px, 24vw, 110px); }
.hero-sub { margin: 0; font-size: 16px; line-height: 1.45; max-width: 38ch; }
.hero-sub .badge { margin-right: 6px; vertical-align: 1px; height: 24px; min-width: 34px; font-size: 14px; }

.filters { margin: 12px -16px 4px; }
.alert {
  margin: 10px 0; padding: 10px 12px; border-radius: var(--radius-s);
  background: rgb(255 162 76 / .12); color: var(--late); font-size: 14px; line-height: 1.4;
}

.more-alerts summary { color: var(--late); font-size: 14px; cursor: pointer; padding: 2px 0 6px; }
.deps { list-style: none; margin: 6px 0 0; padding: 0; }
.dep {
  display: grid; grid-template-columns: 60px 1fr 18px; gap: 12px; align-items: center;
  padding: 11px 2px; border-bottom: 1px solid var(--quay); cursor: pointer;
}
.dep:active { background: var(--quay); }
.dep .when { font-weight: 800; font-size: 21px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.dep .when small { display: block; font-size: 12px; font-weight: 600; color: var(--mist); letter-spacing: 0; }
.dep .what { min-width: 0; }
.dep .line { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dep .dest { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep .meta { font-size: 13px; color: var(--mist); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.dep .chev { color: var(--mist); }
.dep.x .dest, .dep.x .when { text-decoration: line-through; opacity: .5; }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ontime); margin-right: 5px; vertical-align: 1px; }
.est-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; border: 1.5px dashed var(--mist); margin-right: 5px; vertical-align: 0; }
.early { color: var(--early); } .ontime { color: var(--ontime); } .late { color: var(--late); } .gone { color: var(--gone); }

/* Trip */
.trip-head { display: flex; gap: 12px; align-items: center; margin-top: 4px; }
.trip-head .badge { height: 32px; min-width: 48px; font-size: 18px; }
.trip-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 0; line-height: 1.15; }
.trip-meta { color: var(--mist); font-size: 14px; line-height: 1.5; margin: 10px 0 6px; }
.timeline { list-style: none; margin: 12px 0 0; padding: 0; position: relative; }
.timeline li {
  display: grid; grid-template-columns: 52px 18px 1fr; gap: 10px; align-items: start;
  padding: 7px 0; cursor: pointer; position: relative;
}
.timeline .t { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 16px; text-align: right; }
.timeline .t small { display: block; font-size: 11px; font-weight: 600; color: var(--mist); text-decoration: line-through; }
.timeline .rail { position: relative; height: 100%; min-height: 26px; }
.timeline .rail::before { content: ""; position: absolute; left: 7px; top: -8px; bottom: -8px; width: 4px; background: var(--vbg); opacity: .5; }
.timeline li:first-child .rail::before { top: 9px; }
.timeline li:last-child .rail::before { bottom: calc(100% - 9px); }
.timeline .rail::after { content: ""; position: absolute; left: 3px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--night); border: 3px solid var(--vbg); box-sizing: border-box; }
.timeline .n { font-size: 16px; font-weight: 600; }
.timeline .n small { color: var(--mist); font-weight: 400; font-size: 13px; margin-left: 6px; }
.timeline li.past { opacity: .4; }
.timeline li.here .rail::after { background: var(--fog); border-color: var(--fog); width: 16px; height: 16px; left: 1px; top: 2px; }

/* Lists: favourites, recents, search, nearby */
.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--quay); cursor: pointer; }
.list li:active { background: var(--quay); }
.list .nm { flex: 1; min-width: 0; }
.list .nm b { display: block; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .nm span { font-size: 13px; color: var(--mist); }
.list .dist { color: var(--mist); font-size: 13px; font-variant-numeric: tabular-nums; }
.section-title { font-size: 20px; font-weight: 800; margin: 18px 0 2px; letter-spacing: -.01em; }
.search-box {
  width: 100%; margin-top: 8px; padding: 13px 14px 11px; border-radius: 12px; border: 0;
  background: var(--quay); font-size: 17px;
}
.search-box::placeholder { color: var(--mist); }
.text-btn { border: 0; background: none; color: var(--mist); cursor: pointer; padding: 6px 0; font-size: 14px; text-decoration: underline; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.foot { margin-top: 22px; font-size: 13px; color: var(--mist); line-height: 1.55; }

@media (prefers-reduced-motion: reduce) {
  .map-status.live::before { animation: none; }
  .veh .dir { transition: none; }
}
