:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --panel: #ffffff;
  --panel-soft: #eef3ee;
  --text: #202721;
  --muted: #667062;
  --line: #d8ded5;
  --accent: #0e7c6b;
  --accent-strong: #075a4d;
  --accent-soft: #dcefeb;
  --danger: #b54735;
  --shadow: 0 18px 48px rgba(38, 50, 40, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    "PingFang SC",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  line-height: 1.08;
}

h2 {
  font-size: 1.15rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: #d7a400;
}

.status-pill.ready .status-dot {
  background: #15975f;
}

.status-pill.error .status-dot {
  background: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.control-panel,
.result-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

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

label {
  color: #364239;
  font-size: 0.92rem;
  font-weight: 700;
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

textarea {
  min-height: 190px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

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

textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.upload-zone {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 74px;
  padding: 14px;
  border: 1px dashed #a8b6aa;
  border-radius: 8px;
  background: var(--panel-soft);
}

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

.upload-copy {
  display: grid;
  gap: 4px;
  pointer-events: none;
}

.upload-copy span,
.preview-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-button {
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.icon-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.preview-row {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.preview-row img {
  width: 68px;
  height: 68px;
  border-radius: 6px;
  object-fit: cover;
}

.preview-row div {
  min-width: 0;
}

.preview-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.param-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.primary-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

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

.primary-button:disabled {
  opacity: 0.68;
  cursor: wait;
}

.button-icon {
  font-size: 1.05rem;
  line-height: 1;
}

.result-panel {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  min-height: 670px;
  padding: 18px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.download-button {
  min-height: 38px;
  padding: 0 16px;
}

.result-stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #f1f4f1 25%, transparent 25%),
    linear-gradient(-45deg, #f1f4f1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f4f1 75%),
    linear-gradient(-45deg, transparent 75%, #f1f4f1 75%);
  background-color: #fbfcfb;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.empty-state,
.loading-state {
  display: grid;
  gap: 10px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

[hidden] {
  display: none !important;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--accent);
  font-size: 1.5rem;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 820ms linear infinite;
}

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

#resultImage {
  width: 100%;
  height: 100%;
  max-height: 72vh;
  object-fit: contain;
}

.message-box {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  line-height: 1.5;
  word-break: break-word;
}

.message-box.error {
  border-color: rgba(181, 71, 53, 0.35);
  background: #fff7f5;
  color: var(--danger);
}

@media (max-width: 840px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 18px 0;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

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

  .result-panel {
    grid-template-rows: auto minmax(320px, 58vh) auto;
    min-height: 0;
  }

  .result-stage {
    min-height: 320px;
  }
}

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

  .control-panel,
  .result-panel {
    padding: 14px;
  }

  .status-pill {
    white-space: normal;
  }
}
