:root {
  --bg: #fff8f1;
  --card: #ffffff;
  --ink: #2b2118;
  --muted: #8a7a6b;
  --line: #efe2d4;
  --brand: #d9480f;
  --brand-ink: #ffffff;
  --brand-soft: #ffe8d9;
  --ok: #2b8a3e;
  --warn: #c92a2a;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(80, 40, 10, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1612; --card: #262019; --ink: #f3ebe3; --muted: #a8988a; --line: #3a3027;
    --brand: #ff7a3d; --brand-ink: #1b1612; --brand-soft: #3d2618; --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 4px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--warn); min-height: 1.5em; margin: 8px 0 0; }

/* 按鈕與輸入 */
button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.big { width: 100%; padding: 14px; font-size: 1.05rem; }
.btn.huge { width: 100%; padding: 20px; font-size: 1.35rem; border-radius: 18px; margin: 16px 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--warn); }
.btn.sm { padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
.link { background: none; border: 0; color: var(--muted); padding: 4px; }
input, select {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }

/* 登入 */
.screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--card); border-radius: 24px; padding: 32px 24px;
  box-shadow: var(--shadow); text-align: center;
}
.login-card form { text-align: left; margin-top: 20px; }
.logo { font-size: 56px; }

/* 版面 */
#app { max-width: 640px; margin: 0 auto; padding-bottom: 88px; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.topbar h1 { font-size: 1.2rem; }
main { padding: 0 16px; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 0 1 140px; background: none; border: 0; padding: 6px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; font-size: .8rem; color: var(--muted);
}
.tabbar button span { font-size: 1.35rem; }
.tabbar button.active { color: var(--brand); background: var(--brand-soft); font-weight: 700; }

/* 交通方式 */
.mode-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.mode-card {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 18px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: var(--shadow);
}
.mode-card b { font-size: 1.2rem; }
.mode-card small { color: var(--muted); font-size: .8rem; }
.mode-emoji { font-size: 2.2rem; }
.mode-card.selected { border-color: var(--brand); background: var(--brand-soft); }

/* 篩選 */
.filters {
  margin-top: 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.filters summary { font-weight: 600; cursor: pointer; }
.filters[open] summary { margin-bottom: 12px; }
.field { margin-bottom: 12px; }
.field .label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 5px 12px; font-size: .9rem;
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* 店家卡片 */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--line); margin-bottom: 12px;
}
.result { text-align: center; animation: pop .35s ease-out; }
.result .name { font-size: 1.7rem; font-weight: 800; margin: 6px 0; word-break: break-word; }
.spinning .name { opacity: .55; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 4px; }
.tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem;
  background: var(--brand-soft); color: var(--ink);
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .wide { grid-column: 1 / -1; }
.subactions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.stars { display: inline-flex; gap: 2px; }
.stars button { background: none; border: 0; font-size: 1.5rem; padding: 0 2px; line-height: 1; color: #e0b400; }
.stars button.off { color: var(--line); }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* 清單 */
.list-tools { display: grid; gap: 8px; margin-bottom: 8px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px;
}
.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-head b { font-size: 1.02rem; }
.item .meta { justify-content: flex-start; margin: 6px 0 0; }
.item-edit { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 12px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days .chip { padding: 4px 10px; }
.attribution { text-align: center; margin: 16px 0; }

/* 投票 */
.poll-opt {
  display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); margin-bottom: 8px; width: 100%; text-align: left;
}
.poll-opt.mine { border-color: var(--brand); background: var(--brand-soft); }
.poll-opt.winner { border-color: var(--ok); }
.poll-opt .grow { flex: 1; min-width: 0; }
.poll-opt .count { font-size: 1.3rem; font-weight: 800; min-width: 2ch; text-align: right; }
.bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.winner-banner {
  text-align: center; padding: 16px; border-radius: var(--radius); background: var(--brand-soft); margin-bottom: 12px;
}
.winner-banner .name { font-size: 1.5rem; font-weight: 800; }

/* 紀錄 */
.hist-day { margin-bottom: 14px; }
.hist-day h3 { font-size: .95rem; color: var(--muted); margin-bottom: 6px; }

/* 對話框 / 提示 */
dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(440px, calc(100% - 32px));
  background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  opacity: 0; transition: .25s; pointer-events: none; z-index: 20; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.empty .big-emoji { font-size: 48px; display: block; margin-bottom: 8px; }
