:root {
  color-scheme: light;
  --ink: #191a1a;
  --muted: #6b706c;
  --line: #d8d9d3;
  --paper: #fbfbf8;
  --panel: #ffffff;
  --teal: #0f766e;
  --teal-dark: #0b4f4a;
  --coral: #c94f37;
  --amber: #b7791f;
  --rose: #9d2f55;
  --green-soft: #e4f4ee;
  --amber-soft: #fff3d7;
  --coral-soft: #fde8df;
  --shadow: 0 16px 36px rgba(25, 26, 26, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(251, 251, 248, 0) 280px),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

button:hover {
  border-color: var(--teal);
}

button:active {
  transform: translateY(1px);
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(22px, 2.5vw, 34px);
  line-height: 1.12;
}

h2 {
  font-size: 17px;
}

h3 {
  font-size: 14px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 720;
  white-space: nowrap;
}

.status-pill.muted {
  border-color: rgba(183, 121, 31, 0.28);
  background: var(--amber-soft);
  color: #805414;
}

.workspace {
  display: grid;
  grid-template-columns: 308px minmax(520px, 1fr) 390px;
  gap: 16px;
  padding: 18px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.template-panel,
.api-panel {
  align-self: start;
  position: sticky;
  top: 96px;
  max-height: calc(100vh - 116px);
  overflow: auto;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.template-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.template-card {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 12px;
  text-align: left;
  border-color: #e4e2dc;
  background: #fff;
}

.template-card strong {
  font-size: 14px;
}

.template-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.template-card.active {
  border-color: rgba(15, 118, 110, 0.55);
  background: linear-gradient(180deg, var(--green-soft), #fff);
}

.template-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-chip {
  padding: 3px 7px;
  border-radius: 999px;
  background: #f3f3ef;
  color: #4a4d49;
  font-size: 11px;
}

.builder-panel {
  padding-bottom: 12px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #2a2d2a;
  font-size: 13px;
  font-weight: 700;
}

label small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 520;
  line-height: 1.35;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.check-row input {
  width: 18px;
  height: 18px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

select,
input {
  height: 40px;
  padding: 0 10px;
}

textarea {
  min-height: 128px;
  padding: 12px;
  resize: vertical;
  line-height: 1.56;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.wide-input {
  padding: 0 14px 14px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 14px 14px;
}

.action-row button,
.api-form button {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 760;
}

.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.primary:hover {
  border-color: var(--teal-dark);
  background: var(--teal-dark);
}

.full {
  width: 100%;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 0 14px 12px;
}

.tab {
  min-height: 36px;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 720;
}

.tab.active {
  border-color: rgba(201, 79, 55, 0.52);
  background: var(--coral-soft);
  color: #87311f;
}

.output-pane {
  display: none;
  padding: 0 14px;
}

.output-pane.active {
  display: block;
}

#scriptOutput,
#promptOutput,
#payloadOutput {
  min-height: 430px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.storyboard-table {
  display: grid;
  gap: 10px;
  min-height: 430px;
}

.shot-card {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid #e4e2dc;
  border-radius: 8px;
  background: #fff;
}

.shot-number {
  display: grid;
  place-items: center;
  min-height: 82px;
  border-radius: 8px;
  background: #19201f;
  color: #fff;
  font-weight: 820;
}

.shot-body {
  display: grid;
  gap: 6px;
  font-size: 13px;
  line-height: 1.48;
}

.shot-body strong {
  color: var(--teal-dark);
}

.api-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f7f3;
}

.segment {
  min-height: 34px;
  border-color: transparent;
  background: transparent;
  font-weight: 760;
}

.segment.active {
  border-color: rgba(15, 118, 110, 0.3);
  background: #fff;
  color: var(--teal-dark);
}

.preview-shell {
  padding: 0 14px 14px;
}

.video-preview {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121514;
}

.preview-frame {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  height: 220px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.36), transparent 42%),
    radial-gradient(circle at 78% 22%, rgba(201, 79, 55, 0.35), transparent 24%),
    #121514;
  color: #fff;
}

.preview-frame span {
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.74);
  font-size: 12px;
}

.preview-frame strong {
  font-size: 18px;
}

.generated-video {
  display: block;
  width: 100%;
  max-height: 420px;
  background: #050606;
}

.preview-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.preview-thumb {
  aspect-ratio: 9 / 12;
  border-radius: 6px;
  background: linear-gradient(160deg, #f6f7f5, #cfe9df);
}

.preview-thumb:nth-child(2n) {
  background: linear-gradient(160deg, #f6f7f5, #f8d9c8);
}

.download-link {
  display: grid;
  place-items: center;
  min-height: 40px;
  margin-top: 10px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 780;
  text-decoration: none;
}

.progress-wrap {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8e8e2;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--coral), var(--amber));
  transition: width 240ms ease;
}

.log-box {
  min-height: 132px;
  margin: 0 14px 14px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101211;
  color: #d7eee6;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.guardrail-box {
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid rgba(157, 47, 85, 0.25);
  border-radius: 8px;
  background: #fff5f8;
}

.guardrail-box h3 {
  margin-bottom: 8px;
  color: #7c2443;
}

.guardrail-box ul {
  display: grid;
  gap: 6px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.guardrail-box li {
  color: #623247;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: 280px 1fr;
  }

  .api-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .template-panel {
    position: static;
    max-height: none;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }
}
