:root {
  --bg: #ffffff;
  --bg2: #f6f5f1;
  --ink: #1d1d1b;
  --ink2: #5f5d57;
  --line: #e6e3da;
  --accent: #f5b700;
  --accent-ink: #3a2c00;
  --soon: #12a150;
  --later: #2b6fd6;
  --done: #a3a09a;
  --off: #d9d6cf;
  --truck: #ff6a00;
  --danger: #d43c2f;
  --shadow: 0 8px 30px rgba(20, 18, 10, .16);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1b19; --bg2: #252522; --ink: #f1efe8; --ink2: #b3b0a7; --line: #36352f;
    --done: #77746d; --off: #46443e; --shadow: 0 8px 30px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1b19; --bg2: #252522; --ink: #f1efe8; --ink2: #b3b0a7; --line: #36352f;
  --done: #77746d; --off: #46443e; --shadow: 0 8px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif; }
button, select, input { font: inherit; color: inherit; }
#map { position: fixed; inset: 0; }

/* ---------- 上方列 ---------- */
.topbar {
  position: fixed; top: 10px; left: 10px; right: 10px; z-index: 5;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px; background: var(--bg); border-radius: var(--r); box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 6px; font-size: 17px; white-space: nowrap; }
.logo { font-size: 22px; display: inline-block; animation: drive 3s ease-in-out infinite; }
@keyframes drive { 0%,100% { transform: translateX(0); } 50% { transform: translateX(3px); } }
.cities { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.cities button, .mode {
  border: 1px solid var(--line); background: var(--bg2); padding: 5px 12px; border-radius: 999px;
  cursor: pointer; white-space: nowrap;
}
.cities button[aria-pressed="true"], .mode[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.modes { display: flex; gap: 4px; }

/* ---------- 面板 ---------- */
.panel {
  position: fixed; z-index: 4; top: 76px; left: 10px; bottom: 10px; width: 390px;
  display: flex; flex-direction: column; background: var(--bg); border-radius: var(--r); box-shadow: var(--shadow);
  overflow: hidden;
}
.grip { display: none; }
.panel-head { padding: 12px 14px 8px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.clock { display: flex; justify-content: space-between; color: var(--ink2); font-size: 13px; }
.clock #now { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
.controls { display: flex; gap: 8px; }
.controls select { flex: 1; min-width: 0; }
select, input[type="search"] {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 10px; padding: 8px 10px; min-height: 40px;
}
input[type="search"] { width: 100%; }
.primary {
  border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: 10px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap; min-height: 40px;
}
.primary:active { transform: translateY(1px); }
.dayrow { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--ink2); }
.dayrow select { min-height: 32px; padding: 4px 8px; margin-left: 6px; }
.live-badge { color: var(--soon); font-weight: 700; animation: blink 2s infinite; }
@keyframes blink { 50% { opacity: .45; } }

.panel-body { flex: 1; overflow-y: auto; padding: 6px 0 12px; overscroll-behavior: contain; }
.panel-foot { border-top: 1px solid var(--line); padding: 8px 14px; font-size: 12px; color: var(--ink2); }
.panel-foot a { color: inherit; }

h2.sec { font-size: 13px; letter-spacing: .04em; color: var(--ink2); margin: 12px 14px 6px; font-weight: 700; }
.hint { margin: 10px 14px; padding: 12px; background: var(--bg2); border-radius: 10px; color: var(--ink2); font-size: 14px; }
.hint b { color: var(--ink); }
.hint ul { margin: 6px 0 0; padding-left: 18px; }

.stop {
  display: grid; grid-template-columns: 62px 1fr auto; gap: 2px 10px; align-items: start;
  padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.stop:hover, .stop:focus-visible { background: var(--bg2); outline: none; }
.stop .time { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stop .time small { display: block; font-size: 11px; font-weight: 600; color: var(--ink2); }
.stop .addr { font-weight: 600; word-break: break-word; }
.stop .meta { grid-column: 2 / 4; font-size: 12px; color: var(--ink2); }
.stop .when { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.when.soon { background: color-mix(in srgb, var(--soon) 15%, transparent); color: var(--soon); }
.when.later { background: color-mix(in srgb, var(--later) 14%, transparent); color: var(--later); }
.when.done { background: var(--bg2); color: var(--done); }
.when.off { background: var(--bg2); color: var(--ink2); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; grid-column: 2 / 4; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--bg2); color: var(--ink2); border: 1px solid var(--line); }
.tag.g { background: #fff4cc; color: #6b5200; border-color: #f2df9b; }
.tag.r { background: #e3f0ff; color: #1f4f96; border-color: #bcd6f7; }
.tag.f { background: #e6f6ea; color: #1d6b37; border-color: #bfe4c8; }
.tag.ap { background: transparent; border-style: dashed; }
.tag.live { background: #fff0e5; color: #b04800; border-color: #ffd0ad; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag.g { background: #3d3311; color: #f5d777; border-color: #5b4b17; }
  :root:not([data-theme="light"]) .tag.r { background: #15283f; color: #9cc6ff; border-color: #22406a; }
  :root:not([data-theme="light"]) .tag.f { background: #15301d; color: #94e0a9; border-color: #21492c; }
  :root:not([data-theme="light"]) .tag.live { background: #3a2210; color: #ffb37d; border-color: #5c3415; }
}

/* 詳細頁 */
.detail { padding: 6px 14px 14px; }
.back { border: 0; background: none; color: var(--later); cursor: pointer; padding: 8px 0; font-weight: 600; }
.detail h3 { margin: 4px 0 2px; font-size: 19px; }
.detail .sub { color: var(--ink2); font-size: 13px; }
.bigtime { display: flex; align-items: baseline; gap: 10px; margin: 10px 0; }
.bigtime b { font-size: 38px; font-variant-numeric: tabular-nums; line-height: 1; }
.week { display: grid; grid-template-columns: auto repeat(7, 1fr); gap: 3px; font-size: 12px; text-align: center; margin: 10px 0; }
.week div { padding: 4px 0; border-radius: 6px; }
.week .h { color: var(--ink2); }
.week .lab { text-align: left; color: var(--ink2); padding-right: 6px; }
.week .y { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.week .n { background: var(--bg2); color: var(--off); }
.week .today { outline: 2px solid var(--ink); outline-offset: -2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.actions button, .actions a {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 10px; padding: 7px 12px; cursor: pointer;
  text-decoration: none; font-size: 14px;
}
.livebox { margin: 10px 0; padding: 10px 12px; border-radius: 10px; background: #fff0e5; color: #6b2c00; font-size: 14px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .livebox { background: #3a2210; color: #ffd1b0; } }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; border-left: 3px solid var(--line); }
.timeline li { position: relative; padding: 5px 0 5px 14px; font-size: 14px; cursor: pointer; }
.timeline li::before { content: ""; position: absolute; left: -7.5px; top: 11px; width: 12px; height: 12px; border-radius: 50%; background: var(--off); border: 2px solid var(--bg); }
.timeline li.done::before { background: var(--done); }
.timeline li.next::before { background: var(--soon); box-shadow: 0 0 0 4px color-mix(in srgb, var(--soon) 25%, transparent); }
.timeline li.me { font-weight: 800; }
.timeline li.me::before { background: var(--accent); }
.timeline li span { font-variant-numeric: tabular-nums; color: var(--ink2); margin-right: 8px; }
.truckhere { color: var(--truck); font-weight: 700; font-size: 12px; margin-left: 4px; }

/* 圖例 */
.legend {
  position: fixed; z-index: 3; right: 10px; bottom: 34px; display: flex; gap: 10px; flex-wrap: wrap;
  background: var(--bg); padding: 6px 10px; border-radius: 10px; box-shadow: var(--shadow); font-size: 12px;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; border: 1.5px solid #fff; }
.dot.soon { background: var(--soon); } .dot.later { background: var(--later); } .dot.done { background: var(--done); }
.dot.off { background: var(--off); } .dot.truck { background: var(--truck); }

.toast {
  position: fixed; z-index: 10; left: 50%; top: 80px; transform: translateX(-50%) translateY(-10px);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: .25s; max-width: calc(100vw - 32px); font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.maplibregl-popup-content { background: var(--bg); color: var(--ink); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.maplibregl-popup-tip { display: none; }
.maplibregl-ctrl-group { background: var(--bg); }
.loading { padding: 16px 14px; color: var(--ink2); }

/* ---------- 手機：底部抽屜 ---------- */
@media (max-width: 760px) {
  .topbar { top: 8px; left: 8px; right: 8px; padding: 6px 8px; gap: 6px; }
  .brand b { display: none; }
  .cities button, .mode { padding: 4px 10px; font-size: 14px; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 55vh; border-radius: 18px 18px 0 0;
    transition: height .25s ease;
  }
  .panel.min { height: 168px; }
  .panel.max { height: calc(100vh - 70px); }
  .grip { display: block; border: 0; background: none; padding: 8px 0 2px; cursor: pointer; width: 100%; }
  .grip span { display: block; margin: 0 auto; width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
  .panel-head { padding-top: 4px; }
  .legend { display: none; }
  .maplibregl-ctrl-bottom-right { bottom: 56vh; }
}
@media (prefers-reduced-motion: reduce) { .logo, .live-badge { animation: none; } .panel { transition: none; } }
