:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #15191e;
  --muted: #69727d;
  --line: #e4e7eb;
  --soft: #eef1f4;
  --accent: #0f766e;
  --accent-soft: #e0f2ef;
  --ok: #15803d;
  --ok-soft: #e3f5e8;
  --warn: #b45309;
  --warn-soft: #fdf0dd;
  --bad: #c62828;
  --bad-soft: #fde7e7;
  --bus: #2563eb;
  --train: #0f766e;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1113; --card: #191d21; --text: #eceff2; --muted: #9aa3ad; --line: #2a3036; --soft: #22282d;
    --accent: #2dd4bf; --accent-soft: #10302c; --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #33270f;
    --bad: #f87171; --bad-soft: #3a1717; --bus: #60a5fa; --train: #2dd4bf;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { margin: 0; }
input, select, button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 版面 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 24px; font-weight: 800; letter-spacing: .5px; }
main { max-width: 640px; margin: 0 auto; padding: 4px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.2; }

/* ---------- 基本元件 ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px #0000000d, 0 1px 2px #00000008; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06201d; } }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 14px; border-radius: 10px; }
.link { border: 0; background: none; color: var(--accent); padding: 8px 4px; cursor: pointer; font-size: 16px; }
.link.strong { font-weight: 700; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 50%; font-size: 20px; color: var(--muted); cursor: pointer; }
.icon-btn:active { background: var(--soft); }

.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--soft); font-size: 16px; appearance: none; -webkit-appearance: none;
}
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.row:last-child { margin-bottom: 0; }

.switch { display: flex; align-items: center; gap: 8px; min-height: 46px; font-size: 15px; white-space: nowrap; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; transition: background .2s; margin: 0; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px #0003; transition: transform .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

.segmented { display: flex; gap: 4px; padding: 4px; background: var(--soft); border-radius: 12px; margin-bottom: 12px; overflow-x: auto; }
.segmented button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; cursor: pointer; }
.segmented button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px #0002; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.chips:empty { display: none; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 14px; cursor: pointer; }
.chip:active { background: var(--soft); }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.tight, .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.missed, .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.unknown, .pill.gray { background: var(--soft); color: var(--muted); }
.pill.tpass { background: var(--accent-soft); color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); font-size: 14px; margin: 8px 0 0; }
.error:empty { display: none; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 14px; margin: 16px 0 8px; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-icon { font-size: 44px; margin-bottom: 8px; }
.empty p { margin: 0 0 16px; }
.empty ol { text-align: left; display: inline-block; margin: 0 0 20px; padding-left: 20px; line-height: 1.9; }

.skeleton { height: 18px; border-radius: 8px; background: linear-gradient(90deg, var(--soft), var(--line), var(--soft)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin: 10px 0; }
.skeleton.big { height: 34px; width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 帳號 ---------- */
.avatar-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; padding: 0; overflow: hidden; background: var(--accent-soft); color: var(--accent); font-weight: 800; cursor: pointer; }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.popover { position: absolute; right: 16px; top: calc(env(safe-area-inset-top) + 56px); background: var(--card); border-radius: 14px; box-shadow: 0 8px 30px #0003; padding: 6px; min-width: 180px; z-index: 20; }
.popover-title { padding: 10px 12px 6px; font-weight: 700; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 10px; font-size: 15px; cursor: pointer; }
.menu-item:active, .menu-item:hover { background: var(--soft); }
.menu-item.danger { color: var(--bad); }

/* ---------- 登入 ---------- */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--card); border-radius: 24px; padding: 36px 28px; max-width: 400px; width: 100%; text-align: center; box-shadow: 0 10px 40px #0000001a; }
.login-card img { border-radius: 18px; }
.login-card h1 { font-size: 26px; margin: 12px 0 6px; }
.login-card > p { color: var(--muted); margin: 0 0 20px; }
.login-points { list-style: none; padding: 16px; margin: 0 0 24px; text-align: left; background: var(--soft); border-radius: 14px; line-height: 2; font-size: 15px; }
.line-btn { display: flex; align-items: center; justify-content: center; min-height: 52px; background: #06c755; color: #fff; text-decoration: none; font-weight: 800; font-size: 17px; border-radius: 14px; }
.line-btn:active { background: #05b34c; }

/* ---------- 通勤卡片 ---------- */
.commute { padding: 18px 18px 12px; position: relative; }
.commute-top { display: flex; align-items: center; gap: 8px; }
.commute-top h2 { font-size: 17px; flex: 1; }
.hero { margin: 10px 0 4px; }
.hero-main { font-size: 34px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.hero-main.now { color: var(--bad); }
.hero-main small { font-size: 18px; font-weight: 700; margin-left: 2px; }
.hero-sub { color: var(--muted); font-size: 15px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero-sub b { color: var(--text); }

.timeline { list-style: none; margin: 16px 0 6px; padding: 0; }
.tl { display: grid; grid-template-columns: 44px 1fr; column-gap: 10px; position: relative; }
.tl::before { content: ""; position: absolute; left: 21px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.tl:first-child::before { top: 22px; }
.tl:last-child::before { bottom: calc(100% - 22px); }
.tl-time { grid-column: 1; text-align: center; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; padding-top: 2px; }
.tl-dot { position: relative; z-index: 1; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; background: var(--soft); }
.tl.bus .tl-dot { background: color-mix(in srgb, var(--bus) 14%, var(--card)); }
.tl.tra .tl-dot { background: color-mix(in srgb, var(--train) 16%, var(--card)); }
.tl-body { padding: 2px 0 16px; min-width: 0; }
.tl-title { font-weight: 700; font-size: 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tl-line { display: flex; gap: 8px; font-size: 15px; margin-top: 2px; }
.tl-line .t { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 44px; }
.tl-note { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tl.walk .tl-dot { width: 44px; height: 30px; background: none; font-size: 16px; }
.tl.walk .tl-body { padding: 4px 0 10px; color: var(--muted); font-size: 14px; }

.commute-foot { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.commute .menu-btn { position: absolute; right: 8px; top: 10px; }
.commute .popover { top: 48px; right: 10px; }

/* ---------- 列表 ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; letter-spacing: .5px; }

/* 台鐵 */
.od { display: grid; grid-template-columns: 1fr 44px; grid-template-rows: auto auto; gap: 8px 8px; margin-bottom: 12px; }
.od .field:first-child { grid-column: 1; grid-row: 1; }
.od .field:last-child { grid-column: 1; grid-row: 2; }
.od .swap { grid-column: 2; grid-row: 1 / span 2; align-self: center; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 20px; cursor: pointer; }
.train { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.train:last-child { border-bottom: 0; }
.train .times { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.train .times s { font-size: 13px; font-weight: 500; color: var(--muted); display: block; line-height: 1; }
.train .arrow { color: var(--muted); font-weight: 400; margin: 0 2px; }
.train .info { min-width: 0; }
.train .info b { font-size: 15px; }
.train .side { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.train.next { background: linear-gradient(90deg, var(--accent-soft), transparent 70%); margin: 0 -16px; padding: 14px 16px; border-radius: 0; }
.countdown { color: var(--accent); font-weight: 700; font-size: 13px; }

/* 公車 */
.stop-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.stop-row:last-child { border-bottom: 0; }
.stop-row .seq { width: 22px; height: 22px; border-radius: 50%; background: var(--soft); color: var(--muted); font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: none; }
.stop-row .name { flex: 1; min-width: 0; }
.stop-row.coming .seq { background: var(--bus); color: #fff; }
.eta { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.eta.now { color: var(--bad); }
.eta.soon { color: var(--warn); }
.eta.off { color: var(--muted); font-weight: 500; font-size: 14px; }
.route-chip { display: inline-grid; place-items: center; min-width: 52px; padding: 4px 8px; border-radius: 8px; background: color-mix(in srgb, var(--bus) 12%, var(--card)); color: var(--bus); font-weight: 800; font-size: 15px; }
.station-row .dist { color: var(--muted); font-size: 14px; }

/* ---------- 編輯器（底部彈出） ---------- */
dialog.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92vh; border-radius: 22px 22px 0 0; background: var(--bg); color: var(--text); }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 22px; } }
dialog.sheet::backdrop { background: #0008; }
dialog.sheet[open] { animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet-head h2 { text-align: center; font-size: 17px; }
.sheet-head .link:last-child { text-align: right; }
.sheet-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; }
#name-chips { margin-top: 8px; }
.step { background: var(--card); border-radius: 14px; padding: 12px 14px; margin: 12px 0; display: flex; align-items: center; gap: 10px; }
.step-icon { font-size: 22px; }
.inline { font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.num { width: 64px; min-height: 40px; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); text-align: center; font-size: 16px; }
.leg { background: var(--card); border-radius: 14px; padding: 14px; margin: 12px 0; border-left: 4px solid var(--bus); }
.leg.tra { border-left-color: var(--train); }
.leg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.leg-head h3 { font-size: 16px; }
.leg .row { flex-wrap: wrap; }
.leg .segmented { margin-bottom: 12px; }
.leg .estimate { font-size: 13px; color: var(--accent); margin-top: 4px; }
.leg-walk { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; padding-top: 4px; }

/* ---------- 怎麼去 / 搜尋 ---------- */
.tabbar a span { font-size: 11px; }
.search-bar { display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: 14px; padding: 4px 6px 4px 12px; box-shadow: 0 1px 3px #0000000d; margin-bottom: 10px; border: 1px solid var(--line); }
.search-bar:focus-within { outline: 2px solid var(--accent); border-color: transparent; }
.search-bar input { flex: 1; min-width: 0; border: 0; background: none; font-size: 17px; padding: 12px 4px; outline: none; }
.search-bar.small-bar input { font-size: 15px; padding: 8px 4px; }
.search-icon { font-size: 16px; opacity: .7; }
.mic-inline { border: 0; background: var(--accent-soft); width: 42px; height: 42px; border-radius: 12px; font-size: 20px; cursor: pointer; }
.from-line { font-size: 14px; color: var(--muted); margin: 0 4px 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.from-btn { border: 0; background: var(--soft); border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; }
.chip.fav { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 700; }
.dest { display: flex; align-items: flex-start; gap: 10px; }
.dest h2 { font-size: 19px; }
.dest .sub { font-size: 13px; color: var(--muted); }
.dest-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.alt-places { margin-top: 10px; font-size: 13px; color: var(--muted); }
.alt-places .chip { font-size: 13px; padding: 3px 10px; }
.route-card { padding: 16px; }
.route-card.best { outline: 2px solid var(--accent); }
.route-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.route-head .mins { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.route-head .mins small { font-size: 16px; font-weight: 700; margin-left: 2px; }
.route-head .when { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.route-head .when b { color: var(--text); }
.route-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.badge-best { font-size: 12px; font-weight: 800; color: #fff; background: var(--accent); border-radius: 6px; padding: 1px 8px; }
@media (prefers-color-scheme: dark) { .badge-best { color: #06201d; } }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); }
.steps li:first-child { border-top: 0; }
.steps .ic { font-size: 20px; text-align: center; }
.steps .main { font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.steps .detail { font-size: 14px; color: var(--muted); margin-top: 2px; }
.steps .walk { color: var(--muted); font-size: 14px; }
.line-chip { display: inline-grid; place-items: center; min-width: 40px; padding: 1px 8px; border-radius: 7px; font-weight: 800; font-size: 14px; background: color-mix(in srgb, var(--bus) 14%, var(--card)); color: var(--bus); }
.line-chip.tra { background: color-mix(in srgb, var(--train) 16%, var(--card)); color: var(--train); }
.line-chip.highway { background: color-mix(in srgb, #9333ea 14%, var(--card)); color: #9333ea; }
.speak-btn { margin-left: auto; }

/* ---------- 語音 ---------- */
.voice-btn { margin-left: auto; margin-right: 10px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 40%, transparent); }
.voice-btn svg, .listen-ring svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#listening { position: fixed; inset: 0; z-index: 60; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: grid; place-items: center; padding: 24px; }
.listen-box { text-align: center; max-width: 320px; }
.listen-ring { width: 96px; height: 96px; margin: 0 auto 20px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; animation: pulse 1.4s infinite; }
.listen-ring svg { width: 40px; height: 40px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); } 70% { box-shadow: 0 0 0 28px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
#listen-text { font-size: 22px; font-weight: 800; min-height: 1.5em; margin: 0 0 8px; }
.small-switch { font-size: 15px; min-height: 0; }
.fav-row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.fav-row .grow b { display: block; }

/* =====================================================================
   動畫
   ===================================================================== */
:root { --spring: cubic-bezier(.2, .9, .25, 1.15); --ease-out: cubic-bezier(.2, .8, .2, 1); }

@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes blink { 50% { opacity: .35; } }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.06); } 30% { transform: scale(1); } 45% { transform: scale(1.04); } }
@keyframes glow { 0% { box-shadow: inset 4px 0 0 var(--accent); } 50% { box-shadow: inset 4px 0 0 var(--accent), 0 0 0 4px var(--accent-soft); } 100% { box-shadow: inset 4px 0 0 var(--accent); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes tick { from { transform: translateY(60%); opacity: 0; } }
@keyframes draw { from { transform: scaleY(0); } }
@keyframes breathe { 0%, 100% { box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent); }
  50% { box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 0 6px transparent; } }
@keyframes wave { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }
@keyframes sheet-down { to { transform: translateY(60px); opacity: 0; } }
@keyframes backdrop-in { from { opacity: 0; } }
@keyframes confetti { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }

/* 逐一浮現：容器加 .stagger，子元素依序出現 */
.stagger > * { animation: rise .5s var(--ease-out) both; }
.stagger > :nth-child(2) { animation-delay: .05s; }
.stagger > :nth-child(3) { animation-delay: .1s; }
.stagger > :nth-child(4) { animation-delay: .15s; }
.stagger > :nth-child(5) { animation-delay: .2s; }
.stagger > :nth-child(6) { animation-delay: .25s; }
.stagger > :nth-child(7) { animation-delay: .3s; }
.stagger > :nth-child(8) { animation-delay: .35s; }
.stagger > :nth-child(9) { animation-delay: .4s; }
.stagger > :nth-child(n+10) { animation-delay: .45s; }
/* 自動更新時不要整張重播 */
.calm .stagger > *, .calm.stagger > *, .calm .tl::before, .calm .tl-dot { animation: none !important; }

/* 分頁切換：支援 View Transitions 的瀏覽器左右滑動，其餘淡入 */
main { view-transition-name: page; }
.topbar h1 { view-transition-name: title; }
.tabbar { view-transition-name: tabbar; }
::view-transition-group(page) { animation-duration: .32s; animation-timing-function: var(--ease-out); }
::view-transition-old(page) { animation: .2s ease-in both vt-out-left; }
::view-transition-new(page) { animation: .32s var(--ease-out) both vt-in-right; }
html[data-nav="back"]::view-transition-old(page) { animation-name: vt-out-right; }
html[data-nav="back"]::view-transition-new(page) { animation-name: vt-in-left; }
::view-transition-old(title) { animation: .15s ease-in both fade reverse; }
::view-transition-new(title) { animation: .3s var(--ease-out) both tick; }
/* 分頁列不參與換頁動畫，直接顯示即時畫面，讓指示條在圖示後面滑動 */
::view-transition-old(tabbar) { display: none; }
::view-transition-new(tabbar) { animation: none; }
@keyframes vt-out-left { to { opacity: 0; transform: translateX(-28px); } }
@keyframes vt-in-right { from { opacity: 0; transform: translateX(36px); } }
@keyframes vt-out-right { to { opacity: 0; transform: translateX(28px); } }
@keyframes vt-in-left { from { opacity: 0; transform: translateX(-36px); } }
@supports not (view-transition-name: a) { .view { animation: rise .35s var(--ease-out) both; } }

/* 底部分頁列：滑動指示 + 圖示彈跳 */
.tabbar { position: fixed; }
.tab-indicator { position: absolute; top: 6px; left: 0; height: 44px; width: calc(100% / var(--tabs, 5)); pointer-events: none;
  transform: translateX(calc(var(--tab, 0) * 100%)); transition: transform .38s var(--spring); }
.tab-indicator::before { content: ""; position: absolute; inset: 0 18%; border-radius: 14px; background: var(--accent-soft); }
.tabbar a { position: relative; z-index: 1; transition: color .2s; }
.tabbar a.active svg { animation: pop .45s var(--spring); }

/* 按壓回饋 */
.btn, .chip, .segmented button, .tabbar a, .icon-btn, .from-btn, .mic-inline, .voice-btn, .swap, .menu-item, .link {
  transition: transform .18s var(--spring), background-color .2s, color .2s, box-shadow .2s; }
.btn:active, .chip:active, .from-btn:active, .mic-inline:active, .swap:active { transform: scale(.94); }
.segmented button:active, .menu-item:active { transform: scale(.97); }
.voice-btn:active { transform: scale(.88); }
.swap { transition: transform .45s var(--spring); }
.swap.flip { transform: rotate(180deg); }
.segmented button.on { animation: pop .3s var(--spring); }

/* 卡片、彈出 */
.popover:not([hidden]) { animation: pop .22s var(--spring); transform-origin: top right; }
#toast.show { transition: opacity .2s, transform .4s var(--spring); }
.empty-icon { display: inline-block; animation: float 3.2s ease-in-out infinite; }
.pill { animation: pop .35s var(--spring) both; }
.skeleton { animation: shimmer 1.2s infinite, fade .3s both; }
dialog.sheet[open] { animation: up .38s var(--spring); }
dialog.sheet[open]::backdrop { animation: backdrop-in .25s ease both; }
dialog.sheet.closing { animation: sheet-down .2s ease-in both; }
dialog.sheet.closing::backdrop { animation: backdrop-in .2s ease reverse both; }
.leg { animation: rise .4s var(--ease-out) both; }

/* 通勤卡片 */
.hero-main { display: inline-block; }
.hero-main.tick { animation: tick .45s var(--spring); }
.hero-main.now { animation: beat 1.6s ease-in-out infinite; transform-origin: left center; }
.tl::before { transform-origin: top; animation: draw .5s var(--ease-out) both; }
.tl-dot { animation: pop .45s var(--spring) both; }
.timeline > :nth-child(2) .tl-dot, .timeline > :nth-child(2)::before { animation-delay: .08s; }
.timeline > :nth-child(3) .tl-dot, .timeline > :nth-child(3)::before { animation-delay: .16s; }
.timeline > :nth-child(4) .tl-dot, .timeline > :nth-child(4)::before { animation-delay: .24s; }
.timeline > :nth-child(5) .tl-dot, .timeline > :nth-child(5)::before { animation-delay: .32s; }
.timeline > :nth-child(6) .tl-dot, .timeline > :nth-child(6)::before { animation-delay: .4s; }
.timeline > :nth-child(n+7) .tl-dot, .timeline > :nth-child(n+7)::before { animation-delay: .48s; }
.tl.next .tl-dot { animation: pop .45s var(--spring) both, bob 2.2s ease-in-out .6s infinite; box-shadow: 0 0 0 3px var(--card), 0 0 0 5px color-mix(in srgb, var(--bus) 35%, transparent); }
.tl.tra.next .tl-dot { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px color-mix(in srgb, var(--train) 40%, transparent); }
.calm .tl.next .tl-dot { animation: bob 2.2s ease-in-out infinite !important; }
.spin-icon { display: inline-block; }
.spinning .spin-icon { animation: spin .8s linear infinite; }

/* 即時狀態 */
.eta.now::before, .pill.warn::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 1px; animation: blink 1s ease-in-out infinite; }
.stop-row.coming .seq { animation: beat 1.4s ease-in-out infinite; }
.train.next { animation: rise .5s var(--ease-out) both, glow 2.4s ease-in-out .5s 2; }
.route-card.best { animation: rise .5s var(--ease-out) both; }
.countdown { display: inline-block; animation: blink 2s ease-in-out infinite; }

/* 語音 */
.voice-btn { animation: breathe 2.8s ease-in-out infinite; }
.listen-box { animation: pop .35s var(--spring); }
#listening:not([hidden]) { animation: backdrop-in .2s ease both; }
.wave { display: flex; justify-content: center; align-items: center; gap: 5px; height: 32px; margin: 4px 0 16px; }
.wave span { width: 5px; height: 100%; border-radius: 3px; background: var(--accent); transform-origin: center; animation: wave 1s ease-in-out infinite; }
.wave span:nth-child(2) { animation-delay: -.8s; animation-duration: .9s; }
.wave span:nth-child(3) { animation-delay: -.3s; animation-duration: 1.15s; }
.wave span:nth-child(4) { animation-delay: -.6s; animation-duration: .85s; }
.wave span:nth-child(5) { animation-delay: -.15s; animation-duration: 1.05s; }
#listen-text.heard { animation: tick .3s var(--spring); }

/* 慶祝小彩帶 */
.confetti { position: fixed; z-index: 70; width: 8px; height: 12px; border-radius: 2px; pointer-events: none; animation: confetti .9s cubic-bezier(.15, .7, .3, 1) both; }

/* 尊重「減少動態效果」設定 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* =====================================================================
   台鐵車站時刻表
   ===================================================================== */
.mode-switch { margin-bottom: 12px; }
.mode-switch button { padding: 10px; font-size: 15px; }
.board-pick { padding: 12px 14px; }
.board-pick .row { margin: 0; }

/* 車種顏色 */
.tc { display: inline-grid; place-items: center; padding: 1px 8px; border-radius: 7px; font-weight: 800; font-size: 13px; white-space: nowrap; }
.tc-blue   { background: color-mix(in srgb, #2563eb 13%, var(--card)); color: #2563eb; }
.tc-teal   { background: color-mix(in srgb, #0d9488 15%, var(--card)); color: #0d9488; }
.tc-orange { background: color-mix(in srgb, #ea580c 14%, var(--card)); color: #ea580c; }
.tc-amber  { background: color-mix(in srgb, #b45309 15%, var(--card)); color: #b45309; }
.tc-sky    { background: color-mix(in srgb, #0284c7 14%, var(--card)); color: #0284c7; }
.tc-red    { background: color-mix(in srgb, #dc2626 14%, var(--card)); color: #dc2626; }
.tc-purple { background: color-mix(in srgb, #7c3aed 14%, var(--card)); color: #7c3aed; }
.tc-gray   { background: var(--soft); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .tc-blue { color: #93c5fd; } .tc-teal { color: #5eead4; } .tc-orange { color: #fdba74; } .tc-amber { color: #fcd34d; }
  .tc-sky { color: #7dd3fc; } .tc-red { color: #fca5a5; } .tc-purple { color: #c4b5fd; }
}

/* 方向切換 */
.dir-switch button { display: flex; flex-direction: column; align-items: center; line-height: 1.25; padding: 8px 6px; }
.dir-switch button small { font-size: 11px; font-weight: 500; color: var(--muted); }
.dir-switch button b { font-size: 16px; }

/* 下一班 */
.next-train { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #1e3a8a)); color: #fff; border-radius: 20px; padding: 18px; margin-bottom: 14px; position: relative; overflow: hidden; }
@media (prefers-color-scheme: dark) { .next-train { color: #04201c; } }
.next-train::after { content: "🚆"; position: absolute; right: -6px; bottom: -14px; font-size: 92px; opacity: .14; transform: rotate(-8deg); }
.next-label { font-size: 13px; font-weight: 700; opacity: .85; letter-spacing: 1px; }
.next-main { display: flex; align-items: baseline; gap: 12px; margin: 2px 0 6px; flex-wrap: wrap; }
.next-time { font-size: 44px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; line-height: 1.05; }
.next-count { font-size: 18px; font-weight: 800; background: #ffffff2e; padding: 2px 12px; border-radius: 999px; }
.next-count.soon { animation: beat 1.6s ease-in-out infinite; }
.next-info { font-size: 15px; font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.next-info .tc { background: #ffffff33; color: inherit; }
.next-live { font-size: 14px; margin-top: 8px; opacity: .95; }
.next-live .pill { background: #ffffff33; color: inherit; }
.next-after { font-size: 13px; margin-top: 10px; padding-top: 10px; border-top: 1px solid #ffffff33; opacity: .9; }

/* 每小時班次 */
.hist-card { padding: 14px 14px 10px; }
.hist-title { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.hist { display: flex; align-items: flex-end; gap: 3px; height: 84px; }
.hist button { flex: 1; min-width: 0; height: 100%; border: 0; background: none; padding: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; cursor: pointer; }
.hist .bar { width: 100%; border-radius: 4px 4px 2px 2px; background: color-mix(in srgb, var(--accent) 35%, var(--soft)); transform-origin: bottom; animation: draw-up .6s var(--ease-out) both; }
.hist .n { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist button.past .bar { background: var(--line); }
.hist button.cur .bar { background: var(--accent); }
.hist button.cur .n { color: var(--accent); font-weight: 800; }
.hist-axis { display: flex; gap: 3px; margin-top: 4px; }
.hist-axis span { flex: 1; text-align: center; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
@keyframes draw-up { from { transform: scaleY(0); } }
.calm .hist .bar { animation: none; }

/* 篩選、列表 */
.board-filters { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 10px; padding-bottom: 2px; }
.board-filters .chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.past-toggle { width: 100%; border: 1px dashed var(--line); background: none; color: var(--muted); border-radius: 12px; padding: 10px; font-size: 14px; margin-bottom: 10px; cursor: pointer; }
.hour-group { margin-bottom: 12px; scroll-margin-top: 70px; }
.hour-head { position: sticky; top: 58px; z-index: 2; display: flex; align-items: baseline; gap: 8px; padding: 6px 6px; background: var(--bg); font-weight: 800; }
.hour-head .h { font-size: 18px; font-variant-numeric: tabular-nums; }
.hour-head small { color: var(--muted); font-weight: 600; font-size: 12px; }
.hour-head.cur .h { color: var(--accent); }
.brow { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.brow:last-child { border-bottom: 0; }
.brow .bt { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.brow .bt s { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.brow .bt.late { color: var(--bad); }
.brow .bi { min-width: 0; }
.brow .bi .top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.brow .bi .no { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.brow .bi .dest { font-weight: 700; font-size: 15px; margin-top: 2px; }
.brow .bi .where { font-size: 12px; color: var(--accent); margin-top: 1px; }
.brow .bs { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.brow.past { opacity: .45; }
.brow.term { opacity: .6; }
.brow.next { background: linear-gradient(90deg, var(--accent-soft), transparent 75%); }
.hour-card { padding: 0; overflow: hidden; }

/* =====================================================================
   公車站牌到站
   ===================================================================== */
.stop-pick { padding: 12px; }
.search-bar.inset { box-shadow: none; background: var(--soft); border-color: transparent; margin-bottom: 0; }
.stop-pick #stop-favs { margin: 10px 0 0; }
.suggest { margin-top: 8px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); animation: rise .25s var(--ease-out); }
.suggest button { display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: var(--card); padding: 11px 14px; font-size: 15px; cursor: pointer; }
.suggest button:last-child { border-bottom: 0; }
.suggest button:active { background: var(--soft); }
.suggest .grow small { display: block; color: var(--muted); font-size: 12px; }
.suggest mark { background: none; color: var(--accent); font-weight: 800; }

.stop-head { display: flex; align-items: center; gap: 10px; }
.stop-head .ic { font-size: 30px; }
.stop-head h2 { font-size: 19px; line-height: 1.3; }
.stop-head .sub { font-size: 13px; color: var(--muted); }
.star { border: 0; background: none; font-size: 26px; cursor: pointer; line-height: 1; padding: 4px; filter: grayscale(1); opacity: .5; transition: transform .3s var(--spring), filter .2s, opacity .2s; }
.star.on { filter: none; opacity: 1; transform: scale(1.1); }
.star:active { transform: scale(.8); }

/* 即將到站卡片（橫向捲動） */
.soon-row { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px 14px; padding: 2px 16px 6px; scrollbar-width: none; }
.soon-row::-webkit-scrollbar { display: none; }
.soon-card { flex: 0 0 132px; scroll-snap-align: start; background: var(--card); border-radius: 18px; padding: 14px; box-shadow: 0 1px 3px #0000000d; animation: rise .45s var(--ease-out) both; cursor: pointer; border: 0; text-align: left; }
.soon-card:nth-child(2) { animation-delay: .06s; } .soon-card:nth-child(3) { animation-delay: .12s; } .soon-card:nth-child(4) { animation-delay: .18s; } .soon-card:nth-child(n+5) { animation-delay: .24s; }
.soon-card .m { font-size: 34px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.soon-card .m small { font-size: 14px; font-weight: 700; margin-left: 2px; letter-spacing: 0; }
.soon-card .to { font-size: 13px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.soon-card .route-chip { margin-top: 10px; }
.soon-card.first { background: linear-gradient(140deg, var(--bus), color-mix(in srgb, var(--bus) 60%, #0f766e)); color: #fff; }
.soon-card.first .to { color: #ffffffcc; }
.soon-card.first .route-chip { background: #ffffff30; color: #fff; }
.soon-card .m.now { color: var(--bad); animation: blink 1s ease-in-out infinite; }
.soon-card.first .m.now { color: #fff; }
.calm .soon-card { animation: none; }

/* 接下來 30 分鐘時間軸 */
.tline-card { padding: 14px 16px 12px; }
.tline-title { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.tline { position: relative; margin: 0 22px 0 20px; }
.tline-lanes { position: relative; }
.tline-lane { position: relative; height: 30px; }
.tline-axis { position: relative; height: 22px; border-top: 2px solid var(--line); margin-top: 2px; }
.tline-axis span { position: absolute; top: 4px; transform: translateX(-50%); white-space: nowrap; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tline-axis span::before { content: ""; position: absolute; left: 50%; top: -8px; width: 2px; height: 5px; background: var(--line); }
.tline-now { position: absolute; left: 0; top: 0; bottom: 22px; width: 2px; background: var(--bad); border-radius: 1px; z-index: 0; }
.tline-now::after { content: "現在"; position: absolute; bottom: -20px; left: 0; transform: translateX(-50%); white-space: nowrap; font-size: 11px; color: var(--bad); font-weight: 800; }
.tmark { position: absolute; top: 2px; transform: translateX(-50%); padding: 2px 7px; border-radius: 7px; font-size: 12px; font-weight: 800; white-space: nowrap;
  background: color-mix(in srgb, var(--bus) 14%, var(--card)); color: var(--bus); border: 1px solid color-mix(in srgb, var(--bus) 30%, transparent);
  animation: mark-in .6s var(--spring) both; cursor: pointer; z-index: 1; }
.tmark.near { background: var(--bus); color: #fff; }
@keyframes mark-in { from { opacity: 0; transform: translateX(calc(-50% + 40px)); } }
.calm .tmark { animation: none; transition: left .8s var(--ease-out); }

/* 分組列表 */
.arr-group { margin-bottom: 12px; }
.arr-group > summary { list-style: none; cursor: pointer; }
.arr-group > summary::-webkit-details-marker { display: none; }
.arr-title { display: flex; align-items: baseline; gap: 8px; font-weight: 800; font-size: 15px; margin: 0 4px 8px; }
.arr-title small { color: var(--muted); font-weight: 600; font-size: 12px; }
.arr-card { padding: 0; overflow: hidden; }
.arr { border-bottom: 1px solid var(--line); }
.arr:last-child { border-bottom: 0; }
.arr-main { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; width: 100%; padding: 12px 14px; border: 0; background: none; text-align: left; cursor: pointer; }
.arr-main:active { background: var(--soft); }
.arr-main .to { min-width: 0; }
.arr-main .to b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arr-main .to small { color: var(--muted); font-size: 12px; }
.arr-main .eta { font-size: 18px; }
.arr-main .eta small { font-size: 12px; font-weight: 600; }
.arr.off .arr-main { opacity: .55; }
.arr-detail { padding: 0 14px 12px 14px; font-size: 14px; animation: rise .3s var(--ease-out); }
.arr-detail .where { background: var(--soft); border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dots { display: flex; align-items: center; gap: 4px; margin: 8px 0 4px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dots i.bus { background: var(--bus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bus) 25%, transparent); animation: beat 1.4s infinite; }
.dots i.me { background: var(--accent); width: 14px; height: 14px; }
.dots i.pass { background: color-mix(in srgb, var(--bus) 35%, var(--line)); }
