:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #65605a;
  --line: #ddd7cf;
  --paper: #f7f4ef;
  --panel: #ffffff;
  --accent: #1f6f68;
  --accent-strong: #0d4f49;
  --rose: #a43f52;
  --gold: #b48942;
  --shadow: 0 18px 60px rgba(32, 28, 23, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(18px, 4vw, 54px);
  background: rgba(247, 244, 239, 0.88);
  border-bottom: 1px solid rgba(221, 215, 207, 0.75);
  backdrop-filter: blur(18px);
}

.brand,
.nav,
.hero-actions,
.field-row,
.preview-toolbar,
.result-meta,
.hero-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  font-size: 13px;
  letter-spacing: 0;
}

.nav {
  gap: 24px;
  color: var(--muted);
  font-size: 14px;
}

.nav a:hover {
  color: var(--ink);
}

.ghost-button,
.secondary-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.ghost-button,
.primary-button,
.secondary-button,
.submit-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 18px;
  cursor: pointer;
}

.hero {
  position: relative;
  min-height: min(760px, calc(100vh - 72px));
  display: grid;
  align-items: end;
  overflow: hidden;
}

.hero-media,
.hero-media img,
.hero-scrim {
  position: absolute;
  inset: 0;
}

.hero-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 28%;
}

.hero-scrim {
  background:
    linear-gradient(90deg, rgba(13, 18, 17, 0.78) 0%, rgba(13, 18, 17, 0.38) 52%, rgba(13, 18, 17, 0.12) 100%),
    linear-gradient(0deg, rgba(13, 18, 17, 0.55), transparent 48%);
}

.hero-content {
  position: relative;
  width: min(760px, calc(100% - 36px));
  margin: 0 0 clamp(46px, 9vh, 96px) clamp(18px, 6vw, 76px);
  color: #fff;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(42px, 6vw, 78px);
  line-height: 1.02;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 620px;
  margin: 22px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: clamp(16px, 1.8vw, 20px);
  line-height: 1.7;
}

.hero-actions {
  gap: 12px;
  margin-top: 30px;
  flex-wrap: wrap;
}

.primary-button,
.submit-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  color: #fff;
  background: var(--accent);
  font-weight: 750;
}

.primary-button:hover,
.submit-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.35);
}

.studio,
.replace,
.workflow,
.api {
  padding: clamp(54px, 8vw, 92px) clamp(18px, 5vw, 64px);
}

.section-heading {
  width: min(1120px, 100%);
  margin: 0 auto 22px;
}

.section-heading h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 46px);
  letter-spacing: 0;
}

.workspace {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  gap: 18px;
  align-items: start;
}

.replace {
  background: #fff;
}

.replace-workspace {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 0.78fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.preview-panel,
.replace-panel,
.replace-preview,
.api-layout {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel,
.replace-panel {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.result-meta span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 146px;
  resize: vertical;
  padding: 12px;
  line-height: 1.65;
}

select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 104, 0.14);
}

.field-row {
  gap: 12px;
}

.field-row .field {
  flex: 1;
}

.checks {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.checks legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.checks label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: #363330;
  font-size: 14px;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.template-card,
.export-button,
.variant-thumb,
.history-item,
.upload-card,
.mini-heading button {
  cursor: pointer;
  font: inherit;
}

.template-card {
  display: grid;
  gap: 4px;
  min-height: 68px;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fbfaf7;
}

.template-card span {
  font-weight: 800;
}

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

.template-card.is-active {
  border-color: var(--accent);
  background: rgba(31, 111, 104, 0.1);
}

.score-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid rgba(31, 111, 104, 0.22);
  border-radius: 8px;
  background: rgba(31, 111, 104, 0.08);
}

.score-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.score-card strong {
  color: var(--accent-strong);
  font-size: 24px;
}

.score-bar {
  grid-column: 1 / -1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(31, 111, 104, 0.14);
}

