:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #fbfcfa;
  --line: #dfe6dc;
  --line-strong: #c4d0c2;
  --text: #19211b;
  --muted: #667164;
  --soft: #879284;
  --green: #2f6f4f;
  --green-dark: #245d3f;
  --green-soft: #eef8f1;
  --orange: #d08234;
  --danger: #c94545;
  --shadow: 0 18px 48px rgba(31, 48, 35, 0.09);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, #fbfcf8 0%, #f4f7f1 48%, #edf3e9 100%);
  letter-spacing: 0;
}

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

button {
  border: 0;
}

[hidden] {
  display: none !important;
}

.shell {
  width: min(100vw, 1720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 20;
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 28px rgba(30, 48, 34, 0.08);
  backdrop-filter: blur(10px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--green);
  color: white;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(28, 47, 32, 0.12);
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.theme-toggle,
.connection-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8faf6;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.theme-toggle {
  cursor: pointer;
}

.connection-pill strong {
  max-width: 320px;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--soft);
}

.dot.live {
  background: #2bbf78;
  box-shadow: 0 0 0 4px rgba(43, 191, 120, 0.14);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.config-view {
  min-height: calc(100vh - 116px);
  display: grid;
  grid-template-columns: minmax(280px, 0.86fr) minmax(320px, 560px);
  gap: 24px;
  align-items: center;
  padding: 18px 6px 42px;
}

.intro {
  max-width: 620px;
  display: grid;
  gap: 16px;
}

.eyebrow,
.badge {
  width: max-content;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid #b9d7c5;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.intro h2 {
  margin: 0;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 0.98;
}

.intro p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.simple-hero {
  width: min(480px, 100%);
  display: grid;
  gap: 8px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 14px 32px rgba(31, 52, 36, 0.08);
}

.simple-hero strong {
  font-size: 20px;
}

.simple-hero span {
  color: var(--muted);
}

.config-card {
  padding: 22px;
}

.panel-title,
.studio-head,
.history-head,
.reference-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  margin-bottom: 18px;
}

.panel-title h3,
.settings-section h3,
.studio-head h2,
.history-head h3 {
  margin: 0;
}

.panel-title p,
.studio-head span,
.reference-head span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.form-grid,
.field,
.settings-section,
.reference-card {
  display: grid;
  gap: 10px;
}

.form-grid {
  gap: 14px;
}

.field > span,
.field label {
  color: #2d392e;
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cfd8cc;
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  padding: 10px 12px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 111, 79, 0.13);
}

.readonly-field {
  background: #f5f8f3;
  color: var(--muted);
  cursor: default;
}

.input-shell {
  position: relative;
}

.secret-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  transform: translateY(-50%);
  background: #f1f5ef;
  color: var(--green);
  cursor: pointer;
}

.model-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.model-status {
  color: var(--muted);
  font-size: 12px;
}

