/* ============================================
   图片去背景 - 样式表
   参考 imagecut 紫蓝渐变风格
   ============================================ */

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #1b1b1b;
  background: linear-gradient(135deg, #f6f7fb 0%, #f0f4f9 100%);
  min-height: 100vh;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

a { text-decoration: none; color: inherit; }

/* ---- 顶部导航 ---- */
.topbar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 14px 0;
}

.topbar .content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.brand {
  font-size: 1.5rem;
  font-weight: bold;
  color: white;
}

.nav-links {
  display: flex;
  gap: 24px;
}

.nav-links a {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
  transition: color 0.2s ease;
}

.nav-links a:hover,
.nav-links a.active {
  color: white;
  font-weight: 600;
}

/* ---- 主容器 ---- */
#app {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 40px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- 上传区域 ---- */
.upload-section {
  width: 100%;
  max-width: 640px;
  margin: 24px 16px 16px 16px;
}

.file-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border-radius: 12px;
  margin: 0 auto;
  width: 100%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  text-align: center;
  transition: all 0.3s ease;
  border: 2px dashed rgba(102, 126, 234, 0.4);
  cursor: pointer;
  min-height: 160px;
}

.file-selector:hover,
.file-selector.highlight {
  background: linear-gradient(135deg, #f6f7fb 0%, #ffffff 100%);
  border-color: #667eea;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.file-selector-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: #1b1b1b;
}

.file-selector-subtitle {
  font-size: 0.8rem;
  color: #6b7280;
  margin-bottom: 16px;
}

.file-selector-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.file-selector-button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.file-selector-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.file-selector-button.btn-secondary {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  border: 1px solid rgba(102, 126, 234, 0.3);
}

.file-selector-button.btn-secondary:hover {
  background: rgba(102, 126, 234, 0.15);
  color: #5a6bb8;
}

/* URL输入 */
.url-input-wrapper {
  margin-top: 12px;
  width: 100%;
}

.url-input-row {
  display: flex;
  gap: 8px;
}

.url-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid rgba(102, 126, 234, 0.2);
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.url-input:focus {
  border-color: #667eea;
}

.url-input::placeholder {
  color: #aaa;
}

.url-btn {
  padding: 10px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.url-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.url-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ---- 编辑区域 ---- */
.editor-section {
  width: 100%;
  max-width: 900px;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 模型加载状态 */
.model-status {
  width: 100%;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  text-align: center;
}

.model-status-bar {
  width: 100%;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.model-status-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.model-status-text {
  font-size: 0.8rem;
  color: #6b7280;
}

/* 处理中状态 */
.processing-status {
  width: 100%;
  background: #fff;
  border-radius: 12px;
  padding: 32px 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.processing-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(102, 126, 234, 0.2);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.processing-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1b1b1b;
}

.processing-progress {
  width: 80%;
  max-width: 300px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
}

.processing-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* 预览对比容器 */
.preview-container {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.preview-panel {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  overflow: hidden;
}

.preview-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #1b1b1b;
  padding: 10px 14px 6px;
  text-align: center;
}

.preview-image-wrapper {
  position: relative;
  /* 棋盘格背景 - 表示透明区域 */
  background-image:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  max-height: 400px;
  padding: 8px;
}

.preview-image-wrapper img {
  max-width: 100%;
  max-height: 380px;
  object-fit: contain;
  display: block;
}

/* 选项面板 */
.options-panel {
  width: 100%;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

/* 上传区内的格式面板 */
#formatPanel {
  max-width: 100%;
  margin-top: 0;
}

/* 已选图片面板 */
#selectedPanel {
  margin-top: 12px;
}

.selected-preview {
  position: relative;
  display: flex;
  justify-content: center;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.selected-preview img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 8px;
}

.selected-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.selected-remove:hover {
  background: rgba(239, 68, 68, 0.9);
}

/* 全宽开始处理按钮 */
.btn-full {
  width: 100%;
  padding: 14px 0;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-full:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.btn-full:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.option-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #1b1b1b;
  white-space: nowrap;
}

.option-btns {
  display: flex;
  gap: 6px;
}

.option-btn {
  padding: 6px 14px;
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: 6px;
  background: #fff;
  color: #667eea;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.option-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
}

.option-btn:hover:not(.active) {
  border-color: #667eea;
  background: rgba(102, 126, 234, 0.05);
}

.option-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-picker {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(102, 126, 234, 0.3);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

/* 操作按钮 */
.action-buttons {
  width: 100%;
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.action-btn {
  flex: 1;
  padding: 14px 0;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.action-btn.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.action-btn.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.action-btn.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.action-btn.btn-secondary {
  background: #fff;
  color: #667eea;
  border: 2px solid rgba(102, 126, 234, 0.3);
}

.action-btn.btn-secondary:hover {
  border-color: #667eea;
  background: rgba(102, 126, 234, 0.05);
}

.action-btn svg {
  width: 18px;
  height: 18px;
}

/* ---- 其它工具导航链接 ---- */
.navigation-links {
  max-width: 800px;
  width: 100%;
  margin: 0 auto 16px auto;
  padding: 0 16px;
}

.navigation-section-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1b1b1b;
  margin-bottom: 16px;
  text-align: center;
  padding-top: 24px;
  position: relative;
}

.navigation-section-title::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 2px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 1px;
}

.navigation-links-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.navigation-link-item {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border: 2px solid rgba(102, 126, 234, 0.25);
  border-radius: 10px;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.navigation-link-item:hover {
  border-color: #667eea;
  background: linear-gradient(135deg, #f6f7fb 0%, #ffffff 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.navigation-link-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.navigation-link-icon svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
}

.navigation-link-item:hover .navigation-link-icon svg {
  transform: scale(1.1);
}

.navigation-link-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #1b1b1b;
  margin-bottom: 4px;
  line-height: 1.2;
}

.navigation-link-subtitle {
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 0;
  line-height: 1.2;
  display: inline-block;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ---- 使用说明 ---- */
.howto-section {
  margin-top: 24px;
  padding: 20px 0;
  width: 100%;
  max-width: 640px;
}

.howto-section h2 {
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: #1b1b1b;
  margin-bottom: 16px;
  position: relative;
  padding-top: 12px;
}

.howto-section h2::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 2px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 1px;
}

.howto-section p {
  font-size: 0.9rem;
  color: #4f4f4f;
  line-height: 1.7;
  margin-bottom: 10px;
}

.howto-list {
  list-style: none;
  counter-reset: step-counter;
  padding: 0;
}

.howto-list li {
  counter-increment: step-counter;
  position: relative;
  padding: 14px 14px 14px 52px;
  margin-bottom: 10px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  font-size: 14px;
  color: #4f4f4f;
  line-height: 1.5;
}

.howto-list li::before {
  content: counter(step-counter);
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.howto-list li strong,
.howto-list dt strong {
  color: #1b1b1b;
}

.howto-list dt {
  font-size: 14px;
  padding: 10px 14px 2px;
  margin-top: 6px;
  background: #fff;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.howto-list dd {
  font-size: 14px;
  color: #666;
  padding: 2px 14px 12px;
  margin: 0 0 2px;
  background: #fff;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(27, 27, 27, 0.9);
  color: #fff;
  padding: 12px 28px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: fadeInUp 0.3s ease;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.toast-error {
  background: rgba(239, 68, 68, 0.9);
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- 响应式 ---- */
@media (max-width: 767px) {
  .file-selector {
    width: calc(100% - 32px);
    padding: 20px 12px;
  }

  .file-selector-title {
    font-size: 1.1rem;
  }

  .file-selector-subtitle {
    font-size: 0.8rem;
    margin-bottom: 14px;
  }

  .preview-container {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .preview-image-wrapper {
    min-height: 150px;
    max-height: 300px;
  }

  .preview-image-wrapper img {
    max-height: 280px;
  }

  .options-panel {
    flex-direction: column;
    gap: 12px;
  }

  .option-row {
    width: 100%;
  }

  .url-input-row {
    flex-direction: column;
  }

  .url-btn {
    width: 100%;
  }

  .editor-section {
    padding: 0 8px;
  }

  .navigation-links-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .navigation-link-item {
    padding: 8px 4px;
    min-height: 50px;
  }

  .navigation-link-icon svg {
    width: 16px;
    height: 16px;
  }

  .navigation-link-title {
    font-size: 0.7rem;
  }

  .navigation-link-subtitle {
    font-size: 0.65rem;
    padding: 3px 6px;
  }

  .processing-status {
    padding: 24px 16px;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .preview-container {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .preview-image-wrapper {
    min-height: 180px;
  }
}

@media (min-width: 769px) {
  .preview-container {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .navigation-links-grid {
    gap: 16px;
  }

  .navigation-link-item {
    padding: 16px 12px;
    min-height: 70px;
  }
}
