:root {
  --primary: #b15cff;
  --primary-2: #ff7eb3;
  --bg: #f6f2fb;
  --card: #ffffff;
  --text: #2c2440;
  --muted: #8b83a0;
  --line: #ece6f5;
  --guide-blue: #2f7bff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, #faf4ff 0%, #f3ecff 40%, #fdeef6 100%);
  color: var(--text);
  min-height: 100vh;
}
#app { max-width: 480px; margin: 0 auto; padding: 0 14px 40px; }

/* ===== 顶部栏 ===== */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 4px 12px;
}
.brand {
  font-size: 22px; font-weight: 800;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  letter-spacing: 1px;
}
.header-actions { display: flex; gap: 8px; }
.btn.sm { min-width: 0; padding: 8px 14px; font-size: 13px; border-radius: 10px; flex: none; }

/* ===== 卡片 ===== */
.card {
  background: var(--card); border-radius: 18px; padding: 16px;
  margin-top: 14px; box-shadow: 0 6px 20px rgba(150, 110, 200, 0.08);
}

/* ===== 预览主区 ===== */
.preview-card { padding: 14px; }
.preview-wrap {
  position: relative; width: 100%; max-width: 340px; margin: 0 auto;
  aspect-ratio: 3 / 5;
}
/* 10% 透明度缩略图背景（操作引导）*/
.thumb-bg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0.18; pointer-events: none; border-radius: 0;
  background: #faf8ff;
  transition: opacity .9s ease;
}
/* 开始操作后淡出，让客户看到自己的实际图 */
.thumb-bg.faded { opacity: 0; }
#preview {
  position: relative; width: 100%; height: 100%; aspect-ratio: 3 / 5;
  border-radius: 0;
  background: transparent;   /* 不能设不透明背景，否则会盖住后面的 .thumb-bg */
  box-shadow: 0 8px 24px rgba(80,40,120,.25);
  touch-action: none;
}
.step-hint {
  margin-top: 12px; text-align: center; font-size: 13px; font-weight: 700;
  color: var(--primary); line-height: 1.6; min-height: 20px;
}
.seg-status { font-size: 12px; color: var(--primary); margin-top: 8px; min-height: 16px; text-align: center; line-height: 1.5; }
.seg-status.error { color: #d33; font-weight: 700; background: #fff0f3; padding: 6px 10px; border-radius: 8px; }
.seg-status.ok { color: #2a8; font-weight: 700; }
.seg-status.warn { color: #b8860b; font-weight: 700; background: #fff7e6; padding: 6px 10px; border-radius: 8px; }

/* ===== 模板选择条 ===== */
.template-bar {
  display: flex; gap: 10px; margin-top: 14px; padding: 4px 2px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tpl-item {
  position: relative; flex: 0 0 auto; width: 76px; height: 100px;
  border-radius: 12px; overflow: hidden; cursor: pointer;
  border: 2px solid transparent; background: #f2ecfb;
}
.tpl-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tpl-item .tpl-name {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 10px; text-align: center; padding: 2px 0;
  background: rgba(44,36,64,.55); color: #fff;
}
.tpl-item.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(177,92,255,.25); }
.tpl-item.locked::after {
  content: "🔒"; position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; font-size: 26px;
  background: rgba(44,36,64,.45);
}
.tpl-item.locked .tpl-name { background: rgba(44,36,64,.7); }

/* ===== 按钮 ===== */
.btn {
  flex: 1; min-width: 110px; border: none; border-radius: 12px;
  padding: 12px 10px; font-size: 14px; font-weight: 700;
  background: #f0ebfa; color: var(--primary); cursor: pointer;
  transition: transform .05s ease, opacity .2s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(90deg, var(--primary), var(--primary-2)); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* 导出按钮脉动高亮（自动引导时触发）*/
@keyframes pulseDownload {
  0%   { box-shadow: 0 0 0 0 rgba(177,92,255,.55); transform: scale(1); }
  50%  { box-shadow: 0 0 0 12px rgba(177,92,255,0); transform: scale(1.04); }
  100% { box-shadow: 0 0 0 0 rgba(177,92,255,0); transform: scale(1); }
}
.btn.primary.pulse { animation: pulseDownload 1.1s ease-out 2; }

.loading {
  margin-top: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--muted); font-size: 13px;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.app-footer { text-align: center; color: var(--muted); font-size: 11px; margin-top: 22px; line-height: 1.6; }
.hidden { display: none !important; }

/* 导出预览弹层：长按图片保存到相册 */
.save-modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.74);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.save-card {
  background: #fff; border-radius: 16px; padding: 14px 14px 12px;
  max-width: 340px; width: 100%; text-align: center;
}
.save-card img {
  width: 100%; border-radius: 10px; display: block;
  /* 棋盘格底，提示透明区域 */
  background:
    conic-gradient(#e2e2e2 90deg, #f3f3f3 90deg 180deg, #e2e2e2 180deg 270deg, #f3f3f3 270deg) 0 0/22px 22px;
}
.save-tip { font-size: 13px; color: #666; margin: 12px 0 12px; }
.save-tip b { color: var(--primary); }

/* 单格微调弹层 */
.person-modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.person-card {
  background: #fff; border-radius: 16px; padding: 16px; width: 100%;
  max-width: 360px; text-align: center;
}
.person-title { font-size: 15px; font-weight: 600; color: var(--ink); margin: 2px 0 12px; }
#pcCanvas {
  width: 280px; height: 280px; max-width: 100%;
  border-radius: 12px; display: block; margin: 0 auto;
  touch-action: none;   /* 关键：禁止浏览器手势，由我们接管拖动/捏合 */
  /* 透明棋盘格：与导出图透明区视觉一致，编辑时图外区域直接显示 */
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(-45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8d8d8 75%),
    linear-gradient(-45deg, transparent 75%, #d8d8d8 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.person-tip { font-size: 12px; color: #888; margin: 12px 0 14px; }
.person-btns { display: flex; gap: 10px; }
.person-btns .btn { flex: 1; }
