:root {
  --bg: #f3f6f4;
  --panel: #ffffff;
  --ink: #172126;
  --muted: #68747a;
  --line: #dbe4e0;
  --soft: #eef4f1;
  --teal: #0f766e;
  --teal-2: #14b8a6;
  --blue: #2563eb;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 50px rgba(23, 33, 38, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 72px;
  padding: 12px 20px;
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(300px, 1.1fr) auto;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--teal), #1e8b64);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
  white-space: nowrap;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.tool-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 8px;
}

.tab,
.ghost-button,
.primary-button,
.text-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.tab {
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  white-space: nowrap;
}

.tab.is-active {
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(23, 33, 38, 0.08);
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ghost-button,
.text-button {
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  padding: 0 14px;
}

.ghost-button:hover,
.text-button:hover,
.icon-button:hover {
  border-color: #adc2bb;
  transform: translateY(-1px);
}

.primary-button {
  color: white;
  background: var(--teal);
  padding: 0 18px;
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.18);
}

.primary-button:hover {
  background: #0a625b;
  transform: translateY(-1px);
}

.compact {
  min-height: 34px;
  padding: 0 12px;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.tab svg,
.ghost-button svg,
.primary-button svg,
.icon-button svg,
.qa-list svg,
.pipeline svg {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 310px minmax(420px, 1fr) 330px;
  gap: 16px;
  padding: 16px;
}

.panel,
.stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  min-height: calc(100vh - 104px);
  padding: 18px;
  overflow: hidden;
}

.panel-heading,
.stage-header,
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 12px;
  font-size: 15px;
}

.pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--teal);
  background: #e6f5f2;
  font-size: 12px;
  font-weight: 700;
}

.rights-check {
  margin: 16px 0;
  padding: 12px;
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: flex-start;
  gap: 10px;
  color: #405056;
  background: #fff8eb;
  border: 1px solid #f5d49a;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.rights-check input,
.setting-row input,
.toggle input {
  accent-color: var(--teal);
}

.dropzone {
  min-height: 160px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  background:
    linear-gradient(0deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.7)),
    repeating-linear-gradient(135deg, #e5efeb 0 10px, #f6faf8 10px 20px);
  border: 1.5px dashed #9ab4ad;
  border-radius: 8px;
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.dropzone.is-dragover {
  background: #e7f6f2;
  border-color: var(--teal);
}

.dropzone input {
  display: none;
}

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

.dropzone small {
  font-size: 12px;
}

.drop-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--teal);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.queue-toolbar {
  margin: 14px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-button {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}

.queue-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 420px);
  min-height: 160px;
  overflow: auto;
  padding-right: 2px;
}

.queue-empty {
  min-height: 130px;
  display: grid;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: #f7faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.queue-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 24px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.queue-item.is-active {
  border-color: var(--teal);
  box-shadow: inset 3px 0 0 var(--teal);
}

.thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background:
    linear-gradient(140deg, rgba(15, 118, 110, 0.9), rgba(37, 99, 235, 0.84)),
    linear-gradient(45deg, #dbeafe, #ecfdf5);
  position: relative;
  overflow: hidden;
}

.thumb::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
}

.queue-meta {
  min-width: 0;
}

.queue-meta strong,
.queue-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-meta strong {
  font-size: 13px;
}

.queue-meta span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.output-link {
  color: var(--teal);
  font-weight: 800;
  text-decoration: none;
}

.output-link:hover {
  text-decoration: underline;
}

.queue-actions {
  display: grid;
  justify-items: end;
  gap: 9px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
}

.status-dot.ready {
  background: var(--blue);
}

.status-dot.queued,
.status-dot.uploading {
  background: #64748b;
}

.status-dot.interrupted {
  background: var(--red);
}

.status-dot.running {
  background: var(--amber);
}

.status-dot.done {
  background: var(--teal);
}

