:root {
  color-scheme: light dark;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --earned: #15803d;
  --spent: #b42318;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1210;
    --surface: #151d1b;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #26302d;
    --accent: #2dd4bf;
    --accent-text: #04201c;
    --earned: #4ade80;
    --spent: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: var(--radius); padding: .7rem 1rem; background: transparent; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { color: var(--accent); }
.danger { color: var(--spent); }
.icon { font-size: 1.6rem; line-height: 1; padding: .3rem .9rem; color: var(--accent); }

.top { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; max-width: 40rem; margin: 0 auto; }
.top h1 { font-size: 1.25rem; margin: 0; color: var(--accent); }
.top-actions { display: flex; gap: .25rem; }
.top-actions button { padding: .4rem .6rem; font-size: .9rem; }

main { max-width: 40rem; margin: 0 auto; padding: 0 1rem 1rem; }
h2 { font-size: 1.1rem; margin: .5rem 0 1rem; }
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-nav h2 { margin: 0; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 1rem 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; min-width: 0; }
.card span { display: block; font-size: .8rem; color: var(--muted); }
.card strong { display: block; font-size: clamp(.8rem, 4vw, 1.05rem); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.earned strong { color: var(--earned); }
.card.spent strong { color: var(--spent); }

#add-transaction { width: 100%; }
.rows { list-style: none; padding: 0; margin: 1rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rows:empty { display: none; }
.rows li + li { border-top: 1px solid var(--line); }
.rows button { width: 100%; display: flex; align-items: center; gap: .75rem; text-align: left; border-radius: 0; padding: .8rem 1rem; }
.rows .main { flex: 1; min-width: 0; }
.rows .title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows .sub { display: block; font-size: .8rem; color: var(--muted); }
.rows .amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .amount.in { color: var(--earned); }
.empty, .note { color: var(--muted); text-align: center; margin: 1.5rem 0; }
.empty:empty { display: none; }
.error { color: var(--spent); margin: .25rem 0; }

.inline-form { display: flex; gap: .5rem; }
input, select { width: 100%; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.inline-form input { flex: 1; }

.tabs { position: fixed; inset: auto 0 0 0; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; border-radius: 0; padding: 1rem; color: var(--muted); }
.tabs button.active { color: var(--accent); font-weight: 600; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(28rem, calc(100vw - 2rem)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: #0008; }
dialog form { padding: 1.25rem; display: grid; gap: .8rem; }
dialog h3 { margin: 0; }
dialog label > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: .6rem; margin: 0 !important; font-size: 1rem !important; color: var(--text) !important; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text) !important; font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }
.dialog-actions { display: flex; gap: .25rem; align-items: center; }
.dialog-actions .spacer { flex: 1; }
