:root {
  --bg: #f3eeff;
  --bg-grad: linear-gradient(165deg, #faf7ff 0%, #efe6ff 42%, #e4e9ff 100%);
  --glass: rgb(248 244 255 / 82%);
  --surface: #ffffff;
  --ink: #2b2542;
  --muted: #6f6889;
  --line: #e2daf5;
  --accent: #7b5bd6;
  --accent-2: #a58af0;
  --accent-ink: #ffffff;
  --accent-soft: #eee7ff;
  --star: #d39200;
  --like: #2f8f5b;
  --dislike: #c4513d;
  --new: #d0457f;
  --shadow: 0 1px 2px rgb(76 52 150 / 6%), 0 4px 14px rgb(76 52 150 / 7%);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { background: var(--bg); }
body {
  min-height: 100vh;
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  padding: env(safe-area-inset-top, 0px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
  -webkit-text-size-adjust: 100%;
}
/* 固定在畫面後方的淡紫漸層（iOS 不支援 background-attachment: fixed，所以用偽元素） */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--bg-grad); }
[hidden] { display: none !important; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 0.95rem; color: var(--muted); font-weight: 600; margin-top: 20px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--dislike); margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; font-weight: 600; cursor: pointer;
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); border-color: transparent; color: var(--accent-ink);
  box-shadow: 0 2px 8px rgb(123 91 214 / 30%);
}
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }

