/* ===== 全局 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

/* ===== 头部 ===== */
header {
  text-align: center;
  padding: 32px 0 24px;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  color: #1a1a2e;
}

.subtitle {
  color: #666;
  margin-top: 6px;
  font-size: 15px;
}

/* ===== 模式选择 ===== */
.mode-selector {
  display: flex;
  gap: 16px;
  margin-bottom: 28px;
}

.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 16px;
  background: #fff;
  cursor: pointer;
  transition: all 0.25s;
  font-size: 14px;
  color: #555;
}

.mode-btn:hover {
  border-color: #4a90d9;
  background: #f5f9ff;
}

.mode-btn.active {
  border-color: #4a90d9;
  background: linear-gradient(135deg, #4a90d9 0%, #357abd 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(74, 144, 217, 0.3);
}

.mode-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.mode-label {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
}

.mode-desc {
  font-size: 12px;
  opacity: 0.8;
}

/* ===== 上传区域 ===== */
.upload-section {
  margin-bottom: 24px;
}

.upload-area {
  border: 2px dashed #ccc;
  border-radius: 16px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  transition: all 0.25s;
}

.upload-area:hover {
  border-color: #4a90d9;
  background: #f5f9ff;
}

.upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.upload-area p {
  font-size: 16px;
  color: #333;
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 13px;
  color: #999;
}

/* ===== 预览区域 ===== */
.preview-section {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.preview-header h3 {
  font-size: 18px;
  font-weight: 600;
}

/* ===== 画布工具栏 ===== */
.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #f8f9fa;
  border-radius: 10px;
}

.toolbar-hint {
  font-size: 13px;
  color: #666;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.radius-label {
  font-size: 13px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 6px;
}

.radius-label input[type="range"] {
  width: 80px;
  accent-color: #4a90d9;
}

#brushSizeVal {
  min-width: 20px;
  text-align: center;
}

/* ===== 画布容器 ===== */
.canvas-container {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: repeating-conic-gradient(#e0e0e0 0% 25%, #fff 0% 50%) 50% / 20px 20px;
  margin-bottom: 16px;
}

.canvas-container canvas,
.canvas-container img {
  display: block;
  max-width: 100%;
  max-height: 500px;
  object-fit: contain;
}

#maskCanvas {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
}

.bg-wrap .canvas-container {
  display: block;
  text-align: center;
}

.bg-wrap img {
  max-height: 500px;
  border-radius: 10px;
}

/* ===== 结果区域 ===== */
.result-section {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.result-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #27ae60;
}

.result-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.result-item {
  text-align: center;
}

.result-label {
  display: block;
  font-size: 13px;
  color: #888;
  margin-bottom: 8px;
  font-weight: 500;
}

.result-img-wrap {
  border-radius: 10px;
  overflow: hidden;
  background: repeating-conic-gradient(#e0e0e0 0% 25%, #fff 0% 50%) 50% / 16px 16px;
  border: 1px solid #eee;
}

.result-img-wrap img {
  display: block;
  width: 100%;
  max-height: 400px;
  object-fit: contain;
}

/* ===== 按钮 ===== */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #4a90d9 0%, #357abd 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #357abd 0%, #2a6498 100%);
  box-shadow: 0 4px 12px rgba(74, 144, 217, 0.35);
}

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

.btn-secondary {
  padding: 8px 18px;
  background: #f0f2f5;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #e4e6e9;
}

.btn-sm {
  padding: 6px 14px;
  background: #fff;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-sm:hover {
  background: #f0f2f5;
}

/* ===== 加载动画 ===== */
.loading {
  text-align: center;
  padding: 60px 20px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border: 4px solid #e0e0e0;
  border-top-color: #4a90d9;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading p {
  color: #666;
  font-size: 15px;
}

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  .mode-selector {
    flex-direction: column;
  }

  .result-compare {
    grid-template-columns: 1fr;
  }

  .canvas-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar-actions {
    margin-left: 0;
  }
}
