/* ---------------------------------------------------------------------------
 * CUHK Shuttle Helper
 *
 * The design target is someone standing at a bus stop in bright Hong Kong
 * sunlight, holding the phone in one hand, in a hurry.
 *
 *   • Body text is 16px and times are 22px. Prose never drops below 13px;
 *     the only smaller type is the 12.5px uppercase labels, where the letter-
 *     spacing carries the legibility.
 *   • Every tappable thing is at least 44px tall, including the quiet ones
 *     that look like plain text.
 *   • Contrast is high; subtle greys wash out outdoors.
 *   • Colour never carries meaning alone — there is always a word or icon.
 *
 * The layout is a document, not a dashboard. Options are separated by hairline
 * rules rather than boxed into cards: a stack of bordered, rounded, shadowed
 * panels reads as chrome competing with the content, and there is very little
 * content here that is not a name or a number.
 *
 * Colour is reserved for information. Each shuttle route has a colour, and it
 * appears as a short bar beside that route's name and as its line on the map —
 * nowhere else. Warnings are amber. Everything else is ink on cream.
 * ------------------------------------------------------------------------- */

:root {
  --page:        #f3efe5;   /* warm cream ground */
  --surface:     #fffdf8;   /* the sheet the content sits on */
  --surface-2:   #f6f1e6;   /* recessed: inputs, quiet buttons */

  --ink:         #1c1a15;
  --ink-2:       #46413a;
  --ink-3:       #6b6355;

  --line:        #e2dbcb;
  --line-strong: #c3b9a4;

  --accent:      #1c1a15;   /* deliberately ink: nothing here needs a brand blue */
  --walk:        #3f6b4f;
  --warn:        #8a5a12;
  --danger:      #96331f;

  --radius:      3px;
  --tap:         44px;
  --gutter:      18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page:        #14120e;
    --surface:     #1c1a15;
    --surface-2:   #262319;

    --ink:         #f3eee2;
    --ink-2:       #cdc5b4;
    --ink-3:       #968d7c;

    --line:        #322e25;
    --line-strong: #514a3c;

    --accent:      #f3eee2;
    --walk:        #8fc9a2;
    --warn:        #e0ac5c;
    --danger:      #e89080;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
        "Noto Sans", "PingFang HK", "Microsoft JhengHei", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 var(--gutter) 56px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  min-height: 100vh;
}

.icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 1.15em;
  height: 1.15em;
  line-height: 0;
}
.icon svg { width: 100%; height: 100%; fill: currentColor; }
.icon--mode { width: 22px; height: 22px; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* --- banners ------------------------------------------------------------ */

.banner {
  max-width: 620px;
  margin: 0 auto;
  padding: 11px var(--gutter);
  font-size: 14px;
  line-height: 1.45;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.banner--danger { color: var(--danger); border-bottom-color: var(--danger); }
.banner--warn   { color: var(--warn); }

/* --- header ------------------------------------------------------------- */

.header {
  max-width: 620px;
  margin: 0 auto;
  padding: 30px var(--gutter) 22px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.header__sub { margin: 5px 0 0; color: var(--ink-3); font-size: 15px; }

/* --- trip inputs -------------------------------------------------------- */

.trip { padding: 0 0 20px; border-bottom: 1px solid var(--line); }

.field { position: relative; }
.field + .field { margin-top: 14px; }

.field__label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-bottom: 5px;
}

.field__row { display: flex; gap: 8px; }

.input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 9px 12px;
  font-size: 17px;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: var(--ink-3); }
.input:focus { background: var(--surface); border-color: var(--ink-2); outline: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn:active { background: var(--line); }
.icon-btn[aria-pressed="true"] { color: var(--ink); border-color: var(--ink-2); }

.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.quick:empty { display: none; }
.quick__btn {
  min-height: var(--tap);
  padding: 5px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.quick__btn:hover { color: var(--ink); border-color: var(--ink-2); }
.quick__btn:active { background: var(--line); }

.field__status {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--ink-3);
  min-height: 1.2em;
}
.field__status--ok  { color: var(--ink-2); }
.field__status--err { color: var(--danger); }

.swap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 0;
  padding: 0;
  min-height: var(--tap);
  font: inherit;
  font-size: 14px;
  color: var(--ink-3);
  background: none;
  border: none;
  cursor: pointer;
}
.swap svg { width: 16px; height: 16px; fill: currentColor; }
.swap:hover { color: var(--ink); }

/* --- autocomplete ------------------------------------------------------- */

.results {
  list-style: none;
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 8px 24px rgba(28, 26, 21, .12);
}
.results li + li { border-top: 1px solid var(--line); }

.results button {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 9px 12px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
}
.results button:hover, .results button:focus { background: var(--surface-2); }

.results__name { display: block; font-size: 16px; font-weight: 500; }
.results__zh   { display: block; font-size: 14px; color: var(--ink-3); }
.results__tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  vertical-align: 1px;
  color: var(--ink-3);
}

