/* 顏色都用變數。主題由 <html data-theme="light|dark"> 決定（index.html 的 <head> 先套、app.js 負責切換）。 */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --text: #1c2030;
  --muted: #5d6475;
  --line: #dde1e8;
  --field-line: #8a91a0;          /* 日期、下拉選單的外框：和背景至少 3:1，看得出是可以填的欄位（WCAG 1.4.11） */
  --accent: #2a66cc;              /* 連結與按鈕；淺灰、淡綠底上也要 4.5:1（原本 #2f6fdb 在 --surface-2 上只有 4.24） */
  --accent-ink: #ffffff;
  --ok: #187a44;                  /* 文字顏色要和背景（--ok-bg、白底）有 4.5:1 的對比（WCAG 1.4.3）；改色前跑 tools/check_a11y.mjs */
  --ok-bg: #e3f4ea;
  --info: #2459b8;
  --info-bg: #e5edfb;
  --warn: #9a5b00;
  --warn-bg: #fdf0d9;
  --off: #62687a;
  --off-bg: #eceef2;
  --shadow: 0 6px 24px rgba(20, 24, 40, .16);
  --topbar-bg: #1f2430;
  --topbar-line: #5a6378;
  --topbar-hover: #2d3445;
  --search-bg: #ffffff;           /* 搜尋欄點進去或有文字時 */
  --search-ink: #1c2030;
  --search-idle-bg: rgba(255, 255, 255, .1);   /* 搜尋欄平常：半透明，融在深色標題列裡 */
  --search-idle-hover: rgba(255, 255, 255, .16);
  --search-idle-line: rgba(255, 255, 255, .18);
  --search-idle-ink: #ffffff;
  --search-idle-muted: #b9c0cf;
  --search-ring: rgba(107, 156, 240, .55);
  --map-bg: #f4f1ea;
  --pin-bg: #ffffff;
  --pin-ring: rgba(0, 0, 0, .35);
  --toast-bg: #1f2430;
  --toast-ink: #ffffff;
  --toast-act-bg: #ffffff;
  --toast-act-ink: #1f2430;
  --num-bg: #1f2430;
  --num-ink: #ffffff;
  --num-ring: #ffffff;
  --num-done: #8a909c;
  --topbar-h: 60px;
  --tabbar-h: 0px;
  --sidebar-w: 390px;
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #14161c; --surface: #1d2028; --surface-2: #272b36; --text: #e8eaf0; --muted: #a9afbd;
  --line: #373c4a; --field-line: #6b7283; --accent: #6b9cf0; --accent-ink: #0f1420;
  --ok: #6fd19a; --ok-bg: #1d3328; --info: #9bbcf7; --info-bg: #1f2a40;
  --warn: #f0bd6a; --warn-bg: #3a2d16; --off: #a3a9b6; --off-bg: #2a2e38;
  --shadow: 0 6px 24px rgba(0, 0, 0, .55);
  --topbar-bg: #171a21; --topbar-line: #4a5266; --topbar-hover: #262b37;
  --search-bg: #262a34; --search-ink: #e8eaf0;
  --search-idle-bg: rgba(255, 255, 255, .07); --search-idle-hover: rgba(255, 255, 255, .11); --search-idle-line: rgba(255, 255, 255, .13);
  --search-idle-muted: #a9afbd; --search-ring: rgba(107, 156, 240, .5);
  --map-bg: #1b1d22;
  --pin-bg: #f4f6fb; --pin-ring: rgba(0, 0, 0, .75);
  --toast-bg: #e8eaf0; --toast-ink: #14161c; --toast-act-bg: #1d2028; --toast-act-ink: #e8eaf0;
  --num-bg: #f2f4f9; --num-ink: #14161c; --num-ring: #14161c; --num-done: #7b8190;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; max-width: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--topbar-bg); color: #fff; position: relative; z-index: 1001;
  border-bottom: 1px solid transparent;
}
/* 標題列底下一條細的漸層線（粉→紫→藍），只是裝飾 */
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none;
  background: linear-gradient(90deg, #ff6aa8, #b26cf5 50%, #5b8cff); opacity: .9;
}
/* 左上：圖示（地圖針＋星星，一般符號，不是官方標誌）＋網站名稱，下面一行是資料筆數與更新日期。
   圖示放在連結裡（點了也回首頁），用絕對定位疊在左邊，所以名稱和日期可以上下排（電腦）或左右排（手機）。 */
