:root {
  --pink: #e91e63;
  --pink-dark: #c2185b;
  --violet: #8e24aa;
  --grad: linear-gradient(135deg, #ff4f8b 0%, #c2185b 45%, #8e24aa 100%);
  --bg: #f6f3f7;
  --card: #ffffff;
  --text: #1d1b20;
  --muted: #6f6a75;
  --line: #ebe6ee;
  --ok: #1aa260;
  --limit: #f59e0b;
  --declined: #7c3aed;
  --alert: #e53935;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

.screen { display: none; min-height: 100dvh; flex-direction: column; max-width: 520px; margin: 0 auto; }
.screen.active { display: flex; }
.screen.dark { background: #000; color: #fff; max-width: none; position: relative; overflow: hidden; }
.screen.gradient { background: var(--grad); color: #fff; max-width: none; align-items: center; justify-content: center; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .7rem; opacity: .7; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .85rem; }

/* ---------- Home ---------- */
.topbar {
  background: var(--grad);
  color: #fff;
  padding: calc(14px + var(--safe-top)) 16px 64px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.brand-name { font-weight: 800; font-size: 1.3rem; letter-spacing: -.02em; }
.lang { display: flex; background: rgba(255,255,255,.18); border-radius: 999px; padding: 3px; }
.lang button { padding: 5px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; color: rgba(255,255,255,.85); }
.lang button.on { background: #fff; color: var(--pink-dark); }

.hero { padding: 0 16px; margin-top: -48px; }
.balance-card {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: 0 10px 30px rgba(120, 20, 80, .15);
}
.balance-label { color: var(--muted); font-size: .85rem; }
.balance-value {
  font-size: 2rem; font-weight: 800; letter-spacing: -.02em; margin: 2px 0;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.balance-sub { font-size: .85rem; color: var(--muted); }

.home-main { padding: 20px 16px calc(24px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.scan-button {
  background: var(--grad); color: #fff; border-radius: 24px; padding: 26px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 1.15rem; font-weight: 700;
  box-shadow: 0 12px 28px rgba(194, 24, 91, .35);
  transition: transform .12s;
}
.scan-button:active { transform: scale(.97); }
.link-button { text-align: center; color: var(--pink-dark); font-weight: 600; padding: 6px; cursor: pointer; }

.history { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.history-head { display: flex; justify-content: space-between; align-items: center; }
.history h2 { font-size: 1rem; margin: 0 0 6px; }
.text-button { color: var(--pink-dark); font-weight: 600; padding: 6px; }
#history-list { list-style: none; margin: 0; padding: 0; }
#history-list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
#history-list li:first-child { border-top: 0; }
#history-list img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex: none; }
.h-text { flex: 1; min-width: 0; }
.h-name { font-weight: 600; font-size: .92rem; }
.h-sub { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-amt { font-weight: 700; font-size: .85rem; color: var(--ok); text-align: right; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-amt.limit { color: var(--limit); } .h-amt.declined { color: var(--declined); } .h-amt.alert { color: var(--alert); }

/* ---------- Scan ---------- */
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#video.mirror { transform: scaleX(-1); }
.scan-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at center, transparent 0 34vmin, rgba(0,0,0,.55) 35vmin);
  pointer-events: none;
}
.scan-frame { position: relative; width: 66vmin; height: 66vmin; max-width: 360px; max-height: 360px; }
.scan-frame > span { position: absolute; width: 44px; height: 44px; border: 5px solid #fff; }
.scan-frame > span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 16px; }
.scan-frame > span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 16px; }
.scan-frame > span:nth-child(3) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 16px; }
.scan-frame > span:nth-child(4) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 16px; }
.scan-line {
  position: absolute; left: 8%; right: 8%; height: 3px; border-radius: 3px;
  background: #ff4f8b; box-shadow: 0 0 14px 3px rgba(255, 79, 139, .8);
  animation: sweep 2.2s ease-in-out infinite;
}
@keyframes sweep { 0%, 100% { top: 8%; } 50% { top: 92%; } }
.scan-hint { margin-top: 26px; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.6); padding: 0 24px; text-align: center; }
.scan-error { background: rgba(0,0,0,.7); padding: 10px 14px; border-radius: 12px; margin: 10px 24px; text-align: center; }
.scan-controls {
  position: absolute; left: 0; right: 0; bottom: calc(56px + var(--safe-bottom));
  display: flex; justify-content: space-around; align-items: center;
}
.round-button { width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.2); font-size: 1.4rem; backdrop-filter: blur(6px); }
.shutter {
  width: 78px; height: 78px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 5px rgba(255,255,255,.35), 0 0 0 9px var(--pink);
}
.shutter:active { transform: scale(.93); }
.scan-upload {
  position: absolute; left: 0; right: 0; bottom: calc(16px + var(--safe-bottom));
  text-align: center; font-weight: 600; text-decoration: underline; cursor: pointer;
}

/* ---------- Sub screens ---------- */
.subbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 8px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.subbar h1 { font-size: 1.05rem; margin: 0; }
.back { font-size: 2rem; line-height: 1; width: 40px; height: 40px; color: var(--pink-dark); }

.avatar { border-radius: 50%; object-fit: cover; background: #ddd; }
.avatar.big { width: 132px; height: 132px; border: 4px solid #fff; box-shadow: 0 8px 24px rgba(0,0,0,.15); }

.confirm-main { padding: 28px 16px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.field { width: 100%; display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.field input {
  font: inherit; font-size: 1.05rem; color: var(--text); padding: 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); outline: none;
}
.field input:focus { border-color: var(--pink); }
.row-line {
  width: 100%; display: flex; justify-content: space-between; gap: 16px; padding: 12px 0;
  border-bottom: 1px solid var(--line); font-size: .92rem;
}
.row-line > span:first-child { color: var(--muted); flex: none; }
.row-line > span:last-child { text-align: right; }
.shimmer { animation: pulse 1.2s ease-in-out infinite; color: var(--pink-dark); }
@keyframes pulse { 50% { opacity: .35; } }

.primary, .secondary {
  width: 100%; padding: 16px; border-radius: 16px; font-weight: 700; font-size: 1.02rem;
}
.primary { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(194, 24, 91, .3); }
.secondary { background: var(--card); color: var(--pink-dark); border: 1.5px solid #f3c6d8; }
.primary:active, .secondary:active { transform: scale(.98); }

.pin-main { padding: 36px 24px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pin-dots { display: flex; gap: 18px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--pink); transition: background .1s; }
.pin-dots i.on { background: var(--pink); }
.pin-dots.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 28px; margin-top: 10px; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; background: var(--card); font-size: 1.7rem; font-weight: 500;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.keypad button:active { background: #fde4ee; }

.processing { display: flex; flex-direction: column; align-items: center; gap: 28px; padding: 24px; text-align: center; }
.spinner {
  width: 84px; height: 84px; border-radius: 50%;
  border: 7px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#processing-text { font-size: 1.05rem; font-weight: 600; min-height: 3em; max-width: 320px; transition: opacity .2s; }

/* ---------- Result ---------- */
.result-head {
  --c: var(--ok);
  background: var(--c); color: #fff; text-align: center;
  padding: calc(28px + var(--safe-top)) 16px 84px;
}
.result-head.limit { --c: var(--limit); }
.result-head.declined { --c: var(--declined); }
.result-head.alert { --c: var(--alert); }
.badge {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; background: #fff; color: var(--c);
  display: flex; align-items: center; justify-content: center; font-size: 2.1rem; font-weight: 900;
  animation: pop .45s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
.result-status { font-size: 1.3rem; font-weight: 800; }
.result-main { padding: 0 16px calc(24px + var(--safe-bottom)); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.avatar.overlap { margin-top: -66px; }
.result-payee { font-weight: 700; font-size: 1.1rem; }
.result-headline { text-align: center; font-size: 1.08rem; line-height: 1.4; margin: 0; padding: 0 6px; }
.result-amount {
  font-size: clamp(1.6rem, 7.5vw, 2.4rem); font-weight: 900; letter-spacing: -.02em; text-align: center;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  word-break: break-word; line-height: 1.15;
}
.details { width: 100%; background: var(--card); border-radius: var(--radius); padding: 4px 16px; margin-top: 6px; }
.details .row-line:last-child { border-bottom: 0; }
.result-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.confetti { position: fixed; top: -12px; width: 10px; height: 14px; pointer-events: none; z-index: 10; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