.model-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.model-suggestions button,
.chip,
.link-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8faf6;
  color: var(--green-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.btn {
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 850;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  border: 1px solid var(--green-dark);
  background: var(--green);
  color: white;
  box-shadow: 0 10px 22px rgba(47, 111, 79, 0.2);
}

.btn.primary:hover {
  background: var(--green-dark);
}

.btn.secondary {
  border: 1px solid var(--line);
  background: #f8faf6;
  color: var(--green-dark);
}

.btn.compact {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
}

.error-box {
  display: none;
  padding: 10px 12px;
  border: 1px solid rgba(201, 69, 69, 0.3);
  border-radius: 10px;
  background: rgba(201, 69, 69, 0.08);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
}

.error-box.show {
  display: block;
}

.studio-view {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(460px, 1fr) minmax(280px, 360px);
  gap: 14px;
  align-items: start;
}

.side-panel,
.settings-panel {
  position: sticky;
  top: 94px;
  max-height: calc(100vh - 112px);
  overflow: auto;
}

.side-panel,
.settings-panel,
.preview-panel {
  padding: 14px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f4f7f1;
}

.mode-tab {
  min-height: 36px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.mode-tab.active {
  background: white;
  color: var(--green-dark);
  box-shadow: 0 6px 16px rgba(31, 52, 36, 0.09);
}

.reference-card,
.settings-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.dropzone {
  min-height: 124px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  border: 1px dashed #b8c8b5;
  border-radius: 12px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

.dropzone.dragover {
  border-color: var(--green);
  background: #f5fbf6;
}

.dropzone input {
  display: none;
}

.drop-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 24px;
  font-weight: 800;
}

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

.thumb {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 10px;
  background: #eef2ec;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb button {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(25, 33, 27, 0.76);
  color: white;
  cursor: pointer;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-panel {
  min-height: calc(100vh - 96px);
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  overflow: hidden;
}

.studio-head {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.studio-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.preview-stage {
  position: relative;
  min-height: 520px;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(35, 62, 45, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(35, 62, 45, 0.055) 1px, transparent 1px),
    #fbfcfa;
  background-size: 28px 28px;
}

.empty-state {
  max-width: 360px;
  display: grid;
  place-items: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
}

.empty-state h3,
.empty-state p {
  margin: 0;
}

.empty-frame {
  width: 116px;
  height: 116px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  color: var(--green);
  font-size: 40px;
}

.result-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  align-self: start;
}

.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  box-shadow: 0 12px 28px rgba(32, 48, 34, 0.08);
}

.result-card img {
  width: 100%;
  display: block;
  aspect-ratio: 1;
  object-fit: contain;
  background: #f0f3ee;
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.result-actions {
  display: flex;
  gap: 8px;
}

.result-actions a,
.result-actions button {
  color: var(--green-dark);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.job-overlay {
  position: absolute;
  inset: 18px;
  z-index: 5;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(246, 248, 244, 0.94);
}

.progress-track {
  width: min(420px, 82%);
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ede4;
}

.progress-track i {
  display: block;
  width: 5%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.4s ease;
}

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

.compact-field {
  width: min(176px, 100%);
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.toggle-line input {
  width: 18px;
  min-height: 18px;
}

.config-summary {
  display: grid;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}

.config-summary div {
  min-width: 0;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.config-summary div:last-child {
  border-bottom: 0;
}

.config-summary span {
  color: var(--muted);
  font-size: 12px;
}

.config-summary strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-button {
  width: 100%;
}

.stop-button {
  width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(201, 69, 69, 0.45);
  background: #fff;
  color: var(--danger);
}

.stop-button:hover {
  border-color: var(--danger);
  background: rgba(201, 69, 69, 0.06);
}

.stop-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.success-history-list {
  display: grid;
  gap: 10px;
}

.history-empty {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.history-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 9px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.history-item img {
  width: 64px;
  height: 64px;
  border-radius: 9px;
  object-fit: cover;
  background: #f0f3ee;
}

.history-body {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.history-body strong,
.history-body span,
.history-body p {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-body strong {
  font-size: 12px;
}

.history-body span,
.history-body p {
  color: var(--muted);
  font-size: 11px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 12px;
  background: #17221a;
  color: white;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1410;
  --panel: #151d17;
  --panel-soft: #111811;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.2);
  --text: #f5f5ef;
  --muted: #aab4a6;
  --soft: #7f8d7b;
  --green-soft: rgba(89, 186, 130, 0.14);
}

[data-theme="dark"] body,
body[data-theme="dark"] {
  background: linear-gradient(180deg, #0f1711, #0b100c);
}

[data-theme="dark"] .topbar,
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] .simple-hero,
[data-theme="dark"] .dropzone,
[data-theme="dark"] .result-card,
[data-theme="dark"] .config-summary,
[data-theme="dark"] .history-item,
[data-theme="dark"] .empty-frame {
  background: #151d17;
}

[data-theme="dark"] .preview-stage {
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #101610;
  background-size: 28px 28px;
}

@media (max-width: 1180px) {
  .studio-view {
    grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr);
  }

  .settings-panel {
    position: static;
    grid-column: 1 / -1;
    max-height: none;
  }
}

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

  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

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

  .side-panel,
  .settings-panel {
    position: static;
    max-height: none;
  }

  .preview-panel {
    min-height: 620px;
  }
}

@media (max-width: 560px) {
  .connection-pill strong {
    max-width: 160px;
  }

  .mini-grid,
  .model-row {
    grid-template-columns: 1fr;
  }

  .preview-stage {
    min-height: 360px;
    padding: 12px;
  }
}
