/* ---------- Tokens ---------- */
:root {
  --bg: #0a1512;
  --glow: rgba(52, 211, 153, .14);
  --card: #12251f;
  --card-2: #183029;
  --line: rgba(255, 255, 255, .07);
  --text: #eafaf3;
  --muted: #8db1a2;
  --accent: #34d399;
  --accent-ink: #04231a;
  --danger: #fb7185;
  --gold: #fbbf24;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 22px;
  --tab-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2faf6;
    --glow: rgba(16, 185, 129, .16);
    --card: #ffffff;
    --card-2: #e9f6f0;
    --line: rgba(10, 40, 30, .08);
    --text: #0d2a20;
    --muted: #5d7d6e;
    --accent: #0f9f6e;
    --accent-ink: #ffffff;
    --shadow: 0 10px 28px rgba(13, 80, 55, .10);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(520px 320px at 85% -60px, var(--glow), transparent 70%),
    radial-gradient(420px 300px at -10% 20%, var(--glow), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3, p { margin: 0; }

#app { max-width: 520px; margin: 0 auto; padding: 0 16px; }
main { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 36px); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 12px) 0 10px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  margin: 0 -16px; padding-left: 16px; padding-right: 16px;
}
.topbar.hidden { display: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 26px; line-height: 1; display: grid; place-items: center;
  transition: transform .12s, opacity .2s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn:disabled { opacity: .3; pointer-events: none; }
.month-label { font-size: 19px; font-weight: 700; padding: 8px 14px; border-radius: 14px; letter-spacing: .2px; }
.month-label small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); text-align: center; }

/* ---------- Views ---------- */
.view { display: none; }
.view.active { display: block; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.greeting { color: var(--muted); font-weight: 600; margin: 4px 2px 12px; }
.page-title { display: flex; align-items: baseline; justify-content: space-between; margin: 10px 2px 14px; }
.page-title h1 { font-size: 28px; letter-spacing: -.5px; }
.page-title span { color: var(--accent); font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- Hero ---------- */
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 22px; border-radius: 28px; color: #fff;
  background: linear-gradient(135deg, #10b981 0%, #0d9488 55%, #0e7490 100%);
  box-shadow: 0 16px 36px rgba(16, 185, 129, .28);
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -50px; top: -60px; width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255, 255, 255, .10);
}
.hero-text { position: relative; z-index: 1; min-width: 0; }
.hero-kicker { font-size: 13px; font-weight: 700; opacity: .85; text-transform: uppercase; letter-spacing: 1px; }
.hero-total { font-size: 42px; font-weight: 800; letter-spacing: -1.5px; line-height: 1.1; margin: 4px 0 2px; word-break: break-all; }
.hero-sub { font-size: 13px; opacity: .85; }
.hero-delta {
  display: inline-block; margin-top: 10px; font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, .2);
}
.hero-delta:empty { display: none; }