.stage {
  min-height: calc(100vh - 104px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.stage-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.preview-frame {
  flex: 1;
  min-height: 390px;
  max-height: calc(100vh - 360px);
  aspect-ratio: 16 / 9;
  width: 100%;
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #0f1719;
  isolation: isolate;
}

#videoPreview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  background: #0f1719;
}

.demo-frame {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 45% 35%, rgba(255, 255, 255, 0.18), transparent 0 20%, transparent 21%),
    linear-gradient(160deg, #71927e 0%, #d8c7a0 36%, #6c8793 68%, #1b3037 100%);
}

.demo-frame::before {
  content: "";
  position: absolute;
  inset: 12% 5% 13%;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08), transparent 30%),
    linear-gradient(180deg, transparent 0 62%, rgba(0, 0, 0, 0.22) 63% 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.demo-person {
  position: absolute;
  left: 42%;
  top: 19%;
  width: 17%;
  height: 56%;
  border-radius: 48% 48% 8px 8px;
  background:
    radial-gradient(circle at 50% 18%, #f5c8a8 0 17%, transparent 18%),
    linear-gradient(180deg, transparent 0 32%, #174b52 33% 100%);
  filter: saturate(0.95);
}

.demo-watermark,
.demo-subtitle {
  position: absolute;
  z-index: 3;
  color: white;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.52);
  user-select: none;
}

.demo-watermark.moving {
  right: 7%;
  top: 18%;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  font-size: 13px;
  animation: drift 5s ease-in-out infinite;
}

.demo-watermark.ghost {
  left: 8%;
  top: 45%;
  opacity: 0.22;
  transform: rotate(-10deg);
  font-size: clamp(18px, 3vw, 36px);
  font-weight: 800;
}

.demo-subtitle {
  left: 50%;
  bottom: 13%;
  transform: translateX(-50%);
  width: min(640px, 76%);
  padding: 8px 14px;
  text-align: center;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  font-size: clamp(13px, 1.7vw, 19px);
  font-weight: 800;
}

.demo-timeline {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 6%;
  height: 4px;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

.demo-timeline::after {
  content: "";
  display: block;
  width: 42%;
  height: 100%;
  background: var(--teal-2);
  border-radius: inherit;
}

@keyframes drift {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(-36px, 24px, 0);
  }
}

.after-layer {
  position: absolute;
  inset: 0;
  width: 52%;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0)),
    linear-gradient(160deg, rgba(80, 126, 119, 0.22), rgba(8, 35, 39, 0.08));
  backdrop-filter: saturate(1.22) contrast(1.08) brightness(1.04);
}

.after-layer::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(transparent 0 76%, rgba(0, 0, 0, 0.16) 77% 100%),
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.16), transparent 0 24%, transparent 25%);
}

.after-layer::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9%;
  height: 19%;
  background: linear-gradient(180deg, transparent, rgba(20, 184, 166, 0.08));
}

.clean-badge {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 5;
  padding: 7px 10px;
  border-radius: 8px;
  color: white;
  background: rgba(15, 118, 110, 0.88);
  font-size: 12px;
  font-weight: 800;
}

.mask-layer {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

.mask-layer.is-hidden {
  display: none;
}

.mask-box {
  position: absolute;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  color: #08333a;
  background: rgba(20, 184, 166, 0.18);
  border: 1px solid rgba(20, 184, 166, 0.76);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.subtitle-mask {
  left: 18%;
  right: 18%;
  bottom: 11%;
  justify-content: center;
  min-height: 54px;
}

.watermark-mask {
  right: 7%;
  top: 17%;
  min-width: 150px;
  min-height: 40px;
  justify-content: center;
}

.faint-mask {
  left: 7%;
  top: 42%;
  min-width: 230px;
  min-height: 68px;
  justify-content: center;
  transform: rotate(-10deg);
  border-color: rgba(217, 119, 6, 0.82);
  background: rgba(217, 119, 6, 0.16);
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 52%;
  z-index: 8;
  width: 2px;
  background: rgba(255, 255, 255, 0.95);
  pointer-events: none;
}

.compare-handle span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 38px;
  height: 38px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.26);
}

.compare-handle span::before,
.compare-handle span::after {
  content: "";
  position: absolute;
  top: 13px;
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--teal);
  border-left: 2px solid var(--teal);
}

.compare-handle span::before {
  left: 10px;
  transform: rotate(-45deg);
}

.compare-handle span::after {
  right: 10px;
  transform: rotate(135deg);
}

.compare-slider {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.compare-slider input {
  width: 100%;
  accent-color: var(--teal);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-strip div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.metric-strip strong,
.metric-strip span {
  display: block;
}

.metric-strip strong {
  font-size: 20px;
}

.metric-strip span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.step {
  min-height: 70px;
  padding: 12px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  background: #f8fbfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}

.step.is-current {
  color: var(--amber);
  border-color: rgba(217, 119, 6, 0.45);
  background: #fff8eb;
}

.step.is-done {
  color: var(--teal);
  border-color: rgba(15, 118, 110, 0.3);
  background: #eaf7f4;
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
}

.settings-section {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.settings-section.is-muted {
  opacity: 0.74;
}

.setting-row,
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  color: #33444a;
  font-size: 14px;
}

.field {
  align-items: stretch;
  flex-direction: column;
  margin-top: 12px;
}

.field input,
.field select {
  width: 100%;
}

select {
  height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

input[type="range"] {
  accent-color: var(--teal);
}

.qa-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.qa-list div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #3b4a50;
  font-size: 13px;
}

.qa-list svg {
  color: var(--teal);
}

.spec-dialog {
  width: min(920px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 28px 90px rgba(23, 33, 38, 0.24);
}

.spec-dialog::backdrop {
  background: rgba(14, 23, 25, 0.46);
  backdrop-filter: blur(3px);
}

.spec-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.spec-grid article {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.spec-grid p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.api-snippet {
  margin: 14px 0 0;
  padding: 14px;
  overflow: auto;
  color: #d8f7ef;
  background: #132224;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.image-lab {
  grid-column: 1 / -1;
  min-height: auto;
}

.image-lab-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 160px;
  gap: 14px;
  align-items: stretch;
}

.image-dropzone {
  min-height: 190px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  background:
    linear-gradient(0deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.7)),
    repeating-linear-gradient(135deg, #e5efeb 0 10px, #f6faf8 10px 20px);
  border: 1.5px dashed #9ab4ad;
  border-radius: 8px;
}

.image-dropzone.is-dragover {
  background: #e7f6f2;
  border-color: var(--teal);
}

.image-dropzone input {
  display: none;
}

.image-dropzone strong {
  color: var(--ink);
}

.image-dropzone small {
  font-size: 12px;
}

.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.image-preview-grid figure {
  margin: 0;
  min-height: 190px;
  display: grid;
  grid-template-rows: 28px minmax(0, 1fr);
  overflow: hidden;
  background: #0f1719;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.image-preview-grid figure span {
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: #d9f5ef;
  background: rgba(15, 23, 25, 0.9);
  font-size: 12px;
  font-weight: 800;
}

.image-preview-grid img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  background:
    linear-gradient(45deg, #11191b 25%, transparent 25%),
    linear-gradient(-45deg, #11191b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #11191b 75%),
    linear-gradient(-45deg, transparent 75%, #11191b 75%);
  background-color: #172126;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

.image-preview-grid img:not([src]) {
  display: none;
}

.image-actions {
  display: grid;
  align-content: center;
  gap: 10px;
}

.ghost-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.ghost-link.is-disabled {
  pointer-events: none;
  color: var(--muted);
  background: #f4f7f5;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 50;
  max-width: min(460px, calc(100vw - 32px));
  padding: 12px 14px;
  transform: translate(-50%, 120%);
  color: white;
  background: #172126;
  border-radius: 8px;
  opacity: 0;
  transition:
    transform 180ms ease,
    opacity 180ms ease;
  box-shadow: 0 16px 44px rgba(23, 33, 38, 0.22);
}

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

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

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .workspace {
    grid-template-columns: 280px minmax(420px, 1fr);
  }

  .settings-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }

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

  .settings-panel > .panel-heading {
    grid-column: 1 / -1;
  }

  .image-lab-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .panel,
  .stage {
    min-height: auto;
  }

  .tool-tabs,
  .metric-strip,
  .pipeline,
  .image-preview-grid,
  .spec-grid,
  .settings-panel {
    grid-template-columns: 1fr;
  }

  .stage-header,
  .stage-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-frame {
    min-height: 260px;
    max-height: none;
  }

  .brand span {
    white-space: normal;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 10px;
  }

  .brand {
    align-items: flex-start;
  }

  .top-actions {
    flex-direction: column;
  }

  .panel,
  .stage {
    padding: 14px;
  }

  h1,
  h2 {
    font-size: 18px;
  }

  .compare-slider {
    grid-template-columns: 1fr;
  }

  .subtitle-mask {
    left: 8%;
    right: 8%;
  }

  .faint-mask {
    min-width: 160px;
  }
}
