:root {
  --bg: #0f1720;
  --card: #182230;
  --line: #27354a;
  --txt: #e8eef6;
  --muted: #93a3b8;
  --primary: #2563eb;
  --accent: #0ea5e9;
  --danger: #e11d48;
  --ok: #16a34a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden 属性必须能真正隐藏元素：下方若干容器设置了 display:flex/grid，
   会覆盖浏览器默认的 [hidden]{display:none}，导致遮罩层始终覆盖页面 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; }

#app { max-width: 640px; margin: 0 auto; padding: 0 0 calc(24px + env(safe-area-inset-bottom)); }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(15,23,32,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.logo {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-weight: 800; font-size: 14px; letter-spacing: .5px;
}
.brand-txt { min-width: 0; }
.title { font-size: 15px; font-weight: 700; }
.sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.counter { text-align: right; flex: none; }
.counter b { display: block; font-size: 20px; line-height: 1; color: var(--accent); }
.counter span { font-size: 11px; color: var(--muted); }

/* ---------- main ---------- */
.main { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.steps { display: flex; flex-direction: column; gap: 10px; }
.step {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.step-no {
  width: 26px; height: 26px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: #22304a; color: var(--muted);
  font-size: 13px; font-weight: 700;
}
.step.active .step-no { background: var(--accent); color: #04121e; }
.step-body { flex: 1; min-width: 0; }
.step-title { font-size: 15px; font-weight: 600; }
.step-desc { font-size: 12px; color: var(--muted); margin-top: 3px; word-break: break-all; }

.btn {
  flex: none;
  border: 0; cursor: pointer;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  color: #fff;
  background: var(--primary);
  transition: transform .1s, opacity .2s, filter .2s;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.5); }
.btn-primary { background: var(--primary); }
.btn-accent { background: var(--accent); color: #04121e; }
.btn-ghost { background: #2b3a52; }
.btn-danger { background: var(--danger); }
/* 注意：.btn-mini 必须放在颜色变体之后，否则会覆盖它们的背景色 */
.btn-mini { padding: 8px 12px; font-size: 13px; }

input[type=file] { display: none; }

/* 安卓 Chrome 对 display:none 的 file input 不弹出系统选择器，
   改为让 input 透明覆盖在按钮上，由用户直接点击按钮区域唤起选择器 */
.file-wrap { position: relative; flex: none; display: inline-block; }
.file-fake { display: inline-block; }
.file-wrap input[type=file] {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: 0;
  cursor: pointer;
}

/* ---------- card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.card-hd { font-size: 12px; color: var(--muted); margin-bottom: 8px; letter-spacing: .5px; }
.target { font-size: 13px; line-height: 1.7; }
.target b { color: var(--accent); }

.snlist {
  margin-top: 12px;
  max-height: 220px; overflow-y: auto;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.sn-chip {
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 7px;
  background: #10243a;
  border: 1px solid #1d3c5c;
  color: #b9d8f5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.sn-chip.dup { background: #2b1a22; border-color: #5c2436; color: #f0a8bb; }

/* ---------- more ---------- */
.link-btn {
  background: none; border: 0; color: var(--accent);
  font-size: 13px; cursor: pointer; padding: 0;
}
.more { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.field textarea {
  width: 100%;
  background: #0d1520; color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; font-size: 13px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ---------- result ---------- */
.result { border-color: #1d4f7a; background: #14243a; }
.result-name {
  font-size: 14px; font-weight: 600; color: var(--accent);
  word-break: break-all; line-height: 1.5;
}
.result-meta { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.7; }
.result .row-btns { margin-top: 12px; }
/* 结果卡片里的两个按钮保持各自的语义色 */
.result .btn-mini.btn-primary { background: var(--primary); color: #fff; }
.result .btn-mini.btn-accent { background: var(--accent); color: #04121e; }
.result .hint { margin-top: 10px; }

/* ---------- scan layer ---------- */
.scan-layer {
  position: fixed; inset: 0; z-index: 100;
  background: #000;
  display: flex; flex-direction: column;
}
.reader { position: absolute; inset: 0; }
.reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.reader img[alt="Info icon"] { display: none; }

.scan-frame {
  position: absolute; left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  width: 74vw; max-width: 320px; aspect-ratio: 1.5;
  border-radius: 14px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.45);
  pointer-events: none;
}
.scan-frame i {
  position: absolute; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, #38bdf8, transparent);
  animation: scanmove 2.2s linear infinite;
}
@keyframes scanmove { 0% { top: 4%; } 100% { top: 96%; } }

.scan-top {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(14px + env(safe-area-inset-top)) 14px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: linear-gradient(180deg, rgba(0,0,0,.6), transparent);
}
.scan-title { font-size: 15px; font-weight: 600; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.16); color: #fff;
  font-size: 16px; cursor: pointer;
}
.icon-btn.active { background: #facc15; color: #1a1200; }

.scan-bottom {
  position: absolute; left: 0; right: 0; bottom: calc(96px + env(safe-area-inset-bottom));
  text-align: center;
  padding: 0 16px;
}
.scan-count { font-size: 14px; color: #cbd5e1; }
.scan-count b { color: #38bdf8; font-size: 20px; }
.scan-last {
  margin-top: 6px; font-size: 13px; color: #7dd3fc;
  font-family: ui-monospace, Menlo, monospace;
  word-break: break-all;
}

.scan-actions {
  position: absolute; left: 0; right: 0;
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; justify-content: center;
}
.btn-stop {
  background: #dc2626; padding: 13px 26px; border-radius: 999px;
  font-size: 15px; font-weight: 700;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0,0,0,.88); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 200;
  max-width: 86vw; text-align: center;
}
