:root {
  --bg: #ffffff;
  --ink: #0b0b0c;
  --ink-2: #3a3b3f;
  --muted: #7a7d85;
  --line: #ececef;
  --soft: #f3f4f6;
  --card: #ffffff;
  --green: #0b9a5e;
  --green-bg: #e7f7ef;
  --red: #d93b40;
  --red-bg: #fdecec;
  --blue: #1a6fdb;
  --blue-bg: #e8f1fe;
  --amber-bg: #fff6dc;
  --amber: #8a5a00;
  --shadow: 0 1px 2px rgba(16, 17, 20, .04), 0 8px 24px rgba(16, 17, 20, .06);
  --radius: 22px;
  --tab-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0e;
    --ink: #f4f4f5;
    --ink-2: #c9cacf;
    --muted: #8d9099;
    --line: #232328;
    --soft: #18181c;
    --card: #141417;
    --green: #2fd18b;
    --green-bg: #0f2a1f;
    --red: #ff6b6f;
    --red-bg: #321617;
    --blue: #5aa2ff;
    --blue-bg: #13233a;
    --amber-bg: #2c2410;
    --amber: #f0c45a;
    --shadow: 0 0 0 1px #202026;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 16px calc(var(--tab-h) + var(--safe-b) + 32px);
  min-height: 100vh;
}

/* ---------- headings ---------- */
.hello { color: var(--muted); font-size: 17px; margin: 6px 0 0; }
.title { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 18px; line-height: 1.15; }
.section-h { display: flex; align-items: center; gap: 10px; margin: 30px 0 12px; }
.section-h h2 { font-size: 22px; font-weight: 800; letter-spacing: -.01em; margin: 0; }
.count-pill { background: var(--soft); border-radius: 999px; padding: 2px 10px; font-weight: 700; font-size: 14px; }
.section-h .spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- search ---------- */
.searchbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--soft); border-radius: 999px; padding: 6px 6px 6px 20px;
}
.searchbar input { flex: 1; border: 0; background: transparent; outline: none; font-size: 17px; min-width: 0; padding: 10px 0; }
.searchbar input::placeholder { color: var(--muted); }
.round-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.round-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0; background: var(--soft); border-radius: 999px; padding: 10px 16px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--bg); }

/* ---------- tracked cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  display: block; margin-bottom: 14px;
}
.ev-head { display: flex; gap: 14px; align-items: center; min-width: 0; }
.ev-head > div { min-width: 0; }
.thumb {
  width: 64px; height: 64px; border-radius: 18px; object-fit: cover; background: var(--soft); flex: none;
}
.ev-name { font-weight: 800; font-size: 17px; line-height: 1.25; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ev-when { color: var(--muted); font-size: 14px; margin-top: 3px; }
.ev-stats { display: flex; align-items: flex-end; gap: 12px; margin-top: 16px; }
.big-price { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.big-price small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 2px; letter-spacing: 0; }
.label { font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 6px; }
.spark { flex: 1; height: 44px; min-width: 60px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 4px 10px;
  font-size: 13px; font-weight: 700; background: var(--soft); color: var(--ink-2);
}
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.pdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.empty {
  text-align: center; padding: 40px 20px; background: var(--soft); border-radius: var(--radius);
}
.empty h3 { margin: 0 0 6px; font-size: 19px; }
.empty p { margin: 0 0 18px; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 14px 22px; font-weight: 700; cursor: pointer;
  background: var(--ink); color: var(--bg); font-size: 16px; transition: transform .1s;
}
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--soft); color: var(--ink); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; padding-left: 12px; padding-right: 12px; }

/* ---------- search results ---------- */
.result {
  display: flex; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); cursor: pointer;
  width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left;
}
.result:last-child { border-bottom: 0; }
.result .meta { flex: 1; min-width: 0; }
.result .ev-name { font-size: 16px; }
.plat-prices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.from { text-align: right; flex: none; }
.from b { font-size: 19px; font-weight: 800; display: block; }