.brandmark { position: relative; min-width: 0; overflow: hidden; padding-left: 44px; }
.brandmark h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .04em; line-height: 1.3; white-space: nowrap; }
.brandmark h1 a { color: inherit; text-decoration: none; border-radius: 4px; }
.brandmark h1 a:hover .brand-name { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }
.brandmark h1 a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.logo {
  position: absolute; left: 0; top: 50%; width: 34px; height: 34px; margin-top: -17px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #ff6aa8 0%, #b26cf5 55%, #5b8cff 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}
.logo svg { width: 21px; height: 21px; display: block; }
.logo-pin { fill: #fff; }
.logo-star { fill: #c062dc; }
.updated { margin: 1px 0 0; font-size: 12px; color: #aab2c3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.upd-dot { display: inline-block; width: 7px; height: 7px; margin: 0 7px 1px 1px; border-radius: 50%; vertical-align: middle; background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .18); }
.updated.is-stale .upd-dot { background: #fbbf24; box-shadow: 0 0 0 3px rgba(251, 191, 36, .2); }
.upd-sep { margin: 0 6px; opacity: .55; }
.upd-day { display: none; }
/* 放不下時（例如英文版的窄手機）：先拿掉筆數，再不行只留日期 */
.updated.is-tight .upd-count, .updated.is-tight .upd-sep, .updated.is-tighter .upd-date { display: none; }
.updated.is-tighter .upd-day { display: inline; }
/* 搜尋欄：平常半透明（跟深色標題列融在一起），點進去或有文字時變成實心、外圈亮起來。
   右邊依序是：符合筆數（桌機）、清除鈕（有文字時）、快速鍵提示「Ctrl K」或「⌘K」（桌機、空白時）。 */
.search { position: relative; flex: 1; max-width: 440px; margin-left: auto; display: flex; align-items: center; }
.search input {
  width: 100%; height: 40px; border-radius: 20px; padding: 0 40px 0 40px; outline: none;
  border: 1px solid var(--search-idle-line); background: var(--search-idle-bg); color: var(--search-idle-ink);
  -webkit-appearance: none; appearance: none;
  transition: background-color .15s, border-color .15s, box-shadow .15s, color .15s;
}
.search input::-webkit-search-cancel-button, .search input::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.search input::placeholder { color: var(--search-idle-muted); opacity: 1; }
.search input:hover { background: var(--search-idle-hover); }
.search input:focus, .search.has-q input { background: var(--search-bg); color: var(--search-ink); border-color: transparent; }
.search input:focus { box-shadow: 0 0 0 3px var(--search-ring); }
.search input:focus::placeholder { color: var(--muted); }
.search-icon {
  position: absolute; left: 14px; width: 17px; height: 17px; pointer-events: none;
  fill: none; stroke: var(--search-idle-muted); stroke-width: 2.4; stroke-linecap: round; transition: stroke .15s;
}
.search.has-q .search-icon { stroke: var(--muted); }
.search:focus-within .search-icon { stroke: var(--accent); }
.search-count {
  position: absolute; right: 42px; padding: 0 8px; border-radius: 10px; pointer-events: none; white-space: nowrap;
  font-size: 12px; line-height: 20px; font-weight: 600; background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--muted);
}
.search-count.zero { background: var(--warn-bg); color: var(--warn); }
.search-clear {
  position: absolute; right: 6px; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); display: grid; place-items: center;
}
.search-clear:hover { background: var(--surface-2); color: var(--text); }
.search-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-clear svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.search-key {
  position: absolute; right: 12px; min-width: 22px; height: 22px; padding: 0 6px; display: grid; place-items: center; pointer-events: none; white-space: nowrap;
  font: 600 12px/1 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--search-idle-muted);
  border: 1px solid var(--search-idle-line); border-radius: 6px;
}
.search-count[hidden], .search-clear[hidden], .search:focus-within .search-key, .search.has-q .search-key { display: none; }
@media (hover: none) { .search-key { display: none; } }
@media (prefers-reduced-motion: reduce) { .search input, .search-icon { transition: none; } }

/* ---------- layout ---------- */
.layout { position: relative; height: calc(100% - var(--topbar-h)); display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain; position: relative; }
/* 開網頁時，篩選和清單等 app.js 畫好才顯示：不然會先出現空的篩選，填入品牌和類型後整個清單往下跳（電腦版 CLS 0.16，tools/measure_vitals.mjs）。
   app.js 沒跑起來時，4 秒後照樣顯示。 */
.is-booting #sidebar > :not(.side-tabs) { visibility: hidden; animation: show-anyway 0s 4s forwards; }
@keyframes show-anyway { to { visibility: visible; } }
.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--map-bg); }
/* 地圖函式庫沒載到時（app.js 的 MAP_OK）：地圖區只放一行說明，手機另有「看活動清單」按鈕 */
#map.map-failed { display: grid; place-items: center; padding: 16px; }
.map-failed-msg { max-width: 320px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }
.map-failed-msg p { margin: 0 0 10px; }
@media (min-width: 861px) { .map-failed-msg [data-goto-list] { display: none; } }

