/* ============ 蝶 · 资产库 交互层样式 ============ */
#lib-root { min-height: 300px; }
.lib-loading { color: var(--mut); padding: 40px 0; text-align: center; letter-spacing: .12em; }

/* ---------- 通用 ---------- */
.lib-sec { margin-bottom: 34px; }
.lib-sec > h2 {
  font-family: "Songti SC","STSong","SimSun",serif; font-size: 18px; letter-spacing: .08em;
  display: flex; align-items: center; gap: 10px; padding-bottom: 10px; margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.lib-sec > h2 i { width: 10px; height: 10px; border-radius: 50%; background: var(--m); flex: 0 0 auto; }
.lib-sec > h2 .n { font-family: ui-monospace,"Cascadia Mono",Consolas,monospace; font-size: 11.5px;
  color: var(--mut); letter-spacing: .08em; font-weight: 400; }
button.lib-btn, a.lib-btn {
  border: 1px solid var(--line); background: #f4f0e8; color: #5a5247; font-size: 12.5px;
  padding: 6px 14px; border-radius: 7px; cursor: pointer; text-decoration: none; display: inline-block;
}
button.lib-btn:hover, a.lib-btn:hover { background: #eae4d7; color: var(--ink); }
button.lib-btn.primary { background: #e9e0d2; border-color: #cdbfa5; }

/* ---------- 首页网格 ---------- */
.lib-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 16px; align-items: start;
}
a.lib-card {
  display: block; text-decoration: none; color: inherit;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  padding: 10px; text-align: center; transition: transform .15s, box-shadow .15s;
}
a.lib-card:hover { transform: translateY(-3px); box-shadow: 0 10px 22px rgba(43,36,51,.13); }
.lib-card .thumb {
  position: relative; width: 100%; aspect-ratio: 1; overflow: hidden;
  border-radius: 9px; background: #f1ede4; border: 1px solid var(--line); margin-bottom: 9px;
}
.lib-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-card .thumb .av-empty {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #9a9488; font-size: 11.5px; letter-spacing: .12em; gap: 6px;
  background: repeating-linear-gradient(45deg,#faf8f3,#faf8f3 6px,#f4f1ea 6px,#f4f1ea 12px);
}
.lib-card .thumb .av-empty svg { width: 34px; height: 26px; color: #b3ab9c; }
.lib-card h3 { font-family: "Songti SC","STSong",serif; font-size: 15.5px; letter-spacing: .04em; margin: 2px 0 4px; }
.lib-card .cnt { font-family: ui-monospace,Consolas,monospace; font-size: 11px; color: var(--mut); }
.lib-card .cat { display: inline-block; font-size: 11px; color: #6a6154; background: #f1ede4;
  border: 1px solid var(--line); padding: 2px 8px; border-radius: 999px; margin-top: 6px; }

/* ---------- 详情页 ---------- */
.lib-back { margin-bottom: 14px; display: inline-flex; align-items: center; gap: 6px; }
.dhead { display: flex; align-items: center; gap: 18px; padding: 6px 0 18px; margin-bottom: 20px;
  border-bottom: 1px solid var(--line); }
.dhead .dav { width: 96px; height: 96px; border-radius: 12px; overflow: hidden; flex: 0 0 auto;
  border: 1px solid var(--line); background: #f1ede4; }
.dhead .dav img { width: 100%; height: 100%; object-fit: cover; }
.dhead h2 { font-family: "Songti SC","STSong",serif; font-size: 24px; letter-spacing: .08em; }
.dhead p { color: var(--mut); font-size: 12.5px; margin-top: 5px; }
.dhead .tag-sel {
  border: 1px solid var(--line); border-radius: 6px; background: #fbfaf6; color: var(--ink);
  font-size: 12px; padding: 3px 9px; margin-left: 8px; font-family: inherit;
}
.basic-gen { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.basic-gen .tip { font-size: 11.5px; color: var(--mut); }
.dsec { margin-bottom: 30px; }
.dsec > h3 { font-size: 14.5px; font-weight: 700; color: #4b3a7d; display: flex; align-items: center;
  gap: 10px; margin-bottom: 12px; }
.dsec > h3 .tip { font-weight: 400; font-size: 11.5px; color: var(--mut); }
.dsec > h3 .add-btn { margin-left: auto; }
.img-grid { display: flex; flex-wrap: wrap; gap: 14px; }
figure.spec { position: relative; }
figure.spec .crop-btn {
  position: absolute; left: 8px; bottom: 6px; border: none; background: rgba(30,25,40,.72); color: #fff;
  font-size: 11.5px; padding: 4px 9px; border-radius: 6px; cursor: pointer; opacity: 0;
  transition: opacity .15s;
}
figure.spec:hover .crop-btn { opacity: 1; }
figure.spec .crop-btn:hover { background: rgba(108,74,158,.9); }

/* ---------- 条目瓦片（缩略图 + 标题，点开进详情弹层） ---------- */
.entry-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.entry-tile {
  position: relative; border: 1px solid var(--line); border-left: 3px solid var(--m);
  border-radius: 10px; background: #fff; padding: 8px; cursor: pointer; text-align: left;
  transition: transform .14s, box-shadow .14s; outline-offset: 2px;
}
.entry-tile:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(43,36,51,.12); }
.entry-tile:focus-visible { outline: 2px solid var(--gold); }
.entry-tile.ct-costume { border-left-color: #a47a26; }
.entry-tile.ct-disease { border-left-color: #a34d4d; }
.entry-tile .tile-thumb {
  position: relative; width: 100%; aspect-ratio: 4/3; overflow: hidden;
  border-radius: 7px; background: #f1ede4; border: 1px solid var(--line);
}
.entry-tile .tile-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.entry-tile .tile-thumb .ad-empty {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; color: #9a9488; font-size: 10.5px; letter-spacing: .1em;
  background: repeating-linear-gradient(45deg,#faf8f3,#faf8f3 6px,#f4f1ea 6px,#f4f1ea 12px);
}
.entry-tile .tile-thumb .ad-empty svg { width: 24px; height: 18px; color: #b3ab9c; }
.entry-tile .tile-title { font-family: "Songti SC","STSong",serif; font-size: 13px; margin: 7px 2px 2px; line-height: 1.3; }
.entry-tile .tile-meta { font-family: ui-monospace,"Cascadia Mono",Consolas,monospace; font-size: 10.5px; color: var(--mut); margin: 0 2px; }
.entry-tile .adopt-badge {
  position: absolute; top: 12px; right: 12px; background: #a47a26; color: #fff;
  font-size: 10px; padding: 1px 7px; border-radius: 999px;
}
.entry-tile.ct-disease .adopt-badge { background: #a34d4d; }

/* ---------- 条目详情弹层 ---------- */
.entry-modal { width: min(760px, 94vw); position: relative; }
.entry-body { padding: 6px 48px 0 0; }
.entry-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.entry-head .e-name { flex: 1; font-family: "Songti SC","STSong",serif; font-size: 15px; font-weight: 700;
  border: 1px solid transparent; background: transparent; color: var(--ink); padding: 4px 6px;
  border-radius: 6px; outline: none; }
.entry-head .e-name:hover { border-color: var(--line); background: #fbfaf6; }
.entry-head .e-name:focus { border-color: var(--glass); background: #fbfaf6; }
.entry-head .del { border: 1px solid var(--line); background: transparent; color: #9a6052; font-size: 11.5px;
  padding: 3px 10px; border-radius: 6px; cursor: pointer; opacity: .75; }
.entry-head .del:hover { background: #f7ecea; opacity: 1; }
.entry-body label { display: block; font-size: 11.5px; color: var(--mut); margin-bottom: 8px; }
.entry-body label > span { display: block; margin-bottom: 3px; letter-spacing: .06em; }
.entry-body textarea {
  width: 100%; min-height: 56px; border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
  font-size: 12.5px; color: var(--ink); background: #fbfaf6; resize: vertical; outline: none;
  font-family: inherit; line-height: 1.5;
}
.entry-body textarea:focus { border-color: var(--glass); box-shadow: 0 0 0 3px rgba(47,123,118,.1); }
.entry-body .e-prompt { min-height: 72px; }
.entry-tools { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.entry-tools .gen-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.gen-state { font-size: 12px; color: var(--mut); }
.gen-state.err { color: #9a3d2b; }

/* 生图大按钮（条目详情弹层） */
button.gen-big {
  display: block; width: 100%; border: none; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, #c08b33, #8a641c);
  color: #fff; font-family: "Songti SC","STSong","SimSun",serif; font-size: 16px;
  letter-spacing: .24em; padding: 14px 20px;
  box-shadow: 0 6px 18px rgba(164,122,38,.28);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
button.gen-big:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(164,122,38,.36); }
button.gen-big:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button.gen-big[disabled] { opacity: .6; cursor: wait; filter: grayscale(.3); }

/* ---------- 页内大图灯箱 ---------- */
a.img-open { display: block; cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center;
  background: rgba(18,14,26,.9);
}
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 8px; box-shadow: 0 22px 70px rgba(0,0,0,.55); background: #fff; }
.lightbox .close-x {
  position: absolute; top: 14px; right: 20px; width: 40px; height: 40px;
  border: 1px solid rgba(255,255,255,.35); border-radius: 50%; background: rgba(0,0,0,.35);
  color: #fff; font-size: 21px; line-height: 1; cursor: pointer;
}
.lightbox .close-x:hover { background: rgba(255,255,255,.22); }
.lightbox .lb-adopt { position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); }

/* ---------- 栏目分色图框：分阶段服装=金色 / 疫病状态=暗红 ---------- */
.dsec.sec-costume > h3 { color: #8a641c; }
.dsec.sec-disease > h3 { color: #8c3f3f; }
.entry.ct-costume { border-left-color: #a47a26; }
.entry.ct-disease { border-left-color: #a34d4d; }

/* ---------- 条目弹层内 主图(采用图) + 备选图 区域 ---------- */
/* 采用图通宽置顶，备选图在下方排成一排（每张约 25% 宽） */
.entry-imgs { display: flex; flex-direction: column; gap: 14px; margin-top: 2px; }
.adopted-zone, .alt-zone { min-width: 0; }
.zone-label { font-size: 11px; letter-spacing: .08em; color: var(--mut); margin-bottom: 6px; }
figure.adopted { margin: 0; position: relative; }
figure.adopted img { width: 100%; border-radius: 8px; border: 2px solid #a47a26; background: #fff; display: block; }
figure.adopted figcaption { font-size: 10.5px; color: var(--mut); margin-top: 4px; word-break: break-all; }
figure.adopted .adopt-badge {
  position: absolute; top: 8px; left: 8px; background: #a47a26; color: #fff;
  font-size: 11px; padding: 2px 10px; border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); letter-spacing: .08em;
}
.ct-disease figure.adopted .adopt-badge { background: #a34d4d; }
.ct-disease figure.adopted img { border-color: #a34d4d; }
.adopted.empty {
  border: 1px dashed var(--line); border-radius: 8px; min-height: 160px;
  display: flex; align-items: center; justify-content: center;
}
.adopted.empty .ad-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: #9a9488; font-size: 11.5px; }
.adopted.empty .ad-empty svg { width: 30px; height: 23px; color: #b3ab9c; }
.alt-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
figure.alt { margin: 0; cursor: pointer; position: relative; }
figure.alt img { width: 100%; border-radius: 6px; border: 1px solid var(--line); background: #fff; display: block; transition: border-color .12s; }
figure.alt:hover img { border-color: #a47a26; }
.ct-disease figure.alt:hover img { border-color: #a34d4d; }
figure.alt .adopt-badge {
  position: absolute; top: 4px; left: 4px; background: #a47a26; color: #fff;
  font-size: 10px; padding: 1px 7px; border-radius: 999px;
}
.ct-disease figure.alt .adopt-badge { background: #a34d4d; }
figure.alt figcaption { font-size: 10.5px; color: var(--mut); margin-top: 3px; word-break: break-all; }
.alt-empty {
  grid-column: 1 / -1; font-size: 11.5px; color: var(--mut); text-align: center;
  border: 1px dashed var(--line); border-radius: 8px; padding: 14px 0; letter-spacing: .08em;
}
.entry-tools .ref-note { font-size: 11.5px; color: var(--mut); }

/* ---------- 基本形象：主基础图高亮 ---------- */
figure.spec.primary img { outline: 3px solid #a47a26; outline-offset: 2px; border-radius: 6px; }
figure.spec .primary-badge {
  position: absolute; top: 6px; left: 6px; background: #a47a26; color: #fff;
  font-size: 10.5px; padding: 2px 9px; border-radius: 999px; z-index: 2;
}
figure.spec .spec-tools {
  position: absolute; left: 8px; right: 8px; bottom: 6px; display: flex; gap: 6px;
  opacity: 0; transition: opacity .15s; z-index: 2;
}
figure.spec:hover .spec-tools { opacity: 1; }
figure.spec .spec-tools .crop-btn { position: static; opacity: 1; flex: 1; text-align: center; }
figure.spec .spec-tools .crop-btn.set-primary { background: rgba(90,60,20,.82); }

/* ---------- 场景/配角 ---------- */
.scene-tools { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.scene-tools .scene-prompt { flex: 1 1 480px; }
.scene-results { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.scene-results figure { margin: 0; width: 240px; }
.scene-results img { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.prompt-list { display: flex; flex-direction: column; gap: 14px; }
.prompt-item { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 12px 14px; }
.prompt-item h4 { font-size: 13px; margin-bottom: 7px; color: #4b3a7d; }
.prompt-item .pp { font-size: 12.5px; color: var(--ink); line-height: 1.6; white-space: pre-wrap; }

/* 图源标签：原图（Pics） vs 生成（本系统生成） */
span.src-badge {
  position: absolute; top: 6px; right: 6px; z-index: 3; font-size: 10px; line-height: 1;
  padding: 3px 8px; border-radius: 999px; letter-spacing: .06em; font-weight: 600;
}
figure.adopted span.src-badge, figure.alt span.src-badge,
figure.spec span.src-badge, .scene-results figure span.src-badge,
.tgen-res span.src-badge, .gl-res figure span.src-badge {
  top: 6px; right: 6px; left: auto;
}
span.src-badge.src-orig { background: rgba(43,36,51,.72); color: #efe9e0; border: 1px solid rgba(255,255,255,.22); }
span.src-badge.src-gen { background: linear-gradient(135deg,#c08b33,#8a641c); color: #fff; box-shadow: 0 2px 6px rgba(164,122,38,.35); }
span.src-badge.src-up { background: linear-gradient(135deg,#5b7bb0,#3d557f); color: #fff; box-shadow: 0 2px 6px rgba(61,85,127,.35); }

/* 备选区标题行：标签 + 上传按钮 */
.zone-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.zone-head .zone-label { flex: 1; }

/* 资产库首页工具栏：一键下载 */
.lib-tools { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.lib-tools .tip { font-size: 11.5px; color: var(--mut); }

/* 上传图的「移除」小按钮（条目备选图 / 场景上传图） */
button.up-del {
  position: absolute; top: 6px; left: 6px; z-index: 4;
  background: rgba(20,16,28,.72); color: #f4ede2;
  border: 1px solid rgba(255,255,255,.28); border-radius: 5px;
  padding: 3px 9px; font-size: 11px; cursor: pointer;
}
button.up-del:hover { background: #c0392b; border-color: #c0392b; color: #fff; }
.scene-up-grid figure { width: 240px; }
.scene-up-grid figure figcaption { font-size: 10.5px; color: var(--mut); margin-top: 3px; word-break: break-all; }
/* 与既有徽标（primary-badge/adopt-badge 在左上）错开 */
figure.spec .src-badge, figure.adopted .src-badge, figure.alt .src-badge { right: 6px; }
.tgen-res { position: relative; }
.scene-results figure, .gl-res figure { position: relative; }

/* TAB 生成结果：被采用时显示金色徽标 */
.tgen-res { position: relative; }
.tgen-res.is-adopted img { outline: 2px solid #a47a26; outline-offset: 1px; }
.tgen-res .adopt-badge {
  position: absolute; top: 4px; left: 4px; z-index: 2; background: #a47a26; color: #fff;
  font-size: 10px; padding: 1px 7px; border-radius: 999px;
}
/* 参考图标本卡点击提示（光标放大镜，与资产库 img-open 一致） */
a.ref-img { display: block; cursor: zoom-in; }

/* ---------- 设置页：模型配置 ---------- */
.cfg-sec, .cfg-log { margin-bottom: 22px; }
.cfg-sec > h3, .cfg-log > h3 {
  font-family: "Songti SC","STSong",serif; font-size: 15.5px; letter-spacing: .08em;
  color: #4b3a7d; display: flex; align-items: center; gap: 10px;
  padding-bottom: 8px; margin-bottom: 12px; border-bottom: 1px solid var(--line);
}
.cfg-sec > h3 .tip { font-weight: 400; font-size: 11.5px; color: var(--mut); }
.cfg-block { margin-bottom: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fbfaf6; }
.cfg-block-title {
  margin: 0 0 9px; font-size: 12.5px; letter-spacing: .12em; color: #8a641c; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.cfg-block-title::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: linear-gradient(135deg,#c08b33,#8a641c); }
.cfg-actions { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.cfg-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.cfg-row label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--mut); }
.cfg-row select {
  border: 1px solid var(--line); border-radius: 7px; background: #fbfaf6; color: var(--ink);
  font-size: 13px; padding: 6px 10px; font-family: inherit; min-width: 220px;
}
.cfg-row select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(164,122,38,.12); }
.cfg-row .cfg-save { padding: 7px 20px; background: #e9e0d2; border-color: #cdbfa5; }
.cfg-row .cfg-price { align-self: center; font-size: 12.5px; color: #8a641c; font-weight: 600; }
.cfg-models { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.cfg-model-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; padding: 9px 13px;
}
.cfg-model-row b { font-size: 13px; color: var(--ink); min-width: 190px; }
.cfg-model-prices { display: flex; gap: 8px; flex-wrap: wrap; }
.cfg-price-tag {
  font-size: 11.5px; color: #5a5247; background: #f4f0e8; border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px;
}

/* ---------- 生图全局遮罩 ---------- */
#gen-mask {
  position: fixed; inset: 0; z-index: 60; display: none; align-items: center; justify-content: center;
  background: rgba(30,26,38,.55); backdrop-filter: blur(2px);
}
#gen-mask.on { display: flex; }
#gen-mask .box { background: #fff; border-radius: 14px; padding: 26px 34px; text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,.35); }
#gen-mask .spin { width: 34px; height: 34px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--gold); animation: lb-spin 1s linear infinite; }
@keyframes lb-spin { to { transform: rotate(360deg); } }
#gen-mask .label { font-family: "Songti SC","STSong",serif; font-size: 15px; color: var(--ink); }
#gen-mask .sub { font-size: 11.5px; color: var(--mut); margin-top: 6px; }

/* ---------- 头像裁剪弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 70; display: none; align-items: center; justify-content: center;
  background: rgba(30,26,38,.6);
}
.modal-mask.on { display: flex; }
.modal {
  position: relative; background: #fff; border-radius: 14px; width: min(720px, 94vw); padding: 20px 22px 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35); max-height: 92vh; overflow: auto;
}
.modal h3 { font-family: "Songti SC","STSong",serif; font-size: 16px; margin-bottom: 4px; }
.modal .hint { font-size: 12px; color: var(--mut); margin-bottom: 12px; }
.crop-stage {
  position: relative; display: flex; align-items: center; justify-content: center; background: #2b2433;
  border-radius: 10px; overflow: hidden; touch-action: none;
}
.crop-stage canvas { display: block; }
.crop-tools { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.crop-tools label { font-size: 12px; color: var(--mut); display: flex; align-items: center; gap: 8px; }
.crop-tools input[type=range] { width: 150px; }
.crop-tools .spacer { flex: 1; }
.modal .mfoot { margin-top: 14px; display: flex; justify-content: flex-end; gap: 10px; }
/* 弹层右上角醒目的关闭叉：金色实心圆钮，位于弹窗内部 */
.entry-modal .close-x {
  position: absolute; top: 12px; right: 12px; z-index: 6; width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%; background: linear-gradient(135deg, #c08b33, #8a641c);
  color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 14px rgba(164,122,38,.4);
}
.entry-modal .close-x:hover { filter: brightness(1.1); }
.entry-modal .close-x:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.modal .close-x { position: absolute; top: 12px; right: 16px; border: none; background: none; font-size: 20px;
  color: var(--mut); cursor: pointer; }

@media (max-width: 720px) {
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .entry-tiles { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
  .alt-grid { grid-template-columns: repeat(2, 1fr); }
  .entry-body { padding-right: 40px; }
}
