:root {
  --bg: #0a0b0e;
  --bg-soft: #101218;
  --panel: #14161c;
  --panel-2: #191c24;
  --border: #24272f;
  --border-strong: #343842;
  --text: #e9eaee;
  --muted: #8b909c;
  --accent: #f5a524;
  --accent-2: #ff7a45;
  --danger: #ff6b6b;
  --radius: 16px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* 作者样式里的 display 会盖掉 [hidden] 的默认 display:none，这里统一兜底 */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 12% -12%, rgba(245, 165, 36, 0.10), transparent 60%),
    radial-gradient(900px 520px at 92% -6%, rgba(255, 122, 69, 0.08), transparent 62%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px 24px 18px;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: 0.2px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  overflow: hidden;
  background: transparent;
}
.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.brand-text { font-size: 17px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.api-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(245, 165, 36, 0.5);
  background: rgba(245, 165, 36, 0.08);
  color: #ffd7a0;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.api-btn:hover { background: rgba(245, 165, 36, 0.18); }

/* 弹窗：历史视频预览 / API 说明 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.66);
}
.modal-card {
  display: flex;
  flex-direction: column;
  width: min(780px, 100%);
  max-height: 88vh;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 14.5px; font-weight: 650; }

.player-card { width: min(1000px, 100%); }
.player-body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  background: #000;
}
.player-body video { width: 100%; max-height: 72vh; background: #000; }
.player-loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 44px 18px; text-align: center; }
.player-loading p { margin: 0; font-size: 13.5px; color: #cfd2da; line-height: 1.6; }
.player-loading.is-error p { color: #ffb3b3; }
.player-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); }

.api-body { padding: 16px 18px 24px; overflow: auto; font-size: 13.5px; line-height: 1.7; color: #c8ccd5; }
.api-body h3 { margin: 20px 0 6px; font-size: 13.5px; color: var(--text); }
.api-body p { margin: 8px 0; }
.api-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.api-body p code, .api-body td code, .api-body li code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
}
.api-body pre {
  margin: 10px 0 12px;
  padding: 12px 14px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0b0d11;
}
.api-body pre code { color: #d7dbe4; line-height: 1.55; }
.api-body table { width: 100%; margin: 8px 0 4px; border-collapse: collapse; font-size: 12.5px; }
.api-body th, .api-body td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.api-body th { color: var(--muted); font-weight: 600; }
.tag {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.workspace {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 20px;
  max-width: 1560px;
  margin: 0 auto;
  padding: 6px 24px 26px;
  align-items: stretch;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.028), rgba(255, 255, 255, 0)), var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.compose { padding: 20px; display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.field label, .label { font-size: 13px; font-weight: 600; color: #cfd2da; }
.field-hint { font-size: 12px; color: var(--muted); }

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea { resize: vertical; min-height: 128px; line-height: 1.6; }

input:focus, textarea:focus {
  border-color: rgba(245, 165, 36, 0.65);
  box-shadow: 0 0 0 3px rgba(245, 165, 36, 0.12);
}

input::placeholder, textarea::placeholder { color: #5f6470; }

.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; letter-spacing: 0.4px; }

.icon-btn {
  flex: 0 0 auto;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: #c3c7d1;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.is-active {
  border-color: rgba(245, 165, 36, 0.75);
  background: rgba(245, 165, 36, 0.10);
  color: #ffd7a0;
}
.chip:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  border-style: dashed;
}
.chip em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
}
.chip.is-active em { color: #d8b98c; }

.ratio-box { width: 14px; height: 10px; border: 1.5px solid currentColor; border-radius: 2px; display: inline-block; }
.ratio-box.tall { width: 10px; height: 14px; }

.optional summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #cfd2da;
  list-style: none;
}
.optional summary::-webkit-details-marker { display: none; }
.optional summary::before { content: "+ "; color: var(--accent); }
.optional[open] summary::before { content: "− "; }
.optional[open] { gap: 10px; }

/* 本地参考图上传 */
.upload-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.upload-drop:hover,
.upload-drop.is-over {
  border-color: rgba(245, 165, 36, 0.7);
  background: rgba(245, 165, 36, 0.06);
  color: #e6cfa8;
}
.upload-drop.has-file { border-style: solid; border-color: rgba(245, 165, 36, 0.45); color: #ffd7a0; }
.upload-plus { font-size: 16px; line-height: 1; }

.upload-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
}
.upload-preview img {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}
.upload-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}
.upload-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-meta .link-btn { align-self: flex-start; padding: 0; }

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: 13px;
  background: linear-gradient(135deg, #ffc46b, var(--accent) 45%, var(--accent-2));
  color: #221604;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(245, 165, 36, 0.22);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.primary:hover { filter: brightness(1.04); }
.primary:active { transform: translateY(1px); }
.primary:disabled { filter: grayscale(0.5) brightness(0.7); cursor: not-allowed; box-shadow: none; }
.primary-cost { font-weight: 600; font-size: 13px; opacity: 0.75; }

.footnote { margin: -6px 0 0; font-size: 12px; color: #6c717c; }

.alert {
  margin: 0;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.09);
  color: #ffb3b3;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview { padding: 16px; display: flex; flex-direction: column; gap: 14px; height: 100%; }

.stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.012) 0 12px, transparent 12px 24px),
    #0d0f14;
  overflow: hidden;
}

