/* ================= AI 漫剧导演台 · V6 暗色主题 =================
   色板参照「视频生成工作台V6」：background hsl(228 12% 8%) / primary hsl(252 56% 57%)
   布局：左侧紫色边栏 + 右侧主区；主区两视图（我的项目 / 项目内页） */
:root {
  --bg: hsl(228 12% 8%);
  --bg-soft: hsl(228 13% 10%);
  --panel: hsl(228 13% 12%);
  --panel2: hsl(228 13% 15%);
  --line: hsl(228 12% 19%);
  --text: #e9ebf2;
  --muted: #8b93a5;
  --primary: hsl(252 56% 57%);
  --primary-hi: hsl(252 66% 66%);
  --primary-soft: hsla(252, 56%, 57%, .16);
  --primary-line: hsla(252, 56%, 57%, .45);
  --ok: #36c275;
  --warn: #f0a020;
  --bad: #ef5b5b;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
::selection { background: var(--primary-soft); }

/* ================= 总体布局：侧边栏 + 主区 ================= */
.app { display: grid; grid-template-columns: 236px 1fr; height: 100vh; overflow: hidden; }

/* ---- 侧边栏 ---- */
.sidebar {
  background: var(--bg-soft); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px; border-bottom: 1px solid var(--line);
}
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--primary), hsl(272 60% 44%));
  color: #fff; font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px hsla(252, 56%, 57%, .35);
}
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: .02em; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
#nav { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.nav-sec { margin-bottom: 14px; }
.nav-label {
  font-size: 11px; color: var(--muted); letter-spacing: .06em;
  padding: 4px 8px 6px; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: transparent; border: none; border-radius: 8px;
  color: var(--muted); font-size: 13px; text-align: left;
  padding: 8px 10px; margin-bottom: 2px; cursor: pointer; position: relative;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.on {
  background: var(--primary-soft); color: var(--primary-hi); font-weight: 500;
}
.nav-item.on::before {
  content: ""; position: absolute; left: 0; top: 7px; bottom: 7px;
  width: 3px; border-radius: 3px; background: var(--primary);
}
.nav-ico { width: 16px; text-align: center; flex: none; font-size: 13px; }
.sidebar-foot {
  border-top: 1px solid var(--line); padding: 10px 14px;
  font-size: 12px; display: flex; align-items: center; gap: 7px;
}

/* ---- 主区 / 视图 ---- */
.main { overflow-y: auto; min-width: 0; }
.view { padding: 22px 26px 40px; }
.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.view-head h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: .02em; }
.view-head p { margin: 0; font-size: 12px; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ================= 我的项目：卡片网格 ================= */
.proj-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.proj-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; position: relative;
  transition: border-color .15s, transform .15s;
}
.proj-card:hover { border-color: var(--primary-line); transform: translateY(-2px); }
.pc-cover {
  height: 74px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, hsla(252,56%,57%,.28), hsla(228,13%,15%,.6) 70%);
  border-bottom: 1px solid var(--line);
}
.pc-cover span { font-size: 26px; font-weight: 700; color: var(--primary-hi); }
.pc-body { padding: 12px 14px 10px; }
.pc-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.pc-date { font-size: 11px; color: var(--muted); margin-top: 3px; }
.pc-stats {
  display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 9px;
  font-size: 12px; color: var(--muted);
}
.pc-stats b { color: var(--text); font-weight: 600; }
.pc-foot {
  padding: 8px 14px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--primary-hi); display: flex; justify-content: space-between; align-items: center;
}
.pc-del {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  background: hsla(228,13%,10%,.8); border: 1px solid var(--line); color: var(--bad);
  border-radius: 6px; width: 24px; height: 24px; padding: 0; line-height: 1; font-size: 14px;
}
.pc-del:hover { background: rgba(239,91,91,.18); }
.proj-empty {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 46px 20px; text-align: center; color: var(--muted); font-size: 13px;
}

