:root {
  --bg: var(--tg-theme-bg-color, #f2f4ef);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #101711);
  --muted: var(--tg-theme-hint-color, #6f786f);
  --accent: var(--tg-theme-button-color, #ccff38);
  --accent-text: var(--tg-theme-button-text-color, #101710);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --danger: #b42318;
  --danger-bg: #fff0ed;
  --warning-bg: #fff8dc;
  --radius: 24px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 15% -5%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 35%),
    var(--bg);
}

button, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar, .brand, footer { display: flex; align-items: center; }
.topbar { justify-content: space-between; margin-bottom: 38px; }
.brand { gap: 10px; font-weight: 800; letter-spacing: -0.02em; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  color: #101710;
  background: var(--accent);
  font-weight: 900;
}

.status-pill {
  max-width: 50%;
  overflow: hidden;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  font-size: 12px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main { flex: 1; }
.step[hidden], .error-banner[hidden] { display: none; }
.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 9vw, 48px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.lead { margin: 16px 0 0; color: var(--muted); font-size: 16px; line-height: 1.5; }
.hero-copy { margin-bottom: 28px; }

.scanner-card, .receipt-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 18px 50px color-mix(in srgb, var(--text) 8%, transparent);
}

.scanner-card { padding: 18px; }
.scanner-frame {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  margin-bottom: 14px;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(135deg, #1c291c, #0d120d);
}

.scanner-frame::after {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent);
  animation: scan 2.6s ease-in-out infinite;
}

@keyframes scan { 0%, 100% { top: 23%; opacity: .55; } 50% { top: 76%; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .scanner-frame::after { animation: none; top: 50%; } }

.corner { position: absolute; width: 32px; height: 32px; border-color: var(--accent); border-style: solid; z-index: 1; }
.corner-tl { top: 18px; left: 18px; border-width: 3px 0 0 3px; border-radius: 8px 0 0; }
.corner-tr { top: 18px; right: 18px; border-width: 3px 3px 0 0; border-radius: 0 8px 0 0; }
.corner-bl { bottom: 18px; left: 18px; border-width: 0 0 3px 3px; border-radius: 0 0 0 8px; }
.corner-br { right: 18px; bottom: 18px; border-width: 0 3px 3px 0; border-radius: 0 0 8px; }

.qr-glyph { display: grid; grid-template-columns: repeat(3, 13px); gap: 5px; opacity: .42; }
.qr-glyph span { width: 13px; height: 13px; border-radius: 3px; background: #fff; }
.qr-glyph span:nth-child(2), .qr-glyph span:nth-child(4), .qr-glyph span:nth-child(9) { opacity: .18; }

.button {
  width: 100%;
  min-height: 52px;
  padding: 14px 18px;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 800;
  transition: transform .15s ease, opacity .15s ease;
}
.button:active { transform: scale(.985); }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button + .button { margin-top: 9px; }
.button svg { width: 20px; height: 20px; margin-right: 8px; vertical-align: -4px; fill: currentColor; }
.button-primary { color: var(--accent-text); background: var(--accent); }
.button-secondary { color: var(--text); background: color-mix(in srgb, var(--text) 8%, var(--surface)); }
.button-quiet { min-height: 42px; color: var(--muted); background: transparent; font-size: 14px; }
.upload-picker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.gallery-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.upload-picker[aria-disabled="true"] { cursor: not-allowed; opacity: .48; }

.manual-entry { margin-top: 14px; color: var(--muted); font-size: 14px; }
.manual-entry summary { padding: 10px 4px; cursor: pointer; text-align: center; }
.manual-entry form { padding-top: 12px; }
.manual-entry label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 700; }
textarea {
  width: 100%;
  resize: vertical;
  margin-bottom: 9px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.error-banner {
  margin-bottom: 16px;
  padding: 13px 15px;
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  border-radius: 14px;
  color: var(--danger);
  background: var(--danger-bg);
  font-size: 14px;
  line-height: 1.4;
}

.back-button { margin: 0 0 28px; padding: 0; border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.receipt-card { margin: 24px 0 14px; padding: 26px 22px 18px; text-align: center; }
.merchant-avatar {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 17px;
  color: #101710;
  background: var(--accent);
  font-size: 23px;
  font-weight: 900;
}
.receipt-label { margin: 0 0 6px; color: var(--muted); font-size: 12px; }
.receipt-card h2 { margin: 0; font-size: 21px; letter-spacing: -0.03em; }
.amount { margin: 20px 0 24px; font-size: 42px; font-weight: 900; letter-spacing: -0.055em; }
.receipt-details { margin: 0; border-top: 1px solid var(--line); font-size: 13px; text-align: left; }
.receipt-details div { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.receipt-details div:last-child { border-bottom: 0; }
.receipt-details dt { color: var(--muted); }
.receipt-details dd { min-width: 0; margin: 0; overflow: hidden; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.notice { margin: 0 0 14px; padding: 13px 15px; border-radius: 14px; background: var(--warning-bg); color: #594800; font-size: 13px; line-height: 1.4; }
.fine-print { color: var(--muted); font-size: 12px; line-height: 1.45; text-align: center; }

.result-step { padding-top: 13vh; text-align: center; }
.result-icon { display: grid; place-items: center; width: 76px; height: 76px; margin: 0 auto 22px; border-radius: 26px; color: #101710; background: var(--accent); font-size: 38px; font-weight: 900; transform: rotate(-4deg); }
.result-step .lead { margin-bottom: 14px; }
.transaction-id { margin: 0 0 26px; color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; word-break: break-all; }

footer { justify-content: center; gap: 8px; margin-top: 28px; color: var(--muted); font-size: 12px; }
.shield { color: var(--accent); -webkit-text-stroke: 1px color-mix(in srgb, var(--text) 25%, transparent); }

@media (prefers-color-scheme: dark) {
  :root:not([style*="--tg-theme-bg-color"]) {
    --bg: #101510;
    --surface: #1a211a;
    --text: #f4f7f1;
    --muted: #9ca89b;
    --danger-bg: #351816;
    --warning-bg: #302b12;
  }
  .notice { color: #f4dc79; }
}
