:root {
  --navy: #17324d;
  --muted: #557083;
  --sky: #eaf7ff;
  --sky-deep: #bde7fb;
  --white: #fffdf8;
  --yellow: #ffd45c;
  --yellow-deep: #e6a72c;
  --coral: #f27c68;
  --coral-deep: #d95d4e;
  --mint: #bfe8d1;
  --mint-deep: #4d9d78;
  --line: #c4dce6;
  --radius: 18px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--navy);
  background: var(--sky);
  font-family: "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
  letter-spacing: 0;
}
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, select, label { -webkit-tap-highlight-color: transparent; }

.topbar { min-height: 76px; padding: 0 clamp(18px, 5vw, 70px); display: flex; align-items: center; justify-content: space-between; background: var(--white); border-bottom: 2px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; color: var(--navy); text-decoration: none; font-size: 19px; font-weight: 800; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; color: var(--navy); background: var(--yellow); border: 2px solid var(--yellow-deep); border-radius: 12px; font-size: 20px; transform: rotate(-6deg); }
.connection { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.connection-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--yellow-deep); box-shadow: 0 0 0 4px rgba(230, 167, 44, .18); }
.connection.ready .connection-dot { background: var(--mint-deep); box-shadow: 0 0 0 4px rgba(77, 157, 120, .17); }
.connection.error .connection-dot { background: var(--coral-deep); box-shadow: 0 0 0 4px rgba(217, 93, 78, .17); }
.topbar-actions { display: flex; align-items: center; gap: clamp(14px, 3vw, 30px); }
.history-button { padding: 10px 15px; border: 2px solid var(--navy); border-radius: 11px; color: var(--navy); background: transparent; font-size: 13px; font-weight: 900; cursor: pointer; transition: background 160ms ease, transform 160ms ease; }
.history-button:hover { background: var(--sky); transform: translateY(-2px); }

.workspace { width: min(1440px, 100%); margin: 0 auto; display: grid; grid-template-columns: minmax(0, .95fr) minmax(420px, 1.05fr); }
.composer, .output { min-width: 0; padding: clamp(28px, 5vw, 70px) clamp(18px, 4vw, 62px); }
.composer { border-right: 2px solid var(--line); }
.section-heading { max-width: 660px; margin-bottom: 32px; }
.kicker { margin: 0 0 10px; color: var(--coral-deep); font-size: 12px; font-weight: 800; letter-spacing: .08em; }
h1, h2 { margin: 0; color: var(--navy); font-weight: 900; }
h1 { max-width: 660px; font-size: clamp(34px, 4.4vw, 62px); line-height: 1.12; }
h2 { font-size: 30px; }
.heading-note { max-width: 520px; margin: 16px 0 0; color: var(--muted); font-size: 15px; line-height: 1.7; }

