:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --bg-2: #eef3ff;
  --card: rgba(255, 255, 255, 0.78);
  --card-solid: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: rgba(42, 55, 84, 0.12);
  --primary: #6c5ce7;
  --primary-2: #00c2ff;
  --primary-3: #ff7ab6;
  --success: #12b76a;
  --danger: #f04438;
  --warning: #f79009;
  --shadow: 0 24px 70px rgba(45, 63, 108, 0.18);
  --shadow-soft: 0 16px 40px rgba(45, 63, 108, 0.12);
  --radius: 28px;
  --input: rgba(255, 255, 255, 0.88);
  --log-bg: rgba(247, 249, 255, 0.82);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #090d18;
  --bg-2: #121a2d;
  --card: rgba(20, 27, 46, 0.72);
  --card-solid: #151d31;
  --text: #edf2ff;
  --muted: #98a2b3;
  --line: rgba(211, 220, 255, 0.12);
  --primary: #9b8cff;
  --primary-2: #31d5ff;
  --primary-3: #ff8fc7;
  --success: #32d583;
  --danger: #ff6b64;
  --warning: #ffb020;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 18px 50px rgba(0, 0, 0, 0.24);
  --input: rgba(255, 255, 255, 0.06);
  --log-bg: rgba(5, 9, 19, 0.38);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--primary) 54%, transparent) transparent;
}
*::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
*::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb {
  min-height: 44px;
  border: 3px solid transparent;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--primary-2), var(--primary-3));
  background-clip: content-box;
}
*::-webkit-scrollbar-corner { background: transparent; }

.logs, .gallery, .history-list, textarea {
  scrollbar-gutter: stable;
}

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

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 12%, rgba(108, 92, 231, 0.28), transparent 28rem),
    radial-gradient(circle at 88% 0%, rgba(0, 194, 255, 0.22), transparent 25rem),
    radial-gradient(circle at 80% 90%, rgba(255, 122, 182, 0.20), transparent 26rem),
    linear-gradient(145deg, var(--bg), var(--bg-2));
  transition: background 260ms ease, color 260ms ease;
}

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

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

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(22px) saturate(1.2);
}

.glow-card { position: relative; overflow: hidden; }
.glow-card::after {
  content: "";
  position: absolute;
  inset: -2px;
  background: linear-gradient(120deg, rgba(108, 92, 231, 0.34), transparent 36%, rgba(0, 194, 255, 0.28), transparent 72%, rgba(255, 122, 182, 0.30));
  opacity: 0.75;
  z-index: -1;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 30px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  margin-bottom: 10px;
}

.hero h1 {
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1;
  margin: 0 0 14px;
  letter-spacing: -0.05em;
}

.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 780px;
  line-height: 1.65;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  min-width: 210px;
}

.icon-btn {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: var(--input);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn .moon { display: none; }
:root[data-theme='dark'] .icon-btn .sun { display: none; }
:root[data-theme='dark'] .icon-btn .moon { display: inline; }

.status-pill {
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--muted);
  padding: 9px 13px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}
.status-pill.ok { color: var(--success); }
.status-pill.warn { color: var(--warning); }
.status-pill.bad { color: var(--danger); }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.72fr) minmax(440px, 1fr);
  grid-template-rows: 650px auto auto;
  align-items: start;
  gap: 22px;
}

.control-panel, .preview-panel, .log-panel, .history-panel { padding: 22px; }
.control-panel { grid-column: 1; grid-row: 1 / span 3; }
.preview-panel {
  grid-column: 2;
  grid-row: 1;
  height: 650px;
  min-height: 610px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.log-panel {
  grid-column: 2;
  grid-row: 2;
  min-height: 292px;
  overflow: hidden;
}
.history-panel { grid-column: 2; grid-row: 3; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.section-title span { font-size: 18px; font-weight: 800; }
.section-title small { color: var(--muted); }
.preview-title { align-items: center; }
.preview-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-progress {
  flex: 0 0 auto;
  margin: -4px 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--log-bg);
}
.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.progress-head strong {
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 52%, transparent);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.10);
}
.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--primary-3));
  transition: width 420ms ease;
}
.preview-progress.is-active .progress-fill {
  background-size: 180% 100%;
  animation: progressGlow 1.35s linear infinite;
}
.preview-progress.is-done .progress-fill { background: linear-gradient(90deg, var(--success), var(--primary-2)); }
@keyframes progressGlow { to { background-position: 180% 0; } }

