/* ============================================================
   保庇啦 bobila — 樣式（依 Claude Design 主視覺 1a／2a／1e）
   夜廟：墨黑地圖 ＋ 宣紙面板。朱紅主色、金描邊、印章 logo、籤條紋。
   ============================================================ */

:root {
  --red:    #B3261E;   /* 朱紅：主色／CTA／標記 */
  --red-d:  #8E1B15;
  --gold:   #E8C872;   /* 金：描邊／強調 */
  --gold-2: #C9A44C;   /* 暗金：小標／邊框 */
  --ink:    #1A1614;   /* 墨黑：夜圖／導覽列 */
  --ink-2:  #2A241F;
  --washi:  #F3EBDC;   /* 宣紙：面板／卡片 */
  --ink-55: rgba(26,22,20,.55);
  --ink-08: rgba(26,22,20,.08);
  --washi-70: rgba(243,235,220,.7);
  --washi-50: rgba(243,235,220,.5);

  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --sans:  "Noto Sans TC", system-ui, -apple-system, "PingFang TC", sans-serif;

  --stripe: repeating-linear-gradient(90deg, var(--red) 0 6px, transparent 6px 12px);      /* 籤條紋 */
  --incense: repeating-linear-gradient(90deg, var(--gold-2) 0 8px, transparent 8px 14px);  /* 香線虛線 */
  --seal-red: inset 0 0 0 1px var(--gold), inset 0 0 0 3px var(--red);
  --seal-ink: inset 0 0 0 1px var(--gold), inset 0 0 0 3px var(--ink);

  --panel-w: 400px;
  --tab-h: 68px;
  --sheet-peek: 96px;   /* 手機：預設只露出把手＋「此範圍廟宇 N 間」，地圖保持完整可見 */
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100%; }
body {
  font-family: var(--sans); color: var(--washi); background: var(--washi);
  -webkit-font-smoothing: antialiased;
}
html { scroll-behavior: smooth; }
html, body { overflow-x: hidden; }
button { font-family: inherit; cursor: pointer; }
button, input, select { font-size: inherit; }

#app { position: relative; }
#home { position: relative; height: 100vh; height: 100dvh; display: flex; background: var(--ink); overflow: hidden; }

/* ---------- 地圖區 ---------- */
#map-wrap { position: relative; flex: 1 1 auto; min-width: 0; background: var(--ink); }
#map { position: absolute; inset: 0; }
#map-grid {
  position: absolute; inset: 0; pointer-events: none; z-index: 1; opacity: 0;
  background-image: linear-gradient(rgba(201,164,76,.05) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(201,164,76,.05) 1px, transparent 1px);
  background-size: 56px 56px;
}
body.theme-dark #map-grid { opacity: 1; }

/* MapLibre 預設控制項隱藏（自訂鈕取代），保留 attribution */
.maplibregl-ctrl-top-right, .maplibregl-ctrl-top-left { display: none; }
.maplibregl-ctrl-attrib { font-size: 10px; background: rgba(26,22,20,.65) !important; color: var(--washi-50); }
.maplibregl-ctrl-attrib a { color: var(--washi-70); }
.maplibregl-ctrl-bottom-right { right: 0; bottom: 0; }
.maplibregl-user-location-dot, .maplibregl-user-location-dot::before { background-color: #1F4E5F; }
.maplibregl-user-location-dot { border: 3px solid var(--washi); box-shadow: 0 0 0 4px rgba(31,78,95,.4); }
.to-events { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 9; border: 1px solid rgba(201,164,76,.5); background: rgba(26,22,20,.9); color: var(--gold); font-family: var(--serif); font-weight: 700; font-size: 13px; letter-spacing: .1em; padding: 9px 16px; display: flex; gap: 8px; align-items: center; }
.to-events span { animation: bob 1.6s ease-in-out infinite; display: inline-block; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(3px); } }

/* ---------- 頂部列（疊在地圖上） ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  height: 72px; padding: 0 24px;
  display: flex; align-items: center; gap: 20px;
  background: linear-gradient(rgba(26,22,20,.9), rgba(26,22,20,0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--washi); }
/* 品牌符號：平安符「庇」（設計 4b） */
.amulet { position: relative; width: 48px; height: 48px; flex: none; display: block; }
.amulet svg { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 3px 8px rgba(179,38,30,.35)); }
.amulet b { position: absolute; left: 0; right: 0; top: 38%; text-align: center; font-family: var(--serif); font-weight: 900; font-size: 19px; line-height: 1; color: var(--washi); }
.brand-lock { display: flex; flex-direction: column; }
.brand-name { font-family: var(--serif); font-weight: 900; font-size: 20px; line-height: 1; letter-spacing: .04em; }
.brand-en { font-size: 9px; letter-spacing: .3em; color: var(--gold-2); font-weight: 700; margin-top: 4px; }

