:root {
  color-scheme: light;
  --ink: #1f2520;
  --muted: #687066;
  --line: #d8ded2;
  --paper: #f8f6ef;
  --panel: #fffdf7;
  --accent: #16634f;
  --accent-strong: #0d4536;
  --warn: #9c5b16;
  --code: #16211d;
  --shadow: 0 20px 70px rgba(26, 37, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

button,
input,
select,
textarea,
.prompt-editor {
  font: inherit;
}

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

.workspace {
  border: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.88);
  box-shadow: var(--shadow);
}

.topbar,
.global-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.global-controls {
  align-items: end;
  background: rgba(243, 245, 238, 0.72);
}

.asset-library {
  display: grid;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.72);
}

.asset-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 12px;
  min-width: 0;
}

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

.asset-card {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.asset-thumb {
  position: relative;
  overflow: visible;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefb;
}

.asset-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

.asset-remove {
  position: absolute;
  right: -7px;
  top: -7px;
  display: grid;
  width: 24px;
  min-height: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid #fffefb;
  border-radius: 50%;
  padding: 0;
  background: #34403a;
  color: white;
  font-size: 15px;
  line-height: 1;
}

.asset-remove:hover {
  background: #9b2f24;
}

.asset-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.asset-meta strong {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-download {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

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

h1 {
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 18px;
}

.status {
  max-width: 420px;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

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

.full {
  grid-column: 1 / -1;
}

label {
  font-size: 13px;
  font-weight: 700;
  color: #2c332d;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  border: 1px solid #cbd3c7;
  border-radius: 6px;
  background: #fffefb;
  color: var(--ink);
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 99, 79, 0.15);
}

.key-field {
  flex: 1 1 640px;
}

.concurrency-field {
  width: 180px;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.ghost {
  background: transparent;
  color: var(--accent);
}

.ghost:hover {
  background: rgba(22, 99, 79, 0.08);
}

.jobs-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  padding: 18px;
}

.jobs-grid[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.jobs-grid[data-count="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.job-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.job-form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.job-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid #cbd3c7;
  border-radius: 8px;
  background: #f1f0e8;
}

.segmented label {
  cursor: pointer;
}

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

.segmented span {
  display: grid;
  min-height: 34px;
  place-items: center;
  border-radius: 5px;
  color: var(--muted);
}

.segmented input:checked + span {
  background: var(--accent);
  color: white;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.background-hint {
  color: var(--warn);
}

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

.locked-value {
  display: flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid #cbd3c7;
  border-radius: 6px;
  padding: 0 12px;
  background: #f5f3ea;
  color: var(--muted);
  font-weight: 700;
}

.upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 10px;
  min-width: 0;
}

.preview-thumb {
  position: relative;
  overflow: visible;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefb;
}

.preview-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
}

.preview-index {
  position: absolute;
  left: 6px;
  top: 6px;
  display: grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: rgba(22, 99, 79, 0.88);
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.preview-remove {
  position: absolute;
  right: -7px;
  top: -7px;
  display: grid;
  width: 24px;
  min-height: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid #fffefb;
  border-radius: 50%;
  padding: 0;
  background: #34403a;
  color: white;
  font-size: 15px;
  line-height: 1;
}

.preview-remove:hover {
  background: #9b2f24;
}

.prompt-wrap {
  position: relative;
  min-width: 0;
}

.prompt-composer {
  display: block;
  min-height: 150px;
  border: 1px solid #cbd3c7;
  border-radius: 8px;
  padding: 12px;
  background: #fffefb;
  min-width: 0;
}

.prompt-composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 99, 79, 0.15);
}

.prompt-editor {
  min-height: 124px;
  min-width: 0;
  outline: none;
  color: var(--ink);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.prompt-editor:empty::before {
  content: attr(data-placeholder);
  color: #98a096;
}

.reference-chip {
  display: inline-grid;
  grid-template-columns: 20px auto;
  align-items: center;
  gap: 4px;
  max-width: 168px;
  margin: 0 2px;
  vertical-align: -6px;
  border-radius: 5px;
  padding: 2px 6px 2px 2px;
  background: #eef4ee;
  color: var(--accent-strong);
  font-weight: 700;
  white-space: nowrap;
  user-select: all;
}

.reference-chip img {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: cover;
}

.reference-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.reference-menu {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid #b9c3b4;
  border-radius: 6px;
  padding: 10px;
  background: #fffefb;
  box-shadow: 0 14px 36px rgba(26, 37, 31, 0.16);
}

.reference-menu[hidden] {
  display: none;
}

.reference-option {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  background: white;
  color: var(--ink);
  text-align: left;
}

.reference-option:hover {
  background: #eef4ee;
}

.reference-option img {
  width: 42px;
  height: 42px;
  border-radius: 5px;
  object-fit: cover;
}

.reference-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
}

.run-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px 12px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.run-stats span {
  white-space: nowrap;
}

.run-stats .cost {
  color: #c46a00;
  font-weight: 700;
}

.job-result {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  border: 1px dashed #aeb9aa;
  border-radius: 6px;
  padding: 14px;
  color: var(--accent-strong);
  background: rgba(255, 253, 247, 0.74);
  font-weight: 700;
}

.loading[hidden] {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(22, 99, 79, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.image-tile {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.image-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefb;
}

.image-tile a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.raw {
  min-width: 0;
}

.raw summary {
  cursor: pointer;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

pre {
  overflow: auto;
  max-width: 100%;
  min-height: 220px;
  max-height: 420px;
  margin: 0;
  border: 1px solid #24352f;
  border-radius: 6px;
  padding: 14px;
  background: var(--code);
  color: #e5f1e7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.55;
}

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

@media (max-width: 1180px) {
  .jobs-grid[data-count="3"] {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .shell {
    width: min(100% - 20px, 760px);
    padding: 10px 0;
  }

  .topbar,
  .global-controls,
  .asset-head {
    display: grid;
    align-items: start;
    padding: 18px;
  }

  .asset-library {
    padding: 14px 18px;
  }

  .status {
    text-align: left;
  }

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

  .concurrency-field {
    width: 100%;
  }

  .jobs-grid,
  .jobs-grid[data-count="2"],
  .jobs-grid[data-count="3"] {
    grid-template-columns: 1fr;
    padding: 12px;
  }

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

  .actions {
    display: grid;
    justify-items: stretch;
  }

  .run-stats {
    justify-content: start;
  }
}