form { display: grid; gap: 16px; }
.field { display: grid; gap: 8px; }
.field span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

textarea, select, input {
  width: 100%;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--line);
  outline: none;
  border-radius: 18px;
  padding: 14px 15px;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
textarea {
  resize: vertical;
  min-height: 190px;
  line-height: 1.65;
}
textarea:focus, select:focus, input:focus {
  border-color: color-mix(in srgb, var(--primary) 64%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}
.checkbox-line input { width: auto; accent-color: var(--primary); }

.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.primary-btn, .ghost-btn {
  border: 0;
  border-radius: 18px;
  padding: 13px 18px;
  min-height: 50px;
  cursor: pointer;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}
.primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 16px 34px rgba(108, 92, 231, 0.34);
  flex: 1 1 160px;
}
.ghost-btn {
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--line);
}
.primary-btn:not(:disabled):hover, .ghost-btn:not(:disabled):hover { transform: translateY(-1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.38);
  border-top-color: #fff;
  border-radius: 50%;
  display: none;
  animation: spin 860ms linear infinite;
}
.is-busy .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  text-align: center;
  align-content: center;
  gap: 12px;
  border: 1px dashed var(--line);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(255,255,255,0.28), rgba(255,255,255,0.06));
  overflow: hidden;
  position: relative;
}
.empty-state h2 { margin: 4px 0 0; }
.empty-state p { margin: 0; color: var(--muted); max-width: 420px; line-height: 1.65; }
.orb {
  width: 138px;
  height: 138px;
  border-radius: 38px;
  background:
    radial-gradient(circle at 30% 24%, rgba(255,255,255,0.95), transparent 22%),
    linear-gradient(135deg, var(--primary), var(--primary-2) 52%, var(--primary-3));
  box-shadow: 0 28px 80px rgba(108, 92, 231, 0.35);
  transform: rotate(10deg);
}

.gallery {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  overflow: auto;
  padding-right: 4px;
}
.image-card {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  background: rgba(0,0,0,0.08);
}
.image-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card-solid);
  border-bottom: 1px solid var(--line);
}
.image-title {
  flex: 1 1 190px;
  min-width: 190px;
  display: grid;
  gap: 4px;
}
.image-toolbar .tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tiny-btn {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--text);
  border-radius: 12px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.tiny-btn:hover { filter: brightness(1.03); }
