:root {
  --bg-page: #f7f4ef;
  --bg-card: #ffffff;
  --bg-subtle: #f1ece4;
  --bg-mask: rgba(44, 34, 26, 0.58);
  --text-main: #2e231a;
  --text-secondary: #5c4b3c;
  --text-muted: #857362;
  --wood-accent: #9c6638;
  --wood-accent-hover: #835228;
  --wood-accent-active: #6e431e;
  --wood-soft: #efe5d8;
  --wood-border: #d9cbb8;
  --border-light: #e6dfd5;
  --error-text: #b92b27;
  --error-bg: #fdf1f0;
  --error-border: #f1c1be;
  --status-done-text: #2a6837;
  --status-done-bg: #edf7ef;
  --status-run-text: #855322;
  --status-run-bg: #f9f0e4;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --shadow-card: 0 1px 3px rgba(46, 35, 26, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.page-wrap {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 12px 36px;
}

@media (min-width: 600px) {
  .page-wrap {
    padding: 28px 20px 48px;
  }
}

/* 顶部标题区 */
.site-header {
  padding: 6px 4px 16px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
}

.site-title {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.01em;
}

.site-subtitle {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* 卡片与步骤 */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px 14px;
  box-shadow: var(--shadow-card);
}

@media (min-width: 600px) {
  .card {
    padding: 20px 20px;
  }
}

.step-header {
  margin-bottom: 12px;
}

.step-header-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.step-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text-main);
}

.step-tip {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  background-color: var(--bg-subtle);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

/* 按钮通用 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  user-select: none;
}

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

.btn-block {
   display: flex;
  width: 100%;
}

.btn-large {
  min-height: 50px;
  font-size: 1.06rem;
}

.btn-small {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 0.9rem;
}

.btn-primary {
  background-color: var(--wood-accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--wood-accent-hover);
}

.btn-primary:active:not(:disabled) {
  background-color: var(--wood-accent-active);
}

.btn-secondary {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--wood-border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--wood-soft);
}

.link-btn {
  background: none;
  border: none;
  color: var(--wood-accent);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  padding: 6px 8px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: var(--wood-accent-hover);
}

/* 状态与进度条 */
.status-box {
  margin-top: 12px;
  padding: 10px 12px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.status-waiting {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--status-run-text);
  background-color: var(--status-run-bg);
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.status-pct {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 8px;
  background-color: var(--border-light);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: var(--wood-accent);
  transition: width 0.2s ease;
}

.loading-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--wood-accent);
  flex-shrink: 0;
  animation: pulse-dot 1.1s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% {
    opacity: 0.35;
    transform: scale(0.88);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

/* 裁切工作区 */
.crop-workspace {
  margin-top: 14px;
}

.crop-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background-color: #231c16;
  user-select: none;
  -webkit-user-select: none;
}

.sample-img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.crop-box {
  position: absolute;
  top: 15%;
  left: 15%;
  width: 50%;
  height: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 9999px rgba(24, 18, 12, 0.52), inset 0 0 0 1px rgba(46, 35, 26, 0.35);
  cursor: move;
  touch-action: none;
  user-select: none;
}

.crop-grid-h,
.crop-grid-v {
  position: absolute;
  pointer-events: none;
}

.crop-grid-h {
  top: 33.33%;
  bottom: 33.33%;
  left: 0;
  right: 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.45);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.45);
}

.crop-grid-v {
  left: 33.33%;
  right: 33.33%;
  top: 0;
  bottom: 0;
  border-left: 1px dashed rgba(255, 255, 255, 0.45);
  border-right: 1px dashed rgba(255, 255, 255, 0.45);
}

/* 四角把手：触控区 36x36px，以角点为中心（框内仅占 18px） */
.crop-handle {
  position: absolute;
  width: 36px;
  height: 36px;
  touch-action: none;
  z-index: 2;
}

.crop-handle::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  background-color: var(--wood-accent);
  border: 2px solid #ffffff;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.handle-nw {
  top: -18px;
  left: -18px;
  cursor: nwse-resize;
}
.handle-nw::after {
  top: 10px;
  left: 10px;
}

.handle-ne {
  top: -18px;
  right: -18px;
  cursor: nesw-resize;
}
.handle-ne::after {
  top: 10px;
  right: 10px;
}

.handle-sw {
  bottom: -18px;
  left: -18px;
  cursor: nesw-resize;
}
.handle-sw::after {
  bottom: 10px;
  left: 10px;
}

.handle-se {
  bottom: -18px;
  right: -18px;
  cursor: nwse-resize;
}
.handle-se::after {
  bottom: 10px;
  right: 10px;
}

.crop-instruction {
  margin: 10px 0 12px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  text-align: center;
}

