* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #111; font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", sans-serif; }
#map { position: absolute; inset: 0; }

.glass {
  background: rgba(20, 24, 28, 0.55);
  color: #fff;
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

button { font: inherit; cursor: pointer; }

button svg, .fav-pin svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#toolbar {
  position: absolute; z-index: 1001;
  top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 2px; padding: 4px; border-radius: 14px;
  max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none;
}
#toolbar button {
  flex: none; width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: transparent; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
#toolbar button:active { transform: scale(0.92); }
#toolbar button.on { background: #16a34a; }
#toolbar button.busy svg { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.pop {
  position: absolute; z-index: 1001;
  top: calc(66px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(420px, calc(100vw - 24px));
  border-radius: 14px; padding: 6px;
  background: rgba(20, 24, 28, 0.82);
}
.pop[hidden] { display: none; }

#layers { display: flex; gap: 4px; }
#layers button {
  flex: 1; border: 0; background: rgba(255, 255, 255, 0.08); color: #ddd;
  padding: 10px 0; border-radius: 10px; font-size: 15px;
}
#layers button.active { background: #16a34a; color: #fff; }

#search { display: flex; gap: 4px; align-items: center; }
#q {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: #fff; font-size: 16px; padding: 8px 8px;
}
#q::placeholder { color: #bbb; }
#q::-webkit-search-cancel-button { display: none; }
button.icon {
  flex: none; width: 38px; height: 38px; border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, 0.1); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
button.icon svg { width: 20px; height: 20px; }
#search button[type=submit] { background: #16a34a; }

#results, #favList {
  list-style: none; margin: 6px 0 0; padding: 0;
  max-height: 50vh; overflow-y: auto;
}
#favList { margin: 0; }
#results li { padding: 9px 10px; border-radius: 8px; font-size: 14px; cursor: pointer; line-height: 1.3; color: #fff; }
#results li small { display: block; color: #aaa; font-size: 12px; }
#results li:hover, #results li:active { background: rgba(255, 255, 255, 0.12); }
#results li.empty, #favList li.empty { color: #aaa; cursor: default; }

#favList li { display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 8px; color: #fff; font-size: 15px; }
#favList li.empty { padding: 10px; font-size: 14px; }
#favList .name { flex: 1; min-width: 0; padding: 8px 0; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#favList .name::before { content: "★ "; color: #facc15; }
#favList .name.route::before { content: "⤳ "; color: #60a5fa; font-weight: 700; }
#card, #card * { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; -webkit-tap-highlight-color: transparent; }
#favList li:hover { background: rgba(255, 255, 255, 0.06); }
#favList button.icon { width: 34px; height: 34px; }
.leaflet-tooltip.fav-label {
  background: rgba(20, 24, 28, 0.7); color: #fff; border: 0; box-shadow: none;
  padding: 2px 6px; border-radius: 6px; font-size: 12px;
}
.leaflet-tooltip.fav-label::before { display: none; }
.pop .hint { margin: 6px 8px 4px; }

.leaflet-bottom.leaflet-right { bottom: env(safe-area-inset-bottom); }


#card {
  position: absolute; z-index: 1000;
  left: 12px; bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; gap: 12px; align-items: center;
  border-radius: 16px; padding: 10px 14px 10px 10px;
  max-width: calc(100vw - 24px);
}
#card.hidden { display: none; }
#card { transition: transform .15s; }
#card.pressed { transform: scale(0.96); }
#mini { width: 120px; height: 120px; border-radius: 10px; background: rgba(0, 0, 0, 0.35); flex: none; }
.stats { min-width: 130px; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.label { font-size: 12px; color: #bbb; }
.val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row.sub { font-size: 13px; margin-top: 2px; }
#status { font-size: 12px; color: #fcd34d; margin-top: 4px; min-height: 1em; }

.pin {
  width: 26px; height: 26px; border-radius: 50%;
  background: #2563eb; color: #fff; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font: 700 12px system-ui, sans-serif; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.pin.start { background: #16a34a; }
.pin.end { background: #dc2626; }
.fav-pin { color: #facc15; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.fav-pin svg { width: 22px; height: 22px; fill: #facc15; stroke: #78350f; stroke-width: 1.2; }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(59,130,246,.35); }
.pin.ghost { width: 22px; height: 22px; background: rgba(37, 99, 235, 0.6); }

#poiCats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
dialog h4 { margin: 16px 0 8px; font-size: 14px; color: #bbb; }
#poiCats label {
  justify-content: flex-start; margin: 0; gap: 8px; padding: 7px 8px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.06); color: #fff; font-size: 14px; cursor: pointer;
}
#poiCats input { width: 18px; height: 18px; padding: 0; margin: 0; accent-color: #16a34a; }
#poiLoading {
  position: absolute; z-index: 1000; left: 50%; transform: translateX(-50%);
  top: calc(62px + env(safe-area-inset-top)); padding: 5px 12px; border-radius: 999px; font-size: 13px;
}
#poiLoading[hidden] { display: none; }
#poiCats .poi { position: static; }
.poi-actions { display: flex; gap: 4px; margin-top: 4px; }
.poi-actions button {
  flex: 1; border: 0; background: rgba(255, 255, 255, 0.08); color: #ddd;
  padding: 8px 0; border-radius: 10px; font-size: 14px;
}
.poi-actions button:active { background: #16a34a; color: #fff; }

.poi {
  position: relative; width: 26px; height: 26px; border-radius: 7px;
  background: #1f2328; border: 2px solid var(--c); color: var(--c);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45); flex: none;
}
.poi svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.poi .poi-name {
  display: none; position: absolute; left: 30px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; font: 600 12px system-ui, sans-serif; color: var(--c);
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000; pointer-events: none;
}
.poi-labels .poi .poi-name { display: block; }
.poi-pop .leaflet-popup-content-wrapper, .poi-pop .leaflet-popup-tip { background: #1f2328; color: #eee; }
.poi-pop .leaflet-popup-content { margin: 10px 12px; font-size: 14px; }
.poi-pop b { display: block; font-size: 15px; }
.poi-pop small { color: var(--c); }
.poi-pop button {
  display: block; width: 100%; margin-top: 8px; border: 0; border-radius: 8px;
  padding: 7px 0; background: #16a34a; color: #fff; font-size: 14px;
}

dialog {
  border: 0; border-radius: 16px; padding: 18px 20px; width: min(340px, calc(100vw - 32px));
  background: #1f2328; color: #eee;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h3 { margin: 0 0 12px; }
dialog label { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; font-size: 14px; gap: 8px; }
dialog input { width: 70px; padding: 6px; border-radius: 8px; border: 1px solid #444; background: #111; color: #fff; font-size: 15px; text-align: right; }
dialog select { padding: 6px; border-radius: 8px; border: 1px solid #444; background: #111; color: #fff; font-size: 14px; }
.hint { font-size: 12px; color: #999; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.actions button { border: 0; border-radius: 10px; padding: 8px 16px; background: #333; color: #eee; }
.actions button.primary { background: #16a34a; color: #fff; }
dialog input.wide { width: 100%; text-align: left; padding: 9px 10px; font-size: 16px; }