.download-btn {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 40%, var(--line));
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--primary) 14%, transparent),
    color-mix(in srgb, var(--primary-2) 12%, transparent));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 20%, transparent);
}
.download-btn:hover {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.download-btn:disabled,
.download-btn[aria-disabled='true'] {
  opacity: 0.5;
  pointer-events: none;
}
.zoom-label { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.image-meta, .history-image-info {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.image-meta { color: color-mix(in srgb, var(--muted) 86%, var(--primary)); }

.viewer {
  flex: 1 1 auto;
  min-height: 430px;
  height: auto;
  overflow: hidden;
  position: relative;
  cursor: grab;
  touch-action: none;
  background:
    linear-gradient(45deg, rgba(128,128,128,0.10) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(128,128,128,0.10) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(128,128,128,0.10) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(128,128,128,0.10) 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
}
.viewer.dragging { cursor: grabbing; }
.viewer img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center;
  will-change: transform;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
  border-radius: 8px;
}

.logs {
  height: clamp(230px, 26vh, 310px);
  min-height: 230px;
  overflow: auto;
  padding: 14px 12px 14px 14px;
  background: var(--log-bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
}
.log-item {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 4px 2px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}
.log-item:last-child { border-bottom: 0; }
.log-time { color: var(--muted); }
.log-msg { color: var(--text); overflow-wrap: anywhere; }
.log-item.ok .log-msg { color: var(--success); }
.log-item.warn .log-msg { color: var(--warning); }
.log-item.error .log-msg { color: var(--danger); }

@media (max-width: 980px) {
  .hero { align-items: flex-start; flex-direction: column; }
  .hero-actions { flex-direction: row; align-items: center; min-width: 0; width: 100%; justify-content: space-between; }
  .workspace-grid { grid-template-columns: 1fr; grid-template-rows: auto; }
  .control-panel, .preview-panel, .log-panel, .history-panel { grid-column: auto; grid-row: auto; }
  .log-panel { min-height: 260px; }
  .preview-panel { height: 560px; min-height: 520px; }
  .viewer { min-height: 440px; }
}

@media (max-width: 620px) {
  .app-shell { width: min(100% - 20px, 1440px); padding-top: 10px; }
  .hero, .control-panel, .preview-panel, .log-panel, .history-panel { padding: 16px; border-radius: 22px; }
  .field-grid { grid-template-columns: 1fr; }
  .section-title { align-items: flex-start; flex-direction: column; gap: 4px; }
  .preview-actions { justify-content: flex-start; }
  .image-toolbar { align-items: flex-start; flex-direction: column; }
  .image-title { min-width: 0; }
  .viewer { min-height: 360px; }
}

.reference-box {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(255,255,255,0.35), rgba(255,255,255,0.08));
  border-radius: 22px;
  padding: 14px;
}
.reference-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.reference-head div { display: grid; gap: 3px; }
.reference-head strong { font-size: 14px; }
.reference-head small { color: var(--muted); font-size: 12px; }
.upload-area {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 118px;
  border: 1px dashed color-mix(in srgb, var(--primary) 42%, var(--line));
  border-radius: 18px;
  background: var(--input);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 180ms ease, transform 180ms ease, background 180ms ease;
}
.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary);
  transform: translateY(-1px);
  background: color-mix(in srgb, var(--primary) 10%, var(--input));
}
.upload-area input { display: none; }
.upload-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-radius: 14px;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 12px 28px rgba(108, 92, 231, 0.26);
}
.reference-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}
.ref-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.08);
}
.ref-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ref-thumb button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(0,0,0,0.58);
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
}
.ref-thumb small {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  color: #fff;
  font-size: 10px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}



