:root {
  --bg: #f5f6f3;
  --card: #ffffff;
  --text: #1b1f1c;
  --muted: #66706a;
  --line: #e3e6e1;
  --accent: #15803d;
  --accent-soft: #dcf2e3;
  --warn: #c27c0e;
  --neg: #c0392b;
  --track: #eceee9;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413;
    --card: #1b1e1c;
    --text: #edf0ec;
    --muted: #9aa39d;
    --line: #2b302d;
    --accent: #4ade80;
    --accent-soft: #1c3526;
    --warn: #f0b44c;
    --neg: #f87171;
    --track: #2a2f2c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 150px);
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
.title { font-size: 1.4rem; margin: 18px 0 10px; }
.sec { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 22px 0 8px; }
.label { color: var(--muted); font-size: .85rem; display: block; }
.muted { color: var(--muted); margin: 4px 0; }
.small { font-size: .85rem; display: block; }
.neg { color: var(--neg); }
.pos { color: var(--accent); }
.grow { flex: 1; min-width: 0; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.monthnav h1 { font-size: 1.25rem; }

.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--track); color: var(--muted); }
.badge.s-keep { background: var(--accent-soft); color: var(--accent); }
.badge.s-think { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.s-cancel { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 8px 10px; margin-top: 10px; font-size: .9rem; }
.notice.bad { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.notice-row { margin: 12px 0 0; background: var(--accent-soft); border-color: transparent; }
.plain { border: 0; background: none; padding: 0; text-align: left; }
.small-btn { padding: 6px 10px; font-size: .85rem; }
.top-gap { margin-top: 16px; }
.save-note { margin: 10px 0 0; }
.favs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 4px; scrollbar-width: none; }
.fav { flex: none; border: 1px solid var(--accent); color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 6px 12px; font-size: .85rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .c-budget, .legend .c-budget { fill: color-mix(in srgb, var(--muted) 35%, transparent); background: color-mix(in srgb, var(--muted) 35%, transparent); }
.chart .c-spent, .legend .c-spent { fill: var(--accent); background: var(--accent); }
.chart .c-over, .legend .c-over { fill: var(--neg); background: var(--neg); }
.chart .c-axis { stroke: var(--line); }
.chart .c-label { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sheet .card { background: var(--bg); }
.sheet h3.sec { margin-top: 14px; }
.imp { align-items: flex-start; }
.imp-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 55%; }
.imp select {
  max-width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: .9rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { font-size: 1.05rem; }
.card > .btn { margin-top: 12px; }
.hero { text-align: center; }
.big { font-size: 2rem; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.hero .big { font-size: 2.4rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats > div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; }
.stats b { font-variant-numeric: tabular-nums; font-size: .95rem; }

.bar { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.warn span { background: var(--warn); }
.bar.over span { background: var(--neg); }

.list { display: flex; flex-direction: column; gap: 8px; }
.cat, .item {
  display: flex;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.cat { flex-direction: column; }
.item { align-items: center; gap: 12px; }
.item b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.done { opacity: .6; }
.check { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--accent-soft); border-radius: 99px; padding: 3px 10px; font-size: .85rem; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) {
  .btn.primary, .chips input:checked + span, .fab { color: #0b1a10; }
}
.btn.danger { color: var(--neg); }
.btn.wide { width: 100%; margin: 10px 0 4px; }
.icon {
  border: 0;
  background: transparent;
  font-size: 1.4rem;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex: none;
  color: var(--muted);
}
.icon:active, .btn:active, .item:active, .cat:active { transform: scale(.98); }

.sumrows { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; font-variant-numeric: tabular-nums; }
.sumrows .total { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 600; }

.fab {
  position: fixed;
  right: max(16px, calc(50% - 264px));
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .2);
}
.fab svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 2.5; fill: none; stroke-linecap: round; }

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0;
  background: none;
  padding: 8px 2px 10px;
  font-size: .72rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tabs svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tabs [aria-current] { color: var(--accent); font-weight: 600; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.modal[hidden] { display: none; }
.sheet {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.sheet h2 { font-size: 1.2rem; margin-bottom: 12px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  font-size: 1.05rem;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chips { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { font-size: .85rem; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px; }
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.err { color: var(--neg); margin: 0 0 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 160px);
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 20;
  max-width: calc(100% - 32px);
}