.stage.is-tall { max-width: 460px; width: 100%; margin: 0 auto; }

.stage.has-results { align-items: stretch; padding: 12px; overflow-y: auto; }

.stage-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #9aa0ac;
  font-size: 14px;
  text-align: center;
}
.stage-icon { color: #3d424d; }
.stage-empty p { margin: 0; }

.stage-status { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stage-status p { margin: 0; font-size: 14px; color: #cfd2da; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(245, 165, 36, 0.18);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  width: min(320px, 62vw);
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.4s ease;
}

/* 结果网格 */
.results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
  width: 100%;
}

/* 只生成一条时铺满整个预览区 */
.results[data-count="1"] { grid-template-columns: minmax(0, 1fr); }

.result-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
}

.result-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.014) 0 12px, transparent 12px 24px),
    #0b0d11;
}
.result-media.is-tall { aspect-ratio: 9 / 16; }

.result-media video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.result-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
}
.result-text { margin: 0; font-size: 13px; color: #cfd2da; line-height: 1.5; }
.result-status.is-error .result-text { color: #ffb3b3; font-size: 12.5px; }
.result-status.is-error { background: rgba(255, 107, 107, 0.06); }
.result-status .progress { width: min(220px, 70%); }

.result-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: #8b909c;
}
.result-meta.is-warn { color: #ffcf8a; }
.result-download:disabled { opacity: 0.4; cursor: not-allowed; }

.stage-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.secondary {
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: #cfd2da;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.secondary:hover:not(:disabled) { border-color: var(--border-strong); color: #fff; }
.secondary:disabled { opacity: 0.45; cursor: not-allowed; }

.muted { color: var(--muted); font-size: 12.5px; }

.history-wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px 60px; }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.history-head h2 { margin: 0; font-size: 14px; font-weight: 600; color: #cfd2da; }
.link-btn { background: none; border: none; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; }
.link-btn:hover { color: var(--text); }

.history { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.history-item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.history-item:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.play-badge {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding-left: 3px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  pointer-events: none;
  transition: background 0.15s ease, transform 0.15s ease;
}
.history-item:hover .play-badge { background: rgba(245, 165, 36, 0.85); border-color: transparent; }
.history-item video { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; }
.history-item .cap { padding: 8px 10px; font-size: 12px; color: #a8adb8; line-height: 1.4; }
.history-item .cap span { display: block; color: #6c717c; font-size: 11px; margin-top: 3px; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; padding: 4px 14px 20px; }
  .topbar { padding: 16px 14px 12px; }
  .preview { height: auto; }
  .stage { min-height: 280px; }
  .results { grid-template-columns: minmax(0, 1fr); }
  .history-wrap { padding: 0 14px 40px; }
}
