:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --ink: #111426;
  --ink-2: #4a5068;
  --ink-3: #8087a2;
  --line: #e6e8f2;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --accent: #06b6d4;
  --ok: #059669;
  --ok-bg: #e7f8f1;
  --warn-bg: #fff6e0;
  --err: #dc2626;
  --err-bg: #fdecec;
  --red: #c8102e;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(17, 20, 38, .04), 0 12px 32px -12px rgba(41, 37, 120, .16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
code, kbd { font-family: var(--mono); font-size: .88em; background: #eef0fa; padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--ink-3); }

/* ---------- background ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .5; }
.b1 { width: 480px; height: 480px; background: #c7d2fe; top: -140px; left: -120px; }
.b2 { width: 420px; height: 420px; background: #a5f3fc; top: 120px; right: -140px; }
.b3 { width: 460px; height: 460px; background: #fbcfe8; bottom: -180px; left: 25%; opacity: .4; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(20px, calc((100% - 1040px) / 2));
  background: rgba(244, 245, 251, .72);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid rgba(230, 232, 242, .8);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.01em; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 14px -4px rgba(79, 70, 229, .55);
}
.brand-name b { font-weight: 800; color: var(--brand); margin-left: 1px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px;
}
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- layout ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 20px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.wrap > * { min-width: 0; }
html, body { max-width: 100%; overflow-x: clip; }

.hero { text-align: center; padding: 22px 0 8px; }
.eyebrow {
  display: inline-block; font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--brand); background: #eceafe; padding: 5px 12px; border-radius: 999px; margin-bottom: 16px;
}
.hero h1 { font-size: clamp(28px, 5.2vw, 46px); line-height: 1.12; letter-spacing: -.03em; font-weight: 800; max-width: 760px; margin: 0 auto 14px; }
.grad { background: linear-gradient(100deg, var(--brand), var(--brand-2) 55%, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--ink-2); max-width: 620px; margin: 0 auto; font-size: clamp(15px, 2vw, 17px); }
.flow { list-style: none; padding: 0; margin: 22px auto 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.flow li {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; color: var(--ink-2);
  background: rgba(255, 255, 255, .75); border: 1px solid var(--line); padding: 6px 14px 6px 7px; border-radius: 999px;
}
.flow b { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }

.card {
  background: var(--surface); border: 1px solid rgba(230, 232, 242, .9); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(18px, 3vw, 30px);
}
.reveal:not([hidden]) { animation: rise .5s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.step-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.step-head > div { flex: 1; min-width: 0; }
.step-head h2 { font-size: 21px; letter-spacing: -.02em; line-height: 1.25; }
.step-head p { font-size: 14px; }
.step-num {
  flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 8px 16px -6px rgba(79, 70, 229, .6);
}
.step-num.ok { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 8px 16px -6px rgba(5, 150, 105, .55); }

.badge { flex: none; font-size: 11.5px; font-weight: 800; letter-spacing: .08em; padding: 5px 11px; border-radius: 999px; }
.badge-static { background: var(--warn-bg); color: #9a6200; }
.badge-dynamic { background: var(--ok-bg); color: var(--ok); }

/* ---------- buttons ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 14px; padding: 11px 18px; font-weight: 650; font-size: 14.5px;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible, .source-card:focus-visible, .tab:focus-visible, .chip:focus-visible, .seg-btn:focus-visible {
  outline: 3px solid rgba(79, 70, 229, .35); outline-offset: 2px;
}
.btn.primary {
  color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 20px -8px rgba(79, 70, 229, .65);
}
.btn.primary:hover { box-shadow: 0 14px 26px -8px rgba(79, 70, 229, .75); transform: translateY(-1px); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: #c9cdf5; background: #f7f7ff; }
.btn.text { background: none; color: var(--ink-3); padding-inline: 10px; }
.btn.text:hover { color: var(--ink); }
.btn.lg { padding: 14px 24px; font-size: 16px; border-radius: 16px; width: 100%; }
@media (min-width: 560px) { .btn.lg { width: auto; min-width: 260px; } }

/* ---------- source cards ---------- */
.source-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.source-card {
  display: flex; align-items: center; gap: 16px; text-align: left; padding: 16px;
  background: #fff; border: 2px solid var(--line); border-radius: 18px;
  transition: border-color .2s, box-shadow .2s, transform .2s, background .2s;
}
.source-card:hover { border-color: #c4c8f5; transform: translateY(-2px); box-shadow: 0 14px 28px -16px rgba(79, 70, 229, .45); }
.source-card[aria-pressed="true"] { border-color: var(--brand); background: linear-gradient(180deg, #fafaff, #f3f2ff); box-shadow: 0 0 0 4px rgba(79, 70, 229, .12); }
.source-thumb {
  flex: none; width: 92px; height: 92px; border-radius: 14px; overflow: hidden; background: #f1f2fa; border: 1px solid var(--line);
  display: grid; place-items: center;
}
.source-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: center 62%; display: block; }
.source-icon { color: var(--brand); background: linear-gradient(135deg, #eef0ff, #f6f0ff); }
.source-body { display: grid; gap: 4px; min-width: 0; }
.source-title { font-weight: 750; font-size: 17px; letter-spacing: -.01em; }
.source-desc { color: var(--ink-2); font-size: 13.5px; line-height: 1.45; }
.source-tag { justify-self: start; margin-top: 4px; font-size: 11.5px; font-weight: 700; color: var(--brand); background: #eceafe; padding: 3px 10px; border-radius: 999px; }
.source-tag.alt { color: #0e7490; background: #dcf6fb; }

/* ---------- user panel ---------- */
.user-panel { margin-top: 18px; border: 1px solid var(--line); border-radius: 18px; padding: 16px; background: #fbfbfe; animation: rise .35s ease both; }
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: #eceef8; border-radius: 14px; margin-bottom: 14px; }
.tab { display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 8px 16px; border-radius: 11px; font-weight: 650; font-size: 14px; color: var(--ink-2); }
.tab.active { background: #fff; color: var(--brand); box-shadow: 0 2px 8px rgba(17, 20, 38, .08); }
.hint { margin-top: 12px; font-size: 12.8px; color: var(--ink-3); }

.camera-box {
  position: relative; width: 100%; max-width: 520px; aspect-ratio: 4 / 3; border-radius: 18px; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #1c2040, #0c0e1f); display: grid; place-items: center;
}
.camera-box video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.camera-box.live video { display: block; }
.camera-idle { color: #b9bde0; text-align: center; padding: 20px; display: grid; gap: 10px; justify-items: center; font-size: 14px; max-width: 320px; }
.camera-box.live .camera-idle { display: none; }
.scan-frame { position: absolute; inset: 14% 22%; pointer-events: none; }
.scan-frame i { position: absolute; width: 28px; height: 28px; border: 4px solid #fff; border-radius: 6px; filter: drop-shadow(0 0 6px rgba(0, 0, 0, .5)); }
.scan-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scan-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scan-frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scan-frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.scan-line { position: absolute; left: 6%; right: 6%; height: 3px; border-radius: 3px; background: linear-gradient(90deg, transparent, #22d3ee, transparent); box-shadow: 0 0 14px #22d3ee; animation: scan 2.2s ease-in-out infinite; }
@keyframes scan { 0%, 100% { top: 6%; } 50% { top: 92%; } }

.dropzone {
  display: grid; justify-items: center; gap: 6px; text-align: center; padding: 34px 18px; cursor: pointer; color: var(--ink-2);
  border: 2px dashed #c4c8f5; border-radius: 18px; background: #fff; transition: all .2s;
}
.dropzone svg { color: var(--brand); }
.dropzone strong { color: var(--ink); font-size: 16px; }
.dropzone span { font-size: 13px; color: var(--ink-3); }
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: #f5f5ff; }

/* ---------- alerts ---------- */
.alert { margin-top: 16px; padding: 12px 16px; border-radius: 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert.error { background: var(--err-bg); color: #991b1b; }
.alert.info { background: #eef2ff; color: #3730a3; }
.alert.success { background: var(--ok-bg); color: #047857; }
.alert .spin { flex: none; width: 16px; height: 16px; margin-top: 3px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- info ---------- */
.info-layout { display: grid; grid-template-columns: 130px 1fr; gap: 22px; align-items: start; }
.info-thumb { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #fff; aspect-ratio: 1; display: grid; place-items: center; }
.info-thumb img { width: 100%; height: 100%; object-fit: cover; }
.info-grid { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 24px; }
.info-grid > div { min-width: 0; }
.info-grid dt { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.info-grid dd { margin: 2px 0 0; font-weight: 650; font-size: 16px; overflow-wrap: anywhere; }
.info-grid dd.mono { font-family: var(--mono); font-size: 14.5px; }

/* ---------- step 3 ---------- */
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 8px; }
.money, .fee-input {
  display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 6px 16px;
  transition: border-color .2s, box-shadow .2s;
}
.money:focus-within, .fee-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(79, 70, 229, .12); }
.money-prefix { font-weight: 800; color: var(--ink-3); font-size: 18px; }
.money input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; font-size: clamp(26px, 5vw, 36px); font-weight: 800; letter-spacing: -.02em; padding: 8px 0; color: var(--ink); }
.fee-input { margin-top: 12px; padding: 2px 14px; max-width: 280px; }
.fee-input input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; font-size: 18px; font-weight: 700; padding: 10px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; font-weight: 650; font-size: 13.5px; color: var(--ink-2); transition: all .15s; }
.chip:hover { border-color: var(--brand); color: var(--brand); background: #f5f5ff; }

.fee-box { margin-top: 18px; border: 1px dashed #cfd3f0; border-radius: 16px; padding: 12px 16px; background: #fbfbfe; }
.fee-box summary { cursor: pointer; font-weight: 650; font-size: 14px; list-style: none; display: flex; gap: 8px; align-items: center; }
.fee-box summary::-webkit-details-marker { display: none; }
.fee-box summary::before { content: "+"; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; background: #eceafe; color: var(--brand); font-weight: 800; transition: transform .2s; }
.fee-box[open] summary::before { content: "–"; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: #eceef8; border-radius: 13px; margin-top: 12px; }
.seg-btn { border: 0; background: transparent; padding: 7px 14px; border-radius: 10px; font-weight: 650; font-size: 13.5px; color: var(--ink-2); }
.seg-btn.active { background: #fff; color: var(--brand); box-shadow: 0 2px 8px rgba(17, 20, 38, .08); }

.sum { margin-top: 18px; display: grid; gap: 8px; padding: 14px 18px; border-radius: 16px; background: linear-gradient(135deg, #f5f5ff, #f0fbff); border: 1px solid #e3e5fb; max-width: 460px; }
.sum > div { display: flex; justify-content: space-between; gap: 12px; font-size: 14.5px; color: var(--ink-2); }
.sum b { color: var(--ink); font-variant-numeric: tabular-nums; }
.sum-total { padding-top: 8px; border-top: 1px dashed #cfd3f0; font-weight: 700; color: var(--ink) !important; font-size: 16px !important; }
.sum-total b { color: var(--brand); font-size: 18px; }
.error-text { color: var(--err); font-size: 13.5px; margin-top: 10px; font-weight: 600; }

/* ---------- result ---------- */
.result-layout { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 28px; align-items: start; }
.result-qr { position: sticky; top: 80px; }
#resultCanvas { width: 100%; height: auto; display: block; border-radius: 20px; border: 1px solid var(--line); box-shadow: 0 20px 40px -20px rgba(41, 37, 120, .35); background: #fff; }
.result-side h3 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 10px; }
.result-side h3:not(:first-child) { margin-top: 22px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl td { padding: 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl td:last-child { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.tbl tr.total td { border-bottom: 0; font-weight: 800; font-size: 16px; color: var(--brand); padding-top: 12px; }
.tbl.changes td:last-child { font-weight: 500; }
.tag-chip { display: inline-block; font-family: var(--mono); font-size: 12px; font-weight: 700; background: #eceafe; color: var(--brand); padding: 1px 8px; border-radius: 7px; margin-right: 8px; }
.arrow { color: var(--ink-3); margin: 0 4px; }
.to { color: var(--ok); font-weight: 700; }
.payload {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7; word-break: break-all; padding: 14px 16px; border-radius: 14px;
  background: #0f1226; color: #aab0d6; max-height: 190px; overflow: auto;
}
.payload .seg-n { color: #aab0d6; }
.payload .seg-h { color: #0f1226; background: #67e8f9; border-radius: 4px; padding: 1px 3px; font-weight: 700; }
.payload .seg-crc { color: #0f1226; background: #fcd34d; border-radius: 4px; padding: 1px 3px; font-weight: 700; }
.muted-payload { background: #f1f2fa; color: #4a5068; margin-top: 10px; }
.old-payload { margin-top: 10px; font-size: 13.5px; color: var(--ink-2); }
.old-payload summary { cursor: pointer; font-weight: 600; }

.note { font-size: 13px; color: var(--ink-2); background: rgba(255, 255, 255, .7); border: 1px solid var(--line); border-radius: 16px; padding: 14px 18px; }
.foot { max-width: 1040px; margin: 0 auto; padding: 4px 20px 36px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; z-index: 50;
  background: #111426; color: #fff; padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 16px 32px -10px rgba(0, 0, 0, .4); transition: all .3s cubic-bezier(.2, .8, .2, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .result-layout { grid-template-columns: 1fr; }
  .result-qr { position: static; max-width: 380px; margin: 0 auto; width: 100%; }
}
@media (max-width: 680px) {
  .source-grid { grid-template-columns: 1fr; }
  .info-layout { grid-template-columns: 1fr; }
  .info-thumb { width: 110px; }
  .info-grid { grid-template-columns: 1fr 1fr; gap: 12px 16px; }
  .pill-ok { font-size: 11.5px; padding: 5px 10px; }
  .step-head h2 { font-size: 18px; }
  .btn-row .btn { flex: 1 1 auto; }
}
@media (max-width: 420px) {
  .info-grid { grid-template-columns: 1fr; }
  .brand-name { font-size: 15px; }
  .source-thumb { width: 72px; height: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media print { .topbar, .bg, .btn-row, .note, .foot { display: none !important; } }
