:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe7d8;
  --ink: #1d2b36;
  --ink-2: #4f5d68;
  --ink-3: #85909a;
  --line: #e2d8c6;
  --accent: #d9663f;
  --accent-ink: #ffffff;
  --accent-soft: #f8e1d6;
  --pos: #2f7d5b;
  --pos-soft: #dcefe4;
  --neg: #b4432a;
  --neg-soft: #f7ddd5;
  --shadow: 0 1px 2px rgba(29, 43, 54, .06), 0 4px 16px rgba(29, 43, 54, .06);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12191f;
    --surface: #1a242c;
    --surface-2: #233039;
    --ink: #eee6d6;
    --ink-2: #b5bcc2;
    --ink-3: #7e8a94;
    --line: #2c3a44;
    --accent: #ef7c55;
    --accent-ink: #1a1410;
    --accent-soft: #3a261e;
    --pos: #6cc49b;
    --pos-soft: #1d3329;
    --neg: #f08a70;
    --neg-soft: #3b231d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + 96px); min-height: 100dvh; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 700; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
a { color: inherit; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.loading { padding: 40vh 0 0; text-align: center; color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px;
  background: var(--bg);
}
.top h1 { flex: 1; font-size: 1.35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { text-decoration: none; font-size: 1.4rem; line-height: 1; padding: 6px 8px 6px 0; color: var(--ink-2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink); font-size: .85rem; font-weight: 500;
  text-decoration: none; white-space: nowrap; border: 0;
}

/* ---------- cards & lists ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { display: block; font-size: .82rem; color: var(--ink-2); }
.row .amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .amt .sub { font-size: .78rem; }
a.row:active, button.row:active { background: var(--surface-2); }
button.row { width: 100%; background: none; border: 0; border-top: 1px solid var(--line); font: inherit; text-align: left; cursor: pointer; }
button.row:first-child { border-top: 0; }
.day { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 20px 4px 8px; }
.icon {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; font-size: 1.1rem; background: var(--surface-2);
}
.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }

/* ---------- summary ---------- */
.summary { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 4px 0 8px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.stat .label { font-size: .78rem; color: var(--ink-2); }
.stat .value { font-family: Fraunces, Georgia, serif; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hero-balance { text-align: center; padding: 22px 16px; }
.hero-balance .value { font-family: Fraunces, Georgia, serif; font-size: 2rem; font-weight: 700; overflow-wrap: anywhere; }
.hero-balance.pos { background: var(--pos-soft); }
.hero-balance.neg { background: var(--neg-soft); }

/* ---------- forms ---------- */
label { display: block; font-size: .85rem; font-weight: 500; color: var(--ink-2); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 11px 12px; outline: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, select:focus { border-color: var(--accent); }
input[type="checkbox"] { width: 22px; height: 22px; padding: 0; flex: none; border-radius: 6px; cursor: pointer; display: grid; place-items: center; }
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after { content: "✓"; color: var(--accent-ink); font-size: 14px; font-weight: 700; }
.amount-input { font-family: Fraunces, Georgia, serif; font-size: 1.8rem; font-weight: 700; padding: 10px 12px; }
.inline { display: flex; gap: 10px; align-items: center; }
.inline > * { flex: 1; }
.inline > .fit { flex: none; }
.hint { font-size: .8rem; color: var(--ink-3); margin-top: 6px; }
.error-text { color: var(--neg); font-size: .85rem; margin-top: 10px; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; font: inherit; font-size: .9rem; font-weight: 500; color: var(--ink-2); padding: 8px 6px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.split-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.split-row:first-child { border-top: 0; }
.split-row .name { flex: 1; }
.split-row input:not([type="checkbox"]) { width: 110px; padding: 8px 10px; text-align: right; }
.split-row .each { font-size: .82rem; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 80px; text-align: right; }
.split-tools { display: flex; justify-content: space-between; align-items: center; margin: 8px 2px 0; font-size: .85rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 1rem;
  padding: 13px 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: none; color: var(--neg); }
.btn.small { padding: 8px 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); font-weight: 500; cursor: pointer; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }

.fab {
  position: fixed; z-index: 6; right: max(16px, calc(50% - 264px));
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  box-shadow: 0 6px 20px rgba(217, 102, 63, .35);
  border-radius: 999px; padding: 14px 20px;
}

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; z-index: 6; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; max-width: 186px; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; font-size: .75rem; font-weight: 500; color: var(--ink-3);
}
.nav a .glyph { font-size: 1.25rem; line-height: 1; }
.nav a[aria-current="page"] { color: var(--accent); }

/* ---------- home ---------- */
.hero { padding: 18vh 0 28px; }
.hero .mark { width: 56px; height: 56px; margin-bottom: 18px; }
.hero h1 { font-size: 2.4rem; margin-bottom: 8px; }
.hero p { font-size: 1.05rem; color: var(--ink-2); max-width: 30ch; }

/* ---------- transfers ---------- */
.transfer { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.transfer:first-child { border-top: 0; }
.transfer .who { flex: 1; min-width: 0; }
.transfer .who b { font-weight: 600; }
.transfer .arrow { color: var(--ink-3); margin: 0 4px; }
.transfer .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.transfer.mine { background: var(--accent-soft); }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; position: relative; overflow: hidden; }
.bar span { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.bar .p { left: 50%; background: var(--pos); }
.bar .n { right: 50%; background: var(--neg); }

.share { display: flex; gap: 8px; }
.share input { font-size: .85rem; color: var(--ink-2); }
.banner { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.tag { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-left: 6px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; z-index: 20; left: 50%; bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; max-width: calc(100% - 32px); transition: .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--neg); color: #fff; }
