/* ==========================================================
   PoseForge — 暗房工作台
   深炭底 + 琥珀色强调 + 衬线标题 + 细线分隔 + 胶片颗粒
   主题：:root 为暗色；[data-theme="light"] 覆盖为明亮色
   ========================================================== */
:root {
  color-scheme: dark;

  --ink: #08080a;
  --bg: #0b0b0d;
  --panel: #111114;
  --panel-2: #17171c;
  --panel-3: #1e1e24;
  --line: #26262d;
  --line-strong: #34343d;
  --text: #ecebe7;
  --muted: #8b8781;
  --dim: #615d58;
  --accent: #e6a03c;
  --accent-hover: #f0ae4f;
  --accent-soft: rgba(230, 160, 60, .14);
  --accent-ink: #1a1206;
  --ok: #78b98a;
  --ok-soft: rgba(120, 185, 138, .07);
  --ok-line: rgba(120, 185, 138, .5);
  --err: #e2705f;
  --err-soft: rgba(226, 112, 95, .07);
  --err-line: rgba(226, 112, 95, .5);

  /* 结构色：主题切换时这些也要跟着换 */
  --glow-accent: rgba(230, 160, 60, .07);
  --glow-cool: rgba(120, 150, 190, .05);
  --topbar-bg: linear-gradient(180deg, rgba(23, 23, 28, .9), rgba(11, 11, 13, .6));
  --panel-grad: linear-gradient(180deg, var(--panel), #0e0e11);
  --shadow-color: #000;
  --plate: #f4f2ee;
  --media-bg: #0b0b0e;
  --stage-bg: #0a0a0c;
  --stage-glow: rgba(255, 255, 255, .045);
  --stage-grid: rgba(255, 255, 255, .028);
  --stage-vignette: inset 0 0 70px 18px rgba(0, 0, 0, .55);
  --dropzone-bg: rgba(23, 23, 28, .55);
  --tint: rgba(255, 255, 255, .02);
  --overlay: rgba(8, 8, 10, .55);
  --overlay-strong: rgba(8, 8, 10, .8);
  --overlay-ink: #ffffff;
  --badge-bg: rgba(8, 8, 10, .72);
  --badge-text: #efece6;
  --badge-border: rgba(255, 255, 255, .1);
  --scrim: rgba(4, 4, 6, .82);
  --scroll-thumb: #2b2b33;
  --scroll-thumb-hover: #3b3b45;
  --grain-opacity: .035;

  --radius: 14px;
  --radius-sm: 9px;
  --mono: "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
  --serif: "Optima", "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

/* ---------- 明亮主题：日光相纸 ---------- */
:root[data-theme="light"] {
  color-scheme: light;

  --ink: #fffefb;
  --bg: #f4f2ec;
  --panel: #fffefb;
  --panel-2: #f7f4ee;
  --panel-3: #ede9e0;
  --line: #e2ddd2;
  --line-strong: #cec7b8;
  --text: #24211c;
  --muted: #6b655b;
  --dim: #9a9387;
  --accent: #b0741a;
  --accent-hover: #c9861f;
  --accent-soft: rgba(176, 116, 26, .12);
  --accent-ink: #fffaf0;
  --ok: #3d7f4f;
  --ok-soft: rgba(61, 127, 79, .1);
  --ok-line: rgba(61, 127, 79, .38);
  --err: #bf4b36;
  --err-soft: rgba(191, 75, 54, .09);
  --err-line: rgba(191, 75, 54, .38);

  --glow-accent: rgba(176, 116, 26, .1);
  --glow-cool: rgba(120, 150, 190, .12);
  --topbar-bg: linear-gradient(180deg, rgba(255, 254, 251, .92), rgba(244, 242, 236, .78));
  --panel-grad: linear-gradient(180deg, var(--panel), #faf7f0);
  --shadow-color: rgba(72, 56, 30, .22);
  --plate: #fbf9f3;
  --media-bg: #ece8df;
  --stage-bg: #eeeae1;
  --stage-glow: rgba(255, 255, 255, .7);
  --stage-grid: rgba(36, 33, 28, .055);
  --stage-vignette: inset 0 0 70px 18px rgba(120, 102, 72, .12);
  --dropzone-bg: rgba(247, 244, 238, .92);
  --tint: rgba(36, 33, 28, .03);
  --overlay: rgba(255, 254, 251, .62);
  --overlay-strong: rgba(255, 254, 251, .92);
  --overlay-ink: #24211c;
  --badge-bg: rgba(255, 254, 251, .9);
  --badge-text: #4a443a;
  --badge-border: rgba(36, 33, 28, .14);
  --scrim: rgba(58, 47, 30, .45);
  --scroll-thumb: #d3ccbe;
  --scroll-thumb-hover: #b9b1a1;
  --grain-opacity: .02;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 620px at 8% -10%, var(--glow-accent), transparent 62%),
    radial-gradient(900px 520px at 100% 0%, var(--glow-cool), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

/* 颗粒 / 胶片质感 */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 999; opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/></filter><rect width='120' height='120' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(6px);
}
.brand {
  font-family: var(--serif); font-size: 21px; font-weight: 600;
  letter-spacing: .06em; color: var(--text);
}
.brand span { color: var(--accent); }
.sub {
  font-size: 10px; color: var(--dim); letter-spacing: .16em;
  padding-left: 14px; border-left: 1px solid var(--line);
}
.top-actions {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto;
}

/* ---------------- 三栏 ---------------- */
.layout {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 384px;
  gap: 14px; padding: 14px 18px 18px;
}
.panel {
  background: var(--panel-grad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
  box-shadow: 0 18px 40px -32px var(--shadow-color);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: 14px; letter-spacing: .1em; color: var(--text);
}
.count {
  font-family: var(--mono); font-size: 10px; color: var(--dim);
  letter-spacing: .06em;
}
.hint { font-size: 10px; color: var(--dim); letter-spacing: .04em; }

/* ---------------- 姿势库 ---------------- */
.filters {
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.search {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 11px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--accent); background: var(--panel-3); }
.search svg {
  width: 15px; height: 15px; flex: none;
  fill: none; stroke: var(--dim); stroke-width: 1.8; stroke-linecap: round;
}
.search input {
  flex: 1; min-width: 0; border: none; outline: none; background: none;
  color: var(--text); font: inherit; font-size: 14px;
}
.search input::placeholder { color: var(--dim); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
/* 二级筛选：左侧小标签 + 横向滚动胶囊 */
.filter-row {
  display: grid; grid-template-columns: 26px minmax(0, 1fr);
  gap: 6px; align-items: start;
}
.filter-tag {
  font-family: var(--mono); font-size: 14px; letter-spacing: .08em;
  color: var(--dim); padding-top: 8px; white-space: nowrap;
}
.filter-row .chips { padding-bottom: 2px; touch-action: pan-x; }
/* 横向可滚动时右侧留一点渐隐提示 */
.filter-row { position: relative; }

.chips {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 3px;
  scrollbar-width: none;
  cursor: grab; user-select: none;
}
.chips.dragging { cursor: grabbing; }
.chips.dragging .chip { pointer-events: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent;
  color: var(--muted); font: inherit; font-size: 14px;
  letter-spacing: .04em; cursor: pointer;
  transition: .15s;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip.active {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent);
}

.pose-grid {
  flex: 1; min-height: 0; overflow-y: auto; padding: 14px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  /* auto 行高会与图片 aspect-ratio + 百分比宽度形成循环依赖导致塌陷 */
  grid-auto-rows: max-content;
  gap: 12px; align-content: start;
}
.pose-card {
  position: relative; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2); overflow: hidden;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  animation: rise .34s cubic-bezier(.2, .7, .3, 1) both;
}
.pose-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: 0 16px 26px -20px var(--shadow-color);
}
.pose-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 18px 30px -24px var(--shadow-color);
}
.pose-card.active::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, var(--accent-soft), transparent 42%);
}
.pose-card img {
  display: block; width: 100%; aspect-ratio: 3 / 4;
  object-fit: contain; background: var(--plate);
}
.pose-card .cap {
  padding: 7px 9px 8px; font-size: 14px; color: var(--muted);
  line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-top: 1px solid var(--line);
}
.pose-card.active .cap { color: var(--text); }
.pose-card .angle-badge {
  position: absolute; top: 7px; right: 7px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .08em;
  padding: 2px 6px; border-radius: 5px;
  background: var(--badge-bg); color: var(--badge-text);
  border: 1px solid var(--badge-border);
  backdrop-filter: blur(4px);
}

