:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --ink: #23262b;
  --muted: #6f747c;
  --line: #e7e1d6;
  --line-strong: #d8d1c3;
  --primary: #17624f;
  --primary-ink: #ffffff;
  --gold: #b08d3f;
  --walk: #9aa3ab;
  --wait: #e3d3ae;
  --warn-bg: #fdf3e3;
  --warn-ink: #8a5a12;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(32, 28, 20, .06), 0 8px 24px rgba(32, 28, 20, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK", "Noto Sans HK", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

html {
  scroll-padding-bottom: 112px;
  scroll-padding-top: 8px;
}

.plan { scroll-margin-top: 8px; }

button, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

.topbar {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px 6px;
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .01em;
}
.topbar .sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── 起點／終點 ─────────────────────────────── */
.pickers {
  position: relative;
  padding: 6px 14px 6px 14px;
}

.picker {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 40px 8px 0;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}
.pickers .picker:last-of-type { border-bottom: 0; }

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.dot--from { background: var(--primary); }
.dot--to { background: var(--gold); }

.picker__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.picker__label { font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }
.picker__value {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.picker__value.is-empty { color: #a8adb5; font-weight: 500; }

.swap {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
}
.swap:active { background: #eee8dd; }

/* ── 時間 chips ─────────────────────────────── */
.times {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
}
.chip {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.chip.is-on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip:active { transform: scale(.98); }

.time-input {
  width: 92px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  font-size: 16px;
  letter-spacing: .06em;
}

/* ── CTA ────────────────────────────────────── */
.cta {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, rgba(247,244,239,0));
  pointer-events: none;
}
.go {
  pointer-events: auto;
  display: block;
  width: 100%;
  max-width: 528px;
  margin: 0 auto;
  min-height: 56px;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(23, 98, 79, .22);
}
.go[disabled] { background: #cfc9bd; color: #fff; box-shadow: none; }
.go:active:not([disabled]) { transform: translateY(1px); }

/* ── 結果 ───────────────────────────────────── */
.results { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

.notice {
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
}
.notice--warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #f0dfbf; }
.notice--plain {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}
.notice h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
}
.notice p { margin: 6px 0 0; }
.notice .stop-line { margin: 6px 0 0; color: var(--muted); }
.notice__actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

.ghost {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ghost--wide {
  width: 100%;
  min-height: 48px;
  margin-top: 2px;
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

/* ── 方案卡 ─────────────────────────────────── */
.plan {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.plan__head {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "badge total" "meta meta" "bar bar";
  gap: 2px 10px;
  align-items: baseline;
  padding: 14px 16px 12px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.badge {
  grid-area: badge;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--primary);
}
.total {
  grid-area: total;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.total b { font-size: 26px; }
.total span { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }

.meta {
  grid-area: meta;
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.bar {
  grid-area: bar;
  display: flex;
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #f1ece2;
}
.bar i { display: block; height: 100%; min-width: 5px; }
.bar .b-walk { background: var(--walk); }
.bar .b-bus { background: var(--primary); }
.bar .b-wait { background: var(--wait); }

.legend {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.legend > span:nth-child(2) { text-align: center; }
.legend > span:nth-child(3) { text-align: right; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: 1px; }

/* ── 步驟 ───────────────────────────────────── */
.steps { padding: 0 16px 14px; border-top: 1px solid var(--line); }
.step {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  padding: 12px 0;
  position: relative;
}
.step + .step { border-top: 1px dashed #ece6da; }
.step__icon {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 11px;
  background: #f1ece2;
  color: var(--muted);
}
.step--stop .step__icon { background: var(--primary); color: #fff; }
.step__body { min-width: 0; }
.step__top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.step__title { font-size: 14.5px; font-weight: 600; }
.step__time { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.step__detail { font-size: 13px; color: var(--muted); margin-top: 2px; }
.step__detail strong { color: var(--ink); font-weight: 600; }
.ride-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
}
.op-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ── 站列（巴士停邊幾站） ─────────────────── */
.step--ride { grid-template-columns: 1fr; }
.step--ride .step__body { width: 100%; }

.stops {
  list-style: none;
  margin: 8px 0 6px;
  padding: 0;
}
.stops__row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding-left: 22px;
  font-size: 13.5px;
  color: var(--ink);
}
.stops__row::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #e3ded2;
}
.stops__row:first-child::before { top: 50%; }
.stops__row:last-child::before { bottom: 50%; }

.stops__dot {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #cfc8ba;
  box-sizing: border-box;
}
.stops__row.is-board .stops__dot {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 98, 79, .15);
}
.stops__row.is-alight .stops__dot {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(176, 141, 63, .18);
}
.stops__row.is-past,
.stops__row.is-after { opacity: .42; }
.stops__row.is-past .stops__name,
.stops__row.is-after .stops__name { font-size: 12.5px; }

.stops__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stops__row.is-board .stops__name,
.stops__row.is-alight .stops__name { font-weight: 700; }

.stops__tag {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--primary);
  background: #e7f0ec;
  border-radius: 6px;
  padding: 2px 8px;
}
.stops__tag--off {
  color: #7a5a12;
  background: #f7edd7;
}

/* ── 地點 sheet ─────────────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.sheet[hidden] { display: none; }
.sheet__head {
  display: grid;
  grid-template-columns: 1fr 44px;
  grid-template-areas: "title close" "search search";
  gap: 6px;
  padding: 12px 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.sheet__title { grid-area: title; font-size: 15px; font-weight: 700; align-self: center; }
.sheet__close {
  grid-area: close;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}
.sheet__search {
  grid-area: search;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  font-size: 16px;
}
.sheet__list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0 calc(20px + env(safe-area-inset-bottom));
}
.opt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 18px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}
.opt:active { background: #efe9dd; }
.opt__name { font-size: 15.5px; font-weight: 600; }
.opt__meta { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.opt__area {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--muted);
  background: #f1ece2;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}
.empty { padding: 24px 18px; color: var(--muted); font-size: 14px; }

.foot {
  max-width: 560px;
  margin: 18px auto 0;
  padding: 0 16px;
  font-size: 11.5px;
  color: #9aa0a8;
  line-height: 1.5;
}

@media (min-width: 600px) {
  .topbar { padding-top: 22px; }
  body { padding-bottom: 120px; }
}
