/* ===== 台灣公路旅遊達人 — 全域樣式 ===== */
:root {
  --bg: #f4f6fa;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-solid: #ffffff;
  --text: #16202e;
  --muted: #5b6879;
  --line: #dde3ec;
  --accent: #1f6feb;
  --accent-soft: #e8f1ff;
  --danger: #e5484d;
  --shadow: 0 10px 32px rgba(15, 32, 60, 0.18);
  --radius: 14px;
  --topbar-h: 60px;
  --hand-font: "Zhi Mang Xing", "Ma Shan Zheng", "Noto Serif TC", cursive;
  --paper: #f3e9d0;
  --ink: #6b5337;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1420;
  --panel: rgba(22, 31, 45, 0.96);
  --panel-solid: #161f2d;
  --text: #e8eef7;
  --muted: #9aabc0;
  --line: #2b3a4f;
  --accent: #5b9cff;
  --accent-soft: #1c2e48;
  --danger: #ff7b7f;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.55;
}

button, input { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ===== 地圖 ===== */
#map,
#map.leaflet-container {
  position: absolute;
  inset: 0;
  z-index: 0;
  /* 紙張底色 + 淡紙紋 + 手繪水波紋（全部為內嵌 SVG，不帶外部資源） */
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.085'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='130' height='72'%3E%3Cg fill='none' stroke='%237fa8b8' stroke-width='1.15' stroke-linecap='round' opacity='0.42'%3E%3Cpath d='M3 16 q9 -6 18 0 t18 0 t18 0'/%3E%3Cpath d='M67 46 q9 -6 18 0 t18 0 t18 0'/%3E%3Cpath d='M-12 54 q9 -6 18 0 t18 0'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.55), transparent 70%);
  background-repeat: repeat, repeat, no-repeat;
}

/* 瓦片透明度／濾鏡由 JS 依縮放等級控制，這裡只負責平滑過渡 */
.leaflet-tile-pane { transition: opacity .5s ease, filter .5s ease; }

/* ===== 頂部工具列 ===== */
#topbar {
  position: absolute;
  z-index: 1100;
  top: 12px;
  left: 12px;
  right: 12px;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.brand-logo { font-size: 24px; line-height: 1; }
.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .5px;
  white-space: nowrap;
}

.search-wrap { position: relative; flex: 1 1 320px; min-width: 140px; }
#search-input {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#search-input::placeholder { color: var(--muted); }

