:root {
  --bg: #0b0f0d;
  --surface: #151b18;
  --surface-2: #1e2622;
  --line: #2a332e;
  --text: #f2f5f3;
  --muted: #9aa7a0;
  --accent: #33cc66;
  --neg: #ff5a52;
  --spending: #fac738;
  --funds: #5c9ef2;
  --piggy: #4ccc78;
  --settings: #ab85f2;
  --on-tile: #0b0f0d;
  --radius: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f5; --surface: #ffffff; --surface-2: #eceeed; --line: #d9dedb;
    --text: #111614; --muted: #5d6b64; --neg: #d1241b; --accent: #1f9e4c;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
#app {
  max-width: 560px; margin: 0 auto; min-height: 100vh;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
button { font: inherit; color: inherit; }
.pad { padding: 16px; }

/* Money: monospaced digits everywhere a figure appears */
.money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; white-space: nowrap; }
.neg { color: var(--neg); }
.reached { color: var(--accent); }

/* Header */
.bar { display: flex; align-items: center; gap: 8px; min-height: 48px; margin-bottom: 8px; }
.bar h1 { flex: 1; font-size: 15px; letter-spacing: .08em; margin: 0; text-align: center; color: var(--muted); font-weight: 600; }
.bar .side { width: 64px; display: flex; }
.bar .side.right { justify-content: flex-end; }
.iconbtn { background: var(--surface); border: 0; border-radius: 999px; min-width: 44px; height: 44px; padding: 0 14px; font-size: 20px; cursor: pointer; }

/* Landing tiles */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  border: 0; border-radius: var(--radius); padding: 16px; min-height: 132px; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between; color: var(--on-tile);
}
.tile .t { font-size: 13px; font-weight: 700; letter-spacing: .08em; opacity: .85; }
.tile .v { font-size: 26px; font-weight: 700; }
.tile.spending { background: var(--spending); }
.tile.funds { background: var(--funds); }
.tile.piggy { background: var(--piggy); }
.tile.settings { background: var(--settings); }
.tile .v.neg { color: #7a0d07; }
.caption { color: var(--muted); font-size: 13px; letter-spacing: .04em; }
.center { text-align: center; }
.mt { margin-top: 16px; }

/* Envelope tiles on a section page */
.list { display: flex; flex-direction: column; gap: 10px; }
.env {
  background: var(--surface); border: 0; border-radius: var(--radius); padding: 14px 16px; text-align: left;
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; cursor: pointer; width: 100%;
  border-left: 5px solid var(--kind-color, var(--line));
}
.env .name { font-weight: 600; overflow-wrap: anywhere; }
.env .bal { font-size: 22px; font-weight: 700; grid-row: span 2; }
.env .sub { color: var(--muted); font-size: 13px; }
.kind-SPENDING { --kind-color: var(--spending); }
.kind-FUND { --kind-color: var(--funds); }
.kind-BOOSTER { --kind-color: var(--piggy); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; grid-column: 1 / -1; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--funds); }
.progress.done > i { background: var(--accent); }

/* Big balance header on a detail page */
.hero { text-align: center; padding: 8px 0 18px; }
.hero .label { color: var(--muted); font-size: 13px; letter-spacing: .08em; font-weight: 600; }
.hero .amount { font-size: 44px; font-weight: 700; line-height: 1.1; margin-top: 4px; }

/* Rows */
.rows { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.rows + .rows { margin-top: 14px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%; border: 0; background: none;
  text-align: left; border-top: 1px solid var(--line); min-height: 52px;
}
.row:first-child { border-top: 0; }
button.row { cursor: pointer; }
button.row:active { background: var(--surface-2); }
.row .k { color: var(--muted); font-size: 13px; letter-spacing: .06em; font-weight: 600; flex: 1; }
.row .val { text-align: right; overflow-wrap: anywhere; }
.row.chev::after { content: "›"; color: var(--muted); font-size: 22px; margin-left: 4px; }
.row.danger .k, .row.danger .val { color: var(--neg); }
.row.sel .val::after { content: " ✓"; color: var(--accent); }

/* Action buttons */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.actions.one { grid-template-columns: 1fr; }
.btn {
  border: 0; border-radius: 14px; padding: 15px; font-weight: 700; letter-spacing: .06em; cursor: pointer;
  background: var(--surface-2); min-height: 52px;
}
.btn.primary { background: var(--accent); color: #06130b; }
.btn.danger { background: var(--neg); color: #fff; }
.btn:disabled { opacity: .35; cursor: default; }

/* Keypad */
.display { text-align: center; font-size: 46px; font-weight: 700; padding: 10px 0 2px; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.key { border: 0; border-radius: 16px; background: var(--surface); font-size: 26px; height: 64px; cursor: pointer; }
.key:active { background: var(--surface-2); }

/* Confirm */
.confirm { background: var(--surface); border-radius: var(--radius); padding: 18px; }
.confirm .what { font-size: 20px; font-weight: 700; text-align: center; }
.confirm .amt { font-size: 40px; font-weight: 700; text-align: center; margin: 6px 0 14px; }
.confirm .res { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0; border-top: 1px solid var(--line); }
.confirm .res .k { color: var(--muted); font-size: 13px; letter-spacing: .06em; font-weight: 600; }
.confirm .res .v { font-size: 22px; font-weight: 700; }

.notice { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-size: 15px; }
.notice .btn { display: block; width: 100%; margin-top: 10px; background: var(--surface); }
.notice.warn { border-left: 4px solid var(--neg); }
.notice.ok { border-left: 4px solid var(--accent); }

input[type=text], input[type=date] {
  width: 100%; font: inherit; font-size: 20px; padding: 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

/* Collection receipt */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 10;
}
.sheet .card { background: var(--surface); border-radius: 24px; padding: 24px; width: 100%; max-width: 360px; text-align: center; }
.sheet .card .amount { font-size: 40px; font-weight: 700; margin: 8px 0 18px; color: var(--accent); }
.hidden { display: none; }
