:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #14171c;
  --muted: #5d6470;
  --line: #dde1e7;
  --accent: #0b7a5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3ed;
  --warn-soft: #fff4dc;
  --warn-line: #e8c36a;
  --danger: #b3261e;
  --radius: 14px;
  --tap: 48px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1f2530;
    --text: #eef1f5;
    --muted: #9aa3b2;
    --line: #2a313d;
    --accent: #3ccf9a;
    --accent-ink: #062218;
    --accent-soft: #123528;
    --warn-soft: #3a2f12;
    --warn-line: #8a6d1f;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; letter-spacing: 0.01em; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

h2 { font-size: 22px; margin: 8px 0 4px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 6px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* Tab bar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 3;
}
.tabbar a {
  display: flex; align-items: center; justify-content: center;
  min-height: 56px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

/* Banners */
.banner {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.banner p { margin: 0 0 8px; }
.banner p:last-child { margin-bottom: 0; }
.banner.warn { background: var(--warn-soft); border: 1px solid var(--warn-line); }

/* Amount */
.amount {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin-bottom: 14px;
}
.amount span { font-weight: 600; }
.amount input {
  flex: 1;
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  text-align: right;
  outline: none;
}

/* Category grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  display: flex; align-items: center;
  min-height: 72px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  line-height: 1.25;
}
.tile:active { background: var(--surface-2); }

/* Results */
.back { display: inline-flex; align-items: center; min-height: 40px; text-decoration: none; font-weight: 600; }
.back::before { content: "<"; margin-right: 6px; }
.hint { color: var(--muted); margin: 0 0 14px; }

.result {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.result.top { border: 2px solid var(--accent); }
.eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.result-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-name { font-size: 20px; font-weight: 700; line-height: 1.25; margin: 2px 0; }
.result.runner .card-name { font-size: 17px; }
.rate { font-size: 34px; font-weight: 800; color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }
.result.runner .rate { font-size: 22px; color: var(--text); }
.upto { font-size: 12px; font-weight: 600; color: var(--muted); margin-right: 4px; }
.reason { margin: 6px 0 0; }

.hints { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  margin-top: 10px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn.small { min-height: 36px; margin-top: 0; font-size: 14px; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; padding: 4px 8px; }

/* Card info */
.cardinfo {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.cardinfo header { display: flex; align-items: center; gap: 10px; }
.cardinfo h2 { margin: 0; font-size: 20px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.facts { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.earn-list, .perks { margin: 0; padding: 0; list-style: none; }
.earn { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.earn:first-child { border-top: 0; }
.earn-rate { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.earn-tags { display: block; color: var(--muted); font-size: 13px; }
.perks li { padding: 6px 0 6px 14px; position: relative; }
.perks li::before { content: ""; position: absolute; left: 0; top: 15px; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.notes { margin-top: 10px; padding: 10px 12px; background: var(--warn-soft); border-radius: 10px; font-size: 14px; }
.notes p { margin: 0 0 6px; }
.notes p:last-child { margin: 0; }
.cardinfo footer { margin-top: 12px; }

/* Tracker */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.panel h2 { font-size: 18px; margin: 0 0 8px; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.check:first-of-type { border-top: 0; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.check span span { display: block; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; }
.inline input {
  min-height: 40px;
  width: 9em;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.cap { padding: 10px 0; border-top: 1px solid var(--line); }
.cap:first-of-type { border-top: 0; }
.cap-head { display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar span { display: block; height: 100%; background: var(--accent); }
.log { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.log li { display: grid; grid-template-columns: 7em 1fr auto; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }

/* Toast */
.toast {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  z-index: 4;
}
.toast[hidden] { display: none; }
.toast .link { color: var(--bg); text-decoration: underline; }
