:root {
  --ink: #1c2330;
  --muted: #5b6575;
  --paper: #ffffff;
  --rule: #dfe3e8;
  --rack: #0e8a6a;   /* bicycle parking; RACK_COLOR in app.js */
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  font: 14px/1.4 system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #eef0f2;
}

#map { position: absolute; inset: 0; }

#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 300px;
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgb(0 0 0 / 0.12);
}

h1 { margin: 0 0 8px; font-size: 16px; line-height: 1.2; }
h1 span { display: block; font-weight: 400; color: var(--muted); }

#clock { display: flex; align-items: baseline; gap: 8px; }
#clock-time { font-size: 34px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
#clock-day { color: var(--muted); }
#count { margin: 0 0 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

.row { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }

button, select {
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid #c5ccd6;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { background: #f3f5f7; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid #1b6fb5; outline-offset: 1px; }
#days button { flex: 1; }
#days button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
#play { min-width: 72px; }
.speed { margin-left: auto; color: var(--muted); display: flex; gap: 7px; align-items: center; }
.speed small { font-size: 12px; white-space: nowrap; }
/* Three radio buttons as one pill: the chosen speed is the dark disc that slides to it. */
.seg { position: relative; display: inline-flex; padding: 2px; border: 1px solid #c5ccd6; border-radius: 999px; background: #f3f5f7; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg label span { display: block; min-width: 30px; padding: 3px 0; border-radius: 999px; text-align: center; font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--muted); transition: background 0.15s, color 0.15s, box-shadow 0.15s; }
.seg label:hover span { color: var(--ink); }
.seg input:checked + span { background: var(--ink); color: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); }
.seg input:focus-visible + span { outline: 2px solid #1b6fb5; outline-offset: 1px; }

#time { width: 100%; margin: 4px 0 0; accent-color: var(--ink); }
.ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-bottom: 10px; }

#trip { padding: 8px 0; border-top: 1px solid var(--rule); }
#trip-hint { margin: 0; color: var(--muted); }
/* One card for the racks: whose they are (the sibling map, by its logo and name) above,
   and the switch that uses them below. */
#racks { margin-top: 10px; border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
#racks b { display: block; font-weight: 600; }
#racks small { display: block; font-size: 12px; color: var(--muted); }
#parking-link { display: flex; align-items: center; gap: 9px; padding: 8px 10px; background: #edf7f3; color: inherit; text-decoration: none; }
#parking-link:hover { background: #dff0ea; }
#parking-link:hover b { text-decoration: underline; }
#parking-link:focus-visible { outline: 2px solid #1b6fb5; outline-offset: -2px; }
#parking-link svg { flex: none; width: 30px; height: 30px; }
#parking-link span { flex: 1; min-width: 0; }
#parking-link em { font-style: normal; font-size: 15px; color: #0f766e; }
#parking-switch { position: relative; display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-top: 1px solid var(--rule); cursor: pointer; }
#parking-switch span { flex: 1; min-width: 0; }
/* The checkbox is there for the keyboard and the screen reader; what shows is the track
   beside it and the thumb that slides along it. */
#parking-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
#parking-switch i { flex: none; position: relative; width: 38px; height: 22px; border-radius: 999px; background: #c5ccd6; transition: background 0.15s; }
#parking-switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.15s; }
#parking-switch input:checked + i { background: var(--rack); }
#parking-switch input:checked + i::after { transform: translateX(16px); }
#parking-switch input:focus-visible + i { outline: 2px solid #1b6fb5; outline-offset: 2px; }
#parking-switch:has(input:disabled) { cursor: default; opacity: 0.55; }
@media (prefers-reduced-motion: reduce) { #parking-switch i, #parking-switch i::after { transition: none; } }

#trip-panel {
  position: absolute;
  top: 12px;
  right: 54px;
  width: 372px;
  --bike-col: 104px;
  max-height: calc(100% - 60px);
  overflow: auto;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgb(0 0 0 / 0.12);
}
#trip-panel[hidden] { display: none; }
#trip-panel p { margin: 0; }
#trip-close { position: absolute; top: 8px; right: 8px; padding: 0 7px 2px; font-size: 17px; line-height: 1.2; border: 0; color: var(--muted); }
#trip-status { font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
/* Two columns all the way down: the rider's trip, and the same trip by bicycle. */
#trip-head, #trip-lines { display: grid; grid-template-columns: minmax(0, 1fr) var(--bike-col); }
/* The head is the comparison: how long each took, door to door, as large as anything
   here, with the clock times and the speed that follow from it beneath. */
#trip-head { margin: 2px 0 6px; }
#trip-head b { display: block; font-size: 26px; line-height: 1.15; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; white-space: nowrap; }
#trip-head b span { margin-left: 3px; font-size: 14px; font-weight: 600; letter-spacing: 0; }
#trip-head small { display: flex; flex-wrap: wrap; align-items: center; gap: 0 5px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
#trip-head small u { text-decoration: none; color: var(--ink); font-weight: 600; }
.cur u { text-decoration: none; }
#trip-buses { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-bottom: 8px; }
#trip-buses i { font-style: normal; color: var(--muted); }
#trip-buses span { color: var(--muted); }
#trip-buses .badge + span, #trip-buses .badge ~ span { margin-left: 4px; }
.badge { display: inline-block; min-width: 26px; padding: 0 5px; border-radius: 4px; color: #fff; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }

#trip-lines { position: relative; border-top: 1px solid var(--rule); }
#trip-steps { list-style: none; margin: 0; padding: 6px 0; }
#trip-steps li { display: flex; gap: 8px; padding: 4px 0 4px 6px; border-left: 3px solid transparent; }
#trip-steps time { flex: none; font-variant-numeric: tabular-nums; color: var(--muted); }
#trip-steps span { flex: 1; min-width: 0; }
#trip-steps small { display: block; font-size: 12px; color: var(--muted); }
#trip-steps em { flex: none; font-style: normal; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
/* The last row sums the rows above it: the total, as the bicycle's line ends on its own. */
#trip-steps li.arrive em, #trip-rail .end strong { color: var(--ink); font-weight: 650; }
#trip-rail .end strong { display: block; font-variant-numeric: tabular-nums; }
#trip-steps li.done { opacity: 0.55; }
#trip-steps li.now { border-left-color: var(--ink); background: #f3f5f7; }
#trip-steps li.now > span { font-weight: 600; }
#trip-steps li.now small { font-weight: 400; }
#trip-steps li.wait > span { color: var(--muted); }

.rider { width: 26px; height: 38px; cursor: grab; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.45)); }
.rider:active { cursor: grabbing; }
.rider > svg { display: block; width: 100%; height: 100%; fill: var(--ink); stroke: #fff; stroke-width: 1.5; paint-order: stroke; }
.bike { width: 30px; height: 20px; pointer-events: none; }
.bike > svg, #trip-bike svg { display: block; width: 100%; height: 100%; opacity: 0.6; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bike > svg { filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff); }
/* The shadow on foot, between a door and a rack: the figure, as faint as the bicycle. */
.bike > svg.foot, #trip-bike svg.foot { fill: var(--ink); stroke: #fff; stroke-width: 1.5; paint-order: stroke; }
.bike > svg.foot { display: none; }
.bike.afoot { width: 17px; height: 25px; }
.bike.afoot > svg { display: none; }
.bike.afoot > svg.foot { display: block; }
.bike.afoot .medal { top: -12px; right: -14px; }
#trip-bike { padding-left: 8px; }
#trip-bike svg { flex: none; width: 21px; height: 14px; }
#trip-bike svg.foot { width: 10px; height: 15px; }

/* The bicycle's line. app.js places .line, .at and .end on the clock of the steps. */
#trip-rail { position: relative; border-left: 1px solid var(--rule); }
#trip-rail .line { position: absolute; left: 10px; width: 3px; border-radius: 2px; background: #7a8494; opacity: 0.75; }
#trip-rail .line.walk { border-radius: 0; background: repeating-linear-gradient(#7a8494 0 3px, transparent 3px 7px); }
#trip-rail .at { position: absolute; left: 6px; top: -5.5px; z-index: 1; width: 11px; height: 11px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); }
#trip-rail .end { position: absolute; left: 0; right: 0; margin-top: -10px; padding-left: 23px; }
#trip-rail .end::before { content: ""; position: absolute; left: 6px; top: 4.5px; width: 11px; height: 11px; border-radius: 50%; background: #7a8494; }
#trip-rail .end b { display: block; font-weight: 400; font-variant-numeric: tabular-nums; color: var(--muted); }
#trip-rail .end small { display: block; font-size: 12px; color: var(--muted); }

/* The medal waits, unseen but with its place kept, until its owner is there. */
.award { display: inline-flex; align-items: center; gap: 5px; vertical-align: -5px; visibility: hidden; transform-origin: 8px 0; }
.award svg { flex: none; width: 15px; height: 20px; }
#trip-panel .award small { display: block; font-size: 11px; line-height: 1.15; font-weight: 600; color: var(--ink); }
#trip-rail .award { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; margin-top: 5px; }
#trip-panel.won .award { visibility: visible; animation: medal 0.5s cubic-bezier(0.3, 1.6, 0.5, 1); }
.medal { position: absolute; display: none; width: 17px; height: 23px; transform-origin: 50% 0; }
.medal svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 0 1px #fff) drop-shadow(0 1px 1.5px rgb(0 0 0 / 0.4)); }
.rider .medal { top: -6px; right: -13px; }
.bike .medal { top: -19px; right: -8px; }
/* A tie: one handshake, between the two. Under both timelines in the panel, between the
   lanes on a phone, and on the map between the two where they stand apart. */
.award i { display: block; font-style: normal; font-size: 16px; line-height: 1; }
#trip-friends { grid-column: 1 / -1; padding: 2px 0 8px; text-align: center; }
#trip-friends:empty { display: none; }
#race { position: relative; }
#race-shake { display: none; position: absolute; top: 50%; translate: -50% -50%; font-size: 19px; line-height: 1;
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff); }
#trip-panel.friends #race-shake { display: block; animation: shake 0.5s cubic-bezier(0.3, 1.6, 0.5, 1); }
.dest.friends { z-index: 3; }
.dest.friends::after { content: "🤝"; position: absolute; left: 50%; bottom: 15px; translate: -50% 0; font-size: 19px; line-height: 1;
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 1px 1.5px rgb(0 0 0 / 0.4)); animation: shake 0.5s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes shake { from { scale: 0; } }
@media (prefers-reduced-motion: reduce) { #race-shake, .dest.friends::after { animation: none !important; } }
.medalled .medal { display: block; animation: medal 0.5s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes medal { from { transform: scale(0) rotate(-30deg); } }
@media (prefers-reduced-motion: reduce) { .award, .medal { animation: none !important; } }
.dest { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--ink); }

#legend { list-style: none; margin: 0 0 6px; padding: 8px 0 0; border-top: 1px solid var(--rule); }
#legend li { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
#legend small { color: var(--muted); }
/* A family of route numbers, 8X for 80 to 89, as a route badge in the average of their colours. */
#legend .badge { background: var(--muted); margin-right: -4px; }
#legend .badge + small { margin-left: 4px; }
.sw { display: inline-block; width: 26px; height: 0; border-top: 3px solid var(--muted); flex: none; }
.sw.frequent { border-top-width: 6px; }
.sw.university { border-top-style: dashed; }

.fine { margin: 6px 0 0; font-size: 11.5px; color: var(--muted); }
.fine a { color: inherit; }

.maplibregl-popup-content { padding: 8px 10px; font: 12.5px/1.35 system-ui, "Segoe UI", Roboto, sans-serif; }
.pop .badge { min-width: 22px; padding: 0 4px; }
.pop div + div { margin-top: 3px; }
.pop .off { color: var(--muted); }

/* ---------- small screens ----------
   On a wide screen the wrapper is not there, and these are only seen on a small one. */
#ui { display: contents; }
#more, #trip-expand, #race, #tap-hint, #trip-hint .tap { display: none; }
@media (pointer: coarse) {
  #trip-hint .click { display: none; }
  #trip-hint .tap { display: inline; }
}

/* A phone, upright or on its side, or a tablet upright: one sheet holds everything, and the map has the
   rest. The sheet is short: the clock and its controls, and above them, once a trip is
   made, the race. What else there is opens over the map. COMPACT in app.js is this query. */
@media (max-width: 820px), (max-height: 500px) and (max-width: 1000px) {
  #map { bottom: var(--sheet-h, 170px); }
  .maplibregl-ctrl-top-right { display: none; }   /* a phone zooms with two fingers */

  #ui {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    touch-action: manipulation;   /* two quick taps on a button are two taps, not a zoom */
    z-index: 3;   /* over the map's own controls, when it is opened over the map */
    display: flex;
    flex-direction: column;
    max-height: 88%;
    max-height: 88dvh;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--paper);
    border-top: 1px solid var(--rule);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -2px 12px rgb(0 0 0 / 0.12);
    overflow: hidden;
  }
  #panel, #trip-panel {
    position: relative;
    inset: auto;
    width: auto;
    max-height: none;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: none;
    overflow-y: auto;
  }

  /* The controls: play, the clock, the speed and "more" in one row, then the days and
     the time of day. The rest waits behind "more". */
  #panel { display: flex; flex-wrap: wrap; align-items: center; align-content: flex-start; gap: 6px 8px; flex: 0 1 auto; padding: 8px 12px 10px; }
  #panel > * { flex: 0 0 100%; order: 5; margin: 0; }
  #panel .transport { display: contents; }
  #play, #more { flex: 0 0 44px; height: 40px; padding: 0; }
  #play { order: 0; min-width: 0; font-size: 0; }
  #play::before { font-size: 15px; content: "\25B6"; }
  #play[aria-label="Pause"]::before { content: "\275A\275A"; font-size: 12px; letter-spacing: 1px; }
  #clock { order: 1; flex: 1 1 0; min-width: 0; flex-direction: column; align-items: flex-start; gap: 0; }
  #clock-time { font-size: 24px; line-height: 1.05; }
  #clock-day { max-width: 100%; font-size: 11.5px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #speed { order: 1; flex: none; margin-left: 0; flex-direction: column; gap: 0; }
  #speed small { font-size: 10px; line-height: 1.1; }
  .seg label span { min-width: 36px; padding: 4px 0; }
  #more { order: 1; display: block; font-size: 20px; line-height: 1; color: var(--muted); }
  #more[aria-expanded="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
  #days { order: 2; }
  #days button { padding: 8px 4px; }
  #time { order: 3; height: 26px; }
  #panel > .ticks { order: 4; margin-top: -6px; }
  #panel:not(.open) > :is(h1, #count, #trip, #legend, .fine) { display: none; }
  #panel:not(.open), #trip-panel:not(.open) { flex: none; }   /* the closed one keeps its height; the open one scrolls */
  #panel.open > h1 { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--rule); }
  #panel.open > #trip { padding: 0; border: 0; }
  #panel.open > #legend { margin-top: 2px; }
  h1 span { display: inline; }
  /* While they race, the days and the scale under the slider make way. */
  .racing #panel:not(.open) > :is(#days, .ticks) { display: none; }

  /* The race: above the controls, the same sheet. */
  #trip-panel { order: -1; flex: 0 1 auto; padding: 4px 12px 8px; border-bottom: 1px solid var(--rule); --bike-col: 96px; }
  #trip-status { min-height: 34px; padding-right: 144px; line-height: 34px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #trip-close { top: 2px; right: 4px; width: 40px; height: 34px; padding: 0 0 3px; font-size: 24px; background: none; }
  #trip-expand { display: block; position: absolute; top: 2px; right: 56px; height: 34px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; color: var(--muted); }
  #trip-expand::after { content: " \25BE"; }
  #trip-expand[aria-expanded="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
  #trip-expand[aria-expanded="true"]::after { content: " \25B4"; }
  #trip-head { display: none; }
  #trip-panel #trip-buses { margin: 10px 0 0; }
  #trip-lines { display: none; margin-top: 8px; }
  #trip-panel.open #trip-lines { display: grid; }
  #trip-bike { padding-left: 6px; }

  /* Two lanes on one clock, from setting out to the later of the two arrivals. Each
     runner moves along its own line: dotted on foot, solid riding (a bus in its route's
     colour), bare while waiting, with a post where it ends. */
  #race { display: block; }
  .lane { display: grid; grid-template-columns: minmax(0, 1fr) 76px; align-items: end; gap: 12px; }
  .lane + .lane { margin-top: 6px; }
  .track { position: relative; height: 30px; margin: 0 12px 0 14px; }
  .segs i { position: absolute; bottom: 0; height: 5px; border-radius: 2.5px; background: #7a8494; }
  .segs i.base { bottom: 2px; height: 1px; border-radius: 0; background: #c5ccd6; }
  .segs i.walk { border-radius: 0; background: repeating-linear-gradient(90deg, #7a8494 0 3px, transparent 3px 7px); }
  .segs i.fin { bottom: 0; width: 2px; height: 11px; margin-left: -1px; border-radius: 0; background: var(--ink); }
  .runner { position: absolute; bottom: 6px; left: 0; transform: translateX(-50%); }
  .runner > svg { display: block; width: 100%; height: 100%; }
  #lane-rider .runner { width: 14px; height: 21px; }
  #lane-rider .runner > svg, #lane-bike .runner > svg.foot { fill: var(--ink); stroke: #fff; stroke-width: 1.5; paint-order: stroke; }
  #lane-bike .runner { width: 27px; height: 18px; }
  #lane-bike .runner > svg { fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
  #lane-bike .runner > svg.foot { display: none; }
  #lane-bike .runner.afoot { width: 14px; height: 21px; }
  #lane-bike .runner > svg.foot { opacity: 0.6; }
  #lane-bike .runner.afoot > svg { display: none; }
  #lane-bike .runner.afoot > svg.foot { display: block; }
  .runner .medal { top: -7px; right: -11px; width: 13px; height: 18px; }
  #lane-bike .runner:not(.afoot) .medal { top: -11px; right: -7px; }
  .total { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 4px; line-height: 1.1; }
  .total b { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.4px; white-space: nowrap; }
  .total b span { margin-left: 2px; font-size: 12px; font-weight: 600; letter-spacing: 0; }
  .total small { flex: 0 0 100%; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .lane.won .total b { color: #8a5d00; }

  /* What to do, said on the map until it is done. */
  #tap-hint {
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 16px);
    margin: 0;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgb(28 35 48 / 0.88);
    color: #fff;
    font-size: 12.5px;
    line-height: 1.25;
    text-align: center;
    pointer-events: none;
  }
  .racing #tap-hint { display: none; }

  /* A finger is wider than the figure. */
  .rider::after { content: ""; position: absolute; inset: -12px -14px -8px; }
}

/* On its side a phone is too short for a sheet under the map: it stands beside it. */
@media (max-height: 500px) and (min-width: 821px) and (max-width: 1000px) {
  #map { left: 320px; bottom: 0; }
  #ui { top: 0; right: auto; width: 320px; max-height: none; padding-left: env(safe-area-inset-left); border-top: 0; border-right: 1px solid var(--rule); border-radius: 0; box-shadow: 2px 0 12px rgb(0 0 0 / 0.12); }
  #tap-hint { left: calc(320px + (100% - 320px) / 2); max-width: calc(100% - 336px); }
}