/* 生成出的木纹小样 */
.swatch-result {
  margin-top: 14px;
  padding: 10px 12px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--wood-border);
  border-radius: var(--radius-md);
}

.swatch-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.swatch-img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--wood-border);
  background-color: var(--wood-soft);
  flex-shrink: 0;
}

.swatch-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.swatch-title {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-main);
}

.swatch-sub {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* 第 2 步：参数控制 */
.control-group {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.control-group:last-of-type {
  border-bottom: none;
}

.control-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.control-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.control-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--wood-accent);
  background-color: var(--wood-soft);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.slider-end-label {
  font-size: 0.84rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  min-width: 28px;
}

.range-input {
  flex: 1;
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--wood-accent);
  cursor: pointer;
}

/* 竖纹 / 横纹 切换按钮 */
.seg-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.seg-btn {
  min-height: 44px;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid var(--wood-border);
  background-color: var(--bg-subtle);
  color: var(--text-main);
  cursor: pointer;
}

.seg-btn.is-active {
  background-color: var(--wood-accent);
  border-color: var(--wood-accent);
  color: #ffffff;
  font-weight: 600;
}

/* 标签文字输入框 */
.text-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-main);
  background-color: #ffffff;
  border: 1px solid var(--wood-border);
  border-radius: var(--radius-sm);
}

.text-input:focus {
  outline: 2px solid var(--wood-accent);
  outline-offset: 1px;
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* 预览三图 */
.preview-area {
  margin-top: 12px;
  padding-top: 10px;
}

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

.preview-section-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.preview-empty {
  padding: 20px 12px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  border: 1px dashed var(--wood-border);
}

.preview-stage {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.preview-item {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-img-wrap {
  width: 100%;
  aspect-ratio: 9 / 16;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
  cursor: pointer;
}

.preview-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-img:not([src]),
.preview-img[src=""] {
  display: none;
}

.preview-caption {
  margin-top: 5px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: center;
}

.preview-updating-mask {
  position: absolute;
  inset: 0;
  background-color: rgba(247, 244, 239, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
}

.preview-updating-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-card);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--wood-border);
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: var(--shadow-card);
}

/* 第 3 步：生成视频 */
.generate-action-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.generate-hint {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
  text-align: center;
}

/* 第 4 步：我的视频列表 */
.poll-indicator {
  font-size: 0.8rem;
  color: var(--status-run-text);
  background-color: var(--status-run-bg);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.jobs-empty {
  padding: 18px 12px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
}

.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.job-item {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  background-color: #fcfaf7;
}

.job-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.job-swatch {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--wood-border);
  background-color: var(--wood-soft);
  flex-shrink: 0;
}

.job-info {
  flex: 1;
  min-width: 0;
}

.job-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.job-time {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.job-status-badge {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.status-queued,
.status-running {
  color: var(--status-run-text);
  background-color: var(--status-run-bg);
}

.status-done {
  color: var(--status-done-text);
  background-color: var(--status-done-bg);
}

.status-failed {
  color: var(--error-text);
  background-color: var(--error-bg);
}

.job-summary {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-secondary);
  word-break: break-word;
}

.job-progress-wrap {
  margin-top: 10px;
}

.job-error-reason {
  margin: 8px 0 0;
  font-size: 0.86rem;
  color: var(--error-text);
  font-weight: 500;
}

.job-video-wrap {
  margin-top: 10px;
  width: 100%;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background-color: #1c1612;
}

.video-player {
  display: block;
  width: 100%;
  height: auto;
  max-height: 480px;
}

.job-actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.job-actions .btn {
  flex: 1 1 130px;
}

/* 第 5 步：原视频（对照）折叠区 */
.collapse-trigger {
  width: 100%;
  min-height: 44px;
  padding: 4px 0;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.collapse-action-text {
  font-size: 0.88rem;
  color: var(--wood-accent);
  font-weight: 500;
}

.template-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.video-player-wrap {
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background-color: #1c1612;
}

/* 错误提示（红字中文） */
.step-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background-color: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  font-size: 0.9rem;
  font-weight: 500;
  word-break: break-word;
}

/* 底部说明 */
.site-footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
  text-align: center;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.site-footer p {
  margin: 0;
}

/* 预览大图弹窗 */
.lightbox {
  position: fixed;
  inset: 0;
  background-color: var(--bg-mask);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox-inner {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 12px;
  max-width: 420px;
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lightbox-img {
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background-color: #1c1612;
}

.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lightbox-caption {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

[hidden] {
  display: none !important;
}

/* 第二阶段入口（换客户自己的视频） */
.site-switch {
  margin: 10px 0 0;
  font-size: 0.95rem;
}

.site-switch a {
  color: var(--wood-accent);
  font-weight: 600;
  text-decoration: none;
}

.site-switch a:active {
  color: var(--wood-accent-active);
}