.search-wrap { position: relative; width: 380px; max-width: 100%; }
.search {
  width: 100%; height: 44px; border-radius: 22px;
  background: rgba(243,235,220,.96); color: var(--ink);
  display: flex; align-items: center; gap: 10px; padding: 0 12px 0 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.search-icon { width: 18px; height: 18px; flex: none; color: var(--ink); }
#q {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  font-family: var(--sans); font-size: 14px; color: var(--ink);
}
#q::placeholder { color: var(--ink-55); }
#q::-webkit-search-cancel-button { -webkit-appearance: none; }
.search.nearest-on { border: 2px solid var(--red); }
.search-back { border: 0; background: none; color: var(--red); font-size: 20px; font-weight: 700; padding: 0 2px 2px 0; line-height: 1; }
.search-back[hidden] { display: none; }
.nearest-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; color: var(--washi); background: var(--ink); padding: 4px 8px; white-space: nowrap; }
.nearest-tag[hidden] { display: none; }
.nearest-tag i { width: 6px; height: 6px; border-radius: 50%; background: #1F4E5F; border: 1.5px solid var(--washi); display: inline-block; }
.suggest {
  position: absolute; left: 0; right: 0; top: 52px; z-index: 30;
  background: rgba(243,235,220,.97); color: var(--ink); border-radius: 6px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.suggest[hidden] { display: none; }
.sg { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--ink-08); background: none; color: var(--ink); font-size: 14px; }
.sg:last-child { border-bottom: 0; }
.sg:hover, .sg.hot { background: rgba(179,38,30,.07); }
.sg-ic { width: 20px; height: 20px; flex: none; border: 1.5px solid var(--ink); display: grid; place-items: center; font-size: 10px; font-weight: 700; font-family: var(--serif); }
.sg-ic.round { border-radius: 50%; border-width: 2px; }
.sg b { font-weight: 700; }
.sg .sg-tag { margin-left: auto; font-size: 10px; color: var(--red); font-weight: 700; letter-spacing: .1em; }
.sg .sg-sub { margin-left: auto; font-size: 11px; color: var(--ink-55); }
.region-wrap { position: relative; flex: none; display: inline-block; }
.region-tag {
  display: inline-block; font-size: 11px; font-weight: 700; color: var(--red);
  border: 1px solid var(--red); padding: 2px 6px; white-space: nowrap; pointer-events: none;
}
#region { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

#nav { margin-left: auto; display: flex; align-items: center; gap: 18px; white-space: nowrap; }
.nav-link {
  position: relative; background: none; border: 0; padding: 4px 0 2px;
  font-size: 13px; color: var(--washi-70); border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--washi); }
.nav-link.active { color: var(--gold); font-weight: 700; border-bottom-color: var(--red); }
.nav-link .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--red); vertical-align: middle; margin-left: 3px; }
.nav-lang { letter-spacing: .1em; }

/* ---------- 神明籤 ---------- */
#chips {
  position: absolute; top: 84px; left: 24px; right: 24px; z-index: 9;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; white-space: nowrap;
  padding-bottom: 4px; -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}
#chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 4px;
  font-family: var(--serif); font-size: 13px;
  background: rgba(26,22,20,.85); color: var(--gold);
  border: 1px solid rgba(201,164,76,.5);
}
.chip.active { background: var(--red); color: var(--washi); font-weight: 700; border-color: var(--red); box-shadow: inset 0 0 0 1px var(--gold); }

/* ---------- 地圖控制鈕 ---------- */
#map-ctl-left { position: absolute; left: 24px; bottom: 24px; z-index: 9; display: flex; flex-direction: column; gap: 8px; }
#map-ctl-left button {
  width: 40px; height: 40px; border: 0; background: var(--washi); color: var(--ink);
  font-size: 20px; font-weight: 700; line-height: 1; box-shadow: 0 6px 16px rgba(0,0,0,.35);
}
#map-ctl-left .locate { background: var(--red); box-shadow: 0 6px 16px rgba(179,38,30,.45); display: grid; place-items: center; }
#map-ctl-left .locate i { width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid var(--gold); display: block; }
#map-ctl-left .locate.on i { background: var(--gold); }
#map-ctl-left .tilt { font-family: var(--serif); font-size: 13px; letter-spacing: .04em; }
#map-ctl-left .tilt.on { background: var(--ink); color: var(--gold); box-shadow: inset 0 0 0 1.5px var(--gold-2), 0 6px 16px rgba(0,0,0,.35); }

