:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #1a2540;
  --line: #22304f;
  --text: #e6edf7;
  --muted: #8b98b8;
  --accent: #4f8cff;
  --accent-2: #22d3ee;
  --danger: #ff5d73;
  --ok: #34d399;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(1200px 500px at 50% -200px, #16233f 0%, transparent 70%),
    var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

input, select, textarea, button { font-family: inherit; }

/* ── 顶栏 ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 17px; letter-spacing: 0.5px; }

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.chip.on { color: var(--ok); }

/* ── 布局 ── */
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px calc(96px + env(safe-area-inset-bottom));
}

.view h2, .view h3 { margin: 6px 0 14px; font-size: 20px; }

.hero { text-align: center; padding: 34px 0 6px; color: var(--muted); }
.hero-icon { font-size: 64px; line-height: 1; margin-bottom: 10px; }
.hero p { margin: 0; font-size: 14px; line-height: 1.7; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}

.field-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }

.input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid #2a3a5f;
  border-radius: 10px;
  color: var(--text);
  padding: 12px;
  font-size: 16px; /* 防止 iOS 聚焦时缩放 */
  outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.6; }

.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.6; }
.center { text-align: center; }

/* ── 按钮 ── */
.btn {
  display: block;
  width: 100%;
  margin: 10px 0;
  padding: 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid #2a3a5f;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.btn:active { transform: scale(0.985); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #061018;
  font-weight: 700;
}
.btn.big { padding: 16px; font-size: 17px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); border-color: #4a2430; }
.btn.sm {
  width: auto;
  display: inline-block;
  padding: 8px 14px;
  font-size: 14px;
  margin: 0;
}

.row { display: flex; gap: 8px; align-items: center; }
.flex1 { flex: 1; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  margin: 16px auto 0;
  display: block;
  cursor: pointer;
}

/* ── 预览 / 进度 ── */
.preview { margin: 14px 0; }
.crop-stage {
  position: relative;
  margin: 0 auto;
  line-height: 0;
}
.preview img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 12px;
  background: #000;
  border: 1px solid var(--line);
}
/* 手动裁切 */
.crop-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#cropDim { fill: rgba(8, 12, 24, 0.55); }
#cropPoly {
  fill: rgba(79, 140, 255, 0.15);
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.crop-handle {
  position: absolute;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%);
  background: rgba(79, 140, 255, 0.3);
  border: 2px solid var(--accent);
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
  z-index: 5;
}
.crop-handle:active {
  cursor: grabbing;
  background: rgba(79, 140, 255, 0.55);
}
.preview-actions { margin-top: 8px; flex-wrap: wrap; }

.progress { margin: 14px 0; }
.progress-bar {
  height: 6px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
  border-radius: 3px;
}
#progressText { color: var(--muted); font-size: 13px; margin-top: 8px; text-align: center; }

/* ── 名片表单 ── */
.card-form {
  display: grid;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card-form label { display: block; }
.card-form label span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 5px;
}
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── 列表 ── */
.list-tools { margin-bottom: 12px; }
.list-tools .row { margin-top: 10px; flex-wrap: wrap; }

.card-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.card-item:active { background: var(--panel-2); }
.ci-main { min-width: 0; flex: 1; }
.ci-name { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-title { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 6px; }
.ci-company { font-size: 14px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-contact { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-copy {
  margin-left: auto;
  flex: none;
  background: transparent;
  border: 1px solid #2a3a5f;
  border-radius: 8px;
  color: var(--muted);
  padding: 9px 11px;
  font-size: 14px;
  cursor: pointer;
}

.empty { text-align: center; color: var(--muted); padding: 48px 0; font-size: 14px; line-height: 1.8; }

/* ── 拍摄贴士 ── */
.tips-panel { margin-top: 14px; }
.panel-title { margin: 0 0 8px; font-size: 15px; color: var(--text); }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.9; }

/* ── 拍摄质量提示横幅 ── */
.quality-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(255, 196, 87, 0.1);
  border: 1px solid rgba(255, 196, 87, 0.45);
  border-radius: 10px;
}
.quality-text { flex: 1; font-size: 13px; line-height: 1.55; color: #ffd48a; }

/* ── 重复名片提示 ── */
.dup-banner {
  margin: 14px 0 0;
  padding: 12px;
  background: rgba(79, 140, 255, 0.1);
  border: 1px solid rgba(79, 140, 255, 0.5);
  border-radius: 12px;
}
.dup-text { font-size: 13px; line-height: 1.6; color: #9fc0ff; margin-bottom: 10px; }

/* ── 名片照片（卡页正/背双槽 + 列表缩略图）── */
.card-photo-area {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 420px;
  margin: 0 auto 14px;
}
.photo-slot {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0d1526;
}
.photo-box {
  position: relative;
  aspect-ratio: 3 / 2;
  background: #0a1120;
}
.photo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-box img:not([src]) { display: none; }
.photo-ph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: rgba(255, 255, 255, 0.28);
}
.photo-actions {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: flex;
  gap: 4px;
}
.photo-act {
  font-size: 11px;
  line-height: 1;
  padding: 5px 8px;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}
.photo-act-del { background: rgba(160, 40, 40, 0.8); }
.photo-label {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
  padding: 4px 8px;
}
.card-photo-hint {
  position: absolute;
  right: 4px;
  bottom: 26px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(0, 0, 0, 0.45);
  padding: 2px 8px;
  border-radius: 8px;
  pointer-events: none;
}
.ci-thumb {
  width: 56px;
  height: 36px;
  object-fit: cover;
  object-position: center;
  border-radius: 6px;
  flex: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #0d1526;
}
.ci-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  opacity: 0.5;
}

/* ── 识别后保留源图（紧凑模式）── */
.preview.is-compact .crop-stage {
  max-width: 180px;
  margin: 0 auto 8px;
  cursor: zoom-in;
}
.preview.is-compact .crop-stage img { max-width: 180px; height: auto; }

/* ── 底部标签栏 ── */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  position: relative;
}
.tab-icon { font-size: 22px; line-height: 1; }
.tabbar a.active { color: var(--text); }

.badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 30px);
  background: var(--accent);
  color: #061018;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 6px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: #22304f;
  border: 1px solid #35507e;
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: 86vw;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
