/* ── 製版桌設計系統:墨黑/暖紙白/朱色/網點 ── */
/* 自架字型:工作台跟匯出站要用同一支,否則排版時看到的氣泡大小跟成品不一樣。
   font-display:block——寧可晚 0.x 秒顯示,也不要先用系統字排好版再換字跳動。 */
@font-face {
  font-family: 'Comic TC';
  src: url('../assets/fonts/comic-tc.woff2') format('woff2');
  font-weight: 100 900;
  font-display: block;
}
:root {
  color-scheme: dark;
  --ink: #101013;        /* 底:墨 */
  --bench: #17171b;      /* 面:製版桌 */
  --bench-2: #1d1d22;
  --line: #2b2b31;       /* 框線 */
  --fg: #eceae4;         /* 暖紙白 */
  --dim: #97959c;
  --accent: #d9482b;     /* 朱(印章紅):只給主要動作與目前步驟 */
  --accent-dn: #b93a21;
  --ok: #7fae6d;
  --err: #e08890;
  --tone: radial-gradient(circle, #ffffff14 1px, transparent 1.5px); /* 網點 */
  --radius: 10px;
}
* { margin: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  height: 100%;
  background: var(--ink);
  color: var(--fg);
  font-family: 'Comic TC', "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  display: grid;
  grid-template: "top top" auto "nav main" 1fr / 200px 1fr;
}

/* ── topbar ── */
#topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1.1rem;
  background: var(--bench);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.wordmark { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; letter-spacing: .02em; color: var(--fg); text-decoration: none; }
.wordmark .mark {
  width: 1.7em; height: 1.7em; display: grid; place-items: center;
  border: 2px solid var(--fg); border-radius: 6px;
  box-shadow: 3px 3px 0 0 var(--accent);
  font-size: .95em;
}
.badge { color: var(--dim); font-size: .82rem; border: 1px solid var(--line); border-radius: 99px; padding: .1rem .7rem; }
.chapter-ctl { margin-left: auto; display: flex; align-items: center; gap: .45rem; }
.chapter-ctl label { color: var(--dim); font-size: .85rem; white-space: nowrap; margin: 0; }
.chapter-ctl select { max-width: 260px; }
.chapter-ctl button { padding: .35rem .7rem; }

/* ── 步驟導航 ── */
#steps {
  grid-area: nav;
  display: flex; flex-direction: column; gap: .25rem;
  padding: 1rem .7rem;
  border-right: 1px solid var(--line);
  background: var(--bench);
}
.step {
  display: flex; align-items: center; gap: .7rem;
  background: none; border: 1px solid transparent; border-radius: 8px;
  color: var(--dim); padding: .55rem .7rem; font: inherit; cursor: pointer;
  text-align: left;
}
.step .no {
  width: 1.55em; height: 1.55em; display: grid; place-items: center;
  border: 1.5px solid currentColor; border-radius: 4px;
  font-size: .8em; font-weight: 700; flex: none;
}
.step .t { font-size: .95rem; }
.step:hover { color: var(--fg); background: var(--bench-2); }
.step.active { color: var(--fg); background: var(--bench-2); border-color: var(--line); }
.step.active .no { border-color: var(--accent); color: var(--accent); box-shadow: 2px 2px 0 0 #d9482b40; }

/* ── main ── */
main { grid-area: main; overflow-y: auto; padding: 1.6rem clamp(1rem, 3vw, 2.4rem) 6rem; }
.tab { display: none; max-width: 960px; }
.tab.active { display: block; }
.tab-head { margin-bottom: 1.2rem; }
.tab-head h2 {
  font-size: 1.45rem; font-weight: 800; letter-spacing: .03em;
  display: inline-block; position: relative; padding-bottom: .2rem;
}
.tab-head h2::after {
  content: ''; position: absolute; left: 0; right: -0.5rem; bottom: 0; height: 7px;
  background-image: var(--tone); background-size: 5px 5px;
}
.tab-head p { color: var(--dim); font-size: .88rem; max-width: 46em; margin-top: .5rem; }
h3 { font-size: 1.05rem; margin-bottom: .4rem; }
code { background: var(--bench-2); border: 1px solid var(--line); border-radius: 4px; padding: .05em .4em; font-size: .9em; }

/* ── 表單與按鈕 ── */
label { display: block; margin: .8rem 0; color: #c9c7cf; font-size: .88rem; }
label .sub { color: var(--dim); font-weight: 400; margin-left: .5em; font-size: .82em; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
input, textarea, select {
  width: 100%; margin-top: .3rem;
  background: var(--ink); color: var(--fg);
  border: 1px solid var(--line); border-radius: 7px;
  padding: .5rem .65rem; font: inherit;
}
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label.inline input, label.inline select { width: auto; margin-top: 0; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
button {
  background: var(--bench-2); color: var(--fg);
  border: 1px solid #3a3a42; border-radius: 7px;
  padding: .48rem .95rem; font: inherit; cursor: pointer;
}
button:hover { background: #26262c; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: var(--accent-dn); }
button.danger { border-color: #7a3038; color: var(--err); background: none; }
button.danger-solid { background: #7a3038; border-color: #7a3038; }
button:disabled { opacity: .45; cursor: default; }
.actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.toolbar {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  background: var(--bench); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .6rem .9rem; margin-bottom: 1rem;
  position: sticky; top: 0; z-index: 10;
}
.status { color: var(--ok); font-size: .85rem; }
.status.err { color: var(--err); }

/* ── 卡片 ── */
.card {
  background: var(--bench); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin-bottom: 1rem;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }
.sub { color: var(--dim); font-size: .85rem; }

/* ── 空狀態 ── */
.empty-state {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 2.2rem 1.5rem; text-align: center; color: var(--dim); margin: 1rem 0;
  position: relative; overflow: hidden;
}
.empty-tone { position: absolute; inset: 0; background-image: var(--tone); background-size: 7px 7px; opacity: .5; pointer-events: none; }
.empty-state p { margin-bottom: .9rem; position: relative; }
.empty-state button { position: relative; }

/* ── provider 表 ── */
.provider-row { display: grid; grid-template-columns: 1.2fr 1fr 1.6fr .8fr 1fr auto; gap: .4rem; margin-bottom: .5rem; align-items: center; }
.provider-row input, .provider-row select { margin-top: 0; }
.provider-head { color: var(--dim); font-size: .78rem; }
@media (max-width: 760px) { .provider-row { grid-template-columns: 1fr 1fr; } }

/* ── 分鏡 ── */
.sb-panel { background: var(--bench); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin: .7rem 0; }
.sb-panel .head { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; color: var(--dim); }
.sb-panel .head .num {
  font-weight: 800; color: var(--fg); border: 1.5px solid var(--fg); border-radius: 4px;
  padding: 0 .45em; font-size: .82em; box-shadow: 2px 2px 0 0 #d9482b55;
}
.sb-panel .head .spacer { flex: 1; }
.sb-panel textarea { min-height: 2.4em; }
.sb-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: .5rem; }
@media (max-width: 720px) { .sb-grid { grid-template-columns: 1fr; } }
.dlg-row { display: grid; grid-template-columns: 1fr 2.6fr auto auto; gap: .4rem; margin: .3rem 0; }
.dlg-row input, .dlg-row select { margin-top: 0; }
.icon-btn { padding: .3rem .55rem; }

/* ── 角色卡 ── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .9rem; }
.char-card { background: var(--bench); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; }
.char-card img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 7px; background: var(--ink); cursor: zoom-in; }
.char-card .noimg {
  width: 100%; aspect-ratio: 3/4; display: grid; place-items: center; color: var(--dim);
  border: 1.5px dashed var(--line); border-radius: 7px;
  background-image: var(--tone); background-size: 7px 7px;
}
.char-card .cid { color: var(--dim); font-size: .78rem; margin-top: .5rem; }
.char-card .actions { margin-top: .6rem; gap: .4rem; }
.char-card .actions button { padding: .35rem .6rem; font-size: .85rem; }

/* ── 生圖 ── */
.gen-panel { background: var(--bench); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin: .8rem 0; }
.gen-panel .head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.gen-panel .head .num { font-weight: 800; border: 1.5px solid var(--fg); border-radius: 4px; padding: 0 .45em; font-size: .8em; box-shadow: 2px 2px 0 0 #d9482b55; }
.gen-panel .head .scene { color: var(--dim); font-size: .88rem; }
.gen-panel details { margin: .4rem 0; }
.gen-panel summary { color: var(--dim); font-size: .82rem; cursor: pointer; }
.gen-panel .prompt-preview { font-size: .8rem; color: var(--dim); white-space: pre-wrap; background: var(--ink); border-radius: 7px; padding: .5rem .6rem; margin-top: .3rem; max-height: 10em; overflow-y: auto; }
.gen-panel .row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: .4rem; }
.cand-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .6rem; }
.cand {
  position: relative; width: 158px; border-radius: 7px; overflow: hidden;
  border: 2px solid transparent; cursor: zoom-in; background: var(--ink);
}
.cand img { display: block; width: 100%; }
.cand.chosen { border-color: var(--ok); }
.cand.chosen::after {
  content: '已選定'; position: absolute; top: 6px; right: 6px;
  background: var(--ok); color: #10130e; font-size: .72rem; font-weight: 700;
  padding: .05rem .45rem; border-radius: 4px;
}
.chosen-mark { color: var(--ok); font-size: .82rem; }

/* ── 進度條 ── */
.progress { display: flex; align-items: center; gap: .8rem; margin: .6rem 0 1rem; }
.progress-track { flex: 1; height: 10px; background: var(--bench-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress-label { color: var(--dim); font-size: .82rem; white-space: nowrap; }

/* ── 排版氣泡 ── */
.ly-panel { position: relative; margin: 1rem 0; max-width: 660px; container-type: inline-size; }
.ly-panel img { display: block; width: 100%; border-radius: 7px; }
.ly-panel .pnum { position: absolute; top: -0.7rem; left: -0.4rem; z-index: 2; font-weight: 800; font-size: .78rem; background: var(--ink); border: 1.5px solid var(--fg); border-radius: 4px; padding: 0 .45em; box-shadow: 2px 2px 0 0 #d9482b55; }
.bubble {
  position: absolute; transform: translate(-50%, -50%);
  /* 內距/行高/字距要跟匯出站一字不差,否則預覽的換行位置跟成品不一樣,白排 */
  background: #fff; color: #111; padding: .5em .8em; border-radius: 1em;
  font-size: clamp(13px, 3.4cqw, 22px); line-height: 1.6; letter-spacing: .02em; max-width: 46%;
  cursor: grab; user-select: none; box-shadow: 0 1px 4px rgba(0,0,0,.5);
 width: max-content; }
.bubble.thought { background: none; box-shadow: none; border: none; color: #1c1a17; font-weight: 500; text-shadow: 0 0 6px #fff, 0 0 3px #fff, 0 0 1px #fff, 0 0 10px rgba(255,255,255,.8); }
.bubble.narration { background: rgba(16,16,20,.72); color: #f2f0ea; border-radius: 3px; border: none; font-weight: 400; }
/* 對白泡的尾巴——只有對白有(內心是浮字、旁白是方框、效果字沒泡)。每顆泡各自選方向。
   上下左右=border 三角形。斜角改用 clip-path 切直角三角形:轉開三角形會讓底邊離開泡緣、
   只剩一小截露在外面(看起來像貼邊的扁片),直角三角形的底邊天生貼平,尖角自然指向斜方。
   ponytail: 八方向定點,不做任意角度與沿邊滑動;真的不夠再說。 */
.bubble.speech::after { content: ''; position: absolute; width: 0; height: 0; border: .5em solid transparent; }
.bubble.speech.t-none::after { content: none; }
.bubble.speech.t-bottom::after { top: 100%; left: 50%; margin: -1px 0 0 -.5em; border-bottom: 0; border-top-color: #fff; }
.bubble.speech.t-top::after { bottom: 100%; left: 50%; margin: 0 0 -1px -.5em; border-top: 0; border-bottom-color: #fff; }
.bubble.speech.t-left::after { right: 100%; top: 50%; margin: -.5em -1px 0 0; border-left: 0; border-right-color: #fff; }
.bubble.speech.t-right::after { left: 100%; top: 50%; margin: -.5em 0 0 -1px; border-right: 0; border-left-color: #fff; }
.bubble.speech.t-bottom-left::after,
.bubble.speech.t-bottom-right::after,
.bubble.speech.t-top-left::after,
.bubble.speech.t-top-right::after { border: 0; background: #fff; width: .95em; height: .95em; }
.bubble.speech.t-bottom-left::after { top: 100%; left: 20%; margin: -1px 0 0; clip-path: polygon(100% 0, 0 0, 0 100%); }
.bubble.speech.t-bottom-right::after { top: 100%; right: 20%; margin: -1px 0 0; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.bubble.speech.t-top-left::after { bottom: 100%; left: 20%; margin: 0 0 -1px; clip-path: polygon(0 0, 100% 100%, 0 100%); }
.bubble.speech.t-top-right::after { bottom: 100%; right: 20%; margin: 0 0 -1px; clip-path: polygon(100% 0, 100% 100%, 0 100%); }
.bubble .spk { display: block; font-size: .72em; color: #888; }
.bubble .del {
  position: absolute; top: -0.65em; right: -0.65em;
  background: #7a3038; color: #fff; border: 0; border-radius: 50%;
  width: 1.5em; height: 1.5em; line-height: 1; padding: 0; font-size: .8em; display: none;
}
.bubble:hover .del { display: block; }
.export-card { margin-top: 1.6rem; }

/* ── modal / lightbox ── */
dialog { border: none; background: none; padding: 0; }
dialog::backdrop { background: rgba(8,8,10,.72); }
.modal form {
  background: var(--bench); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.3rem 1.4rem; min-width: min(440px, 92vw); max-width: 92vw;
  color: var(--fg);
}
.modal h3 { margin-bottom: .4rem; }
.modal-body { color: var(--dim); font-size: .88rem; margin-bottom: .4rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.1rem; }
.lightbox { max-width: none; max-height: none; }
.lightbox img { max-width: 88vw; max-height: 82vh; border-radius: 8px; display: block; }
.lb-actions { display: flex; justify-content: center; gap: .6rem; margin-top: .8rem; }

/* ── toast ── */
#toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--bench); border: 1px solid #3a3a42; border-left: 3px solid var(--accent);
  padding: .6rem 1.2rem; border-radius: 8px; z-index: 99; box-shadow: 0 4px 18px rgba(0,0,0,.5);
}

/* ── 手機 ── */
@media (max-width: 860px) {
  body { grid-template: "top" auto "nav" auto "main" 1fr / 1fr; }
  #steps { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: .5rem .6rem; }
  .step { flex: none; }
  .chapter-ctl { margin-left: 0; }
  #topbar { flex-wrap: wrap; gap: .5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ── 匯出站(bake) ── */
.bk-strip { max-width: 520px; margin: 0 auto; }
.bk-panel { margin-bottom: 1.2rem; }
.bk-panel img { display: block; width: 100%; border-radius: 8px; cursor: zoom-in; }
.bk-panel img.bk-dim { opacity: .45; }
.bk-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .35rem; }
.bk-tag { font-size: .82rem; color: var(--dim); }
.bk-tag.ok { color: var(--acc); }

/* 效果字氣泡(排版預覽) */
.bubble.sfx { background: none; box-shadow: none; border: none; color: #111; font-weight: 900; font-size: 1.35em; letter-spacing: .06em; transform: translate(-50%,-50%) rotate(-6deg); text-shadow: 1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff; }

/* 效果圖層(排版工作台) */
.ly-panel .fx { position: absolute; transform: translate(-50%,-50%); cursor: grab; }
.ly-tools { display: flex; gap: .5rem; margin: .35rem 0 0; }

/* 角色設定表(立繪/表情集/動作集) */
.sheet-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .6rem; }
.sheet { text-align: center; font-size: .74rem; color: var(--dim); }
.sheet img { width: 100%; aspect-ratio: 1/1; object-fit: cover; object-position: top; border-radius: 6px; cursor: zoom-in; }
.sheet .noimg { aspect-ratio: 1/1; display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 6px; }

/* 完稿檢查結果 */
.lint-list { max-height: 50vh; overflow-y: auto; margin: .6rem 0; font-size: .92rem; }
.lint-list p { padding: .3rem 0; border-bottom: 1px solid var(--line); }
.lint-list b { display: inline-block; min-width: 4.5em; color: var(--dim); font-weight: 600; }
.lint-err { color: var(--err); }
.lint-warn { color: #d6b25f; }

/* 世界頁:平面圖編輯 */
.plan-wrap { max-width: min(78vw, 900px); }
.plan-edit { width: 100%; height: auto; display: block; cursor: crosshair; border-radius: 6px; }
.cam-row { display: grid; grid-template-columns: 4.5rem 1fr auto; gap: .5rem; align-items: center; }
.cam-row input { width: 100%; }

/* 生圖頁:這一格會送哪些參考圖 */
.ref-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-start; margin: .5rem 0 .2rem; }
.ref-label { color: var(--dim); font-size: .82rem; padding-top: .3rem; }
.ref-chip { display: flex; flex-direction: column; align-items: center; gap: .18rem; width: 92px; font-size: .7rem; color: var(--dim); cursor: pointer; }
.ref-chip img { width: 92px; height: 62px; object-fit: cover; border-radius: 4px; border: 2px solid var(--acc); }
.ref-chip span { text-align: center; line-height: 1.25; }
.ref-chip.off img { border-color: var(--line); filter: grayscale(1) opacity(.45); }
.ref-chip.off span { text-decoration: line-through; }
.ref-chip input { margin: 0; }