.seg {
  position: absolute; right: 24px; bottom: 24px; z-index: 9; display: flex;
  background: rgba(26,22,20,.9); border: 1px solid rgba(201,164,76,.5);
  font-family: var(--serif); font-size: 12px;
}
.seg button { border: 0; background: none; padding: 8px 14px; color: rgba(243,235,220,.6); }
.seg button + button { border-left: 1px solid rgba(201,164,76,.3); }
.seg button.active { color: var(--gold); font-weight: 700; background: var(--red); }

/* ---------- 廟宇 popup（2a：宣紙、紅底線、紅三角） ---------- */
.bb-popup .maplibregl-popup-content {
  background: var(--washi); color: var(--ink); border-radius: 0;
  padding: 14px 16px; min-width: 220px; border-bottom: 3px solid var(--red);
  box-shadow: 0 12px 30px rgba(0,0,0,.45); font-family: var(--serif);
}
.bb-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--red); }
.bb-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--washi); }
.bb-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--washi); }
.bb-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--washi); }
.pop-kicker { font-family: var(--sans); font-size: 10px; letter-spacing: .2em; color: var(--red); font-weight: 700; }
.pop-name { font-weight: 900; font-size: 22px; margin-top: 4px; line-height: 1.2; }
.pop-addr { font-family: var(--sans); font-size: 12px; color: rgba(26,22,20,.6); margin-top: 4px; }
.pop-cta {
  display: flex; align-items: center; justify-content: center; margin-top: 10px; height: 36px;
  background: var(--red); color: var(--washi); text-decoration: none;
  font-family: var(--sans); font-weight: 700; font-size: 13px; letter-spacing: .1em;
  box-shadow: var(--seal-red);
}
.pop-cta:hover { background: var(--red-d); }
.approx { font-style: normal; font-family: var(--sans); font-size: 10.5px; color: var(--cinnabar, #B3261E); opacity: .8; margin-left: 4px; white-space: nowrap; }
.pop-dist { color: var(--red); font-weight: 700; }
.pop-bday { margin-top: 6px; font-size: 11.5px; color: var(--ink); padding-left: 10px; border-left: 3px solid var(--gold-2); line-height: 1.5; }
.pop-actions { display: flex; gap: 8px; margin-top: 10px; }
.pop-actions .pop-cta { flex: 1; margin-top: 0; }
.pop-3d { width: 44px; height: 36px; border: 1.5px solid var(--ink); background: none; color: var(--ink); font-family: var(--serif); font-weight: 700; font-size: 12px; letter-spacing: .04em; }
.pop-3d:hover { background: var(--ink); color: var(--gold); }

/* ---------- 宣紙清單欄 ---------- */
#panel {
  position: relative; z-index: 12; flex: none; width: var(--panel-w);
  background: var(--washi); color: var(--ink);
  display: flex; flex-direction: column; box-shadow: -16px 0 40px rgba(0,0,0,.45);
}
.stripe { height: 8px; margin: 0 24px; background: var(--stripe); opacity: .9; flex: none; }
#sheet-handle { display: none; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; padding: 22px 24px 12px; flex: none; }
.panel-title { margin: 0; font-family: var(--serif); font-weight: 900; font-size: 24px; letter-spacing: .04em; }
.panel-count { font-size: 13px; font-weight: 400; color: var(--red); margin-left: 10px; font-family: var(--sans); }
.sort-btn { background: none; border: 0; padding: 0; font-size: 12px; color: var(--ink-55); }
.sort-btn:hover { color: var(--ink); }

.list { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.detail { display: none; }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px 24px 14px 28px; border: 0; border-top: 1px solid var(--ink-08);
  background: none; color: var(--ink); border-left: 4px solid transparent; padding-left: 24px;
}
.row:hover { background: rgba(26,22,20,.035); }
.row.selected { background: rgba(179,38,30,.06); border-left-color: var(--red); }
.seal {
  width: 48px; height: 48px; flex: none; border-radius: 4px; display: grid; place-items: center;
  font-family: var(--serif); font-weight: 900; font-size: 22px;
}
.seal.red { background: var(--red); color: var(--washi); box-shadow: var(--seal-red); }
.seal.ink { background: var(--ink); color: var(--gold); box-shadow: var(--seal-ink); }
.row-main { flex: 1; min-width: 0; }
.row-name { display: block; font-family: var(--serif); font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; font-size: 12.5px; color: rgba(26,22,20,.6); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 收藏：書籤形（未收藏＝金色描邊，已收藏＝紅色實心） */
.save {
  width: 36px; height: 36px; flex: none; border-radius: 4px; border: 0;
  background: none; display: grid; place-items: center; padding: 0; margin-right: -6px; color: var(--gold-2);
}
.save .bm { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; transition: transform .15s; }
.save:active .bm { transform: scale(.9); }
.save.on { color: var(--red); }
.save.on .bm { fill: currentColor; }
.rank { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; font-family: var(--serif); font-weight: 900; font-size: 15px; }
.rank.red { background: var(--red); color: var(--washi); border: 2px solid var(--gold); }
.rank.ink { background: var(--ink); color: var(--gold); border: 2px solid var(--gold-2); }
.row-dist { text-align: right; font-family: var(--serif); font-weight: 900; font-size: 17px; white-space: nowrap; }
.row-dist small { font-size: 10px; font-weight: 400; margin-left: 2px; font-family: var(--sans); }
.row-dist.red { color: var(--red); }
.list-empty { padding: 28px 24px; color: var(--ink-55); font-size: 13.5px; line-height: 1.7; }
.list-empty button { margin-top: 10px; background: none; border: 1.5px solid var(--ink); padding: 8px 14px; font-family: var(--serif); font-weight: 700; color: var(--ink); }

.live-card {
  flex: none; margin: 12px 24px 20px; padding: 14px 16px; text-align: left;
  background: var(--ink); color: var(--washi); border: 0;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--seal-ink);
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px rgba(179,38,30,.35); flex: none; }
.live-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.live-kicker { font-size: 10px; letter-spacing: .2em; color: var(--gold); font-weight: 700; }
.live-title { font-family: var(--serif); font-weight: 700; font-size: 15px; margin-top: 2px; }
.live-more { font-size: 12px; color: var(--gold); white-space: nowrap; }

/* ---------- 手機分頁列（桌機隱藏） ---------- */
#tabbar { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  z-index: 50; padding: 10px 16px; background: var(--washi); color: var(--ink);
  font-size: 13px; font-weight: 700; border-bottom: 3px solid var(--red);
  box-shadow: 0 12px 30px rgba(0,0,0,.45); white-space: nowrap;
}
.toast[hidden] { display: none; }