form { display: grid; gap: 16px; }
.asset-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.drop-field, .prompt-field { position: relative; min-width: 0; padding: 19px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--white); transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease; }
.drop-field { min-height: 136px; display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 12px; }
.drop-field:hover, .drop-field.dragging, .prompt-field:focus-within { border-color: var(--coral); transform: translateY(-2px); box-shadow: 0 8px 0 rgba(23, 50, 77, .06); }
.drop-field.has-file { border-color: var(--mint-deep); background: #f4fcf6; }
.drop-field > input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.field-index { width: 30px; height: 30px; display: grid; place-items: center; color: var(--navy); background: var(--sky-deep); border-radius: 10px; font-size: 13px; font-weight: 900; }
.field-copy { min-width: 0; display: grid; gap: 8px; }
.field-copy strong, .prompt-label { font-size: 16px; font-weight: 900; }
.field-copy span { color: var(--muted); font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }
.field-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.field-action { min-height: 34px; padding: 5px 10px; border: 0; border-radius: 9px; color: var(--navy); background: var(--yellow); font-size: 12px; font-weight: 900; cursor: pointer; }
.field-action.secondary { color: var(--muted); background: var(--sky); }
.field-action:hover { background: var(--yellow-deep); }
.field-action.secondary:hover { background: var(--sky-deep); }
.field-action.recording { color: var(--white); background: var(--coral); animation: recordPulse 1.2s ease-in-out infinite; }

.scene-fields { display: grid; gap: 16px; }
.prompt-field { display: grid; grid-template-columns: 1fr; gap: 9px; }
.prompt-label { align-self: center; }
textarea, .prompt-field select { grid-column: 1; width: 100%; min-height: 48px; padding: 8px 0 5px; border: 0; outline: 0; resize: vertical; color: var(--navy); background: transparent; line-height: 1.7; }
textarea { min-height: 118px; padding-bottom: 30px; }
.prompt-field select { min-height: 42px; border-bottom: 2px solid var(--line); font-size: 15px; font-weight: 800; cursor: pointer; }
.scene-choice-field .field-copy { grid-column: 1; gap: 8px; }
.scene-choice-field select { grid-column: auto; }
.scene-choice-value { color: var(--coral-deep); font-size: 12px; font-weight: 800; }
textarea::placeholder { color: #8ba4b2; }
.char-count { position: absolute; right: 19px; bottom: 14px; color: var(--muted); font-size: 11px; font-weight: 700; }

.settings-strip { display: grid; grid-template-columns: minmax(110px, 1fr) minmax(110px, 1fr) minmax(160px, 1.4fr); border: 2px solid var(--line); border-radius: var(--radius); background: var(--white); overflow: hidden; }
.settings-strip > label { min-width: 0; min-height: 78px; padding: 13px 16px; display: flex; flex-direction: column; justify-content: center; gap: 6px; border-right: 2px solid var(--line); }
.settings-strip label > span:first-child { color: var(--muted); font-size: 11px; font-weight: 800; }
select { width: 100%; padding: 0 20px 0 0; border: 0; outline: 0; color: var(--navy); background: transparent; font-size: 14px; font-weight: 900; cursor: pointer; }
.submit-button { min-height: 78px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; border: 0; color: var(--navy); background: var(--yellow); font-size: 17px; font-weight: 900; cursor: pointer; transition: background 160ms ease, transform 160ms ease; }
.submit-button:hover { background: var(--yellow-deep); transform: translateY(-2px); }
.submit-button:disabled { cursor: wait; opacity: .68; }
.button-arrow { font-size: 25px; }

.output { display: flex; flex-direction: column; background: #f5fbff; }
.output-heading { margin-bottom: 22px; display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.task-id { max-width: 52%; color: var(--muted); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage { position: relative; flex: 1; min-height: 490px; display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; border: 2px solid var(--line); border-radius: 24px; background: var(--navy); box-shadow: 0 10px 0 rgba(23, 50, 77, .08); }
.stage::before { content: ""; position: absolute; inset: 18px; border: 2px dashed rgba(255, 255, 255, .18); border-radius: 17px; pointer-events: none; }
.empty-state, .progress-state, .error-state { position: relative; z-index: 1; text-align: center; color: #edf8ff; }
.empty-number { display: block; color: var(--yellow); font-size: 70px; line-height: 1; animation: floatStar 2.8s ease-in-out infinite; }
.empty-state p { margin: 14px 0 0; font-size: 17px; font-weight: 800; }
.progress-state { width: min(520px, 86%); padding: 30px 26px 24px; text-align: left; }
.progress-orbit { position: relative; width: 72px; height: 72px; margin: 0 auto 18px; border: 2px solid rgba(255, 212, 92, .46); border-radius: 50%; display: grid; place-items: center; animation: orbitPulse 2.6s ease-in-out infinite; }
.progress-orbit::before, .progress-orbit::after { content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--yellow); }
.progress-orbit::before { transform: translateY(-36px); animation: orbitSpin 2.6s linear infinite; }
.progress-orbit::after { width: 6px; height: 6px; background: var(--coral); }
.progress-eyebrow { margin: 0 0 8px; color: #a9d2e7; font-size: 11px; font-weight: 900; text-align: center; }
.progress-state .progress-title { color: #fffdf8; text-align: center; }
.progress-title { margin: 0; font-size: 23px; font-weight: 900; }
.progress-detail { min-height: 18px; margin: 9px 0 24px; color: #b6cfdd; font-size: 12px; text-align: center; }
.progress-meter { height: 9px; margin: 20px 0 22px; overflow: hidden; border-radius: 12px; background: rgba(255, 255, 255, .16); }
.progress-meter span { display: block; width: 38%; height: 100%; border-radius: inherit; background: var(--yellow); animation: progressSlide 2.2s ease-in-out infinite; }
.progress-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.progress-step { min-width: 0; padding: 11px 9px; border: 1px solid rgba(255, 255, 255, .18); border-radius: 10px; color: #8facba; transition: border-color 180ms ease, background 180ms ease, color 180ms ease; }
.progress-step span, .progress-step strong, .progress-step small { display: block; }
.progress-step span { margin-bottom: 8px; color: #83a2b2; font-size: 11px; font-weight: 900; }
.progress-step strong { color: inherit; font-size: 12px; }
.progress-step small { margin-top: 4px; color: #7594a4; font-size: 10px; }
.progress-step.active { border-color: var(--yellow); color: #fffdf8; background: rgba(255, 212, 92, .12); }
.progress-step.done { border-color: var(--mint); color: var(--mint); }
.progress-step.done span::after { content: "  ✓"; color: var(--mint); }
.progress-foot { margin-top: 16px; display: flex; justify-content: space-between; gap: 12px; color: #87a6b5; font-size: 10px; font-weight: 700; }
.result-state { width: 100%; height: 100%; }
.result-state video { width: 100%; height: 100%; display: block; object-fit: contain; background: #102638; }
.error-state { width: min(460px, 82%); }
.error-code { color: #ffad9f; font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.error-state button { margin-top: 16px; padding: 10px 17px; border: 2px solid #a9c8d8; border-radius: 10px; color: #edf8ff; background: transparent; cursor: pointer; }
.result-meta { min-height: 78px; padding-top: 18px; display: grid; grid-template-columns: .7fr 1fr 1.8fr auto; gap: 18px; align-items: center; }
.result-meta div { display: grid; gap: 4px; }
.result-meta span { color: var(--muted); font-size: 10px; font-weight: 700; }
.result-meta strong { font-size: 13px; }
.result-meta a { padding: 11px 16px; border: 0; border-radius: 10px; color: var(--navy); background: var(--yellow); text-decoration: none; font-size: 12px; font-weight: 900; text-align: center; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 30; max-width: min(520px, calc(100vw - 36px)); padding: 13px 17px; transform: translateX(-50%); border: 2px solid var(--navy); border-radius: 12px; color: var(--white); background: var(--navy); font-size: 13px; font-weight: 700; box-shadow: 0 8px 0 rgba(23, 50, 77, .14); }
.history-backdrop { position: fixed; inset: 0; z-index: 24; background: rgba(23, 50, 77, .24); }
.history-panel { position: fixed; z-index: 25; top: 0; right: 0; bottom: 0; width: min(440px, calc(100% - 28px)); padding: 28px 24px; overflow-y: auto; transform: translateX(105%); color: var(--navy); background: var(--white); box-shadow: -12px 0 30px rgba(23, 50, 77, .15); transition: transform 240ms ease-out; }
.history-panel.open { transform: translateX(0); }
.history-panel-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; padding-bottom: 18px; border-bottom: 2px solid var(--line); }
.history-panel-head .kicker { margin-bottom: 7px; }
.history-panel-head h2 { font-size: 28px; }
.history-close { width: 36px; height: 36px; border: 2px solid var(--line); border-radius: 50%; color: var(--navy); background: transparent; font-size: 24px; line-height: 1; cursor: pointer; }
.history-close:hover { border-color: var(--coral); color: var(--coral-deep); }
.history-list { display: grid; gap: 12px; padding-top: 18px; }
.history-empty { margin: 0; padding: 28px 8px; color: var(--muted); text-align: center; font-size: 14px; }
.history-item { padding: 15px; border: 2px solid var(--line); border-radius: 14px; background: #f5fbff; }
.history-item-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.history-item-title { margin: 0; font-size: 15px; font-weight: 900; }
.history-item-time { color: var(--muted); font-size: 10px; }
.history-item-text { margin: 9px 0 12px; color: var(--muted); font-size: 12px; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history-item-link { display: inline-block; padding: 8px 12px; border-radius: 9px; color: var(--navy); background: var(--yellow); text-decoration: none; font-size: 12px; font-weight: 900; }
.history-item-status { color: var(--coral-deep); font-size: 12px; font-weight: 900; }
.hidden { display: none !important; }

.progress-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(23, 50, 77, .95); backdrop-filter: blur(10px); }
.progress-overlay::before { content: ""; position: absolute; inset: 6%; border: 2px dashed rgba(255, 212, 92, .28); border-radius: 28px; pointer-events: none; }
.progress-close { position: absolute; top: 20px; right: 22px; width: 40px; height: 40px; border: 2px solid rgba(255, 253, 248, .62); border-radius: 50%; color: var(--white); background: transparent; font-size: 27px; line-height: 1; cursor: pointer; }
.progress-close:hover { color: var(--navy); background: var(--yellow); border-color: var(--yellow); }
.progress-overlay-content { position: relative; width: min(680px, calc(100% - 42px)); text-align: center; }
.progress-overlay-kicker { margin: 0 0 14px; color: var(--yellow); font-size: 12px; font-weight: 900; letter-spacing: .14em; }
.progress-overlay h2 { color: var(--white); font-size: clamp(31px, 5vw, 56px); }
.flow-progress { position: relative; height: 14px; margin: 40px 0 18px; overflow: hidden; border: 2px solid rgba(255, 253, 248, .28); border-radius: 20px; background: rgba(255, 253, 248, .1); }
.flow-progress::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(115deg, transparent 0 14px, rgba(255, 255, 255, .1) 14px 23px); animation: flowShimmer 1.2s linear infinite; }
.flow-progress span { position: relative; z-index: 1; display: block; width: 3%; height: 100%; border-radius: inherit; background: var(--yellow); box-shadow: 0 0 18px rgba(255, 212, 92, .7); transition: width 700ms ease-out; }
.flow-progress i { position: absolute; z-index: 2; top: 50%; left: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 0 5px rgba(242, 124, 104, .18), 0 0 22px rgba(242, 124, 104, .82); transform: translate(-50%, -50%); animation: flowGlow 1.5s ease-in-out infinite; }
.overlay-progress-value { display: block; color: var(--white); font-size: 18px; font-weight: 900; }
.overlay-progress-hint { min-height: 20px; margin: 10px 0 0; color: #b6cfdd; font-size: 13px; font-weight: 700; }

@keyframes floatStar { 0%, 100% { transform: translateY(0) rotate(-5deg); } 50% { transform: translateY(-8px) rotate(5deg); } }
@keyframes recordPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(242, 124, 104, .38); } 50% { box-shadow: 0 0 0 8px rgba(242, 124, 104, 0); } }
@keyframes orbitPulse { 0%, 100% { transform: scale(.96); opacity: .72; } 50% { transform: scale(1.04); opacity: 1; } }
@keyframes orbitSpin { to { transform: rotate(360deg) translateY(-36px) rotate(-360deg); } }
@keyframes progressSlide { 0% { transform: translateX(-120%); } 60%, 100% { transform: translateX(300%); } }
@keyframes flowShimmer { to { transform: translateX(36px); } }
@keyframes flowGlow { 0%, 100% { opacity: .65; } 50% { opacity: 1; } }

@media (max-width: 1020px) {
  .workspace { grid-template-columns: 1fr; }
  .composer { border-right: 0; border-bottom: 2px solid var(--line); }
  .stage { min-height: 420px; }
}
@media (max-width: 680px) {
  .topbar { min-height: 64px; padding-inline: 16px; }
  .brand { font-size: 16px; }
  .connection { font-size: 11px; }
  .history-button { padding: 8px 10px; font-size: 12px; }
  .workspace { display: block; }
  .composer, .output { padding: 28px 15px; }
  h1 { font-size: 38px; }
  .heading-note { font-size: 14px; }
  .asset-row { grid-template-columns: 1fr; }
  .drop-field { min-height: 112px; }
  .settings-strip { grid-template-columns: 1fr 1fr; }
  .settings-strip > label { border-bottom: 2px solid var(--line); }
  .settings-strip > label:nth-child(2) { border-right: 0; }
  .submit-button { grid-column: 1 / -1; }
  .stage { min-height: 360px; aspect-ratio: 4 / 5; }
  .progress-state { padding-inline: 16px; }
  .progress-overlay::before { inset: 4%; }
  .progress-overlay-content { width: min(680px, calc(100% - 28px)); }
  .progress-close { top: 13px; right: 13px; }
  .progress-step { padding: 9px 6px; }
  .progress-step small { display: none; }
  .result-meta { grid-template-columns: 1fr 1fr; }
  .result-meta a { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
