* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", system-ui, sans-serif;
  background: #f7f7f8;
  color: #1a1a1a;
}

/* ---------- 顶部栏 ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: #ffffff;
  border-bottom: 1px solid #e5e5e5;
}
.app-header h1 { margin: 0; font-size: 1.1rem; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.empty-hint { text-align: center; padding: 0 16px; color: #666; font-size: 0.85rem; }

.file-label {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  background: #2d6cdf;
  color: #fff;
  border-radius: 8px;
  font-size: 0.9rem;
  position: relative;
  cursor: pointer;
  white-space: nowrap;
}
.file-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  cursor: pointer;
}

.hint { color: #666; font-size: 0.85rem; margin: 4px 0; }

/* ---------- 页签（预览 / 精修） ---------- */
.stage-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 12px 0;
}
.stage-tab {
  flex: 1;
  max-width: 220px;
  padding: 10px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 8px 8px 0 0;
  font-size: 0.95rem;
  cursor: pointer;
}
.stage-tab.active { background: #2d6cdf; color: #fff; border-color: #2d6cdf; }
.stage-tab:disabled { color: #aaa; cursor: not-allowed; background: #f0f0f0; }

/* ---------- 主工作区：窄屏/竖屏堆叠，宽屏三栏 ---------- */
#workspace {
  display: grid;
  gap: 10px;
  padding: 10px;
  max-width: 1400px;
  margin: 0 auto;
  grid-template-columns: 1fr;
  grid-template-areas:
    "canvas"
    "params"
    "export"
    "colors";
}
@media (min-width: 900px) {
  #workspace {
    grid-template-columns: 260px 1fr 260px;
    grid-template-areas:
      "params canvas export"
      "colors colors colors";
    align-items: start;
  }
}

.panel {
  background: #ffffff;
  border-radius: 10px;
  padding: 14px;
}
.panel h2 { margin: 0 0 10px; font-size: 1rem; }

.params-panel { grid-area: params; }
.canvas-panel { grid-area: canvas; padding: 8px; }
.export-panel { grid-area: export; }
.colors-panel { grid-area: colors; }

/* ---------- 参数表单 ---------- */
.field {
  display: block;
  margin-bottom: 14px;
  font-size: 0.95rem;
}
.field-label { display: block; margin-bottom: 4px; }
.field input[type="text"],
.field input[type="number"],
.field select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
}
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checkbox-field input { width: auto; }

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.slider-row input[type="range"] { flex: 1; }
.slider-row input[type="number"] {
  width: 68px;
  flex-shrink: 0;
  margin-top: 0;
}

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip-btn {
  padding: 6px 12px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
}
.chip-btn.active { background: #2d6cdf; color: #fff; border-color: #2d6cdf; }
.chip-btn:disabled { color: #bbb; background: #f2f2f2; cursor: not-allowed; }

.primary-btn, .secondary-btn {
  display: block;
  padding: 10px 16px;
  font-size: 0.95rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.primary-btn { background: #2d6cdf; color: #fff; }
.primary-btn.small, .secondary-btn.small { padding: 8px 14px; font-size: 0.9rem; }
.secondary-btn { background: #eef1f6; color: #1a1a1a; }

/* ---------- 画布区 ---------- */
.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  flex-wrap: wrap;
}
.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 8px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.zoom-pct { font-size: 0.85rem; color: #444; min-width: 42px; text-align: center; }
.perf-readout { margin-left: auto; font-size: 0.75rem; color: #999; }

.zoom-container {
  width: 100%;
  height: 56vh;
  overflow: hidden;
  background: #222;
  border-radius: 8px;
  touch-action: none;
  position: relative;
}
@media (min-width: 900px) {
  .zoom-container { height: 72vh; }
}
.zoom-content {
  transform-origin: 0 0;
  position: absolute;
  top: 0; left: 0;
}
.zoom-content canvas { display: block; image-rendering: pixelated; }

/* ---------- 颜色与用量 ---------- */
.total-stat { font-weight: bold; margin: 0 0 8px; }
.search-input {
  display: block;
  width: 100%;
  padding: 8px;
  margin-bottom: 10px;
  font-size: 0.95rem;
  border: 1px solid #ccc;
  border-radius: 6px;
}
.color-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}
.color-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  padding: 6px;
  border: 1px solid #eee;
  border-radius: 6px;
  cursor: pointer;
}
.color-item.highlighted { border-color: #2d6cdf; box-shadow: 0 0 0 1px #2d6cdf inset; }
.color-item.excluded { opacity: 0.5; }
.color-item.hidden-by-search { display: none; }
.color-swatch {
  width: 18px; height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
  flex-shrink: 0;
}
.color-code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exclude-btn {
  flex-shrink: 0;
  padding: 3px 8px;
  font-size: 0.75rem;
  border: 1px solid #ccc;
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
}
.color-item.excluded .exclude-btn { border-color: #2d6cdf; color: #2d6cdf; }

/* ---------- 导出弹层（复用 v1 样式） ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.sheet {
  width: 100%;
  max-width: 720px;
  background: #f4f4f4;
  border-radius: 14px 14px 0 0;
  padding: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.sheet-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  background: #ffffff;
  color: #2d6cdf;
}
.sheet-btn:first-child { margin-top: 0; }
.sheet-cancel { color: #c80000; font-weight: bold; margin-top: 12px; }