/* ---------------- 工作台 ---------------- */
.stage-panel { padding: 0; overflow: hidden; }
.stage-panel .panel-head { background: var(--panel); padding: 13px 16px; }
.stage-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 14px; }

.stage {
  position: relative; margin-top: 16px;
  flex: none; /* 防止被 flex 压缩塌陷 */
  height: clamp(250px, 42vh, 440px);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
  background-color: var(--stage-bg);
  background-image:
    radial-gradient(75% 60% at 50% 42%, var(--stage-glow), transparent 72%),
    linear-gradient(0deg, var(--stage-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px);
  background-size: 100% 100%, 28px 28px, 28px 28px;
  overflow: hidden;
}
.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: var(--stage-vignette);
}
.stage-img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: 6px;
  box-shadow: 0 24px 44px -26px var(--shadow-color);
  animation: fade .32s ease both;
}
.placeholder { text-align: center; color: var(--muted); position: relative; z-index: 1; }
.ph-mark {
  width: 46px; height: 46px; margin: 0 auto 12px;
  display: grid; place-items: center; border-radius: 50%;
  border: 1px dashed var(--line-strong); color: var(--accent);
  font-size: 22px; line-height: 1;
}
.placeholder p { margin: 0; font-family: var(--serif); font-size: 14px; letter-spacing: .06em; color: var(--text); }
.ph-sub { display: block; margin-top: 6px; font-size: 10px; color: var(--dim); }

