:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2421;
  --muted: #65706b;
  --border: #dde3e0;
  --accent: #1f8a5b;
  --accent-text: #ffffff;
  --good: #1a7a4f;
  --bad: #c0392b;
  --notice-bg: #fff6dd;
  --notice-text: #6b5200;
  --field: #ffffff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1c2220;
    --text: #e8eeeb;
    --muted: #9aa6a0;
    --border: #2e3733;
    --accent: #2fa772;
    --accent-text: #08130e;
    --good: #4fce94;
    --bad: #ff7b6b;
    --notice-bg: #3a3214;
    --notice-text: #f3dc8a;
    --field: #141917;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
.wrap { max-width: 520px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 0.6rem; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.topnav { display: flex; gap: 4px; margin-bottom: 12px; padding: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.topnav a { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.topnav a.active { background: var(--accent); color: var(--accent-text); }

.monthbar { display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 4px 0 12px; }
.monthbar h1 { flex: 1; text-align: center; }
.arrow { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; line-height: 1; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.arrow.disabled { opacity: 0.3; }
.badge { display: inline-block; vertical-align: middle; margin-left: 4px; padding: 2px 8px;
  border-radius: 999px; background: var(--border); color: var(--muted);
  font-size: 0.7rem; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin-bottom: 12px; }
.card.narrow { margin-top: 10vh; }
.card.narrow h1 { margin-bottom: 0.8rem; }

label { display: block; margin: 0.7rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }
.optional { font-weight: normal; opacity: 0.8; }
input[type=text], input[type=email], input[type=password], input[type=date] {
  width: 100%; min-height: 44px; padding: 0.5rem 0.65rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--field); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  -webkit-appearance: none; appearance: none; }
input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }

button, .button { display: inline-block; min-height: 44px; margin-top: 0.9rem; padding: 0.55rem 1.1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text);
  font: inherit; font-size: 1rem; font-weight: 600; text-align: center; text-decoration: none;
  cursor: pointer; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent);
  color: var(--accent-text); }
button.danger { color: var(--bad); }
button.link { min-height: 0; margin-top: 0.8rem; padding: 0; border: none; background: none;
  font-size: 0.85rem; font-weight: normal; text-decoration: underline; }
button.icon { min-height: 0; width: 36px; height: 36px; margin: 0; padding: 0; border: none;
  background: none; color: var(--muted); font-size: 1.4rem; line-height: 1; }
.block { display: block; width: 100%; }
.card > .button.block:first-child { margin-top: 0; }

.expense-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.expense-form .wide { grid-column: 1 / -1; }
.expense-form .field { min-width: 0; }
.expense-form .field:nth-child(-n+3) label { margin-top: 0; }
.row-form { display: flex; gap: 8px; align-items: stretch; }
.row-form input { flex: 1; min-width: 0; }
.row-form button { margin-top: 0; white-space: nowrap; }

.summary { text-align: center; }
.summary .label { margin: 0; font-size: 0.85rem; color: var(--muted); }
.remaining { margin: 2px 0 10px; font-size: 2.6rem; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.meter { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.meter .fill.over { background: var(--bad); }
.detail { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); }

.inline-form { margin-top: 12px; text-align: left; }
.inline-form summary { color: var(--accent); font-size: 0.9rem; cursor: pointer; padding: 4px 0; }
.inline-form .row-form { margin-top: 8px; }
.hint { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); line-height: 1.45; }
.count { display: inline-block; margin-left: 4px; padding: 1px 8px; border-radius: 999px;
  background: var(--border); color: var(--muted); font-size: 0.75rem; font-weight: 600; }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: flex; align-items: center; gap: 8px; padding: 10px 0;
  border-top: 1px solid var(--border); }
.lines li:first-child { border-top: none; padding-top: 2px; }
.line-main { flex: 1; min-width: 0; }
.vendor { display: block; font-weight: 600; overflow-wrap: anywhere; }
.meta { display: block; font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fund-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fund-head h2 { margin: 0; overflow-wrap: anywhere; }
.fund-head .amount { font-size: 1.2rem; }

.choices { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.choices.inline { flex-direction: row; gap: 16px; }
.choice { display: flex; align-items: center; gap: 10px; min-height: 40px; margin: 0;
  font-size: 1rem; color: var(--text); }
.choice input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }
.choice .meta { display: inline; }

.flash { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 0.9rem;
  line-height: 1.4; border: 1px solid var(--border); background: var(--card); }
.flash.ok { color: var(--good); }
.flash.error { color: var(--bad); }
.flash.notice { background: var(--notice-bg); color: var(--notice-text); border-color: transparent; }
form .flash { margin: 12px 0 0; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 30; pointer-events: none; }
.celebrate { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center;
  justify-content: center; padding: 24px; background: rgba(0, 0, 0, 0.45); }
.celebrate-box { width: 100%; max-width: 340px; padding: 28px 22px; border-radius: 18px;
  background: var(--card); text-align: center; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); }
.celebrate-box h2 { margin: 0 0 8px; font-size: 2rem; color: var(--good); }
.celebrate-box p { margin: 6px 0; line-height: 1.45; }
