:root {
  --bg: #0f0f12;
  --bg-2: #16161a;
  --bg-3: #1e1e24;
  --bg-hover: #26262e;
  --border: #2a2a33;
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --muted: #71717a;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --accent-dim: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --warning: #fbbf24;
  --danger: #ef4444;
  --radius: 14px;
  --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%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
#app { min-height: 100%; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
button, input, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; flex: none; }

/* ---------- layout ---------- */
.header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: rgba(15, 15, 18, 0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header .brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.header .brand svg { color: var(--accent-2); }
.icon-btn {
  all: unset; cursor: pointer; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px; color: var(--text-2);
}
.icon-btn:active { background: var(--bg-hover); color: var(--text); }
.icon-btn.primary { background: var(--accent); color: #fff; }
.main { flex: 1; padding: 16px 16px calc(var(--safe-bottom) + 24px); }
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: calc(var(--safe-top) + 32px) 24px calc(var(--safe-bottom) + 32px); min-height: 100vh; min-height: 100dvh; }
.hero-icon { width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; background: var(--accent-dim); color: var(--accent-2); margin-bottom: 20px; }
.hero-icon svg { width: 38px; height: 38px; }
.center h2 { margin: 0 0 8px; font-size: 24px; letter-spacing: -0.02em; }
.center p { margin: 0 0 24px; color: var(--text-2); max-width: 340px; }
.stack { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; text-align: left; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  background: var(--bg-3); border: 1px solid var(--border); outline: none;
  font-size: 16px; /* stops iOS zooming in */
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.input.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.04em; }
.btn {
  all: unset; cursor: pointer; box-sizing: border-box; display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 16px; border-radius: 12px; font-weight: 600; text-align: center;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
}
.btn:active { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: #4f46e5; }
.btn.danger { color: var(--danger); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.link-btn { all: unset; cursor: pointer; color: var(--accent-2); font-weight: 600; padding: 8px; }
.error { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; text-align: left; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; text-align: left; }
details.advanced { margin: 0 0 14px; text-align: left; }
details.advanced summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 4px 0; }
details.advanced[open] summary { margin-bottom: 8px; }

/* ---------- accounts ---------- */
.search { margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 14px 16px; border-radius: var(--radius);
  background: var(--bg-2); border: 1px solid var(--border); cursor: pointer; user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
.card:active { background: var(--bg-3); }
.card .info { flex: 1; min-width: 0; }
.card .issuer { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .acct { color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .code { font: 600 30px/1.15 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.05em; margin-top: 4px; }
.card .code.warn { color: var(--warning); }
.card .copied { color: var(--success); font-size: 13px; font-weight: 600; }
.card .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width 1s linear; }
.card .bar.warn { background: var(--warning); }
.ring { width: 34px; height: 34px; flex: none; position: relative; display: grid; place-items: center; font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.ring svg { position: absolute; inset: 0; width: 34px; height: 34px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring .track { stroke: var(--bg-hover); }
.ring .prog { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.ring.warn .prog { stroke: var(--warning); }
.more { all: unset; cursor: pointer; padding: 8px; margin: -8px -6px -8px 0; color: var(--muted); border-radius: 10px; }
.more:active { background: var(--bg-hover); }
.empty { text-align: center; color: var(--text-2); padding: 48px 16px; }
.empty .hero-icon { margin: 0 auto 16px; }
.status { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; }
.status.err { color: #fca5a5; }

/* ---------- add ---------- */
.option {
  all: unset; cursor: pointer; box-sizing: border-box; width: 100%;
  display: flex; align-items: center; gap: 14px; padding: 16px; margin-bottom: 10px;
  border-radius: var(--radius); background: var(--bg-2); border: 1px solid var(--border);
}
.option:active { background: var(--bg-3); }
.option .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-dim); color: var(--accent-2); flex: none; }
.option h4 { margin: 0; font-size: 16px; }
.option p { margin: 2px 0 0; font-size: 13px; color: var(--text-2); }

/* ---------- camera ---------- */
.scanner { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; left: 50%; top: 45%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 20px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55); border: 2px solid rgba(255, 255, 255, 0.85); }
.scanner .top { position: relative; z-index: 2; padding: calc(var(--safe-top) + 14px) 16px 0; display: flex; justify-content: space-between; align-items: center; color: #fff; }
.scanner .msg { position: absolute; z-index: 2; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 40px); text-align: center; color: #fff; padding: 0 24px; }
.scanner .msg .error { display: inline-block; }

/* ---------- settings ---------- */
.section { margin-bottom: 22px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 8px 4px; }
.panel { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.panel p { margin: 0 0 12px; color: var(--text-2); font-size: 14px; }
.panel .btn + .btn { margin-top: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row select { background: var(--bg-3); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 28px); transform: translateX(-50%);
  background: #fafafa; color: #18181b; font-weight: 600; font-size: 14px; padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); z-index: 50; animation: pop 0.18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--bg-hover); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.install-tip { background: var(--accent-dim); border: 1px solid rgba(99, 102, 241, 0.35); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; color: var(--text); margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.install-tip button { all: unset; cursor: pointer; color: var(--muted); margin-left: auto; padding: 0 4px; font-size: 18px; line-height: 1; }

/* ---------- privacy page ---------- */
.doc { max-width: 680px; margin: 0 auto; padding: 32px 20px 64px; }
.doc h1 { font-size: 28px; margin: 0 0 6px; }
.doc h2 { font-size: 18px; margin: 28px 0 8px; }
.doc p, .doc li { color: var(--text-2); }
.doc li { margin-bottom: 8px; }
.doc strong { color: var(--text); }
.doc a { color: var(--accent-2); }
.doc .muted { color: var(--muted); font-size: 14px; }