.slot-meta {
  position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 24px);
  font-family: var(--mono); font-size: 10px; letter-spacing: .05em;
  color: var(--badge-text); background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  padding: 4px 9px; border-radius: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(4px); z-index: 2;
}

/* 角度分段控件 */
.angle-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
  margin-top: 14px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2);
}
.angle-label {
  flex: none; white-space: nowrap;
  font-family: var(--mono); font-size: 10px; letter-spacing: .16em;
  color: var(--dim); text-transform: uppercase; padding-left: 4px;
}
.angle-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.angle-tab {
  padding: 5px 11px; border-radius: 999px; border: 1px solid transparent;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 14px; letter-spacing: .04em; cursor: pointer;
  transition: .15s;
}
.angle-tab:hover { color: var(--text); background: var(--panel-3); }
.angle-tab.active {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 600;
}

/* 参考图：姿势（图1） + 人物（图2）并排 */
.ref-row {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 14px; margin-top: 16px;
  align-items: stretch;
}
.ref-slot { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ref-slot .stage { margin-top: 0; height: clamp(230px, 34vh, 360px); flex: none; min-height: 200px; }
.ref-slot .angle-bar { margin-top: 2px; }

.block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.prompt-block { margin-top: 14px; }
.block-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: 10px; color: var(--muted); letter-spacing: .08em;
}
.dropzone {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  justify-content: center; align-items: flex-start;
  padding: 14px; min-height: 108px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
  background: var(--dropzone-bg);
  transition: .15s;
}
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }

/* 服装 / 场景：并排的紧凑槽位 */
.aux-row {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px; margin-top: 14px;
}
.role-zone { align-items: stretch; justify-content: center; }
.role-zone.compact { min-height: 118px; justify-content: center; }
.role-zone .btn { align-self: flex-start; }
.role-zone.filled { border-style: solid; border-color: var(--line-strong); }
.role-preview {
  position: relative; width: 100%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
/* 悬停提示可点击更换 / 可拖入新图 */
.role-preview::after {
  content: "点击更换 · 也可拖入新图";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
  color: var(--accent); text-align: center; padding: 0 6px;
  background: var(--overlay); border-radius: 6px;
  opacity: 0; transition: opacity .15s; pointer-events: none;
}
.role-preview:hover::after { opacity: 1; }
.role-zone.dragover .role-preview::after { content: "松手替换"; opacity: 1; }
.role-preview img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 6px; box-shadow: 0 14px 26px -20px var(--shadow-color);
}
.role-zone:not(.compact) .role-preview img { max-height: 300px; }
.role-zone.compact .role-preview img { max-height: 104px; }

