:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --border: #e3ded3;
  --text: #1d2321;
  --text-2: #5d6662;
  --text-3: #8a918d;
  --accent: #2f6f6a;
  --accent-ink: #ffffff;
  --accent-soft: #e0eeec;
  --dad: #257de0;
  --mom: #e2603a;
  --good: #1f7a3a;
  --good-soft: #e3f3e7;
  --warn: #a35d00;
  --warn-soft: #fdf0dc;
  --bad: #c03537;
  --bad-soft: #fbe5e5;
  --series-1: #257de0;
  --series-2: #f47230;
  --grid: #ebe7df;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 4px 14px rgba(30, 30, 20, .05);
  --radius: 16px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111615;
    --surface: #1a2120;
    --surface-2: #222b29;
    --border: #2e3a37;
    --text: #edf1ef;
    --text-2: #a9b4b0;
    --text-3: #7d8884;
    --accent: #5fb3aa;
    --accent-ink: #0d1716;
    --accent-soft: #1f3532;
    --dad: #4c9bf0;
    --mom: #ef8a63;
    --good: #5cc77a;
    --good-soft: #193323;
    --warn: #e6a64a;
    --warn-soft: #3a2b14;
    --bad: #f07a7b;
    --bad-soft: #3a1c1d;
    --series-1: #338ced;
    --series-2: #e76624;
    --grid: #263130;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111615; --surface: #1a2120; --surface-2: #222b29; --border: #2e3a37;
  --text: #edf1ef; --text-2: #a9b4b0; --text-3: #7d8884;
  --accent: #5fb3aa; --accent-ink: #0d1716; --accent-soft: #1f3532;
  --dad: #4c9bf0; --mom: #ef8a63;
  --good: #5cc77a; --good-soft: #193323; --warn: #e6a64a; --warn-soft: #3a2b14;
  --bad: #f07a7b; --bad-soft: #3a1c1d;
  --series-1: #338ced; --series-2: #e76624; --grid: #263130; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40vh 0; text-align: center; color: var(--text-3); }

/* ---------- layout */
.shell { max-width: 760px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  margin: 0 -16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -.01em; }
.topbar .who { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; flex: none;
}
.avatar.dad { background: var(--dad); } .avatar.mom { background: var(--mom); }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }

nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs .inner { display: flex; width: 100%; max-width: 760px; }
nav.tabs button {
  flex: 1; height: var(--nav-h); border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--text-3);
}
nav.tabs button svg { width: 22px; height: 22px; }
nav.tabs button.on { color: var(--accent); font-weight: 600; }

.fab {
  position: fixed; z-index: 11; right: max(16px, calc(50% - 364px));
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  height: 52px; padding: 0 20px 0 16px; border-radius: 26px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 650;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.fab svg { width: 22px; height: 22px; }

/* ---------- cards & type */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }
.section-title { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase;
  letter-spacing: .04em; margin: 22px 4px 8px; display: flex; align-items: center; gap: 8px; }
.section-title .spacer { flex: 1; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--text-3); padding: 28px 12px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; }