.score-bar i {
  display: block;
  width: 62%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.submit-button {
  width: 100%;
  min-height: 48px;
}

.export-button {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #fff;
  font-weight: 750;
}

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

.upload-card {
  position: relative;
  display: grid;
  min-height: 142px;
  align-content: center;
  gap: 6px;
  overflow: hidden;
  padding: 14px;
  border: 1px dashed rgba(31, 111, 104, 0.5);
  border-radius: 8px;
  color: var(--accent-strong);
  background: rgba(31, 111, 104, 0.06);
  text-align: center;
}

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

.upload-card span {
  position: relative;
  z-index: 1;
  font-weight: 850;
}

.upload-card small {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 12px;
}

.upload-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-card.has-image span,
.upload-card.has-image small {
  color: #fff;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.75);
}

.model-upload {
  grid-column: span 2;
  min-height: 184px;
}

.preview-panel {
  padding: 18px;
}

.replace-preview {
  padding: 18px;
}

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

.preview-toolbar h3 {
  margin: 0;
  font-size: 22px;
}

.status-pill {
  min-width: 72px;
  text-align: center;
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--accent-strong);
  background: rgba(31, 111, 104, 0.12);
  font-size: 13px;
  font-weight: 750;
}

.result-frame {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #ede8df;
  aspect-ratio: 4 / 5;
}

.replace-canvas {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #ede8df;
  aspect-ratio: 4 / 5;
}

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

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

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  color: #fff;
  background: rgba(18, 23, 22, 0.56);
  text-align: center;
  font-weight: 750;
}

.loading[hidden] {
  display: none;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border: 3px solid rgba(255, 255, 255, 0.34);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.result-meta {
  gap: 12px;
  align-items: stretch;
  margin-top: 14px;
}

.result-meta > div {
  flex: 1;
  min-width: 0;
  padding: 14px;
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result-meta p {
  margin: 8px 0 0;
  color: #2a2825;
  line-height: 1.55;
  word-break: break-word;
}

.variant-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.variant-thumb {
  position: relative;
  overflow: hidden;
  min-height: 96px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #ede8df;
}

.variant-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  aspect-ratio: 4 / 5;
}

.variant-thumb span {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  background: rgba(15, 20, 19, 0.72);
  font-size: 12px;
  font-weight: 800;
}

.variant-thumb.is-active {
  border-color: var(--accent);
}

.history-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.mini-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.mini-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mini-heading button {
  border: 0;
  color: var(--accent-strong);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.history-item span {
  color: var(--muted);
}

.history-item strong {
  white-space: nowrap;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.replace-readiness {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(31, 111, 104, 0.2);
  border-radius: 8px;
  color: var(--accent-strong);
  background: rgba(31, 111, 104, 0.08);
  font-size: 13px;
  font-weight: 800;
}

.steps {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.steps article {
  min-height: 190px;
  padding: 22px;
  border-top: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.58);
}

.steps span {
  color: var(--rose);
  font-weight: 850;
}

.steps h3 {
  margin: 36px 0 8px;
  font-size: 21px;
}

.steps p,
.api-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.api-layout {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 18px;
  padding: 18px;
}

.api-copy {
  padding: 12px;
}

.code-block {
  min-height: 230px;
  overflow: auto;
  margin: 0;
  padding: 16px;
  border-radius: 8px;
  color: #e8f1ef;
  background: #10201e;
  font-size: 13px;
  line-height: 1.6;
}

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

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

  .nav {
    display: none;
  }

  .hero {
    min-height: 680px;
  }

  .hero-media img {
    object-position: 58% center;
  }

  .hero-content {
    margin-left: 18px;
  }

  .workspace,
  .replace-workspace,
  .steps,
  .api-layout {
    grid-template-columns: 1fr;
  }

  .field-row,
  .result-meta {
    flex-direction: column;
  }

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

  .upload-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

  .ghost-button {
    display: none;
  }

  .hero h1 {
    font-size: 40px;
  }

  .studio,
  .replace,
  .workflow,
  .api {
    padding-left: 14px;
    padding-right: 14px;
  }

  .button-row,
  .variant-strip {
    grid-template-columns: 1fr 1fr;
  }

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

  .model-upload {
    grid-column: auto;
  }
}
