:root {
  --bg: #FAF5EE;
  --surface: #FFFDFA;
  --surface-2: #F3EBE0;
  --ink: #2A1F18;
  --muted: #75685E;
  --line: #EADFD2;
  --brand: #C2560F;
  --brand-ink: #FFFDFA;
  --brand-soft: #FCE6D4;
  --accent: #F5A25D;
  --pos: #1E7A4E;
  --neg: #B42318;
  --hero: #C2560F;
  --hero-ink: #FFFDFA;
  --shadow: 0 1px 2px rgba(60, 35, 15, .06), 0 6px 20px rgba(60, 35, 15, .06);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
/* Dark: when chosen in Settings, or when "System" is chosen and the phone is dark */
:root[data-theme="dark"] {
    --bg: #16120F;
    --surface: #201A16;
    --surface-2: #2B231D;
    --ink: #F3EEE9;
    --muted: #A89A8F;
    --line: #3A302A;
    --brand: #F28C3C;
    --brand-ink: #1A0F06;
    --brand-soft: #3D2615;
    --accent: #F5A25D;
    --pos: #5CC98F;
    --neg: #F27060;
    --hero: #8A3A0C;
    --hero-ink: #FFF4EA;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #16120F;
    --surface: #201A16;
    --surface-2: #2B231D;
    --ink: #F3EEE9;
    --muted: #A89A8F;
    --line: #3A302A;
    --brand: #F28C3C;
    --brand-ink: #1A0F06;
    --brand-soft: #3D2615;
    --accent: #F5A25D;
    --pos: #5CC98F;
    --neg: #F27060;
    --hero: #8A3A0C;
    --hero-ink: #FFF4EA;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100%; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + var(--safe-t)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 22px; font-weight: 750; letter-spacing: -.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2);
  display: grid; place-items: center; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- avatars ---------- */
.av {
  --c: var(--brand);
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 700; font-size: 16px;
  border: 0; padding: 0;
}
.av.sm { width: 32px; height: 32px; font-size: 13px; }
.av.lg { width: 76px; height: 76px; font-size: 30px; }

/* ---------- main ---------- */
main { padding: 4px 16px calc(110px + var(--safe-b)); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 2px 10px; }
.section-title h2 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.link { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 4px; font-size: 15px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }

.hero { padding: 22px 20px 20px; background: var(--hero); color: var(--hero-ink); border-radius: 24px; position: relative; overflow: hidden; }
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
  background: #FFD3A8; opacity: .18;
}
.hero .label { font-size: 15px; opacity: .85; position: relative; }
.hero .amount { font-size: 42px; font-weight: 800; letter-spacing: -.03em; margin: 2px 0 14px; position: relative; }
.hero .amount small { font-size: 20px; font-weight: 700; opacity: .8; margin-right: 4px; }
.hero .row { display: flex; gap: 8px; position: relative; flex-wrap: wrap; }
.chip-btn {
  border: 0; border-radius: 999px; padding: 9px 14px; font-weight: 600; font-size: 14px;
  background: color-mix(in srgb, var(--hero-ink) 16%, transparent); color: var(--hero-ink);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip-btn svg { width: 16px; height: 16px; }

/* ---------- list rows ---------- */
.list { padding: 4px 0; }
.row-item .av svg { width: 20px; height: 20px; }
.row-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%;
  background: none; border: 0; text-align: left;
}
.list .row-item + .row-item { border-top: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: block; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { text-align: right; flex: none; }
.row-end .big { font-weight: 700; }
.row-end .small { font-size: 13px; color: var(--muted); }

.transfer { padding: 14px 16px; }
.transfer + .transfer { border-top: 1px solid var(--line); }
.transfer .line { display: flex; align-items: center; gap: 8px; }
.transfer .names { flex: 1; min-width: 0; font-weight: 600; }
.transfer .arrow { color: var(--muted); font-weight: 400; margin: 0 2px; }
.transfer .pay { font-size: 13px; color: var(--muted); margin: 6px 0 0 40px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.transfer.mine { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.transfer:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.transfer:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.transfer:only-child { border-radius: var(--radius); }
.btn-sm { white-space: nowrap; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.btn-sm.solid { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.empty { text-align: center; padding: 28px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.month { font-size: 13px; font-weight: 700; color: var(--muted); margin: 22px 4px 8px; text-transform: uppercase; letter-spacing: .06em; }
.date-pill { font-size: 12px; color: var(--muted); }
.exp-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 19px; flex: none; }

/* ---------- FAB & nav ---------- */
.fab {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: calc(78px + var(--safe-b));
  border: 0; border-radius: 999px; padding: 15px 24px;
  background: var(--brand); color: var(--brand-ink); font-weight: 750; font-size: 16px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 40%, transparent);
  display: inline-flex; align-items: center; gap: 8px;
}
.fab svg { width: 20px; height: 20px; }
.nav {
  position: fixed; z-index: 9; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.nav-inner { display: flex; width: 100%; max-width: 560px; }
.nav button {
  flex: 1; border: 0; background: none; padding: 10px 0 9px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--brand); }

/* ---------- auth screens ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 32px 20px calc(32px + var(--safe-b)); }
.logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 18px; display: block; box-shadow: var(--shadow); }
.auth h1 { text-align: center; margin: 0 0 6px; font-size: 30px; letter-spacing: -.02em; }
.auth p { text-align: center; color: var(--muted); margin: 0 0 26px; }
.who { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 10px; margin-top: 8px; }
.who button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 600; padding: 4px; }
.who button:active .av { transform: scale(.94); }
.who .av { transition: transform .15s; }

/* ---------- forms ---------- */
.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 8px 2px; text-transform: uppercase; letter-spacing: .06em; }
.input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 16px;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
textarea.input { resize: vertical; min-height: 64px; }
.amount-wrap { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--line); padding: 4px 2px 8px; }
.amount-wrap:focus-within { border-color: var(--brand); }
.amount-wrap span { font-size: 24px; font-weight: 700; color: var(--muted); }
.amount-input { border: 0; background: none; outline: none; font-size: 40px; font-weight: 800; width: 100%; letter-spacing: -.02em; padding: 0; min-width: 0; }
.btn {
  width: 100%; border: 0; border-radius: 14px; padding: 15px; font-weight: 700; font-size: 16px;
  background: var(--brand); color: var(--brand-ink);
}
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: none; color: var(--neg); border: 1px solid color-mix(in srgb, var(--neg) 40%, transparent); }
.btn + .btn { margin-top: 10px; }
.err-msg { color: var(--neg); font-size: 14px; margin: -6px 2px 14px; min-height: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 12px 7px 7px; display: inline-flex; align-items: center; gap: 7px; font-weight: 600; font-size: 15px;
}
.chip .av { width: 26px; height: 26px; font-size: 12px; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); }
.chip.text { padding: 7px 13px; }
.chip:not(.on) .av { filter: grayscale(.4); opacity: .75; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.split-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.split-row + .split-row { border-top: 1px solid var(--line); }
.split-row .name { flex: 1; font-weight: 600; }
.split-row input { width: 120px; text-align: right; padding: 9px 11px; }
.split-sum { display: flex; justify-content: space-between; font-size: 14px; margin-top: 10px; font-weight: 600; }
.hint { font-size: 14px; color: var(--muted); margin-top: 10px; }

/* ---------- sheet ---------- */
.sheet-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 12, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(22px + var(--safe-b));
  animation: up .24s cubic-bezier(.2, .8, .2, 1);
  overscroll-behavior: contain;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.detail-amount { font-size: 36px; font-weight: 800; letter-spacing: -.02em; }
.kv { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); gap: 12px; }
.kv:first-child { border-top: 0; }

/* ---------- banners & toast ---------- */
.banner {
  display: flex; gap: 12px; align-items: center; padding: 12px 8px 12px 12px; margin-bottom: 10px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
}
.banner-ic {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}
.banner-ic svg { width: 20px; height: 20px; }
.banner-txt { flex: 1; min-width: 0; line-height: 1.3; }
.banner-txt strong { display: block; font-size: 15px; }
.banner-txt span { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.banner .btn-sm { flex: none; white-space: nowrap; padding: 8px 14px; }
.banner-x {
  width: 30px; height: 30px; flex: none; border: 0; border-radius: 50%; background: none;
  color: var(--muted); display: grid; place-items: center; padding: 0;
}
.banner-x svg { width: 16px; height: 16px; }
.offline { text-align: center; font-size: 13px; font-weight: 600; padding: 6px; background: var(--surface-2); color: var(--muted); border-radius: 10px; margin-bottom: 10px; }
.toast {
  position: fixed; z-index: 100; left: 50%; transform: translateX(-50%);
  bottom: calc(140px + var(--safe-b));
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px; max-width: calc(100% - 32px); text-align: center;
  animation: fade .2s;
}
.toast.err { background: var(--neg); color: #fff; }

.setting { display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%; border: 0; background: none; text-align: left; font-size: 16px; }
.list .setting + .setting { border-top: 1px solid var(--line); }
.setting > svg { width: 22px; height: 22px; flex: none; color: var(--muted); }
.setting .row-main small { display: block; color: var(--muted); font-size: 13px; }
.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(18px); }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 40vh auto 0; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* theme picker */
.theme-seg { margin: 4px 16px 14px; }
.theme-row { padding: 14px 16px 0; display: flex; align-items: center; gap: 12px; }
.theme-row svg { width: 22px; height: 22px; color: var(--muted); flex: none; }

/* ---------- PIN ---------- */
.pin-screen { justify-content: flex-start; padding-top: calc(48px + var(--safe-t)); position: relative; }
.pin-back { position: absolute; top: calc(12px + var(--safe-t)); left: 8px; }
.pin-av { display: flex; justify-content: center; margin: 12px 0 16px; }
.pin-screen h1 { font-size: 24px; }
.pin-screen > p { margin-bottom: 22px; }
.pin-dots { display: flex; justify-content: center; gap: 18px; margin-bottom: 10px; }
.pin-dots span { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--brand); transition: background .12s; }
.pin-dots span.on { background: var(--brand); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-err { min-height: 22px; text-align: center; color: var(--neg); font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 28px; justify-content: center; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--surface);
  box-shadow: var(--shadow); font-size: 28px; font-weight: 500; display: grid; place-items: center;
  font-variant-numeric: tabular-nums;
}
.keypad button:active { background: var(--brand-soft); transform: scale(.96); }
.keypad button.del { background: none; box-shadow: none; color: var(--muted); }
.keypad button.del svg { width: 26px; height: 26px; }
.pin-foot { margin-top: 24px !important; font-size: 14px; }
@media (max-height: 680px) {
  .keypad { grid-template-columns: repeat(3, 64px); gap: 12px 24px; }
  .keypad button { width: 64px; height: 64px; font-size: 24px; }
  .pin-av .av.lg { width: 56px; height: 56px; font-size: 22px; }
}