/* balance hero */
.hero { padding: 20px; position: relative; overflow: hidden; }
.hero .label { font-size: 14px; color: var(--text-2); }
.hero .amount { font-size: 40px; font-weight: 750; letter-spacing: -.02em; margin: 2px 0 4px; }
.hero.owing .amount { color: var(--text); }
.hero.square .amount { color: var(--good); }
.hero .sub { font-size: 13px; color: var(--text-2); }
.hero .actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 620px) { .tiles.four { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.tile .t-label { font-size: 12px; color: var(--text-2); }
.tile .t-value { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; }
.tile .t-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center; color: var(--text-2); }
.iconbtn:hover { background: var(--surface-2); }
.iconbtn svg { width: 20px; height: 20px; }

/* ---------- lists */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row .emoji { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 20px; flex: none; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12.5px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 1px; }
.row .right { text-align: right; flex: none; }
.row .right .amt { font-weight: 700; }
.row .right .share { font-size: 12.5px; color: var(--text-2); }
.row.archived { opacity: .55; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- filters / chips */
.toolbar { display: flex; gap: 8px; align-items: center; margin: 4px 0 12px; flex-wrap: wrap; }
.search { flex: 1; min-width: 160px; position: relative; }
.search input { width: 100%; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); padding: 0 12px 0 36px; }
.search svg { position: absolute; left: 11px; top: 11px; width: 18px; height: 18px; color: var(--text-3); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip { flex: none; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 13.5px; display: inline-flex; align-items: center; gap: 5px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.dashed { border-style: dashed; color: var(--text-2); }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; height: 34px; cursor: pointer; font-size: 13.5px; color: var(--text-2); padding: 0 8px; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- forms */
.field { margin-bottom: 14px; }
.field > label, .field > .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
input.in, select.in, textarea.in {
  width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); padding: 0 12px; outline: none;
}
textarea.in { height: auto; min-height: 70px; padding: 10px 12px; resize: vertical; }
input.in:focus, select.in:focus, textarea.in:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.money { position: relative; }
.money span { position: absolute; left: 12px; top: 11px; color: var(--text-3); font-weight: 600; }
.money input { padding-left: 28px; font-size: 18px; font-weight: 650; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.summary b { font-size: 16px; }
.summary .line { display: flex; justify-content: space-between; gap: 10px; }
.err { color: var(--bad); font-size: 13.5px; margin: 6px 0 10px; min-height: 1em; }

/* ---------- sheet / modal */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10, 15, 14, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { background: var(--bg); width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 0 16px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease; }
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; max-height: 88vh; } }
.sheet-head { position: sticky; top: 0; z-index: 2; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: 14px 0 10px; }
.sheet-head h3 { margin: 0; flex: 1; font-size: 18px; }
.sheet-foot { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); background: var(--bg); padding: 12px 0 0; display: flex; gap: 8px; }
.sheet-foot .btn { flex: 1; height: 46px; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- auth */
.auth { max-width: 420px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 16px 40px; }
.auth .logo { width: 64px; height: 64px; margin: 0 auto 10px; display: block; }
.auth h1 { text-align: center; margin: 0 0 4px; font-size: 26px; }
.auth p.lead { text-align: center; color: var(--text-2); margin: 0 0 24px; }
.who-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.who-pick button { border: 2px solid var(--border); background: var(--surface); border-radius: 16px; padding: 16px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 650; }
.who-pick button .avatar { width: 46px; height: 46px; font-size: 18px; }
.who-pick button.on { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--text); fill-opacity: .04; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12.5px; padding: 8px 10px; border-radius: 10px;
  white-space: nowrap; transform: translate(-50%, calc(-100% - 8px)); opacity: 0; transition: opacity .1s; z-index: 3; }
.tip.show { opacity: 1; }
.tip b { display: block; margin-bottom: 2px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; align-items: center; gap: 10px; padding: 7px 0; font-size: 13.5px; }
.hbar .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { height: 12px; border-radius: 0 4px 4px 0; position: relative; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.hbar .val small { display: block; font-weight: 400; color: var(--text-3); font-size: 11.5px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 7px 6px; border-top: 1px solid var(--border); }
table.data th { color: var(--text-2); font-weight: 600; border-top: 0; }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }

/* misc */
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--good); border-radius: 3px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.receipts { display: flex; gap: 8px; flex-wrap: wrap; }
.receipts .rc { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: grid; place-items: center; font-size: 12px; color: var(--text-2); text-decoration: none; }
.receipts .rc img { width: 100%; height: 100%; object-fit: cover; }
.receipts .rc button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 13px; line-height: 1; }
.feed .item { display: flex; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 14px; }
.feed .item:first-child { border-top: 0; }
.feed .when { font-size: 12px; color: var(--text-3); }
.set-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); }
.set-row:first-child { border-top: 0; }
.set-row input.in { height: 38px; }
.set-row .emoji-in { width: 52px; text-align: center; padding: 0; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.btn svg { width: 18px; height: 18px; flex: none; }