/* 窄桌機／橫向平板（1024–1200px）：頂部列緊湊，避免導覽被右欄蓋住 */
@media (min-width: 1024px) and (max-width: 1200px) {
  #topbar { padding: 0 16px; gap: 12px; }
  .brand-lock { display: none; }
  .search-wrap { width: 250px; }
  #nav { gap: 12px; }
  .nav-link { font-size: 12.5px; }
  #chips { left: 16px; }
}

/* ============================================================
   平板／手機（< 1024px）：地圖滿版、頂部 logo＋搜尋、底部宣紙面板＋分頁列
   ============================================================ */
@media (max-width: 1023px) {
  #home { display: block; }
  #map-wrap { position: absolute; inset: 0; }
  .to-events { display: none; }

  #topbar { height: auto; padding: 14px 16px 0; gap: 10px; background: linear-gradient(rgba(26,22,20,.85), rgba(26,22,20,0) 140%); }
  .brand-lock { display: none; }
  .amulet { width: 44px; height: 44px; }
  .amulet b { font-size: 17px; }
  .search-wrap { flex: 1; width: auto; min-width: 0; }
  .search { width: 100%; height: 46px; border-radius: 23px; padding: 0 10px 0 14px; gap: 8px; }
  /* iOS：輸入框字級小於 16px 時，聚焦會自動把整頁放大，離開後版面就偏掉 → 手機一律 16px */
  #q, #region, select, input, textarea { font-size: 16px; }
  .suggest { top: 54px; }
  #nav { display: none; }

  #chips { top: 74px; left: 16px; right: 0; padding-right: 16px; }

  #map-ctl-left { left: 16px; bottom: calc(var(--tab-h) + var(--sheet-peek) + 14px); }
  #zoom-in, #zoom-out { display: none; }
  body.sheet-open #basemap, body.sheet-open #map-ctl-left { opacity: 0; pointer-events: none; transition: opacity .2s; }
  /* 底圖切換移到右上（籤列下方），底部留給面板與卡片 */
  .seg { right: 16px; top: 122px; bottom: auto; font-size: 11px; }
  .seg button { padding: 6px 10px; }
  /* 手機：地圖上只放精簡標籤，完整資訊在底部面板詳情卡 */
  .bb-popup .maplibregl-popup-content { min-width: 0; padding: 8px 12px 9px; border-bottom-width: 3px; }
  .bb-popup .pop-kicker { font-size: 9px; letter-spacing: .12em; }
  .bb-popup .pop-name { font-size: 15px; margin-top: 2px; }
  .bb-popup .pop-addr, .bb-popup .pop-actions, .bb-popup .pop-bday { display: none; }   /* 手機精簡：聖誕與地址在詳情卡 */
  .bb-popup .maplibregl-popup-content { max-width: min(80vw, 340px); }
  .bb-popup .pop-name { white-space: normal; line-height: 1.25; }
  .detail { display: block; flex: none; margin: 0 16px 8px; padding: 12px 14px 12px; background: var(--washi); border: 1.5px solid var(--ink); box-shadow: 4px 4px 0 var(--red); }
  .detail[hidden] { display: none; }
  .dt-k { font-size: 10px; letter-spacing: .2em; color: var(--red); font-weight: 700; }
  .dt-name { font-family: var(--serif); font-weight: 900; font-size: 20px; line-height: 1.2; margin-top: 3px; }
  .dt-sub { font-size: 12px; color: rgba(26,22,20,.6); margin-top: 4px; line-height: 1.5; }
  .dt-dist { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 3px 9px; background: var(--red); color: var(--washi); font-size: 12px; font-weight: 700; letter-spacing: .04em; }
  .dt-dist i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); display: block; }
  .dt-bday { margin-top: 6px; font-size: 12px; color: var(--ink); padding-left: 9px; border-left: 3px solid var(--gold-2); line-height: 1.45; }
  .dt-actions { display: flex; gap: 8px; margin-top: 10px; }
  .dt-actions .go { flex: 1; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--red); color: var(--washi); text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 14px; letter-spacing: .1em; box-shadow: var(--seal-red); }
  .dt-actions .d3 { width: 44px; height: 40px; border: 1.5px solid var(--ink); background: none; color: var(--ink); font-family: var(--serif); font-weight: 700; font-size: 12px; }
  .dt-actions .sv, .dt-actions .cl { width: 40px; height: 40px; border: 1.5px solid var(--ink); background: none; display: grid; place-items: center; color: var(--ink); font-size: 16px; }
  .dt-actions .sv.on { background: var(--red); border-color: var(--red); color: var(--washi); }
  .dt-actions .sv .bm { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
  .dt-actions .sv.on .bm { fill: currentColor; }

  #panel {
    position: absolute; left: 0; right: 0; bottom: var(--tab-h); width: auto;
    height: var(--sheet-peek); border-radius: 22px 22px 0 0;
    box-shadow: 0 -16px 40px rgba(0,0,0,.45); transition: height .28s cubic-bezier(.2,.8,.2,1);
  }
  #panel { overflow: hidden; }
  #panel.expanded { height: calc(100% - var(--tab-h) - 120px); }
  /* 選到廟：面板長到剛好放下詳情卡（清單先收起來），沒展開就不蓋地圖 */
  #panel.has-detail:not(.expanded) { height: auto; max-height: calc(100% - var(--tab-h) - 200px); }
  #panel.has-detail:not(.expanded) .list, #panel.has-detail:not(.expanded) .live-card { display: none; }
  #panel.has-detail:not(.expanded) .panel-head { padding-bottom: 8px; }
  /* 收合狀態只露把手＋標題列，清單與進香小卡整個藏起來（不露半截） */
  #panel:not(.expanded):not(.has-detail) .list, #panel:not(.expanded):not(.has-detail) .live-card { display: none; }
  .stripe { margin: 0 22px; border-radius: 0 0 2px 2px; }
  /* 拉桿：22px 高的觸控區，中間畫 40×4 的把手 */
  #sheet-handle { display: block; width: 100%; height: 22px; background: none; border: 0; padding: 0; margin: 0; position: relative; flex: none; }
  #sheet-handle::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: rgba(26,22,20,.2); margin: 9px auto 0; }
  .panel-head { padding: 4px 22px 6px; cursor: pointer; }
  .panel-title { font-size: 22px; }
  .row { padding: 12px 22px; }
  .seal { width: 44px; height: 44px; font-size: 20px; }
  .live-card { margin: 10px 22px 14px; }

  #tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--tab-h); z-index: 40;
    display: grid; grid-template-columns: repeat(4, 1fr); padding: 10px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--ink); border-top: 2px solid var(--red);
  }
  .tab { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: none; color: var(--washi-50); font-size: 11px; }
  .tab.active { color: var(--gold); font-weight: 700; }
  .ic { width: 22px; height: 22px; border: 2px solid currentColor; display: block; }
  .ic-map, .ic-saved { border-radius: 50%; }
  .ic-passport, .ic-events { border-radius: 3px; }
  .ic-parade, .ic-me { border-radius: 50% 50% 3px 3px; }
  .tab.active .ic { background: var(--red); border-color: var(--gold); }

  .toast { bottom: calc(var(--tab-h) + 16px); max-width: calc(100% - 32px); white-space: normal; text-align: center; }
}

