:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --border: #e4e8f0;
  --text: #1c2333;
  --text-2: #5b6478;
  --text-3: #8a92a6;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { font-size: 40px; }
.brand h1 { font-size: 20px; font-weight: 700; }
.brand-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.brand-sub code {
  font-size: 12px; background: var(--accent-soft); color: var(--accent);
  padding: 1px 6px; border-radius: 6px;
}

.quota-badge {
  font-size: 13px; font-weight: 600; color: var(--green);
  background: #ecfdf3; border: 1px solid #bbf0d0;
  padding: 7px 14px; border-radius: 999px; white-space: nowrap;
}

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  gap: 24px;
  padding: 24px 32px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.panel h2 { font-size: 16px; margin-bottom: 18px; }

/* ---------- Creator ---------- */
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }

.prompt-wrap { position: relative; }
textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px 26px;
  font-size: 14px;
  line-height: 1.6;
  font-family: inherit;
  color: var(--text);
  background: #fafbfd;
  transition: border-color .15s;
}
textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.char-count {
  position: absolute; right: 12px; bottom: 10px;
  font-size: 12px; color: var(--text-3);
}

.examples { margin-top: 16px; }
.examples-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.example-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  border: 1px solid var(--border);
  background: #fafbfd;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-2);
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.options-grid { margin-top: 20px; display: flex; flex-direction: column; gap: 18px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg-item {
  border: 1px solid var(--border);
  background: #fafbfd;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  transition: all .15s;
}
.seg-sub { font-size: 11px; color: var(--text-3); }
.seg-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.seg-item.active .seg-sub { color: var(--accent); opacity: .8; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.range-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); }

.cost-hint {
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-2);
  background: #fffaeb;
  border: 1px solid #fde9b8;
  border-radius: 10px;
  padding: 10px 14px;
}
.cost-hint b { color: #b45309; }

.btn-primary {
  margin-top: 18px;
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(.99); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.fine-print { margin-top: 12px; font-size: 12px; color: var(--text-3); text-align: center; }

/* ---------- Preview ---------- */
.preview { min-height: 560px; display: flex; flex-direction: column; }

.stage {
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fafbfd;
  min-height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}

.stage-empty { text-align: center; color: var(--text-3); }
.stage-empty-icon { font-size: 48px; margin-bottom: 10px; }

.stage-loading { text-align: center; width: 100%; max-width: 360px; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-status { font-size: 15px; font-weight: 600; color: var(--text); }
.loading-elapsed { margin-top: 6px; font-size: 13px; color: var(--text-3); }
.progress-track {
  margin-top: 14px; height: 8px;
  background: #e8ebf3; border-radius: 999px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  border-radius: 999px;
  transition: width 1s linear;
}

.stage-result { width: 100%; display: flex; flex-direction: column; gap: 12px; }
#videoPlayer {
  width: 100%;
  max-height: 480px;
  border-radius: 10px;
  background: #000;
}
.result-meta { font-size: 13px; color: var(--text-2); }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
}
.btn-secondary:hover { background: #e2e6ff; }

.stage-error { text-align: center; max-width: 420px; }
.stage-error-icon { font-size: 40px; margin-bottom: 8px; }
.stage-error p { font-size: 14px; color: var(--red); line-height: 1.7; }

/* ---------- History ---------- */
.history { margin-top: 20px; }
.history-head { display: flex; align-items: center; justify-content: space-between; }
.history-head h3 { font-size: 14px; }
.link-btn {
  border: none; background: none; color: var(--accent);
  font-size: 13px; cursor: pointer;
}
.history-note { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.history-list { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; cursor: pointer;
  transition: border-color .15s;
  background: #fafbfd;
}
.history-item:hover { border-color: var(--accent); }
.history-thumb {
  width: 72px; height: 44px; border-radius: 6px;
  object-fit: cover; background: #000; flex-shrink: 0;
}
.history-info { flex: 1; min-width: 0; }
.history-prompt {
  font-size: 13px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-meta { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.history-status { font-size: 12px; flex-shrink: 0; }
.history-status.ok { color: var(--green); }
.history-status.fail { color: var(--red); }
.history-empty { font-size: 13px; color: var(--text-3); padding: 8px 0; }

.hidden { display: none !important; }

/* ---------- Footer ---------- */
.site-footer {
  padding: 16px 32px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}
.site-footer code { background: #f0f2f7; padding: 1px 5px; border-radius: 4px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .site-header { padding: 14px 16px; }
}
