:root {
  --bg: #f6f7f8;
  --card: #ffffff;
  --text: #1e2329;
  --muted: #737b86;
  --line: #e5e8ec;
  --accent: #ef4b3f;
  --accent-soft: #fff0ee;
  --teal: #14b8a6;
  --teal-soft: #e9fbf8;
  --shadow: 0 10px 30px rgba(31, 38, 46, .08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 460px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 14px 98px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 14px;
}

.topbar > div {
  flex: 1 1 auto;
  min-width: 0;
}

.topbar h1,
.topbar p,
.section h2,
.step-title h2,
.assistant-head h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar p,
.step-title p,
.assistant-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.icon-btn,
.history-btn,
.text-btn {
  border: 0;
  background: transparent;
  color: var(--text);
}

.icon-btn {
  width: 42px;
  height: 42px;
  font-size: 24px;
}

.history-btn {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.credit-card,
.step-card,
.assistant-card,
.result-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.credit-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 12px;
  gap: 10px;
}

.credit-card div {
  min-width: 0;
}

.label,
.credit-card strong {
  display: block;
}

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

.credit-card strong {
  margin-top: 5px;
  font-size: 15px;
}

.section {
  margin-top: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h2 {
  font-size: 16px;
  white-space: nowrap;
}

.text-btn {
  color: var(--accent);
}

.template-row {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding-bottom: 8px;
  cursor: grab;
  overscroll-behavior-x: contain;
  scroll-behavior: smooth;
  scrollbar-color: #c6ced8 transparent;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.template-row::-webkit-scrollbar {
  height: 6px;
}

.template-row::-webkit-scrollbar-track {
  background: transparent;
}

.template-row::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #c6ced8;
}

.template-row.is-dragging {
  cursor: grabbing;
  scroll-behavior: auto;
  user-select: none;
}

.template-chip {
  flex: 0 0 auto;
  min-width: 86px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}

.template-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.step-card,
.assistant-card,
.result-card {
  padding: 16px;
}

.step-title,
.assistant-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.step-title > span,
.bot-dot {
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 800;
  font-size: 13px;
}

.step-title h2,
.assistant-head h2 {
  font-size: 16px;
  white-space: nowrap;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.upload-box {
  display: grid;
  gap: 8px;
  min-height: 188px;
  padding: 10px;
  border: 1px dashed #cfd5dd;
  border-radius: 8px;
  text-align: center;
  background: #fbfcfd;
}

.upload-box input {
  display: none;
}

.upload-box img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  background: #eef1f4;
}

.upload-box strong {
  font-size: 14px;
}

.upload-box small {
  color: var(--muted);
  font-size: 11px;
}

.asset-group {
  display: grid;
  gap: 7px;
  margin-top: 13px;
}

.asset-group > span {
  color: var(--muted);
  font-size: 12px;
}

.asset-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
}

.asset-thumb {
  overflow: hidden;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #eef1f4;
}

.asset-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.asset-thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.form-stack {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.form-stack label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-row > label {
  min-width: 0;
}

.field-help {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
}

.mode-summary {
  display: grid;
  gap: 3px;
  padding: 11px 12px;
  border: 1px solid #bfe9e3;
  border-radius: 8px;
  background: var(--teal-soft);
}

.mode-summary strong {
  color: #0f766e;
  font-size: 13px;
}

.mode-summary span {
  color: #367c75;
  font-size: 12px;
  line-height: 1.45;
}

.advanced-media-settings {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.settings-label {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.file-field span {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px dashed #cfd5dd;
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-weight: 400;
}

.file-field input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.form-stack input[type="range"] {
  height: 30px;
  padding: 0;
  border: 0;
  box-shadow: none;
  accent-color: var(--accent);
}

.form-stack output {
  float: right;
  color: var(--accent);
  font-weight: 700;
}

.form-stack input,
.form-stack select,
.form-stack textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  padding: 12px;
  font-weight: 400;
  outline: none;
}

.form-stack textarea {
  resize: vertical;
}

.form-stack input:focus,
.form-stack select:focus,
.form-stack textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, .12);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.button-row.single-action {
  grid-template-columns: 1fr;
}

.optional-script-card {
  padding: 0;
}

.script-details {
  padding: 16px;
}

.script-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  font-size: 15px;
  font-weight: 800;
}

.script-details summary::-webkit-details-marker {
  display: none;
}

