:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e3e8f0;
  --primary: #4a6cf7;
  --primary-dark: #3a56d4;
  --danger-bg: #fdecea;
  --danger-ink: #b3261e;
  --danger-line: #f5c6c2;
  --ok: #12a150;
  --shadow: 0 2px 10px rgba(24, 39, 75, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; }

/* 兜底：确保 hidden 属性在任何情况下都生效（作者样式表的 display 声明会覆盖 UA 样式表的 [hidden]{display:none}） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: linear-gradient(120deg, #2b3a67 0%, #4a6cf7 100%);
  color: #fff;
  padding: 16px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; color: #ffd166; }
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.sub { margin: 2px 0 0; font-size: 12px; opacity: .85; }
.disclaimer {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  max-width: 560px;
}

/* ---------- 错误提示条 ---------- */
.error-bar {
  margin: 12px 24px 0;
  background: var(--danger-bg);
  color: var(--danger-ink);
  border: 1px solid var(--danger-line);
  border-left: 5px solid var(--danger-ink);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
}
.error-bar::before { content: "⚠ "; font-weight: 700; }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 24px 24px;
  align-items: start;
}
@media (max-width: 1000px) {
  /* 单列时用 minmax(0,1fr)：允许结果面板收缩到容器宽度以下，
     否则宽图纸会把整个面板撑宽、页面横向溢出，canvas-wrap 内部的横向滚动就失效了 */
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.controls h2 {
  font-size: 14px;
  color: var(--primary-dark);
  margin: 18px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--line);
}
.controls h2:first-child { margin-top: 0; }

