:root {
  --bg: #f6f7f9; --card: #ffffff; --ink: #0d1117; --muted: #6b7480; --faint: #9aa3ad; --line: #eceef1;
  --accent: #2563eb; --accent-soft: #e8efff; --out: #0d1117; --in: #0f9d58; --warn: #d97706; --warn-soft: #fff4e5; --bad: #dc2626;
  --track: #eef0f3; --fill: #2563eb; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f14; --card: #141a21; --ink: #eef2f6; --muted: #8b95a1; --faint: #5f6974; --line: #1f2731;
    --accent: #5b8cff; --accent-soft: #1a2540; --out: #eef2f6; --in: #34d399; --warn: #fbbf24; --warn-soft: #2a2110; --bad: #f87171;
    --track: #1f2731; --fill: #5b8cff; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 10px; }
.bar { display: flex; align-items: center; justify-content: space-between; max-width: 640px; margin: 0 auto; }
.title { border: 0; background: none; padding: 4px 0; font-size: 22px; font-weight: 750; letter-spacing: -.02em; display: flex; align-items: baseline; gap: 8px; }
.title span { font-weight: 500; color: var(--muted); font-size: 17px; }
.title i { font-style: normal; color: var(--faint); font-size: 14px; }
.actions { display: flex; gap: 8px; align-items: center; }
.pill { border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600; }
.icon { border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 50%; width: 34px; height: 34px; font-size: 17px; line-height: 1; }
.icon.busy { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.seg { display: flex; background: var(--track); border-radius: 10px; padding: 3px; margin: 12px auto 0; max-width: 640px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 0; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

main { padding: 6px 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 640px; margin: 0 auto; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding: 6px 12px calc(env(safe-area-inset-bottom) + 6px); }
.tabs button { flex: 1; max-width: 140px; border: 0; background: none; padding: 6px 0; font-size: 11px; font-weight: 600; color: var(--faint);
  display: flex; flex-direction: column; align-items: center; gap: 3px; }
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); }

/* hero */
.hero { background: var(--card); border-radius: 20px; padding: 20px; box-shadow: var(--shadow); margin-top: 6px; }
.hero .k { font-size: 13px; color: var(--muted); font-weight: 500; }
.hero .big { font-size: 40px; font-weight: 750; letter-spacing: -.03em; line-height: 1.1; margin: 4px 0 2px; }
.hero .sub { font-size: 13px; color: var(--muted); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); margin: 16px -20px -20px; border-top: 1px solid var(--line); border-radius: 0 0 20px 20px; overflow: hidden; }
.split > div { background: var(--card); padding: 12px 20px 14px; }
.split .k { font-size: 12px; }
.split .v { font-size: 18px; font-weight: 700; margin-top: 1px; }

/* attention */
.alert { display: flex; align-items: center; gap: 12px; background: var(--warn-soft); border-radius: 14px; padding: 12px 14px; margin-top: 12px; border: 0; width: 100%; text-align: left; }
.alert b { font-weight: 700; }
.alert .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.alert .go { margin-left: auto; color: var(--warn); font-weight: 600; font-size: 13px; white-space: nowrap; }

/* sections */
.sec { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 2px 10px; }
.sec h2 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.sec button { border: 0; background: none; color: var(--accent); font-size: 14px; font-weight: 600; padding: 0; }
.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.li { display: flex; gap: 12px; align-items: center; padding: 13px 16px; position: relative; }
.li + .li::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.li.tap { cursor: pointer; } .li.tap:active { background: var(--track); }
.li .main { flex: 1; min-width: 0; }
.li .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.li .m { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.li .amt { text-align: right; white-space: nowrap; font-weight: 600; }
.li .amt small { display: block; font-size: 12px; color: var(--faint); font-weight: 500; }
.av { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center;
  font-weight: 700; font-size: 14px; flex: none; }
.av.in { background: color-mix(in srgb, var(--in) 14%, transparent); color: var(--in); }
.in { color: var(--in); } .warn { color: var(--warn); } .bad { color: var(--bad); } .muted { color: var(--muted); }
.track { height: 6px; background: var(--track); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.track i { display: block; height: 100%; background: var(--fill); border-radius: 3px; }
.status { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: 1px; background: var(--in); }
.status.warn { background: var(--warn); } .status.bad { background: var(--bad); }
.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 20px 4px 8px; }
.empty { color: var(--muted); padding: 28px 16px; text-align: center; font-size: 14px; }
.note { font-size: 12px; color: var(--faint); margin: 10px 4px; }

/* activity */
.search { position: relative; margin-top: 6px; }
.search input { width: 100%; border: 0; background: var(--card); box-shadow: var(--shadow); color: var(--ink); border-radius: 12px;
  padding: 11px 14px 11px 38px; font: inherit; outline: none; -webkit-appearance: none; }
.search::before { content: "⌕"; position: absolute; left: 13px; top: 8px; font-size: 19px; color: var(--faint); }
.chips { display: flex; gap: 8px; margin: 12px 0 0; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 0; background: var(--card); box-shadow: var(--shadow); padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); }
.chips button.on { background: var(--ink); color: var(--bg); }

/* debts */
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.duo > div { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 14px 16px; }
.duo .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.duo .v { font-size: 22px; font-weight: 750; letter-spacing: -.02em; margin-top: 2px; }

/* sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet-card { background: var(--card); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
  max-height: 88vh; overflow: auto; animation: up .2s ease-out; }
.grab { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }
.sheet-card h3 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.sheet-card .amount { font-size: 30px; font-weight: 750; letter-spacing: -.02em; margin: 6px 0 2px; }
.sheet-card label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 6px; }
.sheet-card select { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; -webkit-appearance: none; }
.sheet-card .row { display: flex; gap: 10px; margin-top: 22px; }
.sheet-card .row .btn { flex: 1; }
.opt { display: flex; justify-content: space-between; align-items: center; width: 100%; border: 0; background: none; padding: 14px 4px; font-size: 16px; text-align: left; }
.opt + .opt { border-top: 1px solid var(--line); }
.opt.on::after { content: "✓"; color: var(--accent); font-weight: 700; }
.opt small { display: block; color: var(--muted); font-size: 13px; }

.btn { display: inline-block; border: 0; border-radius: 12px; padding: 13px 18px; background: var(--track); text-decoration: none; color: var(--ink); font-weight: 600; text-align: center; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.wide { display: block; width: 100%; }
.btn:disabled { opacity: .5; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 84px); background: var(--ink); color: var(--bg);
  padding: 11px 16px; border-radius: 12px; z-index: 30; font-size: 14px; white-space: pre-line; max-width: calc(100% - 32px); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { text-align: center; max-width: 340px; width: 100%; }
.login-card img { border-radius: 16px; box-shadow: var(--shadow); }
.login-card h1 { margin: 16px 0 4px; font-size: 30px; letter-spacing: -.02em; }
.login-card p { color: var(--muted); margin: 0 0 28px; }
.err { color: var(--bad) !important; margin-top: 14px !important; }
.loading { opacity: .5; transition: opacity .2s; }
