:root {
  --text: #16181d;
  --muted: #6a717c;
  --line: #e8e9ed;
  --soft: #f6f7f9;
  --blue: #2f73ff;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
body {
  min-height: 100vh;
  margin: 0;
  background: #fbfbfc;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
a { color: inherit; text-decoration: none; }
button, textarea { font: inherit; }
button { cursor: pointer; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(17, 24, 39, 0.06);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(16px);
}
.brand, .nav, .top-actions { display: flex; align-items: center; }
.brand { gap: 10px; font-size: 21px; font-weight: 800; }
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 12px; background: #111; color: #fff; font-size: 15px;
}
.nav { gap: 8px; padding: 5px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.nav a {
  min-height: 36px; display: inline-flex; align-items: center; border-radius: 999px;
  padding: 0 14px; color: var(--muted); font-size: 14px; font-weight: 700;
}
.nav a.active, .nav a:hover { background: #111; color: #fff; }
.top-actions { gap: 10px; }
.status-pill {
  min-height: 34px; display: inline-flex; align-items: center; border: 1px solid var(--line);
  border-radius: 999px; padding: 0 12px; background: #fff; color: var(--muted); font-size: 13px; font-weight: 800;
}
.status-pill.ok { color: #047857; border-color: #bbf7d0; background: #f0fdf4; }
.status-pill.error { color: #b42318; border-color: #fecaca; background: #fff7f7; }
.icon-button, .user-button { border: 1px solid var(--line); background: #fff; color: var(--text); }
.icon-button {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px;
}
.icon-button:disabled { cursor: not-allowed; opacity: 0.45; }
svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;
}
.user-button { min-height: 40px; border-radius: 999px; padding: 0 17px; font-weight: 800; }
.user-button.has-key { border-color: #bbf7d0; background: #f0fdf4; color: #047857; }
.workspace {
  width: min(100% - 32px, 1180px);
  min-height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: minmax(360px, 0.92fr) minmax(440px, 1.08fr);
  gap: 18px;
  margin: 0 auto;
  padding: 26px 0;
}
.composer, .preview-panel {
  border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: var(--shadow);
}
.composer, .preview-panel { display: flex; flex-direction: column; }
.section-head, .preview-head { padding: 22px 24px; border-bottom: 1px solid var(--line); }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.eyebrow { margin: 0; color: var(--blue); font-size: 13px; font-weight: 800; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { margin-top: 8px; font-size: clamp(32px, 4vw, 48px); line-height: 1.05; }
h2 { margin-top: 5px; font-size: 24px; }
.video-form { flex: 1; display: flex; flex-direction: column; gap: 15px; padding: 22px 24px 24px; }
.field-label, legend { color: #282c34; font-size: 14px; font-weight: 800; }
textarea {
  width: 100%; min-height: 190px; resize: vertical; border: 1px solid var(--line); border-radius: 18px;
  outline: 0; padding: 16px; background: #fcfcfd; color: var(--text); font-size: 16px; line-height: 1.65;
}
textarea:focus { border-color: rgba(47, 115, 255, 0.7); box-shadow: 0 0 0 4px rgba(47, 115, 255, 0.1); }
textarea::placeholder { color: #a0a7b2; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
fieldset { min-width: 0; margin: 0; border: 0; padding: 0; }
legend { margin-bottom: 9px; }
.segments { display: flex; flex-wrap: wrap; gap: 8px; }
.segments button {
  min-height: 36px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft);
  color: var(--muted); padding: 0 12px; font-size: 14px; font-weight: 800;
}
.segments button.selected { border-color: var(--blue); background: var(--blue); color: #fff; }
.form-actions { display: flex; gap: 10px; margin-top: auto; padding-top: 8px; }
.generate-button, .secondary-button {
  min-height: 48px; border: 0; border-radius: 15px; padding: 0 18px; font-weight: 900;
}
.generate-button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 9px; background: #111; color: #fff;
}
.generate-button:disabled { cursor: not-allowed; opacity: 0.55; }
.secondary-button { background: var(--soft); color: #4b5563; }
.video-stage {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden; margin: 24px 24px 0; border-radius: 22px; background: #080a0f;
}
.result-video {
  position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; object-fit: cover; background: #050505;
}
.result-video[hidden],
.play-button[hidden],
.progress-card[hidden] {
  display: none;
}
.video-art {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 72% 22%, rgba(59, 130, 246, 0.45), transparent 23%),
    linear-gradient(135deg, rgba(20, 184, 166, 0.28), transparent 38%),
    linear-gradient(180deg, #151827, #080a0f 68%);
}
.sun {
  position: absolute; top: 15%; right: 18%; width: 120px; height: 120px; border-radius: 999px;
  background: radial-gradient(circle, rgba(255,255,255,.95), rgba(59,130,246,.02) 70%); filter: blur(2px); opacity: .8;
}
.scan-lines {
  position: absolute; inset: auto 0 0; height: 38%;
  background-image: linear-gradient(90deg, rgba(255,255,255,.13) 1px, transparent 1px);
  background-size: 42px 100%; opacity: .42;
}
.subject {
  position: absolute; left: 12%; bottom: 0; width: 30%; height: 46%; border-radius: 28px 28px 0 0;
  background: linear-gradient(160deg, rgba(255,255,255,.18), rgba(255,255,255,.04));
}
.stage-state {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; align-content: center; gap: 12px;
  color: rgba(255,255,255,.72); font-size: 15px; font-weight: 800;
}
.stage-state svg { width: 46px; height: 46px; }
.stage-state.hidden { display: none; }
.play-button {
  position: absolute; z-index: 4; left: 50%; top: 50%; width: 72px; height: 72px; display: grid; place-items: center;
  transform: translate(-50%, -50%); border: 0; border-radius: 999px; background: #fff; color: #111;
  box-shadow: 0 18px 45px rgba(0,0,0,.32);
}
.play-button svg { width: 30px; height: 30px; fill: currentColor; stroke-width: 0; transform: translateX(2px); }
.progress-card {
  position: absolute; z-index: 4; left: 50%; bottom: 24px; width: min(360px, calc(100% - 48px)); transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.16); border-radius: 18px; padding: 15px; background: rgba(255,255,255,.12);
  color: #fff; backdrop-filter: blur(14px);
}
.progress-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 14px; }
.progress-track { height: 9px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.2); }
#progress-bar { width: 0; height: 100%; border-radius: inherit; background: #fff; transition: width 240ms ease; }
.meta-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 18px 24px 0;
}
.meta-grid div, .task-box { border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.meta-grid div { padding: 14px; }
.meta-grid span, .task-box span { display: block; color: var(--muted); font-size: 13px; font-weight: 800; }
.meta-grid strong { display: block; margin-top: 5px; font-size: 16px; }
.task-box { flex: 1; margin: 18px 24px 24px; padding: 16px; background: #fcfcfd; }
.task-box p { margin: 10px 0 0; color: #4b5563; font-size: 14px; line-height: 1.75; white-space: pre-wrap; }
.key-dialog {
  width: min(92vw, 480px);
  border: 0;
  border-radius: 22px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);
}
.key-dialog::backdrop {
  background: rgba(15, 23, 42, 0.24);
  backdrop-filter: blur(4px);
}
.key-panel {
  display: grid;
  gap: 14px;
  padding: 22px;
  background: #fff;
}
.key-head,
.key-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.key-head h2 {
  margin-top: 4px;
}
.key-panel label {
  font-size: 14px;
  font-weight: 800;
}
.key-panel input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: 0;
  padding: 0 14px;
  color: var(--text);
}
.key-panel input:focus {
  border-color: rgba(47, 115, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(47, 115, 255, 0.1);
}
.key-actions .generate-button {
  flex: 0 0 auto;
}
.video-stage.ready .video-art { animation: cinematicMove 5.5s ease-in-out infinite alternate; }
.video-stage.ready .subject { animation: subjectDrift 5.5s ease-in-out infinite alternate; }
@keyframes cinematicMove {
  from { transform: scale(1); filter: saturate(1); }
  to { transform: scale(1.055); filter: saturate(1.15); }
}
@keyframes subjectDrift {
  from { transform: translateX(0); }
  to { transform: translateX(16px); }
}
@media (max-width: 920px) {
  .topbar { padding: 0 16px; }
  .nav { display: none; }
  .workspace { grid-template-columns: 1fr; width: min(100% - 24px, 720px); padding: 16px 0 28px; }
}
@media (max-width: 560px) {
  .control-grid, .meta-grid { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; }
  .section-head, .preview-head, .video-form { padding-left: 18px; padding-right: 18px; }
  .video-stage, .task-box { margin-left: 18px; margin-right: 18px; }
  .meta-grid { padding-left: 18px; padding-right: 18px; }
}