.req {
  font-style: normal; font-size: 10px; letter-spacing: .08em;
  color: var(--accent); border: 1px solid var(--accent-soft);
  background: var(--accent-soft); border-radius: 5px;
  padding: 1px 5px; margin-left: 4px; vertical-align: 1px;
}
.hint.dim { color: var(--dim); }

/* 风格化 */
.style-block { margin-top: 16px; }
.style-groups { display: flex; flex-direction: column; gap: 8px; }
.style-row {
  display: grid; grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px; align-items: start;
}
.style-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
  color: var(--dim); padding-top: 6px; white-space: nowrap;
}
/* 主控组：整体风格表现 */
.style-row.primary {
  grid-template-columns: 92px minmax(0, 1fr);
  padding: 8px 10px 9px;
  border: 1px solid var(--line); border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm); background: var(--tint);
}
.style-row.primary .style-label {
  padding-top: 4px; white-space: normal; line-height: 1.45; color: var(--text);
}
.style-flag {
  display: inline-block; margin-left: 4px; padding: 0 4px;
  font-family: var(--mono); font-style: normal; font-size: 10px;
  letter-spacing: .04em; color: var(--accent);
  border: 1px solid var(--accent-soft); background: var(--accent-soft);
  border-radius: 4px; vertical-align: 1px;
}
.chips.wrap { flex-wrap: wrap; overflow: visible; gap: 6px; }
.chips.wrap .chip { font-size: 14px; padding: 4px 9px; }
.chips.wrap .chip.more {
  border-style: dashed; color: var(--dim); background: transparent;
}
.chips.wrap .chip.more:hover { color: var(--accent); border-color: var(--accent); }
.thumb {
  position: relative; width: 60px; height: 60px;
  border-radius: 7px; overflow: hidden; border: 1px solid var(--line-strong);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .del {
  position: absolute; top: 2px; right: 2px; width: 17px; height: 17px;
  border-radius: 50%; border: none; cursor: pointer; line-height: 1;
  background: var(--overlay-strong); color: var(--overlay-ink); font-size: 14px;
}
.thumb .del:hover { background: var(--err); color: #fff; }

#promptInput {
  flex: 1; width: 100%; min-height: 108px; resize: vertical;
  padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font: inherit; font-size: 14px; line-height: 1.6;
  outline: none; transition: border-color .15s;
}
#promptInput:focus { border-color: var(--accent); }
#promptInput::placeholder { color: var(--dim); }

/* 最终提示词预览（可编辑） */
.final-block { margin-top: 10px; }
.final-block .block-head { align-items: center; }
.hint.inline {
  display: inline-block; margin-left: 8px; padding: 1px 6px;
  font-style: normal; font-size: 10px; letter-spacing: .08em;
  border: 1px solid var(--line); border-radius: 4px;
  color: var(--dim); background: var(--panel-2);
}
.hint.inline.dirty {
  color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft);
}
#finalPrompt {
  width: 100%; min-height: 118px; resize: vertical;
  padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px dashed var(--line-strong); background: var(--tint);
  color: var(--muted); font-family: var(--mono); font-size: 14px; line-height: 1.7;
  outline: none; transition: border-color .15s, color .15s, background .15s;
}
#finalPrompt:focus {
  border-style: solid; border-color: var(--accent);
  color: var(--text); background: var(--panel-2);
}
#finalPrompt::placeholder { color: var(--dim); }

/* 底部操作条：固定在面板底部，不随内容滚动 */
.actionbar {
  flex: none;
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px 12px;
  padding: 12px 16px; border-top: 1px solid var(--line);
  background: var(--panel);
}
.mini-field select#modelInput { width: 186px; }
.mini-field { display: flex; flex-direction: column; gap: 5px; }
.mini-field > span {
  font-family: var(--mono); font-size: 10px; letter-spacing: .14em;
  color: var(--dim); text-transform: uppercase; padding-left: 2px;
}
.mini-field input, .mini-field select {
  width: 96px; padding: 9px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.mini-field select { width: 86px; }
.mini-field input:focus, .mini-field select:focus { border-color: var(--accent); }
.px-tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: .06em;
  color: var(--dim); padding-bottom: 11px; white-space: nowrap;
}
.actionbar .btn.primary.big { margin-left: auto; flex: none; }

