:root {
  --bg: #f3f0e8;
  --surface: #fffdf8;
  --ink: #1b2320;
  --muted: #5d6762;
  --line: #e1dccf;
  --accent: #0e5a4b;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe5;
  --good: #1d7149;
  --good-soft: #dff0e5;
  --warn: #8a5300;
  --warn-soft: #f8ead2;
  --bad: #9c2f28;
  --bad-soft: #f6e0dc;
  --idle: #6b716e;
  --idle-soft: #ebe8e1;
  --focus: #1d6fd1;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(27 35 32 / 6%), 0 4px 16px rgb(27 35 32 / 5%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a201d;
    --ink: #e7ece9;
    --muted: #9ba6a1;
    --line: #2b3430;
    --accent: #4cb498;
    --accent-ink: #0b1210;
    --accent-soft: #1d3530;
    --good: #5cc98f;
    --good-soft: #193326;
    --warn: #e8a948;
    --warn-soft: #382a14;
    --bad: #ec7d71;
    --bad-soft: #3a1d1a;
    --idle: #9aa19d;
    --idle-soft: #262c29;
    --focus: #7db4ff;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 0.8125rem; }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 36px; height: 36px; flex: none; border-radius: 10px; display: block; }
.brand-name { font-weight: 650; letter-spacing: 0.01em; white-space: nowrap; }
.bar-actions { display: flex; gap: 8px; }

.chip {
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 0.875rem;
  white-space: nowrap; flex: none;
}
@media (max-width: 359px) {
  .brand-name { display: none; }
}

main {
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.view { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
}

/* forms */
form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
label { font-size: 0.875rem; font-weight: 600; }
input, textarea {
  width: 100%; min-height: 48px; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg);
  font-size: 16px; /* no iOS zoom */
}
textarea { resize: vertical; min-height: 84px; overflow-wrap: anywhere; }
input:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.primary, .ghost {
  min-height: 48px; padding: 0 18px;
  border-radius: 10px; cursor: pointer; font-weight: 600;
}
.primary { border: 0; background: var(--accent); color: var(--accent-ink); margin-top: 4px; }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.primary.busy { opacity: 0.7; cursor: progress; }
.ghost { border: 1px solid var(--line); background: transparent; flex: none; }
.ghost.small { min-height: 34px; padding: 0 12px; font-size: 0.8125rem; font-weight: 500; }

.field-msg { min-height: 1.25em; font-size: 0.875rem; color: var(--muted); }
.field-msg.ok { color: var(--good); }
.field-msg.err { color: var(--bad); }
.field-msg:empty { min-height: 0; }

/* login */
.login { margin-top: 8vh; padding: 24px 20px; display: flex; flex-direction: column; gap: 8px; }
.login .fine { margin-top: 8px; }
.login .field-msg { font-size: 1.0625rem; min-height: 1.5em; color: var(--ink); }
.login .field-msg.err { color: var(--bad); }

/* wallet */
.wallet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wallet-head h2 { color: var(--muted); font-weight: 500; font-size: 0.875rem; }
.amount {
  margin: 4px 0 14px;
  font-size: clamp(2rem, 9vw, 2.5rem); font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.amount .cur { font-size: 0.6em; font-weight: 600; margin-right: 4px; color: var(--muted); }
.wallet-grid { margin: 0 0 10px; background: var(--bg); border-radius: 10px; padding: 2px 12px; }
.wallet-grid div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 0; }
.wallet-grid div + div { border-top: 1px solid var(--line); }
.wallet-grid dt { font-size: 0.875rem; color: var(--muted); }
.wallet-grid dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* how it works */
.how { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 0.875rem; }
.how summary { cursor: pointer; font-weight: 600; color: var(--accent); min-height: 32px; }
.how ol { margin: 8px 0 0; padding-left: 1.25em; display: flex; flex-direction: column; gap: 6px; color: var(--muted); }

/* list */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 2px 10px; }
.live { font-size: 0.75rem; color: var(--good); display: inline-flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .live::before { animation: none; } }
.empty { padding: 4px 2px; }

