:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17191d;
  background: #eef1f5;
  color-scheme: light;
  --ink: #17191d;
  --muted: #626a76;
  --line: #dce1e8;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --focus: #315ff5;
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.shell {
  width: min(1080px, calc(100% - 32px));
  margin: 46px auto 82px;
}

header { margin-bottom: 28px; }
.eyebrow {
  margin: 0;
  letter-spacing: .15em;
  font-size: 12px;
  font-weight: 850;
}

h1 {
  max-width: 900px;
  margin: 8px 0 14px;
  font-size: clamp(36px, 6vw, 66px);
  line-height: .98;
  letter-spacing: -.045em;
}

header > p:last-child {
  max-width: 790px;
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
}

.panel {
  margin-top: 22px;
  padding: 25px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 16px 48px rgba(24, 31, 43, .075);
}

label > span,
.field-title {
  display: block;
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 790;
}

label small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 22px;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 154px;
  padding: 34px 18px;
  overflow: hidden;
  text-align: center;
  cursor: pointer;
  background: #fafbfd;
  border: 2px dashed #aeb6c2;
  border-radius: 16px;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.drop-zone:hover,
.drop-zone:focus-within {
  border-color: #657a9d;
  background: #f5f8fc;
  transform: translateY(-1px);
}

.primary-upload {
  border-color: #7b8eae;
  background: #f6f9fd;
}

.drop-zone input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.drop-zone strong { font-size: 18px; }
.drop-zone span {
  margin-top: 8px;
  color: #6b727d;
  font-weight: 500;
}

.previews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 12px;
  margin: 16px 0 22px;
}

.single-preview { grid-template-columns: minmax(138px, 220px); }

.preview-card {
  overflow: hidden;
  background: #fff;
  border: 1px solid #e1e5eb;
  border-radius: 13px;
  box-shadow: 0 5px 16px rgba(25, 32, 45, .05);
}

.preview-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: #eef1f4;
}

.preview-card span {
  display: block;
  overflow: hidden;
  padding: 9px;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea,
select,
input[name="modelName"] {
  width: 100%;
  padding: 13px 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cdd3dc;
  border-radius: 12px;
}

textarea { resize: vertical; }

textarea:focus,
select:focus,
input[name="modelName"]:focus {
  outline: 3px solid rgba(49, 95, 245, .14);
  border-color: var(--focus);
}

.grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr 1.2fr;
  gap: 14px;
  margin-top: 16px;
}

.background-box {
  display: grid;
  grid-template-columns: minmax(210px, .78fr) 2fr;
  gap: 14px;
  margin-top: 16px;
  padding: 17px;
  background: var(--surface-soft);
  border: 1px solid #dfe4eb;
  border-radius: 15px;
}

.background-box .wide { min-width: 0; }

.prompt-preview {
  margin-top: 16px;
  padding: 13px 14px;
  background: #fbfcfd;
  border: 1px solid #dfe4eb;
  border-radius: 12px;
}

.prompt-preview summary {
  cursor: pointer;
  font-weight: 800;
}

.prompt-preview textarea {
  margin-top: 12px;
  background: #f5f7fa;
}

.output-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

#submit,
.result a {
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  font-weight: 820;
  text-decoration: none;
}

#submit {
  width: 100%;
  margin-top: 21px;
  color: #fff;
  background: #121418;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease, opacity .15s ease;
}

#submit:hover:not(:disabled) {
  background: #2a2e35;
  transform: translateY(-1px);
}

#submit:disabled { opacity: .56; cursor: wait; }

.status {
  min-height: 24px;
  margin: 12px 0 0;
  color: #535b66;
  line-height: 1.45;
}

/* Progress and log workspace */
.processing {
  margin-top: 16px;
  padding: 19px;
  background: linear-gradient(180deg, #f9fafc 0%, #f4f6f9 100%);
  border: 1px solid #dce2e9;
  border-radius: 17px;
}

.progress-top,
.log-toolbar,
.result-head,
.stream-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.progress-top > div:first-child,
.log-toolbar > div:first-child,
.result-head > div { min-width: 0; }

.processing-label {
  display: block;
  color: #737b87;
  font-size: 10px;
  font-weight: 880;
  letter-spacing: .14em;
}

#progressStage {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-numbers {
  display: grid;
  justify-items: end;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

#progressPercent {
  font-size: 22px;
  line-height: 1;
}

#elapsed {
  margin-top: 5px;
  color: #69717d;
  font-size: 11px;
}

