:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --ink: #1d2521;
  --ink-2: #56605a;
  --line: #d9d2c3;
  --brand: #0f4c45;
  --brand-2: #1c6b61;
  --brand-ink: #ffffff;
  --gold: #c98a0b;
  --gold-soft: #fbefd2;
  --ok: #2f7d3b;
  --ok-soft: #e1f1e1;
  --warn: #a0560d;
  --warn-soft: #fbe6cf;
  --bad: #b3261e;
  --bad-soft: #f9dedc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .06);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1a201d;
    --surface-2: #232b27;
    --ink: #ecefe9;
    --ink-2: #a3ada7;
    --line: #2f3833;
    --brand: #5fb8a9;
    --brand-2: #7dcabd;
    --brand-ink: #0b1f1c;
    --gold: #e8b34a;
    --gold-soft: #3a2f17;
    --ok: #7cc489;
    --ok-soft: #1d3322;
    --warn: #e8a05a;
    --warn-soft: #3a2816;
    --bad: #f08a82;
    --bad-soft: #3d1f1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
img, video { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; letter-spacing: .02em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--ink-2); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { position: relative; color: var(--ink); display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; }
.badge {
  position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.offline-bar { background: var(--warn-soft); color: var(--warn); padding: 8px 16px; font-size: .9rem; text-align: center; }

main { max-width: 760px; margin: 0 auto; padding: 16px; outline: none; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--ink-2); text-decoration: none;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--brand); font-weight: 700; }
.tabbar .tab-primary svg { background: var(--brand); color: var(--brand-ink); border-radius: 12px; width: 40px; height: 32px; padding: 4px 8px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }

.hero {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: var(--brand-ink); border-radius: 20px; padding: 22px 20px; margin-bottom: 16px;
}
.hero h1 { font-size: 1.6rem; }
.hero p { opacity: .9; }
.hero .big { font-size: 2.6rem; font-weight: 800; letter-spacing: .01em; color: var(--gold-soft); }
@media (prefers-color-scheme: dark) { .hero .big { color: #fff4d6; } }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 520px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.type-card {
  text-align: left; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius); padding: 14px; cursor: pointer; font: inherit; width: 100%;
}
.type-card strong { display: block; font-size: 1rem; }
.type-card .amount { color: var(--gold); font-weight: 800; font-size: 1.1rem; }
.type-card[aria-pressed="true"] { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1.5px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--brand); color: var(--brand-ink);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.gold { background: var(--gold); color: #1e1400; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px;
  padding: 4px 12px; font: inherit; font-size: .85rem; cursor: pointer;
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

label { display: block; font-weight: 600; font-size: .92rem; margin: 12px 0 4px; }
label .req { color: var(--bad); margin-left: 2px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .type-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 1px; border-color: var(--brand);
}
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 10px 0; }
.check input { width: 22px; min-height: 22px; height: 22px; margin-top: 2px; flex: none; accent-color: var(--brand); }
.hint { font-size: .85rem; color: var(--ink-2); margin-top: 4px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.pill { display: inline-block; font-size: .78rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

.notice { border-radius: 12px; padding: 12px 14px; margin: 10px 0; font-size: .92rem; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.info { background: var(--surface-2); color: var(--ink); }
.notice ul { margin: 6px 0 0; padding-left: 1.2rem; }

table.amounts { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.amounts th, table.amounts td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.amounts td.num { text-align: right; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }
.list a.item { display: flex; gap: 12px; align-items: center; padding: 12px 2px; color: var(--ink); text-decoration: none; }
.list .item-main { flex: 1; min-width: 0; }
.list .item-main strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .amount { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.steps { display: flex; gap: 6px; margin-bottom: 14px; }
.steps span { flex: 1; height: 5px; border-radius: 3px; background: var(--surface-2); }
.steps span.done { background: var(--brand); }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 14px 8px; }
.timeline li::before { content: ""; position: absolute; left: -25px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.media-tile { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.media-tile img, .media-tile video { width: 100%; aspect-ratio: 16/10; object-fit: cover; background: #000; }
.media-tile .meta { padding: 6px 8px; font-size: .78rem; }
.media-tile .hash { font-family: var(--mono); font-size: .7rem; color: var(--ink-2); word-break: break-all; }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; cursor: pointer;
  background: var(--surface);
}
.dropzone.drag { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 6%, var(--surface)); }
progress { width: 100%; height: 8px; accent-color: var(--brand); }

pre.packet {
  white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 14px; border-radius: 12px;
  font-family: var(--font); font-size: .92rem; max-height: 420px; overflow: auto; margin: 0;
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 50; font-size: .92rem;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.loading { display: flex; gap: 6px; justify-content: center; padding: 40px; }
.loading span { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); animation: bounce 1s infinite ease-in-out; }
.loading span:nth-child(2) { animation-delay: .15s; }
.loading span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.5); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

.county-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.county {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.county strong { display: block; }
.county .amt { font-size: .82rem; color: var(--gold); font-weight: 700; }
.county.none { opacity: .55; }
.county.sel { border-color: var(--brand); box-shadow: inset 0 0 0 1.5px var(--brand); }

.kv { display: grid; grid-template-columns: 7.5em 1fr; gap: 4px 10px; font-size: .94rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; word-break: break-word; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.center { text-align: center; }
.empty { text-align: center; color: var(--ink-2); padding: 30px 10px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print {
  .topbar, .tabbar, .btn, .btn-row, .no-print { display: none !important; }
  body { padding: 0; background: #fff; }
  .card { box-shadow: none; border: none; }
}