@media (max-width: 480px) {
  .bb-popup .maplibregl-popup-content { min-width: 0; }
}
/* 矮螢幕手機：底部面板預設收得更矮，多留地圖 */
@media (max-width: 1023px) and (max-height: 720px) {
  :root { --sheet-peek: 92px; }
}

/* ============================================================
   廟會活動 ＋ 進香倒數（3a 桌機／3c 手機）—— 獨立頁 events.html
   ============================================================ */
/* 活動頁的頂欄：不疊在地圖上，固定於頁頂 */
#topbar.page-top { position: sticky; top: 0; background: var(--ink); border-bottom: 2px solid var(--red); pointer-events: auto; z-index: 30; }
.page-title { display: flex; flex-direction: column; gap: 3px; font-family: var(--serif); font-weight: 700; font-size: 15px; color: var(--washi); padding-left: 20px; border-left: 1px solid rgba(201,164,76,.35); white-space: nowrap; }
a.nav-link, a.tab { text-decoration: none; }
a.nav-link { display: inline-block; line-height: 1.5; }
#events.page { min-height: calc(100vh - 72px); min-height: calc(100dvh - 72px); }
#events.page .countdown { border-top: 0; }
.ev-locate { display: inline-flex; align-items: center; gap: 8px; border: 1.5px solid var(--ink); background: none; color: var(--ink); font-size: 12.5px; padding: 8px 12px; }
.ev-locate i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; display: block; }
.ev-locate.on { background: var(--ink); color: var(--gold); border-color: var(--ink); }
.ev-locate.on i { background: var(--gold); border-color: var(--gold); }
@media (max-width: 1023px) {
  #topbar.page-top { height: 64px; padding: 0 16px; gap: 12px; align-items: center; }
  .page-title { font-size: 14px; padding-left: 12px; }
  .page-title .kicker { display: none; }
  #events.page { min-height: calc(100dvh - 64px); }
  .ev-block-loc { padding-top: 2px; }
}
#events { position: relative; background: var(--washi); color: var(--ink); scroll-margin-top: 0; overflow-x: hidden; }
.kicker { font-size: 10px; letter-spacing: .28em; color: var(--gold); font-weight: 700; }
.kicker.red { color: var(--red); }