.transfers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.tr { padding: 14px 14px 12px; }
.tr-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tr-id { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tr-main { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 10px; }
.tr-item { font-size: 0.875rem; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.tr-item b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.tr-price { font-weight: 700; font-size: 1.125rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tr-note { margin-top: 8px; font-size: 0.875rem; padding: 8px 10px; border-radius: 8px; }
.tr-note.bad { background: var(--bad-soft); color: var(--bad); }
.tr-note.warn { background: var(--warn-soft); color: var(--warn); }
.tr-note.idle { background: var(--idle-soft); color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 600; line-height: 1.4;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pill.active { background: var(--accent-soft); color: var(--accent); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.idle { background: var(--idle-soft); color: var(--idle); }

/* 4-step progress */
.steps { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.steps li { font-size: 0.6875rem; color: var(--muted); line-height: 1.3; padding-top: 7px; position: relative; min-width: 0; }
.steps li::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--line); }
.steps li.done::before { background: var(--accent); }
.steps li.now { color: var(--ink); font-weight: 600; }
.steps li.now::before { background: linear-gradient(90deg, var(--accent) 50%, var(--line) 50%); }
.steps.complete li.now::before { background: var(--good); }
.steps.complete li.done::before { background: var(--good); }

.tr-more {
  margin-top: 10px; padding: 0; min-height: 32px;
  border: 0; background: none; color: var(--accent); font-size: 0.8125rem; font-weight: 600; cursor: pointer;
}
.tr-detail { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 0.8125rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kv dd.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.75rem; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.timeline li { position: relative; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline .t-state { font-weight: 600; }
.timeline .t-time { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 6px; }
.timeline .t-detail { color: var(--muted); }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg);
  font-size: 0.875rem; box-shadow: 0 6px 24px rgb(0 0 0 / 25%);
  z-index: 10;
}
.noscript { padding: 24px 16px; text-align: center; }

@media (min-width: 600px) {
  main { padding-top: 28px; }
  .card { padding: 22px 22px; }
  .tr { padding: 16px 18px 14px; }
  .steps li { font-size: 0.75rem; }
}
.warn-text { color: var(--warn); }

/* tabs */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; background: var(--idle-soft); border-radius: 12px; }
.tab {
  min-height: 42px; padding: 4px 6px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  font-weight: 600; font-size: 0.875rem; line-height: 1.2; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tab-count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 0.75rem; line-height: 20px; }
.panel { display: flex; flex-direction: column; gap: 10px; }

/* store */
.store-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 2px 0; }
.store-head h2 { font-size: 1.0625rem; }
#store-meta, #store-msg, .min-hint { margin: 0 2px; }
.search {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 16px;
}
.group-h { margin: 6px 2px 0; font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.item {
  width: 100%; height: 100%; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; padding: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.item:active { transform: scale(0.98); }
.item:hover { border-color: var(--accent); }
.thumb {
  aspect-ratio: 4 / 3; width: 100%; border-radius: 10px; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, var(--surface), var(--idle-soft));
  display: flex; align-items: center; justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb .ph { width: 40%; height: 40%; border-radius: 50%; background: var(--line); }
.item-name {
  font-size: 0.8125rem; font-weight: 600; line-height: 1.3; min-height: 2.6em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere;
}
.item-sub { font-size: 0.6875rem; color: var(--muted); line-height: 1.35; overflow-wrap: anywhere; }
.item-price { margin-top: auto; font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; }
.paste { padding: 14px 16px; margin-top: 6px; }
.paste summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: 0.875rem; }
.paste form { margin-top: 10px; }
.panel > .how { border-top: 0; padding: 0 2px; margin-top: 0; }

/* confirm sheet */
.backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 45%);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; background: var(--surface); color: var(--ink);
  border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 -8px 32px rgb(0 0 0 / 25%);
  max-height: 90vh; overflow-y: auto;
}
.sheet-item { display: flex; gap: 12px; align-items: center; }
.sheet-item .thumb { width: 96px; flex: none; }
.sheet-text { min-width: 0; }
.sheet-name { font-weight: 600; overflow-wrap: anywhere; }
.sheet-q { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 4px; }
.sheet-actions .primary { margin-top: 0; }
body.sheet-open { overflow: hidden; }
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
}

