/* TapTap — warm light theme, forest green + brown + cream */
:root {
  --bg: #f5f1e8;
  --bg-elev: #ffffff;
  --bg-soft: #ece5d3;
  --line: #d9d0bf;
  --text: #2d2a24;
  --text-dim: #7a6f5f;
  --accent: #3d7a4f;
  --accent-soft: #c8dcc9;
  --brown: #8b6f4e;
  --success: #3d7a4f;
  --danger: #b84040;
  --warn: #c7823a;
  --radius: 20px;
  --radius-lg: 28px;
  --tap: 72px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* User header (above every screen) */
.user-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; min-height: 48px;
  background: var(--bg-elev);
  box-shadow: 0 1px 0 var(--line);
}
.user-header .uh-left {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0;
}
.user-header .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brown);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; letter-spacing: 0.01em;
  overflow: hidden; flex-shrink: 0;
}
.user-header .avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.user-header .uh-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 180px;
}
.user-header .uh-right {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 11px; color: var(--text-dim);
  max-width: 130px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.user-header .signin-pill {
  appearance: none; border: 0; cursor: pointer;
  background: var(--brown); color: #fff;
  padding: 8px 14px; border-radius: 999px;
  font-weight: 600; font-size: 13px; letter-spacing: 0.01em;
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
}
.user-header .signin-pill svg { width: 14px; height: 14px; }
.user-header .signin-pill:active { transform: scale(0.97); }

.qr-username {
  margin-top: 14px; font-size: 18px; font-weight: 600;
  color: var(--text); letter-spacing: -0.01em;
}

/* Top bar */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
}
.top .brand {
  font-weight: 700; font-size: 19px; letter-spacing: -0.01em;
}
.top .brand .dot { color: var(--accent); }
.iconbtn {
  background: var(--bg-elev); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); cursor: pointer;
}
.iconbtn:active { transform: scale(0.96); }

/* Balance hero */
.hero {
  padding: 22px 22px 14px;
}
.hero .label { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }
.hero .amount {
  font-size: 54px; font-weight: 700; letter-spacing: -0.02em; line-height: 1;
}
.hero .amount .unit { font-size: 22px; font-weight: 500; color: var(--text-dim); margin-left: 8px; }
.hero .sub { margin-top: 10px; color: var(--text-dim); font-size: 15px; }
.hero .net-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elev); padding: 6px 10px; border-radius: 999px;
  font-size: 12px; color: var(--text-dim); border: 1px solid var(--line);
}
.net-pill .led { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.net-pill.live .led { background: var(--success); }

/* Big action buttons */
.actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 10px 18px 22px;
}
.action {
  appearance: none; border: 0; cursor: pointer;
  padding: 22px 18px; border-radius: var(--radius-lg);
  font-size: 22px; font-weight: 700; letter-spacing: -0.01em;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: transform 0.06s ease;
  min-height: 150px;
}
.action:active { transform: scale(0.98); }
.action.pay { background: var(--accent); color: #ffffff; }
.action.get { background: var(--bg-elev); color: var(--text); border: 1px solid var(--line); }
.action.get svg { color: var(--brown); }
.action svg { width: 40px; height: 40px; }

/* Cards / rows */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 10px 18px;
}
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .k { color: var(--text-dim); font-size: 14px; }
.row .v { font-weight: 600; font-size: 15px; text-align: right; }

/* Screens */
.screen { flex: 1; padding-bottom: 24px; display: flex; flex-direction: column; }
.screen .h {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  padding: 6px 22px 2px;
}
.screen .sh { color: var(--text-dim); font-size: 15px; padding: 0 22px 16px; }

/* Receive / QR */
.qr-wrap {
  display: flex; flex-direction: column; align-items: center; padding: 8px 22px;
}
.qr-frame {
  background: white; padding: 18px; border-radius: 24px;
  box-shadow: 0 10px 40px rgba(61, 122, 79, 0.18);
}
.qr-frame canvas, .qr-frame svg { display: block; }
.addr {
  margin-top: 18px; font-family: "SF Mono", ui-monospace, Menlo, monospace;
  color: var(--text-dim); font-size: 12px; word-break: break-all; text-align: center;
  padding: 0 22px;
}
.tap-hint {
  margin-top: 22px; padding: 14px 22px; text-align: center;
  color: var(--text-dim); font-size: 14px;
}
.tap-hint .pulse {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.7); }
}

/* Camera / scanner */
.scanner {
  position: relative; width: 100%; aspect-ratio: 1; background: #000;
  border-radius: 24px; overflow: hidden; margin: 0 0 16px;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .reticle {
  position: absolute; inset: 15%;
  border: 3px solid rgba(255,255,255,0.8); border-radius: 24px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.3) inset;
}