.history-panel {
  padding: 22px;
  min-height: 260px;
}
.history-actions {
  margin-top: -8px;
  margin-bottom: 12px;
  display: flex;
  justify-content: flex-end;
}
.ghost-btn.compact {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
}
.history-list {
  display: grid;
  gap: 12px;
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}
.history-empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  background: var(--log-bg);
}
.history-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--input);
}
.history-thumb {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  object-fit: cover;
  background: rgba(0,0,0,0.1);
  border: 1px solid var(--line);
}
.history-main {
  min-width: 0;
  display: grid;
  gap: 7px;
}
.history-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.history-date {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.history-prompt {
  font-size: 13px;
  line-height: 1.45;
  max-height: 38px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.history-meta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.history-image-info {
  padding: 6px 9px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--line));
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}
.history-buttons {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.history-buttons .tiny-btn {
  padding: 6px 9px;
  font-size: 12px;
}

@media (max-width: 980px) {
  .history-item { grid-template-columns: 84px 1fr; }
  .history-thumb { width: 84px; height: 84px; }
}

@media (max-width: 620px) {
  .history-panel { padding: 16px; border-radius: 22px; }
  .history-item { grid-template-columns: 1fr; }
  .history-thumb { width: 100%; height: 180px; }
  .history-topline { align-items: flex-start; flex-direction: column; }
}



/* 双端兼容增强：本地/线上共用，电脑/手机浏览器自适应 */
button,
.tiny-btn,
.primary-btn,
.ghost-btn,
.icon-btn,
.upload-area {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

.gallery,
.viewer,
.logs,
.history-list,
textarea {
  overscroll-behavior: contain;
}

.viewer img {
  touch-action: none;
}

@media (hover: none) and (pointer: coarse) {
  .tiny-btn,
  .ghost-btn.compact,
  .history-buttons .tiny-btn {
    min-height: 38px;
    padding: 8px 12px;
  }

  .primary-btn,
  .ghost-btn {
    min-height: 46px;
  }

  .upload-area {
    min-height: 110px;
  }
}

@media (max-width: 760px) {
  .workspace-grid {
    gap: 16px;
  }

  textarea,
  select,
  input {
    font-size: 16px;
  }

  textarea {
    min-height: 150px;
  }

  .button-row button,
  .primary-btn,
  .ghost-btn {
    width: 100%;
  }

  .reference-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .reference-head .tiny-btn {
    width: 100%;
  }

  .image-toolbar .tools {
    width: 100%;
    justify-content: flex-start;
  }

  .image-toolbar .tools .tiny-btn,
  .download-btn {
    flex: 1 1 92px;
    justify-content: center;
  }

  .logs {
    height: 260px;
    min-height: 220px;
  }
}

@media (max-width: 620px) {
  .hero p {
    font-size: 14px;
  }

  .preview-panel {
    height: min(74vh, 620px);
    min-height: 500px;
  }

  .viewer {
    min-height: 330px;
  }

  .preview-progress {
    padding: 10px 12px;
  }

  .preview-actions,
  .history-actions,
  .history-buttons {
    width: 100%;
  }

  .preview-actions .tiny-btn,
  .history-actions .ghost-btn,
  .history-buttons .tiny-btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .log-item {
    grid-template-columns: 68px minmax(0, 1fr);
    gap: 8px;
  }

  .history-list {
    max-height: 520px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: min(100% - 14px, 1440px);
  }

  .hero,
  .control-panel,
  .preview-panel,
  .log-panel,
  .history-panel {
    padding: 14px;
    border-radius: 20px;
  }

  .preview-panel {
    height: min(72vh, 580px);
    min-height: 470px;
  }

  .viewer {
    min-height: 300px;
  }

  .history-thumb {
    height: 160px;
  }
}


/* 桌面端布局优化：日志放到生成设置下面，预览区扩大，更适合 16:9 画面 */
@media (min-width: 981px) {
  .app-shell {
    width: min(1760px, calc(100% - 28px));
    padding-top: 18px;
  }

  .hero {
    padding: 22px 26px;
    margin-bottom: 16px;
  }

  .hero h1 {
    font-size: clamp(30px, 3.6vw, 50px);
    margin-bottom: 10px;
  }

  .hero p {
    line-height: 1.5;
  }

  .workspace-grid {
    grid-template-columns: minmax(340px, 410px) minmax(720px, 1fr);
    grid-template-rows: auto auto auto;
    align-items: stretch;
    gap: 16px;
  }

  .control-panel {
    grid-column: 1;
    grid-row: 1;
  }

  .log-panel {
    grid-column: 1;
    grid-row: 2;
    min-height: 230px;
  }

  .history-panel {
    grid-column: 1;
    grid-row: 3;
  }

  .preview-panel {
    grid-column: 2;
    grid-row: 1 / span 3;
    height: clamp(700px, calc(100vh - 150px), 980px);
    min-height: 680px;
  }

  .viewer {
    min-height: 540px;
  }

  .logs {
    height: clamp(180px, 22vh, 260px);
    min-height: 180px;
  }

  .history-list {
    max-height: 300px;
  }
}

@media (min-width: 1400px) {
  .workspace-grid {
    grid-template-columns: minmax(360px, 430px) minmax(900px, 1fr);
  }

  .preview-panel {
    height: clamp(760px, calc(100vh - 145px), 1040px);
  }

  .viewer {
    min-height: 620px;
  }
}

@media (max-width: 980px) {
  .control-panel { order: 1; }
  .log-panel { order: 2; }
  .preview-panel { order: 3; }
  .history-panel { order: 4; }
}

/* 一屏铺满版：减少左右空白，桌面端固定为一屏内布局；历史记录回到预览区下方 */
@media (min-width: 981px) {
  html,
  body {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .app-shell {
    width: 100vw;
    max-width: none;
    height: 100vh;
    padding: 10px;
    display: flex;
    flex-direction: column;
  }

  .hero {
    flex: 0 0 auto;
    padding: 12px 18px;
    margin-bottom: 10px;
    gap: 16px;
  }

  .eyebrow {
    margin-bottom: 4px;
    font-size: 11px;
  }

  .hero h1 {
    font-size: clamp(24px, 2.5vw, 36px);
    margin-bottom: 6px;
  }

  .hero p {
    max-width: none;
    font-size: 14px;
    line-height: 1.38;
  }

  .hero-actions {
    min-width: 185px;
    gap: 8px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 15px;
  }

  .status-pill {
    padding: 7px 11px;
    font-size: 12px;
  }

  .workspace-grid {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    grid-template-columns: minmax(390px, 26vw) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(168px, 22vh);
    align-items: stretch;
    gap: 10px;
  }

  .control-panel,
  .preview-panel,
  .log-panel,
  .history-panel {
    min-height: 0;
    padding: 14px;
    border-radius: 20px;
  }

  .control-panel {
    grid-column: 1;
    grid-row: 1;
    overflow: auto;
  }

  .log-panel {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .preview-panel {
    grid-column: 2;
    grid-row: 1;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .history-panel {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .section-title {
    margin-bottom: 10px;
    gap: 10px;
  }

  form {
    gap: 10px;
  }

  textarea {
    min-height: 118px;
    line-height: 1.5;
  }

  textarea,
  select,
  input {
    padding: 10px 12px;
    border-radius: 14px;
  }

  .field {
    gap: 6px;
  }

  .field-grid {
    gap: 10px;
  }

  .reference-box {
    padding: 10px;
    gap: 8px;
    border-radius: 18px;
  }

  .upload-area {
    min-height: 76px;
    padding: 12px;
    border-radius: 16px;
  }

  .reference-preview {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: 170px;
    overflow: auto;
  }

  .button-row {
    gap: 8px;
  }

  .primary-btn,
  .ghost-btn {
    min-height: 42px;
    padding: 10px 14px;
    border-radius: 15px;
  }

  .preview-progress {
    margin: -2px 0 10px;
    padding: 9px 12px;
    border-radius: 15px;
  }

  .progress-head {
    margin-bottom: 7px;
  }

  .gallery,
  .empty-state,
  .image-card,
  .viewer {
    min-height: 0;
  }

  .viewer {
    flex: 1 1 auto;
  }

  .logs {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    padding: 10px;
  }

  .history-actions {
    margin: -2px 0 8px;
  }

  .history-list {
    flex: 1 1 auto;
    max-height: none;
    min-height: 0;
    overflow: auto;
  }

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

  .history-thumb {
    width: 76px;
    height: 76px;
  }
}

@media (min-width: 1500px) {
  .workspace-grid {
    grid-template-columns: minmax(410px, 24vw) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(180px, 21vh);
  }
}

/* 历史记录三列卡片 + 进度条平滑渐变修正 */
.preview-progress.is-active .progress-fill {
  background-size: 100% 100%;
  background-position: center;
  animation: none;
}

@media (min-width: 981px) {
  .history-panel .section-title {
    margin-bottom: 6px;
  }

  .history-actions {
    margin: -2px 0 6px;
  }

  .history-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: start;
    gap: 10px;
    padding-right: 2px;
  }

  .history-empty {
    grid-column: 1 / -1;
  }

  .history-item {
    grid-template-columns: 82px minmax(0, 1fr);
    align-items: start;
    min-width: 0;
    padding: 8px;
    gap: 8px;
    border-radius: 16px;
  }

  .history-thumb {
    width: 82px;
    height: 82px;
    border-radius: 12px;
  }

  .history-main {
    gap: 5px;
  }

  .history-topline {
    gap: 4px;
  }

  .history-date,
  .history-meta,
  .history-image-info {
    font-size: 11px;
  }

  .history-prompt {
    font-size: 12px;
    line-height: 1.35;
    max-height: 32px;
  }

  .history-image-info {
    padding: 4px 7px;
    border-radius: 10px;
  }

  .history-buttons {
    gap: 5px;
  }

  .history-buttons .tiny-btn {
    min-height: 28px;
    padding: 5px 7px;
    font-size: 11px;
    border-radius: 9px;
  }
}

/* 历史标题合并 + 柔和动态进度条 */
.preview-progress.is-active .progress-fill {
  background-image: linear-gradient(90deg,
    var(--primary) 0%,
    var(--primary-2) 24%,
    var(--primary-3) 50%,
    var(--primary-2) 76%,
    var(--primary) 100%);
  background-size: 220% 100%;
  background-position: 0% 50%;
  animation: progressFlowSoft 2.6s ease-in-out infinite alternate, progressBreath 1.8s ease-in-out infinite;
}

@keyframes progressFlowSoft {
  from { background-position: 0% 50%; }
  to { background-position: 100% 50%; }
}

@keyframes progressBreath {
  0%, 100% { filter: saturate(1) brightness(1); }
  50% { filter: saturate(1.12) brightness(1.06); }
}

.history-title {
  align-items: center;
}

.history-title-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-left: auto;
}

.history-title-actions #historyCount {
  white-space: nowrap;
}

@media (min-width: 981px) {
  .history-panel .section-title.history-title {
    margin-bottom: 8px;
  }

  .history-title-actions .ghost-btn.compact {
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 11px;
    font-size: 12px;
  }

  .history-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .history-item {
    grid-template-columns: 86px minmax(0, 1fr);
    padding: 9px;
    gap: 9px;
  }

  .history-thumb {
    width: 86px;
    height: 86px;
  }

  .history-main {
    gap: 6px;
  }

  .history-date,
  .history-meta,
  .history-image-info {
    font-size: 12px;
  }

  .history-prompt {
    font-size: 13px;
    line-height: 1.38;
    max-height: 36px;
  }

  .history-buttons .tiny-btn {
    min-height: 30px;
    padding: 6px 8px;
    font-size: 12px;
  }
}

@media (max-width: 620px) {
  .history-title-actions {
    width: 100%;
    justify-content: space-between;
  }
}


/* 实时状态标签优化 */
.status-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px 9px 12px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.01em;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--text) 8%, transparent), inset 0 1px 0 rgba(255,255,255,0.28);
}
.status-pill::before {
  content: "";
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 16%, transparent), 0 0 18px color-mix(in srgb, currentColor 55%, transparent);
  animation: statusBreath 1.7s ease-in-out infinite;
}
.status-pill.ok {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 42%, var(--line));
  background: linear-gradient(135deg, color-mix(in srgb, var(--success) 15%, var(--input)), color-mix(in srgb, var(--primary-2) 9%, var(--input)));
}
.status-pill.warn {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 45%, var(--line));
  background: linear-gradient(135deg, color-mix(in srgb, var(--warning) 16%, var(--input)), color-mix(in srgb, var(--primary) 8%, var(--input)));
}
.status-pill.bad {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  background: linear-gradient(135deg, color-mix(in srgb, var(--danger) 15%, var(--input)), color-mix(in srgb, var(--primary-3) 8%, var(--input)));
}
.status-pill.bad::before { animation-duration: 900ms; }
@keyframes statusBreath {
  0%, 100% { transform: scale(0.82); opacity: 0.72; }
  50% { transform: scale(1.08); opacity: 1; }
}
@media (max-width: 620px) {
  .status-pill {
    max-width: 100%;
    white-space: normal;
  }
}
/* 实时状态标签优化结束 */