.countdown {
  background: var(--ink); color: var(--washi);
  padding: 22px 24px 24px; display: flex; gap: 16px; align-items: stretch;
  border-top: 2px solid var(--red); border-bottom: 1px solid rgba(201,164,76,.35);
}
.cd-title { width: 120px; flex: none; display: flex; flex-direction: column; justify-content: center; }
.cd-title h2 { font-family: var(--serif); font-weight: 900; font-size: 22px; margin: 4px 0 0; line-height: 1.1; }
.cd-cards { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.cd { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 1.5px solid rgba(201,164,76,.5); text-align: left; color: var(--washi); background: none; text-decoration: none; min-width: 0; }
.cd.live { background: var(--red); border-color: var(--red); box-shadow: var(--seal-red); }
.cd-num { text-align: center; flex: none; }
.cd-num b { display: block; font-family: var(--serif); font-weight: 900; font-size: 34px; line-height: 1; color: var(--gold); }
.cd-num span { display: block; font-size: 10px; color: var(--washi-50); margin-top: 2px; white-space: nowrap; }
.cd-main { flex: 1; min-width: 0; border-left: 1px dashed rgba(201,164,76,.4); padding-left: 14px; }
.cd.live .cd-main { border-left: 0; padding-left: 0; }
.cd-live { display: flex; align-items: center; gap: 6px; font-size: 10px; letter-spacing: .2em; color: var(--gold); font-weight: 700; }
.cd-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 3px rgba(232,200,114,.3); }
.cd-name { font-family: var(--serif); font-weight: 900; font-size: 16px; margin-top: 4px; line-height: 1.25; }
.cd-sub { font-size: 11px; color: rgba(243,235,220,.6); margin-top: 3px; }
.cd-route { font-size: 11px; color: var(--gold); margin-top: 2px; }
.cd-est { display: inline-block; font-size: 9.5px; letter-spacing: .1em; color: var(--ink); background: var(--gold); padding: 1px 6px; margin-left: 6px; vertical-align: 1px; }
.cd-more { font-family: var(--serif); font-weight: 700; font-size: 12px; color: var(--gold); white-space: nowrap; }
.cd-empty { grid-column: 1 / -1; color: var(--washi-50); font-size: 13px; padding: 12px 0; }

