:root {
  color-scheme: dark;
  --bg: #111112;
  --panel: #191a1d;
  --panel-strong: #22242a;
  --text: #f4f1eb;
  --muted: #a9a39a;
  --line: #34363d;
  --gold: #d8ad55;
  --teal: #62c8ba;
  --red: #f57575;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(98, 200, 186, 0.18), transparent 30rem),
    radial-gradient(circle at 84% 8%, rgba(216, 173, 85, 0.16), transparent 26rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(380px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(25, 26, 29, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
}

.login-card input {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101113;
  color: var(--text);
  font: inherit;
}

.login-error {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--red);
  font-size: 13px;
}

.app {
  min-height: 100vh;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.workspace {
  width: min(1360px, 100%);
  display: grid;
  grid-template-columns: minmax(520px, 0.95fr) minmax(430px, 0.85fr);
  gap: 14px;
}

.editor,
.preview {
  background: rgba(25, 26, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
}

.title-row,
.preview-top,
.progress-label,
.actions,
.settings {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101113;
}

.field-hint {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.icon-button {
  width: 42px;
  min-height: 42px;
  margin-top: 0;
  color: var(--text);
  background: #101113;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
}

h2 {
  font-size: 20px;
}

.model-pill,
.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  white-space: nowrap;
  color: var(--muted);
  background: var(--panel-strong);
  font-size: 13px;
}

.status.working {
  color: var(--gold);
  border-color: rgba(216, 173, 85, 0.55);
}

.status.done {
  color: var(--teal);
  border-color: rgba(98, 200, 186, 0.55);
}

.status.error {
  color: var(--red);
  border-color: rgba(245, 117, 117, 0.55);
}

label {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

textarea,
select {
  width: 100%;
  margin-top: 8px;
  background: #101113;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  outline: none;
}

.model-select {
  min-width: 100%;
}

.model-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.model-info span,
.model-info b {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #101113;
  font-weight: 600;
}

.model-info b {
  color: var(--teal);
}

textarea {
  min-height: 250px;
  resize: vertical;
  padding: 12px;
  line-height: 1.62;
}

select {
  min-width: 160px;
  padding: 12px;
}

.duration-control {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 86px 28px;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

.duration-control input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.duration-control input[type="number"] {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101113;
  color: var(--text);
  font: inherit;
}

.duration-control span {
  color: var(--muted);
}

.field-hint {
  margin-top: 8px;
}

button,
.download {
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #f2d38a);
  color: #15110a;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
}

.icon-button {
  width: 42px;
  min-height: 42px;
  margin-top: 0;
  color: var(--text);
  background: #101113;
  border: 1px solid var(--line);
}

.secondary-button {
  min-height: 40px;
  margin-top: 10px;
  background: #101113;
  color: var(--text);
  border: 1px solid var(--line);
}

button:disabled,
.download.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.image-panel {
  margin-top: 6px;
}

.upload-box {
  display: grid;
  grid-template-columns: minmax(0, 210px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.upload-box input {
  width: 100%;
  margin-top: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #101113;
  color: var(--muted);
}

.image-preview {
  min-height: 74px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101113;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  overflow: hidden;
}

.image-preview[data-required="true"] {
  border-color: rgba(216, 173, 85, 0.65);
}

.image-preview img {
  width: 74px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
}

.image-preview span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-icon {
  font-size: 13px;
}

.preview {
  display: flex;
  flex-direction: column;
}

.result-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.balance-compact {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #101113;
  color: var(--muted);
  font-size: 12px;
}

.balance-compact strong {
  color: var(--text);
}

.tiny-icon-button {
  width: 26px;
  min-height: 26px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 13px;
}

.video-shell {
  margin-top: 14px;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #090a0b;
  position: relative;
}

video,
.empty-state {
  width: 100%;
  height: 100%;
}

video {
  object-fit: contain;
  background: #000;
}

.empty-state {
  display: grid;
  place-items: center;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}

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

.progress-wrap {
  margin-top: 12px;
}

.progress-label {
  color: var(--muted);
  font-size: 13px;
}

.progress-bar {
  height: 9px;
  margin-top: 10px;
  border-radius: 999px;
  background: #0f1012;
  border: 1px solid var(--line);
  overflow: hidden;
}

#progressFill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 300ms ease;
}

.download {
  margin-top: 12px;
}

#log {
  min-height: 48px;
  max-height: 90px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101113;
  color: var(--muted);
  white-space: pre-wrap;
  font-size: 12px;
}

.history-section {
  margin-top: 14px;
}

.history-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  max-height: 210px;
  overflow: auto;
}

.history-empty {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #101113;
}

.history-item {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #101113;
}

.history-item video {
  width: 132px;
  height: 74px;
  border-radius: 6px;
  object-fit: cover;
}

.history-meta {
  min-width: 0;
}

.history-line,
.history-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.history-line strong {
  color: var(--text);
  font-size: 13px;
}

.history-line span,
.history-tags span,
.history-meta p {
  color: var(--muted);
  font-size: 12px;
}

.history-meta p {
  margin: 8px 0;
  line-height: 1.5;
}

.history-tags span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
}

.history-download {
  display: inline-flex;
  margin-top: 10px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

@media (max-width: 900px) {
  .app {
    padding: 16px;
    align-items: stretch;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .title-row,
  .preview-top,
  .settings,
  .upload-box {
    align-items: flex-start;
    flex-direction: column;
  }

  .duration-control {
    grid-template-columns: 1fr;
  }

  .icon-button {
    width: 100%;
  }

  select {
    min-width: 100%;
  }

  textarea {
    min-height: 300px;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .history-item video {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }
}
