:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #191d20;
  --panel-2: #20262a;
  --line: #30373d;
  --text: #f5f0e8;
  --muted: #a9b0b5;
  --soft: #717b84;
  --mint: #52f0b8;
  --mint-2: #b5f26b;
  --amber: #ffc36f;
  --coral: #ff705c;
  --blue: #62b8ff;
  --ink: #090a0b;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #121619;
}

.brand,
.topbar-actions,
.stage-toolbar,
.stage-tools,
.section-head,
.slot-title,
.stepper-row,
.api-block summary,
.advanced-block summary {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(82, 240, 184, 0.7);
  border-radius: 8px;
  color: var(--mint);
  background: #0f1d19;
  font-size: 13px;
  font-weight: 800;
}

.brand h1,
.brand p,
.stage-toolbar h2,
.stage-toolbar p,
.section-head h2 {
  margin: 0;
}

.brand h1 {
  font-size: 16px;
  line-height: 1.2;
}

.brand p,
.stage-toolbar p,
.section-head span,
.control-label,
.field-block span,
.field-row span,
.slot-empty {
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(255, 195, 111, 0.12);
}

.workspace {
  display: grid;
  grid-template-columns: 52px minmax(240px, 330px) minmax(360px, 1fr) minmax(260px, 320px);
  min-height: 0;
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 8px;
  border-right: 1px solid var(--line);
  background: #14181b;
}

.rail-button,
.icon-button,
.stepper button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel);
  cursor: pointer;
}

.rail-button.active {
  color: var(--ink);
  background: var(--mint);
  border-color: var(--mint);
}

.icon-button:hover,
.rail-button:hover,
.stepper button:hover {
  color: var(--text);
  border-color: #59626a;
}

.icon-button svg,
.rail-button svg,
.primary-button svg,
.secondary-button svg,
.slot-title svg,
.stepper button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.input-panel,
.control-panel {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: var(--panel);
}

.input-panel {
  border-right: 1px solid var(--line);
}

.control-panel {
  border-left: 1px solid var(--line);
}

.section-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2,
.stage-toolbar h2 {
  font-size: 15px;
}

.section-head span,
#costBadge {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #15191c;
}

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

.upload-slot {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 210px;
  overflow: hidden;
  border: 1px dashed #4b555e;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(82, 240, 184, 0.09), transparent 45%),
    linear-gradient(315deg, rgba(255, 195, 111, 0.09), transparent 42%),
    #151a1d;
  cursor: pointer;
}

.upload-slot.dragging {
  border-color: var(--mint);
  background-color: #10231d;
}

.upload-slot input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.slot-title {
  z-index: 1;
  gap: 7px;
  padding: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.slot-empty {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-slot img,
.upload-slot video {
  position: absolute;
  inset: 40px 8px 8px;
  width: calc(100% - 16px);
  height: calc(100% - 48px);
  object-fit: cover;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 160ms ease;
}

.upload-slot.has-image img,
.upload-slot.has-image video {
  opacity: 1;
}

.upload-slot.has-image .slot-empty {
  color: rgba(245, 240, 232, 0.76);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.75);
}

.field-block {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field-block input,
.field-block textarea,
.field-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #111518;
  outline: none;
}

.field-block input,
.field-row input {
  height: 38px;
  padding: 0 11px;
}

.field-block textarea {
  resize: vertical;
  min-height: 102px;
  padding: 10px 11px;
  line-height: 1.45;
}

.field-block input:focus,
.field-block textarea:focus,
.field-row input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(82, 240, 184, 0.1);
}

