:root {
  --bg: #111214;
  --card: #1a1b1f;
  --card-2: #212328;
  --line: #2c2e34;
  --text: #ece8df;
  --muted: #8f8b82;
  --gold: #c9a24a;
  --gold-2: #e3c47f;
  --gold-ink: #1b1608;
  --pos: #74b483;      /* owed to me */
  --neg: #d7766a;      /* I owe */
  --warn: #e3b341;     /* < 1 month */
  --danger: #e2574c;   /* < 1 week */
  --radius: 16px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 Manrope, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; }

#app { max-width: 560px; margin: 0 auto; padding: 14px 16px calc(var(--tabbar) + 90px + var(--safe-b)); }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font: 700 24px/1 'Cormorant Garamond', Georgia, serif; letter-spacing: .3px; color: var(--gold-2); }
.motto { font-size: 11.5px; color: var(--muted); margin-top: 3px; letter-spacing: .2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.icon-btn.sub-icon.active { color: var(--gold); border-color: #5a4a22; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }

.summary { background: linear-gradient(160deg, #23242a 0%, #17181c 60%); position: relative; overflow: hidden; }
.summary::after {
  content: ''; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
  border: 1px dashed rgba(201, 162, 74, .18);
}
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sum-cell .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.sum-cell .val { font-size: 22px; font-weight: 800; margin-top: 2px; white-space: nowrap; }
.sum-cell .val.pos { color: var(--pos); }
.sum-cell .val.neg { color: var(--neg); }
.sum-cell .vals.many .val { font-size: 17px; line-height: 1.35; margin-top: 0; }
.sum-cell .vals.many { margin-top: 4px; }
.sum-cell .vals.pos .val { color: var(--pos); }
.sum-cell .vals.neg .val { color: var(--neg); }
.sum-cell .val.muted { color: var(--muted); }
.sum-rub { font-size: 13px; color: var(--muted); margin-top: 4px; font-weight: 600; }
.sum-bal { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.sum-bal .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; }
.bal-row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding: 3px 0; }
.bal-row b { white-space: nowrap; }
.bal-row b.pos { color: var(--pos); } .bal-row b.neg { color: var(--neg); } .bal-row b.muted { color: var(--muted); }
.bal-row.total { margin-top: 4px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 15px; }
.sum-cur { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.sum-cur span { font-size: 12.5px; padding: 3px 8px; border-radius: 8px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.sum-cur .pos { color: var(--pos); }
.sum-cur .neg { color: var(--neg); }
.sum-note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.sum-net { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; font-size: 13.5px; }
.sum-net b.pos { color: var(--pos); } .sum-net b.neg { color: var(--neg); }

.alert {
  display: flex; gap: 10px; align-items: center; padding: 11px 14px; border-radius: 12px; margin-bottom: 10px;
  font-size: 13.5px; border: 1px solid;
}
.alert.warn { background: rgba(227, 179, 65, .08); border-color: rgba(227, 179, 65, .35); color: #f0d48a; }
.alert.danger { background: rgba(226, 87, 76, .09); border-color: rgba(226, 87, 76, .4); color: #f2a59d; }
.alert.info { background: rgba(201, 162, 74, .07); border-color: rgba(201, 162, 74, .3); color: var(--gold-2); }
.alert .alert-btn { margin-left: auto; font-weight: 700; white-space: nowrap; color: inherit; text-decoration: underline; }

.list-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 2px 10px; gap: 10px; }
.list-head h2, .section-title { font: 700 21px/1.1 'Cormorant Garamond', Georgia, serif; color: var(--gold-2); }
.section-title { margin: 20px 2px 10px; }

.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.seg button { padding: 6px 11px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }
.seg.wide { display: flex; width: 100%; }
.seg.wide button { flex: 1; padding: 9px 6px; }
.seg.dir button.on[data-v="owes_me"] { background: rgba(116, 180, 131, .16); color: var(--pos); }
.seg.dir button.on[data-v="i_owe"] { background: rgba(215, 118, 106, .16); color: var(--neg); }

/* ---------- people ---------- */
.person {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
  border-left-width: 3px;
}
.person.warn { border-left-color: var(--warn); }
.person.danger { border-left-color: var(--danger); }
.avatar-i {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: #2a2b31; color: var(--gold-2); font-weight: 800; border: 1px solid #3a3b42;
}
.p-main { flex: 1; min-width: 0; }
.p-name { font-weight: 700; display: flex; align-items: center; gap: 6px; overflow: hidden; }
.p-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-sum { text-align: right; font-weight: 800; font-size: 14.5px; white-space: nowrap; }
.p-sum div { line-height: 1.3; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: #2d2e34; color: var(--muted); white-space: nowrap; }
.due.warn { color: var(--warn); } .due.danger { color: var(--danger); font-weight: 700; }

.empty {
  text-align: center; padding: 34px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty img { width: 56px; opacity: .85; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.limit {
  display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); padding: 10px 4px;
}
.limit .bar { flex: 1; height: 6px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
.limit .bar i { display: block; height: 100%; background: var(--gold); border-radius: 4px; }
.limit button { color: var(--gold-2); font-weight: 700; }

/* ---------- debt rows (inside the person sheet) ---------- */
.debt {
  width: 100%; text-align: left; display: block; background: var(--card-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 12px 14px; margin-bottom: 8px; border-left-width: 3px;
}
.debt.warn { border-left-color: var(--warn); }
.debt.danger { border-left-color: var(--danger); }
.debt.repaid { opacity: .6; }
.d-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.d-dir { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.d-amount { font-size: 18px; font-weight: 800; white-space: nowrap; }
.d-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.d-note { font-size: 13px; color: var(--muted); margin-top: 4px; font-style: italic; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 16px; border-radius: 13px; font-weight: 700; font-size: 15px;
  background: var(--card-2); border: 1px solid var(--line);
}
.btn.wide { width: 100%; margin-top: 10px; }
.btn.gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--gold-ink); border-color: #a8843a; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: rgba(226, 87, 76, .35); }
.btn.pos { color: var(--pos); border-color: rgba(116, 180, 131, .4); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; margin-top: 10px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar) + 14px + var(--safe-b)); z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 13px 18px 13px 15px; border-radius: 30px;
  background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--gold-ink); font-weight: 800;
  box-shadow: 0 8px 24px rgba(0,0,0,.45), 0 0 0 1px #a8843a inset;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; height: calc(var(--tabbar) + var(--safe-b));
  padding-bottom: var(--safe-b); display: flex; background: rgba(17, 18, 20, .94); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.tabbar button.on { color: var(--gold-2); }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-width: 560px; margin: 0 auto;
  background: #16171b; border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0;
  max-height: 92vh; overflow-y: auto; transform: translateY(105%); transition: transform .25s ease;
  padding: 8px 16px calc(20px + var(--safe-b));
  overscroll-behavior: contain;
}
.sheet.on { transform: none; }
.grip { width: 38px; height: 4px; background: #3a3b41; border-radius: 3px; margin: 2px auto 12px; }
.sheet h3 { font: 700 23px/1.15 'Cormorant Garamond', Georgia, serif; color: var(--gold-2); margin-bottom: 4px; }
.sheet .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sheet-head .avatar-i { width: 48px; height: 48px; font-size: 19px; }

/* ---------- form ---------- */
.lbl { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 16px 2px 7px; }
.lbl small { text-transform: none; letter-spacing: 0; font-weight: 500; }
.input {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 13px; outline: none;
  font-size: 16px;
}
.input:focus { border-color: #6a5729; }
.input-at { position: relative; }
.input-at::before { content: '@'; position: absolute; left: 13px; top: 50%; transform: translateY(-52%); color: var(--muted); font-size: 16px; }
.input-at .input { padding-left: 30px; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row .input { flex: 1; }
.input-row .unit { color: var(--muted); font-weight: 700; min-width: 34px; }
textarea.input { resize: none; min-height: 64px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 8px 11px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-weight: 700; font-size: 13.5px;
}
.chips button.on { background: rgba(201, 162, 74, .14); border-color: #8a6f33; color: var(--gold-2); }
.hint { font-size: 12.5px; color: var(--muted); margin: 7px 2px 0; }
.hint b { color: var(--text); }
.hint .link { color: var(--gold-2); font-weight: 700; text-decoration: underline; }
.field-error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* ---------- debt details ---------- */
.big-amount { font-size: 30px; font-weight: 800; margin: 4px 0 2px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14px; margin: 14px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.history { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.history li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; }
.history li span { color: var(--muted); white-space: nowrap; }

/* ---------- subscription ---------- */
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 4px; }
.plans button {
  position: relative; text-align: left; padding: 13px; border-radius: 13px; background: var(--card); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.plans button.on { border-color: var(--gold); background: rgba(201, 162, 74, .1); }
.plans .price { font-size: 18px; font-weight: 800; color: var(--gold-2); }
.plans small { color: var(--muted); font-size: 12px; }
.plans .save { position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 800; color: var(--gold-ink); background: var(--gold); padding: 1px 6px; border-radius: 6px; }
.sub-status { padding: 10px 12px; border-radius: 11px; background: rgba(116, 180, 131, .1); color: var(--pos); font-weight: 700; font-size: 14px; margin-bottom: 8px; }

/* ---------- support ---------- */
.author { display: flex; flex-direction: column; gap: 10px; }
.author-head { display: flex; align-items: center; gap: 12px; }
.author-head img, .author-head .ph { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; border: 2px solid #5a4a22; }
.author-head b { display: block; font-size: 17px; }
.author-head span { color: var(--muted); font-size: 13px; }
.author p { margin: 0; font-size: 14px; color: #cfcac0; }
.links { display: flex; gap: 8px; }
.links a { flex: 1; text-align: center; padding: 10px; border-radius: 11px; background: var(--card-2); border: 1px solid var(--line); color: var(--gold-2); text-decoration: none; font-weight: 700; font-size: 13.5px; }
.pay-block { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; margin-bottom: 10px; }
.pay-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.pay-head span { color: var(--muted); font-size: 12.5px; }
.pay-row { display: flex; gap: 8px; align-items: center; }
.pay-row code { flex: 1; font-size: 12px; word-break: break-all; color: #d8d2c6; background: var(--card-2); padding: 8px 10px; border-radius: 9px; }
.copy-btn { padding: 8px 11px; border-radius: 9px; background: var(--card-2); border: 1px solid var(--line); font-weight: 700; font-size: 12.5px; color: var(--gold-2); }
.copy-btn.done { color: var(--pos); }
.qr { display: block; width: 180px; max-width: 70%; margin: 12px auto 4px; border-radius: 12px; background: #fff; padding: 8px; }
.qr-note { text-align: center; font-size: 12px; color: var(--muted); }
.stars-row { display: flex; gap: 6px; }
.stars-row button { flex: 1; padding: 9px 4px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--line); font-weight: 700; font-size: 13.5px; }
.stars-row button.on { border-color: var(--gold); color: var(--gold-2); background: rgba(201, 162, 74, .1); }
.credits { text-align: center; font-size: 12px; color: var(--muted); margin: 18px 0 4px; }
.credits a { color: var(--gold-2); text-decoration: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 80px + var(--safe-b)); transform: translate(-50%, 20px);
  background: #2a2b31; color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 90; max-width: 90vw; text-align: center;
  border: 1px solid #3a3b42;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- onboarding ---------- */
.onboarding { position: fixed; inset: 0; z-index: 80; background: radial-gradient(120% 80% at 50% 0%, #22232a 0%, var(--bg) 60%); display: flex; flex-direction: column; overflow: hidden; }
.ob-skip { position: absolute; top: 14px; right: 16px; color: var(--muted); font-size: 14px; font-weight: 600; z-index: 2; padding: 6px; }
.ob-track { flex: 1; display: flex; overflow: hidden; }
.ob-slide {
  flex: 0 0 100%; padding: 70px 26px 10px; transition: transform .3s ease; display: flex; flex-direction: column; align-items: center; text-align: center;
}
.ob-slide h2 { font: 700 32px/1.1 'Cormorant Garamond', Georgia, serif; color: var(--gold-2); margin: 22px 0 10px; }
.ob-slide p { margin: 0 0 10px; font-size: 15.5px; max-width: 380px; }
.ob-art { width: 100%; max-width: 320px; min-height: 160px; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.ob-art.coin { align-items: center; }
.ob-art.coin img { width: 150px; height: 150px; filter: drop-shadow(0 10px 30px rgba(201, 162, 74, .25)); }
.mock-row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; text-align: left; border-left-width: 3px; }
.mock-row b { flex: 1; }
.mock-row .av { width: 28px; height: 28px; border-radius: 50%; background: #2a2b31; display: grid; place-items: center; color: var(--gold-2); font-weight: 800; font-size: 13px; }
.mock-row.warn { border-left-color: var(--warn); } .mock-row.warn span { color: var(--warn); }
.mock-row.danger { border-left-color: var(--danger); } .mock-row.danger span { color: var(--danger); font-weight: 700; }
.mock-bell { text-align: center; color: var(--gold-2); font-weight: 700; margin-top: 6px; }
.ob-big { font: 700 96px/1 'Cormorant Garamond', Georgia, serif; color: var(--gold-2); display: flex; flex-direction: column; align-items: center; }
.ob-big small { font: 600 15px Manrope, sans-serif; color: var(--muted); margin-top: 4px; }
.ob-author { display: flex; align-items: center; gap: 12px; margin: 20px 0 16px; text-align: left; }
.ob-author .avatar { width: 64px; height: 64px; border-radius: 50%; overflow: hidden; border: 2px solid #5a4a22; background: #2a2b31; display: grid; place-items: center; font-size: 24px; font-weight: 800; color: var(--gold-2); }
.ob-author .avatar img { width: 100%; height: 100%; object-fit: cover; }
.ob-author b { display: block; font-size: 18px; }
.ob-author span { color: var(--muted); }
.ob-links { display: flex; gap: 8px; width: 100%; max-width: 380px; margin-top: 8px; }
.ob-links a { flex: 1; padding: 11px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--gold-2); text-decoration: none; font-weight: 700; font-size: 14px; }
.ob-foot { padding: 10px 24px calc(22px + var(--safe-b)); max-width: 440px; width: 100%; margin: 0 auto; }
.ob-dots { display: flex; justify-content: center; gap: 7px; }
.ob-dots span { width: 7px; height: 7px; border-radius: 4px; background: #3a3b41; transition: all .2s; }
.ob-dots span.on { width: 22px; background: var(--gold); }

@media (max-width: 360px) {
  .sum-cell .val { font-size: 19px; }
  .fab span { display: none; }
  .fab { padding: 15px; }
}
