:root {
  --bg: #0c0c0e;
  --bg-2: #141417;
  --card: #18181b;
  --card-2: #232327;
  --line: #2c2c31;
  --text: #f5f5f7;
  --muted: #8e8e96;
  --faint: #5f5f68;
  --accent: #3d7bff;
  --green: #22c55e;
  --red: #f43f5e;
  --amber: #f59e0b;
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea {
  width: 100%; background: var(--card-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=checkbox] { width: auto; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pos { color: var(--green); }
.neg { color: var(--text); }
.hidden { display: none !important; }

#app { max-width: 520px; margin: 0 auto; min-height: 100%; position: relative; }
.screen { padding: calc(16px + var(--safe-t)) 16px calc(110px + var(--safe-b)); animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.topbar .title { flex: 1; font-weight: 700; font-size: 22px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--card); display: grid; place-items: center;
  position: relative; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.badge {
  position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.search-pill {
  flex: 1; height: 42px; border-radius: 21px; background: var(--card); display: flex; align-items: center;
  padding: 0 16px; gap: 8px; color: var(--muted); font-weight: 500;
}
.search-pill b { color: var(--text); font-weight: 800; letter-spacing: .04em; }

/* ---------- Avatar ---------- */
.avatar {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none;
  background: var(--c, var(--accent)); box-shadow: inset 0 0 0 2px rgba(255,255,255,.12);
}
.avatar.sm { width: 34px; height: 34px; font-size: 17px; }
.avatar.lg { width: 72px; height: 72px; font-size: 38px; }
.avatar.xl { width: 96px; height: 96px; font-size: 52px; }
.avatar.bank { background: #fff; font-size: 18px; font-weight: 800; color: #0c0c0e; }

/* ---------- Balance ---------- */
.balance { text-align: center; padding: 18px 0 8px; }
.balance .label { color: var(--muted); font-size: 14px; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.balance .amount { font-size: 48px; font-weight: 800; letter-spacing: -0.04em; margin: 4px 0 2px; }
.balance .amount small { font-size: 26px; font-weight: 700; color: var(--muted); }
.balance .sub { font-size: 13px; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--card);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip.accent { background: rgba(61, 123, 255, .15); color: #8fb2ff; }
.chip.green { background: rgba(34, 197, 94, .15); color: #86efac; }
.chip.amber { background: rgba(245, 158, 11, .15); color: #fcd34d; }
.chip.red { background: rgba(244, 63, 94, .15); color: #fda4af; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 22px 0 26px; }
.action { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text); }
.action .circle {
  width: 54px; height: 54px; border-radius: 50%; background: var(--card-2); display: grid; place-items: center;
  transition: transform .1s, background .15s;
}
.action:active .circle { transform: scale(.92); }
.action .circle svg { width: 22px; height: 22px; }
.action.primary .circle { background: #fff; color: #0c0c0e; }

/* ---------- Cards & lists ---------- */
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 4px 10px; }
.section-title h3 { font-size: 17px; }
.section-title button { color: var(--accent); font-weight: 600; font-size: 14px; }
.card { background: var(--card); border-radius: var(--radius); padding: 6px 0; }
.card.pad { padding: 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.row + .row { border-top: 1px solid rgba(255,255,255,.04); }
.row .main { flex: 1; min-width: 0; }
.row .main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .main .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.row .amt .s { font-size: 12px; font-weight: 500; color: var(--muted); }
.row.tap:active { background: rgba(255,255,255,.03); }
.emoji-box { width: 42px; height: 42px; border-radius: 14px; background: var(--card-2); display: grid; place-items: center; font-size: 22px; flex: none; color: var(--text); }
.emoji-box svg { width: 20px; height: 20px; }
.day-label { font-size: 13px; color: var(--muted); font-weight: 600; padding: 14px 16px 4px; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 6px; }

.alert-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 0; margin-bottom: 10px;
}

/* ---------- Vaults ---------- */
.hscroll { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.vault { flex: 0 0 150px; scroll-snap-align: start; background: var(--card); border-radius: var(--radius); padding: 14px; text-align: left; }
.vault .e { font-size: 26px; }
.vault .n { font-weight: 600; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vault .b { font-weight: 800; font-size: 18px; }
.vault.add { display: grid; place-items: center; color: var(--muted); border: 1.5px dashed var(--line); background: transparent; font-weight: 600; }
.progress { height: 6px; background: var(--card-2); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------- Segmented ---------- */
.seg { display: flex; background: var(--card); border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 16px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card-2); color: var(--text); }

/* ---------- Tasks ---------- */
.task { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.task .head { display: flex; gap: 12px; align-items: center; }
.task .head .main { flex: 1; min-width: 0; }
.task .head .t { font-weight: 700; }
.task .head .s { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.task .reward { font-weight: 800; color: var(--green); white-space: nowrap; }
.task .btns { display: flex; gap: 8px; margin-top: 12px; }
.task .btns .btn { flex: 1; padding: 10px; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 15px 20px; border-radius: 999px;
  font-weight: 700; background: var(--card-2); transition: transform .1s, opacity .15s; width: 100%;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: #fff; color: #0c0c0e; }
.btn.white { background: #fff; color: #0b0b12; }
.btn.green { background: var(--green); color: #052e16; }
.btn.danger { background: rgba(244,63,94,.15); color: #fda4af; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }

.fab {
  position: fixed; right: max(16px, calc(50% - 244px)); bottom: calc(96px + var(--safe-b)); width: 56px; height: 56px;
  border-radius: 50%; background: #fff; color: #0c0c0e; display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.5); z-index: 5;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- Bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding: 8px 8px calc(8px + var(--safe-b));
  background: rgba(12,12,14,.9); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-top: 1px solid var(--line);
}
.nav .inner { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; color: var(--faint); text-decoration: none; padding: 4px 0; position: relative; }
.nav a svg { width: 24px; height: 24px; }
.nav a.on { color: var(--text); }
.nav a .badge { top: 0; right: calc(50% - 22px); }
.nav a.scan .qr {
  width: 54px; height: 54px; border-radius: 18px; background: #fff; display: grid; place-items: center; color: #0c0c0e;
  margin-top: -22px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

/* ---------- Sheets ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; animation: ofade .2s ease; display: flex; align-items: flex-end; justify-content: center; }
@keyframes ofade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; background: var(--bg-2); border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(24px + var(--safe-b)); animation: up .28s cubic-bezier(.2,.9,.3,1);
}
.sheet.full { height: 100%; max-height: 100%; border-radius: 0; padding-top: calc(10px + var(--safe-t)); }
@keyframes up { from { transform: translateY(100%); } }
.sheet .grab { width: 40px; height: 5px; background: var(--line); border-radius: 3px; margin: 0 auto 14px; }
.sheet .sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sheet .sheet-head h2 { flex: 1; font-size: 22px; }
.overlay.closing { animation: ofade .2s ease reverse forwards; }
.overlay.closing .sheet { animation: up .2s ease reverse forwards; }

/* ---------- Pay / amount ---------- */
.amount-input { text-align: center; margin: 18px 0 8px; }
.amount-input .val { font-size: 56px; font-weight: 800; letter-spacing: -0.04em; min-height: 70px; }
.amount-input .val small { font-size: 30px; color: var(--muted); }
.amount-input .hint { color: var(--muted); font-size: 13px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 16px; }
.keypad button { height: 58px; border-radius: 16px; font-size: 24px; font-weight: 600; }
.keypad button:active { background: var(--card); }
.recipient { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.recipient .n { font-weight: 700; font-size: 18px; }
.people { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.person { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; flex: none; width: 66px; }
.person .avatar { width: 56px; height: 56px; font-size: 28px; transition: transform .1s, box-shadow .15s; }
.person.on .avatar { box-shadow: 0 0 0 3px var(--bg-2), 0 0 0 5px #fff; }
.person span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 66px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 20px; text-align: center; }
.logo { width: 76px; height: 76px; border-radius: 24px; margin-bottom: 18px; }
.brand { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }
.tagline { color: var(--muted); margin-top: 6px; margin-bottom: 30px; }
.member-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 12px; width: 100%; max-width: 360px; }
.member-grid .person { width: auto; }
.member-grid .avatar { width: 72px; height: 72px; font-size: 36px; }
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 22px 0 6px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--faint); transition: all .15s; }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.login .keypad { width: 100%; max-width: 300px; }
.login .keypad button { height: 68px; font-size: 28px; border-radius: 50%; }
.err { color: #fda4af; font-size: 14px; min-height: 20px; }

/* ---------- QR ---------- */
.qr-card { background: #fff; color: #0b0b12; border-radius: 28px; padding: 22px; text-align: center; margin: 4px auto 16px; max-width: 320px; }
.qr-card img { width: 100%; aspect-ratio: 1; display: block; }
.qr-card .who { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 18px; margin-bottom: 12px; }
.qr-card .amt { font-weight: 800; font-size: 26px; margin-top: 10px; }
.qr-card .note { color: #555; font-size: 14px; }
.scanner { position: relative; border-radius: 28px; overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 60vh; margin: 0 auto 16px; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18%; border-radius: 24px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45); border: 3px solid rgba(255,255,255,.9); }
.scanner .laser { position: absolute; left: 20%; right: 20%; height: 2px; background: #fff; box-shadow: 0 0 10px rgba(255,255,255,.8); top: 30%; animation: laser 2s ease-in-out infinite alternate; }
@keyframes laser { to { top: 70%; } }
.info-box { background: var(--card); border-radius: var(--radius); padding: 16px; font-size: 14px; color: var(--muted); }
.info-box b { color: var(--text); }

/* ---------- Virtual card ---------- */
.vcard {
  aspect-ratio: 1.586; border-radius: 22px; padding: 20px; background: linear-gradient(160deg, #2b2b30 0%, #121214 100%); position: relative; overflow: hidden; color: #fff;
  display: flex; flex-direction: column; justify-content: space-between; border: 1px solid #34343a;
}
.vcard .top { display: flex; justify-content: space-between; font-weight: 800; letter-spacing: .08em; position: relative; z-index: 1; }
.vcard .num { font-family: ui-monospace, monospace; font-size: 18px; letter-spacing: .14em; position: relative; z-index: 1; }
.vcard .bot { display: flex; justify-content: space-between; align-items: end; font-size: 13px; position: relative; z-index: 1; }
.vcard .bot b { font-size: 15px; display: block; }
.vcard .chipimg { width: 40px; height: 30px; border-radius: 6px; background: linear-gradient(135deg, #d4d4d8, #8e8e96); position: relative; z-index: 1; }

/* ---------- Leaderboard ---------- */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 8px; margin: 10px 0 18px; text-align: center; }
.podium .p { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.podium .p .avatar { width: 60px; height: 60px; font-size: 30px; }
.podium .p.first .avatar { width: 78px; height: 78px; font-size: 40px; box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px #fff; }
.podium .stand { width: 100%; border-radius: 14px 14px 0 0; background: var(--card); display: grid; place-items: center; font-weight: 800; font-size: 22px; }
.podium .first .stand { height: 90px; background: var(--card-2); }
.podium .second .stand { height: 66px; }
.podium .third .stand { height: 48px; }
.podium .nm { font-weight: 700; font-size: 14px; }
.podium .sc { font-size: 12px; color: var(--muted); }

/* ---------- Shop ---------- */
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.shop-item { background: var(--card); border-radius: var(--radius); padding: 16px; text-align: left; display: flex; flex-direction: column; gap: 6px; position: relative; }
.shop-item .e { font-size: 34px; }
.shop-item .t { font-weight: 600; font-size: 14px; flex: 1; }
.shop-item .p { font-weight: 800; }
.shop-item.cant { opacity: .5; }
.shop-item .x { position: absolute; top: 8px; right: 10px; color: var(--faint); font-size: 18px; }

/* ---------- Pickers ---------- */
.emoji-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.emoji-pick button { width: 44px; height: 44px; border-radius: 12px; background: var(--card-2); font-size: 22px; }
.emoji-pick button.on { box-shadow: 0 0 0 2px #fff; }
.color-pick { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.color-pick button { width: 34px; height: 34px; border-radius: 50%; }
.color-pick button.on { box-shadow: 0 0 0 3px var(--bg-2), 0 0 0 5px #fff; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; background: var(--card-2); border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; }
.switch { width: 48px; height: 28px; border-radius: 14px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .2s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }

/* ---------- Success ---------- */
.success { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; text-align: center; padding: 24px; animation: ofade .25s; }
.success .check { width: 96px; height: 96px; border-radius: 50%; background: var(--green); color: #04220f; display: grid; place-items: center; margin-bottom: 20px; animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.success .check svg { width: 50px; height: 50px; }
@keyframes pop { from { transform: scale(0); } }
.success h2 { font-size: 34px; }
.success p { color: var(--muted); margin: 8px 0 32px; font-size: 16px; }
.success .btn { max-width: 320px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; top: calc(12px + var(--safe-t)); left: 0; right: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  background: rgba(40,40,44,.96); backdrop-filter: blur(10px); padding: 12px 18px; border-radius: 18px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 480px; width: 100%; animation: tin .3s ease; display: flex; gap: 10px; align-items: center;
}
.toast.error { background: rgba(127,29,29,.95); }
@keyframes tin { from { transform: translateY(-20px); opacity: 0; } }


@media (min-width: 560px) {
  .screen { padding-top: 28px; }
}
