:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-2: #F0F2F5;
  --ink: #1B1F24;
  --ink-2: #3D434C;
  --muted: #6B7280;
  --line: #E4E7EC;
  --accent: #2457D6;
  --accent-soft: #EAF0FF;
  --gold: #B7791F;
  --gold-soft: #FDF4E3;
  --warn: #B45309;
  --warn-soft: #FEF3E2;
  --ok: #157F5B;
  --ok-soft: #E6F5EE;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1115;
    --surface: #171A20;
    --surface-2: #1E222A;
    --ink: #ECEEF1;
    --ink-2: #C9CDD4;
    --muted: #9AA1AC;
    --line: #2A2F38;
    --accent: #8AA9FF;
    --accent-soft: #1C2540;
    --gold: #F2C46B;
    --gold-soft: #2D2414;
    --warn: #F0B46A;
    --warn-soft: #2C2114;
    --ok: #6FD3A8;
    --ok-soft: #13271F;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
[hidden] { display: none !important; }

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 18px) calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 18px);
  display: flex;
  flex-direction: column;
}
main { flex: 1; }

/* 頂部 */
.top { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.brand { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.brand img { border-radius: 8px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--ink-2); }
.icon-btn:active { background: var(--surface-2); }

/* 分段切換 */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; margin: 6px 0 12px; }
.seg-btn { height: 40px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.seg-btn.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* 搜尋框 */
.search { position: relative; }
.search input {
  width: 100%;
  height: 54px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 17px; /* 大於 16px，iPhone 才不會自動放大 */
  padding: 0 46px 0 46px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s;
}
.search input:focus { border-color: var(--accent); }
.search input::-webkit-search-cancel-button { display: none; }
.search-ico { position: absolute; left: 15px; top: 17px; color: var(--muted); pointer-events: none; }
.clear { position: absolute; right: 8px; top: 8px; width: 38px; height: 38px; display: grid; place-items: center; color: var(--muted); border-radius: 10px; }

/* 快速選項 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.chip { height: 36px; padding: 0 14px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); font-size: 14.5px; color: var(--ink-2); }
.chip:active, .chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* 結果 */
#results { margin-top: 10px; }
.notice { font-size: 14px; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 14px; margin: 4px 0 12px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .04em; margin: 22px 2px 10px; }

.res {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  margin-bottom: 10px;
}
.res.top1 { border: 1.5px solid var(--accent); }
.res-head { display: flex; align-items: flex-start; gap: 12px; }
.rank { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted); margin-top: 2px; }
.top1 .rank { background: var(--accent); color: #fff; }
.res-name { flex: 1; min-width: 0; }
.res-card { font-size: 16.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.res-title { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.res-rate { flex: none; text-align: right; }
.rate-num { font-size: 28px; font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.rate-num small { font-size: 16px; font-weight: 700; margin-left: 1px; }
.rate-unit { font-size: 12px; color: var(--muted); margin-top: 2px; }
.top1 .rate-num { color: var(--accent); }

.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.best { background: var(--gold-soft); color: var(--gold); }
.pill.plan { background: var(--accent-soft); color: var(--accent); }
.pill.reg { background: var(--warn-soft); color: var(--warn); }
.pill.day { background: var(--surface-2); color: var(--ink-2); }
.pill.net { background: var(--surface-2); color: var(--ink-2); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.how { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14.5px; }
.how b { font-weight: 650; }
.how .must { color: var(--warn); font-weight: 650; }
.fine { margin-top: 8px; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.fine span + span::before { content: "・"; margin: 0 2px; }
.hint { margin-top: 8px; font-size: 13px; color: var(--ok); }
.src { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 12.5px; }

.more { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.more summary { font-size: 13.5px; color: var(--accent); cursor: pointer; list-style: none; padding: 4px 0; }
.more summary::-webkit-details-marker { display: none; }
.alt { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.alt:last-child { border-bottom: 0; }
.alt-top { display: flex; justify-content: space-between; gap: 10px; }
.alt-rate { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* AI 臨時活動 */
.live { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.live-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.live-item:last-child { border-bottom: 0; }
.live-title { font-weight: 650; font-size: 15px; }
.live-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.live-note { font-size: 12.5px; color: var(--warn); margin-top: 8px; }
.skeleton { height: 14px; border-radius: 7px; background: var(--surface-2); margin: 10px 0; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* 卡片詳情 */
.card-hero { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; }
.card-hero h3 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.card-hero .meta { font-size: 14px; color: var(--ink-2); margin-top: 8px; }
.group-title { font-size: 15px; font-weight: 700; margin: 22px 2px 8px; display: flex; align-items: center; gap: 8px; }
.rule { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 8px; }
.rule-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.rule-title { font-weight: 650; font-size: 15px; }
.rule-rate { font-weight: 750; font-size: 20px; font-variant-numeric: tabular-nums; color: var(--accent); white-space: nowrap; }
.merchants { font-size: 13.5px; color: var(--ink-2); margin-top: 6px; }
.card-list { display: grid; gap: 8px; }
.card-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; text-align: left; width: 100%; }
.card-row .nm { font-weight: 650; }
.card-row .sub { font-size: 13px; color: var(--muted); }
.card-row .chev { margin-left: auto; color: var(--muted); }

/* 設定 */
.back { display: inline-flex; align-items: center; gap: 2px; height: 40px; color: var(--accent); font-size: 16px; margin-left: -6px; }
.page-title { font-size: 24px; margin: 4px 2px 14px; }
.set-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.set-label { font-size: 13px; color: var(--muted); margin: 0 4px 8px; font-weight: 600; letter-spacing: .03em; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); min-height: 56px; }
.set-row:last-child { border-bottom: 0; }
.set-row .txt { flex: 1; min-width: 0; }
.set-row .txt small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.45; margin-top: 2px; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 31px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 27px; height: 27px; background: #fff; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
select.sel { font: inherit; font-size: 15px; color: var(--ink); background: var(--surface-2); border: 0; border-radius: 10px; height: 36px; padding: 0 10px; }

.foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 28px; line-height: 1.7; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 15px; }

@media (min-width: 760px) {
  .app { padding-top: 24px; }
  .rate-num { font-size: 32px; }
}