.progress-track {
  position: relative;
  height: 15px;
  margin-top: 15px;
  overflow: hidden;
  background: #dfe4eb;
  border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(20, 27, 39, .08);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #355de8, #69a7ff);
  border-radius: inherit;
  box-shadow: 0 0 18px rgba(53, 93, 232, .22);
  transition: width .36s ease;
}

.progress-track.is-complete .progress-bar {
  background: linear-gradient(90deg, #168454, #55bf85);
  box-shadow: 0 0 18px rgba(22, 132, 84, .22);
}

.progress-track.is-error .progress-bar {
  background: linear-gradient(90deg, #b52f3b, #e5646d);
  box-shadow: 0 0 18px rgba(181, 47, 59, .2);
}

.progress-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 17px;
  margin-top: 9px;
  color: #68717c;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#jobLabel {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.estimate-label {
  padding: 3px 8px;
  color: #675815;
  background: #fff0a8;
  border: 1px solid #ebdb89;
  border-radius: 999px;
}

.progress-note {
  margin: 10px 0 0;
  color: #6d7580;
  font-size: 11px;
  line-height: 1.45;
}

.stream-preview {
  margin-top: 17px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #dbe1e9;
  border-radius: 14px;
}

.stream-preview-head {
  padding: 11px 13px;
  border-bottom: 1px solid #e2e6ec;
}

.stream-preview-head strong { font-size: 13px; }
.stream-preview-head span {
  color: #69717d;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.stream-preview img {
  display: block;
  width: min(100%, 560px);
  max-height: 540px;
  margin: 0 auto;
  object-fit: contain;
  background: #edf1f5;
}

.log-shell {
  margin-top: 18px;
  overflow: hidden;
  background: #15191f;
  border: 1px solid #272d36;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(18, 23, 31, .1);
}

.log-toolbar {
  padding: 12px 13px;
  color: #f3f5f8;
  background: #1d222a;
  border-bottom: 1px solid #303741;
}

.log-toolbar strong { display: block; font-size: 13px; }
.log-toolbar > div:first-child span {
  display: block;
  margin-top: 3px;
  color: #a7afbb;
  font-size: 10px;
}

.log-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.secondary-action {
  width: auto;
  margin: 0;
  padding: 8px 10px;
  color: #edf1f7;
  background: #262c35;
  border: 1px solid #424b58;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 760;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.secondary-action:hover { background: #333b46; }

.logs {
  height: 290px;
  overflow: auto;
  padding: 12px 13px;
  color: #e7ebf0;
  background: #15191f;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  scrollbar-color: #48515d #15191f;
}

.log-empty { margin: 0; color: #89929e; }

.log-line {
  display: grid;
  grid-template-columns: 76px 66px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 2px 0;
}

.log-line time {
  color: #8f98a5;
  font-variant-numeric: tabular-nums;
}

.log-level {
  color: #90b7ff;
  font-size: 10px;
  font-weight: 870;
  letter-spacing: .05em;
}

.log-message { overflow-wrap: anywhere; }
.log-warning .log-level { color: #f0cb70; }
.log-error .log-level { color: #ff818b; }
.log-success .log-level { color: #78d7a3; }

.result-head h2 { margin: 4px 0 0; }
.result a { color: #fff; background: #121418; white-space: nowrap; }
.result a:hover { background: #2a2e35; }
.result-meta { margin: 7px 0 0; color: #68717c; font-size: 13px; }

.result img {
  display: block;
  width: 100%;
  max-height: 80vh;
  margin-top: 20px;
  object-fit: contain;
  background: #f0f2f5;
  border: 1px solid #e1e5eb;
  border-radius: 13px;
}

.hidden { display: none !important; }

@media (max-width: 840px) {
  .output-grid { grid-template-columns: 1fr 1fr; }
  .output-grid label:last-child { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .upload-grid,
  .background-box,
  .grid,
  .output-grid {
    grid-template-columns: 1fr;
  }

  .output-grid label:last-child { grid-column: auto; }
  .shell { margin-top: 25px; }
  .panel { padding: 17px; }
  #progressStage { white-space: normal; }
  .log-line { grid-template-columns: 66px 58px minmax(0, 1fr); gap: 6px; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 20px, 1080px); }
  .progress-top,
  .log-toolbar,
  .result-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .progress-numbers {
    width: 100%;
    grid-template-columns: auto 1fr;
    align-items: baseline;
    justify-items: start;
    gap: 12px;
  }

  #elapsed { margin-top: 0; }
  .log-actions { width: 100%; }
  .secondary-action { flex: 1; text-align: center; }
  .logs { height: 250px; }
  .log-line { grid-template-columns: 1fr; gap: 0; padding: 5px 0; }
  .log-level { margin-top: 1px; }
}
