* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #185fa5;
  --primary-light: #e6f1fb;
  --danger: #a32d2d;
  --text: #2c2c2a;
  --text-secondary: #5f5e5a;
  --border: #d3d1c7;
  --bg: #f1efe8;
  --surface: #ffffff;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* 微信提示 */
.wechat-tip {
  background: #faeeda;
  border-bottom: 1px solid #ef9f27;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}

.wechat-tip-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.wechat-tip-icon {
  background: #ba7517;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: bold;
  flex-shrink: 0;
  margin-top: 2px;
}

.wechat-tip-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}

.wechat-tip-text strong { color: #854f0b; }
.wechat-tip-text span { color: #633806; }

.wechat-tip-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #854f0b;
  line-height: 1;
  padding: 0 4px;
}

/* 头部 */
.header {
  background: var(--surface);
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
}

.header-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* 主内容 */
.main { padding: 16px; }

.step { display: none; }
.step.active { display: block; }

/* 上传区 */
.upload-card {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.upload-card.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  color: var(--primary);
}

.upload-icon svg { width: 100%; height: 100%; }

.upload-card h2 { font-size: 17px; margin-bottom: 4px; }
.upload-card p { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }

/* 按钮 */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.2s;
}

.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 16px;
  margin-top: 16px;
}

.btn-back {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  padding: 6px 0;
  font-family: inherit;
  cursor: pointer;
}

/* 提示卡片 */
.tips-card, .hint-card, .fallback-tips {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}

.tips-card h3, .fallback-tips h3 {
  font-size: 14px;
  margin-bottom: 8px;
}

.tips-card ul {
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-secondary);
}

.tips-card li { margin-bottom: 6px; }
.hint-card { font-size: 13px; color: var(--text-secondary); text-align: center; }
.fallback-tips p { font-size: 13px; color: var(--text-secondary); }

/* 步骤头 */
.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.step-header h2 { font-size: 17px; }

/* 文件标签 */
.file-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.file-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
}

.file-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* 预览画布 */
.preview-wrap {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
}

#preview-canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

.cut-lines {
  position: absolute;
  inset: 12px;
  pointer-events: none;
}

.cut-line {
  position: absolute;
  background: var(--danger);
  pointer-events: auto;
  cursor: grab;
}

.cut-line:active { cursor: grabbing; }
.cut-line.vertical { width: 2px; top: 0; bottom: 0; }
.cut-line.horizontal { height: 2px; left: 0; right: 0; }

.cut-line::after {
  content: '';
  position: absolute;
  background: var(--danger);
  border-radius: 4px;
}

.cut-line.vertical::after {
  width: 12px;
  height: 36px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cut-line.horizontal::after {
  width: 36px;
  height: 12px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* 控制卡片 */
.control-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}

.control-row {
  margin-bottom: 16px;
}

.control-row label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.layout-buttons, .quality-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.layout-btn, .quality-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.layout-btn.active, .quality-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* 结果页 */
.result-info {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.result-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px;
}

.result-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.result-item-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 6px;
}

.save-actions {
  position: sticky;
  bottom: 16px;
  background: var(--bg);
  padding-top: 16px;
}

.save-hint {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(44, 44, 42, 0.9);
  color: white;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 1000;
  max-width: 90vw;
  text-align: center;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

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

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

.loading-text {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

@media (min-width: 600px) {
  .main { max-width: 600px; margin: 0 auto; }
  .result-grid { grid-template-columns: repeat(3, 1fr); }
}
