/* Bristol 生图 — 样式。中性灰阶 + 单一强调色；深/浅主题由 CSS 变量驱动。 */

/* ---------- 主题变量 ---------- */
:root,
html[data-theme="light"] {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #eeeeea;
  --line: #e0e0da;
  --line-strong: #cacac3;
  --text: #1b1c1a;
  --muted: #6a6b66;
  --faint: #9a9b95;
  --accent: #2f6f62;
  --accent-hover: #275d52;
  --accent-ink: #ffffff;
  --accent-soft: #e2eeea;
  --danger: #b0443a;
  --danger-soft: #f7e6e3;
  --ok: #2e8a58;
  --warn: #a8720f;
  --info: #3a6ea5;
  --idle: #8e8f88;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #111211;
  --surface: #181917;
  --surface-2: #1f211f;
  --line: #2a2c2a;
  --line-strong: #3a3d3a;
  --text: #ebebe7;
  --muted: #9ea09a;
  --faint: #6b6e68;
  --accent: #7cc1af;
  --accent-hover: #93d0bf;
  --accent-ink: #0d1d19;
  --accent-soft: #1d2d28;
  --danger: #e0786c;
  --danger-soft: #3a211e;
  --ok: #5fc08b;
  --warn: #e0b35a;
  --info: #7aa9de;
  --idle: #6f726c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #111211;
    --surface: #181917;
    --surface-2: #1f211f;
    --line: #2a2c2a;
    --line-strong: #3a3d3a;
    --text: #ebebe7;
    --muted: #9ea09a;
    --faint: #6b6e68;
    --accent: #7cc1af;
    --accent-hover: #93d0bf;
    --accent-ink: #0d1d19;
    --accent-soft: #1d2d28;
    --danger: #e0786c;
    --danger-soft: #3a211e;
    --ok: #5fc08b;
    --warn: #e0b35a;
    --info: #7aa9de;
    --idle: #6f726c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
    color-scheme: dark;
  }
}

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

[hidden] { display: none !important; }

html {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", "Source Han Sans SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

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

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

img { display: block; max-width: 100%; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: 6px;
}
.skip-link:focus { top: 12px; }

.hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.hint:empty { display: none; }

.section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.counter {
  font-size: 12px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- 按钮 ---------- */
.primary-btn,
.ghost-btn,
.link-btn,
.icon-btn {
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, opacity 180ms ease;
}

.primary-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 44px; padding: 0 20px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; letter-spacing: 0.02em;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn.wide { width: 100%; }

.ghost-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: transparent; color: var(--text);
  font-size: 13.5px; white-space: nowrap;
}
.ghost-btn:hover:not(:disabled) { background: var(--surface-2); }
.ghost-btn.danger { color: var(--danger); }
.ghost-btn.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: transparent; }

.link-btn {
  padding: 0; border: 0; background: none;
  color: var(--accent); font-weight: 600;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: transparent; color: var(--text);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: var(--accent);
  box-shadow: inset 0 0 0 5px var(--bg);
}
.brand-name { font-weight: 650; letter-spacing: 0.01em; white-space: nowrap; }

.service-status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px; color: var(--muted);
  min-width: 0;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--idle);
  transition: background-color 200ms ease;
}
.dot[data-state="online"] { background: var(--ok); }
.dot[data-state="busy"] { background: var(--warn); }
.dot[data-state="offline"] { background: var(--danger); }
.dot[data-state="maintenance"] { background: var(--info); }
.dot[data-state="unknown"] { background: var(--idle); }

.topbar-actions {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto; min-width: 0;
}

.user-area { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name {
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13.5px; color: var(--muted);
}

/* ---------- 横幅 ---------- */
.banner {
  padding: 10px 20px;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  animation: fade-in 200ms ease;
}
.banner[data-kind="offline"] {
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom-color: transparent;
}
.banner[data-kind="maintenance"] {
  background: var(--accent-soft);
  color: var(--info);
  border-bottom-color: transparent;
}

@keyframes fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- 表单通用 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; color: var(--muted); }

input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, textarea:disabled { background: var(--surface-2); color: var(--faint); }

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

input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 0.4; }

