:root {
  --bg: #f4f6f5; --card: #fff; --text: #1c2421; --muted: #6b7772; --line: #dfe5e2;
  --main: #1f7a5c; --main-soft: #e2f1eb; --income: #2563eb; --danger: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121614; --card: #1c2220; --text: #e8eeeb; --muted: #94a09b; --line: #2c3532; --main: #3fae88; --main-soft: #1d3a30; --income: #6ea0ff; --danger: #ef6b5b; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif; }
body { touch-action: manipulation; }
#view { max-width: 480px; margin: 0 auto; padding: 0 12px calc(24px + env(safe-area-inset-bottom)); padding-top: env(safe-area-inset-top); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, select { font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); width: 100%; min-width: 0; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 52px; }
.bar .ledger { font-weight: 600; padding: 8px 10px; border-radius: 10px; background: var(--card); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .total { text-align: center; line-height: 1.2; flex: 1; }
.bar .total small { color: var(--muted); font-size: 12px; display: block; }
.bar .total b { font-size: 17px; }
.bar .gear { font-size: 22px; padding: 6px 8px; text-decoration: none; }
.bar .back { color: var(--main); text-decoration: none; font-weight: 600; padding: 8px 4px; }
.offline { background: #b7791f; color: #fff; text-align: center; font-size: 13px; padding: 4px; border-radius: 8px; margin-bottom: 6px; }

.amtrow { display: flex; align-items: center; gap: 10px; padding: 4px 4px 8px; }
.amt { flex: 1; font-size: 44px; font-weight: 700; text-align: right; overflow: hidden; white-space: nowrap; }
.amt.zero { color: var(--muted); }
.amt.income { color: var(--income); }
.kind { display: flex; background: var(--card); border-radius: 10px; padding: 3px; flex: none; }
.kind button { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.kind button.on { background: var(--main); color: #fff; font-weight: 600; }
.kind button.on[data-kind="income"] { background: var(--income); }

.cats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.chip { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0 5px; border-radius: 10px; background: var(--card); border: 2px solid transparent; font-size: 20px; min-width: 0; }
.chip span { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; white-space: nowrap; }
.chip.on { border-color: var(--main); background: var(--main-soft); }
.chip.on span { color: var(--text); font-weight: 600; }

.noterow { margin: 8px 0 0; }
.sug { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.sug button { padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.pad button { height: 52px; border-radius: 12px; background: var(--card); font-size: 22px; font-weight: 500; }
.pad button:active { background: var(--line); }
.primary { width: 100%; height: 54px; margin-top: 8px; border-radius: 12px; background: var(--main); color: #fff; font-size: 18px; font-weight: 700; }
.primary:disabled { opacity: .4; }
.primary.income { background: var(--income); }

h3 { margin: 18px 4px 6px; font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:last-child { border-bottom: 0; }
.list .em { font-size: 22px; width: 28px; text-align: center; flex: none; }
.list .mid { flex: 1; min-width: 0; }
.list .mid div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .mid small { color: var(--muted); }
.list .num { font-weight: 600; flex: none; }
.list .num.income { color: var(--income); }
.empty { color: var(--muted); text-align: center; padding: 18px; font-size: 14px; }

dialog { border: 0; border-radius: 16px; padding: 16px; width: min(92vw, 420px); background: var(--bg); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.btns { display: flex; gap: 8px; margin-top: 14px; }
.btn { flex: 1; height: 44px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-weight: 600; padding: 0 12px; }
.btn.main { background: var(--main); color: #fff; border-color: var(--main); }
.btn.danger { color: var(--danger); flex: none; }
.btn.small { height: 36px; flex: none; font-size: 14px; font-weight: 500; }
.pick button { display: block; width: 100%; text-align: left; padding: 12px; border-radius: 10px; background: var(--card); margin-bottom: 6px; }
.pick button.on { outline: 2px solid var(--main); font-weight: 600; }
.pick small { color: var(--muted); margin-left: 6px; }

.atabs { display: flex; gap: 4px; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.atabs a { flex: 1; text-align: center; padding: 8px 0; border-radius: 9px; text-decoration: none; color: var(--muted); font-size: 14px; }
.atabs a.on { background: var(--main); color: #fff; font-weight: 600; }
.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.monthnav button { font-size: 22px; padding: 4px 16px; color: var(--main); }
.sum3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 4px; }
.sum3 div { background: var(--card); border-radius: 12px; padding: 10px; text-align: center; }
.sum3 small { display: block; color: var(--muted); font-size: 12px; }
.card { background: var(--card); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.card h4 { margin: 0 0 10px; font-size: 15px; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.row .emo { width: 52px; flex: none; text-align: center; padding: 10px 4px; }
.row .mini { flex: none; width: 36px; height: 40px; border-radius: 8px; background: var(--bg); }
.row .mini:disabled { opacity: .3; }
.row.arch input { opacity: .5; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.tag { font-size: 12px; color: var(--muted); flex: none; }

.login { padding-top: 18vh; text-align: center; }
.login h1 { font-size: 24px; margin: 0 0 6px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.toast { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 99; white-space: nowrap; }

details summary { color: var(--main); font-weight: 600; cursor: pointer; }
.steps { padding-left: 20px; margin: 10px 0; font-size: 14px; line-height: 1.7; }
.steps li { margin-bottom: 6px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 13px; word-break: break-all; }

.statbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.statbar .monthnav { flex: 1; margin: 0; }
.hero { text-align: center; display: grid; gap: 2px; }
.hero small, .hero span { color: var(--muted); font-size: 13px; }
.hero b { font-size: 34px; }
.bar-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 14px; }
.bar-name { width: 84px; flex: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bar-name.wide { width: auto; flex: 1; }
.bar-track { flex: 1; height: 12px; }
.bar-track i { display: block; height: 100%; background: var(--main); border-radius: 0 4px 4px 0; }
.bar-val { flex: none; text-align: right; font-weight: 600; min-width: 76px; }
.bar-val small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.cols { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; height: 170px; }
.col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; padding: 0; }
.col small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.col i { width: 60%; max-width: 28px; background: var(--main); opacity: .4; border-radius: 4px 4px 0 0; }
.col span { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); width: 100%; padding-top: 4px; }
.col.on i { opacity: 1; }
.col.on small, .col.on span { color: var(--text); font-weight: 600; }
.list.flat { background: none; }
.list.flat li { padding: 8px 0; }
.atabs a { font-size: 13px; }
