:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-strong: #eef1f4;
  --ink: #15181d;
  --muted: #657080;
  --line: #d8dde4;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --gold: #b9812c;
  --danger: #a44343;
  --shadow: 0 18px 42px rgba(21, 24, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px 10px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h2,
.music-strip p,
.script-output p {
  margin: 0;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.15;
}

.brand p,
.topbar p,
.music-strip span,
.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px;
}

.panel h2 {
  font-size: 15px;
}

.dropzone {
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 132px;
  margin: 0 14px 14px;
  border: 1px dashed #aab4c0;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  text-align: center;
  cursor: pointer;
}

.dropzone input {
  display: none;
}

.drop-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 25px;
  line-height: 1;
}

.dropzone small {
  color: var(--muted);
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 210px;
  overflow: auto;
  padding: 0 14px 14px;
}

.asset-card {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #dfe5eb;
}

.asset-card img,
.asset-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.asset-card span {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.62);
  color: white;
  font-size: 11px;
}

.segmented,
.copy-options,
.ai-config {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.segmented {
  grid-template-columns: repeat(3, 1fr);
}

.copy-options {
  grid-template-columns: 1fr;
}

.ai-config label {
  display: grid;
  gap: 6px;
}

.ai-config label span,
.ai-config small {
  color: var(--muted);
  font-size: 12px;
}

.ai-config input,
.ai-config select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  padding: 0 10px;
}

.segmented button,
.copy-options button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  color: var(--ink);
}

.segmented button.active,
.copy-options button.active {
  border-color: var(--accent);
  background: #e2f3f0;
  color: var(--accent-strong);
  font-weight: 700;
}

.primary-action,
.ghost-action,
.chat-form button {
  min-height: 44px;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.primary-action {
  margin-top: auto;
}

.primary-action:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.stage {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar h2 {
  margin-top: 2px;
  font-size: 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
}

.ghost-action {
  min-width: 96px;
  background: var(--ink);
}

.ghost-action:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.92fr) minmax(360px, 1.08fr) 330px;
  gap: 18px;
  min-height: 0;
  padding: 20px;
}

.preview-column,
.script-column,
.chat-panel {
  min-width: 0;
}

.preview-frame {
  position: relative;
  display: grid;
  width: min(100%, 440px);
  max-height: calc(100vh - 170px);
  margin: 0 auto;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #11161c;
  box-shadow: var(--shadow);
}

.ratio-vertical {
  aspect-ratio: 9 / 16;
}

.ratio-wide {
  aspect-ratio: 16 / 9;
  width: 100%;
}

.ratio-square {
  aspect-ratio: 1;
  width: min(100%, 560px);
}

.preview-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: white;
}

.preview-empty span {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  font-weight: 800;
}

.preview-empty.loading span {
  border-radius: 50%;
  border-color: rgba(255, 255, 255, 0.24);
  border-top-color: white;
  color: transparent;
  animation: spin 0.85s linear infinite;
}

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

#previewImage,
#previewVideo,
#renderedVideo {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.subtitle-layer {
  position: absolute;
  right: 18px;
  bottom: 22px;
  left: 18px;
  color: white;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.72);
}

.subtitle-layer p {
  display: inline-flex;
  margin: 0 0 8px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.42);
  font-size: 13px;
}

.subtitle-layer h3 {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
  letter-spacing: 0;
}

.music-strip {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.music-strip strong {
  display: block;
  margin-top: 3px;
}

.music-strip p {
  color: var(--muted);
  line-height: 1.55;
}

.rendered-video {
  display: none;
  width: 100%;
  height: 100%;
  background: #11161c;
}

.script-column {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.script-panel,
.timeline-panel,
.chat-panel {
  overflow: hidden;
}

.script-output {
  padding: 0 14px 16px;
  color: var(--muted);
  line-height: 1.7;
}

.script-output strong {
  color: var(--ink);
}

.timeline-panel {
  min-height: 320px;
}

.timeline-empty,
.timeline-list {
  padding: 0 14px 14px;
}

.timeline-empty {
  color: var(--muted);
}

.timeline-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 450px);
  overflow: auto;
}

.shot {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
}

.shot.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px #d7efeb;
}

.shot-index {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 6px;
  background: var(--ink);
  color: white;
  font-weight: 800;
}

.shot h3,
.shot p {
  margin: 0;
}

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

.shot p {
  display: -webkit-box;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.shot time {
  color: var(--muted);
  font-size: 13px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 118px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 0 14px 14px;
}

.ai-message,
.user-message {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.55;
  font-size: 14px;
}

.ai-message {
  align-self: flex-start;
  background: var(--surface-strong);
}

.user-message {
  align-self: flex-end;
  background: #e2f3f0;
  color: var(--accent-strong);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
}

.chat-form button {
  min-height: 42px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .chat-panel {
    min-height: 420px;
  }
}

@media (max-width: 720px) {
  .topbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .workspace,
  .sidebar {
    padding: 14px;
  }
}