/* 单选项：风格 */
.control-group { margin: 0; padding: 0; border: 0; min-width: 0; }
.control-group + .control-group,
.control-row + .control-group,
.control-group + .control-row,
.control-row + .generate-block { margin-top: 22px; }

.group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.group-title {
  display: block; padding: 0; margin: 0 0 8px;
  font-size: 13px; font-weight: 600; color: var(--text); letter-spacing: 0.02em;
}
.group-head .group-title { margin: 0; }

.style-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px;
}

.choice { position: relative; display: block; cursor: pointer; }
.choice input,
.ratio-opt input,
.segmented input {
  position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none;
}
.choice span {
  display: flex; align-items: center; justify-content: center;
  height: 36px; padding: 0 8px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  font-size: 13.5px; color: var(--muted); white-space: nowrap;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}
.choice:hover span { color: var(--text); }
.choice input:checked + span {
  border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600;
}
.choice input:focus-visible + span,
.ratio-opt input:focus-visible + .ratio-box,
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 比例 */
.ratio-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px;
}
.ratio-opt {
  position: relative; display: flex; align-items: center; gap: 8px;
  min-width: 0; height: 52px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease;
}
.ratio-opt:hover { background: var(--surface-2); }
.ratio-opt:has(input:checked) {
  border-color: var(--accent); background: var(--accent-soft);
}
.ratio-box {
  flex: none;
  width: calc(26px * var(--rw) / max(var(--rw), var(--rh)));
  height: calc(26px * var(--rh) / max(var(--rw), var(--rh)));
  border: 1.5px solid var(--faint);
  border-radius: 3px;
  transition: border-color 180ms ease, background-color 180ms ease;
}
.ratio-opt:has(input:checked) .ratio-box { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); }
.ratio-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.ratio-text b { font-size: 13px; font-weight: 600; white-space: nowrap; }
.ratio-text small {
  font-size: 10.5px; color: var(--muted);
  white-space: nowrap;
  letter-spacing: -0.2px;
  font-variant-numeric: tabular-nums;
}
.ratio-opt-custom .ratio-box { border-style: dashed; }

.size-inputs {
  display: flex; align-items: flex-end; gap: 8px; margin-top: 10px;
}
.field-inline { flex: 1; }
.field-inline input { height: 38px; }
.size-x { padding-bottom: 9px; color: var(--faint); }

/* 分段控件 */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; border-radius: 10px; background: var(--surface-2);
}
.segmented label { position: relative; display: block; cursor: pointer; }
.segmented span {
  display: flex; align-items: center; justify-content: center;
  height: 34px; border-radius: 7px;
  font-size: 13.5px; color: var(--muted);
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span {
  background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow);
}

.control-row { display: block; }

/* 种子 */
.seed-row { display: flex; gap: 8px; margin-top: 10px; }
.seed-row input { height: 38px; flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.seed-row .icon-btn { width: 38px; height: 38px; }

/* ---------- 左侧控制栏 ---------- */
.studio {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 0;
  align-items: start;
  min-height: calc(100vh - 60px);
}

.controls {
  position: sticky; top: 60px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 24px 22px 32px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  scrollbar-width: thin;
}

.control-form { display: block; }

.prompt-area { position: relative; }

.generate-block .primary-btn { margin-top: 0; }

.generate-block .hint { text-align: center; min-height: 0; }

/* 任务面板 */
.task-panel {
  margin-top: 22px; padding: 14px 14px 12px;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface-2);
  animation: fade-in 200ms ease;
}
.task-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.task-label { font-weight: 600; font-size: 14px; }
.task-meta { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.progress {
  position: relative; height: 4px; margin-top: 10px; border-radius: 999px;
  background: var(--line); overflow: hidden;
}
.progress span {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  border-radius: inherit; background: var(--accent);
  transition: width 400ms ease;
}
.task-panel[data-state="queued"] .progress span {
  width: 30%;
  animation: indeterminate 1.6s ease-in-out infinite;
}
@keyframes indeterminate {
  0% { left: -30%; }
  100% { left: 100%; }
}
.task-panel[data-state="failed"] .progress span { width: 100%; background: var(--danger); opacity: 0.35; }

.task-error { margin: 10px 0 0; font-size: 13px; color: var(--danger); word-break: break-word; }
.task-actions { margin-top: 10px; display: flex; justify-content: flex-end; }

/* ---------- 右侧舞台 ---------- */
.stage {
  display: flex; flex-direction: column; gap: 28px;
  min-width: 0;
  padding: 24px 28px 40px;
}

.preview { margin: 0; min-width: 0; }

.preview-frame {
  position: relative;
  display: grid; place-items: center;
  height: min(68vh, 720px);
  min-height: 320px;
  border-radius: 14px;
  background:
    repeating-conic-gradient(var(--surface-2) 0% 25%, transparent 0% 50%) 0 0 / 22px 22px,
    var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
}

.preview-frame img {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: var(--shadow);
  cursor: zoom-in;
  animation: fade-in 220ms ease;
}

.preview-empty { text-align: center; padding: 24px; }
.empty-title { margin: 0; font-size: 16px; font-weight: 600; }
.empty-sub { margin: 6px 0 0; font-size: 13.5px; color: var(--muted); }

.preview-loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 22%, transparent);
  transition: opacity 200ms ease;
  pointer-events: none;
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.preview-zoom {
  position: absolute; right: 12px; top: 12px;
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--text);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.preview-zoom svg { width: 18px; height: 18px; }
.preview-zoom:hover { background: var(--surface); }

