/* ===================================================
   拼豆图片转化器 — 响应式样式
   移动端优先 · 平板 · 桌面三断点
   =================================================== */

/* ----- 变量 ----- */
:root {
  --bg: #F5F5F5;
  --surface: #FFFFFF;
  --surface-hover: #F8F8F8;
  --border: #E0E0E0;
  --text: #333333;
  --text-secondary: #888888;
  --primary: #FF6B35;
  --primary-hover: #E55A28;
  --secondary: #4A90D9;
  --secondary-hover: #3A7BC8;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.10);
}

/* ----- 重置 ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===================================================
   头部
   =================================================== */
.header {
  text-align: center;
  padding: 14px 0 6px;
}

.header h1 {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 2px;
}

/* ===================================================
   主布局：移动端单列
   =================================================== */
.main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

/* ----- 面板通用 ----- */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.section:last-child { border-bottom: none; }

.section h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ----- 上传区域 ----- */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.drop-zone:active,
.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: #FFF5F0;
  color: var(--primary);
}

.upload-icon {
  width: 32px;
  height: 32px;
  opacity: 0.45;
  flex-shrink: 0;
}
.drop-zone:active .upload-icon,
.drop-zone:hover .upload-icon,
.drop-zone.dragover .upload-icon { opacity: 1; }

.drop-zone p { font-size: 13px; }

/* ----- 表单字段 ----- */
.field {
  margin-bottom: 12px;
}
.field:last-child { margin-bottom: 0; }

.field label {
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
  white-space: nowrap;
}

.select,
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}
.select:focus,
input[type="number"]:focus { border-color: var(--primary); }

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  margin: 10px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.range-hints {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-secondary);
}

.value-hint {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 12px;
}

/* 定制尺寸行 */
.custom-size {
  display: flex;
  align-items: center;
  gap: 6px;
}
.custom-size input { flex: 1; }
.custom-size span {
  color: var(--text-secondary);
  font-size: 14px;
  flex-shrink: 0;
}

/* ----- 按钮 ----- */
.actions {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 14px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }
.btn-secondary:active:not(:disabled) { background: var(--surface-hover); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ----- 预览区 ----- */
.preview-section { min-height: 120px; }
.result-section { min-height: 120px; }

.preview-box {
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: #FAFAFA;
  padding: 10px;
}
.preview-box.has-image { padding: 10px; }

.original-img {
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px 12px;
}
.empty-state svg { width: 36px; height: 36px; }
.empty-state p { font-size: 12px; margin-top: 6px; }
.empty-state.small { padding: 14px; }

/* ----- 结果画布 —— 关键响应式区域 ----- */
.result-canvas-wrap {
  display: flex;
  justify-content: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px;
  background: #FAFAFA;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 100px;
  /* 移动端限制容器最大宽度，内部 canvas 自适应 */
  max-width: 100%;
}

.result-canvas-wrap canvas {
  box-shadow: var(--shadow);
  border-radius: 2px;
  display: block;
  /* canvas 宽高由 JS 动态设置，CSS 不缩放 */
  max-width: 100%;
  height: auto;
}

/* 移动端：大画布可水平滚动 */
@media (max-width: 767px) {
  .result-canvas-wrap {
    justify-content: flex-start;
  }
}

.loading {
  text-align: center;
  padding: 28px;
  color: var(--text-secondary);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----- 色号统计 ----- */
.stats-list {
  max-height: none;
  overflow-y: visible;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #F0F0F0;
  font-size: 12px;
}
.stat-row:last-child { border-bottom: none; }

.stat-row.total {
  font-weight: 700;
  border-top: 2px solid var(--border);
  margin-top: 4px;
  padding-top: 10px;
}

.stat-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.stat-name {
  flex: 1;
  color: var(--text);
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-count {
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: 11px;
}

/* 背景排除提示 */
.stat-tip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0 10px;
  font-size: 11px;
  color: var(--text-secondary);
  border-bottom: 1px dashed var(--border);
  margin-bottom: 4px;
}

/* ----- 页脚 ----- */
.footer {
  text-align: center;
  padding: 10px;
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.8;
}

/* ===================================================
   平板断点 768px+
   双列：左侧控制 | 右侧预览+统计
   =================================================== */
@media (min-width: 768px) {
  .app { padding: 14px; }

  .header { padding: 18px 0 10px; }
  .header h1 { font-size: 22px; }

  .main {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 14px;
    align-items: start;
  }

  .panel-right {
    grid-column: 1 / -1;
  }

  .section { padding: 14px; }

  .actions {
    flex-direction: row;
  }
  .actions .btn { flex: 1; }

  .drop-zone { padding: 22px 16px; min-height: 80px; }
  .upload-icon { width: 30px; height: 30px; }

  .preview-box { min-height: 180px; }
  .original-img { max-height: 320px; }

  .result-canvas-wrap { max-width: 100%; }

  /* 统计两列布局 */
  .stats-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
  }
  .stat-tip { grid-column: 1 / -1; }
  .stat-row.total { grid-column: 1 / -1; }

  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }
  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }
}

/* ===================================================
   桌面断点 1100px+
   三列：控制 | 预览 | 统计
   =================================================== */
@media (min-width: 1100px) {
  .app { padding: 20px; }

  .header { padding: 24px 0 16px; }
  .header h1 { font-size: 26px; }
  .subtitle { font-size: 14px; }

  .main {
    grid-template-columns: 280px 1fr 270px;
    gap: 16px;
  }

  .panel-right {
    grid-column: auto;
  }

  .section { padding: 16px; }

  .stats-list {
    display: block;
    max-height: 560px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .stat-tip { grid-column: auto; }
  .stat-row.total { grid-column: auto; }
}