/* ---------- filters ---------- */
.filters { padding: 14px 16px 6px; border-bottom: 1px solid var(--line); }
.filters-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.filters-head h2 { font-size: 15px; margin: 0; }
.close-filters, .apply-filters { display: none; }
fieldset { border: 0; padding: 0; margin: 10px 0 12px; min-width: 0; }
legend { font-size: 13px; font-weight: 700; color: var(--muted); padding: 0; margin-bottom: 6px; display: flex; gap: 8px; align-items: baseline; width: 100%; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }
.link-button.small { font-size: 12px; font-weight: 400; margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 3px 11px 3px 9px;
  border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; line-height: 1.2;
}
.chip .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }
.chip .n { color: var(--muted); font-size: 12px; }
.chip[aria-pressed="true"] { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 12%, var(--surface)); font-weight: 600; }
.chip[aria-pressed="false"] { color: var(--muted); } /* 不用半透明：整顆變淡時文字對比不到 4.5:1 */
.chip[aria-pressed="false"] .dot { background: transparent; border: 2px solid var(--c); }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.segmented button { flex: 1; border: 0; background: var(--surface); padding: 7px 4px; font-size: 13px; border-right: 1px solid var(--line); }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.date-row { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.date-row label { flex: 1 1 130px; min-width: 0; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.date-row input { flex: 1; min-width: 0; height: 34px; border: 1px solid var(--field-line); border-radius: 8px; padding: 0 8px; background: var(--surface); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.presets button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 14px; padding: 3px 11px; font-size: 12.5px; }
.presets button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- list ---------- */
.result-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: 9px 16px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.result-bar #resultCount { color: var(--text); font-weight: 600; }
.sort button { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 1px 9px; font-size: 12.5px; margin-left: 3px; }
.sort button[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.event-list { list-style: none; margin: 0; padding: 0 0 16px; }
.group-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px 4px; font-size: 13px; font-weight: 700; color: var(--muted);
}
.group-head .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.event-item { padding: 0 8px; }
.event-item button {
  width: 100%; display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: start; text-align: left;
  background: none; border: 0; border-radius: 10px; padding: 9px 8px;
}
.event-item button:hover { background: var(--surface-2); }
.event-item.active button { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.list-pin {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 17px;
  background: var(--pin-bg); border: 3px solid var(--c); margin-top: 1px;
}
.list-pin.upcoming { border-style: dashed; }
.ev-title { display: block; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.ev-meta { display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 9px; line-height: 1.5; white-space: nowrap;
}
.badge.ongoing { color: var(--ok); background: var(--ok-bg); }
.badge.upcoming { color: var(--info); background: var(--info-bg); }
.badge.ending { color: var(--warn); background: var(--warn-bg); }
.badge.off { color: var(--off); background: var(--off-bg); }
.list-empty { padding: 24px 16px; color: var(--muted); }
.sidebar-foot { padding: 14px 16px 24px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--muted); background: var(--pin-bg); display: inline-block; }
.legend i.dashed { border-style: dashed; }
.feedback-line { margin: 10px 0; }
.feedback-link { font-weight: 600; white-space: nowrap; }
@media (pointer: coarse) { .feedback-link { display: inline-block; padding: 8px 0; } } /* 手機上好點一點 */
/* 下載 KML、加到主畫面（RULES.md 第 16 節） */
.foot-tool { margin: 10px 0; }
.foot-tool .link-button { font-weight: 600; white-space: nowrap; }
@media (pointer: coarse) { .foot-tool .link-button { padding: 8px 0; } }

/* ---------- map pins ---------- */
.pin-icon { background: none; border: 0; }
.pin-body {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 16px; line-height: 1;
  background: var(--pin-bg); border: 3px solid var(--c); box-shadow: 0 0 0 1.5px var(--pin-ring), 0 2px 6px rgba(0, 0, 0, .35); transition: transform .15s;
}
.pin-icon.upcoming .pin-body { border-style: dashed; }
.pin-icon.selected { z-index: 10000 !important; }
/* 用 Tab 鍵走到的圖釘或群聚移到最上層，不會被疊在一起的其他圖釘蓋住（WCAG 2.4.11） */
.leaflet-marker-icon:focus-visible { z-index: 10001 !important; }
.pin-icon.selected .pin-body { transform: scale(1.3); box-shadow: 0 0 0 1.5px var(--pin-ring), 0 0 0 5px color-mix(in srgb, var(--c) 40%, transparent), 0 3px 10px rgba(0, 0, 0, .45); }
.cluster-icon { background: none; }
.cluster-icon div {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c, #2b3040); color: #fff; font-weight: 800; font-size: 14px;
  border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--pin-ring), 0 0 0 4px color-mix(in srgb, var(--c, #2b3040) 30%, transparent), 0 2px 8px rgba(0, 0, 0, .35);
}
.cluster-icon.mixed div { background: conic-gradient(var(--g)); }
/* 數字一律放在深色圓心上：白字直接放在品牌色上，黃、橘、綠、青等品牌色對比不到 4.5:1（WCAG 1.4.3） */
.cluster-icon div span { background: rgba(20, 24, 36, .82); border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 11px; }
.map-tool {
  background: var(--surface); color: var(--text); border: 0; width: 36px; height: 36px; display: grid; place-items: center;
  font-size: 17px; border-bottom: 1px solid var(--line);
}
.map-tool:last-child { border-bottom: 0; }
.leaflet-bar.tools { border: 0; box-shadow: 0 1px 6px rgba(0, 0, 0, .3); border-radius: 8px; overflow: hidden; }
.leaflet-bar { border: 0 !important; box-shadow: 0 1px 6px rgba(0, 0, 0, .3) !important; border-radius: 8px !important; overflow: hidden; }
.leaflet-bar a, .leaflet-bar a:hover, .leaflet-bar a:focus { background-color: var(--surface); color: var(--text); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background-color: var(--surface-2); }
.leaflet-container .leaflet-control-attribution { background: var(--surface); color: var(--muted); } /* 不透明：半透明時連結疊在深色圖磚上對比不到 4.5:1 */
.leaflet-container .leaflet-control-attribution a { color: var(--accent); }
.leaflet-tooltip { background: var(--surface); color: var(--text); border-color: var(--line); box-shadow: 0 1px 5px rgba(0, 0, 0, .4); }
.leaflet-tooltip-top:before { border-top-color: var(--line); }
.leaflet-tooltip-bottom:before { border-bottom-color: var(--line); }
.leaflet-tooltip-left:before { border-left-color: var(--line); }
.leaflet-tooltip-right:before { border-right-color: var(--line); }
/* 向量底圖的畫布在 Leaflet 的圖磚層裡；MapLibre 自己的控制項我們不用 */
.leaflet-gl-layer { pointer-events: none; }
/* 後備的地理院點陣圖在深夜模式沒有深色版，用濾鏡把它變暗（反相後轉回色相，顏色大致不變、底變深） */
:root[data-theme="dark"] #map.is-fallback .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.8); }

/* ---------- detail ---------- */
.detail {
  position: absolute; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); z-index: 1000;
  background: var(--surface); border-right: 1px solid var(--line); box-shadow: var(--shadow);
  overflow-y: auto; overscroll-behavior: contain;
}
.detail[hidden] { display: none; }
/* 捲動後墊在關閉鈕後面的橫條（不佔版面；app.js 依捲動加 is-scrolled） */
.detail::before {
  content: ''; position: sticky; top: 0; z-index: 2; display: block; height: 54px; margin-bottom: -54px;
  background: var(--surface); border-bottom: 1px solid var(--line); opacity: 0; pointer-events: none; transition: opacity .15s;
}
.detail.is-scrolled::before { opacity: 1; }
.detail-grip { display: none; }
.detail-close {
  position: sticky; top: 10px; float: right; margin: 10px 10px 0 0; z-index: 3; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; line-height: 1;
}
.detail-body { padding: 16px 18px 28px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 40px 10px 0; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; padding: 2px 9px; border-radius: 10px; background: var(--surface-2); }
.tag .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.detail h2 { font-size: 20px; line-height: 1.35; margin: 0 0 4px; overflow-wrap: anywhere; }
.official-title { font-size: 13px; color: var(--muted); margin: 0 0 8px; overflow-wrap: anywhere; }
/* 活動敘述：標題下面的淡色框（RULES.md 第 1 節） */
.summary { margin: 10px 0 14px; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.facts { margin: 0; }
.fact { display: grid; grid-template-columns: 26px 1fr; gap: 4px; padding: 10px 0; border-top: 1px solid var(--line); }
.fact > .ico { font-size: 16px; line-height: 1.5; }
.fact h3 { margin: 0 0 2px; font-size: 12.5px; color: var(--muted); font-weight: 700; }
.fact p { margin: 0; overflow-wrap: anywhere; }
.fact .sub { font-size: 13px; color: var(--muted); }
.fact .nearby { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.fact .app-switch { margin: 6px 0 2px; } /* Apple 裝置才有的「改用 Apple 地圖導航」 */
/* 長文字（richText）：一句一段、「；」列點；太長的收合（foldLong） */
.tx p { margin: 0 0 4px; }
.tx > :last-child, .tx-sub > :last-child { margin-bottom: 0; }
.tx-list { margin: 0 0 4px; padding-left: 1.15em; }
.tx-list li { margin: 1px 0; }
.tx-list li::marker { color: var(--muted); }
.tx-sub { margin-top: 8px; font-size: 13px; color: var(--muted); }
.tx-sub .tx-label { margin: 0 0 2px; font-weight: 600; }
.notice-list > li + li { margin-top: 4px; }
.fold.is-folded:not(.is-open) {
  max-height: var(--fold-h); overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent);
}
.fold-btn { display: block; border: 0; background: none; padding: 6px 0 0; color: var(--accent); font-weight: 600; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px; font-size: 14px; font-weight: 600;
  text-decoration: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.windows { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.window { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.window .w-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; }
.window .w-when { font-size: 13px; margin-top: 2px; }
.window .w-cond { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.closed-windows summary { font-size: 13px; color: var(--muted); cursor: pointer; margin-top: 8px; }
.notice-list { margin: 2px 0 0; padding-left: 18px; }
.links { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 6px; }
.links a { display: inline-flex; gap: 6px; align-items: baseline; overflow-wrap: anywhere; }
.links .host { color: var(--muted); font-size: 12px; }
.nearby { list-style: none; padding: 0; margin: 4px 0 0; }
.nearby button { background: none; border: 0; padding: 4px 0; color: var(--accent); text-align: left; text-decoration: underline; text-underline-offset: 2px; }
.detail-foot { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }

/* ---------- side tabs & trip ---------- */
.side-tabs { display: flex; gap: 4px; padding: 6px 12px 0; border-bottom: 1px solid var(--line); background: var(--surface); }
.side-tabs button {
  flex: 1; border: 0; background: none; padding: 9px 6px 9px; font-weight: 700; font-size: 14px; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.side-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.trip-count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11.5px; line-height: 18px; }
.trip-count:empty { display: none; }
.trip { display: none; padding: 12px 16px 20px; }
body.view-trip .trip { display: block; }
body.view-trip:not(.filters-open) .filters, body.view-trip .result-bar, body.view-trip .event-list, body.view-trip .list-empty { display: none; }
.sub { color: var(--muted); font-size: 12.5px; margin: 0; }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 9px; }
.trip-shared { border: 1px solid var(--accent); background: var(--info-bg); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.trip-shared p { margin: 0 0 2px; }
.trip-head { display: flex; align-items: baseline; gap: 10px; }
.trip-head h2 { font-size: 17px; margin: 0; }
.trip-sum { color: var(--muted); font-size: 13px; }
.trip-head .link-button { margin-left: auto; }
.trip-settings { margin: 10px 0 12px; display: grid; gap: 8px; }
.setting { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.setting .label { font-size: 13px; font-weight: 700; color: var(--muted); width: 4.6em; flex: none; }
.setting .segmented { flex: 1; min-width: 210px; }
.date-row input:focus-within, .setting input[type="date"]:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; } /* 原生日期欄位拿到焦點時外面沒有框（WCAG 2.4.7）；Tab 到年月日之間時只有 :focus-within 對得上 */
.setting input[type="date"] { height: 34px; border: 1px solid var(--field-line); border-radius: 8px; padding: 0 8px; background: var(--surface); }
.next-row { display: flex; gap: 8px; align-items: stretch; }
.next-stop {
  flex: 1; min-width: 0; display: flex; gap: 12px; align-items: center; padding: 11px 14px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; box-shadow: 0 2px 8px rgba(20, 24, 40, .18);
}
.next-stop.all-done { background: var(--ok-bg); color: var(--ok); font-weight: 700; box-shadow: none; }
.ns-ico { font-size: 22px; }
.ns-label { display: block; font-size: 12px; }
.ns-title { display: block; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.qr-btn { flex: none; padding: 0 12px; }
.next-more { margin: 6px 0 0; font-size: 13px; }
.trip-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.trip-stops { list-style: none; margin: 10px 0 0; padding: 0; }
.stop { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 6px 0; }
.stop-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--c); color: #fff; font-weight: 800; font-size: 14px;
  display: grid; place-items: center; margin-top: 1px;
}
.stop.done .stop-num { background: var(--off); }
/* 拖曳排序：站號下面的「⠿」是把手；拖曳中被拖的站浮起來，目標位置畫一條線，各段交通變淡 */
.stop-side { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stop-grip {
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--muted);
  font-size: 18px; line-height: 1; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.stop-grip:hover { background: var(--surface-2); color: var(--text); }
.stop-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.trip-stops.is-dragging, .trip-stops.is-dragging .stop-grip { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.stop.dragging { position: relative; z-index: 5; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); opacity: .96; }
.trip-stops.is-dragging .leg { opacity: .3; }
.stop.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.stop.drop-after { box-shadow: 0 3px 0 var(--accent); }
@media (prefers-reduced-motion: reduce) { .stop.dragging { box-shadow: none; outline: 2px solid var(--accent); } }
.stop.done .stop-title { text-decoration: line-through; color: var(--muted); }
.stop-main { min-width: 0; }
.stop-title { background: none; border: 0; padding: 0; text-align: left; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; color: var(--text); }
.stop-title:hover { color: var(--accent); }
.stop-meta { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stop-warn { margin: 5px 0 0; font-size: 12.5px; color: var(--warn); background: var(--warn-bg); padding: 3px 8px; border-radius: 8px; }
.stop-ctrl { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.done-toggle { font-size: 13px; display: inline-flex; gap: 5px; align-items: center; }
.spacer { flex: 1; }
.icon-btn { width: 32px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); line-height: 1; font-size: 14px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.leg { margin-left: 13px; padding: 4px 0 10px 23px; border-left: 3px solid var(--text); }
.leg.mode-driving { border-left-style: dashed; }
.leg.mode-walking { border-left-style: dotted; }
.leg-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 13px; }
.leg-mode, .mode-select { height: 32px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--surface); padding: 0 6px; }
.leg-mode.custom { border-color: var(--accent); font-weight: 700; }
.mode-select { height: 38px; border-radius: 10px; }
.leg-dist { color: var(--muted); }
.leg-sugg { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 7px; }
.sugg {
  border: 1px dashed var(--c); background: color-mix(in srgb, var(--c) 8%, var(--surface)); border-radius: 14px;
  padding: 3px 10px; font-size: 12.5px; text-align: left; line-height: 1.4; overflow-wrap: anywhere;
}
.sugg .sub { font-size: 12px; }
.leg-add { margin-top: 6px; background: none; border: 0; padding: 2px 0; color: var(--accent); font-size: 13px; font-weight: 700; }
.trip-end { padding-left: 40px; }
.picker { margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--surface-2); }
.picker-q { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--surface); }
.picker-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 280px; overflow-y: auto; }
.picker-list button { width: 100%; display: grid; grid-template-columns: 30px 1fr; gap: 8px; text-align: left; background: none; border: 0; border-radius: 8px; padding: 6px; }
.picker-list button:hover { background: var(--surface); }
.picker-none { padding: 6px; }
.list-pin.small { width: 28px; height: 28px; font-size: 14px; border-width: 2px; }
.warn-text { color: var(--warn); font-weight: 700; }
.trip-missing { margin-top: 10px; }
.trip-empty { padding: 14px 0 4px; }
.trip-empty p { margin: 0 0 6px; }
.trip-export { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.trip-export h3 { font-size: 14.5px; margin: 0 0 4px; }
.export-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
.ex { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; }
.ex-label { flex: 1; min-width: 0; font-size: 13.5px; }
.ex-label .sub { display: block; }
.ex-btns { display: flex; gap: 6px; flex: none; }
.notes { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.trip-actions { margin: -4px 0 12px; align-items: center; }
.in-trip { font-size: 13.5px; font-weight: 700; color: var(--ok); }
.btn.add-trip { border-color: var(--accent); color: var(--accent); }
.trip-num { background: none; border: 0; }
.trip-num span {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--num-bg); color: var(--num-ink);
  font-size: 12px; font-weight: 800; border: 2px solid var(--num-ring); box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.trip-num.done span { background: var(--num-done); color: #fff; }

/* ---------- QR dialog ---------- */
.qr-dialog {
  border: 0; border-radius: 16px; padding: 16px 20px 18px; background: var(--surface); color: var(--text);
  width: min(360px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
.qr-dialog::backdrop { background: rgba(10, 12, 20, .55); }
:root[data-theme="dark"] .qr-dialog { border: 1px solid var(--line); }
.qr-dialog h2 { font-size: 17px; margin: 4px 0 4px; }
.qr-close-form { float: right; margin: 0; }
.qr-close-form .detail-close { position: static; float: none; margin: 0; }
.qr-sub, .qr-hint { font-size: 13px; color: var(--muted); margin: 0; overflow-wrap: anywhere; }
.qr-box { width: 236px; height: 236px; margin: 12px auto; background: #fff; border-radius: 8px; display: grid; place-items: center; text-align: center; }
.qr-box svg { width: 100%; height: 100%; display: block; }
.qr-actions { justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px); transform: translateX(-50%); z-index: 3000;
  background: var(--toast-bg); color: var(--toast-ink); padding: 8px 16px; border-radius: 18px; font-size: 13.5px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); width: max-content;
}
.toast[hidden] { display: none; }
.toast-act {
  flex: none; border: 0; border-radius: 12px; background: var(--toast-act-bg); color: var(--toast-act-ink); font-weight: 700; font-size: 13.5px;
  padding: 6px 14px; min-height: 32px; cursor: pointer;
}
.save-note { margin: 8px 0 0; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; line-height: 1.5; color: var(--muted); background: var(--surface-2); }
.save-note p { margin: 0 0 6px; }
.save-note .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.save-note.warn { color: var(--warn); background: var(--warn-bg); }
.save-note.quiet { background: none; padding-left: 0; padding-right: 0; opacity: .75; }
.trip-tools-note { margin: 4px 0 0; }
.tabbar { display: none; }

/* ---------- phone ---------- */
@media (max-width: 860px) {
  :root { --topbar-h: 104px; --tabbar-h: 58px; --sidebar-w: 100%; }
  .topbar { flex-wrap: wrap; align-content: center; gap: 6px; padding: 8px 16px; }
  .brandmark { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 30px; padding-left: 38px; }
  .brandmark h1 { font-size: 16px; flex: none; }
  .logo { width: 29px; height: 29px; margin-top: -14.5px; border-radius: 9px; }
  .logo svg { width: 18px; height: 18px; }
  .updated { flex: 1; margin: 0; text-align: right; font-size: 11.5px; }
  .search { max-width: none; margin: 0; }
  .layout { display: block; height: calc(100% - var(--topbar-h) - var(--tabbar-h)); }
  .map-wrap { position: absolute; inset: 0; z-index: 0; } /* 地圖按鈕留在地圖層內，不浮到清單上 */
  .sidebar { position: absolute; inset: 0; z-index: 900; border: 0; display: none; }
  body.view-list .sidebar, body.view-trip .sidebar { display: block; }
  .side-tabs { display: none; }
  .trip { padding-bottom: 28px; }
  .tabbar button { font-size: 11.5px; }
  .filters { display: none; }
  /* z-index:auto 讓全螢幕篩選層不被側欄的堆疊層級困住（否則會被標題列與按鈕蓋住） */
  body.filters-open .sidebar { display: block; z-index: auto; }
  body.filters-open .filters {
    display: block; position: fixed; inset: 0; z-index: 2500; background: var(--surface); overflow-y: auto; padding: 16px 16px 90px;
  }
  .close-filters { display: inline-block; margin-left: auto; border: 0; background: none; color: var(--accent); font-weight: 700; font-size: 15px; }
  .apply-filters {
    display: block; position: fixed; left: 16px; right: 16px; bottom: 16px; height: 48px; border: 0; border-radius: 12px;
    background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; box-shadow: var(--shadow);
  }
  .chip { min-height: 36px; }
  .segmented button { padding: 9px 2px; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar-h); z-index: 2000;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 12px; color: var(--muted); }
  .tabbar button span { font-size: 18px; line-height: 1; }
  .tabbar button[aria-pressed="true"] { color: var(--accent); font-weight: 700; }
  .tabbar em { font-style: normal; white-space: nowrap; }
  .tabbar b { font-weight: 600; }
  #filterBadge { display: inline-block; min-width: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 10.5px; }
  #filterBadge[hidden] { display: none; }
  .detail {
    position: fixed; top: auto; left: 0; right: 0; bottom: var(--tabbar-h); width: 100%; max-height: 55vh;
    border: 0; border-radius: 16px 16px 0 0; z-index: 1500;
  }
  .detail-grip { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
  .detail-close { margin-top: 4px; }
  .detail-body { padding: 6px 16px 22px; }
  .detail h2 { font-size: 18px; }
  /* 地圖右下角的出處：手機上字小一點、拿掉 Leaflet 字樣（不是必要標示；頁尾仍有完整出處），OpenFreeMap、OpenMapTiles、OpenStreetMap 照規定保留 */
  .leaflet-container .leaflet-control-attribution { font-size: 9px; line-height: 1.35; padding: 0 4px; max-width: 72vw; }
  .leaflet-control-attribution > a:first-child, .leaflet-control-attribution > a:first-child + span[aria-hidden] { display: none; }
}

/* ---------- 英文版 ---------- */
.lang-btn {
  flex: none; min-width: 52px; height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--topbar-line); background: transparent;
  color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .02em;
}
.lang-btn:hover, .theme-btn:hover { background: var(--topbar-hover); }
.theme-btn {
  flex: none; width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--topbar-line); background: transparent;
  color: #fff; font-size: 16px; line-height: 1; display: grid; place-items: center;
}
.lang-btn:focus-visible, .theme-btn:focus-visible { outline: 2px solid #9bbcf7; outline-offset: 2px; }
.untr {
  display: inline-block; font-size: 11px; line-height: 1.5; padding: 0 7px; margin-left: 4px; border-radius: 9px; vertical-align: 1px;
  background: var(--warn-bg); color: var(--warn); font-weight: 600; white-space: nowrap;
}
.mt-note { margin: -6px 0 12px; font-size: 12.5px; color: var(--muted); }
html[lang="en"] .segmented button { line-height: 1.25; }
html[lang="en"] .trip-tools .btn, html[lang="en"] .ex-btns .btn { white-space: normal; text-align: left; }
html[lang="en"] .setting .label { width: 8em; }
.trip-head h2, .trip-head .link-button { white-space: nowrap; }
@media (max-width: 860px) {
  /* 手機：語言按鈕和搜尋框同一排，第一排留給標題與資料日期 */
  .search { flex: 1 1 0; width: auto; min-width: 0; }
  .search input { height: 38px; font-size: 16px; } /* iOS 小於 16px 會在點進去時自動放大整頁 */
  .lang-btn { height: 38px; }
  .theme-btn { width: 38px; height: 38px; }
}