.ev-body { display: flex; min-height: 640px; }
.ev-side { width: 280px; flex: none; border-right: 1.5px solid var(--ink); padding: 26px 24px; display: flex; flex-direction: column; gap: 24px; }
.ev-h { font-family: var(--serif); font-weight: 900; font-size: 32px; line-height: 1.1; margin: 8px 0 0; letter-spacing: .03em; }
.ev-sub { font-size: 12.5px; color: rgba(26,22,20,.6); margin-top: 6px; }
.ev-lab { display: flex; align-items: baseline; justify-content: space-between; font-family: var(--serif); font-weight: 700; font-size: 14px; }
.ev-lab-sub { font-size: 11px; color: rgba(26,22,20,.5); font-family: var(--sans); font-weight: 400; }
.ev-months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.ev-months button { height: 40px; border: 1.5px solid var(--ink); background: none; color: var(--ink); font-family: var(--serif); font-size: 13px; }
.ev-months button.active { background: var(--red); border-color: var(--red); color: var(--washi); font-weight: 700; }
.ev-months button.dim { border-color: rgba(26,22,20,.25); color: rgba(26,22,20,.4); }
.ev-note { font-size: 11px; color: rgba(26,22,20,.5); margin-top: 8px; }
.ev-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ev-chips button { padding: 6px 12px; border: 1.5px solid var(--ink); background: none; color: var(--ink); font-size: 12.5px; font-family: var(--serif); }
.ev-chips button.active { background: var(--red); border-color: var(--red); color: var(--washi); font-weight: 700; }
.ev-types { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; font-size: 13px; }
.ev-types label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.ev-types input { appearance: none; width: 14px; height: 14px; border: 1.5px solid var(--ink); margin: 0; }
.ev-types input:checked { background: var(--red); }

.ev-main { flex: 1; min-width: 0; padding: 26px 28px 40px; }
.ev-tabs { display: flex; align-items: baseline; gap: 18px; margin-bottom: 16px; font-family: var(--serif); font-size: 15px; }
.ev-tabs button { border: 0; background: none; color: rgba(26,22,20,.55); font: inherit; padding: 0 0 4px; border-bottom: 2px solid transparent; }
.ev-tabs button.active { color: var(--ink); font-weight: 900; border-bottom-color: var(--red); }
.ev-tabs button span { font-size: 12px; font-weight: 400; margin-left: 2px; font-family: var(--sans); }
.ev-tabs button.active span { color: var(--red); }
.ev-sort { margin-left: auto; font-size: 12px; color: rgba(26,22,20,.55); font-family: var(--sans); }

