:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --surface-3: #f3f1ed;
  --line: #ebe8e3;
  --line-strong: #dedad3;
  --text: #26231f;
  --text-2: #5b564f;
  --muted: #928c83;
  --accent: #c94a2f;
  --accent-hover: #b23d25;
  --accent-soft: #fff0ea;
  --accent-line: #f4c8ba;
  --green: #4f9a6b;
  --yellow: #d79a32;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(30, 26, 20, 0.04), 0 8px 24px rgba(30, 26, 20, 0.04);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 62px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
}

.mark {
  display: grid;
  place-items: center;
  width: 33px;
  height: 33px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.brand-sub {
  color: var(--muted);
  font-size: 10.5px;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 3px;
  margin: 0 auto;
  padding: 4px;
  background: var(--surface-3);
  border-radius: 999px;
}

.topnav-link {
  padding: 6px 15px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.topnav-link:hover {
  color: var(--text);
}

.topnav-link.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(30, 26, 20, 0.08);
}

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

.latency-chip,
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
}

.latency-gauge,
.status-dot,
.queue-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.latency-gauge.good,
.status-dot.online,
.queue-dot.busy {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(79, 154, 107, 0.13);
}

.latency-gauge.mid,
.queue-dot.pending {
  background: var(--yellow);
  box-shadow: 0 0 0 3px rgba(215, 154, 50, 0.13);
}

.latency-gauge.bad,
.status-dot.offline {
  background: #c9685a;
  box-shadow: 0 0 0 3px rgba(201, 104, 90, 0.12);
}

.status-dot.working {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 74, 47, 0.14);
}

.endpoint {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.edition-pill {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- layout ---------- */

.app-body {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 18px 80px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(30, 26, 20, 0.03);
}

.tab:hover {
  border-color: var(--line-strong);
}

.tab.is-active {
  border-color: var(--line-strong);
  color: var(--text);
  font-weight: 600;
  background: #fff;
}

.page-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

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

.form-sheet {
  padding: 0;
  overflow: hidden;
}

.form-section {
  padding: 16px 20px;
  scroll-margin-top: 82px;
}

.form-section + .form-section {
  border-top: 1px solid var(--line);
}

.form-sheet > .action {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  padding: 14px 20px 16px;
}

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

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.title-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  flex: 0 0 auto;
}

.card-head h2 {
  font-size: 14.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge,
.panel-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
  white-space: nowrap;
}

.badge.warn,
.panel-tag.warn {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- form ---------- */

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.6;
}

.label,
.field-wrap .label,
.slider-wrap .label {
  display: block;
  margin: 13px 0 6px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

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

.label-row .label {
  margin: 0 0 6px;
}

.label-row .hint {
  margin: 0;
}

.field-wrap,
.slider-wrap {
  display: block;
  min-width: 0;
}

.slider-wrap .label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.slider-wrap b {
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.field {
  display: block;
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  outline: none;
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field:hover {
  border-color: #cbc5bb;
}

.field:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 74, 47, 0.11);
}

select.field {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%238a857d' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

select.field:disabled {
  color: var(--muted);
  background-color: var(--surface-3);
  cursor: not-allowed;
}

.area {
  resize: vertical;
  min-height: 96px;
  line-height: 1.65;
}

.area.small {
  min-height: 70px;
}

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

.nl-box .field {
  background: #fff;
}

.nl-box .hint {
  margin-bottom: 0;
}

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

input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 10px 0 2px;
  appearance: none;
  border-radius: 999px;
  background: var(--line-strong);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 3px rgba(30, 26, 20, 0.2);
  cursor: pointer;
}

.seed-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.seed-row .field-wrap {
  flex: 1;
}

.seed-row .label {
  margin-top: 0;
}

.lora-box {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.lora-box .field-wrap .label {
  margin-top: 0;
}

.lora-box .slider-wrap {
  margin-top: 8px;
}

.lora-box .hint {
  margin-bottom: 0;
}

details.advanced summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

details.advanced summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  font-size: 14.5px;
  font-weight: 700;
}

.summary-note {
  color: var(--muted);
  font-size: 11.5px;
}

.adv-body {
  margin-top: 4px;
}

/* ---------- chips & buttons ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip:hover {
  border-color: var(--accent-line);
  color: var(--text);
}

.chip.active {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover:not(:disabled) {
  background: #ece9e4;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(201, 74, 47, 0.2);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn.exhibit {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

.btn.ghost {
  background: var(--surface-2);
  border-color: var(--line);
}

.btn.danger {
  color: #b44735;
}

.btn.link {
  padding: 4px 2px;
  background: none;
  color: var(--accent);
}

.btn.tiny {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 11.5px;
  border-radius: 999px;
  white-space: nowrap;
}

.action {
  padding: 14px 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.action-note {
  font-size: 12.5px;
  font-weight: 600;
}

.action-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.action-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.action-shortcut {
  color: var(--muted);
  font-size: 11px;
}

.action .btn.primary {
  min-width: 132px;
  min-height: 40px;
  font-size: 13px;
}

.turnstile-wrap {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--line);
}

.turnstile-box {
  min-height: 66px;
}

/* ---------- stage ---------- */

.stage {
  padding: 16px;
  scroll-margin-top: 82px;
}

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

.stage-label {
  font-size: 14px;
  font-weight: 700;
}

.stage-top #stageMeta {
  color: var(--muted);
  font-size: 11.5px;
  text-align: right;
}

.stage-body {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 330px;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}

.placeholder {
  text-align: center;
  max-width: 280px;
}

.placeholder-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
}

