:root {
  color-scheme: light;
  --ink: #23201d;
  --muted: #6f6760;
  --line: #d8d0c7;
  --paper: #fbf7f0;
  --panel: #fffdf8;
  --sage: #7d927b;
  --rose: #b97972;
  --ochre: #bd8741;
  --charcoal: #2c3030;
}

* {
  box-sizing: border-box;
}

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

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

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workbench {
  max-width: 1320px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 20px;
  border-bottom: 1px solid var(--line);
}

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

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 42px;
  font-weight: 500;
  line-height: 1;
}

.status-pill {
  min-width: 96px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.studio-grid {
  display: grid;
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
  gap: 24px;
  padding-top: 24px;
}

.controls,
.preview {
  min-width: 0;
}

fieldset {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

legend {
  padding: 0 6px;
  color: var(--charcoal);
  font-size: 13px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

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

input {
  min-height: 42px;
  padding: 0 10px;
}

textarea {
  min-height: 260px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

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

.segmented label {
  margin: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 42px;
  padding: 0 8px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  text-align: center;
}

.segmented input:checked + span {
  border-color: var(--sage);
  background: #edf2ea;
  color: var(--charcoal);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 10px 0 0;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--sage);
}

.direction-note {
  min-height: 36px;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.primary-action {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  background: var(--charcoal);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.button-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 8px;
}

.secondary-action,
.ghost-action {
  width: 100%;
  min-height: 42px;
  border-radius: 6px;
  font-weight: 800;
  cursor: pointer;
}

.secondary-action {
  border: 1px solid var(--sage);
  background: #edf2ea;
  color: var(--charcoal);
}

.ghost-action {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.field-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.setup-panel.is-ready {
  border-color: rgba(125, 146, 123, 0.65);
  background: #f5f9f2;
}

.primary-action:disabled {
  cursor: wait;
  opacity: 0.58;
}

.preview {
  display: grid;
  gap: 14px;
}

.image-stage {
  display: grid;
  min-height: 620px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(125, 146, 123, 0.08), transparent 40%),
    #fffdf8;
  overflow: hidden;
}

.image-stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 760px;
  object-fit: contain;
}

.empty-state {
  display: grid;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.result-meta {
  min-height: 44px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.result-meta a {
  color: var(--ochre);
  font-weight: 800;
}

.error-detail {
  max-height: 180px;
  margin: 10px 0 0;
  padding: 10px;
  overflow: auto;
  border: 1px solid #e4b9b4;
  border-radius: 6px;
  background: #fff5f3;
  color: #71322b;
  font-size: 12px;
  white-space: pre-wrap;
}

@media (max-width: 920px) {
  .app-shell {
    padding: 16px;
  }

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

  h1 {
    font-size: 34px;
  }

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

  .image-stage {
    min-height: 420px;
  }
}