.field-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) minmax(120px, 1.4fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.advanced-block,
.api-block {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.advanced-block summary,
.api-block summary {
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
  margin-bottom: 12px;
}

.advanced-block summary::-webkit-details-marker,
.api-block summary::-webkit-details-marker {
  display: none;
}

.advanced-block summary svg,
.api-block summary svg {
  width: 16px;
  height: 16px;
  color: var(--soft);
  transition: transform 160ms ease;
}

.advanced-block[open] summary svg,
.api-block[open] summary svg {
  transform: rotate(180deg);
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 88px;
  min-width: 0;
  min-height: 0;
  padding: 18px 18px 14px;
  background:
    linear-gradient(90deg, rgba(255, 112, 92, 0.06), transparent 28%),
    linear-gradient(270deg, rgba(98, 184, 255, 0.07), transparent 30%),
    #101214;
}

.stage-toolbar {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.stage-tools {
  gap: 8px;
}

.result-frame {
  position: relative;
  place-self: center;
  display: grid;
  place-items: center;
  width: min(100%, 760px);
  max-height: 100%;
  overflow: hidden;
  border: 1px solid #3a4249;
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    #15191c;
  background-size: 22px 22px;
  box-shadow: var(--shadow);
}

.result-frame.ratio-1-1 {
  aspect-ratio: 1 / 1;
}

.result-frame.ratio-3-4 {
  aspect-ratio: 3 / 4;
}

.result-frame.ratio-9-16 {
  aspect-ratio: 9 / 16;
}

#resultCanvas {
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 180ms ease;
}

#resultVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  object-fit: contain;
  background: #090a0b;
}

.has-result #resultCanvas {
  opacity: 1;
}

.has-video #resultCanvas {
  opacity: 0;
}

.has-video #resultVideo {
  display: block;
}

.empty-result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--soft);
  font-size: 13px;
}

.empty-result svg {
  width: 36px;
  height: 36px;
}

.has-result .empty-result {
  display: none;
}

.progress-layer {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(9, 10, 11, 0.72);
  backdrop-filter: blur(8px);
}

.is-running .progress-layer {
  display: grid;
}

.progress-ring {
  position: relative;
  width: 126px;
  height: 126px;
}

.progress-ring svg {
  width: 126px;
  height: 126px;
  transform: rotate(-90deg);
}

.progress-ring circle {
  fill: none;
  stroke-width: 9;
}

.progress-ring circle:first-child {
  stroke: rgba(255, 255, 255, 0.12);
}

#progressCircle {
  stroke: var(--mint);
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
}

.progress-ring strong {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.thumb-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow-x: auto;
  padding-top: 14px;
}

.thumb-strip button {
  flex: 0 0 58px;
  height: 74px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 0;
  cursor: pointer;
}

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

.mode-tabs,
.segmented {
  display: grid;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111518;
}

.mode-tabs {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 16px;
}

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

.segmented.wrap {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tab,
.segmented button {
  min-height: 34px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.tab.active,
.segmented button.active {
  color: var(--ink);
  background: var(--amber);
  font-weight: 800;
}

.control-group {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.slider-block {
  display: grid;
  gap: 8px;
  margin-bottom: 17px;
}

.slider-block span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.slider-block strong {
  color: var(--text);
  font-size: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--mint);
}

.stepper-row {
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 13px;
}

.stepper {
  display: grid;
  grid-template-columns: 34px 42px 34px;
  align-items: center;
  gap: 6px;
}

.stepper button {
  width: 34px;
  height: 34px;
}

.stepper strong {
  text-align: center;
  font-size: 14px;
}

.api-block {
  margin: 16px 0;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  color: var(--ink);
  background: linear-gradient(90deg, var(--mint), var(--mint-2));
}

.primary-button:hover {
  filter: brightness(1.04);
}

.primary-button.compact {
  min-height: 36px;
  padding: 0 14px;
}

.secondary-button {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.run-button {
  width: 100%;
}

.hidden {
  display: none;
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: auto;
  }

  .workspace {
    grid-template-columns: 52px minmax(280px, 0.9fr) minmax(360px, 1.1fr);
    grid-template-rows: minmax(620px, calc(100vh - 64px)) auto;
  }

  .control-panel {
    grid-column: 2 / 4;
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 14px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .control-panel .section-head,
  .control-panel .run-button,
  .api-block {
    grid-column: 1 / -1;
  }
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell {
    grid-template-rows: auto 1fr;
  }

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

  .rail {
    display: none;
  }

  .input-panel,
  .control-panel {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage {
    min-height: 620px;
  }

  .control-panel {
    grid-column: auto;
    grid-template-columns: 1fr;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }
}
