:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f3efe9;
  --text: #1d1a17;
  --muted: #6d655c;
  --line: #e2dbd1;
  --accent: #b2603a;
  --accent-soft: #f5e7df;
  --ok: #3f7d58;
  --err: #b3403a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 26, 23, .05), 0 8px 24px rgba(29, 26, 23, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120f;
    --surface: #1d1a16;
    --surface-2: #26221d;
    --text: #f2ede6;
    --muted: #a79d91;
    --line: #332d26;
    --accent: #d98a5f;
    --accent-soft: #33241b;
    --ok: #6fbf8e;
    --err: #e0776f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* 兜底：provider 的报错、generation_id 这类长串没有空格可断，
     不设这一条它们会一路撑出卡片、把整页顶出横向滚动条 */
  overflow-wrap: break-word;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 840px; margin: 0 auto; padding: 0 20px; }

.site-header { padding: 48px 0 28px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-link { display: inline-block; max-width: 100%; border-radius: 4px; }
.brand-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }
.brand-logo { display: block; width: 150px; max-width: 100%; height: auto; }
@media (prefers-color-scheme: dark) {
  .brand-logo { filter: invert(1); }
}
.tagline { margin: 10px 0 0; color: var(--muted); font-size: 15px; }

.step {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.step h2 { margin: 0 0 6px; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.step-no {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
}
.hint { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.hint strong { color: var(--text); }
.person-limit { color: var(--accent); font-size: 13px; }

.dropzone {
  display: grid; place-items: center; gap: 4px;
  padding: 32px 20px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: 12px;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 26px; color: var(--accent); line-height: 1; }
.dz-text { font-size: 15px; }
.dz-sub { font-size: 12px; color: var(--muted); }

.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.thumb { position: relative; width: 88px; height: 112px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  cursor: zoom-in;   /* 人物参考图也能点开看大图 */
}
.thumb .badge {
  position: absolute; left: 5px; top: 5px;
  background: rgba(0,0,0,.66); color: #fff; font-size: 10px;
  padding: 2px 6px; border-radius: 20px;
}
.thumb .rm {
  position: absolute; right: 4px; top: 4px; width: 20px; height: 20px;
  border: 0; border-radius: 50%; cursor: pointer; line-height: 1;
  background: rgba(0,0,0,.66); color: #fff; font-size: 14px;
}

.themes { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.theme-card {
  text-align: left; cursor: pointer; padding: 16px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: inherit; font: inherit;
  transition: border-color .15s, background .15s;
}
.theme-card:hover:not(:disabled) { border-color: var(--accent); }
.theme-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.theme-card:disabled { opacity: .5; cursor: not-allowed; }
.theme-name { display: block; font-size: 19px; font-weight: 600; }
.theme-meta { display: block; margin-top: 4px; font-size: 12.5px; color: var(--muted); }

.params {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px;
  margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line);
}
@media (max-width: 860px) { .params { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .params { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.param[hidden] { display: none; }

.param { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.param-label { font-size: 11.5px; color: var(--muted); letter-spacing: .03em; }
.param select {
  width: 100%; min-width: 0; text-overflow: ellipsis; padding: 7px 8px; font: inherit; font-size: 13.5px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.param select:focus { outline: none; border-color: var(--accent); }
.param-readout {
  padding: 7px 8px; font-size: 13.5px; color: var(--muted);
  background: var(--surface-2); border: 1px dashed var(--line); border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.cta {
  width: 100%; padding: 16px; font-size: 17px; font-weight: 600;
  color: #fff; background: var(--accent); border: 0; border-radius: 12px; cursor: pointer;
  transition: opacity .15s;
}
.cta:hover:not(:disabled) { opacity: .9; }
.cta:disabled { opacity: .4; cursor: not-allowed; }
.cta-note { margin: 10px 0 0; text-align: center; font-size: 13px; color: var(--muted); }

.cta-download {
  display: block; margin-top: 18px; text-align: center; text-decoration: none;
}
.cta-download[hidden] { display: none; }

.progress-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress-bar { flex: 1; height: 7px; border-radius: 20px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress-label { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.scene-list { list-style: none; margin: 0; padding: 0; }
/* 名称和状态一行；报错另起一行铺满，状态标签永远不会被长报错挤出卡片 */
.scene-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  column-gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px;
}
.scene-list li:first-child { border-top: 0; }
.scene-name { min-width: 0; color: var(--muted); }
.scene-error {
  grid-column: 1 / -1; margin: 6px 0 2px; padding: 8px 10px;
  border-radius: 8px; background: var(--surface-2); color: var(--err);
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
  /* 整段报错都留着，但框的高度有上限——超出的部分在框内滚动 */
  max-height: 8.5em; overflow-y: auto;
}
.state { font-size: 12.5px; padding: 3px 9px; border-radius: 20px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.state.running { background: var(--accent-soft); color: var(--accent); }
.state.done { background: transparent; color: var(--ok); }
.state.failed { background: transparent; color: var(--err); }
.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--accent); border-right-color: transparent;
  animation: spin .7s linear infinite; display: inline-block; vertical-align: -1px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gallery figure { margin: 0; cursor: zoom-in; }
.gallery img {
  width: 100%; aspect-ratio: 9 / 16; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line); display: block;
  transition: transform .15s;
}
.gallery figure:hover img { transform: translateY(-2px); }
.gallery figcaption { margin-top: 6px; font-size: 12px; color: var(--muted); }
.idscore {
  display: inline-block; margin-left: 2px; padding: 1px 6px;
  border-radius: 20px; font-size: 11px; white-space: nowrap;
}
.idscore-ok { background: rgba(63, 125, 88, .14); color: var(--ok); }
.idscore-bad { background: rgba(179, 64, 58, .14); color: var(--err); }
.idscore-na { background: var(--surface-2); color: var(--muted); }
/* 重做标记：中性偏警示，不抢相似度本身的红/绿 */
.idscore-retry { background: rgba(176, 124, 42, .16); color: #8a5f1c; }

.proc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.proc-item { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.proc-item dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.proc-item dd { margin: 3px 0 0; font-size: 14px; word-break: break-all; }

.proc-block { border-top: 1px solid var(--line); padding: 10px 0; }
.proc-block summary { cursor: pointer; font-size: 14.5px; font-weight: 600; padding: 4px 0; }
.proc-block ol, .proc-block ul { margin: 8px 0 4px; padding-left: 20px; font-size: 14px; color: var(--muted); }
.proc-block li { margin: 5px 0; }
.prompt-box {
  margin: 10px 0 0; padding: 14px; max-height: 380px; overflow: auto;
  background: var(--surface-2); border-radius: 10px;
  font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.record {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
  margin-top: 8px; font-size: 13px; overflow-wrap: anywhere;
}
.record b { font-weight: 600; }
.record .kv { color: var(--muted); }

.danger { text-align: center; background: transparent; border: 0; box-shadow: none; padding: 4px; }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 9px 18px; border-radius: 10px; cursor: pointer; font-size: 13.5px;
}
.ghost:hover { border-color: var(--err); color: var(--err); }

.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92);
  display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 40px 16px 16px;
}
.lightbox[hidden] { display: none; }
.lb-stage {
  display: grid; place-items: center; width: 100%; height: 100%;
  overflow: hidden; touch-action: pan-y;   /* 允许纵向滚动，横向留给划屏切换 */
}
.lightbox img {
  max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px;
  user-select: none; -webkit-user-drag: none;
  transition: transform .18s ease-out, opacity .18s ease-out;
}
.lightbox img.swiping { transition: none; }

.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .14); color: #fff;
  font-size: 26px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.lb-nav:hover { background: rgba(255, 255, 255, .26); }
.lb-nav:disabled { opacity: 0; pointer-events: none; }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }
/* 触屏设备靠划屏，不占画面 */
@media (hover: none) and (pointer: coarse) {
  .lb-nav { display: none; }
}

.lb-counter { color: rgba(255, 255, 255, .6); font-variant-numeric: tabular-nums; }
.lb-close {
  position: absolute; top: 10px; right: 14px; z-index: 2;
  background: transparent; border: 0; color: #fff; font-size: 34px; cursor: pointer; line-height: 1;
}
.lb-bar { display: flex; align-items: center; gap: 16px; color: #fff; font-size: 13px; padding: 12px 0 0; }
.lb-download { color: #fff; text-decoration: underline; }

.loading { color: var(--muted); font-size: 14px; margin: 0; }
.error-box {
  background: var(--accent-soft); color: var(--err); border-radius: 10px;
  padding: 12px 14px; font-size: 14px; margin-top: 12px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 11em; overflow-y: auto;
}

.site-footer { padding: 30px 0 50px; color: var(--muted); font-size: 12.5px; text-align: center; }


/* ---------- 批次记录页 ---------- */

.footer-link { color: var(--accent); text-decoration: none; }
.footer-link:hover { text-decoration: underline; }

.batch { padding-top: 18px; }
.batch-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.batch-title { margin: 0 0 4px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.batch-meta { font-size: 12px; color: var(--muted); }
.batch-meta code { font-size: 11.5px; }
.batch-status { font-size: 11.5px; padding: 2px 8px; border-radius: 20px; font-weight: 400; }
.batch-done { background: rgba(63,125,88,.14); color: var(--ok); }
.batch-partial { background: var(--accent-soft); color: var(--accent); }
.batch-failed { background: rgba(179,64,58,.14); color: var(--err); }
.batch-running, .batch-queued { background: var(--surface-2); color: var(--muted); }

.hist-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13.5px; }
.hist-table th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.hist-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.hist-table tr:last-child td { border-bottom: 0; }
.hist-table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-thumb {
  width: 40px; height: 60px; object-fit: cover; display: block;
  border-radius: 6px; border: 1px solid var(--line);
}
.hist-err {
  color: var(--err); font-size: 12px; margin-top: 2px;
  overflow-wrap: anywhere; max-height: 7em; overflow-y: auto;
}
.hist-table .kv { font-size: 11.5px; }

/* 批次指标：一行四个数字，紧凑 */
.batch-metrics {
  display: flex; flex-wrap: wrap; gap: 8px 22px;
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface-2); border-radius: 10px;
}
.metric { display: flex; align-items: baseline; gap: 5px; }
.metric b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric small { font-size: 11.5px; color: var(--muted); }

/* 参数：压成一行小字，超出自动换行 */
.batch-params {
  display: flex; flex-wrap: wrap; gap: 4px 14px;
  font-size: 12px; color: var(--text); margin-bottom: 12px; line-height: 1.7;
}
.batch-params span { white-space: nowrap; }
.batch-params i {
  font-style: normal; color: var(--muted); margin-right: 4px;
  font-size: 11px; letter-spacing: .02em;
}
.scene-state {
  margin-left: 6px; padding: 1px 6px; border-radius: 20px;
  font-size: 11px; background: var(--surface-2); color: var(--muted);
}
/* 窄屏下表格横向滚动，不把页面撑破 */
.hist-scroll { overflow-x: auto; }
.hist-table { min-width: 520px; }

/* 主题选择和操作按钮彼此独立，窄屏仍可点击。 */
.theme-card { position: relative; padding: 0; }
.theme-select { border: 0; background: transparent; color: inherit; font: inherit; text-align: left; width: 100%; padding: 18px 46px 18px 18px; cursor: pointer; }
.theme-select:disabled { opacity: .5; cursor: not-allowed; }
.theme-menu { position: absolute; right: 6px; top: 10px; }
.theme-menu summary { list-style: none; cursor: pointer; font-size: 24px; padding: 0 9px; border-radius: 6px; }
.theme-menu summary::-webkit-details-marker { display: none; }
.theme-actions { position: absolute; right: 0; top: 34px; z-index: 10; min-width: 120px; background: var(--bg, #fff); border: 1px solid var(--border, #ddd); border-radius: 8px; box-shadow: 0 4px 16px #0002; padding: 4px; }
.theme-actions button { display: block; width: 100%; border: 0; background: transparent; color: inherit; text-align: left; padding: 10px; cursor: pointer; font: inherit; }
.theme-actions button:hover { background: var(--accent-soft); }
.theme-add { min-height: 82px; padding: 18px; border-style: dashed; }

/* ---------- 人物卡 ---------- */

.identities { margin-top: 14px; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); }
/* 整张卡都能选中这个人物，所以整张卡都要有可点的手感。
   以前只有顶部标题条可点，卡片却整体 hover 高亮——用户以为点过了。 */
.identity-card { min-width: 0; cursor: pointer; align-self: start; }
.identity-card .theme-select { padding-bottom: 10px; }
.theme-name { overflow-wrap: anywhere; }

.step-status {
  margin-left: auto; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 400; letter-spacing: 0;
  background: var(--surface-2); color: var(--muted);
}
.step-status.chosen { background: var(--accent-soft); color: var(--accent); }

.identity-photos { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 12px; }
.identity-photo-cell { position: relative; }
.identity-preview {
  display: block; position: relative; width: 74px; height: 94px;
  padding: 0; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; cursor: zoom-in; background: var(--surface-2);
}
.identity-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.identity-role {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 2px 4px;
  background: linear-gradient(transparent, #000a 40%); color: #fff;
  font-size: 10px; line-height: 1.4; text-align: center;
}
/* 每张照片的「改角色 / 替换 / 删除」收在这一个按钮后面 */
.photo-menu { position: absolute; top: 3px; right: 3px; }
.photo-menu > summary {
  list-style: none; display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 6px;
  background: #000000a6; color: #fff; font-size: 15px; line-height: 1; cursor: pointer;
}
.photo-menu > summary::-webkit-details-marker { display: none; }
.photo-menu > summary:hover { background: #000000d9; }
.photo-menu .theme-actions { top: 26px; }

/* 照片菜单一屏要放下 5 个角色 + 2 个操作，所以比主题菜单更紧凑 */
.identity-menu .theme-actions { min-width: 112px; padding: 5px; }
.identity-menu .theme-actions button { padding: 6px 9px; font-size: 13px; border-radius: 6px; }
.menu-heading {
  margin: 4px 0 2px; padding: 0 9px;
  font-size: 10.5px; letter-spacing: .04em; color: var(--muted);
}
.menu-heading + .menu-heading, .theme-actions button + .menu-heading {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line);
}
.theme-actions .menu-check.is-current::before { content: '✓ '; color: var(--accent); }
.theme-actions .menu-check.is-current { color: var(--accent); opacity: 1; }
.theme-actions .menu-danger:hover:not(:disabled) { color: var(--err); }

.identity-upload-menu { position: relative; }
.identity-upload-menu > summary { list-style: none; padding: 10px 14px; cursor: pointer; font-size: 13px; }
.identity-upload-menu > summary::-webkit-details-marker { display: none; }
.identity-upload-menu .theme-actions { left: 0; right: auto; top: 100%; }
/* 「补充照片」是照片条下方一条通栏虚线按钮：不论有几张照片，
   它都占满一行，不会在最后一行留下一块空白的大方块。 */
.identity-photo-add { flex: 1 0 100%; }
.identity-photo-add > summary {
  display: grid; place-items: center; width: 100%; height: 34px; padding: 0;
  border: 1.5px dashed var(--line); border-radius: 8px;
  color: var(--muted); font-size: 12.5px;
}
.identity-photo-add > summary:hover { border-color: var(--accent); color: var(--accent); }
.identity-evidence { border-top: 1px solid var(--line); margin: 0 14px; padding: 8px 0 10px; }
.identity-add { min-height: 82px; border-style: dashed; align-self: start; }
.identity-add > summary { min-height: 82px; display: flex; align-items: center; padding: 18px; font-size: 16px; }
.theme-actions { background: var(--surface); border-color: var(--line); }
.theme-actions button:disabled { opacity: .5; cursor: not-allowed; }
.identity-upload-menu > summary:disabled { cursor: wait; }

.prompt-toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin: 12px 0; }
.prompt-toolbar .param { width: 210px; max-width: 100%; }
.prompt-toolbar #prompt-scene-wrap { width: 100px; }
.prompt-toolbar .ghost { padding: 7px 10px; font-size: 13px; }
.prompt-editor { display: block; width: 100%; height: 216px; min-height: 140px; max-height: 360px; resize: vertical; overflow-y: scroll; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }
.prompt-editor:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.prompt-status { margin: 8px 0 0; font-size: 12px; }
.prompt-editor { scrollbar-gutter: stable; }
.prompt-editor::-webkit-scrollbar { width: 9px; }
.prompt-editor::-webkit-scrollbar-track { background: var(--surface-2); border-radius: 8px; }
.prompt-editor::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--surface-2); border-radius: 8px; }

.identity-evidence { font-size:11px; line-height:1.8; color:var(--muted); }
.clothing-description { flex:1; min-width:160px; }
.clothing-description input { padding:8px; width:100%; }
