/* ── 色彩系統：SPEC.md §3 的驗證結果，改動前先讀那份文件 ── */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --panel: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --line: #e1e0d9;

  /* 美食 CP 值（橘色階，T1→T4 淺到深） */
  --t1: #ef9a5f; --t2: #e87434; --t3: #cf5011; --t4: #9c3607;
  /* 景點熱門度（藍色階） */
  --s1: #86b6ef; --s2: #5598e7; --s3: #256abf; --s4: #104281;
  /* 分類 chips（固定順序，不可重排） */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #4a3aa7; --c8: #e34948; --c0: #898781;

  --accent: #cf5011;
  --shadow: 0 2px 10px rgba(11,11,11,0.14);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --panel: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --line: #2c2c2a;

    --t1: #f6c19b; --t2: #ef9a5f; --t3: #e87434; --t4: #cf5011;
    --s1: #b7d3f6; --s2: #86b6ef; --s3: #3987e5; --s4: #184f95;
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
    --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c0: #898781;

    --accent: #e87434;
    --shadow: 0 2px 10px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --panel: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --line: #2c2c2a;

  --t1: #f6c19b; --t2: #ef9a5f; --t3: #e87434; --t4: #cf5011;
  --s1: #b7d3f6; --s2: #86b6ef; --s3: #3987e5; --s4: #184f95;
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
  --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c0: #898781;

  --accent: #e87434;
  --shadow: 0 2px 10px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Noto Sans TC", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}

#map { position: fixed; inset: 0; }
.leaflet-container { background: var(--page); font-family: inherit; }

/* ── 頂部工具列 ── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1200;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.28), rgba(0,0,0,0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.mode-switch {
  display: flex; background: var(--panel); border-radius: 999px;
  box-shadow: var(--shadow); overflow: hidden;
}
.mode-switch button {
  border: none; background: none; padding: 9px 14px; font-size: 14px; font-weight: 700;
  color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.mode-switch button.active { background: var(--accent); color: #fff; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--panel); box-shadow: var(--shadow);
  font-size: 17px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--ink);
}
#filter-btn { position: relative; margin-left: auto; }
#filter-count {
  position: absolute; top: -3px; right: -3px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 800;
  display: none; align-items: center; justify-content: center; line-height: 16px;
}
#filter-count.show { display: flex; }

/* ── 定位失敗提示條 ── */
#geo-banner {
  position: fixed; top: 60px; left: 12px; right: 12px; z-index: 1150;
  background: var(--panel); color: var(--ink-2); font-size: 13px;
  padding: 8px 12px; border-radius: 10px; box-shadow: var(--shadow);
  display: none; align-items: center; gap: 8px;
}
#geo-banner.show { display: flex; }
#geo-banner button { margin-left: auto; border: none; background: none; color: var(--ink-3); font-size: 16px; cursor: pointer; }

/* ── 右下角浮動按鈕 ── */
#fab-col {
  position: fixed; right: 14px; bottom: 0; z-index: 1200;
  display: flex; flex-direction: column; gap: 10px;
  transition: bottom .25s ease;
}
#fab-col button { width: 46px; height: 46px; font-size: 20px; }
#dice-btn { background: var(--accent); color: #fff; }

/* ── 標記 ── */
.marker-dot {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--panel); box-shadow: 0 1px 5px rgba(0,0,0,.45);
  color: #fff; font-size: 11px; line-height: 1;
}
.marker-dot.t4 { font-size: 13px; }
.marker-hit { position: relative; }
.marker-hit::after { content: ""; position: absolute; inset: -14px; }

.cluster-bubble {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--panel); box-shadow: 0 1px 6px rgba(0,0,0,.45);
  color: #fff; font-weight: 800; font-size: 12px;
}

