:root {
  --bg: #f3f3f1;
  --surface: #ffffff;
  --surface-2: #ecece9;
  --text: #111111;
  --muted: #82827d;
  --line: #e5e5e1;
  --ink: #111111;
  --on-ink: #ffffff;
  --on-ink-muted: #a6a6a2;
  --on-ink-soft: rgba(255, 255, 255, 0.09);
  --radius: 18px;
  --tabs-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0d0d0d;
  --surface: #191919;
  --surface-2: #262626;
  --text: #f1f1ef;
  --muted: #8d8d89;
  --line: #2b2b2b;
  --ink: #f1f1ef;
  --on-ink: #111111;
  --on-ink-muted: #6b6b68;
  --on-ink-soft: rgba(0, 0, 0, 0.07);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.3 -apple-system, BlinkMacSystemFont, 'SF Pro Text', Roboto, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  -webkit-user-select: none; user-select: none;
}
button, input { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
input { -webkit-user-select: text; user-select: text; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ic { display: block; width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.view { max-width: 520px; margin: 0 auto; padding: 14px 16px calc(var(--tabs-h) + var(--safe-b) + 28px); }
.page-title { font-size: 13px; font-weight: 600; color: var(--muted); padding: 4px 4px 12px; }
.page-h { font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; padding: 4px 4px 14px; }
.section-head { display: flex; align-items: center; justify-content: space-between; min-height: 24px; padding: 24px 4px 10px; }
.section-head h3 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.section-head .aside { font-size: 13px; color: var(--muted); }
.link { color: var(--muted); font-size: 14px; padding: 4px 0 4px 12px; }
.card { background: var(--surface); border-radius: var(--radius); }

/* Balance */
.balance { background: var(--ink); color: var(--on-ink); border-radius: 24px; padding: 20px 14px 14px; }
.balance .label { font-size: 13px; color: var(--on-ink-muted); padding: 0 6px; }
.balance .total { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 36px; line-height: 1.1; font-weight: 700; letter-spacing: -0.03em; padding: 6px 6px 0; }
.balance .total small { font-size: 17px; font-weight: 500; letter-spacing: 0; color: var(--on-ink-muted); }
.wallets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 18px; }
.wallet { display: block; text-align: left; padding: 11px 12px 12px; border-radius: 14px; background: var(--on-ink-soft); color: inherit; min-width: 0; transition: transform 0.15s var(--ease); }
.wallet:active { transform: scale(0.97); }
.wallet .w-name { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 16px; color: var(--on-ink-muted); }
.wallet .w-name .ic { width: 16px; height: 16px; }
.wallet .w-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wallet .w-sum { display: block; font-size: 16px; font-weight: 600; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { padding: 14px; min-width: 0; }
.tile .label { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 16px; color: var(--muted); }
.tile .label .ic { width: 16px; height: 16px; }
.tile .sum { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; margin-top: 8px; overflow-wrap: anywhere; }
.tile.wide { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tile.wide .sum { margin: 0; }

/* Rows */
.list { overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 62px; padding: 10px 14px; text-align: left; transition: background 0.15s; }
.row + .row { box-shadow: inset 0 1px 0 var(--line); }
.row:active { background: var(--surface-2); }
.badge { width: 40px; height: 40px; border-radius: 13px; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.row .body { flex: 1; min-width: 0; display: block; }
.row .title { display: block; font-weight: 500; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .desc { display: block; font-size: 13px; line-height: 17px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row .amt { font-weight: 600; white-space: nowrap; text-align: right; flex: none; }
.row .amt.neutral { color: var(--muted); font-weight: 500; }
.row .chev { color: var(--muted); flex: none; }
.row .chev .ic { width: 18px; height: 18px; }
.row.dim { opacity: 0.45; }
.day-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); padding: 18px 4px 8px; }

.empty { text-align: center; padding: 34px 22px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 52px; padding: 0 22px; border-radius: 16px; font-weight: 600; background: var(--surface-2); transition: transform 0.15s var(--ease), opacity 0.15s; }
.btn.primary { background: var(--ink); color: var(--on-ink); }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: none; color: var(--muted); font-weight: 500; height: 44px; }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.seg { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 14px; padding: 3px; }
.seg::before { content: ''; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / var(--n)); border-radius: 11px; background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); transform: translateX(calc(var(--i) * 100%)); transition: transform 0.3s var(--ease); }
:root[data-theme='dark'] .seg::before { background: #3b3b3b; box-shadow: none; }
.seg button { position: relative; height: 38px; font-size: 14px; font-weight: 500; color: var(--muted); transition: color 0.2s; }
.seg button.on { color: var(--text); font-weight: 600; }

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 19px; background: var(--surface); font-size: 14px; line-height: 1; font-weight: 500; white-space: nowrap; transition: transform 0.15s var(--ease), background 0.2s, color 0.2s; }
.chip:active { transform: scale(0.95); }
.chip .ic { width: 16px; height: 16px; }
.chip.on { background: var(--ink); color: var(--on-ink); }
.sheet .chip { background: var(--surface-2); }
.sheet .chip.on { background: var(--ink); }

.period { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.period .arrow { width: 44px; height: 44px; border-radius: 14px; background: var(--surface); display: grid; place-items: center; flex: none; transition: transform 0.15s var(--ease); }
.period .arrow:active { transform: scale(0.92); }
.period .arrow[disabled] { opacity: 0.3; }
.period .label { flex: 1; min-width: 0; height: 44px; border-radius: 14px; background: var(--surface); font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px; }
.period .label .ic { width: 16px; height: 16px; color: var(--muted); }

.search { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px; border-radius: 14px; background: var(--surface); margin-bottom: 10px; color: var(--muted); }
.search .ic { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font-size: 16px; padding: 0; -webkit-appearance: none; appearance: none; }
.search input::-webkit-search-cancel-button { display: none; }

/* Stats */
.chart { padding: 16px 14px 12px; margin-top: 8px; }
.chart .cap { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 112px; }
.bar { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; }
.bar i { display: block; width: 100%; min-height: 2px; background: var(--ink); border-radius: 3px 3px 1px 1px; transform-origin: bottom; animation: grow 0.55s var(--ease) both; animation-delay: calc(var(--i) * 12ms); transition: opacity 0.2s; }
.bar.zero i { background: var(--line); }
.bars.picked .bar:not(.on) i { opacity: 0.25; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 8px; }
.cat-row .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cat-row .top .title { flex: 1; min-width: 0; }
.cat-row .pct { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: 6px; }
.cat-row .meter { display: block; height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 7px; overflow: hidden; }
.cat-row .meter i { display: block; height: 100%; background: var(--ink); border-radius: 2px; transform-origin: left; animation: widen 0.6s var(--ease) both; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: var(--tabs-h); font-size: 11px; line-height: 13px; font-weight: 500; color: var(--muted); transition: color 0.2s; }
.tab .ic { width: 22px; height: 22px; transition: transform 0.2s var(--ease); }
.tab:active .ic { transform: scale(0.88); }
.tab.on { color: var(--text); }
.tab.pop .ic { animation: pop 0.34s var(--ease); }
.tab-add { justify-self: center; width: 50px; height: 50px; border-radius: 17px; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; transition: transform 0.18s var(--ease); }
.tab-add .ic { width: 24px; height: 24px; stroke-width: 2.2; transition: transform 0.3s var(--ease); }
.tab-add:active { transform: scale(0.9); }
.tab-add:active .ic { transform: rotate(90deg); }

/* Sheet */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.46); animation: fade 0.22s ease-out both; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 520px; margin: 0 auto; max-height: 94%;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 26px 26px 0 0;
  animation: rise 0.34s var(--ease) both;
}
.sheet.tall { height: 94%; }
.closing .backdrop { animation: fade-out 0.2s ease-in both; }
.closing .sheet { animation: sink 0.22s ease-in both; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px; flex: none; }
.sheet-head h2 { font-size: 19px; line-height: 34px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-head .close { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; transition: transform 0.15s var(--ease); }
.sheet-head .close:active { transform: scale(0.88); }
.sheet-head .close .ic { width: 17px; height: 17px; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 18px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet h3 { font-size: 13px; line-height: 16px; font-weight: 500; color: var(--muted); margin: 20px 2px 9px; }
.sheet-foot { flex: none; display: grid; gap: 2px; padding: 10px 16px calc(12px + var(--safe-b)); box-shadow: inset 0 1px 0 var(--line); overflow: hidden; max-height: 180px; transition: max-height 0.3s var(--ease), padding 0.3s var(--ease), opacity 0.2s; }
.kp-open .sheet-foot { max-height: 0; padding-top: 0; padding-bottom: 0; opacity: 0; }

/* Composer */
.amount { display: flex; align-items: baseline; justify-content: center; gap: 8px; width: 100%; padding: 26px 0 22px; }
.amount .digits { font-size: 46px; line-height: 1; font-weight: 700; letter-spacing: -0.035em; font-variant-numeric: tabular-nums; }
.amount.long .digits { font-size: 34px; }
.amount.empty .digits { color: var(--muted); opacity: 0.45; }
.amount .cur { font-size: 18px; font-weight: 500; color: var(--muted); }
.amount .caret { align-self: center; width: 2px; height: 38px; margin-left: -4px; border-radius: 1px; background: var(--text); opacity: 0; }
.kp-open .amount .caret { animation: blink 1.1s steps(1) infinite; }

.keypad { flex: none; overflow: hidden; max-height: 0; opacity: 0; padding: 0 12px; transition: max-height 0.32s var(--ease), opacity 0.2s, padding 0.32s var(--ease); }
.kp-open .keypad { max-height: 360px; opacity: 1; padding: 6px 12px calc(12px + var(--safe-b)); }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.key { height: 52px; border-radius: 15px; background: var(--surface-2); font-size: 22px; font-weight: 500; display: grid; place-items: center; font-variant-numeric: tabular-nums; transition: transform 0.1s, background 0.15s; }
.key:active { transform: scale(0.94); background: var(--line); }
.key.small { font-size: 18px; }
.key.plain { background: none; }
.key .ic { width: 24px; height: 24px; }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 4px; }
.cell { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 0; min-width: 0; color: var(--muted); }
.cell .badge { width: 52px; height: 52px; border-radius: 18px; color: var(--text); transition: background 0.2s, color 0.2s, transform 0.15s var(--ease); }
.cell .badge .ic { width: 22px; height: 22px; }
.cell:active .badge { transform: scale(0.92); }
.cell .name { display: block; width: 100%; font-size: 12px; line-height: 15px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.cell.on { color: var(--text); font-weight: 600; }
.cell.on .badge { background: var(--ink); color: var(--on-ink); animation: pop 0.3s var(--ease); }
.grid.icons { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px 4px; }
.grid.icons .badge { width: 46px; height: 46px; border-radius: 15px; }

.field { display: block; width: 100%; height: 50px; padding: 0 14px; border-radius: 14px; border: 0; outline: 0; background: var(--surface-2); font-size: 16px; box-shadow: inset 0 0 0 0 var(--ink); transition: box-shadow 0.2s; -webkit-appearance: none; appearance: none; }
.field:focus { box-shadow: inset 0 0 0 1.5px var(--ink); }
.field::placeholder { color: var(--muted); }
.date-row { display: flex; gap: 6px; align-items: center; }
.date-row .chip { height: 44px; border-radius: 14px; }
.date-row .field { flex: 1; min-width: 0; height: 44px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.money-field { display: flex; align-items: center; gap: 8px; height: 50px; padding: 0 14px; border-radius: 14px; background: var(--surface-2); }
.money-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.money-field span { color: var(--muted); }

.menu { margin: 0 -14px; }
.menu .row { justify-content: space-between; min-height: 52px; }

.toast { position: fixed; left: 16px; right: 16px; top: 12px; z-index: 40; margin: 0 auto; max-width: 420px; padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--on-ink); font-size: 14px; font-weight: 500; text-align: center; opacity: 0; transform: translateY(-12px) scale(0.96); pointer-events: none; transition: opacity 0.22s, transform 0.3s var(--ease); }
.toast.show { opacity: 1; transform: none; }

.splash { min-height: 76vh; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.splash b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.splash .btn { margin-top: 18px; }
.splash .dots { display: inline-flex; gap: 5px; margin-top: 14px; }
.splash .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink-soft 1s ease-in-out infinite; }
.splash .dots i:nth-child(2) { animation-delay: 0.15s; }
.splash .dots i:nth-child(3) { animation-delay: 0.3s; }

/* Entrance */
.view.enter > * { animation: rise-in 0.36s var(--ease) both; }
.view.enter > :nth-child(2) { animation-delay: 30ms; }
.view.enter > :nth-child(3) { animation-delay: 60ms; }
.view.enter > :nth-child(4) { animation-delay: 90ms; }
.view.enter > :nth-child(5) { animation-delay: 120ms; }
.view.enter > :nth-child(n + 6) { animation-delay: 150ms; }
.fresh { animation: rise-in 0.3s var(--ease) both; }

@keyframes fade { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }
@keyframes sink { to { transform: translateY(100%); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes grow { from { transform: scaleY(0); } }
@keyframes widen { from { transform: scaleX(0); } }
@keyframes pop { 0% { transform: scale(0.86); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }
@keyframes blink-soft { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0s !important; transition-duration: 0.01ms !important; }
}