/* Amount pad */
.amount-box {
  text-align: center; padding: 20px 22px 10px;
}
.amount-box .big {
  font-size: 68px; font-weight: 700; letter-spacing: -0.03em; line-height: 1;
}
.amount-box .big .u { font-size: 28px; color: var(--text-dim); margin-left: 6px; }
.amount-box .to { color: var(--text-dim); font-size: 13px; margin-top: 12px; word-break: break-all; }
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 12px 16px 16px;
}
.keypad button {
  appearance: none; background: transparent; color: var(--text);
  border: 0; font-size: 28px; font-weight: 500; padding: 16px;
  border-radius: 16px; cursor: pointer;
}
.keypad button:active { background: var(--bg-soft); }

/* Primary button */
.primary {
  margin: 6px 18px 12px; display: block; width: calc(100% - 36px);
  padding: 20px; border-radius: 18px;
  background: var(--accent); color: white;
  font-size: 18px; font-weight: 700; border: 0; cursor: pointer;
  letter-spacing: -0.01em;
}
.primary:active { transform: scale(0.98); }
.primary[disabled] { background: var(--bg-soft); color: var(--text-dim); cursor: not-allowed; }
.secondary {
  margin: 0 18px 12px; display: block; width: calc(100% - 36px);
  padding: 16px; border-radius: 16px;
  background: var(--bg-elev); color: var(--text);
  font-size: 15px; font-weight: 600; border: 1px solid var(--line); cursor: pointer;
}
.linkbtn {
  background: transparent; border: 0; color: var(--accent);
  font-size: 14px; padding: 10px; cursor: pointer;
}

/* Toast / inline alerts */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--text); padding: 12px 18px; border-radius: 14px;
  font-size: 14px; z-index: 100; max-width: 90vw;
}
.toast.ok { border-color: var(--success); }
.toast.err { border-color: var(--danger); }

/* Splash / welcome */
.welcome {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  align-items: center; padding: 40px 28px; text-align: center;
}
.welcome .logo {
  width: 96px; height: 96px; margin-bottom: 28px;
}
.welcome h1 { font-size: 42px; font-weight: 700; letter-spacing: -0.03em; margin: 0 0 10px; }
.welcome h1 .dot { color: var(--accent); }
.welcome p { color: var(--text-dim); font-size: 17px; line-height: 1.5; max-width: 320px; }
.welcome .feat {
  display: flex; gap: 24px; margin: 28px 0 12px; color: var(--text-dim); font-size: 13px;
  flex-wrap: wrap; justify-content: center;
}
.welcome .feat span { display: flex; align-items: center; gap: 6px; }

/* Transaction list */
.tx-list { padding: 0 18px; }
.tx {
  display: flex; align-items: center; padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.tx:last-child { border-bottom: 0; }
.tx .ico {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--bg-soft); display: flex; align-items: center; justify-content: center;
  margin-right: 12px; flex-shrink: 0;
}
.tx .meta { flex: 1; min-width: 0; }
.tx .meta .t { font-weight: 600; font-size: 15px; }
.tx .meta .s { color: var(--text-dim); font-size: 12px; margin-top: 2px; font-family: "SF Mono", ui-monospace, monospace; }
.tx .amt { font-weight: 700; font-size: 16px; text-align: right; flex-shrink: 0; }
.tx .amt.in { color: var(--success); }
.tx .amt.out { color: var(--text); }

/* Back button */
.back {
  background: transparent; border: 0; color: var(--text-dim);
  padding: 10px 14px; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.back:active { color: var(--text); }

/* PIN screen */
.pin-screen {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 24px;
}
.pin-dots {
  display: flex; justify-content: center; gap: 18px; margin: 24px 0 32px;
}
.pin-dots .dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg-soft); border: 1px solid var(--line);
}
.pin-dots .dot.on { background: var(--accent); border-color: var(--accent); }

/* Merchant mode */
.mode-banner {
  background: var(--accent-soft); color: var(--accent);
  padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 600;
  margin: 0 18px 8px; text-align: center;
}

/* ---- Native MultipeerConnectivity tap flow ---- */
.tap-stage { align-items: center; justify-content: space-between; padding-bottom: 28px; }
.tap-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px 28px; text-align: center; gap: 14px; width: 100%;
}
.tap-title {
  font-size: 22px; font-weight: 700; letter-spacing: -0.01em; color: var(--text);
  margin-top: 18px; max-width: 320px;
}
.tap-sub { color: var(--text-dim); font-size: 15px; max-width: 320px; line-height: 1.45; }
.tap-hash {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  color: var(--text-dim); font-size: 11px; word-break: break-all; padding: 6px 22px;
  opacity: 0.6;
}
.tap-foot { padding: 0 0 10px; }