/* ---------- 上传区 ---------- */
.dropzone {
  border: 2px dashed #b9c4dd;
  border-radius: var(--radius);
  background: #fbfcff;
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  transition: .18s;
}
.dropzone:hover, .dropzone:focus { border-color: var(--primary); background: #f2f6ff; outline: none; }
.dropzone.drag { border-color: var(--primary); background: #e9f0ff; }
.dz-icon { font-size: 30px; color: var(--primary); line-height: 1; }
.dz-main { margin: 8px 0 4px; }
.dz-hint { margin: 0; font-size: 12px; color: var(--muted); }

.preview-wrap { margin-top: 12px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.preview-wrap img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: repeating-conic-gradient(#eef1f7 0% 25%, #fff 0% 50%) 50% / 16px 16px;
  margin-top: 6px;
}
.img-meta { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* ---------- 表单 ---------- */
.field { display: block; margin: 10px 0; }
.field > span { display: flex; justify-content: space-between; font-size: 13px; color: #374151; margin-bottom: 6px; }
.field > span em { font-style: normal; color: var(--primary-dark); font-weight: 600; }
.field select, .field input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  color: var(--ink);
}
.field input[type="number"] { max-width: 96px; }
.row { display: flex; gap: 10px; align-items: center; }
.row input[type="range"] { flex: 1; accent-color: var(--primary); }

.check { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; font-size: 13px; }
.check input { margin-top: 3px; accent-color: var(--primary); }
/* 选项说明：主行为「功能名 · 作用」，副行为灰色小字的适用场景 */
.check-text { display: block; flex: 1; min-width: 0; }
.check-text > b { display: block; font-weight: 600; color: var(--ink); line-height: 1.4; }
.check-text > i {
  display: block;
  margin-top: 2px;
  font-style: normal;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

.presets { display: flex; gap: 8px; margin: 8px 0; }
.preset {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}
.preset:hover { border-color: var(--primary); color: var(--primary-dark); }
.preset.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.palette-info {
  font-size: 12px;
  color: #374151;
  background: #f7f9ff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0;
}

.custom-palette { margin: 10px 0; font-size: 13px; }
.custom-palette summary { cursor: pointer; color: var(--primary-dark); font-weight: 600; }
.custom-palette .fmt { font-size: 12px; color: var(--muted); background: #fafbff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.custom-palette code { background: #eef2fb; padding: 1px 4px; border-radius: 4px; font-family: Consolas, monospace; }
.custom-palette input[type="file"] { margin: 8px 0; font-size: 12px; max-width: 100%; }

/* ---------- 按钮 ---------- */
.actions { display: flex; gap: 10px; margin-top: 16px; }
button.primary, button.ghost {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  font-weight: 600;
}
button.primary { background: var(--primary); color: #fff; flex: 1; }
button.primary:hover { background: var(--primary-dark); }
button.primary:disabled { background: #b9c4dd; cursor: not-allowed; }
button.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
button.ghost:hover { border-color: var(--primary); color: var(--primary-dark); }
button.small { padding: 7px 12px; font-size: 13px; flex: none; }
.link-btn { background: none; border: none; color: var(--primary-dark); cursor: pointer; font-size: 12px; padding: 0; text-decoration: underline; }

/* ---------- 结果区 ---------- */
.result-head { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.result-head h2 { font-size: 16px; }
.result-actions { display: flex; align-items: center; gap: 12px; }
.meta-line { font-size: 12px; color: var(--muted); }

/* ---------- 导出方式与进度 ---------- */
.export-opts { margin: 10px 0 2px; }
.export-modes { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.export-title { font-size: 12px; color: var(--muted); }
.export-radio {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.export-radio input { margin: 0; cursor: pointer; }
.export-hint {
  margin: 8px 0 0;
  padding: 8px 11px;
  font-size: 12px;
  line-height: 1.7;
  color: #4b5563;
  background: #f1f5ff;
  border-left: 3px solid var(--primary);
  border-radius: 6px;
}
.export-progress { margin-top: 9px; }
.ep-track { height: 8px; background: #e5eaf5; border-radius: 99px; overflow: hidden; }
.ep-fill { height: 100%; width: 0; background: var(--primary); border-radius: 99px; transition: width .18s ease; }
.ep-text { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); }

/* ---------- 导出结果（手机长按存相册 / 桌面右键另存） ---------- */
.export-results { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.er-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.er-head-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.er-head-text strong { font-size: 14px; color: var(--ink); }
.er-tip { font-size: 12px; color: var(--muted); }
.er-tip b { color: var(--primary-dark); }
/* 手机上「怎么存到相册」是留给用户的唯一指引，不能淹没在灰色小字里 */
.er-tip-strong { color: var(--primary-dark); font-weight: 600; font-size: 12.5px; }
.er-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
}
.er-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.er-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
/* 缩略图本身就是按钮：点开看原图（手机上再长按存相册）。
   用 button 而不是 a[target=_blank]，是为了让手机也能走「页面内看原图」这条最稳的路。 */
.er-thumb {
  display: block;
  width: 100%;
  padding: 0;
  margin: 0;
  border: 0;
  background: #f7f8fb;
  cursor: zoom-in;
  line-height: 0;
}
.er-thumb img { display: block; width: 100%; height: auto; background: #f7f8fb; }
/* 卡片底部：名称和「下载」同行，体积文字独占下一行（窄屏两列时也放得下） */
.er-foot {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1px 8px;
  padding: 6px 8px 8px;
}
.er-name { grid-column: 1; grid-row: 1; font-size: 12px; font-weight: 600; color: var(--ink); }
.er-save {
  grid-column: 2;
  grid-row: 1;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  color: var(--primary-dark);
  text-decoration: none;
  background: #fff;
  white-space: nowrap;
}
.er-save:hover { border-color: var(--primary); background: #f2f6ff; }
.er-meta { grid-column: 1 / -1; grid-row: 2; font-size: 11px; color: var(--muted); }

/* ---------- 原图查看器（手机长按存相册的关键路径） ---------- */
/* img 的 src 指向完整分辨率原图的 blob 地址；屏幕上是等比缩放显示，
   但长按/右键保存拿到的是原始像素，不是屏幕上看到的缩小版。
   底色必须不透明：早先用半透明，底下的页面文字透上来跟顶栏标题糊在一起。 */
.img-viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: #101520;
}
.iv-bar {
  flex: 0 0 auto;
  padding: 10px 12px;
  color: #eef1f7;
  background: #161c28;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.iv-row { display: flex; align-items: center; gap: 8px; }
.iv-title { flex: 1 1 auto; min-width: 0; font-size: 13px; font-weight: 600; }
.iv-tip { display: block; margin-top: 6px; font-size: 11.5px; line-height: 1.5; color: #aab4c8; }
.iv-tip b { color: #dbe4f5; }
.iv-actions { flex: 0 0 auto; display: flex; gap: 6px; }
.iv-btn {
  padding: 5px 11px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #eef1f7;
  font-size: 12px;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.iv-btn:hover { background: rgba(255, 255, 255, 0.18); }
.iv-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.iv-btn.primary:hover { background: var(--primary-dark); }
/* 「新标签打开」在手机上没多大用（长按才是正路），窄屏直接藏掉，别挤爆顶栏 */
@media (max-width: 640px) {
  .iv-open { display: none; }
}
.iv-stage {
  flex: 1 1 auto;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}
.iv-stage img {
  display: block;
  max-width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.45);
}

.loading { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--muted); }
.spinner {
  width: 20px; height: 20px;
  border: 3px solid #dbe3f5;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { padding: 34px 10px; text-align: center; color: var(--muted); }

/* ---------- 图纸缩放控件 ---------- */
.zoom-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}
.zoom-title { font-weight: 600; color: #374151; }
.zoom-btn {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}
.zoom-btn:hover { border-color: var(--primary); color: var(--primary-dark); }
.zoom-btn:disabled { opacity: .45; cursor: not-allowed; border-color: var(--line); color: var(--muted); }
.zoom-label {
  min-width: 84px;
  text-align: center;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.zoom-fit { margin-left: auto; }
.zoom-hint { width: 100%; }

.canvas-wrap {
  margin-top: 12px;
  overflow: auto;
  max-width: 100%;
  max-height: 70vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}
#patternCanvas { display: block; image-rendering: auto; }

.stats-title { font-size: 14px; margin: 18px 0 8px; color: var(--primary-dark); }
.table-wrap { max-height: 340px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table.stats { width: 100%; border-collapse: collapse; font-size: 13px; }
table.stats th, table.stats td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.stats thead th { position: sticky; top: 0; background: #f7f9ff; z-index: 1; font-weight: 600; }
table.stats .num { text-align: right; font-variant-numeric: tabular-nums; }
table.stats tfoot td { font-weight: 700; background: #fbfcff; }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,.18); vertical-align: middle; }
.mono { font-family: Consolas, monospace; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 24px 24px; }

/* 页脚统计开关：说明文字必须让人看懂「统计什么/不统计什么」，不能只放一个勾选框 */
.foot .privacy {
  margin: 10px auto 0;
  max-width: 720px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 4px 10px;
  line-height: 1.6;
}
.privacy-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
}
.privacy-toggle input { cursor: pointer; margin: 0; }
.privacy-note { flex: 1 1 420px; min-width: 0; text-align: left; color: var(--muted); }

/* ---------- 页脚反馈入口 ---------- */
.foot-actions {
  margin: 12px 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.foot-actions-note { font-size: 12px; color: var(--muted); }

/* ---------- 反馈弹窗（无需登录，默认匿名） ---------- */
.fb-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(18, 22, 32, 0.5);
  overflow: auto;
}
.fb-card {
  width: 100%;
  max-width: 520px;
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(24, 39, 75, 0.24);
  text-align: left;
}
.fb-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.fb-head h2 { margin: 0 0 4px; font-size: 16px; color: var(--primary-dark); }
.fb-sub { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.fb-sub b { color: var(--ink); }
.fb-close {
  margin-left: auto;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.fb-close:hover { border-color: var(--primary); color: var(--primary-dark); }

.fb-body { padding: 14px 18px 4px; display: flex; flex-direction: column; gap: 14px; }

/* 表单分两块：① 评价（匿名） ② 联系方式（选填）。
   分成两块而不是平铺，是因为这两件事性质不同 —— 评价是不记名的，联系方式是要回话的，
   混在一起用户会以为「不填邮箱就提交不了」。 */
.fb-part {
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafd;
}
.fb-part-head { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 12px; }
.fb-part-no {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.fb-part-head-text { display: block; }
.fb-part-title { display: block; font-size: 13px; font-weight: 700; color: var(--ink); }
.fb-part-title em { font-style: normal; font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }
.fb-part-note { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.fb-part .fb-field + .fb-field { margin-top: 12px; }

/* 选了「商务合作 / 版权投诉」时的提醒：这两类不留邮箱其实没法推进 */
.fb-nudge {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border-left: 3px solid #f0a51e;
  background: #fff6e6;
  color: #8a5a00;
  font-size: 12px;
  line-height: 1.5;
}

.fb-field { display: block; }
.fb-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--ink); }
.fb-label em { font-style: normal; font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }

/* 类型选择：五个 chip。用 radio 而不是 select —— 手机上少一次展开，一眼看全 */
.fb-kinds { display: flex; flex-wrap: wrap; gap: 8px; }
.fb-chip { position: relative; cursor: pointer; }
.fb-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.fb-chip span {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
}
.fb-chip input:checked + span {
  border-color: var(--primary);
  background: #eef3ff;
  color: var(--primary-dark);
  font-weight: 600;
}
.fb-chip input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* 评分：五颗星 + 一句说明（不用数字，避免「3 分算好还是差」的歧义） */
.fb-stars { display: flex; align-items: center; gap: 4px; }
.fb-star {
  padding: 0 2px;
  border: 0;
  background: none;
  font-size: 26px;
  line-height: 1;
  color: #d9dde7;
  cursor: pointer;
  transition: color .12s;
}
.fb-star:hover, .fb-star.on { color: #f0a51e; }
.fb-star-text { margin-left: 8px; font-size: 12px; color: var(--muted); }

.fb-body textarea, .fb-body input[type="email"] {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  resize: vertical;
}
.fb-body textarea:focus, .fb-body input[type="email"]:focus {
  outline: none;
  border-color: var(--primary);
}
.fb-count { display: block; margin-top: 4px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.fb-hint { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* 提交结果：成功和「被拒」都要说清发生了什么，不能只显示「失败」 */
.fb-status {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  border-left: 4px solid transparent;
}
.fb-status.ok { background: #eef9f1; border-left-color: var(--ok); color: #0b6b36; }
.fb-status.err { background: var(--danger-bg); border-left-color: var(--danger-ink); color: var(--danger-ink); }
.fb-status.wait { background: #f2f6ff; border-left-color: var(--primary); color: var(--primary-dark); }

.fb-foot {
  display: flex;
  gap: 10px;
  padding: 14px 18px 18px;
}
.fb-foot button { flex: 1; }
@media (max-width: 480px) {
  .fb-modal { align-items: flex-start; padding: 10px; }
  .fb-star { font-size: 24px; }
}