/* 密碼與選人畫面 */
.screen { min-height: 100vh; display: grid; place-items: center; }
.gate-card {
  width: 100%; max-width: 360px; display: grid; gap: 12px;
  background: var(--surface); padding: 24px; border-radius: 20px; box-shadow: var(--shadow);
}
.gate-card p { margin: 0; }
.gate-card input { min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.who-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.who-buttons .btn { min-height: 64px; font-size: 1.1rem; }

/* 上方篩選區 */
.top {
  position: sticky; top: 0; z-index: 5;
  margin-inline: -16px; padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid rgb(226 218 245 / 70%);
  display: grid; gap: 10px;
}
.top-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.loc {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  border: 0; background: none; padding: 4px 0; font-weight: 600; cursor: pointer;
}
.loc #loc-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loc .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.loc.live .dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.me {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 4px 12px; font-size: 0.9rem; cursor: pointer;
}
.search {
  width: 100%; min-height: 44px; padding: 0 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
}
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 0.95rem;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .n { color: var(--muted); font-size: 0.8rem; margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .n { color: inherit; opacity: 0.8; }
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.filters label { display: grid; gap: 2px; font-size: 0.75rem; color: var(--muted); }
.filters select {
  min-height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 6px; font-size: 0.9rem; min-width: 0;
}

.summary { display: flex; align-items: center; gap: 10px; padding-block: 10px; color: var(--muted); font-size: 0.9rem; }
.summary #count { flex: 1; min-width: 0; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: rgb(255 255 255 / 70%); border: 1px solid var(--line); flex: none; }
.seg button { border: 0; background: none; min-height: 32px; padding: 0 14px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* 地點清單 */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  display: grid; grid-template-columns: 72px 1fr auto; gap: 2px 12px; align-items: start;
  background: var(--surface); border-radius: 16px; padding: 10px 12px 10px 10px;
  box-shadow: var(--shadow); cursor: pointer; border: 1px solid transparent;
}
.card:active { border-color: var(--accent-2); }
.card.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card .thumb { grid-row: 1 / span 3; }
.card .name { font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.card .dist { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; color: var(--accent); }
.card .meta, .meta { font-size: 0.88rem; color: var(--muted); margin: 0; }
.card .eta { font-size: 0.8rem; color: var(--muted); text-align: right; white-space: nowrap; }
.card-actions { grid-column: 2 / -1; display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; min-height: 30px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--accent-soft); color: var(--accent);
  font-size: 0.82rem; font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.list-name { margin: -4px 0 0; font-size: 0.8rem; font-weight: 700; color: var(--accent); letter-spacing: 0.02em; }
.eta-line { margin: 2px 0 0; font-size: 0.88rem; font-weight: 600; color: var(--accent); }
.eta-line:empty { display: none; }
.card .gnote, .card .badges { grid-column: 2 / -1; }
.thumb {
  position: relative;
  width: 72px; height: 72px; border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; font-size: 1.6rem;
  background: linear-gradient(135deg, #f1ebff, #e3dafc);
}
.thumb img, .hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; animation: fade 0.25s ease-out; }
@keyframes fade { from { opacity: 0; } }
.stars { color: var(--star); font-weight: 700; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.badge { font-size: 0.78rem; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); }
.badge.like { background: color-mix(in srgb, var(--like) 15%, transparent); color: var(--like); }
.badge.dislike { background: color-mix(in srgb, var(--dislike) 15%, transparent); color: var(--dislike); }
.badge.new { background: color-mix(in srgb, var(--new) 14%, transparent); color: var(--new); }
.gnote { font-size: 0.9rem; margin: 4px 0 0; overflow-wrap: anywhere; }
.gnote::before { content: "📝 "; }
.gnote:empty { display: none; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* 地圖 */
.map-wrap {
  position: relative; height: calc(100dvh - 260px); min-height: 380px;
  border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); background: var(--accent-soft);
}
.map { position: absolute; inset: 0; }
.map-msg { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }
.pin {
  width: 32px; height: 32px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  display: grid; place-items: center; background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 2px 6px rgb(43 37 66 / 30%);
}
.pin span { transform: rotate(45deg); font-size: 15px; line-height: 1; }
.pin.cat-eat { background: #e0795b; }
.pin.cat-drink { background: #c88a3a; }
.pin.cat-play { background: #3f9d78; }
.pin.cat-stay { background: #4f7bd8; }
.pin.cat-other { background: #8a80a8; }
.pin.trip { background: var(--accent); width: 34px; height: 34px; }
.pin.trip span { font-size: 14px; font-weight: 800; color: #fff; }
.pin.liked { box-shadow: 0 0 0 3px #ffd54a, 0 2px 6px rgb(43 37 66 / 30%); }
.pin.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 6px rgb(59 130 246 / 25%); }
.map-card {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  display: grid; grid-template-columns: 64px 1fr; gap: 2px 12px; align-items: center;
  background: var(--surface); border-radius: 16px; padding: 10px; box-shadow: 0 6px 24px rgb(43 37 66 / 20%); cursor: pointer;
}
.map-card .thumb { width: 64px; height: 64px; }
.map-card .name { font-weight: 700; line-height: 1.3; }
.map-card .row { display: flex; gap: 12px; font-size: 0.85rem; }
.map-card .row { color: var(--accent); font-weight: 600; }
.map-card .card-actions { grid-column: 2; margin-top: 4px; }
.map-card .thumb { grid-row: 1 / span 4; }

/* 底部彈出視窗 */
.sheet {
  width: 100%; max-width: 560px; max-height: 90vh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--ink);
}
.sheet::backdrop { background: rgb(43 30 80 / 35%); }
.hero { position: relative; height: 200px; overflow: hidden; background: linear-gradient(135deg, #f1ebff, #e3dafc); display: grid; place-items: center; font-size: 2.4rem; }
.hero img { position: absolute; inset: 0; }
.sheet-body { padding: 20px 16px calc(env(safe-area-inset-bottom, 0px) + 20px); display: grid; gap: 10px; }
.sheet-body p { margin: 0; }
.sheet-body input[list] { min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.icon-btn { border: 0; background: var(--accent-soft); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; flex: none; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.btn.wide, .actions .wide { grid-column: 1 / -1; }
#d-trip.on { background: var(--accent-soft); border-color: var(--accent-2); color: var(--accent); }
.others { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.others li { background: var(--bg); border-radius: 12px; padding: 8px 12px; font-size: 0.92rem; }
.others .who { font-weight: 700; }
.others .memo { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.my-note { display: grid; gap: 10px; }
.verdict { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vbtn { min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 600; }
.vbtn[aria-pressed="true"][data-verdict="like"] { background: var(--like); border-color: var(--like); color: #fff; }
.vbtn[aria-pressed="true"][data-verdict="dislike"] { background: var(--dislike); border-color: var(--dislike); color: #fff; }
.field { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  padding: 10px 12px; font-size: 1rem; color: var(--ink);
}
.field input { min-height: 44px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* 今日行程 */
body.has-trip { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 88px); }
.trip-bar {
  position: fixed; z-index: 6; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  max-width: 560px; margin-inline: auto;
  display: grid; grid-template-columns: 1fr auto; gap: 0 12px; align-items: center; text-align: left;
  padding: 10px 16px; border: 0; border-radius: 16px; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, #9b7ef0, #6d4fd0); box-shadow: 0 8px 24px rgb(109 79 208 / 35%);
}
.trip-bar .tb-title { font-weight: 800; }
.trip-bar .tb-meta { grid-column: 1; font-size: 0.82rem; opacity: 0.9; }
.trip-bar .tb-open { grid-column: 2; grid-row: 1 / span 2; font-weight: 700; }
.trip-tools { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }
.legs, .stops { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.leg { font-size: 0.85rem; color: var(--muted); padding: 2px 0 2px 14px; border-left: 3px solid var(--accent-2); margin-left: 13px; }
.park { background: var(--bg); border-radius: 14px; padding: 10px; display: grid; gap: 8px; }
.park-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.82rem; font-weight: 700; color: var(--accent); }
.stop { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 10px; padding: 6px 8px; }
.stop-head { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.stop-name { font-weight: 700; overflow-wrap: anywhere; line-height: 1.3; }
.num {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 0.8rem; font-weight: 800;
}
.walk { font-size: 0.8rem; color: #3f9d78; padding-left: 34px; }
.stop-tools { display: flex; gap: 4px; flex: none; }
.mini { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 0.85rem; }
.mini:disabled { opacity: 0.35; cursor: default; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* 管理頁 */
.admin-main { max-width: 720px; margin: 0 auto; padding-top: 20px; display: grid; gap: 12px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.admin-lists { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.admin-card { background: var(--surface); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.ac-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ac-id { font-size: 0.85rem; color: var(--accent); background: var(--accent-soft); padding: 1px 8px; border-radius: 6px; }
.ac-url { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.9rem; }
.ac-url a { color: var(--accent); overflow-wrap: anywhere; }
.ac-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 0.9rem; }
.ac-facts dt { color: var(--muted); }
.ac-facts dd { margin: 0; overflow-wrap: anywhere; }
.ac-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.danger { background: var(--dislike); border-color: var(--dislike); color: #fff; box-shadow: none; }
.btn.danger-text { color: var(--dislike); }
.notice { margin: 0; padding: 10px 14px; border-radius: 12px; background: #e7f6ee; color: #1f6b44; font-size: 0.92rem; }
.preview { display: grid; gap: 8px; background: var(--bg); border-radius: 12px; padding: 12px; }
.warn { margin: 0; padding: 10px 12px; border-radius: 10px; background: #fdecea; color: #8f2d1f; font-weight: 600; font-size: 0.92rem; }
.sheet-body input:not([type]), .sheet-body input[type="file"] { width: 100%; }