/* ---------- event detail ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--soft); display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.hero {
  background: #111113; color: #fff; border-radius: 28px; padding: 20px; display: flex; gap: 16px; align-items: center;
}
.hero > div { min-width: 0; }
.hero .ev-when { color: rgba(255,255,255,.72); }
.hero .thumb { width: 76px; height: 76px; border: 3px solid rgba(255,255,255,.92); }
.hero .ev-name { color: #fff; font-size: 19px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.tag { background: rgba(255,255,255,.14); border-radius: 10px; padding: 4px 10px; font-size: 13px; font-weight: 700; }
.tag span { opacity: .65; font-weight: 600; margin-right: 4px; }

.now { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 22px 2px 4px; flex-wrap: wrap; }
.now .big-price { font-size: 40px; }

.seg { display: flex; background: var(--soft); border-radius: 999px; padding: 4px; margin: 16px 0 8px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 999px; padding: 8px 0; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.chart { position: relative; height: 220px; margin: 6px 0 4px; touch-action: pan-y; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .band { fill: var(--green-bg); }
.chart-tip {
  position: absolute; top: -6px; pointer-events: none; background: var(--ink); color: var(--bg); border-radius: 12px;
  padding: 6px 10px; font-size: 12px; white-space: nowrap; transform: translateX(-50%); display: none; z-index: 2; line-height: 1.5;
}
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); margin: 4px 2px 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-empty { min-height: 150px; display: grid; place-items: center; color: var(--muted); background: var(--soft); border-radius: 18px; text-align: center; padding: 16px; font-size: 14px; }

.plat {
  display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line);
}
.plat:last-child { border-bottom: 0; }
.plat .logo {
  width: 40px; height: 40px; border-radius: 12px; color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none;
}
.plat .meta { flex: 1; min-width: 0; }
.plat .name { font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.plat .sub { color: var(--muted); font-size: 13px; }
.plat .price { text-align: right; flex: none; }
.plat .price b { font-size: 20px; font-weight: 800; display: block; font-variant-numeric: tabular-nums; }
.plat .go { font-size: 13px; font-weight: 700; color: var(--blue); }
.plat.dim .logo { opacity: .45; }
.cheapest { color: var(--green); font-size: 12px; font-weight: 800; }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--soft); border-radius: 16px; padding: 12px; }
.stat b { display: block; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }

.kv { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); flex: none; }
.kv span:last-child { font-weight: 600; text-align: right; }

/* ---------- alerts ---------- */
.alert-row { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.alert-row .thumb { width: 48px; height: 48px; border-radius: 14px; }
.alert-row h4 { margin: 0; font-size: 15px; }
.alert-row p { margin: 2px 0 0; font-size: 14px; color: var(--ink-2); }
.alert-row.unread h4::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); margin-right: 6px; vertical-align: 2px; }

/* ---------- forms / sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease-out;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 28px 28px 0 0; padding: 10px 20px calc(24px + var(--safe-b));
  animation: up .24s cubic-bezier(.2,.8,.2,1);
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 4px; font-size: 21px; font-weight: 800; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

.field { margin-top: 20px; }
.field > label, .field > .flabel { display: block; font-weight: 700; margin-bottom: 8px; }
.field .hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.qty { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.qty button { aspect-ratio: 1; max-width: 48px; border-radius: 50%; border: 0; background: var(--soft); font-weight: 700; cursor: pointer; padding: 0; }
.qty button.on { background: var(--ink); color: var(--bg); }
.range { display: flex; align-items: center; gap: 10px; }
.money { flex: 1; display: flex; align-items: center; background: var(--soft); border-radius: 16px; padding: 0 14px; min-width: 0; }
.money span { color: var(--muted); font-weight: 700; }
.money input { border: 0; background: transparent; outline: none; width: 100%; padding: 13px 6px; font-size: 17px; font-weight: 700; min-width: 0; }
select.input {
  width: 100%; appearance: none; -webkit-appearance: none; border: 0; background: var(--soft); border-radius: 16px; padding: 13px 14px; font-size: 16px; font-weight: 600;
}
.toggle-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .txt { flex: 1; }
.toggle-row .txt b { display: block; font-weight: 600; }
.toggle-row .txt span { font-size: 13px; color: var(--muted); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--blue); outline-offset: 2px; }
select.pct { width: auto; padding: 6px 28px 6px 10px; border-radius: 10px; font-size: 14px; border: 0; background: var(--soft); font-weight: 700; }
.error { color: var(--red); font-size: 14px; margin-top: 10px; font-weight: 600; }

.note {
  background: var(--soft); border-radius: 16px; padding: 12px 14px; font-size: 14px; color: var(--ink-2); margin-top: 12px;
}
.note b { color: var(--ink); }
.note code { font-size: 13px; background: var(--card); padding: 1px 5px; border-radius: 6px; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b));
  width: min(520px, calc(100% - 24px)); height: var(--tab-h);
  display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--bg) 84%, transparent); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-radius: 999px; box-shadow: 0 0 0 1px var(--line), 0 10px 30px rgba(0,0,0,.08); z-index: 30;
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 600;
  color: var(--muted); padding: 8px 14px; border-radius: 999px;
}
.tabbar a.on { color: var(--ink); background: var(--soft); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .dot { position: absolute; top: 6px; right: 14px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 24px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.skeleton { background: var(--soft); border-radius: 18px; height: 92px; margin: 12px 0; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }
