:root {
  --ink: #202033;
  --muted: #6f7188;
  --line: #deddf0;
  --surface: #ffffff;
  --lavender: #a98be8;
  --violet: #8469dc;
  --sky: #92c9ef;
  --pink: #f1a6bb;
  --mint: #a9ddd1;
  --wash: #f8f6ff;
  --shadow: 0 18px 45px rgba(82, 74, 128, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(169, 139, 232, 0.22), transparent 280px),
    radial-gradient(circle at top right, rgba(146, 201, 239, 0.22), transparent 310px),
    linear-gradient(180deg, #fff 0%, var(--wash) 44%, #fff 100%);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

.hero {
  position: relative;
  min-height: 520px;
  padding: 28px clamp(18px, 4vw, 64px) 42px;
  overflow: hidden;
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(169, 139, 232, 0.16);
  pointer-events: none;
}

.hero::before {
  width: 230px;
  height: 230px;
  left: -72px;
  bottom: -92px;
}

.hero::after {
  width: 190px;
  height: 190px;
  right: -54px;
  top: 40px;
}

.topbar,
.hero-grid,
main {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 50px;
}

.brand,
.toolbar,
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.actions {
  position: relative;
}

.brand {
  font-weight: 800;
  font-size: 1.08rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: white;
  background: linear-gradient(135deg, var(--violet), var(--sky));
  box-shadow: 0 10px 22px rgba(132, 105, 220, 0.28);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.88fr) minmax(320px, 1.12fr);
  align-items: center;
  gap: clamp(24px, 4vw, 58px);
  max-width: 1220px;
  margin: 0 auto;
}

.hero-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--violet);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 720px;
  font-size: clamp(2.35rem, 4.5vw, 5rem);
  line-height: 1.02;
}

.lede {
  max-width: 620px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.65;
}

.workflow-preview {
  margin: 0;
  border: 1px solid rgba(222, 221, 240, 0.95);
  border-radius: 8px;
  overflow: hidden;
  background: white;
  box-shadow: var(--shadow);
}

.workflow-preview img {
  display: block;
  width: 100%;
  height: auto;
}

main {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto 48px;
}

.panel {
  margin-bottom: 26px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.section-heading,
.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.section-heading h2,
.stage-title {
  font-size: clamp(1.35rem, 2vw, 2rem);
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(241, 166, 187, 0.55);
  border-radius: 999px;
  padding: 8px 12px;
  color: #9d4665;
  background: rgba(241, 166, 187, 0.13);
  font-size: 0.86rem;
  font-weight: 700;
}

.status-pill.ready {
  color: #33766a;
  border-color: rgba(169, 221, 209, 0.8);
  background: rgba(169, 221, 209, 0.22);
}

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

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

.model-combobox {
  position: relative;
  display: grid;
}

.model-combobox input {
  padding-right: 44px;
}

.model-menu-toggle {
  position: absolute;
  top: 1px;
  right: 1px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-left: 1px solid transparent;
  border-radius: 0 8px 8px 0;
  color: var(--ink);
  background: transparent;
  font-size: 0.95rem;
  font-weight: 900;
}

.model-menu-toggle:hover,
.model-menu-toggle[aria-expanded="true"] {
  background: rgba(132, 105, 220, 0.08);
}

.model-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 8;
  display: grid;
  gap: 5px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 16px 34px rgba(82, 74, 128, 0.18);
}

.model-menu[hidden] {
  display: none;
}

.model-menu-option {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: transparent;
  font-size: 0.86rem;
  font-weight: 800;
  text-align: left;
}

.model-menu-option:hover,
.model-menu-option:focus-visible {
  background: rgba(132, 105, 220, 0.12);
  outline: none;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

textarea:disabled {
  color: var(--muted);
  background: #f3f2fa;
  cursor: not-allowed;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 4px rgba(132, 105, 220, 0.12);
}

.notice {
  margin: 18px 0 0;
  padding: 12px 14px;
  border: 1px solid rgba(146, 201, 239, 0.55);
  border-radius: 8px;
  color: #405777;
  background: rgba(146, 201, 239, 0.12);
  line-height: 1.55;
}

.notice-prefix {
  color: #c93655;
}

.first-visit-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(32, 32, 51, 0.28);
  backdrop-filter: blur(5px);
}

.first-visit-modal[hidden] {
  display: none;
}

.first-visit-dialog {
  width: min(460px, 100%);
  border: 1px solid rgba(146, 201, 239, 0.62);
  border-radius: 8px;
  padding: 22px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 60px rgba(82, 74, 128, 0.24);
}

.first-visit-dialog h2 {
  margin: 0 0 10px;
  font-size: 1.18rem;
}

.first-visit-dialog p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.55;
}

.stage-head {
  justify-content: flex-start;
}

.stage-number {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  color: white;
  background: linear-gradient(135deg, var(--violet), var(--pink));
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(132, 105, 220, 0.22);
}

.stage-layout {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(280px, 0.76fr);
  gap: 22px;
}

.stage-control {
  display: grid;
  gap: 14px;
  align-content: start;
}

.stage-results {
  min-height: 160px;
  border: 1px solid rgba(222, 221, 240, 0.72);
  border-radius: 8px;
  padding: 12px;
  background: rgba(248, 246, 255, 0.58);
}

.stage-results-title {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 900;
  letter-spacing: 0;
}

.results-loading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 128px;
  margin-bottom: 12px;
  border: 1px dashed rgba(132, 105, 220, 0.3);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  font-size: 0.9rem;
  font-weight: 800;
}

.results-loading > .cancel-info-panel {
  flex: 1 0 100%;
}

.results-loading[hidden] {
  display: none;
}

.cancel-generation-button {
  min-height: 34px;
  border: 1px solid rgba(241, 166, 187, 0.58);
  border-radius: 8px;
  padding: 0 12px;
  color: #9d4665;
  background: rgba(255, 255, 255, 0.84);
  font-size: 0.82rem;
  font-weight: 900;
}

.cancel-generation-button:hover,
.cancel-generation-button:focus-visible {
  background: rgba(241, 166, 187, 0.14);
  outline: none;
}

.cancel-info-panel {
  border: 1px solid rgba(146, 201, 239, 0.6);
  border-radius: 8px;
  padding: 9px 11px;
  color: #405777;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 10px 20px rgba(82, 74, 128, 0.1);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.45;
  text-align: left;
}

.carry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.reference-guidance {
  display: grid;
  gap: 10px;
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
}

.reference-slot {
  min-height: 112px;
  border: 1px dashed rgba(132, 105, 220, 0.42);
  border-radius: 8px;
  padding: 10px;
  background: rgba(248, 246, 255, 0.78);
}

.upload-slot {
  display: grid;
  gap: 9px;
  align-content: start;
}

.upload-slot-wide {
  min-height: 96px;
}

.upload-slot.disabled {
  opacity: 0.55;
}

.upload-slot.drag-over {
  border-color: var(--violet);
  background: rgba(169, 139, 232, 0.16);
  box-shadow: inset 0 0 0 2px rgba(132, 105, 220, 0.12);
}

.upload-slot.disabled .upload-button {
  pointer-events: none;
  color: var(--muted);
  background: #eceaf6;
  border-color: var(--line);
  box-shadow: none;
  cursor: not-allowed;
}

.upload-slot.disabled .delete-upload-button {
  pointer-events: none;
  opacity: 0.65;
  cursor: not-allowed;
}

.previous-carry-note {
  display: none;
  margin: 0;
  color: #6f5dac;
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.35;
}

.upload-slot.disabled .previous-carry-note {
  display: block;
}

.reference-slot strong {
  display: block;
  color: var(--ink);
  font-size: 0.83rem;
}

.reference-slot span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.35;
}

.slot-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.slot-actions {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.upload-button {
  display: inline-grid;
  place-items: center;
  width: fit-content;
  min-height: 36px;
  border: 1px solid rgba(132, 105, 220, 0.36);
  border-radius: 8px;
  padding: 0 14px;
  color: white;
  background: linear-gradient(135deg, var(--violet), var(--sky));
  box-shadow: 0 8px 16px rgba(132, 105, 220, 0.18);
  font-size: 0.84rem;
  font-weight: 900;
  user-select: none;
  cursor: pointer;
}

.delete-upload-button {
  display: inline-grid;
  place-items: center;
  min-height: 36px;
  border: 1px solid rgba(241, 166, 187, 0.58);
  border-radius: 8px;
  padding: 0 12px;
  color: #9d4665;
  background: rgba(241, 166, 187, 0.12);
  font-size: 0.84rem;
  font-weight: 900;
  cursor: pointer;
}

.delete-upload-button.is-hidden {
  display: none;
}

.upload-help-tip,
.run-help-tip {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 4;
  width: max-content;
  max-width: min(280px, calc(100vw - 56px));
  border: 1px solid rgba(146, 201, 239, 0.55);
  border-radius: 8px;
  padding: 9px 11px;
  color: #405777;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 28px rgba(82, 74, 128, 0.16);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition: opacity 0.08s ease, transform 0.08s ease;
}

.upload-help-tip::before,
.run-help-tip::before {
  content: "";
  position: absolute;
  left: 16px;
  top: -6px;
  width: 10px;
  height: 10px;
  border-left: 1px solid rgba(146, 201, 239, 0.55);
  border-top: 1px solid rgba(146, 201, 239, 0.55);
  background: rgba(255, 255, 255, 0.96);
  transform: rotate(45deg);
}

.upload-button:hover ~ .upload-help-tip,
.upload-button:focus-visible ~ .upload-help-tip,
.run-stage:hover ~ .run-help-tip,
.run-stage:focus-visible ~ .run-help-tip {
  opacity: 1;
  transform: translateY(0);
}

.slot-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 7px;
}

.reference-warning {
  margin: 0;
  border: 1px solid rgba(241, 166, 187, 0.55);
  border-radius: 8px;
  padding: 9px 10px;
  color: #9d4665;
  background: rgba(241, 166, 187, 0.12);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.4;
}

.reference-warning.ok {
  color: #33766a;
  border-color: rgba(169, 221, 209, 0.8);
  background: rgba(169, 221, 209, 0.18);
}

.upload-thumb {
  position: relative;
  display: grid;
  grid-template-rows: 64px auto;
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.upload-thumb img {
  display: block;
  width: 100%;
  height: 64px;
  object-fit: contain;
  background: #fff;
}

.upload-thumb span {
  display: block;
  overflow: hidden;
  padding: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-upload-button {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(32, 32, 51, 0.16);
  border-radius: 999px;
  padding: 0;
  color: white;
  background: rgba(32, 32, 51, 0.72);
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.upload-thumb:hover .remove-upload-button,
.remove-upload-button:focus-visible {
  opacity: 1;
  transform: scale(1);
}

.carry-row input {
  width: 18px;
  height: 18px;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--violet), var(--sky));
  box-shadow: 0 10px 18px rgba(132, 105, 220, 0.18);
}

.ghost-button,
.icon-button {
  color: var(--ink);
  background: white;
  border-color: var(--line);
}

.primary-button:disabled,
.ghost-button:disabled {
  opacity: 0.58;
  cursor: wait;
}

.stage-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.loading-spinner {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(132, 105, 220, 0.24);
  border-top-color: var(--violet);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

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

.result-grid {
  display: grid;
  gap: 12px;
}

.single-result-grid {
  grid-template-columns: minmax(0, 1fr);
}

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

.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-card.selected {
  border-color: var(--violet);
  box-shadow: 0 0 0 4px rgba(132, 105, 220, 0.13);
}

.result-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background:
    linear-gradient(45deg, #f4f4fa 25%, transparent 25%),
    linear-gradient(-45deg, #f4f4fa 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f4f4fa 75%),
    linear-gradient(-45deg, transparent 75%, #f4f4fa 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
}

.result-actions a,
.result-actions button {
  display: grid;
  place-items: center;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.result-actions button.active {
  color: white;
  border-color: var(--violet);
  background: var(--violet);
}

.helper-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.helper-fields {
  display: grid;
  gap: 14px;
}

.output-prompt {
  margin-top: 14px;
  background: #fcfbff;
}

@media (max-width: 900px) {
  .hero {
    min-height: auto;
  }

  .hero-grid,
  .stage-layout {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .helper-grid {
    grid-template-columns: 1fr 1fr;
  }
}

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

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

  .form-grid,
  .helper-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }
}
