/* 拼豆商用平台 —— 移动端优先样式 */
:root {
  --primary: #ff6b35;
  --primary-dark: #e5522a;
  --accent: #ffd166;
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #2b2620;
  --text-dim: #8a8177;
  --border: #ece5da;
  --success: #2e9e5b;
  --danger: #d64545;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(80, 60, 30, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- 顶部 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(135deg, var(--primary), #ff8f5e);
  color: #fff; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 700; letter-spacing: .5px; }
.topbar .badge {
  font-size: .72rem; background: rgba(255,255,255,.22);
  padding: 3px 10px; border-radius: 20px;
}

.container { max-width: 680px; margin: 0 auto; padding: 16px 14px 90px; }

/* ---------- 输入框 ---------- */
.input {
  display: block; width: 100%;
  padding: 14px 16px;
  font-size: 1rem; font-family: inherit; color: var(--text);
  background: #fff; border: 1.5px solid var(--border); border-radius: 12px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(255,107,53,.15); }
.input::placeholder { color: var(--text-dim); }
/* 卡密激活输入框：更大触控目标，契合卡片风格 */
#cardInput {
  padding: 16px 18px; font-size: 1.15rem; font-weight: 600;
  text-align: center; letter-spacing: 1px; border-radius: 14px;
  background: var(--bg);
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card-title {
  font-size: .95rem; font-weight: 700; margin: 0 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: .78rem; flex: none;
}

/* ---------- 上传区 ---------- */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px 16px; text-align: center; cursor: pointer;
  background: #fdfbf7; transition: border-color .2s, background .2s;
}
.upload-zone:active, .upload-zone.drag { border-color: var(--primary); background: #fff5ee; }
.upload-zone .icon { font-size: 2.2rem; margin-bottom: 8px; }
.upload-zone .main { font-size: .95rem; font-weight: 600; }
.upload-zone .sub { font-size: .78rem; color: var(--text-dim); margin-top: 6px; }

.preview-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: #f0ebe2; }
.preview-wrap img, .preview-wrap canvas { width: 100%; display: block; max-height: 320px; object-fit: contain; }

/* ---------- 滑块（移动端友好） ---------- */
.slider-row { margin-bottom: 18px; }
.slider-row:last-child { margin-bottom: 4px; }
.slider-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .86rem; margin-bottom: 8px;
}
.slider-label .val {
  font-weight: 700; color: var(--primary);
  background: #fff0e8; padding: 2px 10px; border-radius: 12px;
  font-size: .82rem; min-width: 52px; text-align: center;
}
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 30px; background: transparent; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--primary) var(--fill, 50%), #eee2d4 var(--fill, 50%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: 3px solid var(--primary);
  margin-top: -10px; box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 3px; background: #eee2d4;
}
input[type="range"]::-moz-range-progress {
  height: 6px; border-radius: 3px; background: var(--primary);
}
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 3px solid var(--primary);
}

/* ---------- 分段选择 ---------- */
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-btn {
  flex: 1; min-width: 70px; padding: 10px 6px; border-radius: 12px;
  border: 1.5px solid var(--border); background: #fff;
  font-size: .84rem; text-align: center; cursor: pointer;
  color: var(--text); transition: all .15s; font-family: inherit;
}
.seg-btn.on {
  border-color: var(--primary); background: #fff3ec;
  color: var(--primary); font-weight: 700;
}
.seg-btn .desc { display: block; font-size: .68rem; color: var(--text-dim); margin-top: 2px; font-weight: 400; }
.seg-btn.on .desc { color: var(--primary-dark); opacity: .8; }

/* ---------- 开关 ---------- */
.switch-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: none; }
.switch-row .name { font-size: .88rem; }
.switch-row .hint { font-size: .72rem; color: var(--text-dim); margin-top: 2px; }
.switch {
  position: relative; width: 48px; height: 28px; flex: none;
  background: #ddd2c4; border-radius: 14px; cursor: pointer; transition: background .2s;
  -webkit-tap-highlight-color: transparent;
}
/* 隐藏原生 checkbox（保留可点击性：label 包裹 + input 透明绝对定位） */
.switch input {
  position: absolute; opacity: 0; width: 0; height: 0; margin: 0; pointer-events: none;
}
.switch.on { background: var(--success); }
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch.on::after { transform: translateX(20px); }