/* Pulse rings */
.tap-pulse {
  position: relative; width: 180px; height: 180px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.tap-pulse.success { color: var(--success); }
.tap-pulse .ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid currentColor;
}
.tap-pulse .ring.outer {
  animation: pulse-ring-outer 1.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
  opacity: 0.55;
}
.tap-pulse .ring.inner {
  inset: 22px;
  animation: pulse-ring-inner 1.2s ease-in-out infinite;
  opacity: 0.85;
}
.tap-pulse .core {
  width: 70px; height: 70px; border-radius: 50%;
  background: currentColor; opacity: 0.18;
  box-shadow: 0 0 24px currentColor;
}
@keyframes pulse-ring-outer {
  0%   { transform: scale(1);    opacity: 0.6; }
  80%  { transform: scale(1.55); opacity: 0;   }
  100% { transform: scale(1.6);  opacity: 0;   }
}
@keyframes pulse-ring-inner {
  0%, 100% { transform: scale(1);    opacity: 0.7; }
  50%      { transform: scale(1.1);  opacity: 1;   }
}

/* Stage crossfade */
.stage-fade {
  animation: stage-fade-in 280ms ease-out;
}
@keyframes stage-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* Check / cross SVG */
.tap-check {
  width: 104px; height: 104px;
  color: var(--success);
  animation: check-pop 420ms cubic-bezier(0.2, 1.2, 0.5, 1) both;
}
.tap-check.large { width: 128px; height: 128px; }
.tap-check.fail { color: var(--danger); }
.tap-check path {
  stroke-dasharray: 80;
  stroke-dashoffset: 80;
  animation: check-draw 500ms 120ms ease-out forwards;
}
.tap-check.fail path {
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
}
@keyframes check-draw {
  to { stroke-dashoffset: 0; }
}
@keyframes check-pop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* Signing spinner */
.tap-spinner {
  width: 72px; height: 72px; position: relative;
}
.tap-spinner span {
  position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Receive — QR halo + peer status */
.qr-frame-halo {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 18px;
}
.qr-frame-halo .halo-ring {
  position: absolute; inset: 0; border-radius: 32px;
  border: 2px solid var(--accent);
  pointer-events: none;
  opacity: 0;
}
.qr-frame-halo.dual .halo-ring.outer {
  animation: halo-outer 2.2s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}
.qr-frame-halo.dual .halo-ring.inner {
  inset: 8px; border-radius: 28px;
  animation: halo-inner 1.6s ease-in-out infinite;
}
.qr-frame-halo.linked .halo-ring { border-color: var(--success); }
@keyframes halo-outer {
  0%   { transform: scale(1);    opacity: 0.35; }
  80%  { transform: scale(1.08); opacity: 0;    }
  100% { transform: scale(1.1);  opacity: 0;    }
}
@keyframes halo-inner {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.75; }
}

.receive-status {
  margin-top: 18px; padding: 8px 14px;
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 14px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 999px;
  transition: color 160ms ease, border-color 160ms ease;
}
.receive-status.ok { color: var(--success); border-color: var(--success); }
.status-led {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s infinite;
}
.status-led.ok {
  background: var(--success);
  animation: none;
}

/* Pay — dual-channel tap + scan */
.dual-search { padding-bottom: 20px; }
.dual-head {
  padding: 8px 22px 14px; text-align: center;
}
.dual-head .tap-title { margin-top: 6px; }
.dual-grid {
  display: grid; grid-template-columns: 1fr; gap: 14px;
  padding: 4px 18px 18px; flex: 1;
}
@media (min-width: 520px) {
  .dual-grid { grid-template-columns: 1fr 1fr; }
}
.dual-cell {
  position: relative;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 18px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: opacity 220ms ease, border-color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
  min-height: 220px;
}
.dual-cell.dim {
  opacity: 0; transform: scale(0.96);
  pointer-events: none;
}
.dual-cell.won {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 12px 40px rgba(91, 108, 255, 0.28);
}
.dual-label {
  font-size: 15px; font-weight: 600; color: var(--text); margin-top: 6px;
}
.dual-sub {
  font-size: 12px; color: var(--text-dim);
}

.dual-pulse {
  position: relative; width: 120px; height: 120px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); margin-top: 6px;
}
.dual-pulse .ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid currentColor;
}
.dual-pulse .ring.outer {
  animation: pulse-ring-outer 1.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
  opacity: 0.55;
}
.dual-pulse .ring.inner {
  inset: 16px;
  animation: pulse-ring-inner 1.2s ease-in-out infinite;
  opacity: 0.85;
}
.dual-pulse .core {
  width: 46px; height: 46px; border-radius: 50%;
  background: currentColor; opacity: 0.18;
  box-shadow: 0 0 18px currentColor;
}

.dual-scanner {
  position: relative; width: 100%; aspect-ratio: 1;
  max-width: 160px;
  background: #000; border-radius: 18px; overflow: hidden;
  margin-top: 2px;
}
.dual-scanner video { width: 100%; height: 100%; object-fit: cover; }
.dual-reticle {
  position: absolute; inset: 16%;
  border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28) inset;
}