/* ── Leaflet popup 覆蓋樣式 ── */
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--ink); border-radius: 12px; }
.leaflet-popup-tip { background: var(--panel); }
.popup-name { font-size: 15px; font-weight: 800; margin-bottom: 4px; }
.popup-badges { display: flex; gap: 4px; margin-bottom: 4px; flex-wrap: wrap; }
.badge-chip { font-size: 11px; padding: 2px 6px; border-radius: 999px; background: var(--line); color: var(--ink-2); }
.popup-meta { font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.popup-addr { font-size: 12px; color: var(--ink-3); margin-bottom: 8px; }
.popup-actions { display: flex; gap: 6px; }
.popup-actions a {
  flex: 1; text-align: center; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 700;
  text-decoration: none;
}
.btn-nav { background: #4285f4; color: #fff; }
.btn-review { background: var(--line); color: var(--ink); }

/* ── 底部清單（bottom sheet） ── */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100;
  height: 90vh; max-height: 90vh;
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.2);
  transform: translateY(calc(90vh - 56px));
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
  touch-action: none;
}
#sheet.dragging { transition: none; }
#sheet[data-snap="mid"] { transform: translateY(45vh); }
#sheet[data-snap="full"] { transform: translateY(0); }

#sheet-handle { flex: 0 0 auto; padding: 8px 0 4px; display: flex; justify-content: center; cursor: grab; }
#sheet-handle::before { content: ""; width: 36px; height: 4px; border-radius: 999px; background: var(--line); }

#sheet-header {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 2px 16px 10px; border-bottom: 1px solid var(--line);
}
#sheet-title { font-size: 15px; font-weight: 800; }
#sheet-sub { font-size: 12px; color: var(--ink-3); }
#legend-btn { margin-left: auto; font-size: 12px; color: var(--ink-2); background: var(--line); border: none; border-radius: 999px; padding: 5px 10px; }
#sort-select { font-size: 12px; color: var(--ink-2); background: var(--line); border: none; border-radius: 999px; padding: 5px 8px; }

#legend-panel {
  display: none; flex-wrap: wrap; gap: 8px 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--ink-2);
}
#legend-panel.show { display: flex; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; }

#list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--ink-3); font-size: 14px; }

.place-card {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.place-card:active { background: var(--page); }
.place-card.highlight { background: var(--page); }
.place-dot {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff;
}
.place-body { flex: 1 1 auto; min-width: 0; }
.place-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place-badges { display: inline-flex; gap: 3px; margin-left: 6px; }
.place-meta { font-size: 12px; color: var(--ink-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place-nav { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--line); font-size: 15px; }

#load-more { display: block; width: calc(100% - 32px); margin: 10px 16px 20px; padding: 10px; border: none; border-radius: 10px; background: var(--line); color: var(--ink-2); font-size: 13px; font-weight: 700; }

/* ── 篩選面板 ── */
#filter-sheet {
  position: fixed; inset: 0; z-index: 1300; display: none;
  background: rgba(0,0,0,0.35);
}
#filter-sheet.show { display: block; }
#filter-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--panel); border-radius: 16px 16px 0 0; padding: 16px 16px 28px;
}
.filter-section { margin-bottom: 18px; }
.filter-section h4 { font-size: 13px; color: var(--ink-3); margin-bottom: 8px; font-weight: 700; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid transparent; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 700;
  color: #fff; opacity: .45; cursor: pointer; white-space: nowrap;
}
.chip.active { opacity: 1; border-color: rgba(255,255,255,.85); }
.chip.plain { background: var(--line); color: var(--ink-2); opacity: 1; }
.chip.plain.active { background: var(--accent); color: #fff; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; font-size: 14px; }
.switch { position: relative; width: 42px; height: 24px; border-radius: 999px; background: var(--line); border: none; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .18s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); background: #fff; }
#filter-apply { width: 100%; padding: 13px; border: none; border-radius: 12px; background: var(--accent); color: #fff; font-size: 15px; font-weight: 800; }
#filter-panel-header { display: flex; align-items: center; margin-bottom: 12px; }
#filter-panel-header h3 { font-size: 16px; font-weight: 800; }
#filter-close { margin-left: auto; background: none; border: none; font-size: 20px; color: var(--ink-3); }

/* ── 卡片彈出（隨機推薦用） ── */
#pick-card {
  position: fixed; left: 12px; right: 12px; bottom: 70px; z-index: 1250;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  padding: 14px; display: none;
}
#pick-card.show { display: block; }
#pick-close { position: absolute; top: 8px; right: 10px; background: none; border: none; color: var(--ink-3); font-size: 16px; }

/* ≥900px：地圖左、清單右 */
@media (min-width: 900px) {
  #sheet {
    left: auto; right: 0; top: 0; bottom: 0; width: 380px; height: auto; max-height: none;
    border-radius: 0; transform: none !important; transition: none;
  }
  #sheet-handle { display: none; }
  #fab-col { right: 396px; }
}
