:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --ink: #18212b;
  --muted: #6c7785;
  --line: #d9e0e8;
  --panel: #ffffff;
  --accent: #176b87;
  --accent-strong: #0f5168;
  --warm: #f4b860;
  --danger: #b42318;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(23, 107, 135, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(244, 184, 96, 0.16), transparent 34%),
    var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

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

.workspace {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 45px rgba(22, 32, 43, 0.08);
}

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

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.example-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.example-group {
  display: grid;
  gap: 8px;
  min-width: 0;
}

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

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

.example-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.example-item:hover,
.example-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.12);
}

.example-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #f3f6f9;
}

.example-item span,
.example-empty {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.example-empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  text-align: center;
}

.dropzone {
  position: relative;
  display: grid;
  align-content: center;
  min-height: 210px;
  overflow: hidden;
  border: 1px dashed #9aabbc;
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  text-align: center;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.dropzone.drag-over {
  border-color: var(--accent);
  background: #eef8fb;
  box-shadow: 0 0 0 4px rgba(23, 107, 135, 0.14);
  transform: translateY(-1px);
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-title,
.drop-hint {
  position: relative;
  z-index: 2;
  padding: 0 10px;
}

.drop-title {
  font-weight: 800;
}

.drop-hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.dropzone img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 160ms ease;
}

.dropzone img.visible {
  opacity: 1;
}

.dropzone img.visible ~ span,
.dropzone:has(img.visible) .drop-title,
.dropzone:has(img.visible) .drop-hint {
  opacity: 0;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

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

.seed-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 43px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 900;
  text-decoration: none;
}

.primary {
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

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

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

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent-strong);
}

.result-panel {
  display: grid;
  grid-template-rows: minmax(520px, min(74vh, 760px)) auto auto;
  gap: 14px;
  padding: 18px;
}

.result-stage {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #f9fbfc 25%, transparent 25%),
    linear-gradient(-45deg, #f9fbfc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f9fbfc 75%),
    linear-gradient(-45deg, transparent 75%, #f9fbfc 75%),
    #eef3f7;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.empty-state,
.loading-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(248, 251, 253, 0.72);
}

.empty-state {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid rgba(23, 107, 135, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.result-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.result-stage[data-state="loading"] .result-image,
.result-stage[data-state="empty"] .result-image {
  display: none;
}

.result-actions {
  display: flex;
  justify-content: flex-end;
}

.message {
  margin: 0;
  white-space: pre-wrap;
  color: var(--danger);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

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

  .result-panel {
    grid-template-rows: auto auto auto;
  }
}

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

  .topbar,
  .upload-grid,
  .example-picker,
  .settings,
  .seed-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

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