/* readiness: how much of the buyer's own balance is ready to deliver now */
.ready { margin: -4px 0 14px; display: flex; flex-direction: column; gap: 6px; }
.meter { height: 8px; border-radius: 999px; background: var(--idle-soft); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width 0.4s ease; }
.ready.full .meter span { background: var(--good); }
.ready-line { font-weight: 600; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .meter span { transition: none; } }
.group-note { margin: -4px 2px 2px; }
.item-later { font-size: 0.6875rem; font-weight: 600; color: var(--accent); }

/* history */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat dt { font-size: 0.75rem; color: var(--muted); }
.stat dd { margin: 2px 0 0; font-weight: 700; font-size: 1.25rem; font-variant-numeric: tabular-nums; line-height: 1.25; white-space: nowrap; }
.stat .stat-sub { display: block; margin-top: 2px; font-size: 0.75rem; font-weight: 400; color: var(--muted); }
.hist-sec { display: flex; flex-direction: column; gap: 6px; }
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.rows li { padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline; }
.rows li + li { border-top: 1px solid var(--line); }
.rows .r-main { font-weight: 600; font-variant-numeric: tabular-nums; }
.rows .r-date { font-size: 0.8125rem; color: var(--muted); text-align: right; white-space: nowrap; }
.rows .r-sub { grid-column: 1 / -1; font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.rows .r-sub a { color: var(--accent); font-weight: 600; text-decoration: none; }
.rows .r-sub a:hover { text-decoration: underline; }
.rows .r-empty { color: var(--muted); font-size: 0.875rem; }
.rows .r-more { display: block; }
.rows .r-more button { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 0.8125rem; cursor: pointer; padding: 4px 0; min-height: 32px; }
@media (max-width: 379px) {
  .stats { grid-template-columns: 1fr; }
  .tab { font-size: 0.8125rem; padding: 4px 2px; }
}

/* history rows (tappable) */
.rows li { padding: 0; display: block; }
.rows li.r-empty { padding: 12px; }
.rows li.r-more { padding: 4px 12px; }
.hrow {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px; text-align: left;
  border: 0; background: transparent; cursor: pointer; color: inherit;
}
.hrow:hover { background: var(--bg); }
.rows li:first-child .hrow { border-radius: var(--radius) var(--radius) 0 0; }
.rows li:last-child .hrow { border-radius: 0 0 var(--radius) var(--radius); }
.hrow .thumb { width: 64px; flex: none; aspect-ratio: 4 / 3; border-radius: 8px; }
.h-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.h-title { font-weight: 600; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.with-thumb .h-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 0.875rem; line-height: 1.3; }
.h-sub { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.h-right { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.h-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.h-date { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.meter.small { height: 4px; margin-top: 3px; max-width: 220px; }

/* detail popup */
.detail { gap: 8px; }
.detail .thumb.big { width: 100%; max-width: 320px; align-self: center; aspect-ratio: 4 / 3; }
.detail-kind { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.detail-title { font-size: 1.125rem; overflow-wrap: anywhere; }
.detail-amount { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.detail-kv { margin: 6px 0 0; font-size: 0.875rem; }
.detail-kv dd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mono-wrap { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.8125rem; overflow-wrap: anywhere; }
.hash {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.8125rem; overflow-wrap: anywhere; word-break: break-all;
  background: var(--bg); border-radius: 8px; padding: 10px 12px;
}
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.link-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; min-height: 40px; padding: 0 14px; margin-top: 0; font-size: 0.875rem; }
.detail-actions .ghost.small { min-height: 40px; }
.rows.mini .hrow .thumb { width: 52px; }
#detail-close { margin-top: 6px; }