/* ---------- 按钮 ---------- */
.btn {
  display: block; width: 100%; padding: 14px; border-radius: 14px;
  border: none; font-size: 1rem; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--primary), #ff8f5e); color: #fff; box-shadow: 0 4px 14px rgba(255,107,53,.35); }
.btn-primary:disabled { opacity: .5; box-shadow: none; }
.btn-ghost { background: #fff; border: 1.5px solid var(--border); color: var(--text); margin-top: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; margin-top: 0; }

/* ---------- AI 风格 ---------- */
.style-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.style-card {
  border: 1.5px solid var(--border); border-radius: 12px; padding: 12px;
  text-align: center; cursor: pointer; background: #fff; transition: all .15s;
}
.style-card.on { border-color: var(--primary); background: #fff3ec; }
.style-card .emoji { font-size: 1.6rem; }
.style-card .name { font-size: .86rem; font-weight: 700; margin-top: 4px; }
.style-card .desc { font-size: .68rem; color: var(--text-dim); margin-top: 2px; }
.style-none { grid-column: 1 / -1; }

/* ---------- 结果 ---------- */
.stats-bar {
  display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
}
.stat-chip {
  flex: 1; min-width: 90px; background: #fff5ee; border-radius: 12px;
  padding: 10px; text-align: center;
}
.stat-chip .num { font-size: 1.15rem; font-weight: 800; color: var(--primary); }
.stat-chip .lbl { font-size: .7rem; color: var(--text-dim); margin-top: 2px; }

#resultCanvasWrap {
  overflow: auto; border-radius: 12px; border: 1px solid var(--border);
  background: repeating-conic-gradient(#f5f1e9 0% 25%, #fdfbf7 0% 50%) 50% / 20px 20px;
  max-height: 60vh; -webkit-overflow-scrolling: touch;
}
#resultCanvasWrap canvas { display: block; image-rendering: pixelated; }

/* ---------- 预览区（缩放适配屏幕宽度） ---------- */
.preview-holder { position: relative; display: block; }
.preview-holder canvas {
  display: block; max-width: 100%; height: auto; image-rendering: pixelated;
}
.adj-overlay {
  position: absolute; inset: 0; z-index: 5; cursor: crosshair;
  touch-action: none; user-select: none; -webkit-user-select: none;
}

/* ---------- 预览显示选项（网格/色号/坐标） ---------- */
.preview-opts {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  flex-wrap: wrap;
}
.preview-opts-label { font-size: .78rem; color: var(--text-dim); margin-right: 2px; }
.preview-opts .seg-btn {
  flex: none; padding: 7px 14px; font-size: .82rem; border-radius: 9px;
}
.preview-opts .seg-btn.on { background: var(--primary); color: #fff; }

/* ---------- 弹层 ---------- */
.color-list { max-height: 220px; overflow-y: auto; }
.color-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--border); font-size: .84rem;
}
.color-item:last-child { border-bottom: none; }
.color-swatch {
  width: 26px; height: 26px; border-radius: 6px; flex: none;
  border: 1px solid rgba(0,0,0,.15);
}
.color-item .code { font-weight: 700; min-width: 54px; }
.color-item .cnt { margin-left: auto; color: var(--text-dim); }

/* ---------- 画笔编辑工具条 ---------- */
.brush-toolbar {
  margin-top: 12px; padding: 10px; border-radius: 12px;
  background: #fff8f1; border: 1.5px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.brush-tools, .brush-size { display: flex; gap: 6px; align-items: center; }
.brush-tools .seg-btn, .brush-size .seg-btn {
  flex: none; padding: 8px 14px; font-size: .85rem; border-radius: 9px;
}
.brush-size .seg-btn { min-width: 40px; padding: 8px 0; }
.brush-label { font-size: .78rem; color: var(--text-dim); margin-right: 4px; }
.brush-current {
  width: 34px; height: 34px; border-radius: 8px; border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px var(--border), inset 0 0 0 1px rgba(0,0,0,.08);
  cursor: pointer; padding: 0; background: #ccc;
}
.brush-palette {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 8px; padding: 10px; background: #fff; border-radius: 10px;
  border: 1px solid var(--border);
}
.brush-palette.hide { display: none; }
.brush-palette .swatch {
  height: 40px; border-radius: 8px; border: 2px solid transparent;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12); cursor: pointer; position: relative;
  display: flex; align-items: flex-end; justify-content: center;
  font-size: .6rem; font-weight: 700; color: #fff; padding-bottom: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.brush-palette .swatch.on { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.brush-toolbar .btn-ghost { margin-top: 0; flex: none; width: auto; }
.brush-active .adj-overlay { cursor: cell; }
/* 卡片标题内的内联小按钮（如"编辑图纸"）：自适应内容宽度，避免 .btn 的 width:100% 撑破布局 */
.card-title .btn { width: auto; flex: none; margin-top: 0; }

/* ---------- 弹层 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(30,25,18,.55);
  z-index: 100; display: none; align-items: flex-end; justify-content: center;
}
.mask.show { display: flex; }
.sheet {
  background: #fff; width: 100%; max-width: 680px;
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-title { font-size: 1.05rem; font-weight: 800; margin: 0 0 14px; text-align: center; }
.sheet-close {
  position: absolute; right: 16px; top: 16px; width: 30px; height: 30px;
  border: none; background: #f0ebe2; border-radius: 50%; font-size: 1rem; color: var(--text-dim);
}

/* cropper 容器 */
#cropperBox { max-height: 50vh; background: #1c1814; border-radius: 12px; overflow: hidden; }
#cropperBox img { display: block; max-width: 100%; }

/* 裁剪比例按钮 */
.ratio-row { display: flex; gap: 8px; margin: 12px 0; }
.ratio-btn {
  flex: 1; padding: 8px 4px; border-radius: 10px; border: 1.5px solid var(--border);
  background: #fff; font-size: .8rem; cursor: pointer; font-family: inherit;
}
.ratio-btn.on { border-color: var(--primary); color: var(--primary); font-weight: 700; background: #fff3ec; }

/* ---------- loading / toast ---------- */
.loading {
  position: fixed; inset: 0; z-index: 200; background: rgba(250,247,242,.85);
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.loading.show { display: flex; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid #ffe3d3; border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading .txt { font-size: .9rem; color: var(--text-dim); }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(40,34,26,.92); color: #fff; padding: 10px 18px;
  border-radius: 24px; font-size: .85rem; z-index: 300; display: none;
  max-width: 86vw; text-align: center;
}
#toast.show { display: block; }

/* ---------- 授权状态条 ---------- */
.license-bar {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: 12px; padding: 10px 14px;
  font-size: .8rem; margin-bottom: 14px; box-shadow: var(--shadow);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; }
.dot.warn { background: #f0a020; }
.license-bar .info { flex: 1; color: var(--text-dim); }

/* ---------- 桌面端优化 ---------- */
@media (min-width: 900px) {
  .container { max-width: 860px; }
  .two-col { display: flex; gap: 16px; align-items: flex-start; }
  .two-col > .col { flex: 1; }
}

.empty-hint { text-align: center; color: var(--text-dim); font-size: .85rem; padding: 24px 0; }

/* admin */
.form-item { margin-bottom: 14px; }
.form-item label { display: block; font-size: .84rem; margin-bottom: 6px; color: var(--text-dim); }
.form-item input, .form-item select {
  width: 100%; padding: 12px; border-radius: 12px; border: 1.5px solid var(--border);
  font-size: .95rem; font-family: inherit; background: #fff;
}
.order-item {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  margin-bottom: 10px; font-size: .82rem;
}
.order-item .url { word-break: break-all; color: var(--primary); font-size: .76rem; margin-top: 6px; }
.copy-btn {
  margin-top: 8px; padding: 6px 14px; border-radius: 8px; border: 1.5px solid var(--primary);
  background: #fff; color: var(--primary); font-size: .78rem; cursor: pointer; font-family: inherit;
}

/* 精度预设按钮 */
.preset-row { display: flex; gap: 6px; flex-wrap: wrap; }
.preset-btn {
  flex: 1; min-width: 64px; padding: 7px 4px; border-radius: 8px;
  border: 1.5px solid var(--border); background: #fff; color: var(--text-dim);
  font-size: .76rem; cursor: pointer; font-family: inherit; transition: all .15s;
}
.preset-btn.on {
  border-color: var(--primary); color: var(--primary); background: #fff5f0; font-weight: 600;
}

/* 导出配额提示 */
.quota-hint {
  margin-top: 10px; padding: 10px 14px; border-radius: 10px;
  background: linear-gradient(135deg, #fff5f0, #fff9e8);
  border: 1px solid rgba(255,107,53,.2); font-size: .85rem; color: var(--text); text-align: center;
}
