:root {
  --bg: #0b0f17;
  --surface: rgba(22, 28, 40, 0.72);
  --surface-solid: #161c28;
  --text: #eef2f8;
  --muted: #8b95a7;
  --accent: #5b8cff;
  --accent-2: #8a5bff;
  --danger: #ff5b6e;
  --ok: #38d39f;
  --radius: 20px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: 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: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
}

.app { position: fixed; inset: 0; overflow: hidden; }

/* ---------- Scanner ---------- */
.scanner { position: absolute; inset: 0; background: #000; }
#video { width: 100%; height: 100%; object-fit: cover; }

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(var(--safe-t) + 14px) 18px calc(var(--safe-b) + 18px);
  background:
    radial-gradient(130% 80% at 50% 42%, transparent 38%, rgba(0,0,0,0.55) 100%);
  pointer-events: none;
}
.overlay > * { pointer-events: auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; }
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 16px; letter-spacing: .2px;
  background: rgba(0,0,0,.3); backdrop-filter: blur(10px);
  padding: 8px 14px; border-radius: 999px;
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 10px var(--ok);
  animation: pulse 1.8s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  color: #fff; border: 0; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit;
  padding: 8px 14px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(91,140,255,.4);
  animation: pulse 2.4s infinite;
}
.pill-btn:active { transform: scale(.94); }

.ios-steps { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 12px; }
.ios-steps li {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.05); border-radius: 14px; padding: 14px;
  font-size: 15px; line-height: 1.4;
}
.ios-steps .ios-ico { font-size: 22px; }

/* Viewfinder */
.viewfinder { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.frame {
  position: relative; width: min(72vw, 300px); aspect-ratio: 1;
  border-radius: 28px;
}
.corner { position: absolute; width: 34px; height: 34px; border: 4px solid #fff; }
.corner.tl { top:0; left:0; border-right:0; border-bottom:0; border-top-left-radius:20px; }
.corner.tr { top:0; right:0; border-left:0; border-bottom:0; border-top-right-radius:20px; }
.corner.bl { bottom:0; left:0; border-right:0; border-top:0; border-bottom-left-radius:20px; }
.corner.br { bottom:0; right:0; border-left:0; border-top:0; border-bottom-right-radius:20px; }

.laser {
  position: absolute; left: 8%; right: 8%; top: 8%; height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  box-shadow: 0 0 14px var(--accent);
  animation: scan 2.4s cubic-bezier(.4,0,.2,1) infinite;
}
@keyframes scan { 0%{top:8%} 50%{top:88%} 100%{top:8%} }

.frame.locked .corner { border-color: var(--ok); transition: border-color .2s; }
.frame.locked .laser { opacity: 0; }

.hint {
  margin: 0; font-size: 14px; color: #dfe5f0;
  background: rgba(0,0,0,.35); backdrop-filter: blur(8px);
  padding: 8px 16px; border-radius: 999px;
}

/* Bottom bar */
.bottombar { display: flex; align-items: center; justify-content: space-between; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; background: rgba(255,255,255,.1); border: 0;
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  backdrop-filter: blur(8px); transition: transform .15s, background .2s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.big {
  flex-direction: column; gap: 3px; width: 64px; height: 64px;
  border-radius: 18px; font-size: 11px; font-weight: 600;
}
.shutter {
  width: 72px; height: 72px; border-radius: 50%; cursor: pointer;
  color: #fff; border: 4px solid rgba(255,255,255,.85);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 28px rgba(91,140,255,.45); transition: transform .15s;
}
.shutter:active { transform: scale(.92); }

/* ---------- State / permission ---------- */
.state {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(120% 120% at 50% 0%, #141b2b, #0b0f17);
}
.state-card { text-align: center; max-width: 320px; }
.state-icon { font-size: 54px; margin-bottom: 8px; }
.state-card h2 { margin: 10px 0 6px; font-size: 20px; }
.state-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.5; }

/* ---------- Buttons ---------- */
.btn {
  width: 100%; padding: 15px 18px; border: 0; border-radius: 14px;
  font-size: 15px; font-weight: 600; cursor: pointer; color: #fff;
  transition: transform .15s, opacity .2s; font-family: inherit;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 24px rgba(91,140,255,.35); }
.btn.ghost { background: rgba(255,255,255,.08); color: var(--text); }
.btn.tiny { width: auto; padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn.danger { background: rgba(255,91,110,.15); color: var(--danger); }

/* ---------- Sheets ---------- */
.sheet-scrim {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
@keyframes fade { from{opacity:0} to{opacity:1} }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 11;
  background: var(--surface-solid);
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(var(--safe-b) + 22px);
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  animation: slideUp .32s cubic-bezier(.16,1,.3,1);
  max-height: 85vh; overflow-y: auto;
}
.sheet.tall { min-height: 55vh; }
@keyframes slideUp { from{ transform: translateY(100%);} to{ transform: translateY(0);} }

.sheet-handle {
  width: 42px; height: 5px; border-radius: 3px;
  background: rgba(255,255,255,.2); margin: 6px auto 16px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 18px; }

.result-type { margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(91,140,255,.16); color: var(--accent);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.result-value {
  background: rgba(255,255,255,.05); border-radius: 14px; padding: 16px;
  font-size: 15px; line-height: 1.5; word-break: break-word;
  margin-bottom: 18px; max-height: 32vh; overflow-y: auto;
  border: 1px solid rgba(255,255,255,.06);
}
.result-value a { color: var(--accent); }
.result-actions { display: grid; gap: 10px; margin-bottom: 10px; }

/* ---------- History ---------- */
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.04); border-radius: 14px; padding: 12px 14px;
  cursor: pointer; transition: background .2s;
}
.history-item:active { background: rgba(255,255,255,.09); }
.history-item .h-ico { font-size: 20px; }
.history-item .h-body { flex: 1; min-width: 0; }
.history-item .h-val { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* ---------- Toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 90px); z-index: 20;
  transform: translateX(-50%);
  background: rgba(20,26,38,.95); color: #fff; padding: 11px 18px;
  border-radius: 999px; font-size: 14px; backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: toastIn .25s ease;
  border: 1px solid rgba(255,255,255,.08);
}
@keyframes toastIn { from{ opacity:0; transform: translate(-50%, 10px);} to{ opacity:1; transform: translate(-50%,0);} }

[hidden] { display: none !important; }