.placeholder-icon svg {
  width: 24px;
  height: 24px;
}

.ph-title {
  font-size: 13.5px;
  font-weight: 600;
}

.ph-text {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

#result {
  display: block;
  max-width: 100%;
  max-height: 620px;
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 20px rgba(30, 26, 20, 0.08);
}

.progress-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(300px, 80%);
  transform: translate(-50%, -50%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 12px;
  font-weight: 600;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.stage-actions .btn {
  flex: 1 1 auto;
}

/* ---------- gallery ---------- */

.history {
  margin-top: 22px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  scroll-margin-top: 82px;
}

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

.history-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-title h2 {
  font-size: 15px;
  font-weight: 700;
}

.history-count {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.card.gallery-card,
.gallery .card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: none;
}

.thumb-wrap {
  aspect-ratio: 1 / 1;
  background: var(--surface-3);
  overflow: hidden;
}

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

.card-body {
  padding: 10px;
}

.card-prompt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 34px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-2);
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10.5px;
}

.card-actions {
  display: flex;
  gap: 6px;
  margin-top: 9px;
}

.mini {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text-2);
  font-size: 11px;
  cursor: pointer;
}

.mini:hover {
  border-color: var(--accent-line);
  color: var(--accent);
}

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

.mini.report:hover {
  border-color: #e3b7b0;
  color: #b42318;
}

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

/* ---------- queue dock & toast ---------- */

.queue-dock {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 25;
}

.queue-dock-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 11.5px;
  box-shadow: 0 6px 18px rgba(30, 26, 20, 0.1);
  cursor: pointer;
}

.queue-caret {
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  margin-left: 2px;
}

.queue-panel {
  width: 290px;
  max-height: 330px;
  margin-bottom: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(30, 26, 20, 0.12);
  overflow: auto;
}

.queue-panel-head {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 700;
}

.queue-panel-count {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
}

.queue-today {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.queue-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.queue-empty {
  padding: 12px 0;
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
}

.queue-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.queue-item-model {
  font-size: 11.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-item-meta {
  grid-column: 1;
  color: var(--muted);
  font-size: 10.5px;
}

.queue-tag {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10.5px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 40;
  max-width: min(460px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(30, 26, 20, 0.14);
  font-size: 12.5px;
  transform: translateX(-50%);
}

/* ---------- responsive ---------- */

@media (max-width: 980px) {
  .topbar {
    gap: 12px;
    padding: 0 16px;
  }

  .topnav,
  .endpoint,
  .edition-pill {
    display: none;
  }

  .app-body {
    padding: 16px 14px 70px;
  }

  .stage-body {
    min-height: 320px;
  }

  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .latency-chip {
    display: none;
  }
}

@media (max-width: 560px) {
  .brand-sub,
  .status-chip span:not(.status-dot) {
    display: none;
  }

  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .action-right {
    justify-content: space-between;
  }

  .action .btn.primary {
    flex: 1;
  }

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

  .card-head {
    align-items: flex-start;
  }
}