.preview-bar {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px 24px;
  margin: 16px 0 0; padding: 0;
  animation: fade-in 200ms ease;
}

.meta {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px 20px;
  margin: 0; min-width: 0; flex: 1 1 360px;
}
.meta > div { min-width: 0; }
.meta .meta-prompt { grid-column: 1 / -1; }
.meta dt { font-size: 12px; color: var(--faint); }
.meta dd {
  margin: 1px 0 0; font-size: 13.5px; color: var(--text);
  font-variant-numeric: tabular-nums; word-break: break-word;
}
.meta .meta-prompt dd {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.6;
}
.meta .meta-prompt dd.expanded { display: block; -webkit-line-clamp: unset; }

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

/* 历史 */
.history { min-width: 0; }
.history-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.history-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px;
}

.thumb {
  position: relative; display: block; min-width: 0;
  padding: 0; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); overflow: hidden; aspect-ratio: 1 / 1;
  transition: border-color 180ms ease, transform 180ms ease;
}
.thumb img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 220ms ease;
}
.thumb:hover { border-color: var(--line-strong); }
.thumb:hover img { transform: scale(1.03); }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.thumb-skel { width: 100%; height: 100%; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.thumb-fail {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 12px; color: var(--danger); background: var(--danger-soft);
}
.thumb-tools {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 4px; justify-content: space-between; padding: 6px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
  opacity: 0; transition: opacity 180ms ease;
}
.thumb:hover .thumb-tools,
.thumb:focus-within .thumb-tools,
.thumb.active .thumb-tools { opacity: 1; }
.thumb-tools button {
  height: 26px; padding: 0 8px; border: 0; border-radius: 6px;
  background: rgba(255, 255, 255, 0.92); color: #1b1c1a; font-size: 12px;
}
.thumb-tools button.danger { color: #a33a30; }
.thumb-tools button:hover { background: #fff; }

@media (hover: none) {
  .thumb-tools { opacity: 1; }
}

@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.history-empty { margin-top: 4px; }
.history-foot { display: flex; justify-content: center; margin-top: 14px; }

/* ---------- 登录 / 注册 ---------- */
.auth-view {
  display: grid; place-items: center;
  min-height: calc(100vh - 60px);
  padding: 40px 20px;
}
.auth-panel {
  width: 100%; max-width: 380px;
  padding: 36px 32px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: fade-in 220ms ease;
}
.auth-title { margin: 0; font-size: 22px; font-weight: 650; }
.auth-sub { margin: 6px 0 24px; font-size: 13.5px; color: var(--muted); }
.auth-form { display: grid; gap: 16px; }
.auth-switch { margin: 22px 0 0; text-align: center; font-size: 13.5px; color: var(--muted); }
.auth-switch .link-btn { margin-left: 4px; }

.form-error {
  margin: 0; padding: 9px 12px; border-radius: 8px;
  background: var(--danger-soft); color: var(--danger); font-size: 13.5px;
}

/* ---------- 管理面板 ---------- */
.admin-view {
  max-width: 1080px; margin: 0 auto;
  padding: 28px 24px 56px;
  animation: fade-in 200ms ease;
}
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.admin-error {
  margin-bottom: 16px; padding: 10px 14px; border-radius: 8px;
  background: var(--danger-soft); color: var(--danger); font-size: 14px;
}

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.stat { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; background: var(--surface); }
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

.admin-block {
  margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line);
}
.admin-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch-track {
  position: relative; width: 44px; height: 24px; border-radius: 999px;
  background: var(--line-strong);
  transition: background-color 200ms ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 200ms ease;
}
.switch input:checked + .switch-track { background: var(--info); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.45; }
.switch-text { font-size: 14px; color: var(--muted); min-width: 4em; }

.table-wrap { overflow-x: auto; margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; }
.task-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.task-table th,
.task-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.task-table th { font-weight: 600; color: var(--muted); background: var(--surface-2); font-size: 12.5px; }
.task-table tr:last-child td { border-bottom: 0; }
.task-table td.prompt-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-table td.num { font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; background: var(--surface-2); color: var(--muted);
}
.badge[data-s="done"] { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge[data-s="failed"] { color: var(--danger); background: var(--danger-soft); }
.badge[data-s="running"], .badge[data-s="queued"] { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

/* ---------- 全屏查看 ---------- */
.lightbox {
  position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: transparent;
  display: grid; place-items: center;
}
.lightbox[open] { display: grid; }
.lightbox::backdrop { background: rgba(10, 11, 10, 0.86); animation: fade-in 200ms ease; }
.lightbox img {
  max-width: 94vw; max-height: 92vh; width: auto; height: auto;
  object-fit: contain; border-radius: 8px;
  animation: fade-in 200ms ease;
}
.lightbox-close {
  position: fixed; right: 16px; top: 14px;
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, 0.14); color: #fff;
  font-size: 24px; line-height: 1;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.24); }

/* ---------- 轻提示 ---------- */
.toast-host {
  position: fixed; left: 50%; bottom: 24px; z-index: 200;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font-size: 13.5px; box-shadow: var(--shadow);
  animation: toast-in 200ms ease;
  max-width: 100%; word-break: break-word;
}
.toast[data-kind="error"] { background: var(--danger); color: #fff; }
.toast[data-kind="success"] { background: var(--ok); color: #fff; }
.toast.leaving { opacity: 0; transition: opacity 200ms ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .topbar { height: auto; min-height: 56px; flex-wrap: wrap; padding: 10px 14px; gap: 10px 12px; }
  .service-status { order: 3; width: 100%; border-radius: 10px; }
  .topbar-actions { margin-left: auto; }
  .user-name { display: none; }
  .brand-name { font-size: 15px; }

  .studio {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "preview"
      "controls"
      "history";
    min-height: 0;
  }
  /* 让 stage 的子元素参与外层网格，实现：预览 → 控制 → 历史 */
  .stage { display: contents; }
  .preview { grid-area: preview; padding: 16px 16px 0; }
  .history { grid-area: history; padding: 0 16px 36px; }
  .controls {
    grid-area: controls;
    position: static; max-height: none; overflow: visible;
    border-right: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
    padding: 22px 16px 26px;
  }

  .preview-frame { height: auto; min-height: 0; aspect-ratio: 1 / 1; max-height: 70vh; }
  .preview-frame img { max-height: 100%; }
  .preview-zoom { width: 34px; height: 34px; }

  .history-grid {
    display: flex; overflow-x: auto; gap: 10px;
    padding: 2px 2px 10px; scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }
  .history-grid .thumb { flex: 0 0 118px; scroll-snap-align: start; }
  .history-grid .thumb-tools { opacity: 1; }

  .style-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ratio-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preview-bar { flex-direction: column; }
  .preview-actions { width: 100%; }
  .preview-actions .ghost-btn { flex: 1; }

  .auth-view { padding: 24px 16px; align-items: start; }
  .auth-panel { padding: 28px 22px 24px; margin-top: 8px; }
  .admin-view { padding: 20px 14px 40px; }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .studio { grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); }
  .controls { padding: 22px 18px 28px; }
  .stage { padding: 22px 20px 36px; }
}

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