/* ---------------- 按钮 ---------------- */
.btn {
  border: 1px solid var(--line-strong); background: var(--panel-2);
  color: var(--text); padding: 9px 15px; border-radius: var(--radius-sm);
  cursor: pointer; font: inherit; font-size: 14px; letter-spacing: .04em;
  transition: .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn.primary:disabled { opacity: .45; cursor: progress; }
.btn.ghost { background: transparent; }
.btn.big { flex: 1; padding: 12px 20px; font-size: 14px; letter-spacing: .12em; }

.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 14px;
  letter-spacing: .06em; transition: color .15s;
}
.link-btn:hover { color: var(--accent); }

/* ---------------- 状态 ---------------- */
.status {
  margin-top: 12px; padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 10px; letter-spacing: .03em;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.status.ok { border-color: var(--ok-line); color: var(--ok); background: var(--ok-soft); }
.status.err { border-color: var(--err-line); color: var(--err); background: var(--err-soft); }

/* ---------------- 结果 ---------------- */
.result-grid {
  flex: 1; min-height: 0; overflow-y: auto; padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  /* 关键：auto 行在固定高度的滚动容器里会被压扁，必须用 max-content */
  grid-auto-rows: max-content;
  align-content: start; align-items: start;
  gap: 10px;
}
.result-item {
  position: relative; display: flex; flex-direction: column;
  border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--line); background: var(--panel-2);
  cursor: pointer;
  animation: rise .34s cubic-bezier(.2, .7, .3, 1) both;
}
/* 正方形缩略图 + contain：任何比例都能完整显示，不裁切 */
.result-item img {
  display: block; width: 100%; height: auto;
  aspect-ratio: 1 / 1; object-fit: contain;
  background: var(--media-bg);
}
.result-item:hover { border-color: var(--line-strong); }
.result-caption {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 8px 7px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 10px; letter-spacing: .04em;
  color: var(--dim); background: var(--panel);
}
.cap-model {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted);
}
.cap-time { flex: none; }
.result-hover {
  position: absolute; inset: 0 0 auto 0; height: calc(100% - 25px);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10px; letter-spacing: .16em;
  color: var(--accent); text-transform: uppercase;
  background: var(--overlay);
  opacity: 0; transition: opacity .18s;
}
.result-item:hover .result-hover { opacity: 1; }

.head-tools { display: flex; align-items: center; gap: 10px; }