/* ================= 项目内页 ================= */
.proj-topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.breadcrumb { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.breadcrumb .sep { opacity: .5; }
.breadcrumb b { color: var(--text); font-weight: 600; }
.breadcrumb .bc-home { cursor: pointer; }
.breadcrumb .bc-home:hover { color: var(--primary-hi); }

.stat-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px;
}
.sc-label { font-size: 12px; color: var(--muted); }
.sc-value { font-size: 22px; font-weight: 700; margin: 5px 0 3px; letter-spacing: .02em; }
.sc-sub { font-size: 11px; color: var(--muted); }

.proj-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 18px;
}

/* ================= 面板 / 表单 ================= */
.pane { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h2 {
  font-size: 13px; margin: 0 0 12px; color: var(--text);
  letter-spacing: .03em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.panel h2 .muted { font-weight: 400; font-size: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.row:last-child { margin-bottom: 0; }

input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 10px; width: 100%; font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-line); }
select { width: auto; min-width: 130px; cursor: pointer; }
button {
  background: var(--primary); color: #fff; border: 1px solid transparent;
  border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: filter .12s;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.ghost { background: var(--panel2); border: 1px solid var(--line); color: var(--text); font-weight: 400; }
button.ghost:hover { border-color: var(--primary-line); color: var(--primary-hi); }
button.import-hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hi) 100%);
  border: none;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: all 0.2s ease;
}
button.import-hero:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}
button.danger { color: var(--bad); border-color: rgba(239,91,91,.4); background: transparent; }
button.danger:hover { background: rgba(239,91,91,.12); color: var(--bad); }

.proj-tag {
  background: var(--primary-soft); color: var(--primary-hi);
  padding: 1px 9px; border-radius: 20px; font-size: 11px; font-weight: 500;
}
.ep-sel { max-width: 300px; }

/* 拖拽导入 */
.drop {
  border: 1.5px dashed var(--line); border-radius: 10px; padding: 26px; text-align: center;
  color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1.7;
}
.drop:hover { border-color: var(--primary-line); }
.drop.hot { border-color: var(--primary); color: var(--primary-hi); background: var(--primary-soft); }

/* 徽标 / 状态 */
.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px; margin: 2px 4px 2px 0; white-space: nowrap; }
.b-ok { background: rgba(54,194,117,.16); color: var(--ok); }
.b-bad { background: rgba(239,91,91,.16); color: var(--bad); }
.b-info { background: var(--primary-soft); color: var(--primary-hi); }
.b-warn { background: rgba(240,160,32,.16); color: var(--warn); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; flex: none; }
.on { background: var(--ok); } .off { background: var(--bad); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
pre { white-space: pre-wrap; word-break: break-word; }

/* 表格（分镜板） */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: none; }

