:root {
  --bg: #f2f2f7;
  --card: #fff;
  --text: #1c1c1e;
  --hint: #8e8e93;
  --link: #2f74d0;
  --btn: #2f74d0;
  --btn-text: #fff;
  --danger: #d92d20;
  --line: #e5e5ea;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --hint: #8e8e93;
    --link: #6cb0ff;
    --btn: #2f74d0;
    --btn-text: #fff;
    --danger: #ff6961;
    --line: #2c2c2e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0 auto; max-width: 560px;
  padding: 0 12px calc(28px + env(safe-area-inset-bottom));
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

.view { display: none; padding-top: 12px; }
.view.on { display: block; }
[hidden] { display: none !important; }

input, select, button, textarea { font-family: inherit; font-size: 16px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text);
}
input::placeholder { color: var(--hint); }
input:focus, select:focus { outline: 2px solid var(--link); outline-offset: -1px; }
label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--hint); }

button {
  border: none; border-radius: 10px; background: var(--btn); color: var(--btn-text);
  padding: 12px 18px; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--link); }
button.danger { background: var(--danger); }
button.block { width: 100%; margin-top: 16px; }

#topbar { display: flex; align-items: center; gap: 10px; padding: 10px 0 2px; }
#topbar span { font-weight: 600; }

.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar input { flex: 1; }
.icon { padding: 11px 14px; font-size: 18px; line-height: 1; flex: none; }
/* 比卡片之间的 8px 明显大，搜索框才不会看起来黏在列表上 */
#list { margin-top: 18px; }

/* ---------- 解锁页 ---------- */
.lock-box { max-width: 340px; margin: 12vh auto 0; text-align: center; }
.lock-box h1 { font-size: 22px; margin: 0 0 6px; }
.lock-box p { color: var(--hint); font-size: 13px; margin: 0 0 18px; }
.lock-box input { margin-bottom: 10px; text-align: center; }
.err-text { color: var(--danger) !important; min-height: 20px; margin: 10px 0 0 !important; }
.note { text-align: left; line-height: 1.6; margin-top: 22px !important; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
  position: relative; cursor: pointer; transition: opacity .12s;
}
.card:active { opacity: .6; }
.card .issuer { font-weight: 600; padding-right: 34px; }
.card .label { color: var(--hint); font-size: 13px; margin-top: 1px; padding-right: 34px; word-break: break-all; }
/* 非 30 秒周期的标记，只在少数非标准条目上出现 */
.card .tag {
  margin-left: 6px; padding: 1px 6px; border-radius: 5px; vertical-align: 1px;
  background: var(--line); color: var(--hint); font-size: 11px; font-weight: 400;
}
.card .row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 12px; }
.card .code {
  font: 600 28px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 1px; color: var(--link);
}
.card .code.bad { font-size: 15px; color: var(--danger); letter-spacing: 0; }
.menu-btn {
  position: absolute; top: 6px; right: 6px; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  color: var(--hint); font-size: 19px; border-radius: 8px; background: none; padding: 0;
}

.ring { display: flex; align-items: center; gap: 6px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring .bg { stroke: var(--line); }
.ring .fg { stroke: var(--link); stroke-linecap: round; transition: stroke-dashoffset .3s linear; }
.ring.warn .fg { stroke: var(--danger); }
.ring.warn .secs { color: var(--danger); }
.ring .secs { font-size: 12px; color: var(--hint); min-width: 24px; text-align: right; }

.skel { background: var(--card); border-radius: 14px; height: 96px; margin-bottom: 8px; position: relative; overflow: hidden; }
.skel::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(128,128,128,.14), transparent);
  animation: sweep 1.2s infinite;
}
@keyframes sweep { to { transform: translateX(100%); } }

.empty, .err { text-align: center; color: var(--hint); padding: 44px 20px; font-size: 14px; }
.err { color: var(--danger); }
.err button { display: block; margin: 14px auto 0; }

/* ---------- 表单 / 扫码 ---------- */
.tabs { display: flex; gap: 6px; background: var(--card); padding: 4px; border-radius: 10px; margin-bottom: 6px; }
.tabs button { flex: 1; padding: 9px; background: transparent; color: var(--hint); font-size: 14px; }
.tabs button.on { background: var(--btn); color: var(--btn-text); }