/* ---------------- 结果详情模态框 ---------------- */
body.modal-open { overflow: hidden; }
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fade .16s ease both;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(3px);
}
.modal-card {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .85fr);
  grid-template-rows: minmax(0, 1fr);   /* 行高锁定在容器内：内容过高时右侧信息区内部滚动，而不是撑破卡片 */
  width: min(1180px, 100%); max-height: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--panel); overflow: hidden;
  box-shadow: 0 40px 90px -40px var(--shadow-color);
  animation: rise .2s cubic-bezier(.2, .7, .3, 1) both;
}
.modal-media {
  display: flex; align-items: center; justify-content: center;
  min-height: 0; padding: 16px; background: var(--bg);
  overflow: hidden;
}
.modal-media img {
  max-width: 100%; max-height: calc(100vh - 130px);
  object-fit: contain; border-radius: var(--radius-sm);
}
.modal-info {
  display: flex; flex-direction: column; min-height: 0;
  padding: 16px 18px 18px; gap: 12px;
  border-left: 1px solid var(--line); overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 {
  margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
}
.icon-btn {
  width: 28px; height: 28px; line-height: 1; font-size: 18px;
  border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }

.meta-list {
  display: grid; grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 12px; margin: 0; font-size: 14px;
}
.meta-list dt {
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
  color: var(--dim); padding-top: 2px; white-space: nowrap;
}
.meta-list dd { margin: 0; color: var(--text); word-break: break-word; }

.meta-block { display: flex; flex-direction: column; gap: 6px; }
.meta-block.grow { flex: 0 0 auto; }   /* 提示词保持自然高度，信息区整体滚动 */
.meta-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em;
  color: var(--dim); text-transform: uppercase;
}
.meta-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb-fig {
  margin: 0; width: 74px; border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden; background: var(--panel-2);
}
.thumb-fig img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.thumb-fig figcaption {
  padding: 3px 5px; font-family: var(--mono); font-size: 10px;
  color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta-prompt {
  margin: 0; padding: 9px 10px; max-height: 160px; overflow: auto;
  font-family: var(--mono); font-size: 14px; line-height: 1.6;
  color: var(--muted); white-space: pre-wrap; word-break: break-word;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.modal-actions {
  display: flex; gap: 8px;
  position: sticky; bottom: 0;             /* 信息区滚动时按钮始终可见 */
  padding: 10px 0 2px; margin-top: auto;
  background: var(--panel);
}
.modal-actions .btn { flex: 1; text-align: center; text-decoration: none; }
/* 超长提示词最多占 1/3 屏，内部滚动，把空间留给其他信息 */
.meta-block.grow .meta-prompt { max-height: 30vh; overflow-y: auto; }

@media (max-width: 900px) {
  .modal { padding: 12px; }
  .modal-card { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .modal-media img { max-height: 46vh; }
  .modal-info { border-left: none; border-top: 1px solid var(--line); max-height: 48vh; }
}

.empty {
  grid-column: 1 / -1;
  color: var(--dim); font-size: 10px; letter-spacing: .08em;
  text-align: center; padding: 34px 0;
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
}

/* ---------------- 生成记录页 ---------------- */
.history-main {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 18px 18px;
}
.history-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-title { display: flex; align-items: baseline; gap: 10px; }
.history-title h2 {
  margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
}
.history-grid {
  flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr));
  gap: 14px; align-content: start;
}
.history-card {
  position: relative; overflow: hidden; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2);
  animation: rise .34s cubic-bezier(.2, .7, .3, 1) both;
  transition: border-color .15s, transform .15s;
}
.history-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.hc-media { position: relative; aspect-ratio: 1 / 1; background: var(--media-bg); }
.hc-media img { display: block; width: 100%; height: 100%; object-fit: contain; }
.hc-failed {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10px; letter-spacing: .12em;
  color: var(--err); background: var(--err-soft);
}
.hc-badge {
  position: absolute; top: 8px; right: 8px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .04em;
  padding: 2px 6px; border-radius: 4px;
  background: var(--badge-bg); border: 1px solid var(--line-strong); color: var(--muted);
}
.hc-body {
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 10px 9px; border-top: 1px solid var(--line); background: var(--panel);
}
.hc-model {
  font-size: 14px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hc-sub { font-family: var(--mono); font-size: 10px; letter-spacing: .04em; color: var(--dim); }
.history-card.is-error .hc-model { color: var(--err); }
.hc-del {
  position: absolute; top: 6px; left: 6px; width: 22px; height: 22px;
  border-radius: 5px; border: 1px solid var(--line-strong);
  background: var(--badge-bg); color: var(--muted);
  font-size: 14px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.history-card:hover .hc-del { opacity: 1; }
.hc-del:hover { color: var(--err); border-color: var(--err-line); }

/* 多图记录：媒体区纵向排布 + 缩略图切换 */
.modal-media { flex-direction: column; gap: 10px; }
.detail-thumbs {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  max-width: 100%;
}
.detail-thumb {
  padding: 0; width: 54px; height: 54px; overflow: hidden; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); opacity: .62;
  transition: opacity .15s, border-color .15s;
}
.detail-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.detail-thumb.active { opacity: 1; border-color: var(--accent); }

.err-text { color: var(--err); border-color: var(--err-line); }
.link-btn.danger:hover { color: var(--err); }
.btn.ghost.danger { color: var(--err); border-color: var(--err-line); }
.btn.ghost.danger:hover { border-color: var(--err); }

@media (max-width: 820px) {
  .history-main { padding: 10px; }
  .history-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}

/* ---------------- 动效 ---------------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------- 滚动条 ---------------- */
::-webkit-scrollbar { width: 9px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1320px) {
  .layout { grid-template-columns: 310px minmax(0, 1fr) 340px; gap: 12px; }
  .ref-row { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 10px; }
}
@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    overflow-y: auto;
  }
  .result-panel { grid-column: 1 / -1; max-height: 380px; }
  .result-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (max-width: 820px) {
  .topbar { padding: 12px 14px; }
  .sub { display: none; }
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .poses-panel { max-height: 420px; }
  .result-panel { max-height: 340px; }
  .ref-row { grid-template-columns: 1fr; }
  .ref-slot .stage { height: 240px; flex: none; }
  .dropzone { min-height: 120px; }
}