.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 340px;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.search-results.show { display: block; }
.search-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
}
.search-item:last-child { border-bottom: 0; }
.search-item:hover, .search-item:focus { background: var(--accent-soft); }
.search-item .si-kind { font-size: 16px; }
.search-item .si-id { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.search-item .si-name { font-weight: 600; }
.no-result { padding: 12px; color: var(--muted); }

.toolbar { display: flex; gap: 6px; flex: 0 0 auto; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 38px;
  padding: 0 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.btn-icon { min-width: 38px; padding: 0 9px; font-size: 16px; }
.btn.btn-block { width: 100%; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ===== 浮動面板（篩選 / 附近） ===== */
.popover {
  display: none;
  position: absolute;
  z-index: 1150;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  max-height: calc(100vh - var(--topbar-h) - 44px);
  overflow-y: auto;
}
.popover.open { display: block; }
.filter-popover {
  top: calc(var(--topbar-h) + 22px);
  left: 12px;
  width: 300px;
}
.nearby-popover {
  top: calc(var(--topbar-h) + 22px);
  right: 12px;
  width: 300px;
}
.pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.filter-group { margin: 10px 0; }
.filter-group h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 700; }
.chk-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 8px; }
.chk {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 4px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
}
.chk:hover { background: var(--accent-soft); }
.chk input { accent-color: var(--accent); margin: 0; }
.result-count { margin: 10px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.nearby-list { display: flex; flex-direction: column; gap: 2px; }
.nearby-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 6px;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 8px;
}
.nearby-item:hover { background: var(--accent-soft); }
.nearby-item .ni-kind { font-size: 17px; }
.nearby-item .ni-name { flex: 1; font-weight: 600; }
.nearby-item .ni-dist { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ===== 側邊面板 ===== */
.side-panel {
  display: flex;
  flex-direction: column;
  position: absolute;
  z-index: 1050;
  top: calc(var(--topbar-h) + 22px);
  bottom: 34px;
  width: 350px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .26s ease, opacity .26s ease;
}
.road-panel { left: 12px; transform: translateX(calc(-100% - 20px)); opacity: 0; pointer-events: none; }
.detail-panel { right: 12px; width: 380px; transform: translateX(calc(100% + 20px)); opacity: 0; pointer-events: none; }
.side-panel.open { transform: translateX(0); opacity: 1; pointer-events: auto; }
.panel-close { position: absolute; top: 10px; right: 10px; z-index: 2; background: var(--bg); }

.road-head { position: relative; padding: 16px 46px 12px 16px; border-bottom: 1px solid var(--line); }
.road-head h2 { margin: 6px 0 4px; font-size: 17px; }
.road-meta { color: var(--muted); font-size: 12px; }
.road-body, .detail-body { padding: 12px 16px 18px; overflow-y: auto; flex: 1; }
.tag {
  display: inline-block;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--tag-color, var(--accent));
  background: color-mix(in srgb, var(--tag-color, var(--accent)) 14%, transparent);
  border-radius: 999px;
}
.tag-road { --tag-color: var(--accent); }
.road-summary { margin: 0 0 10px; color: var(--text); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.road-facts { display: grid; grid-template-columns: 72px 1fr; gap: 6px 10px; margin: 0 0 14px; font-size: 12.5px; }
.road-facts dt { color: var(--muted); }
.road-facts dd { margin: 0; }
.section-title { font-size: 13px; margin: 0 0 8px; color: var(--muted); }
.section-title span { color: var(--accent); }
.road-spots { list-style: none; margin: 0; padding: 0; counter-reset: spot; }
.road-spot {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  margin-bottom: 3px;
  text-align: left;
  color: var(--text);
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 9px;
}
.road-spot:hover { border-color: var(--accent); }
.road-spot.current { border-color: var(--accent); background: var(--accent-soft); }
.rs-num { flex: 0 0 42px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.rs-kind { font-size: 16px; }
.rs-name { flex: 1; font-weight: 600; }

/* ===== 景點詳情 ===== */
.detail-head { position: relative; padding: 16px 46px 12px 16px; border-bottom: 1px solid var(--line); }
.detail-head h2 { margin: 8px 0 0; font-size: 18px; }
.id-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 6px;
  font-size: 11.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.carousel {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--bg);
  border-radius: 10px;
}
.carousel-images { position: absolute; inset: 0; }
.carousel-images img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .25s ease;
}
.carousel-images img.active { opacity: 1; }
.carousel-images img.broken { display: none; }
.carousel-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
.carousel-placeholder.hidden { display: none; }
.carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  color: #fff;
  background: rgba(0, 0, 0, .45);
  border: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}