.script-details summary::after {
  content: "+";
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #f1f3f5;
  color: var(--muted);
  font-size: 20px;
  font-weight: 400;
}

.script-details[open] summary::after {
  content: "−";
}

.script-details summary small {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.storyboard-status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: #0f766e;
  font-size: 12px;
  line-height: 1.5;
}

.storyboard-status.error {
  background: var(--accent-soft);
  color: #b42318;
}

.storyboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.storyboard-item {
  overflow: hidden;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #eef1f4;
  text-align: left;
}

.storyboard-item.active {
  border-color: var(--accent);
}

.storyboard-item img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
}

.storyboard-item span {
  display: block;
  overflow: hidden;
  padding: 8px;
  background: var(--card);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.secondary-btn,
.primary-btn {
  height: 48px;
  border-radius: 8px;
  border: 0;
  font-weight: 800;
}

.secondary-btn:disabled,
.primary-btn:disabled {
  cursor: wait;
  opacity: .72;
}

.is-loading::before {
  content: "";
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -2px;
  animation: button-spin .7s linear infinite;
}

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

.secondary-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}

.secondary-btn.accent-outline {
  border-color: rgba(239, 75, 63, .45);
  color: #d83b31;
  background: var(--accent-soft);
}

.primary-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 26px rgba(239, 75, 63, .28);
}

.suggestion-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.suggestion-item {
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: #0f766e;
  font-size: 13px;
  line-height: 1.55;
}

.script-box {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.shot {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.shot b {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.shot strong {
  display: block;
  font-size: 14px;
}

.shot small,
.shot em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.shot-copy {
  display: block;
  margin-top: 4px;
  color: #46505c;
  font-size: 12px;
  line-height: 1.45;
}

.narration-block {
  padding: 12px;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--accent-soft);
  font-size: 13px;
  line-height: 1.65;
}

.prompt-block {
  padding: 12px;
  border-radius: 8px;
  background: #f7f8fa;
  color: #3e4651;
  font-size: 13px;
  line-height: 1.6;
}

.preview-phone {
  position: relative;
  overflow: hidden;
  width: min(260px, 76vw);
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  border-radius: 8px;
  background: #e8ebef;
}

.preview-phone img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-copy {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 14px;
  display: grid;
  gap: 6px;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .45);
}

.preview-copy strong {
  font-size: 22px;
}

.preview-copy span {
  font-size: 13px;
}

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

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.progress-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #e9edf2;
}

.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width .25s ease;
}

#videoPlayer {
  display: block;
  width: 100%;
  max-height: 70vh;
  margin-top: 14px;
  border-radius: 8px;
  background: #111;
}

.result-actions,
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.action-link {
  display: grid;
  place-items: center;
  text-decoration: none;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 24, 29, .52);
}

.modal-panel {
  width: min(100%, 460px);
  max-height: min(88vh, 760px);
  overflow: auto;
  padding: 16px;
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 24px 64px rgba(15, 23, 42, .24);
}

.history-panel {
  width: min(100%, 680px);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2,
.modal-head p {
  margin: 0;
}

.modal-head h2 {
  font-size: 18px;
}

.modal-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.modal-close {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: #f1f3f5;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.modal-field {
  display: grid;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.modal-field input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

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

.history-item {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.history-item video {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  background: #111;
  object-fit: cover;
}

.history-copy {
  min-width: 0;
  padding: 10px;
}

.history-copy h3,
.history-copy p {
  margin: 0;
}

.history-copy h3 {
  overflow: hidden;
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-copy p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.history-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.history-actions a,
.history-actions button {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}

.history-empty {
  padding: 36px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.bottom-actions {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(100%, 460px);
  transform: translateX(-50%);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(246, 247, 248, .92);
  backdrop-filter: blur(12px);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 20;
  max-width: min(88vw, 420px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(30, 35, 41, .92);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: .2s ease;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 860px) {
  .app-shell {
    width: min(100%, 980px);
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 14px;
    align-items: start;
  }

  .topbar,
  .credit-card,
  .section,
  .step-card,
  .assistant-card {
    grid-column: 1;
  }

  .result-card {
    position: sticky;
    top: 16px;
    grid-column: 2;
    grid-row: 2 / span 6;
  }

  .bottom-actions {
    width: min(100%, 980px);
  }
}

@media (max-width: 520px) {
  .history-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-copy {
    padding: 8px;
  }
}

@media (max-width: 330px) {
  .history-list {
    grid-template-columns: 1fr;
  }
}
