:root {
  --canvas: #f4f5f2;
  --paper: #ffffff;
  --ink: #171916;
  --muted: #6e746c;
  --line: #daddd6;
  --line-strong: #b9beb5;
  --accent: #1f7a55;
  --accent-dark: #155a3e;
  --accent-soft: #e4f0e9;
  --info: #35648f;
  --warning: #9a640d;
  --danger: #ad3328;
  --radius: 6px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  letter-spacing: 0;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(31, 122, 85, 0.22);
  outline-offset: 2px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 245, 242, 0.96);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.brand-block,
.service-state,
.section-heading,
.section-heading > div,
.composer-actions,
.worker-detail,
.batch-title-row,
.task-head,
.image-meta {
  display: flex;
  align-items: center;
}

.brand-block { gap: 12px; }

.brand-mark {
  width: 28px;
  height: 28px;
  border: 7px solid var(--ink);
  border-right-color: var(--accent);
  border-radius: 50%;
  transform: rotate(-28deg);
}

h1,
h2,
h3,
p { margin: 0; }

.brand-block h1 {
  font-size: 18px;
  line-height: 1.15;
  font-weight: 720;
}

.brand-block p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.service-state {
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background-color 160ms ease, box-shadow 160ms ease;
}

.state-dot.is-ready {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(31, 122, 85, 0.12);
}

.state-dot.is-working {
  background: var(--info);
  box-shadow: 0 0 0 4px rgba(53, 100, 143, 0.12);
}

.state-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(173, 51, 40, 0.12);
}

.workspace {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

.composer-pane,
.results-pane {
  min-width: 0;
  padding: 32px;
}

.composer-pane {
  border-right: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 72px;
  align-self: start;
  min-height: calc(100vh - 72px);
}

.section-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}

.section-heading > div { gap: 12px; }

.section-index {
  color: var(--accent);
  font: 700 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.section-heading h2 {
  font-size: 18px;
  font-weight: 680;
}

.prompt-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.field-label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

textarea {
  width: 100%;
  min-height: 310px;
  resize: vertical;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfa;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
}

textarea::placeholder { color: #9ba099; }

.composer-actions {
  gap: 10px;
  margin-top: 14px;
}

.primary-action,
.quiet-action,
.session-action,
.download-link,
.delete-button {
  min-height: 42px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.primary-action {
  flex: 1;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 680;
}

.primary-action:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.primary-action:active:not(:disabled),
.quiet-action:active,
.session-action:active,
.download-link:active { transform: translateY(1px); }

.primary-action:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  background: var(--line);
  color: #8b9089;
}

.quiet-action,
.session-action,
.delete-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.quiet-action {
  padding: 0 16px;
}

.quiet-action:hover,
.session-action:hover,
.delete-button:hover { background: #eceee9; }

.quiet-action.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.worker-detail {
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0;
  margin-top: 24px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.worker-detail span { color: var(--muted); }

.worker-detail strong {
  overflow: hidden;
  max-width: 68%;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.session-action {
  width: 100%;
  margin-top: 14px;
  padding: 0 14px;
  font-size: 13px;
}

.results-pane { padding-bottom: 80px; }

.results-heading { margin-bottom: 18px; }

.empty-state {
  min-height: 430px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  animation: rise-in 360ms ease both;
}

.empty-frame {
  width: 142px;
  aspect-ratio: 4 / 3;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 5px;
  margin-bottom: 24px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.empty-frame span {
  background: #e4e7e1;
  border-radius: 2px;
}

.empty-frame span:nth-child(2) { background: var(--accent-soft); }

.empty-state h3 { font-size: 16px; }

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.batch-list { display: grid; gap: 28px; }

.batch {
  border-top: 1px solid var(--line-strong);
  animation: rise-in 280ms ease both;
}

.batch-header {
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
}

.batch-title-row {
  justify-content: space-between;
  gap: 16px;
}

.batch-title-row h3 {
  font-size: 14px;
  font-weight: 680;
}

.batch-title-row time {
  color: var(--muted);
  font-size: 11px;
}

.progress-track {
  height: 3px;
  overflow: hidden;
  margin-top: 14px;
  background: #e3e6e0;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 420ms ease;
}

.batch-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.delete-button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--danger);
  font-size: 11px;
}

.task-list { display: grid; }

.task {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.task-number {
  padding-top: 3px;
  color: var(--muted);
  font: 600 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.task-content { min-width: 0; }

.task-head {
  justify-content: space-between;
  gap: 16px;
}

.task-prompt {
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.55;
}

.task-status {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

.task-status[data-state="succeeded"] { color: var(--accent); }
.task-status[data-state="failed"],
.task-status[data-state="unknown"] { color: var(--danger); }
.task-status[data-state="running"],
.task-status[data-state="submitted"],
.task-status[data-state="generating"] { color: var(--info); }

.task-response {
  margin-top: 10px;
  padding-left: 11px;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.task-error {
  margin-top: 9px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.image-result {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  animation: image-reveal 360ms ease both;
}

.image-link {
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #eceeea;
}

.image-link img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  transition: transform 180ms ease;
}

.image-link:hover img { transform: scale(1.015); }

.image-footer {
  padding: 10px;
  border-top: 1px solid var(--line);
}

.image-meta {
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.download-link {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 9px;
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-size: 12px;
  font-weight: 620;
}

.download-link:hover { background: #eceee9; }

.token-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(20, 24, 20, 0.2);
}

.token-dialog::backdrop { background: rgba(20, 24, 20, 0.48); }

.token-dialog form {
  display: grid;
  gap: 14px;
  padding: 28px;
}

.dialog-label {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.token-dialog h2 { font-size: 22px; }

.token-dialog p,
.token-dialog label {
  color: var(--muted);
  font-size: 12px;
}

.token-dialog input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.form-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 15px;
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  font-size: 12px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 30;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes image-reveal {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 820px) {
  .topbar {
    min-height: 64px;
    padding: 12px 16px;
  }

  .brand-block p { display: none; }

  .workspace { display: block; }

  .composer-pane,
  .results-pane { padding: 24px 18px; }

  .composer-pane {
    min-height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  textarea { min-height: 220px; }

  .results-pane { padding-bottom: 64px; }

  .empty-state { min-height: 320px; }

  .task {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
  }

  .task-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
