:root {
  --bg: #f2f3f7; --card: #fff; --ink: #14151a; --ink2: #6b6f76; --ink3: #9aa0a8; --line: #e9eaef; --line2: #f1f2f6;
  --accent: #3461ff; --accent-soft: #e9edff; --thu: #12a150; --thu-soft: #e4f6ec; --chi: #e5484d; --chi-soft: #fdecec;
  --g-thu1: #1db954; --g-thu2: #0f9b6c; --g-chi1: #ff5a5f; --g-chi2: #e0383e; --g-acc1: #4a6bff; --g-acc2: #3461ff;
  --radius: 18px; --shadow: 0 1px 2px rgba(20,21,26,.04), 0 8px 24px rgba(20,21,26,.06);
  --shadow-s: 0 1px 2px rgba(20,21,26,.05), 0 2px 8px rgba(20,21,26,.05);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0b0b0d; --card: #16171b; --ink: #f3f4f6; --ink2: #9aa0a8; --ink3: #71767e; --line: #26272d; --line2: #1d1e23;
  --accent: #6b8afd; --accent-soft: #1a2345; --thu: #34d17e; --thu-soft: #0f2a1b; --chi: #ff6b70; --chi-soft: #341416;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.5); --shadow-s: 0 1px 3px rgba(0,0,0,.4);
} }
:root[data-theme="dark"] {
  --bg: #0b0b0d; --card: #16171b; --ink: #f3f4f6; --ink2: #9aa0a8; --ink3: #71767e; --line: #26272d; --line2: #1d1e23;
  --accent: #6b8afd; --accent-soft: #1a2345; --thu: #34d17e; --thu-soft: #0f2a1b; --chi: #ff6b70; --chi-soft: #341416;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.5); --shadow-s: 0 1px 3px rgba(0,0,0,.4);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; -webkit-font-smoothing: antialiased; letter-spacing: -.005em; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.thu { color: var(--thu); } .chi { color: var(--chi); } .muted { color: var(--ink2); }
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(104px + env(safe-area-inset-bottom)); }

