:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --surface: #fffaf1;
  --ink: #24221f;
  --muted: #6f6a61;
  --line: #d8d0c3;
  --accent: #256d85;
  --accent-strong: #174d5e;
  --warn: #9b5c16;
  --error: #a83232;
  --ok: #2f7a4f;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

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

.icon-btn {
  width: 36px;
  padding: 0;
}

.topbar {
  height: 68px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.actions,
.preset-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.model-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 12px 0;
  background: var(--surface);
}

.model-head,
.lora-row,
.model-picker-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.model-head {
  align-items: center;
  margin-bottom: 8px;
}

.model-head h3 {
  margin: 0;
  font-size: 14px;
}

.lora-row label:last-child {
  width: 76px;
}

.model-picker-row button {
  align-self: end;
}

.compact-text {
  margin: 0;
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 0.85fr) minmax(390px, 1.5fr) minmax(310px, 1fr);
  gap: 12px;
  padding: 12px;
  min-height: calc(100vh - 68px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
  overflow: auto;
  box-shadow: 0 1px 2px rgba(36, 34, 31, 0.04);
}

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

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.panel-head.small-head h2 {
  font-size: 15px;
}

#modeBadge {
  color: var(--accent);
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 9px;
  min-width: 0;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-grid.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.layers {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.layers label:nth-child(3),
.layers label:nth-child(4) {
  grid-column: 1 / -1;
}

.status-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

.status-row:last-child {
  border-bottom: 0;
}

.status-row span {
  color: var(--muted);
}

.status-row strong {
  text-align: right;
  overflow-wrap: anywhere;
}

.progress-wrap {
  padding: 10px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}

.progress-meta strong {
  color: var(--ink);
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e8dfd0;
  overflow: hidden;
}

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

.progress-bar.failed {
  background: var(--error);
}

.progress-bar.done {
  background: var(--ok);
}

.image-preview {
  display: grid;
  place-items: center;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  margin-bottom: 12px;
  overflow: hidden;
}

.image-preview img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 7px;
}

.preview-frame {
  position: relative;
  width: 100%;
}

.generation-data {
  margin-bottom: 12px;
}

.generation-data.empty {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.generation-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 13px;
}

.generation-card h3,
.generation-card h4,
.generation-card p {
  margin: 0;
}

.generation-head,
.generation-title-row,
.resource-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.generation-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

.generation-head h3 {
  font-size: 17px;
}

.generation-head .link-button {
  padding: 0 8px;
}

.generation-section {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.generation-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.generation-section h4 {
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 14px;
}

.generation-title-row h4 {
  margin-bottom: 0;
}

.generation-title-row {
  margin-bottom: 5px;
}

.generation-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.resource-row {
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.resource-row strong,
.mini-badge,
.meta-badge {
  border-radius: 4px;
  background: #eef8fb;
  border: 1px solid #c6e1e8;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  white-space: nowrap;
}

.metadata-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.copy-icon,
.link-button {
  width: auto;
  min-height: 24px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent);
  padding: 0 7px;
  font-size: 11px;
  font-weight: 700;
}

.copy-icon {
  margin-left: auto;
  min-width: 28px;
  font-size: 13px;
}

.compact-card {
  padding: 10px;
}

.compact-card .generation-head {
  margin-bottom: 8px;
}

.compact-card .generation-head h3 {
  font-size: 14px;
}

.compact-card .generation-section {
  padding: 8px 0;
}

.compact-card .generation-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.compact {
  margin-bottom: 12px;
}

details {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

summary {
  cursor: pointer;
  color: var(--accent);
}

.trace-list {
  margin: 10px 0 0;
  padding-left: 22px;
  font-size: 13px;
}

.trace-list li {
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

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

.history-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: #ffffff;
}

.segmented button {
  min-height: 30px;
  border: 0;
  border-radius: 0;
  padding: 0 9px;
  color: var(--muted);
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button.active {
  background: var(--accent);
  color: #ffffff;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.zoom-control input {
  width: 72px;
  padding: 0;
  accent-color: var(--accent);
}

.history-list {
  display: grid;
  gap: 8px;
  --history-thumb-width: 82px;
  --history-thumb-height: 110px;
}

.history-list.grid-view {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  align-items: start;
}

.history-item {
  display: grid;
  grid-template-columns: var(--history-thumb-width) 1fr;
  gap: 10px;
  width: 100%;
  padding: 8px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.history-item:hover {
  border-color: #b9d9e0;
  box-shadow: 0 8px 18px rgba(36, 34, 31, 0.08);
  transform: translateY(-1px);
}

.grid-view .history-item {
  grid-template-columns: 1fr;
  gap: 8px;
}

.history-thumb {
  position: relative;
  width: var(--history-thumb-width);
  height: var(--history-thumb-height);
  padding: 0;
  border: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
}

.grid-view .history-thumb {
  width: 100%;
  height: var(--history-thumb-height);
}

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

.star-button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  min-height: 30px;
  padding: 0;
  border-color: rgba(216, 208, 195, 0.9);
  background: rgba(255, 253, 248, 0.92);
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(36, 34, 31, 0.14);
}

.star-button.active {
  border-color: #d8a72d;
  background: #fff5cf;
  color: #9b6b00;
}

.history-info {
  min-width: 0;
  display: grid;
  gap: 4px;
  align-content: center;
}

.history-title,
.history-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-title {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
}

.history-meta {
  font-size: 11px;
  color: var(--muted);
}

.history-info .generation-card {
  margin-top: 5px;
  background: var(--panel);
}

.history-details {
  border-top: 0;
  padding: 2px 0 0;
}

.history-details summary {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  padding: 4px 8px;
  font-size: 12px;
}

.history-details[open] summary {
  margin-bottom: 8px;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 12px;
}

dialog {
  width: min(920px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.settings-form {
  padding: 16px;
}

.settings-form textarea {
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
}

.settings-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.settings-tabs button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #eef8fb;
}

.settings-section {
  display: none;
}

.settings-section.active {
  display: block;
}

.setting-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf1;
  margin-bottom: 12px;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.check-row input {
  width: 16px;
  height: 16px;
}

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

.muted {
  color: var(--muted);
}

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

  .panel {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    align-items: flex-start;
  }

  .layers,
  .field-grid,
  .field-grid.three,
  .toggle-grid {
    grid-template-columns: 1fr;
  }
}