/* --- GPS confirmation --------------------------------------------------- */

.confirm {
  margin-top: 12px;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}
.confirm__q { margin: 0 0 9px; font-size: 14px; color: var(--ink-2); }
.confirm__q strong { color: var(--ink); }
.confirm__list { display: flex; flex-wrap: wrap; gap: 7px; }

.confirm__btn {
  flex: 1 1 auto;
  min-height: var(--tap);
  padding: 6px 11px;
  font: inherit;
  font-size: 14px;
  text-align: left;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.confirm__btn[aria-pressed="true"] { border-color: var(--ink); background: var(--surface); }
.confirm__btn small { display: block; font-size: 12.5px; color: var(--ink-3); }

/* --- departure time ----------------------------------------------------- */

.when { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.when__label {
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}
.when__input {
  min-height: var(--tap);
  padding: 5px 9px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.when__now {
  min-height: var(--tap);
  padding: 5px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--ink-2);
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.when__now:hover { color: var(--ink); border-color: var(--ink-2); }

/* --- network browser ---------------------------------------------------- */

.network { border-bottom: 1px solid var(--line); }

.network__toggle {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 58px;
  padding: 14px 0;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
}
.network__toggle-icon { width: 20px; height: 20px; flex-shrink: 0; fill: var(--ink-3); }
.network__toggle strong { display: block; font-size: 16px; font-weight: 600; }
.network__toggle small { display: block; font-size: 13.5px; color: var(--ink-3); margin-top: 1px; }
.network__toggle > span:nth-child(2) { flex: 1; min-width: 0; }
.network__chev {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: var(--ink-3);
  transition: transform .18s ease;
}
.network__toggle.is-open .network__chev { transform: rotate(180deg); }

.network__panel { padding: 0 0 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 5px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.chip__dot { display: none; width: 9px; height: 9px; background: var(--chip-colour); }
.chip--colour .chip__dot { display: block; }
.chip[aria-pressed="true"] {
  color: var(--surface);
  background: var(--ink);
  border-color: var(--ink);
}
.chip--colour[aria-pressed="true"] {
  color: #fff;
  background: var(--chip-colour);
  border-color: var(--chip-colour);
}
.chip[aria-pressed="true"] .chip__dot { background: rgba(255, 255, 255, .9); }

.network__summary { margin: 14px 0 0; font-size: 15px; line-height: 1.5; color: var(--ink-2); }
.network__note { display: block; margin-top: 6px; color: var(--warn); font-size: 13.5px; }

.stoplist { list-style: none; margin: 14px 0 0; padding: 0; }
.stoplist__item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 0;
}
.stoplist__item + .stoplist__item { border-top: 1px solid var(--line); }
.stoplist__code {
  flex-shrink: 0;
  min-width: 46px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: var(--route-colour, var(--ink-3));
  border-radius: 2px;
}
.stoplist__text { flex: 1; min-width: 0; }
.stoplist__name { display: block; font-size: 15.5px; font-weight: 500; }
.stoplist__zh { display: block; font-size: 13.5px; color: var(--ink-3); }
.stoplist__meta { flex-shrink: 0; font-size: 12.5px; color: var(--ink-3); }

/* --- empty state / notice ------------------------------------------------ */

.empty { padding: 44px 0; text-align: center; color: var(--ink-3); }
.empty p { margin: 0 0 4px; font-size: 17px; color: var(--ink-2); }
.empty__hint { font-size: 14px; color: var(--ink-3) !important; }

.notice {
  margin: 20px 0 0;
  font-size: 14px;
  color: var(--ink-3);
}

/* --- options ------------------------------------------------------------
 *
 * A continuous list divided by rules, not a stack of boxes. The route colour
 * appears once per option, as a short bar beside the name.
 * ----------------------------------------------------------------------- */

#options { margin-top: 4px; }

.opt { padding: 22px 0; border-top: 1px solid var(--line); }
.opt:first-of-type { border-top: none; }

.opt__head { display: flex; align-items: baseline; gap: 10px; }

.opt__head .icon--mode {
  align-self: center;
  color: var(--ink-3);
}
.opt--walk .icon--mode { color: var(--ink-3); }

.opt__titles { flex: 1; min-width: 0; }
.opt__mode {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
/* The one place a route's colour appears in the list. */
.opt--bus .opt__mode::before {
  content: '';
  width: 3px;
  height: 15px;
  flex-shrink: 0;
  background: var(--route-stripe, var(--route-colour, var(--ink-3)));
}
.opt__mode-sub { display: block; margin-top: 1px; font-size: 13.5px; color: var(--ink-3); }

.opt__time { text-align: right; flex-shrink: 0; }
.opt__time-range {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.opt__time-unit { font-size: 13px; color: var(--ink-3); margin-left: 3px; }
.opt__arrive {
  display: block;
  margin-top: 2px;
  font-size: 13.5px;
  color: var(--ink-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* The single most important line on the screen: which stop to stand at. */
.board { margin-top: 16px; }
.board__label {
  margin: 0 0 2px;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--ink-3);
}
.board__name { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.3; }
.board__zh { display: block; font-size: 15px; font-weight: 400; color: var(--ink-2); }
.board__walk { margin: 4px 0 0; font-size: 14px; color: var(--ink-3); }
.board__side { margin: 2px 0 0; font-size: 13.5px; color: var(--ink-3); font-style: italic; }

.opt__body { margin-top: 4px; }

/* --- the wait -----------------------------------------------------------
 *
 * Deliberately given its own row rather than folded into the headline or
 * buried among the legs. It is the number most likely to change someone's
 * mind, and the one an "average wait" would quietly lie about.
 * ----------------------------------------------------------------------- */

.waitline {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 16px 0 0;
  padding: 9px 11px;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface-2);
  border-left: 2px solid var(--warn);
}
.waitline .icon { margin-top: 3px; color: var(--warn); }
.waitline__text { flex: 1; min-width: 0; }
.waitline strong { color: var(--warn); font-weight: 600; }
.waitline__arrive {
  display: block;
  margin-top: 2px;
  font-size: 13.5px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* --- where the bus carries on ------------------------------------------
 *
 * The planner already weighed these and picked the best by arrival time, but
 * its walking model is an estimate over an imperfectly mapped campus. Anyone
 * who knows the ground can overrule it here.
 * ----------------------------------------------------------------------- */

.onward { margin-top: 16px; }
.onward__label {
  margin: 0 0 4px;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--ink-3);
}
.onward__list { list-style: none; margin: 0; padding: 0; }
.onward__list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 14.5px;
  color: var(--ink-3);
}
.onward__list li + li { border-top: 1px dotted var(--line); }
.onward__stop { min-width: 0; }
.onward__walk { flex-shrink: 0; font-size: 13.5px; }
/* A later stop that leaves you meaningfully closer on foot. The ranking
   prefers arriving sooner; someone facing a climb in August may not. */
.onward__item--closer { color: var(--ink); }
.onward__item--closer .onward__walk { font-weight: 600; }

/* --- leg breakdown ------------------------------------------------------ */

.legs { list-style: none; margin: 16px 0 0; padding: 0; }
.legs li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  font-size: 15px;
}
.leg__icon { color: var(--ink-3); align-self: center; }
.leg__text { flex: 1; min-width: 0; }
.leg__label { font-weight: 500; }
.leg__sub { display: block; font-size: 13px; color: var(--ink-3); }
.leg__time { flex-shrink: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- departures --------------------------------------------------------- */

.deps { margin: 14px 0 0; }
.deps__label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--ink-3);
  margin-bottom: 3px;
}
.deps__times {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.deps__time { font-size: 16px; font-weight: 500; }
.deps__time--tagged {
  border-bottom: 2px solid var(--route-colour, transparent);
  padding-bottom: 1px;
}
.deps__sep { color: var(--line-strong); }

/* --- flags -------------------------------------------------------------- */

.flag {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 12px 0 0;
  padding-left: 11px;
  border-left: 2px solid var(--line-strong);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}
.flag .icon { margin-top: 2px; color: var(--ink-3); }
.flag--warn, .flag--climb { border-left-color: var(--warn); color: var(--warn); }
.flag--warn .icon, .flag--climb .icon { color: var(--warn); }

/* Red, and the only red in the interface: boarding on the wrong side of the
   road here does not cost you a couple of minutes, it sends you round the
   entire campus. */
.flag--danger { border-left-color: var(--danger); color: var(--danger); }
.flag--danger .icon { color: var(--danger); }
.flag--boxed { padding: 9px 11px; background: var(--surface-2); }

.pick {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: var(--tap);
  margin-top: 14px;
  padding: 6px 13px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.pick:hover { color: var(--ink); border-color: var(--ink-2); }
.pick[aria-pressed="true"] { color: var(--ink); background: var(--surface-2); border-color: var(--ink-2); }

/* --- map ----------------------------------------------------------------
 *
 * One map panel, moved into whichever option is being shown, so it opens
 * directly beneath that card rather than somewhere further down the page.
 * ----------------------------------------------------------------------- */

.map-panel { margin-top: 14px; }


.map {
  height: 300px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
}
.map--network { height: 360px; margin-top: 0; }
.map-note { margin: 8px 0 0; font-size: 13px; color: var(--ink-3); }

.leaflet-container { font: inherit; background: var(--surface-2); }

/* Mute the basemap. OpenStreetMap's default tiles are colourful enough to
   compete with the route lines drawn on top, and the route is the point.
   Leaflet sets `filter` on tiles itself while they fade in, so this needs to
   be at least as specific and marked important to survive. */
.map .leaflet-tile,
.map .leaflet-tile-loaded {
  filter: saturate(0.32) brightness(1.05) contrast(0.92) sepia(0.12) !important;
}
@media (prefers-color-scheme: dark) {
  .map .leaflet-tile,
  .map .leaflet-tile-loaded {
    filter: saturate(0.3) brightness(0.76) contrast(1.06) !important;
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 16px;
  margin-top: 10px;
  font-size: 13.5px;
}
.legend__item { display: flex; align-items: center; gap: 7px; color: var(--ink-2); }
.legend__item--muted { color: var(--ink-3); }
.legend__swatch { width: 20px; height: 4px; flex-shrink: 0; }
.legend__swatch--dashed { height: 0; border-top: 4px dashed currentColor; }
.legend__swatch--dotted { height: 0; border-top: 4px dotted currentColor; }

/* --- map overlays -------------------------------------------------------- */

.stopmark, .arrowmark { background: none; border: none; }

.stopmark__dot {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  background: #fffdf8;
  border: 2px solid #1c1a15;
  border-radius: 50%;
}

/* The label sits beside the dot, not on it. Stops here are close together,
   and centred labels pile into an unreadable stack. */
.stopmark__pill {
  position: absolute;
  left: 8px;
  top: -7px;
  padding: 1px 4px;
  font: 600 10.5px/1.35 ui-sans-serif, -apple-system, sans-serif;
  white-space: nowrap;
  color: #1c1a15;
  background: rgba(255, 253, 248, .93);
  border: 1px solid rgba(28, 26, 21, .45);
  border-radius: 2px;
}
.map--network.labels-off .stopmark__pill { display: none; }

.arrowmark__svg {
  display: block;
  width: 15px;
  height: 15px;
  margin: -7.5px 0 0 -7.5px;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, .3));
}

/* --- footer ------------------------------------------------------------- */

.footer {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.55;
}
.footer p { margin: 0 0 10px; }
.footer__validity { color: var(--ink-2); font-size: 13.5px; }
.footer strong { color: var(--ink-2); font-weight: 600; }

@media (min-width: 560px) {
  :root { --gutter: 28px; }
  .header h1 { font-size: 32px; }
}

/* --- food browser -------------------------------------------------------- */

.foodlist { list-style: none; margin: 14px 0 0; padding: 0; }
.foodlist__item + .foodlist__item { border-top: 1px solid var(--line); }

.foodlist__btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 11px 0;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
}
.foodlist__btn:hover { background: var(--surface-2); }

.foodlist__main { flex: 1; min-width: 0; }
.foodlist__name { display: block; font-size: 15.5px; font-weight: 500; }
.foodlist__sub  { display: block; font-size: 13.5px; color: var(--ink-3); margin-top: 1px; }
.foodlist__dist {
  flex-shrink: 0;
  width: 62px;
  text-align: right;
  font-size: 12.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.foodlist__dist strong { display: block; font-size: 15px; color: var(--ink); font-weight: 600; }