/* ================= 素材卡片网格（人物/场景/道具） ================= */
.asset-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
}
.asset-card {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; position: relative;
}
.asset-card:hover { border-color: var(--primary-line); }
.ac-img { height: 92px; background: var(--bg-soft); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.ac-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ac-ph { font-size: 24px; font-weight: 700; color: var(--muted); opacity: .5; }
.ac-body { padding: 8px 10px 10px; }
.ac-name { font-size: 13px; font-weight: 600; word-break: break-all; }
.ac-note { font-size: 11px; margin-top: 2px; line-height: 1.5; max-height: 34px; overflow: hidden; }
.ac-refs { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.ac-refs img {
  width: 26px; height: 26px; object-fit: cover; border-radius: 5px;
  border: 1px solid var(--line); cursor: pointer;
}
.asset-card .del {
  position: absolute; top: 6px; right: 6px;
  background: hsla(228,13%,10%,.85); border: 1px solid var(--line); color: var(--bad);
  border-radius: 6px; width: 22px; height: 22px; padding: 0; line-height: 1; font-size: 13px;
}
.asset-card .del:hover { background: rgba(239,91,91,.2); }
/* 需求二·2.2 换参考图（联动更新分镜提示词） */
.asset-card .swap {
  position: absolute; top: 6px; right: 32px;
  background: hsla(228,13%,10%,.85); border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; padding: 2px 7px; font-size: 11px; line-height: 1.4;
}
.asset-card .swap:hover { background: hsla(252,56%,57%,.22); color: var(--primary-hi); }
#syncHint, [id^="syncHint-"] {
  display: none; margin: 8px 0 0; padding: 7px 10px; font-size: 12px;
  border: 1px solid var(--line); border-left: 3px solid var(--primary-hi);
  border-radius: 6px; background: var(--panel2); color: var(--text);
}
.ref-preview { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ================= 豆包 AI 助手 ================= */
.ai-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.ai-tab {
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 6px 13px; cursor: pointer; font-size: 13px;
}
.ai-tab:hover { color: var(--text); }
.ai-tab.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.ai-settings {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 12px; background: var(--panel2);
}
.ai-out {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  min-height: 60px; max-height: 460px; overflow: auto; font-size: 13px;
  background: var(--panel2);
}
.ai-out pre { margin: 0; font-size: 13px; line-height: 1.7; }
.ai-tpl { font-size: 12px; margin-bottom: 4px; }

/* 文生图结果 */
.t2i-img-wrap { margin-top: 14px; }
.t2i-img {
  width: 100%; max-width: 430px; border: 1px solid var(--line); border-radius: 10px;
  display: block; background: var(--panel2);
}
.t2i-img-wrap .kv { max-width: 430px; }

/* 滚动条（暗色） */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel2); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* 窄屏兜底 */
@media (max-width: 860px) {
  .app { grid-template-columns: 64px 1fr; }
  .brand-name, .brand-sub, .nav-label, .nav-item span:not(.nav-ico), .sidebar-foot span:not(.status-dot) { display: none; }
  .nav-item { justify-content: center; }
}

/* ---------- 视频生成面板 ---------- */
.vid-player { width: 100%; max-width: 640px; border-radius: 10px; background: #000; display: block; }
.vid-task { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.vid-task.on { border-color: var(--primary-hi); }
.vid-task-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.vid-err { color: var(--err, #f2545b); font-size: 12px; margin-top: 6px; white-space: pre-wrap; word-break: break-all; }

/* ---------- 视频生成 · 分镜时长联动 ---------- */
.vid-shot { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: 13px; flex-wrap: wrap; }
.vid-shot:hover { background: var(--primary-soft); }
.vid-shot-id { min-width: 48px; }
.vid-shot-brief { flex: 1; min-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 长片生成面板 ---------- */
.lf-bar { height: 6px; border-radius: 6px; background: var(--panel2, rgba(255,255,255,.06)); margin: 8px 0 4px; overflow: hidden; }
.lf-bar-in { height: 100%; border-radius: 6px; background: var(--primary, #7c6cf0); transition: width .4s; }
.lf-shot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; margin-top: 10px; }
.lf-shot { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--panel2, rgba(255,255,255,.02)); }
.lf-shot-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12px; margin-bottom: 6px; }
.lf-shot-img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 8px; background: #000; display: block; }
.lf-shot-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.lf-shot-title { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }
.lf-shot-dur { font-size: 11px; margin: -2px 0 6px; }
.lf-shot-dl { display: inline-block; margin-top: 6px; font-size: 11px; }
.lf-shot .vid-err { margin-top: 4px; }

/* ---------- 一句话生成视频 ---------- */
.os-shot-list { display: flex; flex-direction: column; gap: 10px; }
.os-shot { display: flex; gap: 12px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel2, rgba(255,255,255,.02)); }
.os-shot-no { flex: 0 0 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-hi));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; }
.os-shot-body { flex: 1; min-width: 0; }
.os-shot-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.os-shot-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.os-tag { display: inline-block; padding: 2px 8px; border-radius: 12px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  font-size: 11px; color: var(--muted); }
.os-tag-sec { background: var(--primary); color: #fff; border-color: var(--primary); }
.os-shot-action { font-size: 13px; line-height: 1.5; color: var(--fg); }
.os-shot-sum { font-size: 12px; color: var(--muted); margin-top: 4px; font-style: italic; }

.os-seg { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  margin-top: 10px; background: var(--panel2, rgba(255,255,255,.02)); }
.os-seg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.os-seg-k { font-size: 12px; color: var(--muted); margin: 8px 0 4px; font-weight: 600; }
.os-seg-ta { width: 100%; font-size: 12px; line-height: 1.5; font-family: inherit;
  background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; resize: vertical; }

/* ---------- 视频生成 · 提示词附加规则 ---------- */
.vid-rules { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.vid-rules-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.vid-rule-line { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-top: 4px; }
.vid-rules textarea { margin-top: 6px; font-size: 12px; min-height: 46px; }
.vid-preview { margin: 6px 0 0; max-height: 160px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  font-size: 12px; line-height: 1.6; color: var(--fg-muted, #9aa3b2); background: var(--bg-soft, rgba(255,255,255,.03));
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }

/* =================================================================
   移动端适配（PWA / 手机浏览器）
   ================================================================= */

/* 首页 ComfyUI 状态条 */
.comfy-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; margin-bottom: 16px;
  background: var(--bg-soft, rgba(255,255,255,.03));
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px;
}
.comfy-state { display: flex; align-items: center; gap: 8px; }
.comfy-actions { display: flex; gap: 8px; }
.comfy-actions button { padding: 6px 14px; font-size: 13px; min-height: 32px; }
.comfy-actions button.wake-btn { background: #6366f1; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
.comfy-actions button.wake-btn:hover { background: #5558e6; }
.comfy-actions button.wake-btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 768px) {
  /* 布局：单列 + 抽屉侧边栏 */
  .app {
    grid-template-columns: 1fr;
    height: 100dvh;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 78%;
    max-width: 300px; z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  /* 遮罩 */
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; z-index: 190;
    background: rgba(0,0,0,.5);
  }
  .sidebar-backdrop.show { display: block; }

  /* 顶部移动端工具条（汉堡 + 项目名） */
  .m-topbar {
    display: flex !important;
    align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 100;
    height: 52px; padding: 0 12px;
    background: var(--bg-soft); border-bottom: 1px solid var(--line);
  }
  .m-menu-btn {
    width: 38px; height: 38px; flex: none;
    border: 1px solid var(--line); border-radius: 9px;
    background: var(--panel); color: var(--text);
    font-size: 18px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }
  .m-menu-btn:active { background: var(--panel2); }
  .m-title { font-size: 15px; font-weight: 600; flex: 1;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* 主区去掉桌面端的左内边距 */
  .main, .view { height: auto !important; }

  /* 面板与卡片：单列铺满 */
  .panel { padding: 14px !important; border-radius: 10px; }
  .row { flex-wrap: wrap !important; gap: 8px !important; }
  .row > * { flex: 1 1 auto; min-width: 0 !important; }
  .row > input[type="number"] { flex: 0 0 78px; }
  select, input[type="text"], input[type="number"], textarea {
    font-size: 16px !important; /* 防止 iOS 自动缩放 */
    width: 100%;
  }
  textarea { min-height: 90px; }

  /* 按钮：加大触控区 */
  button, .btn, .ghost, .nav-item {
    min-height: 42px;
    padding: 9px 16px;
    font-size: 15px;
  }
  button { width: auto; }
  .row > button { flex: 1 1 140px; }

  /* 卡片网格：两列 */
  .cards, .asset-grid, .grid { grid-template-columns: 1fr 1fr !important; }

  /* 图片卡片内按钮横排不换行 */
  .bi-image-card > div:first-child { flex-wrap: wrap; }

  /* 分镜表：横向滚动而非挤压 */
  table { display: block; overflow-x: auto; white-space: nowrap; }

  /* 任务列表图片缩小 */
  #biJobs img, #vidJobs img { max-width: 100% !important; height: auto; }

  /* 底部安全区（iPhone 刘海屏） */
  body { padding-bottom: env(safe-area-inset-bottom); }

  /* 提示条贴近底部安全区 */
  .panel:last-child { margin-bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* 桌面端隐藏移动端专用元素 */
.m-topbar { display: none; }
.sidebar-backdrop { display: none; }

/* 平板（769-1100）：侧边栏收窄 */
@media (min-width: 769px) and (max-width: 1100px) {
  .app { grid-template-columns: 190px 1fr; }
}

/* ================= PWA：更新提示条 / 安装引导 ================= */
.update-bar,
.install-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(12px + env(safe-area-inset-top));
  z-index: 9999;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, hsl(252 56% 30%), hsl(252 56% 22%));
  border: 1px solid var(--primary-line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color: #fff; font-size: 13px;
  animation: pwaBarIn .28s ease-out;
  max-width: calc(100vw - 24px);
}
.install-bar {
  background: linear-gradient(135deg, hsl(160 45% 24%), hsl(160 45% 18%));
  border-color: hsla(160, 45%, 55%, .45);
}
@keyframes pwaBarIn {
  from { opacity: 0; transform: translate(-50%, -14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.update-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.update-btn {
  flex: 0 0 auto;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
  background: #fff; color: hsl(252 56% 30%);
  border: none; font-size: 13px; font-weight: 600;
}
.update-btn:hover { background: #f0f0f5; }
.update-close {
  flex: 0 0 auto; background: transparent; border: none; color: rgba(255,255,255,.65);
  cursor: pointer; font-size: 14px; padding: 2px 4px; line-height: 1;
}
.update-close:hover { color: #fff; }

/* 移动端：提示条撑满宽度 */
@media (max-width: 768px) {
  .update-bar, .install-bar {
    left: 8px; right: 8px; transform: none;
    max-width: none; border-radius: 14px;
    animation: pwaBarInM .28s ease-out;
  }
  @keyframes pwaBarInM {
    from { opacity: 0; transform: translateY(-14px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* ================= 通用弹窗 ================= */
.dlg-mask {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: dlgFadeIn .2s ease-out;
}
.dlg-mask.out { animation: dlgFadeOut .15s ease-out forwards; }
@keyframes dlgFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dlgFadeOut { from { opacity: 1; } to { opacity: 0; } }

.dlg {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
  min-width: 400px; max-width: 90vw; max-height: 85vh;
  display: flex; flex-direction: column;
  animation: dlgSlideIn .25s ease-out;
}
.dlg.dlg-wide { min-width: 600px; }
@keyframes dlgSlideIn {
  from { opacity: 0; transform: translateY(-20px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dlg-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.dlg-title { font-size: 15px; font-weight: 600; color: var(--text); }
.dlg-x {
  background: none; border: none; font-size: 20px; color: var(--text-dim);
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.dlg-x:hover { color: var(--text); }

.dlg-body {
  padding: 20px; overflow-y: auto; flex: 1;
}

.dlg-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 20px; border-top: 1px solid var(--border);
}
.dlg-foot button {
  padding: 8px 18px; border-radius: 6px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.dlg-ok {
  background: var(--primary); color: #fff; border: none;
}
.dlg-ok:hover { background: var(--primary-hi); }

/* 存入素材库对话框 */
.dlg-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.dlg-label {
  flex: 0 0 60px; font-size: 13px; color: var(--text-dim);
}
.dlg-kinds {
  display: flex; gap: 16px; flex: 1;
}
.dlg-radio {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 13px; color: var(--text);
}
.dlg-radio input { cursor: pointer; }
.dlg-input {
  flex: 1; padding: 8px 12px; border-radius: 6px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); font-size: 13px;
}
.dlg-input:focus {
  outline: none; border-color: var(--primary);
}
.dlg-preview {
  margin-top: 16px; text-align: center;
}
.dlg-preview img {
  max-width: 100%; max-height: 300px; border-radius: 8px;
  border: 1px solid var(--border);
}
.dlg-hint {
  margin-top: 12px; font-size: 12px; color: var(--text-dim);
  text-align: center;
}

/* 素材选择器 */
.ap-tabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.ap-tab {
  flex: 1; padding: 10px 16px; background: none; border: none;
  border-bottom: 2px solid transparent; color: var(--text-dim);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all .15s; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.ap-tab:hover { color: var(--text); }
.ap-tab.on {
  color: var(--primary); border-bottom-color: var(--primary);
}
.ap-cnt {
  font-size: 11px; padding: 2px 6px; border-radius: 10px;
  background: var(--bg-input); color: var(--text-dim);
}
.ap-tab.on .ap-cnt { background: var(--primary); color: #fff; }

.ap-panes {
  max-height: 400px; overflow-y: auto;
}
.ap-pane {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.ap-card {
  display: flex; flex-direction: column; cursor: pointer;
  border: 2px solid var(--border); border-radius: 8px;
  padding: 8px; transition: all .15s; position: relative;
}
.ap-card:hover { border-color: var(--primary); }
.ap-card:has(input:checked) {
  border-color: var(--primary); background: rgba(99,102,241,.08);
}
.ap-card input {
  position: absolute; top: 8px; right: 8px; cursor: pointer;
}
.ap-thumb {
  width: 100%; aspect-ratio: 1; border-radius: 6px; overflow: hidden;
  background: var(--bg-input); display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.ap-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ap-ph {
  font-size: 32px; color: var(--text-dim);
}
.ap-name {
  font-size: 12px; font-weight: 500; color: var(--text);
  text-align: center; word-break: break-all;
}
.ap-note {
  font-size: 11px; color: var(--text-dim); text-align: center;
  margin-top: 4px; word-break: break-all;
}
.ap-empty {
  grid-column: 1 / -1; text-align: center; padding: 40px 20px;
  font-size: 13px;
}

/* ================= 首页 · 创作工具网格 ================= */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 20px;
}
.tool-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all .2s ease;
  text-align: center;
}
.tool-tile:hover {
  background: var(--panel2);
  border-color: var(--primary-line);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, .18);
}
.tool-icon {
  font-size: 28px;
  line-height: 1;
}
.tool-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.tool-sub {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

/* 首页工具模式：返回按钮 */
.home-tool-back {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 8px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.home-tool-back:hover {
  background: var(--panel2);
  border-color: var(--primary-line);
}
/* 当首页有工具 pane 激活时，隐藏导入区和工具网格，显示返回按钮 */
#view-projects.tool-active .view-head,
#view-projects.tool-active .tool-grid,
#view-projects.tool-active #projGridHint {
  display: none !important;
}
#view-projects.tool-active .home-tool-back {
  display: flex;
}

/* ================= 移动端专用视图（2026-10-18） =================
   手机端保留「文生图」「批量生图」「云端文生视频」三项（都是轻量/云端，手机能跑）；
   video / longfilm / oneshot / ai / comfy 为桌面端重流水线（要 24G 显存或复杂编排），移动端隐藏。
   断点与 app.js 的 isMobileLayout() 保持一致（<=768px）。 */
@media (max-width: 768px) {
  /* 隐藏重工具入口：首页网格卡片 + 侧边栏导航项 */
  .tool-tile[data-tab="video"],
  .tool-tile[data-tab="longfilm"],
  .tool-tile[data-tab="oneshot"],
  .tool-tile[data-tab="ai"],
  .tool-tile[data-tab="comfy"],
  #navToolSec .nav-item[data-tab="video"],
  #navToolSec .nav-item[data-tab="longfilm"],
  #navToolSec .nav-item[data-tab="oneshot"],
  #navToolSec .nav-item[data-tab="ai"],
  #navToolSec .nav-item[data-tab="comfy"] {
    display: none !important;
  }
  /* 移动端聚焦两项功能，隐藏项目素材子导航（分镜/人物/场景/道具/音频/其他） */
  #navProjSec { display: none !important; }
  /* 仅剩的入口放大，方便拇指操作 */
  .tool-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .tool-tile { padding: 26px 12px; }
  .tool-icon { font-size: 34px; }
  .tool-label { font-size: 16px; }
  /* 云端文生视频占满整行（奇数个入口时不留半格空位） */
  .tool-tile[data-tab="cloudvideo"] { grid-column: 1 / -1; }
}