.carousel-nav.prev { left: 8px; }
.carousel-nav.next { right: 8px; }
.carousel-nav:hover { background: rgba(0, 0, 0, .7); }
.carousel-nav.hidden { display: none; }
.carousel-dots { position: absolute; bottom: 8px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; }
.carousel-dot { width: 7px; height: 7px; background: rgba(255, 255, 255, .55); border: 0; border-radius: 50%; padding: 0; }
.carousel-dot.active { background: #fff; transform: scale(1.25); }

.detail-desc { margin: 0 0 8px; white-space: pre-wrap; }
.detail-tips {
  margin: 0 0 12px;
  padding: 8px 10px;
  color: var(--muted);
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-size: 12.5px;
}
.detail-tips:empty { display: none; }
.detail-facts { display: flex; gap: 10px; margin-bottom: 12px; }
.detail-facts > div {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 9px;
}
.fact-label { display: block; color: var(--muted); font-size: 11px; }
.detail-facts strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.action-links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.btn-link {
  flex: 1 1 auto;
  padding: 7px 8px;
  text-align: center;
  text-decoration: none;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.btn-link:hover { filter: brightness(.96); }
.btn-link.hidden { display: none; }
.embed-wrap { display: none; margin-top: 10px; }
.embed-wrap.open { display: block; }
.embed-wrap iframe { width: 100%; height: 240px; border: 0; border-radius: 10px; }

/* ===== 提示訊息 ===== */
.status {
  display: none;
  position: absolute;
  z-index: 1300;
  left: 50%;
  bottom: 46px;
  transform: translateX(-50%);
  max-width: min(90vw, 520px);
  padding: 9px 16px;
  color: #fff;
  background: rgba(18, 28, 42, .92);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 13px;
  text-align: center;
}
.status.show { display: block; }
.status.error { background: rgba(180, 38, 42, .94); }

/* ===== 頁尾 ===== */
#footer {
  position: absolute;
  z-index: 1000;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  color: #55637a;
  background: rgba(255, 255, 255, .86);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
:root[data-theme="dark"] #footer { color: #9aabc0; background: rgba(13, 20, 32, .88); }
#footer a { color: inherit; text-decoration: underline; }
#footer .sep { opacity: .5; }

/* ===== Leaflet 覆寫 ===== */
.leaflet-container { font-family: inherit; }
.leaflet-control-layers {
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  box-shadow: var(--shadow) !important;
  background: var(--panel-solid) !important;
  color: var(--text) !important;
}
.leaflet-control-layers label { color: var(--text) !important; }
.leaflet-control-attribution {
  background: rgba(255, 255, 255, .8) !important;
  font-size: 10px !important;
}
:root[data-theme="dark"] .leaflet-control-attribution { background: rgba(13, 20, 32, .85) !important; }
.leaflet-tooltip.road-tip {
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-weight: 700;
}
.leaflet-tooltip.road-tip::before { border-top-color: var(--line); }
.leaflet-tooltip.spot-tip {
  background: rgba(18, 28, 42, .94);
  color: #fff;
  border: 0;
  font-size: 12px;
}
.leaflet-tooltip.spot-tip::before { border-top-color: rgba(18, 28, 42, .94); }
.leaflet-tooltip.spot-tip .tip-id { color: #9ec5ff; font-family: ui-monospace, monospace; margin-right: 5px; }

/* ===== 自訂 marker ===== */
.spot-marker { background: none; border: 0; }
.spot-pin {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--pin, #1f6feb);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.spot-emoji { transform: rotate(45deg); font-size: 15px; line-height: 1; }
.spot-code {
  position: absolute;
  top: -9px;
  right: -16px;
  transform: rotate(45deg);
  padding: 0 4px;
  color: #fff;
  background: rgba(18, 28, 42, .9);
  border-radius: 6px;
  font-size: 9px;
  font-family: ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.spot-code .code-full { display: none; }
.zoom-close .spot-code .code-short { display: none; }
.zoom-close .spot-code .code-full { display: inline; }
.spot-marker.selected .spot-pin { box-shadow: 0 0 0 4px rgba(255, 210, 0, .9), 0 2px 8px rgba(0, 0, 0, .5); }

.cluster-wrap { background: none; border: 0; }
.cluster-bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--accent);
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ===== RWD：手機版 ===== */
@media (max-width: 760px) {
  :root { --topbar-h: auto; }
  #topbar { top: 6px; left: 6px; right: 6px; flex-wrap: wrap; gap: 6px; padding: 7px 8px; }
  .brand h1 { font-size: 15px; }
  .brand-logo { font-size: 20px; }
  .search-wrap { order: 3; flex: 1 1 100%; }
  .toolbar { margin-left: auto; }
  .btn { min-height: 34px; padding: 0 9px; font-size: 12px; }
  .btn.btn-icon { min-width: 34px; }
  .filter-popover { top: 108px; left: 6px; right: 6px; width: auto; }
  .nearby-popover { top: 108px; left: 6px; right: 6px; width: auto; }
  .side-panel,
  .road-panel,
  .detail-panel {
    top: auto;
    bottom: 30px;
    left: 0;
    right: 0;
    width: auto !important;
    max-height: 62vh;
    border-radius: 16px 16px 0 0;
  }
  .road-panel { transform: translateY(105%); }
  .detail-panel { transform: translateY(105%); }
  .side-panel.open { transform: translateY(0); }
  .carousel { aspect-ratio: 16 / 9; }
  #footer { font-size: 10px; }
}

/* ==================================================================
   手繪台灣地圖（wave1-handdrawn）
   ================================================================== */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.brand h1 { font-family: var(--hand-font); font-size: 22px; font-weight: 400; letter-spacing: 1px; }

/* --- 首頁 hero --- */
.hero {
  position: absolute;
  z-index: 1020;
  top: 88px;
  left: 26px;
  max-width: min(70vw, 620px);
  pointer-events: none;
  animation: heroIn 1.1s ease;
  text-shadow: 0 1px 0 rgba(255, 252, 240, .95), 0 2px 8px rgba(255, 250, 230, .8);
}
.hero h2 {
  margin: 0;
  font-family: var(--hand-font);
  font-size: clamp(32px, 5.2vw, 66px);
  font-weight: 400;
  line-height: 1.08;
  color: #4a3520;
  transform: rotate(-2deg);
}
.hero p {
  margin: 4px 0 0;
  font-family: var(--hand-font);
  font-size: clamp(17px, 2.4vw, 27px);
  color: #6c5131;
  transform: rotate(-1deg);
}
.hero-hint {
  display: inline-block;
  margin-top: 10px;
  font-family: var(--hand-font);
  font-size: 14px;
  color: #8a6f4e;
}
.hero.dismissed { opacity: 0; transform: translateY(-14px); transition: opacity .5s ease, transform .5s ease; }
@keyframes heroIn {
  from { opacity: 0; transform: translateY(22px) rotate(-1deg); }
  to { opacity: 1; transform: translateY(0) rotate(0); }
}

.hero-stats {
  position: absolute;
  z-index: 1020;
  top: 88px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 15px;
  font-family: var(--hand-font);
  color: var(--ink);
  background: rgba(255, 250, 233, .88);
  border: 2px solid rgba(107, 83, 55, .38);
  border-radius: 16px 11px 15px 10px;
  box-shadow: 2px 3px 0 rgba(107, 83, 55, .18);
  transform: rotate(1deg);
  pointer-events: none;
}
.stat-item b { font-size: 25px; font-weight: 400; line-height: 1; }
.stat-item small { margin-left: 3px; font-size: 14px; }
.stat-sep { opacity: .5; }

.map-tools {
  position: absolute;
  z-index: 1030;
  left: 26px;
  top: 52%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.btn-hand {
  font-family: var(--hand-font);
  font-size: 15px;
  font-weight: 400;
  color: #5a4327;
  background: #fffaf0;
  border: 2px dashed #b59b73;
  border-radius: 12px 9px 13px 8px;
  box-shadow: 1px 2px 0 rgba(107, 83, 55, .18);
}
.btn-hand:hover { color: #7a3e1d; background: #fff4da; border-color: #8a6f4e; }
#btn-fly-road { margin: 0 0 14px; }

/* --- 重疊路段選單 --- */
.road-picker {
  z-index: 1250;
  width: 250px;
  max-height: 320px;
  font-family: var(--hand-font);
}
.road-picker .pop-head strong { font-size: 15px; font-weight: 400; }
.pick-item {
  display: block;
  width: 100%;
  padding: 8px 9px;
  text-align: left;
  font-family: var(--hand-font);
  font-size: 16px;
  color: #4a3520;
  background: none;
  border: 0;
  border-bottom: 1px dashed rgba(107, 83, 55, .3);
}
.pick-item:last-child { border-bottom: 0; }
.pick-item:hover { background: #fff4da; }
.pick-item .pick-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 7px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .25);
  vertical-align: middle;
}

/* --- 手繪筆觸 --- */
.sketch-a { filter: url(#hand-sketch-a); }
.sketch-b { filter: url(#hand-sketch-b); }
#map:not(.sketch-mode) .sketch-a,
#map:not(.sketch-mode) .sketch-b { filter: none; }

.leaflet-overlay-pane path.road-sketch,
.leaflet-overlay-pane path.county-sketch {
  stroke-linecap: round;
  stroke-linejoin: round;
}
.leaflet-overlay-pane path.road-ghost { opacity: .34; }
.leaflet-overlay-pane path.road-hit { cursor: pointer; }
.leaflet-overlay-pane path.county-sketch { opacity: 0; transition: opacity .45s ease; }
#map.hand-mode path.county-sketch { opacity: .85; }
#map.sketch-mode:not(.hand-mode) path.county-sketch { opacity: .25; }

.leaflet-tooltip.road-tip { font-family: var(--hand-font); font-size: 18px; border-style: dashed; }
.leaflet-tooltip.road-tip::before { border-top-color: var(--line); }

/* --- 山脈與縣市名（僅低縮放） --- */
.mountain-marker,
.county-label {
  background: none;
  border: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
}
#map.hand-mode .mountain-marker,
#map.hand-mode .county-label { opacity: 1; }
.county-label span {
  display: inline-block;
  font-family: var(--hand-font);
  font-size: 19px;
  line-height: 1;
  white-space: nowrap;
  color: #6b5337;
  text-shadow: 0 1px 0 #fffaf0, 1px 1px 0 rgba(255, 250, 240, .9);
}
.mountain-marker .mt-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: rotate(-3deg);
}
.mountain-marker .mt-name {
  font-family: var(--hand-font);
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  color: #5a4327;
  text-shadow: 0 1px 0 #fffaf0;
}

/* --- 簇集 / 景點名（zoom >= 12 才顯示個別名稱） --- */
.cluster-bubble {
  font-family: var(--hand-font);
  font-size: 17px;
  background: #c8873f;
  border: 2px dashed #fff7e6;
  border-radius: 48% 52% 45% 55%;
  box-shadow: 2px 2px 0 rgba(107, 83, 55, .35);
}
.spot-name-label {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 5px;
  font-family: var(--hand-font);
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  color: #3d2f1c;
  background: rgba(255, 249, 232, .86);
  border-radius: 5px;
  pointer-events: none;
}
#map.show-names .spot-name-label { display: block; }

/* --- 比例尺 / 圖層控制的紙感 --- */
.leaflet-control-scale { font-family: var(--hand-font); }
.leaflet-control-scale-line {
  font-size: 12px;
  color: #5a4327;
  background: rgba(255, 249, 232, .85) !important;
  border-color: #6b5337 !important;
}
.leaflet-control-layers { font-family: var(--hand-font); font-size: 13px; }
.road-panel .road-head h2 { font-family: var(--hand-font); font-size: 27px; font-weight: 400; }
.detail-panel .detail-head h2 { font-family: var(--hand-font); font-size: 24px; font-weight: 400; }

@media (max-width: 760px) {
  .hero { top: 118px; left: 12px; max-width: 78vw; }
  .hero h2 { font-size: 34px; }
  .hero p { font-size: 17px; }
  .hero-hint { font-size: 12px; }
  .hero-stats { top: auto; bottom: 40px; right: 8px; padding: 4px 9px; }
  .stat-item b { font-size: 19px; }
  .stat-item small { font-size: 12px; }
  .map-tools { top: auto; bottom: 88px; left: 8px; transform: none; flex-direction: row; }
  .btn-hand { font-size: 13px; }
  .road-picker { width: min(280px, 86vw); }
}

/* ==================================================================
   wave2-ux：照片、桌面／手機操作體驗
   ================================================================== */

/* --- 共用：可 focus、焦點樣式、按鍵尺寸 --- */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
button, a.btn-link, select, input[type="search"] { -webkit-tap-highlight-color: transparent; }
.btn, .icon-btn, .carousel-nav, .carousel-dot, .spot-nav-btn, .tp-move, .tp-del {
  min-width: 44px; min-height: 44px;
}
.carousel-dot { min-width: 14px; min-height: 14px; }

/* --- 左側可收合欄 --- */
.sidebar {
  left: 12px; width: 270px;
  transform: translateX(calc(-100% - 20px)); opacity: 0; pointer-events: none;
}
.sidebar.open { transform: translateX(0); opacity: 1; pointer-events: auto; }
body.sidebar-open .road-panel { left: 292px; }
.side-head { margin: 0; padding: 0 0 8px; gap: 6px; }
.side-head strong { margin-right: auto; font-size: 15px; }
#sidebar-trip { min-height: 38px; padding: 0 10px; font-size: 12px; }
.sidebar-controls { padding: 8px 0 10px; border-bottom: 1px solid var(--line); }
#sidebar-search {
  width: 100%; height: 40px; padding: 0 12px; margin-bottom: 8px;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
}
.sidebar-row { display: flex; align-items: center; gap: 6px; }
.sidebar-row label { color: var(--muted); font-size: 12px; }
#road-sort {
  flex: 1; min-width: 0; height: 38px; padding: 0 8px;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
#sidebar-filters { min-height: 38px; padding: 0 10px; }
.road-list { flex: 1; overflow-y: auto; padding-top: 8px; }
.road-card {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px; margin-bottom: 6px; text-align: left; color: var(--text);
  background: var(--bg); border: 1px solid transparent; border-radius: 10px;
}
.road-card:hover, .road-card.active { border-color: var(--accent); background: var(--accent-soft); }
.rc-img {
  flex: 0 0 62px; width: 62px; height: 48px; object-fit: cover;
  background: var(--accent-soft); border-radius: 7px;
}
.rc-img-none { display: flex; align-items: center; justify-content: center; font-size: 20px; }
.rc-img.broken { visibility: hidden; }
.rc-body { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.rc-title { display: flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 700; }
.rc-swatch { flex: 0 0 10px; width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); }
.rc-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.rc-tag { font-size: 10px; padding: 1px 5px; color: var(--accent); background: var(--accent-soft); border-radius: 999px; }
.rc-meta { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* --- Hero 大圖輪播 --- */
.hero-carousel { aspect-ratio: 16 / 9; margin: 0 0 4px; border-radius: 12px 12px 0 0; }
.carousel-images img.zoomable { cursor: zoom-in; }
.shimmer { background: linear-gradient(100deg, var(--bg) 20%, var(--accent-soft) 40%, var(--bg) 60%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.img-credit {
  margin: 0; padding: 4px 14px 8px; color: var(--muted); font-size: 11.5px;
  border-bottom: 1px solid var(--line); line-height: 1.4;
}
.img-credit:empty { display: none; }
.img-credit a { margin-left: 4px; white-space: nowrap; }
.img-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  color: var(--ink); background: #fff8e8;
  font-family: var(--hand-font); font-size: 15px;
}
:root[data-theme="dark"] .img-fallback { color: #d9c49b; background: #2a2418; }
.img-fallback svg { width: 92px; height: 64px; opacity: .8; }

/* --- 沿線景點清單（縮圖＋標籤＋描述） --- */
.spots-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chk-photos { font-size: 11.5px; white-space: nowrap; }
.road-spot { align-items: flex-start; }
.rs-thumb {
  flex: 0 0 52px; width: 52px; height: 52px; object-fit: cover;
  background: var(--accent-soft); border-radius: 8px;
}
.rs-thumb-none { display: flex; align-items: center; justify-content: center; font-size: 18px; }
.rs-thumb.broken { visibility: hidden; }
.rs-info { display: flex; flex-direction: column; min-width: 0; gap: 2px; flex: 1; }
.rs-line { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.rs-num { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.rs-kind {
  font-size: 10px; font-weight: 700; color: var(--tag-color, var(--accent));
  background: color-mix(in srgb, var(--tag-color, var(--accent)) 12%, transparent);
  padding: 0 5px; border-radius: 999px;
}
.rs-name { font-weight: 700; font-size: 12.5px; }
.rs-desc { color: var(--muted); font-size: 11px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- 景點沿線導覽與進度 --- */
.spot-nav { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.spot-nav-btn { flex: 0 0 auto; padding: 0 8px; font-size: 12px; }
.spot-progress { position: relative; flex: 1; height: 24px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.spot-progress-bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-soft); transition: width .25s ease; }
.spot-progress-text {
  position: relative; display: block; text-align: center; line-height: 24px;
  font-size: 11px; color: var(--text); font-variant-numeric: tabular-nums;
}

/* --- 動作按鈕 --- */
#btn-add-trip.active { background: var(--accent); color: #fff; }

/* --- 我的行程 --- */
/* 預設關閉，且高度上限 70% 視窗；內部捲動不外溢 */
.trip-panel {
  right: 12px; width: 350px;
  bottom: auto; max-height: 70vh;
  overscroll-behavior: contain;
}
.trip-panel .pop-head { flex: 0 0 auto; padding-right: 52px; }
.trip-panel .trip-tools { flex: 0 0 auto; }
.trip-panel .trip-list { min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#trip-close {
  width: 44px; height: 44px; min-width: 44px; min-height: 44px;
  top: 6px; right: 8px; background: var(--bg);
}
.trip-grabber { display: none; }

/* 點面板外遮罩關閉；遮罩在面板之下、工具列之上 */
.trip-backdrop {
  display: none;
  position: absolute; inset: 0; z-index: 1040;
  background: rgba(12, 20, 32, .38);
}
.trip-backdrop.open { display: block; }

/* 行程被路線／詳情收合後的小標籤（桌面用，手機用底部導覽） */
.trip-tab {
  display: none;
  position: absolute; z-index: 1060;
  left: 50%; bottom: 44px; transform: translateX(-50%);
  min-height: 44px; padding: 0 14px;
  align-items: center; gap: 5px;
  color: var(--text); background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow); font-size: 13px; font-weight: 700;
}
.trip-tab.show { display: inline-flex; }

.trip-tools { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.trip-tools .btn { flex: 1 1 auto; min-height: 38px; padding: 0 8px; font-size: 11.5px; }
.trip-list { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
.trip-item {
  display: flex; align-items: center; gap: 6px; padding: 6px; margin-bottom: 6px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; cursor: grab;
}
.tp-grip { color: var(--muted); font-size: 13px; cursor: grab; }
.tp-thumb { flex: 0 0 46px; width: 46px; height: 46px; object-fit: cover; border-radius: 7px; background: var(--accent-soft); }
.tp-thumb-none { display: flex; align-items: center; justify-content: center; }
.tp-thumb.broken { visibility: hidden; }
.tp-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.tp-info b { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-info small { color: var(--muted); font-size: 10.5px; }
.tp-move, .tp-del { width: 32px; min-width: 32px; min-height: 32px; padding: 0; font-size: 12px; background: transparent; border: 0; border-radius: 6px; }
.tp-move:hover, .tp-del:hover { background: var(--accent-soft); }
.trip-item.drop-target { outline: 2px dashed var(--accent); }

/* --- 全螢幕 Lightbox --- */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 2000;
  flex-direction: column; align-items: center; justify-content: center;
  background: rgba(12, 16, 24, .95); color: #fff;
}
.lightbox.open { display: flex; }
body.lb-open { overflow: hidden; }
.lb-stage { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; }
#lb-img { max-width: 92vw; max-height: 74vh; object-fit: contain; transform-origin: center center; touch-action: none; }
.lb-btn {
  position: absolute; width: 48px; min-width: 48px; height: 48px;
  color: #fff; background: rgba(255,255,255,.14); border: 0; border-radius: 50%;
  font-size: 26px; line-height: 1;
}
.lb-btn:hover { background: rgba(255,255,255,.3); }
.lb-close { top: 16px; right: 16px; font-size: 20px; }
.lb-prev { top: 50%; left: 16px; transform: translateY(-50%); }
.lb-next { top: 50%; right: 16px; transform: translateY(-50%); }
.lb-info { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px 24px; font-size: 12px; text-align: center; }
.lb-credit { color: #9ec5ff; }
.lb-count { color: #cbd5e1; font-variant-numeric: tabular-nums; }

/* --- 手機抽屜握把與底部導覽（桌面隱藏） --- */
.drawer-handle, .bottom-nav { display: none; }

@media (max-width: 768px) {
  :root { --topbar-h: 108px; --nav-h: 58px; --safe-b: env(safe-area-inset-bottom, 0px); }
  html, body { height: 100dvh; font-size: 14px; }
  .btn, .icon-btn, .btn-link { min-height: 44px; font-size: 14px; }
  .icon-btn { width: 44px; height: 44px; }
  .action-links .btn-link { padding: 10px 8px; }
  #topbar { min-height: var(--topbar-h); }
  .popover { max-height: calc(100dvh - var(--topbar-h) - var(--nav-h) - 24px); }
  .filter-popover, .nearby-popover { top: calc(var(--topbar-h) + 8px); }

  /* 底部抽屜：三段高度，地圖始終在上面可操作 */
  body[data-drawer="mini"] { --drawer-h: 96px; }
  body[data-drawer="half"] { --drawer-h: 52dvh; }
  body[data-drawer="full"] { --drawer-h: calc(100dvh - var(--topbar-h) - var(--nav-h) - var(--safe-b) - 12px); }
  .side-panel, .sidebar, .road-panel, .detail-panel, .trip-panel {
    top: auto; bottom: calc(var(--nav-h) + var(--safe-b) + 6px);
    left: 6px; right: 6px; width: auto !important;
    height: var(--drawer-h); max-height: none;
    border-radius: 16px 16px 10px 10px;
    transform: translateY(calc(100% + var(--nav-h) + 20px));
    transition: transform .28s ease, height .28s ease;
  }
  .side-panel.open, .sidebar.open { transform: translateY(0); }
  body.sidebar-open .road-panel { left: 6px; }
  .road-body, .detail-body { padding-bottom: calc(18px + var(--nav-h)); }
  .hero-carousel { aspect-ratio: 16 / 9; }
  .carousel { aspect-ratio: 16 / 9; }

  .drawer-handle {
    display: none; position: absolute; z-index: 1400;
    left: 50%; transform: translateX(-50%);
    bottom: calc(var(--nav-h) + var(--safe-b) + var(--drawer-h) + 4px);
    width: 80px; height: 44px; align-items: center; justify-content: center;
    background: transparent; border: 0;
  }
  .drawer-handle.show { display: flex; }
  .drawer-handle span {
    display: block; width: 56px; height: 6px; border-radius: 999px;
    background: var(--muted); box-shadow: 0 0 0 3px var(--panel-solid);
  }

  .bottom-nav {
    position: absolute; z-index: 1500; left: 0; right: 0; bottom: 0;
    height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    display: flex; align-items: stretch;
    background: var(--panel-solid); border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0,0,0,.12);
  }
  .bottom-nav button {
    flex: 1; min-height: 44px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 1px;
    color: var(--muted); background: none; border: 0; font-size: 12px;
  }
  .bottom-nav button span { font-size: 18px; line-height: 1; }
  .bottom-nav button.active { color: var(--accent); background: var(--accent-soft); }

  #footer { display: none; }
  .status { bottom: calc(var(--nav-h) + var(--safe-b) + 10px); font-size: 14px; }
  .hero-stats { bottom: calc(var(--nav-h) + var(--safe-b) + 8px); right: 8px; }
  .map-tools { bottom: calc(var(--nav-h) + var(--safe-b) + 52px); top: auto; left: 8px; transform: none; flex-direction: row; }
  .lb-btn { min-height: 44px; }
  .img-credit, .rs-desc, .rc-meta { font-size: 12px; }
}

/* --- 我的行程：手機抽屜高度上限 70dvh + safe-area --- */
@media (max-width: 768px) {
  .trip-panel {
    height: min(70dvh, var(--drawer-h));
    max-height: 70dvh;
    overscroll-behavior: contain;
  }
  .trip-grabber {
    display: flex; flex: 0 0 auto;
    align-items: center; justify-content: center;
    height: 24px; touch-action: pan-y;
  }
  .trip-grabber::before {
    content: ""; display: block;
    width: 56px; height: 6px;
    background: var(--muted); border-radius: 999px; opacity: .75;
  }
  /* 手機用底部導覽的「行程」按鈕，不另顯示桌面小標籤 */
  .trip-tab { display: none !important; }
}

/* --- 無障礙 / 偏好設定 --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .sketch-a, .sketch-b { filter: none !important; }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}

