:root {
  --red: #c8102e;
  --red-dark: #970d1c;
  --bg: #efeeea;
  --card: #fff;
  --soft: #f4f4f6;
  --ink: #101216;
  --muted: #71757d;
  --faint: #9b9ea4;
  --line: #e6e6ea;
  --green: #087d3b;
  --soon: #d0111f;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --shadow: 0 1px 2px rgba(16,18,22,.05), 0 5px 14px rgba(16,18,22,.05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(16,18,22,.06) 1px, transparent 1px);
  background-size: 22px 22px;
  font-family: Arial, "PingFang HK", "Microsoft JhengHei", "Noto Sans HK", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.view { display: none; }
.view.active { display: block; }

/* Full-screen board follows the reference site's information hierarchy. */
body.pins-full .topbar { display: none; }
body.pins-full #main { max-width: none; padding: 0; }
.board { min-height: 100dvh; display: flex; flex-direction: column; background: #fff; }
.board-head {
  display: flex; align-items: flex-start; gap: 14px; color: #fff;
  padding: calc(var(--safe-t) + 22px) 20px 17px;
  background: linear-gradient(118deg, #e3242c 0%, #c8121b 52%, #980d18 100%);
}
.board-head-main { flex: 1; min-width: 0; }
.board-weather { font-size: clamp(38px, 11vw, 54px); font-weight: 800; line-height: 1; letter-spacing: -.04em; text-shadow: 0 1px 2px rgba(0,0,0,.18); }
.board-forecast { margin-top: 9px; font-size: 14px; font-weight: 550; color: rgba(255,255,255,.9); max-width: 570px; }
.board-tools { display: flex; gap: 8px; flex: none; }
.glass-button { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; color: #fff; background: rgba(255,255,255,.18); }
.glass-button svg { width: 18px; height: 18px; }
.glass-button.on { color: var(--red); background: #fff; }
.glass-button.busy svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.warning-strip { display: flex; flex-wrap: wrap; gap: 7px; min-height: 0; margin-top: 12px; }
.warning-chip { border: 1px solid rgba(255,255,255,.4); border-radius: 999px; padding: 5px 10px; color: #fff; background: rgba(77,0,10,.25); font-size: 12px; font-weight: 700; line-height: 1.2; }
.warning-chip.hot { color: #77130a; background: #ffd8b0; border-color: #ffdfc0; }
.warning-chip.rain { color: #5b3900; background: #ffe5a0; border-color: #ffedbd; }
.warning-chip.danger { color: #fff; background: #650000; border-color: #ffb4b4; }
.warning-chip.cold { color: #073966; background: #cbeaff; border-color: #e4f4ff; }
.warning-none { font-size: 12px; color: rgba(255,255,255,.78); }

.board-cols { display: flex; justify-content: space-between; align-items: center; padding: 11px 20px; color: #fff; background: var(--red); border-top: 1px solid rgba(255,255,255,.17); font-size: 14px; font-weight: 750; }
.board-rows { flex: 1; background: #fff; }
.arrival-card { display: flex; align-items: center; gap: 10px; min-height: 92px; padding: 15px 20px; border-bottom: 1px solid var(--line); position: relative; }
.arrival-card-head { min-width: 0; flex: 1; }
.operator-label { font-size: 12.5px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-label { font-size: 29px; line-height: 1.08; font-weight: 850; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.direction-label { margin-top: 4px; font-size: 15.5px; color: var(--ink); font-weight: 750; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.direction-label.mtr-direction { white-space: normal; overflow: visible; text-overflow: clip; }
.route-label.line-tile { display: inline-block; width: fit-content; margin-top: 4px; padding: 5px 10px; border-radius: 7px; background: var(--line-color); color: var(--line-text); font-size: 20px; line-height: 1.15; letter-spacing: 0; }
.scheduled-label { display: inline-block; margin-top: 4px; padding: 2px 6px; border-radius: 4px; background: #eaf6dc; color: #3d6812; font-size: 10px; font-weight: 700; }
.arrival-numbers { width: 116px; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 59px; }
.arrival-first { min-height: 38px; color: var(--green); font-size: 34px; font-weight: 850; letter-spacing: -.04em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.arrival-first.soon { color: var(--soon); }
.arrival-first.word { min-height: auto; font-size: 23px; letter-spacing: -.02em; white-space: nowrap; }
.arrival-unit { margin-top: -8px; font-size: 11px; font-weight: 650; color: var(--muted); }
.arrival-rest { margin-top: 3px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.arrival-rest.mtr-rest { display: flex; flex-direction: column; gap: 2px; line-height: 1.25; }
.mtr-rest-row { display: block; }
.arrival-error { font-size: 12px; color: var(--muted); text-align: center; }
.edit-actions { width: 72px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.edit-actions button { height: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); color: var(--muted); padding: 0; }
.edit-actions button.remove { color: #fff; background: var(--red); border-color: var(--red); }
.empty-board { padding: 50px 28px; color: var(--muted); text-align: center; line-height: 1.6; }
.empty-board h3 { margin: 0 0 5px; color: var(--ink); font-size: 18px; }
.empty-board p { margin: 0 auto 18px; max-width: 420px; }
.empty-board button { border: 0; border-radius: 999px; padding: 9px 18px; color: #fff; background: var(--red); font-weight: 700; }
.board-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 20px calc(11px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--soft); color: var(--muted); font-size: 12px; }
.network-state { white-space: nowrap; }
.network-state i { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--green); vertical-align: 1px; }
.network-state.error i { background: var(--soon); }

/* Search and detail screens */
.topbar { position: sticky; top: 0; z-index: 20; padding: calc(var(--safe-t) + 9px) 14px 9px; border-bottom: 1px solid var(--line); background: rgba(239,238,234,.91); backdrop-filter: blur(14px) saturate(170%); }
.topbar-row { display: flex; align-items: center; gap: 12px; }
.text-button { flex: none; border: 0; background: none; color: var(--red); padding: 6px 2px; font-size: 14px; }
.provider-tabs { flex: 1; min-width: 0; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.provider-tabs::-webkit-scrollbar { display: none; }
.provider-tab { flex: none; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: var(--muted); font-size: 12px; font-weight: 700; }
.provider-tab.active { color: #fff; border-color: var(--red); background: var(--red); }
#main { max-width: 680px; margin: 0 auto; padding: 13px 16px calc(28px + var(--safe-b)); }
.search-panel h1 { margin: 2px 0 12px; font-size: 22px; }
.search-box { display: flex; align-items: center; gap: 7px; padding: 0 11px; border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.search-box > svg { width: 18px; height: 18px; color: var(--faint); flex: none; }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 13px 2px; background: transparent; }
.search-box button { width: 23px; height: 23px; padding: 0; border: 0; border-radius: 50%; background: var(--soft); color: var(--muted); }
.source-note, .results-caption { margin: 7px 2px 10px; color: var(--faint); font-size: 12px; }
.result-list + .results-caption { margin-top: 22px; }
.search-content { min-height: 180px; }
.message-card, .loading-card { border-radius: 14px; padding: 28px 18px; background: #fff; box-shadow: var(--shadow); color: var(--muted); text-align: center; }
.loading-card span { display: inline-block; width: 7px; height: 7px; margin: 0 3px; border-radius: 50%; background: var(--red); animation: pulse 1s infinite alternate; }
.loading-card span:nth-child(2) { animation-delay: .15s; }.loading-card span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { to { opacity: .22; transform: translateY(-3px); } }
.result-list, .stop-list { display: flex; flex-direction: column; gap: 9px; }
.result-card, .stop-card { overflow: hidden; border: 0; border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.result-card { width: 100%; display: flex; align-items: center; gap: 12px; padding: 13px 14px; text-align: left; }
.route-badge { min-width: 62px; padding: 6px 8px; border-radius: 9px; color: var(--badge-text, #fff); background: var(--badge, var(--red)); font-weight: 800; text-align: center; }
.route-badge.mtr { min-width: 68px; font-size: 13px; }
.result-main { flex: 1; min-width: 0; display: block; }
.result-title, .result-sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-title { font-size: 15px; font-weight: 700; }.result-sub { margin-top: 2px; color: var(--muted); font-size: 12px; }
.result-arrow { color: var(--faint); font-size: 22px; }
.detail-heading { display: flex; align-items: center; gap: 10px; margin: 3px 0 12px; }
.detail-heading h2 { margin: 0; font-size: 21px; }.detail-heading p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.detail-back { width: 36px; height: 36px; display: grid; place-items: center; flex: none; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: #fff; color: var(--red); }
.detail-back svg { width: 18px; height: 18px; }
.stop-row { width: 100%; display: flex; align-items: center; gap: 11px; padding: 12px 14px; border: 0; background: transparent; text-align: left; }
.stop-seq { width: 26px; height: 26px; display: grid; place-items: center; flex: none; border-radius: 50%; background: var(--soft); color: var(--muted); font-size: 12px; font-weight: 700; }
.stop-name { flex: 1; font-weight: 650; }.stop-expand { color: var(--faint); font-size: 19px; }
.eta-panel { padding: 12px 14px 14px; border-top: 1px solid var(--line); background: var(--soft); }
.eta-grid { display: flex; gap: 8px; overflow-x: auto; }
.eta-chip { min-width: 84px; padding: 8px 9px; border-radius: 10px; background: #fff; text-align: center; }
.eta-chip strong { display: block; color: var(--green); font-size: 24px; line-height: 1; }.eta-chip strong.soon { color: var(--soon); }
.eta-chip > span { font-size: 10px; color: var(--muted); }.eta-chip small { display: block; margin-top: 4px; color: var(--faint); font-size: 10px; white-space: nowrap; }
.eta-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.pin-button, .all-stop-button { margin: 10px 7px 0 0; padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); font-size: 12px; font-weight: 700; }
.pin-button.active { color: #fff; border-color: var(--red); background: var(--red); }
.all-stop-button { color: var(--red); }
.direction-group { padding-top: 12px; }.direction-group + .direction-group { margin-top: 12px; border-top: 1px solid var(--line); }
.direction-title { margin: 0 0 8px; font-weight: 750; }
.stop-board-row { display: grid; grid-template-columns: 68px minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.stop-board-row:last-child { border-bottom: 0; }.stop-route { color: var(--red); font-size: 21px; font-weight: 850; }.stop-dest { min-width: 0; font-size: 13px; font-weight: 650; }.stop-dest small { display: block; color: var(--muted); font-weight: 400; }
.stop-times { color: var(--green); font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }.stop-times.soon { color: var(--soon); }

.warning-dialog { width: min(580px, calc(100% - 28px)); max-height: 82dvh; padding: 0; border: 0; border-radius: 18px; box-shadow: 0 22px 80px rgba(0,0,0,.3); }
.warning-dialog::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.dialog-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 18px; color: #fff; background: linear-gradient(118deg,#e3242c,#990d18); }
.dialog-kicker { font-size: 11px; opacity: .8; }.dialog-head h2 { margin: 2px 0 0; font-size: 21px; }.dialog-head button { width: 32px; height: 32px; border: 0; border-radius: 50%; color: #fff; background: rgba(255,255,255,.2); font-size: 22px; }
.warning-body { padding: 18px; color: #30333a; line-height: 1.65; }.warning-body p { margin: 0 0 12px; }.warning-time { color: var(--muted); font-size: 12px; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 9px 14px; border-radius: 999px; color: #fff; background: rgba(16,18,22,.9); font-size: 13px; transition: .2s; }.toast.show { opacity: 1; transform: translate(-50%,0); }

@media (max-width: 520px) {
  .board-head { padding-left: 16px; padding-right: 14px; }
  .board-tools { gap: 5px; }.glass-button { width: 33px; height: 33px; }
  .board-weather { font-size: 38px; }.board-forecast { font-size: 12px; }
  .arrival-card { padding-left: 16px; padding-right: 14px; }.arrival-numbers { width: 102px; }
  .board-cols, .board-foot { padding-left: 16px; padding-right: 16px; }
  .network-state { display: none; }
  .stop-board-row { grid-template-columns: 54px minmax(0,1fr) auto; }.stop-route { font-size: 18px; }
}

@media (min-width: 760px) {
  .board-head, .board-cols, .board-rows, .board-foot { padding-left: max(24px, calc((100vw - 820px) / 2)); padding-right: max(24px, calc((100vw - 820px) / 2)); }
  .board-rows { padding-left: max(0px, calc((100vw - 868px) / 2)); padding-right: max(0px, calc((100vw - 868px) / 2)); }
  .arrival-card { padding-left: 24px; padding-right: 24px; }
}