.ring { position: relative; width: 104px; height: 104px; flex: none; z-index: 1; }
.ring.off { display: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring-bg { stroke: rgba(255, 255, 255, .22); }
.ring-fg { stroke: #fff; stroke-linecap: round; stroke-dasharray: 289; stroke-dashoffset: 289; transition: stroke-dashoffset .9s cubic-bezier(.2, .8, .2, 1); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center b { font-size: 21px; }
.ring-center small { font-size: 10px; opacity: .85; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-top: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; letter-spacing: -.2px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }

/* ---------- Add form ---------- */
.add h2 { margin-bottom: 12px; }
.amount {
  display: flex; align-items: center; gap: 6px;
  background: var(--card-2); border: 2px solid transparent; border-radius: 18px; padding: 8px 16px;
  transition: border-color .2s, transform .2s;
}
.amount:focus-within { border-color: var(--accent); }
.amount.shake { animation: shake .35s; border-color: var(--danger); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.amount .cur { font-size: 30px; font-weight: 700; color: var(--accent); }
.amount input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none;
  font-size: 40px; font-weight: 800; letter-spacing: -1px; padding: 4px 0;
}
.amount input::placeholder { color: var(--muted); opacity: .45; }
.amount.small input { font-size: 26px; }
.amount.small .cur { font-size: 22px; }

.chips { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.chips button {
  padding: 9px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  background: var(--card-2); color: var(--accent); border: 1px solid var(--line);
  transition: transform .1s, background .2s;
}
.chips button:active { transform: scale(.93); }
.chips.big button { color: var(--text); font-size: 18px; padding: 10px 20px; }
.chips.big button.on { background: var(--accent); color: var(--accent-ink); }

.cat-label { margin: 18px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 2px; border-radius: 16px; background: var(--card-2);
  border: 2px solid transparent; font-size: 11px; font-weight: 700; color: var(--muted);
  transition: transform .12s, border-color .2s, color .2s;
}
.cat i { font-style: normal; font-size: 24px; }
.cat:active { transform: scale(.94); }
.cat.on { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 14%, var(--card-2)); }

.note {
  width: 100%; margin-top: 14px; padding: 13px 16px; border-radius: 14px; outline: 0;
  background: var(--card-2); border: 2px solid transparent; font-size: 15px;
}
.note:focus { border-color: var(--accent); }
.note::placeholder { color: var(--muted); }

.date-row { display: flex; gap: 8px; margin-top: 12px; }
.pill {
  padding: 10px 14px; border-radius: 999px; font-size: 14px; font-weight: 700;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
}
.pill.on { background: var(--text); color: var(--bg); }
input.pill { flex: 1; min-width: 0; text-align: center; color: var(--text); font-weight: 600; font-size: 14px; }
input.pill.on { background: var(--text); color: var(--bg); }

.primary {
  width: 100%; margin-top: 18px; padding: 17px; border-radius: 18px;
  background: linear-gradient(135deg, #34d399, #10b981); color: #04231a;
  font-size: 17px; font-weight: 800; letter-spacing: .2px;
  box-shadow: 0 10px 24px rgba(16, 185, 129, .35);
  transition: transform .12s, box-shadow .2s;
}
.primary:active { transform: scale(.97); box-shadow: 0 4px 12px rgba(16, 185, 129, .3); }
.primary.pop { animation: pop .5s; }
@keyframes pop { 40% { transform: scale(1.04); } }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 12px; box-shadow: var(--shadow); }
.stat .ico { font-size: 20px; }
.stat b { display: block; font-size: 18px; margin-top: 6px; letter-spacing: -.4px; overflow-wrap: anywhere; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 26px 2px 10px; }
.section-head h3 { font-size: 18px; }
.link { color: var(--accent); font-weight: 700; font-size: 14px; padding: 6px; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  animation: rise .3s ease both;
}
.row .bubble { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; background: var(--card-2); flex: none; }
.row .meta { flex: 1; min-width: 0; }
.row .meta b { display: block; font-size: 15px; }
.row .meta span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 800; color: var(--accent); font-size: 16px; white-space: nowrap; }
.row .del { width: 34px; height: 34px; border-radius: 50%; color: var(--muted); font-size: 18px; flex: none; }
.row .del:active { background: var(--card-2); color: var(--danger); }

.day-head { display: flex; justify-content: space-between; margin: 18px 4px 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.day-head b { color: var(--text); }
.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty .big { font-size: 46px; margin-bottom: 8px; }
.empty p { font-size: 14px; line-height: 1.5; }

/* ---------- Charts ---------- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; }
.bars .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.bars .bar {
  width: 100%; border-radius: 6px 6px 3px 3px; min-height: 3px;
  background: color-mix(in srgb, var(--accent) 55%, var(--card-2));
  transform-origin: bottom; animation: grow .6s cubic-bezier(.2, .8, .2, 1) both;
}
.bars .col.zero .bar { background: var(--card-2); }
.bars .col.on .bar, .bars .col.today .bar { background: var(--accent); }
.bars .col.on .bar { box-shadow: 0 0 0 2px var(--text) inset; }
@keyframes grow { from { transform: scaleY(0); } }
.bars .lbl { font-size: 9px; color: var(--muted); margin-top: 6px; height: 12px; white-space: nowrap; }
.bars.year { gap: 6px; }
.bars.year .lbl { font-size: 11px; }
.bars .col { cursor: pointer; }

.cat-row { margin-bottom: 14px; }
.cat-row:last-child { margin-bottom: 0; }
.cat-row .top { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.cat-row .top span:last-child { color: var(--muted); font-weight: 600; }
.track { height: 10px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #34d399, #14b8a6); animation: fill .7s cubic-bezier(.2, .8, .2, 1) both; transform-origin: left; }
@keyframes fill { from { transform: scaleX(0); } }

/* ---------- Settings ---------- */
.card p.muted { margin: 4px 0 12px; }
.card h2 + .chips { margin-top: 12px; }
.btn-row { display: flex; gap: 10px; margin-bottom: 12px; }
.ghost { flex: 1; padding: 13px; border-radius: 14px; background: var(--card-2); font-weight: 700; border: 1px solid var(--line); }
.ghost:active { transform: scale(.97); }
.danger { width: 100%; padding: 13px; border-radius: 14px; color: var(--danger); font-weight: 700; border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.about { text-align: center; }
.about-logo { border-radius: 18px; box-shadow: 0 8px 20px rgba(16, 185, 129, .3); margin-bottom: 12px; }
.about-name { font-size: 20px; font-weight: 800; letter-spacing: -.3px; margin: 4px 0 10px; color: var(--accent); }
.about p.muted { line-height: 1.55; margin: 0 0 8px; }
.about-ver { margin-top: 12px; font-size: 12px; color: var(--muted); opacity: .7; }
.foot { text-align: center; color: var(--muted); font-size: 13px; margin: 26px 0 0; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 30;
  width: min(520px, 100%); height: calc(var(--tab-h) + var(--safe-b)); padding: 8px 10px var(--safe-b);
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line); border-radius: 24px 24px 0 0;
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 700; transition: color .2s; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.tabbar button.active { color: var(--accent); }
.tabbar button.active svg { transform: translateY(-2px) scale(1.1); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 40;
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  padding: 13px 18px; border-radius: 16px; font-weight: 700; font-size: 14px; white-space: nowrap;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .3s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast button { color: var(--accent); font-weight: 800; filter: brightness(.8); }

/* ---------- Confetti ---------- */
.confetti { position: fixed; z-index: 50; width: 8px; height: 8px; border-radius: 2px; pointer-events: none; animation: fly 900ms cubic-bezier(.1, .8, .3, 1) forwards; }
@keyframes fly { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (min-width: 560px) { body { padding-top: 12px; } }