.ev-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.evc { background: var(--washi); border: 1.5px solid var(--ink); box-shadow: 5px 5px 0 var(--red); display: flex; flex-direction: column; text-align: left; color: var(--ink); min-width: 0; }
.evc-img { position: relative; height: 150px; background: #2A241F; overflow: hidden; display: grid; place-items: center; }
.evc-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.evc-img .evc-seal { font-family: var(--serif); font-weight: 900; font-size: 96px; color: rgba(232,200,114,.12); line-height: 1; user-select: none; }
.evc-img .evc-tname { position: absolute; right: 12px; bottom: 10px; font-size: 11px; color: rgba(243,235,220,.55); letter-spacing: .1em; }
.lunar-tag { position: absolute; left: 12px; top: 12px; background: var(--red); color: var(--washi); padding: 6px 10px; font-family: var(--serif); font-weight: 900; line-height: 1; text-align: center; box-shadow: var(--seal-red); }
.lunar-tag small { display: block; font-size: 9px; letter-spacing: .1em; opacity: .85; font-weight: 700; }
.lunar-tag b { display: block; font-size: 16px; margin-top: 2px; }
.ev-badge { position: absolute; right: 12px; top: 12px; padding: 4px 8px; font-size: 10px; font-weight: 700; letter-spacing: .1em; }
.ev-badge.live { background: var(--gold); color: var(--ink); }
.ev-badge.soon { background: var(--ink); color: var(--gold); }
.evc-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.evc-k { font-size: 10px; letter-spacing: .2em; color: var(--red); font-weight: 700; }
.evc-t { font-family: var(--serif); font-weight: 900; font-size: 18px; line-height: 1.25; }
.evc-d { font-size: 12px; color: rgba(26,22,20,.6); line-height: 1.5; }
.evc-f { margin-top: auto; padding-top: 10px; display: flex; align-items: center; gap: 12px; font-size: 12px; }
.evc-f .dist { color: rgba(26,22,20,.55); }
.evc-f .act { margin-left: auto; display: flex; gap: 12px; }
.evc-f button { border: 0; background: none; font-family: var(--serif); font-weight: 700; font-size: 12px; color: var(--red); padding: 0; }
.evc-f button.ics { color: var(--ink); }

.ev-rows { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 24px; }
.evr { border: 1.5px solid var(--ink); padding: 14px 16px; display: flex; gap: 14px; align-items: center; background: none; color: var(--ink); text-align: left; min-width: 0; }
.evr-date { text-align: center; flex: none; width: 52px; border-right: 1px dashed rgba(26,22,20,.3); padding-right: 12px; }
.evr-date small { display: block; font-size: 10px; color: var(--red); font-weight: 700; }
.evr-date b { display: block; font-family: var(--serif); font-weight: 900; font-size: 24px; line-height: 1; }
.evr-main { flex: 1; min-width: 0; }
.evr-t { font-family: var(--serif); font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.evr-s { font-size: 11.5px; color: rgba(26,22,20,.55); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-empty { padding: 40px 0; color: rgba(26,22,20,.55); font-size: 13.5px; }

@media (max-width: 1023px) {
  .countdown { flex-direction: column; gap: 14px; padding: 18px 16px 18px; }
  .cd-title { width: auto; flex-direction: row; align-items: baseline; gap: 12px; }
  .cd-cards { display: flex; overflow-x: auto; scrollbar-width: none; gap: 10px; padding-bottom: 4px; }
  .cd-cards::-webkit-scrollbar { display: none; }
  .cd { flex: none; width: 240px; padding: 12px 14px; }
  .cd-num b { font-size: 30px; }
  .cd-name { font-size: 15px; }
  .ev-body { flex-direction: column; min-height: 0; }
  .ev-side { width: auto; border-right: 0; padding: 20px 16px 0; gap: 14px; }
  .ev-h { font-size: 28px; }
  .ev-months { display: flex; overflow-x: auto; scrollbar-width: none; }
  .ev-months button { flex: none; height: 36px; padding: 0 14px; }
  .ev-chips, .ev-types { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ev-types label { flex: none; padding: 6px 10px; border: 1.5px solid var(--ink); font-size: 12px; }
  .ev-main { padding: 16px 16px calc(var(--tab-h) + 32px); }
  .ev-cards { grid-template-columns: 1fr; gap: 12px; }
  .evc { flex-direction: row; min-height: 118px; box-shadow: 4px 4px 0 var(--red); }
  .evc-img { width: 110px; height: auto; flex: none; }
  .evc-img .evc-seal { font-size: 56px; }
  .evc-img .evc-tname { display: none; }
  .lunar-tag { left: 8px; top: 8px; padding: 5px 8px; }
  .lunar-tag b { font-size: 13px; }
  .ev-badge { right: auto; left: 8px; top: auto; bottom: 8px; }
  .evc-body { padding: 12px 14px; gap: 4px; }
  .evc-t { font-size: 15px; }
  .evc-d { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .evc-f { padding-top: 6px; gap: 8px; font-size: 11px; }
  .evc-f .act { gap: 10px; }
  .evc-f button { font-size: 11.5px; white-space: nowrap; }
  .ev-rows { grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
}
@media (max-width: 420px) {
  .evc-f .dist { display: none; }   /* 窄手機：距離改由詳情呈現，頁尾只留動作 */
  .evc-img { width: 96px; }
}