/* header */
.top { position: sticky; top: 0; z-index: 10; margin: 0 -16px 14px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); }
.toprow { display: flex; align-items: center; gap: 10px; }
.toprow h1 { font-size: 22px; margin: 0; flex: 1; font-weight: 700; letter-spacing: -.02em; }
.iconbtn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--card); color: var(--ink2); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-s); flex: none; transition: transform .12s; }
.iconbtn:active { transform: scale(.92); }
.seg { display: flex; background: var(--card); border-radius: 13px; padding: 4px; margin-top: 12px; box-shadow: var(--shadow-s); }
.seg button { flex: 1; border: 0; background: none; padding: 9px 0; border-radius: 10px; font-weight: 600; color: var(--ink2); cursor: pointer; font-size: 15px; transition: color .15s; }
.seg button.on { background: var(--accent); color: #fff; box-shadow: 0 3px 8px color-mix(in srgb, var(--accent) 40%, transparent); }
.nav { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; gap: 8px; }
.nav button { width: 42px; height: 38px; border: 0; background: var(--card); border-radius: 11px; color: var(--ink); font-size: 18px; cursor: pointer; box-shadow: var(--shadow-s); transition: transform .12s; }
.nav button:active { transform: scale(.92); }
.nav .lbl { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }

/* hero */
.hero { border-radius: 22px; padding: 22px 20px; margin-bottom: 16px; color: #fff; position: relative; overflow: hidden; box-shadow: 0 10px 30px rgba(20,21,26,.14); }
.hero.pos { background: linear-gradient(140deg, var(--g-thu1), var(--g-thu2)); }
.hero.neg { background: linear-gradient(140deg, var(--g-chi1), var(--g-chi2)); }
.hero.zero { background: linear-gradient(140deg, var(--g-acc1), var(--g-acc2)); }
.hero .lab { font-size: 13px; opacity: .85; font-weight: 500; }
.hero .net { font-size: 42px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; margin: 3px 0 2px; white-space: nowrap; }
.hero .delta { font-size: 13px; opacity: .92; font-weight: 600; }
.hero .tc { display: flex; gap: 10px; margin-top: 18px; }
.hero .tc > div { flex: 1; background: rgba(255,255,255,.16); border-radius: 14px; padding: 11px 12px; backdrop-filter: blur(4px); }
.hero .tc small { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 5px; }
.hero .tc small i { width: 7px; height: 7px; border-radius: 50%; background: #fff; display: inline-block; }
.hero .tc .n { font-size: 18px; font-weight: 700; margin-top: 3px; white-space: nowrap; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.chart { width: 100%; height: 160px; display: block; overflow: visible; }
.legend { display: flex; gap: 16px; justify-content: center; font-size: 12px; color: var(--ink2); margin-top: 10px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
h2.sec { font-size: 13px; color: var(--ink2); margin: 20px 4px 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }

.catrow { display: flex; align-items: center; gap: 11px; padding: 9px 0; }
.catrow + .catrow { border-top: 1px solid var(--line2); }
.catrow .cdot { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }
.catrow .nm { flex: 1; min-width: 0; }
.catrow .nm b { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catrow .nm .bar { height: 6px; background: var(--line2); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.catrow .nm .bar > i { display: block; height: 100%; border-radius: 3px; }
.catrow .amt { text-align: right; flex: none; }
.catrow .amt b { font-size: 14px; font-weight: 700; white-space: nowrap; }
.catrow .amt small { display: block; font-size: 11px; color: var(--ink2); }

.daygrp { margin-bottom: 4px; }
.dayhd { font-size: 12px; color: var(--ink2); padding: 12px 4px 6px; display: flex; justify-content: space-between; font-weight: 600; }
.tx { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow-s); cursor: pointer; transition: transform .1s; }
.tx:active { transform: scale(.99); }
.tx .cdot { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; }
.tx .mid { flex: 1; min-width: 0; }
.tx .mid b { font-weight: 600; font-size: 15px; }
.tx .mid small { display: block; color: var(--ink2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .val { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 15px; }
.empty { text-align: center; color: var(--ink2); padding: 40px 16px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.fab { position: fixed; right: 18px; bottom: calc(22px + env(safe-area-inset-bottom)); width: 62px; height: 62px; border-radius: 20px; border: 0; background: linear-gradient(140deg, var(--g-acc1), var(--g-acc2)); color: #fff; font-size: 32px; line-height: 1; box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 50%, transparent); cursor: pointer; z-index: 20; transition: transform .12s; }
.fab:active { transform: scale(.9); }

/* bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--card); width: 100%; max-width: 640px; border-radius: 26px 26px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: up .24s cubic-bezier(.2,.8,.2,1); }
@media (min-width: 560px) { .sheet-bg { align-items: center; } .sheet { border-radius: 24px; } }
@keyframes up { from { transform: translateY(40px); } }
.sheet h2 { margin: 2px 0 16px; font-size: 20px; text-align: center; font-weight: 700; }
.tt { display: flex; background: var(--line2); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.tt button { flex: 1; border: 0; background: none; padding: 11px 0; border-radius: 11px; font-weight: 700; font-size: 16px; color: var(--ink2); cursor: pointer; transition: all .15s; }
.tt button.on.thu { background: var(--thu); color: #fff; box-shadow: 0 3px 8px color-mix(in srgb, var(--thu) 40%, transparent); }
.tt button.on.chi { background: var(--chi); color: #fff; box-shadow: 0 3px 8px color-mix(in srgb, var(--chi) 40%, transparent); }
.amtin { width: 100%; border: 0; background: var(--line2); border-radius: 16px; padding: 16px; font-size: 32px; font-weight: 800; text-align: center; outline: none; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.amtin:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
.field { margin-top: 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink2); margin: 0 0 7px 2px; font-weight: 500; }
.input { width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 13px; background: var(--card); padding: 0 12px; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 980px; padding: 9px 15px; font-size: 15px; cursor: pointer; display: flex; align-items: center; gap: 7px; transition: all .12s; }
.chip .cd { width: 10px; height: 10px; border-radius: 50%; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.add { color: var(--accent); border-style: dashed; }
.btn { width: 100%; height: 52px; border: 0; border-radius: 15px; background: var(--accent); color: #fff; font-weight: 700; font-size: 17px; cursor: pointer; margin-top: 18px; transition: transform .1s, filter .15s; }
.btn:hover { filter: brightness(1.05); } .btn:active { transform: scale(.99); } .btn:disabled { opacity: .5; }
.btn.light { background: var(--line2); color: var(--ink); }
.btn.danger { background: var(--chi-soft); color: var(--chi); }
.row2 { display: flex; gap: 10px; } .row2 > * { flex: 1; }
.err { color: var(--chi); font-size: 14px; text-align: center; min-height: 18px; margin-top: 8px; }
.manage-item { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line2); }
.manage-item:first-child { border-top: 0; }
.manage-item .cd { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.manage-item .nm { flex: 1; }
.manage-item button { border: 0; background: none; color: var(--ink2); cursor: pointer; font-size: 14px; padding: 4px 6px; }
.manage-item button[data-del] { color: var(--chi); }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; opacity: 0; pointer-events: none; transition: all .22s; z-index: 60; max-width: 90vw; text-align: center; font-weight: 500; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--chi); color: #fff; }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-bg, .fab, .tx, .btn { animation: none; transition: none; } }
