/* WOWSight 體育社群素材台 — wowsight-sns mock */
/* 設計語言:平面無陰影、大留白、深藏青標題/青品牌色,沿用 v4 的資訊密度但收斂成兩條路線 */
:root {
  --topbar-h: 62px;
  --bg: #FBF3EA;
  --surface: #ffffff;
  --surface-2: #f6f3ec;
  --ink: #2B0B06;
  --mut: #6B4B42;
  --faint: #6b6b70;
  --line: #e6e8f2;
  --a: #C00703;
  --a2: #D6A406;
  --warn: #b71c1c;
  --ok: #0e7a4f;
  --chip: #C0070320;
  --topbar-a: #2B0B06;
  --topbar-b: #665310;
  --font-scale: 1;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: calc(15px * var(--font-scale));
}
.topbar { background: linear-gradient(120deg, var(--topbar-a), var(--topbar-b)); color: #fff; padding: 0; }
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  max-width: 1240px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand b { font-size: calc(15px * var(--font-scale)); letter-spacing: .02em; }
.brand .sub { display: block; font-size: calc(12px * var(--font-scale)); color: rgba(255,255,255,.92); }
.logo {
  height: 30px; width: auto; flex: none; display: block;
}
.logo-missing { display: none; }
.logo-fallback { display: none; font-weight: 800; font-size: calc(16px * var(--font-scale)); letter-spacing: .02em; }
.logo.logo-missing + .logo-fallback { display: inline; }
.topright { display: flex; gap: 10px; align-items: center; font-size: calc(13px * var(--font-scale)); }
.doclinks { display: flex; gap: 11px; align-items: center; flex-wrap: wrap; row-gap: 2px; margin-right: 3px; padding-right: 12px; border-right: 1px solid rgba(255,255,255,.22); }
.doclinks a { color: #fff; font-size: calc(12px * var(--font-scale)); text-decoration: none; white-space: nowrap; }
.doclinks a:hover { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.channel-pill {
  padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.25); font-size: calc(12px * var(--font-scale));
}
.channel-pill.live { background: #0e7a4f; border-color: #0e7a4f; }
.channel-pill.degraded { background: #8a6d00; border-color: #8a6d00; }
.api-status { color: rgba(255,255,255,.92); }

.shell { display: flex; max-width: 1240px; margin: 0 auto; min-height: calc(100vh - var(--topbar-h, 62px)); }
.rail {
  width: 268px; flex: none; padding: 16px 14px; border-right: 1px solid var(--line);
  background: var(--surface); display: flex; flex-direction: column; gap: 13px;
  overflow: hidden; transition: width .22s ease, padding .22s ease;
}
.rail-head { display: flex; justify-content: space-between; align-items: center; min-height: 24px; }
.rail-head-actions { display: flex; gap: 6px; align-items: center; }
.rail-title { font-size: calc(12px * var(--font-scale)); color: var(--faint); letter-spacing: .2em; white-space: nowrap; }
.btn-mini { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 2px 8px; cursor: pointer; color: var(--mut); }
.btn-mini:hover { border-color: var(--a); color: var(--a); }
#rail-toggle { font-size: calc(15px * var(--font-scale)); line-height: 1; padding: 2px 7px; }

/* 素材案窗:收起後只留一條 44px 窄欄與開關按鈕,主區自動變寬 */
.shell.rail-collapsed .rail { width: 44px; padding: 16px 7px; }
.shell.rail-collapsed .rail-title,
.shell.rail-collapsed .rail-search,
.shell.rail-collapsed #case-list,
.shell.rail-collapsed .newcase,
.shell.rail-collapsed #refresh-feed { display: none; }
.shell.rail-collapsed .rail-head { justify-content: center; }
.shell.rail-collapsed #rail-toggle { transform: rotate(180deg); }

.caseitem {
  padding: 10px 11px; margin-bottom: 2px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
  background: var(--surface); transition: border-color .15s;
  display: flex; gap: 7px; align-items: flex-start;
}
.caseitem:hover { border-color: var(--a); }
.caseitem.cur { border-color: var(--a); border-left: 4px solid var(--a); background: color-mix(in srgb, var(--a) 14%, var(--surface)); box-shadow: inset 0 0 0 1px var(--line); }
.caseitem.picked { border-color: var(--a); background: color-mix(in srgb, var(--a) 8%, var(--surface)); }
.caseitem.picked.cur { background: color-mix(in srgb, var(--a) 17%, var(--surface)); }
.caseitem .ci-main { flex: 1 1 auto; min-width: 0; }
/* 勾選框:視覺 19px,點擊區 44px;負 margin 讓列高不被撐大 */
.casepick {
  flex: none; width: 44px; height: 44px; margin: -9px 0 -9px -7px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 8px;
  background: none; color: #fff; cursor: pointer;
}
.casepick:hover { background: var(--chip); }
.casepick .pickbox {
  width: 19px; height: 19px; box-sizing: border-box; border: 2px solid var(--line); border-radius: 6px;
  display: grid; place-items: center; font-size: 13px; line-height: 1; font-weight: 700;
  transition: background .12s, border-color .12s;
}
.casepick.on .pickbox { background: var(--a); border-color: var(--a); }
.casepick.on .pickbox::after { content: "✓"; }
.caseitem .ci-snip { padding-left: 0; padding-right: 0; }
.caseitem .ci-title { font-size: calc(14px * var(--font-scale)); font-weight: 600; color: var(--ink); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.caseitem .ci-meta { display: flex; gap: 6px; margin-top: 5px; align-items: center; }
.badge {
  font-size: calc(11px * var(--font-scale)); padding: 1px 7px; border-radius: 999px; font-weight: 600;
}
.badge.auto { background: #e3f2f4; color: #14657a; }
.badge.manual { background: #eee8fa; color: #5546b8; }
.badge.gen-llm { background: #e5f4ea; color: var(--ok); }
.badge.gen-tpl { background: #f3eefa; color: #7a5f00; }
.badge.gen-none { background: var(--chip); color: var(--mut); }
.badge.kind-sq { background: #e8f0fe; color: #1a56c4; }
.badge.kind-reel { background: #fdeef5; color: #c2185b; }
.ci-date { font-size: calc(11px * var(--font-scale)); color: var(--mut); margin-left: auto; }

.newcase {
  border: 1px dashed var(--a); color: var(--a); background: none;
  border-radius: 10px; padding: 9px; cursor: pointer; font-size: calc(14px * var(--font-scale));
  font-family: inherit;
}
.newcase:hover { background: color-mix(in srgb, var(--a) 12%, var(--surface)); }

/* ---- #/new 手動生成獨立頁(全頁表單,左列收起) ---- */
.np-wrap { max-width: 860px; margin: 0 auto; }
.np-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.np-head h1 { margin: 0; font-size: calc(22px * var(--font-scale)); }
.np-form {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 24px; display: flex; flex-direction: column; gap: 8px;
}
.np-label {
  display: flex; gap: 8px; align-items: baseline; margin-top: 10px;
  font-size: calc(13px * var(--font-scale)); font-weight: 600; color: var(--mut);
}
.np-form .np-label:first-child { margin-top: 0; }
.np-req { font-size: calc(11px * var(--font-scale)); font-weight: 400; color: var(--warn); }
.np-opt { font-size: calc(11px * var(--font-scale)); font-weight: 400; color: var(--faint); }
.np-form input, .np-form textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font: inherit; font-size: calc(14px * var(--font-scale));
  background: var(--surface); color: var(--ink); width: 100%;
}
.np-form input:focus, .np-form textarea:focus { outline: none; border-color: var(--a); }
.np-form textarea { resize: vertical; min-height: 240px; line-height: 1.7; }  /* 內文可拉大 */
.np-form .sect { margin: 16px 0 6px; }
.np-error {
  margin-top: 10px; padding: 9px 12px; border-radius: 8px; font-size: calc(13px * var(--font-scale));
  color: var(--warn); background: #fdf0f0; border: 1px solid #f0d3d3;
}
.np-error[hidden] { display: none; }
.np-check {
  display: flex; align-items: center; gap: 8px; margin: 12px 0 2px; min-height: 44px;
  font-size: calc(13px * var(--font-scale)); color: var(--mut); cursor: pointer;
}
.np-form .np-check input { width: auto; margin: 0; min-height: 18px; padding: 0; border: 0; background: none; }
.np-submit { margin-top: 14px; width: 100%; padding: 12px; font-size: calc(15px * var(--font-scale)); }
.np-form input.np-url { font-size: calc(15px * var(--font-scale)); padding: 12px 14px; border-color: var(--a); }  /* 網址欄最上最大 */
.np-link {
  align-self: flex-start; margin-top: 2px; background: none; border: none; padding: 2px 0;
  color: var(--a); cursor: pointer; font: inherit; font-size: calc(13px * var(--font-scale));
  text-decoration: underline; text-underline-offset: 3px;
}
#np-manual { display: flex; flex-direction: column; gap: 8px; }
#np-manual[hidden] { display: none; }

/* ---- 文章風格晶片(主頁與 #/new 共用):小膠囊;sel 用品牌紫區隔版型(青) ---- */
.stylerow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.stylechip {
  border: 1px solid var(--line); background: var(--surface); color: var(--mut); border-radius: 999px;
  padding: 4px 13px; font: inherit; font-size: calc(13px * var(--font-scale)); cursor: pointer;
}
.stylechip:hover { border-color: var(--a2); color: var(--a2); }
.stylechip.sel { background: color-mix(in srgb, var(--a2) 12%, var(--surface)); border-color: var(--a2); color: var(--ink); font-weight: 600; }

.main { flex: 1; padding: 32px 34px; min-width: 0; }
.casehead h1 { margin: 0 0 6px; font-size: calc(22px * var(--font-scale)); }
.casehead .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.casehead .src { font-size: calc(12px * var(--font-scale)); color: var(--faint); overflow-wrap: anywhere; }
.casehead .src a { color: var(--a); text-decoration: none; }
.casehead .src a:hover { text-decoration: underline; }
.summary {
  margin: 20px 0 32px; padding: 12px 16px; border-left: 4px solid var(--a);
  background: var(--surface); border-radius: 0 10px 10px 0; color: var(--mut); font-size: calc(14px * var(--font-scale));
}

.sect { margin: 34px 0 16px; display: flex; align-items: baseline; gap: 10px; }
.sect b { font-size: calc(15px * var(--font-scale)); }
.sect .hint { font-size: calc(12px * var(--font-scale)); color: var(--faint); font-weight: 400; }

.tplrow { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; align-items: flex-start; }
/* 版型預覽卡:縮略圖 + 名稱 + 一句用途 + 獨立「說明」按鈕(可點,不依賴 hover) */
.tplcard { width: 150px; display: flex; flex-direction: column; gap: 3px; }
.tplbtn {
  width: 100%; border: 1px solid var(--line); background: var(--surface); padding: 6px 7px 9px; border-radius: 10px;
  cursor: pointer; font: inherit; color: var(--mut); text-align: left;
  display: flex; flex-direction: column; gap: 5px; align-items: stretch;
}
.tplbtn:hover { border-color: var(--a); }
.tplbtn.sel { border-color: var(--a); background: color-mix(in srgb, var(--a) 10%, var(--surface)); color: var(--ink); font-weight: 600; }
.tplbtn.sel .tpv-desc { color: var(--mut); }
.tpv-name { font-size: calc(13px * var(--font-scale)); }
.tpv-desc {
  font-size: calc(12px * var(--font-scale)); font-weight: 400; color: var(--faint); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tplinfo {
  align-self: flex-start; border: 0; background: transparent; color: var(--a);
  font: inherit; font-size: calc(12px * var(--font-scale)); line-height: 1.3;
  padding: 2px 0; min-height: 32px; cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}
.tplinfo:hover, .tplinfo[aria-expanded="true"] { color: var(--ink); }
.tplinfo:focus-visible, .tplbtn:focus-visible { outline: 2px solid var(--a); outline-offset: 2px; }
.tpldetail {
  margin: 2px 0 12px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--mut);
  font-size: calc(12.5px * var(--font-scale)); line-height: 1.55; max-width: 760px;
}
.tpldetail p { margin: 4px 0; }
.tpldetail-head { color: var(--ink); font-size: calc(13px * var(--font-scale)); }
.tpldetail-avoid { color: var(--faint); }
.tpldetail-long { color: var(--faint); font-size: calc(12px * var(--font-scale)); }
.tpldetail-link { display: inline-block; margin-top: 5px; min-height: 28px; line-height: 28px; }

/* 縮略圖:1:1 純 CSS 構圖,配色對齊 app/compose.py 頂部色票常數 */
.tpv {
  width: 100%; aspect-ratio: 1/1; border-radius: 7px; overflow: hidden; position: relative;
  display: flex; flex-direction: column; flex: none;
}
.tpv i { display: block; border-radius: 2px; }

.tpv-summary { background: #f7f5f0; padding: 9%; gap: 7%; }               /* PAPER */
.tpv-summary .hl { height: 9%; background: #232a5c; }                     /* INK 大標 */
.tpv-summary .hl1 { width: 88%; }
.tpv-summary .hl2 { width: 62%; }
.tpv-summary .rule { margin-top: auto; height: 2.5%; width: 42%; background: #c9c4b8; }

.tpv-news { background: #fff; }
.tpv-news .band { height: 10%; background: linear-gradient(90deg, #1f7a8c, #22c1c3); border-radius: 0; }  /* TEAL_A→TEAL_B */
.tpv-news .hero { height: 44%; margin: 8% 9% 0; background: linear-gradient(135deg, #dde5f0, #c8d4e8); border-radius: 3px; }  /* HERO_A→B */
.tpv-news .txt { height: 8%; width: 68%; margin: 9% 9% 0; background: #232a5c; }  /* INK */

.tpv-story { background: linear-gradient(165deg, #4a423a, #0c1022 72%); } /* SCRIM 壓暗滿版 */
.tpv-story .txt { margin: auto 10% 10%; height: 18%; background: #fff; }

.tpv-data {                                                               /* NAVY + 細網格 */
  background-color: #10152e;
  background-image:
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 13px 13px;
  align-items: center; justify-content: center; gap: 9%;
}
.tpv-data .num { color: #f5a623; font-size: calc(34px * var(--font-scale)); font-weight: 800; line-height: 1; }  /* AMBER */
.tpv-data .txt { height: 6.5%; width: 56%; background: #969cba; }         /* NAVY_GRAY */

.tpv-quote { background: #0f3a42; align-items: center; justify-content: center; gap: 7%; }  /* QUOTE_BG */
.tpv-quote .q {
  position: absolute; top: 3%; left: 8%; color: rgba(255,255,255,.55);
  font-size: calc(34px * var(--font-scale)); font-weight: 700; line-height: 1.1;
}
.tpv-quote .t1 { height: 8.5%; width: 74%; background: #fff; }
.tpv-quote .t2 { height: 8.5%; width: 52%; background: rgba(255,255,255,.82); }
.tpv-quote .mist { height: 2.5%; width: 26%; margin-top: 4%; background: #7fc4cc; }  /* TEAL_MIST 短線 */

.tpv-cover { background: #232a5c; padding: 9%; position: relative; justify-content: flex-end; gap: 5%; }
.tpv-cover .no { position: absolute; right: 7%; top: 1%; font-size: 22px; font-weight: 800; color: rgba(255,255,255,.16); }
.tpv-cover .bar { height: 3%; width: 28%; background: #22c1c3; }
.tpv-cover .h { height: 9%; background: #fff; }
.tpv-cover .h1 { width: 92%; }
.tpv-cover .h2 { width: 58%; }
.tpv-cover .t { height: 3.5%; width: 55%; margin-top: 2%; background: rgba(255,255,255,.55); }
.tpv-editorial { background: #f7f5f0; padding: 9%; position: relative; justify-content: center; gap: 6%; }
.tpv-editorial .top { position: absolute; left: 9%; right: 9%; top: 9%; height: 2px; background: #232a5c; opacity: .35; }
.tpv-editorial .k { font-size: 6px; letter-spacing: .12em; color: #1f7a8c; font-weight: 700; }
.tpv-editorial .drop { position: absolute; left: 9%; bottom: 20%; font-size: 22px; font-weight: 800; color: #1f7a8c; }
.tpv-editorial .h { height: 8%; width: 88%; background: #232a5c; }
.tpv-editorial .t { height: 4%; width: 64%; background: #969cba; }
.tpv-poster { background: #c00703; padding: 9%; position: relative; justify-content: flex-end; gap: 5%; }
.tpv-poster .no { position: absolute; right: 6%; top: 2%; font-size: 16px; font-weight: 800; color: rgba(255,255,255,.22); }
.tpv-poster .bar { height: 3%; width: 24%; background: #f5a623; }
.tpv-poster .h { height: 10%; background: #fff; }
.tpv-poster .h1 { width: 92%; }
.tpv-poster .h2 { width: 58%; }

.tpv-generic { background: #f5f6fc; }
.tpv-generic .hero { flex: 1; margin: 9%; background: linear-gradient(135deg, #dde5f0, #c8d4e8); border-radius: 3px; }
.tpv-generic .txt { height: 8%; width: 64%; margin: 0 9% 9%; background: #232a5c; }

.genrow { display: flex; gap: 10px; align-items: center; margin: 22px 0 14px; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 16px;
  font: inherit; font-size: calc(14px * var(--font-scale)); cursor: pointer; color: var(--ink);
}
.btn.primary { background: var(--a); color: #fff; border-color: var(--a); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.gen-note { font-size: calc(13px * var(--font-scale)); color: var(--faint); }
.gen-note.ok { color: var(--ok); }
.gen-note.warn { color: var(--warn); }
.gen-note.fallback { color: #8a6d00; } /* LLM 額度盡走模版:黃色警告(同降級 pill 色) */

/* ---- 配圖縮圖條(換圖選單):橫向 scroll;首項「自動」文字 chip ---- */
.imgrow { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 14px; align-items: center; }
.imgauto {
  flex: none; height: 96px; padding: 0 16px; border: 2px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--mut); font: inherit; font-size: calc(13px * var(--font-scale)); cursor: pointer;
}
.imgauto:hover { border-color: var(--a); color: var(--a); }
.imgauto.sel { border-color: var(--a); background: color-mix(in srgb, var(--a) 14%, var(--surface)); color: var(--ink); font-weight: 600; }
.imgnone { border-style: dashed; }
.imgnone.sel { border-style: solid; }
.imgitem { flex: none; width: 96px; padding: 0; border: none; background: none; cursor: pointer; font: inherit; text-align: left; }
.imgitem .imgbox {
  position: relative;
  display: block; width: 96px; height: 96px; border-radius: 8px; overflow: hidden;
  border: 2px solid transparent; transition: border-color .15s, transform .15s;
}
.imgitem .imgbox img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.imgzoom {
  position: absolute; right: 5px; bottom: 5px; width: 20px; height: 20px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 16, 34, .72); color: #fff; font-size: 12px; line-height: 1;
  opacity: 0; transition: opacity .15s; pointer-events: none;
}
.imgitem:hover .imgzoom, .imgitem:focus-visible .imgzoom { opacity: 1; }
.imgitem:hover .imgbox { border-color: var(--line); }
.imgitem.sel .imgbox { border-color: var(--a); transform: scale(1.03); }
.imgitem .img-alt {
  display: block; margin-top: 3px; font-size: calc(11px * var(--font-scale)); line-height: 1.3; color: var(--faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.img-low {
  display: inline-block; margin-top: 3px; padding: 1px 5px; border-radius: 4px;
  font-size: 10px; color: #8a5a00; background: #fff3d6;
}

/* ---- 配圖 lightbox:點縮圖看大圖 ---- */
.img-lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; background: rgba(10, 12, 22, .9);
}
.img-lightbox[hidden] { display: none; }
body.lightbox-open { overflow: hidden; }
.img-lightbox-fig {
  margin: 0; width: min(92vw, 1400px); max-height: 84vh;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.img-lightbox-img {
  width: auto; height: auto; max-width: 100%; max-height: 74vh; object-fit: contain;
  border-radius: 8px; background: #fff; box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
}
.img-lightbox-cap {
  max-width: 80vw; color: #e9ecf4; font-size: calc(13px * var(--font-scale));
  text-align: center; overflow-wrap: anywhere;
}
.img-lightbox-close {
  position: absolute; top: 16px; right: 18px; width: 44px; height: 44px;
  border-radius: 50%; border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(0, 0, 0, .28); color: #fff; font-size: 18px; cursor: pointer;
}
.img-lightbox-close:hover { background: rgba(255, 255, 255, .14); }
.img-lightbox-actions { margin-top: 18px; display: flex; gap: 10px; align-items: center; }
@media (max-width: 520px) {
  .img-lightbox { padding: 14px; }
  .img-lightbox-img { max-height: 68vh; }
  .img-lightbox-close { top: 10px; right: 10px; }
}

/* ---- 版本歷史條:v 號膠囊,latest 高亮 ---- */
.verrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.verlabel { font-size: calc(11px * var(--font-scale)); color: var(--faint); letter-spacing: .1em; }
.verchip {
  border: 1px solid var(--line); background: var(--surface); color: var(--mut); border-radius: 999px;
  padding: 2px 12px; font: inherit; font-size: calc(12px * var(--font-scale)); cursor: pointer;
}
.verchip:hover { border-color: var(--a); color: var(--a); }
.verchip.sel { background: var(--a); border-color: var(--a); color: #fff; font-weight: 600; }

/* 歷史版本圖檔 404 占位(方圖格) */
.oldver-missing {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--faint); font-size: calc(12px * var(--font-scale)); padding: 10px; text-align: center;
}

.progress {
  margin: 16px 0; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; font-size: calc(13px * var(--font-scale)); color: var(--mut); display: none;
}
.progress.on { display: block; }
.progress .step { display: flex; gap: 8px; padding: 2px 0; opacity: .45; }
.progress .step.done { opacity: 1; color: var(--ok); }
.progress .step.doing { opacity: 1; color: var(--a); font-weight: 600; }

.materials { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 24px; margin-top: 22px; align-items: stretch; }
.matcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column; height: 100%;
}
.matcard .mat-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); font-size: calc(13px * var(--font-scale)); font-weight: 600;
}
.matcard .mat-body { padding: 14px; display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; flex: 1; }
.matcard .mat-body.reel-mode { flex-direction: column; }

/* 方圖預覽:等比例縮的 1080x1080 */
.sqcanvas {
  width: 200px; height: 200px; flex: none; border-radius: 12px; position: relative;
  overflow: hidden; border: 1px solid var(--line); background: #f5f6fc;
}
/* reels 預覽:1080x1920 等比 */
.reelcanvas {
  width: 130px; height: 231px; flex: none; border-radius: 12px; position: relative;
  overflow: hidden; border: 1px solid var(--line); background: #1c2247;
}
.reelstrip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.sq-inner { position: absolute; inset: 0; display: flex; flex-direction: column; }
.sq-band { height: 26px; background: linear-gradient(90deg, #1f7a8c, #22c1c3); display: flex; align-items: center; padding: 0 10px; }
.sq-band span { color: #fff; font-size: calc(11px * var(--font-scale)); font-weight: 600; }
.sq-hero { flex: 1; background: linear-gradient(135deg, #dde5f0, #c8d4e8); display: grid; place-items: center; position: relative; overflow: hidden; }
.sq-hero .hero-text { font-size: calc(22px * var(--font-scale)); opacity: .3; }
.sq-title { padding: 8px 10px 2px; font-size: calc(11px * var(--font-scale)); font-weight: 700; color: #232a5c; line-height: 1.3; }
.sq-caption { padding: 0 10px 8px; font-size: calc(11px * var(--font-scale)); color: #5a6082; }
.sq-cta { padding: 4px 10px 8px; font-size: calc(11px * var(--font-scale)); color: #7e57c2; font-weight: 600; }
.reel-slide { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; padding: 10px; }
.reel-slide .rs-num { position: absolute; top: 8px; left: 8px; font-size: calc(11px * var(--font-scale)); color: rgba(255,255,255,.6); }
.reel-slide .rs-text { color: #fff; font-size: calc(11px * var(--font-scale)); font-weight: 700; line-height: 1.4; text-shadow: 0 1px 4px rgba(0,0,0,.4); }
.reel-slide .rs-sub { color: rgba(255,255,255,.8); font-size: calc(11px * var(--font-scale)); margin-top: 4px; }
.reel-bg-1 { background: linear-gradient(160deg, #1c2247, #2a4a7f); }
.reel-bg-2 { background: linear-gradient(160deg, #1f7a8c, #164a5c); }
.reel-bg-3 { background: linear-gradient(160deg, #4527a0, #241460); }
.reel-bg-4 { background: linear-gradient(160deg, #00695c, #003d33); }

.captionbox { flex: 1 1 240px; min-width: 0; }
.captionbox .cp-label { font-size: calc(11px * var(--font-scale)); color: var(--faint); letter-spacing: .1em; margin-bottom: 4px; }
.captionbox .cp-text {
  font-size: calc(13px * var(--font-scale)); line-height: 1.7; color: var(--ink); white-space: pre-wrap;
  background: var(--bg); padding: 10px 12px; border-radius: 9px;
}
.captionbox .cp-tags { margin-top: 6px; font-size: calc(12px * var(--font-scale)); color: var(--a2); }
.mat-actions { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); margin-top: auto; }
.mat-actions .btn { font-size: calc(13px * var(--font-scale)); padding: 5px 12px; }

.discuss { margin-top: 40px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.discuss-head { padding: 10px 14px; font-size: calc(14px * var(--font-scale)); font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; }
.discuss-body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.thread-item { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: calc(13px * var(--font-scale)); }
.thread-item .t-meta { font-size: calc(11px * var(--font-scale)); color: var(--faint); }
.thread-item .t-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 5px; }
.t-before, .t-after { padding: 7px 9px; border-radius: 8px; font-size: calc(12px * var(--font-scale)); }
.t-before { background: #fdf0f0; color: #8a3030; text-decoration: line-through; }
.t-after { background: #eef7f0; color: #1e5c38; }
.discuss-input { display: flex; gap: 8px; margin-top: 10px; }
.discuss-input textarea { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: calc(13px * var(--font-scale)); resize: vertical; }
.empty-main { color: var(--faint); text-align: center; padding: 80px 20px; font-size: calc(14px * var(--font-scale)); }
.empty-main a { color: var(--a); }

/* ---- v5 真圖預覽(/materials;尺寸與 CSS 模擬塊相同,模擬塊保留為空態/占位)---- */
.mat-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
a.btn { display: inline-block; text-decoration: none; }

/* 方圖變體 chips(明/暗 × 純文字/帶圖)與導語三案 */
.varrow { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.varchip {
  border: 1px solid var(--line); background: var(--surface); color: var(--mut);
  font: inherit; font-size: calc(12px * var(--font-scale)); padding: 4px 9px; border-radius: 99px; cursor: pointer;
}
.varchip:hover { border-color: var(--a); color: var(--a); }
.varchip.sel { background: var(--a); border-color: var(--a); color: #fff; font-weight: 600; }
.leadbox { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; flex: 1 1 100%; }
.leadrow {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: start;
}
.lead-txt { font-size: calc(13px * var(--font-scale)); line-height: 1.5; grid-column: 1 / 2; }
.lead-url { font-size: calc(11px * var(--font-scale)); color: var(--faint); grid-column: 1 / 2; word-break: break-all; }
.leadrow .btn.small { grid-column: 2 / 3; grid-row: 1 / 3; align-self: center; font-size: calc(12px * var(--font-scale)); padding: 4px 9px; }

/* Hashtags 卡:chips + 編輯 + 獨立版本 */
.taglist { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.hashtag {
  background: var(--surface-2); color: var(--a); border: 1px solid var(--line);
  font-size: calc(13px * var(--font-scale)); font-weight: 600; padding: 4px 10px; border-radius: 99px;
}
.tagedit { display: flex; gap: 8px; }
.tagedit input {
  flex: 1; min-width: 0; font: inherit; font-size: calc(13px * var(--font-scale)); padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink);
}
.tagtext {
  font-size: calc(13px * var(--font-scale)); line-height: 1.6; color: var(--mut);
  background: var(--surface-2); border: 1px dashed var(--line); border-radius: 8px;
  padding: 8px 10px; word-break: break-all;
}

/* 版型/風格自動建議列 */
.suggestrow {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; margin-bottom: 18px; font-size: calc(13px * var(--font-scale)); color: var(--ink);
}
.suggestrow .sug-lab {
  font-size: calc(11px * var(--font-scale)); letter-spacing: .12em; color: #fff; background: var(--a);
  padding: 2px 7px; border-radius: 99px;
}
.suggestrow .sug-why { color: var(--faint); }
.suggestrow .btn.small { padding: 3px 9px; font-size: calc(12px * var(--font-scale)); }

/* reels:單張預覽 + 幕次 chips(取代 4 張並排) */
.slidechips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.slidechip {
  border: 1px solid var(--line); background: var(--surface); color: var(--mut);
  font: inherit; font-size: calc(12px * var(--font-scale)); padding: 4px 10px; border-radius: 99px; cursor: pointer;
}
.slidechip.sel { background: var(--a); border-color: var(--a); color: #fff; font-weight: 600; }
.reelview { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; width: 100%; }
.reelstage {
  width: min(220px, 100%); height: auto; aspect-ratio: 1080 / 1920; flex: none; border-radius: 12px; overflow: hidden;
  position: relative; border: 1px solid var(--line); background: #1c2247;
}
.reelstage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slideinfo { flex: 1 1 140px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.slideinfo b { font-size: calc(14px * var(--font-scale)); color: var(--ink); }
.slideinfo span { font-size: calc(12px * var(--font-scale)); color: var(--mut); }

/* 文案標題旁的小字「討論/修改」 */
.linkbtn { min-height: 24px;
  border: 0; background: none; color: var(--a); font: inherit; font-size: calc(12px * var(--font-scale));
  cursor: pointer; padding: 0 2px; text-decoration: underline; text-underline-offset: 2px;
}
.linkbtn:hover { color: var(--ink); }

.leadbtns { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.btn.ghost { background: var(--surface); color: var(--mut); border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--a); color: var(--a); }

/* 查詢:rail 搜尋框 + 結果片段 */
.rail-search { padding: 0 10px 8px; }
.rail-search input {
  width: 100%; box-sizing: border-box; font: inherit; font-size: calc(13px * var(--font-scale));
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
.rail-search input:focus { outline: none; border-color: var(--a); }
.searchmeta { font-size: calc(12px * var(--font-scale)); color: var(--faint); padding: 4px 10px 6px; display: flex; gap: 8px; align-items: center; }
.ci-snip { font-size: calc(12px * var(--font-scale)); color: var(--mut); line-height: 1.45; padding: 2px 10px 8px; }
.ci-snip mark { background: #fff2a8; color: inherit; padding: 0 1px; }

/* 討論區:結構化對象列 */
.discuss-ctx { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 0 4px; }
.ctx-lab { font-size: calc(11px * var(--font-scale)); color: var(--faint); letter-spacing: .08em; }
.ctxchip {
  border: 1px solid var(--line); background: var(--surface); color: var(--mut);
  font: inherit; font-size: calc(12px * var(--font-scale)); padding: 3px 9px; border-radius: 99px; cursor: pointer;
}
.ctxchip.sel { background: var(--a); border-color: var(--a); color: #fff; font-weight: 600; }
.ctx-ex {
  flex-basis: 100%; font-size: calc(12px * var(--font-scale)); color: var(--mut); background: var(--surface-2);
  border: 1px dashed var(--line); border-radius: 8px; padding: 6px 9px; margin-top: 2px;
}

/* 搜尋列日期選擇 */
.datebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 6px; margin-top: 6px; align-items: center; }
.datebar .dfield { display: flex; align-items: center; gap: 6px; min-width: 0; }
.datebar .dfield span { flex: none; color: var(--mut); font-size: calc(11px * var(--font-scale)); }
.datebar #d-clear { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.datebar input {
  flex: 1 1 auto; min-width: 0; font: inherit; font-size: calc(11px * var(--font-scale)); padding: 4px 5px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.datebar input::placeholder { color: var(--faint); opacity: .8; }
.datebar span { color: var(--faint); font-size: calc(11px * var(--font-scale)); }
.quickdate { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.quickdate button {
  border: 1px solid var(--line); background: var(--surface); color: var(--mut);
  font: inherit; font-size: calc(11px * var(--font-scale)); padding: 3px 8px; border-radius: 99px; cursor: pointer;
}
.quickdate button:hover { border-color: var(--a); color: var(--a); }
.batch-all {
  display: block; width: 100%; margin-top: 6px; box-sizing: border-box;
  border: 1px dashed var(--line); background: var(--surface); color: var(--mut);
  font: inherit; font-size: calc(11px * var(--font-scale)); padding: 6px 8px; border-radius: 8px; cursor: pointer;
}
.batch-all:hover:not(:disabled) { border-color: var(--a); color: var(--a); }
.batch-all:disabled { opacity: .5; cursor: default; }

/* 批次設定列:有選取時固定在視窗底部 */
.batchbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 10px max(16px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(10, 20, 40, .12);
}
.batchbar[hidden] { display: none; }
.batch-count { font-size: calc(13px * var(--font-scale)); font-weight: 700; color: var(--ink); white-space: nowrap; }
.batch-fieldwrap { display: flex; align-items: center; gap: 6px; font-size: calc(12px * var(--font-scale)); color: var(--mut); }
.batchbar select {
  font: inherit; font-size: calc(12px * var(--font-scale)); padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink);
  max-width: 38vw;
}
.batchbar select:focus { outline: none; border-color: var(--a); }
.batch-progress { width: 110px; height: 8px; flex: none; accent-color: var(--a); }
.batch-progress[hidden] { display: none; }
.batch-note { flex: 1 1 160px; min-width: 0; font-size: calc(12px * var(--font-scale)); color: var(--faint); }
.batch-note.ok { color: var(--ok); }
.batch-note.err { color: #b3261e; }
/* 批次列按鈕:套用(設定)與生成素材;生成會呼叫 LLM,用外框強調、不搶主色 */
.batchbar .btn { font-size: calc(13px * var(--font-scale)); padding: 6px 14px; white-space: nowrap; }
.batch-gen { border-color: var(--a); color: var(--a); background: var(--surface); font-weight: 600; }
.batch-gen:hover:not(:disabled) { background: var(--a); color: #fff; }
body.batch-open .main { padding-bottom: 96px; }

.themerow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0 2px; }
.themerow .verlabel { font-size: calc(11px * var(--font-scale)); color: var(--faint); letter-spacing: .08em; }

/* 使用說明頁 */
.rail-help { display:block; margin-top:0; padding:8px 10px; font-size: calc(12px * var(--font-scale)); color:var(--mut); text-decoration:none; border-top:1px solid var(--line); }
.rail-help:first-of-type { margin-top:auto; }
.rail-help:hover { color:var(--a); }
.helpwrap { max-width: 760px; padding: 28px 32px 60px; }
.helpwrap h1 { font-size: calc(22px * var(--font-scale)); margin: 0 0 6px; }
.helpintro { color: var(--mut); font-size: calc(13px * var(--font-scale)); line-height: 1.7; margin: 0 0 18px; }
.helpsteps { list-style: none; padding: 0; margin: 0 0 24px; display: flex; flex-direction: column; gap: 12px; }
.helpsteps li { display: flex; gap: 12px; align-items: flex-start; }
.helpsteps .num { flex: none; width: 26px; height: 26px; border-radius: 99px; background: var(--a); color: #fff; font-weight: 700; font-size: calc(13px * var(--font-scale)); display: grid; place-items: center; }
.helpsteps b { font-size: calc(14px * var(--font-scale)); }
.helpsteps p { margin: 3px 0 0; font-size: calc(13px * var(--font-scale)); color: var(--mut); line-height: 1.65; }
.helpwrap h2 { font-size: calc(15px * var(--font-scale)); margin: 22px 0 10px; }
.helpterms { margin: 0; display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: calc(13px * var(--font-scale)); }
.helpterms dt { font-weight: 700; color: var(--ink); }
.helpterms dd { margin: 0; color: var(--mut); line-height: 1.65; }

.helpnote { font-size: calc(12px * var(--font-scale)); color: var(--faint); background: var(--surface-2); border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; margin: 0 0 14px; }

/* 討論抽屜(右側) */
.tabs { display: flex; gap: 4px; margin: 18px 0 16px; border-bottom: 1px solid var(--line); }
.tab {
  border: 1px solid var(--line); border-bottom: 0; background: var(--surface-2); color: var(--mut);
  padding: 7px 14px; border-radius: 8px 8px 0 0; font: inherit; font-size: calc(13px * var(--font-scale)); cursor: pointer;
}
.tab.on { background: var(--surface); color: var(--ink); font-weight: 700; border-color: var(--line); }
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: 340px; background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: -8px 0 28px rgba(0,0,0,.12);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; z-index: 40;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; font-size: calc(14px * var(--font-scale)); }
.drawer-ctx { font-size: calc(13px * var(--font-scale)); color: var(--mut); display: flex; flex-direction: column; gap: 6px; }
.drawer-note, #drawer-note {
  width: 100%; box-sizing: border-box; font: inherit; font-size: calc(13px * var(--font-scale)); padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px; resize: vertical; min-height: 90px;
}
.drawer-actions { display: flex; align-items: center; gap: 10px; }
.drawer-hint { font-size: calc(11px * var(--font-scale)); color: var(--faint); }
.copygrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1000px) { .copygrid { grid-template-columns: 1fr; } }

/* 版型/風格/色系:統一欄位對齊 */
.field { display: grid; grid-template-columns: 92px 1fr; gap: 4px 12px; margin: 24px 0 10px; align-items: start; }
.field-lab { display: flex; flex-direction: column; gap: 2px; padding-top: 4px; }
.field-lab b { font-size: calc(13px * var(--font-scale)); color: var(--ink); }
.field-lab .hint { font-size: calc(11px * var(--font-scale)); color: var(--faint); }
.field-body { min-width: 0; }
.field-desc { font-size: calc(12px * var(--font-scale)); color: var(--faint); margin-top: 5px; line-height: 1.45; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; border: 1px solid rgba(0,0,0,.15); vertical-align: -1px; }
.stylerow, .themerow { margin: 0; }

/* 顯示設定（齒輪） */
.settings-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; margin-right: 10px; border-radius: 8px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25); color: #fff; }
.settings-btn:hover { background: rgba(255,255,255,.26); }
.settings-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60; }
.settings-backdrop[hidden], .settings-panel[hidden] { display: none; }
.settings-panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 94vw); background: var(--surface); color: var(--ink); z-index: 61; display: flex; flex-direction: column; box-shadow: -8px 0 28px rgba(0,0,0,.18); }
.settings-head { display: flex; justify-content: space-between; align-items: center; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.settings-head b { font-size: calc(15px * var(--font-scale)); }
.settings-body { padding: 14px 16px 40px; overflow: auto; display: flex; flex-direction: column; gap: 20px; }
.settings-group > b { font-size: calc(13px * var(--font-scale)); }
.settings-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.settings-chips button { min-height: 32px; border: 1px solid var(--line); background: var(--surface-2); color: var(--mut); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: calc(12px * var(--font-scale)); cursor: pointer; }
.settings-chips button:hover { border-color: var(--a); }
.settings-chips button[aria-pressed="true"] { background: var(--a); color: #fff; border-color: var(--a); font-weight: 600; }
@media (max-width: 820px) { .settings-chips button { min-height: 44px; } }

/* header 檢視切換 */
.viewsw { display: inline-flex; border: 1px solid rgba(255,255,255,.28); border-radius: 99px; overflow: hidden; margin-right: 10px; }
.viewsw button { background: transparent; border: 0; color: #fff; font: inherit; font-size: calc(12px * var(--font-scale)); padding: 4px 12px; cursor: pointer; white-space: nowrap; }
.viewsw button.on { background: rgba(0,0,0,.30); color: #fff; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(255,255,255,.22); }

/* 抽屜內歷史 */
.drawer-history { max-height: 40vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.drawer-history:empty { display: none; }

/* 抽屜開啟時主區讓位,不被覆蓋 */
/* 桌面抽屜:與左欄同寬(268)、貼齊 shell 右緣、從 topbar 下方開始 → 左右對稱 */
@media (min-width: 821px) {
  body.drawer-open .main { padding-right: 298px; }
  .drawer {
    top: var(--topbar-h, 62px);
    height: calc(100dvh - var(--topbar-h, 62px));
    width: 268px;
    right: max(0px, calc((100vw - 1240px) / 2));
    border-radius: 0; border-left: 1px solid var(--line); background: var(--surface);
  }
}

/* 手機/小平板:rail 收在上方、主區單欄;抽屜＝底部工作表(bottom sheet) */
.drawer-grip { display: none; }
.drawer-backdrop { display: none; }
:focus-visible { outline: 2px solid var(--a) !important; outline-offset: 2px !important; }
@media (max-width: 820px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
  .brand { min-width: 0; }
  .brand .sub { display: none; }
  .topright { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
  .shell { display: block; }
  .rail { width: auto; border-right: 0; border-bottom: 1px solid var(--line); max-height: 42vh; overflow-y: auto; }
  .shell.rail-collapsed .rail { width:44px; max-height:none; padding:8px 7px; border-bottom:0; }
  .shell.rail-collapsed .rail-help { display:none; }
  .shell.rail-collapsed .rail-head { min-height:28px; }
  .main { padding: 18px 14px 96px; }
  .materials { grid-template-columns: 1fr; }
  .field { grid-template-columns: 1fr; }
  .field-lab { flex-direction: row; align-items: baseline; gap: 8px; padding-top: 0; }
  .ci-title { font-size: calc(14px * var(--font-scale)); }
  .caseitem .ci-meta { flex-wrap: wrap; }
  button, .btn-mini, .quickdate button, .tab, .stylechip, .ctxchip { min-height: 44px; }
  .btn-mini { padding: 6px 10px; }
  .quickdate button, .tab, .ctxchip { padding: 8px 12px; }
  body.drawer-open { overflow: hidden; }
  body.drawer-open .main { padding-right: 14px; }
  .drawer-history { max-height: 50vh; }
  .genrow { position: sticky; bottom: 0; z-index: 20; margin: 0; padding: 10px 0 4px;
    background: linear-gradient(180deg, rgba(245,246,252,0), var(--bg) 28%); }
  .genrow #gen-btn { flex: 1; min-height: 44px; }
  /* 批次設定列:手機整條換行;高於 rail sheet(z70),清單底部留出空間 */
  .batchbar { gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); z-index: 80; }
  .batch-count, .batchbar #batch-clear { flex: none; white-space: nowrap; }
  .batch-fieldwrap { flex: 0 0 auto; white-space: nowrap; }
  .batch-fieldwrap span { white-space: nowrap; }
  .batchbar select { max-width: 100%; }
  .batch-progress { width: 100%; flex: 1 0 100%; order: 8; }
  #batch-field { width: auto; }
  #batch-value { flex: 1 1 120px; min-width: 0; }
  .batchbar #batch-apply { flex: 1 1 auto; }
  .batchbar #batch-generate { flex: 1 1 auto; }
  .batch-note { flex: 1 0 100%; order: 9; }
  body.batch-open .main { padding-bottom: 200px; }
  body.batch-open .genrow { bottom: 150px; }
  body.batch-open .rail #case-list { padding-bottom: 170px; }
  .sqcanvas { width: 100%; max-width: 260px; height: auto; aspect-ratio: 1; }
  .reelcanvas { width: 100%; max-width: 180px; height: auto; aspect-ratio: 1080 / 1920; }
  /* 手機:預覽圖與文案垂直堆疊,避免文案被擠成一直欄 */
  .matcard .mat-body { flex-direction: column; }
  .captionbox, .leadbox { flex: 0 0 auto; width: 100%; min-width: 0; }
  .matcard .mat-body { gap: 10px; }
  .viewsw { display: none; }              /* 手機單欄,不需要分頁/抽屜切換 */
  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 39;
    background: rgba(10, 30, 40, .38); backdrop-filter: blur(2px);
  }
  .drawer-backdrop[hidden] { display: none; }
  .drawer {
    left: 0; right: 0; width: auto; max-width: none; top: auto; bottom: 0;
    max-height: 88dvh; border-radius: 16px 16px 0 0; border-left: 0;
    box-shadow: 0 -12px 32px rgba(0,0,0,.22);
    padding: 8px 16px 18px; overscroll-behavior: contain;
  }
  .drawer-grip {
    display: block; width: 44px; height: 5px; border-radius: 99px;
    background: rgba(0,0,0,.18); margin: 4px auto 8px; flex: 0 0 auto;
  }
}
@media (max-width: 520px) { .drawer { max-height: 92dvh; } }

/* 桌面:左欄固定視窗高,只有案件列表捲動 */
@media (min-width: 821px) {
  .topbar { position: sticky; top: 0; z-index: 50; }
  .shell { align-items: flex-start; }
  .rail { position: sticky; top: var(--topbar-h, 62px); height: calc(100vh - var(--topbar-h, 62px)); height: calc(100dvh - var(--topbar-h, 62px)); overflow: hidden; }
  #case-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .rail-search, .newcase, .rail-head, .rail-help { flex: none; }
  .rail-help { margin-top: 0; }
}

/* 手機:素材案列表做成全螢幕清單(同一個 .rail 節點,不搬 DOM) */
@media (max-width: 820px) {
  .rail { max-height: none; overflow: visible; }
  .rail .rail-search, .rail #case-list, .rail .newcase, .rail-help { display: none; }
  .rail-head { cursor: pointer; }
  .rail-title::after { content: " ▸"; }
  body.rail-sheet-open { overflow: hidden; }
  body.rail-sheet-open .rail {
    position: fixed; inset: 0; z-index: 70; width: auto; max-height: none;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--surface); overflow: hidden;
    padding: max(14px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  }
  body.rail-sheet-open .rail .rail-search,
  body.rail-sheet-open .rail #case-list,
  body.rail-sheet-open .rail .newcase { display: revert; }
  body.rail-sheet-open .rail #case-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  body.rail-sheet-open .rail .rail-help { display: block; }
  body.rail-sheet-open .rail-title::after { content: ""; }
}

/* 文字草稿 → 合成 */
.draftbox { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 12px 14px; margin: 14px 0 6px; }
.drafthead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.drafthead .hint { flex: 1; font-size: calc(12px * var(--font-scale)); color: var(--faint); }
.draftbody { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.draftgrid { display: grid; grid-template-columns: 1fr 170px; gap: 10px; }
.draftbody label { display: flex; flex-direction: column; gap: 4px; font-size: calc(12px * var(--font-scale)); color: var(--mut); }
.draftbody input, .draftbody textarea {
  font: inherit; font-size: calc(13px * var(--font-scale)); padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--ink); width: 100%; box-sizing: border-box;
}
.draftslides { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.draftpreview { display: flex; gap: 14px; align-items: flex-start; }
.draftpreview .sqcanvas { width: 220px; height: 220px; flex: none; }
.draftmeta { font-size: calc(12px * var(--font-scale)); color: var(--faint); }
.draftactions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.imgupload {
  border: 1px dashed var(--line); border-radius: 10px; padding: 0 14px; min-height: 64px;
  display: inline-flex; align-items: center; font: inherit; background: var(--surface);
  font-size: calc(12px * var(--font-scale)); color: var(--mut); cursor: pointer;
}
.imgupload:hover { border-color: var(--a); color: var(--a); }
@media (max-width: 820px) {
  .draftgrid, .draftslides { grid-template-columns: 1fr; }
  .draftpreview { flex-direction: column; }
  .draftpreview .sqcanvas { width: 100%; max-width: 260px; height: auto; aspect-ratio: 1; }
}
.draftfact { font-size: calc(12px * var(--font-scale)); color: #8a6d00; background: #fff8e1; border: 1px solid #f0e0b0; border-radius: 8px; padding: 6px 10px; }

/* 文字稿版本 chips 與一鍵生成防呆 */
.draftvers { display: inline-flex; gap: 4px; margin: 0 2px; }
.oneclick {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  border: 1px solid #f0e0b0; background: #fff8e1; border-radius: 8px;
  padding: 8px 10px; margin-top: 8px; font-size: calc(13px * var(--font-scale));
}
.oneclick span { color: var(--mut); }

/* 觸控目標:桌面 mini/link 不低於 24px;手機按鈕 44px */
.btn-mini { min-height: 24px; }
.linkbtn { min-height: 24px; }
@media (max-width: 820px) { .btn, a.btn, .linkbtn { min-height: 44px; } }

/* 變體選擇器:橫向捲動 + 放大,不再擠成多行 */
.varrow { flex-wrap: wrap; overflow-x: visible; gap: 8px; max-width: 100%;
  padding: 4px 4px 6px; margin: -4px -4px 8px; -webkit-overflow-scrolling: touch; }
.varrow::-webkit-scrollbar { height: 6px; }
.varchip { white-space: nowrap; min-height: 32px; padding: 6px 12px; font-size: calc(12px * var(--font-scale)); }
@media (max-width: 820px) { .varchip { min-height: 40px; padding: 8px 14px; } }
@media (max-width: 820px) {
  .btn-mini, .varchip, .linkbtn { min-height: 44px; }
}
.btn-mini { font: inherit; font-size: calc(12px * var(--font-scale)); line-height: 1.2; }

/* 視覺 review 第二輪 */
.suggestrow { margin-left: 0; }
@media (min-width: 821px) { .suggestrow { margin-left: 104px; } }
.cp-tags .tag { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--mut); margin: 0 4px 4px 0; font-size: calc(11px * var(--font-scale)); }
.leadbtns { flex-direction: row; align-items: center; justify-content: flex-end; gap: 6px; }
.imgbox { background: var(--chip); }
.imgupload { min-height: 96px; }
.imgitem.img-broken .imgbox { background: #e9e9ee; }
.varrow.can-scroll {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent 100%);
}
@media (max-width: 820px) {
  .genrow { padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
  .leadrow { grid-template-columns: 1fr; }
  .lead-url { word-break: normal; overflow-wrap: anywhere; }
  .rail-search input, .datebar input, .tagedit input, .draftbody input, .draftbody textarea,
  .drawer-note, .np-form input, .rail-title, .rail-head, .rail-help { min-height: 44px; }
}
/* P3 polish:選中態/切換對比/卡片等高 */
.caseitem.cur { background: color-mix(in srgb, var(--a) 14%, var(--surface)); }
.viewsw button.on { background: rgba(0,0,0,.30); }
.matcard { display: flex; flex-direction: column; }
.matcard .mat-body { flex: 1 1 auto; }
.matcard .mat-actions { margin-top: auto; }

/* 手機(<=520):壓縮設定區高度,讓草稿/產出更早出現 */
@media (max-width: 520px) {
  .field { margin: 14px 0 6px; }
  .sect { margin: 20px 0 10px; }
  .tplrow { gap: 8px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; align-items: flex-start; }
  .tplcard { flex: 0 0 46%; width: auto; }
  .tplbtn { width: 100%; padding: 5px 6px 7px; }
  .tplbtn .tpv-desc { display: -webkit-box; -webkit-line-clamp: 2; }
  .tplbtn .tpv { aspect-ratio: 4 / 3; }
  .tplinfo { min-height: 44px; font-size: calc(13px * var(--font-scale)); }
  .tpldetail { font-size: calc(13px * var(--font-scale)); }
  /* 一次生成是旁路,不該在手機 sticky 搶主線 CTA */
  .genrow { position: static; background: none; padding: 6px 0; flex-wrap: wrap; }
  .genrow #gen-btn { flex: none; width: auto; }
  .genrow #gen-note { flex: 1 0 100%; }
}

/* 工序分組:A 三階段卡片 / B 輕量色條;段與段間距 44px(手機 30/24) */
.stages { display: flex; flex-direction: column; gap: 44px; margin: 10px 0 30px; }
.stage { min-width: 0; }
.stage-head { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.stage-head h2 { font-size: calc(16px * var(--font-scale)); margin: 0; }
.stage-head .num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--a); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex: none;
}
.stage-head .hint { font-size: calc(12px * var(--font-scale)); color: var(--faint); }
.stages-a .stage {
  background: var(--surface);
  background: color-mix(in srgb, var(--a) 3.5%, var(--surface));
  border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px 20px;
}
.stages-a .stage .draftbox { border: 0; background: transparent; padding: 0; }
.stages-b .stage { background: transparent; border: 0; padding: 0; }
.stages-b .stage-head {
  background: linear-gradient(90deg, var(--surface-2), transparent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--a) 9%, transparent), transparent);
  border-left: 4px solid var(--a); border-bottom: 1px solid var(--line);
  padding: 8px 12px; border-radius: 0 8px 8px 0;
}
.stages-b .stage-head .num { background: transparent; color: var(--a); width: auto; height: auto; font-size: 15px; }
.stages-b .stage3 .genrow {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
}
/* ① 與 ③ 的第一個欄位緊貼段頭,不要多一段上緣留白 */
.stage1 .stage-head + .field, .stage3 .stage-head + .field { margin-top: 0; }
/* ③ 的生成按鈕不要在窄螢幕折成兩行 */
.genrow #compose-main { white-space: nowrap; }
/* ③ 內 色系 → 配圖:配圖的 .sect 是段內標題,不是頁面級分段 */
.stage3 .sect { margin: 18px 0 8px; }
@media (max-width: 820px) {
  .stages { gap: 30px; margin: 6px 0 24px; }
  .stages-a .stage { padding: 13px 12px 15px; border-radius: 12px; }
}
@media (max-width: 520px) {
  .stages { gap: 24px; }
  .stage-head { margin-bottom: 11px; }
  .stage-head .hint { display: none; }
}
/* 手機可點區域一律 ≥44px（含 topbar 文件連結、齒輪、版本 chips） */
@media (max-width: 820px) {
  .doclinks a { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 3px; }
  .settings-btn { min-width: 44px; min-height: 44px; }
  #rail-toggle { min-width: 44px; min-height: 44px; }
  .imgupload { min-width: 44px; }
  .verchip, .slidechip { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .varchip { min-height: 44px; }
  .linkbtn { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .settings-head .btn-mini { min-width: 44px; }
  .settings-chips button { min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* 手機：文件連結收成「文件」選單，避免 topbar 變高、又保留全部入口 */
.docmenu { display: none; position: relative; }
.docmenu > summary {
  list-style: none; cursor: pointer; min-height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 12px; border: 1px solid rgba(255,255,255,.3); border-radius: 999px;
  color: #fff; font-size: calc(12px * var(--font-scale));
}
.docmenu > summary::-webkit-details-marker { display: none; }
.docmenu > summary::marker { content: ""; }
@media (max-width: 520px) {
  .desktop-docs { display: none; }
  .docmenu { display: block; }
  .docmenu .doclinks-mobile {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
    display: flex; flex-direction: column; gap: 2px; min-width: 180px;
    padding: 6px; margin: 0; border: 1px solid rgba(255,255,255,.2); border-right: 0;
    border-radius: 10px; background: #2B0B06; box-shadow: 0 8px 24px rgba(0,0,0,.28);
  }
  .docmenu .doclinks-mobile a {
    min-height: 44px; min-width: 44px; display: flex; align-items: center;
    justify-content: flex-start; padding: 0 10px;
  }
  .docmenu:not([open]) .doclinks-mobile { display: none; }
}

/* 分享短連(brevu.link) */
.shareline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; }
.shareline .share-url { font-size: calc(13px * var(--font-scale)); color: var(--ink); word-break: break-all; }
.shareline .share-stats { font-size: calc(12px * var(--font-scale)); color: var(--faint); }
.shareline .cp-label { margin-bottom: 0; }

/* 狀態圖示徽章(取代文字,title/aria 保留語義) */
.badge.iconb { background: transparent; padding: 1px 2px; border-radius: 4px; line-height: 0; vertical-align: -2px; }
.badge.iconb svg { display: inline-block; }
.badge.gen-llm.iconb { color: #7a4fbf; }
.badge.gen-tpl.iconb { color: #5a6a7a; }
.badge.gen-none.iconb { color: #9a8f80; }
.badge.manual.iconb { color: #8a5a2c; }

/* ⋯ 動作選單(討論/修改、複製收進 kebab) */
.actmenu { position: relative; display: inline-block; vertical-align: middle; margin-left: 4px; }
.actmenu-btn { list-style: none; cursor: pointer; background: none; border: none; color: #9a9080; padding: 2px 5px; border-radius: 6px; line-height: 0; }
.actmenu-btn::-webkit-details-marker { display: none; }
.actmenu-btn:hover { background: #efe9df; color: #5a5348; }
.actmenu[open] .actmenu-btn { background: #efe9df; color: #5a5348; }
.actmenu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 60;
  display: flex; flex-direction: column; gap: 2px; min-width: 108px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(60, 45, 20, .14); padding: 5px;
}
.actmenu-item {
  display: block; width: 100%; text-align: left; white-space: nowrap;
  background: none; border: none; cursor: pointer;
  font-size: calc(12.5px * var(--font-scale)); color: var(--ink);
  padding: 6px 10px; border-radius: 7px;
}
.actmenu-item:hover { background: var(--bg); }
/* leadbtns 內的複製 btn small ghost 進選單後去框 */
.actmenu-item.btn.small.ghost { border: none; box-shadow: none; font-size: calc(12.5px * var(--font-scale)); padding: 6px 10px; }
.actmenu-item.linkbtn { text-decoration: none; color: var(--ink); }
.actmenu-item.linkbtn:hover { text-decoration: none; }
.actmenu-pop.actmenu-up { top: auto; bottom: calc(100% + 4px); }