#scan-video { width: 100%; border-radius: 12px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
#drop-zone {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 24px 16px;
  text-align: center; transition: border-color .15s, background .15s;
}
#drop-zone.over { border-color: var(--link); background: var(--card); }
#scan-hint { color: var(--hint); font-size: 14px; margin: 0 0 14px; line-height: 1.6; }
.scan-actions { display: flex; gap: 8px; justify-content: center; }
.scan-actions button { padding: 9px 16px; font-size: 14px; border: 1px solid var(--line); }
details summary { color: var(--link); font-size: 14px; margin: 16px 0 4px; cursor: pointer; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.grid3 label { margin-top: 0; }

/* ---------- 二维码 ---------- */
.qr-wrap { background: #fff; padding: 16px; border-radius: 14px; text-align: center; }
.qr-wrap svg { width: 100%; max-width: 280px; height: auto; }
.uri {
  margin-top: 12px; padding: 10px; background: var(--card); border-radius: 10px;
  font: 12px/1.5 ui-monospace, Menlo, monospace; word-break: break-all; color: var(--hint);
}
.warn-box {
  background: var(--card); border: 1px solid var(--danger); border-radius: 10px;
  padding: 12px; font-size: 13px; color: var(--danger); margin-bottom: 12px;
}

/* ---------- 操作菜单 / 提示 ---------- */
.sheet-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: none; z-index: 10; }
.sheet-mask.on { display: block; }
.sheet {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
  max-width: 544px; margin: 0 auto;
  background: var(--card); border-radius: 14px; overflow: hidden; z-index: 11;
  transform: translateY(140%); transition: transform .22s ease;
}
.sheet.on { transform: none; }
.sheet div {
  padding: 15px; text-align: center; font-size: 16px; color: var(--link);
  border-top: 1px solid var(--line); cursor: pointer;
}
.sheet div:first-child { border-top: none; color: var(--hint); font-size: 13px; cursor: default; }
.sheet div.danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 12px);
  background: rgba(0,0,0,.85); color: #fff; padding: 9px 18px; border-radius: 20px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .18s; z-index: 20;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 批量导入 ---------- */
#import-summary, #import-skipped { color: var(--hint); font-size: 13px; line-height: 1.6; margin: 8px 0 14px; }
#import-skipped:empty { display: none; }
.import-row {
  display: flex; align-items: center; gap: 12px; margin: 0 0 8px;
  background: var(--card); border-radius: 12px; padding: 12px 14px; cursor: pointer;
}
.import-row input { width: 18px; height: 18px; flex: none; accent-color: var(--btn); }
.import-row span { display: flex; flex-direction: column; min-width: 0; }
.import-row b { font-weight: 600; }
.import-row em { color: var(--hint); font-size: 13px; font-style: normal; word-break: break-all; }

/* ---------- 对话框（替代原生 confirm / alert） ---------- */
.dialog-mask {
  position: fixed; inset: 0; z-index: 30;
  display: none; align-items: center; justify-content: center; padding: 24px;
  background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity .16s ease;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.dialog-mask.on { display: flex; }
.dialog-mask.shown { opacity: 1; }
.dialog {
  width: 100%; max-width: 340px;
  background: var(--card); color: var(--text);
  /* 深色模式下页面本身就是黑的，遮罩压不出层次，靠描边和阴影把对话框托起来 */
  border: 1px solid var(--line);
  border-radius: 16px; padding: 22px 20px 16px;
  box-shadow: 0 18px 56px rgba(0, 0, 0, .6);
  transform: scale(.94); transition: transform .16s ease;
}
.dialog-mask.shown .dialog { transform: none; }
.dialog h3 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.dialog p {
  margin: 0 0 20px; font-size: 14px; line-height: 1.6; color: var(--hint);
  word-break: break-word; white-space: pre-line;
}
.dialog-actions { display: flex; gap: 8px; }
.dialog-actions button { flex: 1; padding: 11px; font-size: 15px; }
.dialog-actions button.ghost { border: 1px solid var(--line); }
.dialog-actions button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
