:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --surface: #ffffff;
  --soft: #f8faf8;
  --text: #1f2320;
  --muted: #66716b;
  --line: #d9ded8;
  --accent: #087f6f;
  --accent-dark: #06695d;
  --ok: #1f7a4d;
  --warn: #b78216;
  --danger: #b13d32;
  --shadow: 0 16px 40px rgba(25, 31, 28, 0.08);
  font-family: "Segoe UI", "Noto Sans TC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar,
.settings-panel,
.copy-panel,
.workspace,
.history-head,
.form-head,
.run-head,
.result-actions,
.progress-meta {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.08rem;
}

.config-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.pill.ok,
.status-badge.complete {
  color: var(--ok);
  border-color: rgba(31, 122, 77, 0.28);
  background: #edf8f0;
}

.pill.warn,
.status-badge.failed {
  color: var(--danger);
  border-color: rgba(177, 61, 50, 0.28);
  background: #fff0ed;
}

.status-badge.running {
  color: var(--warn);
  border-color: rgba(183, 130, 22, 0.32);
  background: #fff8e6;
}

.settings-panel,
.creator,
.run-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-panel {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 18px 20px;
}

.settings-panel p,
.form-head p,
.run-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.92rem;
}

.api-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(210px, 1fr)) auto;
  align-items: end;
  gap: 10px;
  width: min(100%, 820px);
}

.flow-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.flow-strip div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.flow-strip strong {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
}

.flow-strip span {
  font-weight: 800;
}

.workspace {
  align-items: stretch;
  gap: 18px;
}

.copy-panel {
  align-items: stretch;
  gap: 18px;
  margin-bottom: 18px;
}

.source-form,
.copy-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.source-form {
  display: grid;
  flex: 0.9;
  gap: 14px;
  padding: 22px;
}

.source-form p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.92rem;
}

.copy-status {
  flex: 1.1;
  padding: 22px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

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

.creator {
  flex: 1.05;
  padding: 22px;
}

.run-panel {
  flex: 0.95;
  padding: 22px;
}

.form-head,
.run-head {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.field.compact {
  margin-bottom: 0;
}

.field.wide {
  grid-column: 1 / 3;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--text);
  outline: none;
}

.field input {
  height: 42px;
  padding: 0 12px;
}

.field textarea {
  min-height: 74px;
  padding: 10px 12px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 111, 0.14);
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.dropzone {
  position: relative;
  display: grid;
  min-height: 260px;
  place-items: center;
  align-content: center;
  gap: 8px;
  overflow: hidden;
  border: 1.5px dashed #aeb8b1;
  border-radius: 8px;
  background: var(--soft);
  cursor: pointer;
}

.dropzone:hover,
.dropzone:focus-within {
  border-color: var(--accent);
  background: #eef9f5;
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.zone-title {
  font-size: 1.08rem;
  font-weight: 900;
}

.zone-meta {
  max-width: calc(100% - 24px);
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  text-align: center;
}

#cloneVideoPreview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}

.dropzone:has(#cloneVideoPreview:not([hidden])) .zone-title,
.dropzone:has(#cloneVideoPreview:not([hidden])) .zone-meta {
  z-index: 1;
  padding: 6px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.88);
}

#audioPreview {
  width: min(92%, 280px);
  z-index: 1;
}

.primary,
.secondary,
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.primary {
  color: #fff;
  background: var(--accent);
}

.primary:hover {
  background: var(--accent-dark);
}

.primary:disabled,
.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.secondary {
  color: var(--accent-dark);
  border-color: rgba(8, 127, 111, 0.28);
  background: #eef8f4;
}

.ghost {
  color: var(--text);
  border-color: var(--line);
  background: var(--surface);
}

.progress-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ebe5;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

.progress-meta {
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.steps {
  display: grid;
  gap: 8px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.step {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  min-height: 42px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.step-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: var(--muted);
  background: #e7ebe5;
  font-size: 0.76rem;
  font-weight: 900;
}

.step.complete .step-mark {
  color: white;
  background: var(--ok);
}

.step.running .step-mark {
  color: white;
  background: var(--warn);
}

.step.failed .step-mark {
  color: white;
  background: var(--danger);
}

.step-title {
  font-weight: 900;
}

.step-detail {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.result {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.result video {
  width: 100%;
  max-height: 360px;
  border-radius: 8px;
  background: #111;
}

.result-actions {
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.error-box {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(177, 61, 50, 0.25);
  background: #fff0ed;
  color: var(--danger);
  font-weight: 800;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.55;
}

.text-output {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.text-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.text-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.text-output p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.text-output textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}

.text-output textarea + textarea {
  min-height: 82px;
}

.prompt-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.prompt-field textarea {
  min-height: 220px;
  white-space: pre-wrap;
}

.copy-result {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.copy-result textarea {
  min-height: 160px;
  white-space: pre-wrap;
}

.small-link {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.84rem;
}

.history-band {
  margin-top: 22px;
  padding-top: 22px;
}

.history-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.job-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  cursor: pointer;
  text-align: left;
}

.job-card:hover {
  border-color: rgba(8, 127, 111, 0.35);
}

.job-card strong {
  display: block;
  margin-bottom: 7px;
  overflow-wrap: anywhere;
}

.job-card span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
}

@media (max-width: 920px) {
  .topbar,
  .settings-panel,
  .copy-panel,
  .workspace {
    display: grid;
  }

  .api-form {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .flow-strip,
  .job-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .config-strip {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 22px, 1120px);
    padding-top: 18px;
  }

  .form-head,
  .run-head {
    align-items: stretch;
    flex-direction: column;
  }

  .primary,
  .secondary,
  .ghost {
    width: 100%;
  }

  .upload-grid,
  .flow-strip,
  .job-list {
    grid-template-columns: 1fr;
  }

  .dropzone {
    min-height: 220px;
  }
}
