/* ==========================================================================
   app.css — 生成器介面
   原則：介面安靜，讓投影片成為畫面焦點；按下立即有回饋；動態短且可中斷。
   投影片本身的樣式在 js/slides-css.js。
   ========================================================================== */
:root {
  --bg: #0c0c0d;
  --panel: #141416;
  --panel-2: #1b1b1e;
  --line: #2a2a2f;
  --line-2: #38383e;
  --text: #f3f1ec;
  --mute: #9c9993;
  --dim: #6b6964;
  --accent: #ff4a36;
  --accent-ink: #fff;
  --ok: #3ccf8e;
  --warn: #f5b544;
  --err: #ff5a4a;
  --radius: 14px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: 'Inter', 'Noto Sans TC', -apple-system, 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; font-feature-settings: 'palt' 1;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: .92em; background: var(--panel-2); padding: 1px 6px; border-radius: 5px; }
.meta { color: var(--mute); font-size: 13px; }
.hint { color: var(--dim); font-size: 13px; margin: 6px 0 0; }
.label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); margin-bottom: 10px; }
.error-text { color: var(--err); font-size: 13px; }

/* ---------- 按鈕：按下就有回饋 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font-weight: 600; font-size: 14px; background: none; transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ff5f4d; }
.btn.ghost { border-color: var(--line-2); color: var(--text); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.text { color: var(--mute); padding: 0 10px; height: 32px; }
.btn.text:hover { color: var(--text); }
.btn.sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn.sm svg { width: 14px; height: 14px; }
.btn.lg { height: 50px; font-size: 16px; border-radius: 12px; }
.btn.xl { height: 60px; padding: 0 30px; font-size: 18px; font-weight: 700; border-radius: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.busy { pointer-events: none; opacity: .8; }
.icon-btn { position: relative; width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: none; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--mute); transition: background .15s, color .15s, transform .1s; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.icon-btn.lg { width: 38px; height: 38px; border-radius: 10px; }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn .dot { position: absolute; right: 5px; top: 5px; width: 7px; height: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(60,207,142,.18); }

/* ---------- 頂部列 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px; padding: 0 20px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  background: rgba(12,12,13,.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 50% 50%, var(--accent) 0 32%, transparent 34%), var(--panel-2); border: 1px solid var(--line-2); flex: none; }
.brand-name { font-weight: 800; letter-spacing: -.01em; font-size: 17px; }
.steps { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); padding: 4px; border-radius: 12px; }
.step { border: 0; background: none; height: 34px; padding: 0 14px; border-radius: 8px; cursor: pointer; color: var(--mute); font-weight: 600; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; transition: background .15s, color .15s; }
.step b { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; background: var(--panel-2); border: 1px solid var(--line-2); }
.step:hover { color: var(--text); }
.step.active { background: var(--panel-2); color: var(--text); }
.step.active b { background: var(--accent); border-color: var(--accent); color: #fff; }
.step:disabled { opacity: .35; cursor: not-allowed; }
.top-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

/* ---------- 版面 ---------- */
main { min-height: calc(100vh - 64px); }
.view { display: none; padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1240px; margin: 0 auto; }
/* 只在動畫進行中套用 transform，結束後不留下 transform，避免困住 position: fixed 的工具列 */
.view.active { display: block; animation: view-in .3s var(--ease) backwards; }
#view-edit { max-width: none; padding: 0; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.view-head h2 { margin: 0 0 4px; font-size: 28px; letter-spacing: -.01em; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h3 { margin: 0 0 6px; font-size: 19px; letter-spacing: -.01em; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.card-head label, .card-head .label { margin: 0; }
.input, .card textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .card textarea:focus { border-color: var(--line-2); box-shadow: 0 0 0 3px rgba(255,74,54,.15); }
select.input { height: 40px; padding: 0 10px; }
.input.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.5; }
.field { display: flex; flex-direction: column; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.banner { position: relative; border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 12px; padding: 10px 40px 10px 14px; color: var(--mute); font-size: 13px; }
.banner b { color: var(--text); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }
.banner .x { position: absolute; right: 6px; top: 6px; width: 28px; height: 28px; border: 0; }
.seg { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.seg button, .chips button {
  height: 36px; border: 1px solid var(--line); background: var(--bg); color: var(--mute); border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; padding: 0 10px;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
}
.seg button:active, .chips button:active { transform: scale(.96); }
.seg button:hover, .chips button:hover { color: var(--text); border-color: var(--line-2); }
.seg button[aria-checked="true"], .chips button[aria-checked="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ==========================================================================
   1. 素材
   ========================================================================== */
.home { max-width: 820px; margin: 0 auto; padding-top: 4vh; }
.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { font-size: clamp(32px, 5vw, 54px); line-height: 1.1; letter-spacing: -.025em; margin: 0 0 12px; font-weight: 800; }
.hero p { color: var(--mute); font-size: 18px; margin: 0; }
.material { padding: 8px; display: grid; gap: 8px; transition: border-color .2s, box-shadow .2s; }
.material:focus-within { border-color: var(--line-2); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.material.drag { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,74,54,.18); }
.material textarea {
  min-height: 240px; font-size: 17px; line-height: 1.75; padding: 16px 18px; border: 0; background: transparent; resize: vertical; field-sizing: content; max-height: 60vh;
}
.material textarea:focus { box-shadow: none; }
.material-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 2px 10px 6px; min-height: 26px; }
.material-foot .hint { margin: 0; color: var(--warn); }
.go-row { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 26px 0 18px; }
.go-meta { margin: 0; color: var(--mute); font-size: 14px; }
.custom { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.custom summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; font-weight: 700; }
.custom summary::-webkit-details-marker { display: none; }
.custom summary > span:first-child::before { content: '＋'; display: inline-block; width: 22px; color: var(--mute); transition: transform .2s var(--ease); }
.custom[open] summary > span:first-child::before { content: '－'; }
.custom-body { display: grid; gap: 18px; padding: 4px 18px 20px; border-top: 1px solid var(--line); padding-top: 18px; }
.custom-body .input { margin-top: 8px; }
.custom-body .label + .input, .custom-body .label + select { margin-top: 0; }
.engine-line { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; cursor: pointer; text-align: left; font-size: 13px; color: var(--text); }
.engine-line #engine-text { flex: 1; }
.engine-line:hover { border-color: var(--line-2); }
.home-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; margin-top: 18px; }

/* 圖片素材 */
.asset-list { list-style: none; margin: 0; padding: 0 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
.asset-list:empty { display: none; }
.asset { display: flex; flex-direction: column; gap: 6px; min-width: 0; animation: asset-in .3s var(--ease) both; }
@keyframes asset-in { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
.asset.dragging { opacity: .35; }
.asset.drop-before .asset-thumb { box-shadow: -6px 0 0 -2px var(--accent); }
.asset-thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); cursor: grab; }
.asset-thumb:active { cursor: grabbing; }
.asset-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.asset-no { position: absolute; left: 6px; bottom: 6px; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: rgba(0,0,0,.66); color: #fff; }
.asset-btn { position: absolute; top: 5px; width: 28px; height: 28px; border-radius: 8px; border: 0; background: rgba(0,0,0,.6); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; backdrop-filter: blur(6px); transition: transform .1s, background .15s; }
.asset-btn:active { transform: scale(.9); }
.asset-btn svg { width: 15px; height: 15px; }
.asset-btn.star { right: 37px; }
.asset-btn.del { right: 5px; }
.asset-btn.star.on { background: var(--accent); }
.asset-btn.star.on svg { fill: currentColor; }
.asset.is-hero .asset-thumb { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.asset input { height: 32px; font-size: 12px; padding: 0 8px; }
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 10px; text-align: center; flex-wrap: wrap;
  min-height: 64px; padding: 12px 16px; border-radius: 10px; border: 1.5px dashed var(--line-2); color: var(--mute); cursor: pointer; font-size: 14px;
  transition: border-color .15s, background .15s;
}
.dropzone svg { width: 22px; height: 22px; color: var(--dim); }
.dropzone b { color: var(--text); font-weight: 700; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(255,74,54,.05); }
.dropzone[hidden] { display: none; }

/* ==========================================================================
   2. 預覽與微調
   ========================================================================== */
.studio { display: grid; grid-template-columns: 220px minmax(0, 1fr) 360px; height: calc(100vh - 64px); }
.thumbs-col { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.thumbs { list-style: none; margin: 0; padding: 14px 14px 6px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.thumb { display: grid; grid-template-columns: 18px 1fr; gap: 8px; cursor: pointer; align-items: start; }
.thumb .t-num { font-size: 12px; color: var(--dim); font-weight: 700; text-align: right; padding-top: 2px; font-variant-numeric: tabular-nums; }
.thumb .t-frame { position: relative; border-radius: 7px; outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s; }
.thumb .stage { width: 166px; height: 93.375px; border-radius: 6px; border: 1px solid var(--line); }
.thumb .t-role { display: block; font-size: 11px; color: var(--dim); margin-top: 5px; }
.thumb:hover .t-frame { outline-color: var(--line-2); }
.thumb.active .t-frame { outline-color: var(--accent); }
.thumb.active .t-num, .thumb.active .t-role { color: var(--text); }
.thumb.dragging { opacity: .4; }
.thumb.drop-before .t-frame { box-shadow: 0 -8px 0 -5px var(--accent); }
.t-badge { position: absolute; right: 5px; bottom: 5px; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.72); color: #ddd; font-variant-numeric: tabular-nums; }
.t-badge.err { background: var(--err); color: #fff; }
.t-badge.warn { color: var(--warn); }
.add-slide { padding: 10px 14px 14px; display: grid; gap: 8px; border-top: 1px solid var(--line); }
.center-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 14px 24px 18px; gap: 12px; overflow-y: auto; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.tool-group { display: flex; gap: 6px; align-items: center; }
.tool-group .meta { margin-left: 6px; }
.main-stage { width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.45); flex: none; }

/* 在投影片上直接編輯 */
.main-stage [data-f] { border-radius: 8px; outline: 3px solid transparent; outline-offset: 8px; transition: outline-color .15s; cursor: text; }
.main-stage [data-f]:hover { outline-color: rgba(255,255,255,.22); }
.main-stage .slide[data-theme="paper"] [data-f]:hover { outline-color: rgba(0,0,0,.18); }
.main-stage [data-f]:focus { outline-color: var(--accent); }
.main-stage [data-media] { cursor: pointer; }
.main-stage [data-media]:hover::before { content: '換圖'; position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 14px 30px; border-radius: 99px; background: rgba(0,0,0,.72); color: #fff; font: 700 34px/1 var(--font); pointer-events: none; }

.quick-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.qa { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font-size: 13px; font-weight: 600; transition: background .15s, border-color .15s, transform .1s; }
.qa:hover { background: var(--panel-2); border-color: var(--line-2); }
.qa:active { transform: scale(.96); }
.qa svg { width: 15px; height: 15px; color: var(--mute); }
.qa.icon { width: 34px; padding: 0; justify-content: center; }
.qa.danger:hover { color: var(--err); }
.qa.need-ai { color: var(--mute); }
.qa.busy { pointer-events: none; opacity: .7; }
.qa.busy svg { animation: spin 1s linear infinite; }
.qa-sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 4px; }
.edit-tip { margin: -4px 0 0; color: var(--dim); font-size: 12px; }
.qc-panel { display: grid; gap: 10px; }
.qc-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.counter { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--mute); font-variant-numeric: tabular-nums; }
.counter .bar { width: 140px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.counter .bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .2s, background .2s; }
.counter.over .bar i { background: var(--err); }
.counter.over b { color: var(--err); }
.counter.near .bar i { background: var(--warn); }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.issues li { display: flex; gap: 10px; align-items: baseline; font-size: 13px; color: var(--mute); }
.issues li::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex: none; transform: translateY(-1px); background: var(--warn); }
.issues li.error { color: #ffc1ba; }
.issues li.error::before { background: var(--err); }
.issues li.ok::before { background: var(--ok); }
.qc-deck { border-top: 1px solid var(--line); padding-top: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--panel-2); border: 1px solid var(--line); color: var(--mute); }
.pill.err { color: var(--err); border-color: rgba(255,90,74,.4); }
.pill.ok { color: var(--ok); border-color: rgba(60,207,142,.35); }
.pill.warn { color: var(--warn); border-color: rgba(245,181,68,.35); }

.editor-col { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); flex: none; }
.tab { height: 46px; border: 0; background: none; color: var(--mute); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.editor { padding: 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.editor .field > .label { margin-bottom: 6px; }
.editor .input { font-size: 14px; }
.editor textarea.input { min-height: 44px; }
.editor .stack { display: grid; gap: 6px; }
.editor .step-row { display: grid; grid-template-columns: 90px 1fr; gap: 6px; }
.editor .side-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 6px; }
.editor hr, .card hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
.editor .help { font-size: 12px; color: var(--dim); margin: 4px 0 0; }
.editor .est { font-size: 12px; color: var(--mute); margin-top: 6px; }
.editor .est b { color: var(--text); }
.editor .est.over b { color: var(--warn); }

/* 圖片欄位與焦點 */
.media-row { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: start; }
.media-thumb { position: relative; width: 96px; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); border: 1px dashed var(--line-2); cursor: pointer; padding: 0; color: var(--dim); font-size: 12px; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-side { display: grid; gap: 6px; }
.focus-grid { display: grid; grid-template-columns: repeat(3, 26px); gap: 4px; }
.focus-grid button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--bg); cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; }
.focus-grid button::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.focus-grid button[aria-pressed="true"] { border-color: var(--accent); }
.focus-grid button[aria-pressed="true"]::after { background: var(--accent); }

/* 講稿分頁的時間軸 */
.timebar { display: flex; height: 34px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line); background: var(--bg); }
.timebar span { display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--bg); border-right: 2px solid var(--panel); min-width: 0; overflow: hidden; white-space: nowrap; cursor: pointer; background: var(--sec); opacity: .55; transition: opacity .15s; }
.timebar span.on, .timebar span:hover { opacity: 1; }
.timebar span:last-child { border-right: 0; }
.time-sum { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--mute); }
.time-sum b { color: var(--text); font-variant-numeric: tabular-nums; }
.time-sum.over b { color: var(--warn); }
.sec-hook { --sec: #ff4a36; } .sec-problem { --sec: #f5b544; } .sec-insight { --sec: #b48cff; }
.sec-solution { --sec: #4fb3ff; } .sec-impact { --sec: #3ccf8e; } .sec-closing { --sec: #f3f1ec; }
.pause { display: inline-block; font-size: 11px; font-weight: 700; line-height: 1; padding: 4px 7px; margin: 0 4px; border-radius: 99px; background: rgba(255,74,54,.14); color: var(--accent); vertical-align: 2px; letter-spacing: .05em; }

/* 整份分頁 */
.bigidea-box textarea { font-size: 18px; font-weight: 800; line-height: 1.4; }
.tpl-mini { display: grid; gap: 8px; }
.tpl-opt { display: grid; grid-template-columns: 112px 1fr; gap: 12px; align-items: center; padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; text-align: left; color: inherit; transition: border-color .15s, transform .1s; }
.tpl-opt:active { transform: scale(.98); }
.tpl-opt:hover { border-color: var(--line-2); }
.tpl-opt[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tpl-opt .stage { width: 112px; height: 63px; border-radius: 6px; }
.tpl-opt b { display: block; font-size: 14px; }
.tpl-opt span { font-size: 12px; color: var(--mute); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; outline: 1px solid var(--line-2); }
.swatch.active { border-color: var(--bg); outline: 2px solid var(--text); }
.swatches input[type=color] { width: 34px; height: 34px; padding: 0; border: 1px solid var(--line-2); border-radius: 50%; background: none; cursor: pointer; }
.theme-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.theme-pick button { height: 44px; border-radius: 10px; border: 1px solid var(--line-2); cursor: pointer; font-weight: 700; font-size: 13px; }
.theme-pick button.active { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 換圖浮層 */
.popover {
  position: fixed; z-index: 70; width: 320px; max-width: calc(100vw - 24px); padding: 12px;
  background: rgba(27,27,30,.96); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line-2); border-radius: 14px; box-shadow: 0 24px 70px rgba(0,0,0,.55);
  animation: pop-in .18s var(--ease) both; transform-origin: top center;
}
.popover[hidden] { display: none; }
@keyframes pop-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.pop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pop-grid button { aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); padding: 0; background: var(--bg); cursor: pointer; color: var(--mute); font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; transition: transform .1s, border-color .15s; }
.pop-grid button:active { transform: scale(.95); }
.pop-grid button:hover { border-color: var(--line-2); color: var(--text); }
.pop-grid button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pop-grid button[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
.pop-grid button svg { width: 20px; height: 20px; }
.pop-note { margin: 10px 2px 0; }

/* 生成進度 */
.progress { position: fixed; inset: 0; z-index: 60; background: rgba(8,8,9,.84); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.progress[hidden] { display: none; }
.progress-box { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; padding: 26px; box-shadow: 0 40px 120px rgba(0,0,0,.6); animation: pop-in .2s var(--ease) both; }
.progress-box h3 { margin: 0 0 18px; font-size: 20px; }
.progress-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.progress-steps li { display: grid; grid-template-columns: 22px 1fr; gap: 12px; align-items: center; color: var(--dim); font-size: 15px; transition: color .2s; }
.progress-steps li::before { content: ''; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-2); box-sizing: border-box; }
.progress-steps li.active { color: var(--text); font-weight: 600; }
.progress-steps li.active::before { border-color: var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.progress-steps li.done { color: var(--mute); }
.progress-steps li.done::before { border: 0; background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='%230c0c0d' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat; }
.progress-steps li.fail { color: var(--err); font-weight: 600; }
.progress-steps li.fail::before { border: 0; background: var(--err); }
#progress-detail { margin: 16px 0 0; min-height: 20px; }
.progress-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.progress-actions[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   3. 播放或下載
   ========================================================================== */
.share-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; align-items: start; }
.share-html { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; padding: 20px; }
.share-preview .stage { width: 100%; aspect-ratio: 16 / 9; border-radius: 10px; border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.share-body { display: flex; flex-direction: column; gap: 14px; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; color: var(--mute); }
.checks li { display: flex; gap: 8px; }
.checks li::before { content: '✓'; color: var(--ok); font-weight: 800; }
.name-row { display: flex; align-items: center; gap: 8px; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--mute); cursor: pointer; }
.check-line input { accent-color: var(--accent); width: 16px; height: 16px; }
#html-status { margin: 0; min-height: 20px; }
.share-play { display: flex; flex-direction: column; gap: 10px; }
.share-play h3 { margin-bottom: 0; }
.other-formats { display: flex; flex-wrap: wrap; gap: 6px; }

/* 封面 */
.cover-card { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; padding: 24px; }
.cover-preview { display: flex; align-items: center; justify-content: center; min-height: 340px; background: repeating-conic-gradient(#151517 0% 25%, #19191c 0% 50%) 0 / 24px 24px; border-radius: 12px; padding: 24px; }
.cover-frame { display: flex; align-items: center; justify-content: center; width: 100%; }
.cover-frame canvas { display: block; max-width: 100%; max-height: 520px; width: auto; height: auto; border-radius: 6px; box-shadow: 0 30px 80px rgba(0,0,0,.55); transition: opacity .25s; }
.cover-frame canvas.busy { opacity: .6; }
.cover-controls { display: flex; flex-direction: column; gap: 18px; }
.cover-controls .field .card-head { margin-bottom: 6px; }
#cover-format { grid-template-columns: repeat(3, 1fr); }
#cover-format button { height: auto; padding: 8px 4px; line-height: 1.3; }
#cover-format small { display: block; font-size: 10px; font-weight: 500; opacity: .75; }
.hero-pick { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.hero-pick button { aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); padding: 0; background: var(--bg); cursor: pointer; color: var(--dim); font-size: 11px; }
.hero-pick button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-pick button[aria-checked="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
.cover-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto; }

/* ---------- 對話框 / 提示 ---------- */
.dialog { border: 1px solid var(--line-2); border-radius: 18px; background: var(--panel); color: var(--text); padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 40px 120px rgba(0,0,0,.6); }
.dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.dlg-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.dlg-body h3 { margin: 0; font-size: 20px; }
.dlg-body > .meta { margin: -8px 0 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.provider-list { display: grid; gap: 8px; }
.provider { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.provider:has(input:checked) { border-color: var(--accent); background: rgba(255,74,54,.06); }
.provider input { accent-color: var(--accent); margin-top: 4px; }
.provider b { display: block; }
.provider span { color: var(--mute); font-size: 13px; }
.manual-steps { margin: 0; padding-left: 20px; display: grid; gap: 16px; }
.ms-head { display: flex; justify-content: space-between; align-items: center; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 90;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px; max-width: calc(100vw - 32px);
  transition: opacity .2s, transform .2s var(--ease); box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--err); color: #fff; }

/* ---------- 播放模式 ---------- */
.stage { position: relative; overflow: hidden; }
.presenter { position: fixed; inset: 0; z-index: 80; background: #000; display: flex; flex-direction: column; }
.presenter[hidden] { display: none; }
.pr-progress { height: 3px; background: rgba(255,255,255,.08); flex: none; position: relative; z-index: 3; }
.pr-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .45s var(--ease); }
.pr-main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; }
.pr-stage { width: 100%; height: 100%; cursor: pointer; }
.pr-stage > .slide { opacity: 0; transition: opacity .45s cubic-bezier(.4,0,.2,1), visibility 0s .45s; visibility: hidden; }
.pr-stage > .slide.is-current { opacity: 1; visibility: visible; transition: opacity .45s cubic-bezier(.4,0,.2,1), visibility 0s; z-index: 1; }
.pr-side { display: none; }
.presenter.speaker .pr-main { grid-template-columns: minmax(0, 1fr) minmax(340px, 34%); gap: 20px; padding: 20px; background: #0c0c0d; }
.presenter.speaker .pr-stage { border-radius: 10px; border: 1px solid var(--line); }
.presenter.speaker .pr-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.pr-k { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.pr-timers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.pr-timers > div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; }
.pr-timers b { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; }
.pr-timers b.warn { color: var(--warn); } .pr-timers b.over { color: var(--err); }
.pr-target { font-size: 12px; color: var(--mute); }
.pr-next { width: 100%; aspect-ratio: 16 / 9; border-radius: 8px; border: 1px solid var(--line); flex: none; background: #111; }
.pr-next:empty::after { content: '（最後一頁）'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--dim); font-size: 13px; }
.pr-notes { flex: 1; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; font-size: 20px; line-height: 1.75; }
.pr-notes .msg { font-size: 14px; color: var(--mute); margin: 0 0 10px; }
.pr-notes .trans { font-size: 14px; color: var(--mute); margin-top: 14px; }
.pr-black { position: absolute; inset: 0; background: #000; z-index: 5; }
.pr-bar {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 14px;
  background: rgba(20,20,22,.84); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,.1);
  transition: opacity .35s, transform .35s var(--ease);
}
.presenter.idle .pr-bar { opacity: 0; transform: translate(-50%, 10px); pointer-events: none; }
.presenter.idle { cursor: none; }
.presenter.speaker .pr-bar { position: static; transform: none; margin: 0 auto 14px; opacity: 1; pointer-events: auto; }
.presenter.speaker.idle { cursor: auto; }
.pr-btn { min-width: 40px; height: 40px; border: 0; border-radius: 10px; background: none; color: #ddd; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, transform .1s; }
.pr-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.pr-btn:active { transform: scale(.94); }
.pr-btn.wide { padding: 0 12px; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.pr-btn.edit { font-size: 13px; }
.pr-btn.edit svg { width: 16px; height: 16px; }
.pr-btn.paused { color: var(--warn); }
.pr-btn.on { color: var(--accent); }
.pr-btn svg { width: 20px; height: 20px; }
.pr-count { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; color: #ddd; font-size: 14px; }
.pr-sep { width: 1px; height: 22px; background: rgba(255,255,255,.14); margin: 0 4px; }
.pr-help { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-size: 12px; color: rgba(255,255,255,.62); background: rgba(0,0,0,.55); padding: 6px 12px; border-radius: 99px; z-index: 6; transition: opacity .6s; white-space: nowrap; }
.pr-help.gone { opacity: 0; pointer-events: none; }

/* ---------- 列印 / PDF ---------- */
#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  html, body { background: #fff; }
  #print-root { display: block; }
  #print-root * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-page { break-after: page; page-break-after: always; position: relative; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-slides .print-page { width: 1920px; height: 1080px; overflow: hidden; }
  .print-slides .print-page .slide { position: absolute; inset: 0; }
  .print-notes { color: #111; font-family: var(--font); }
  .print-notes .pn-head { display: flex; justify-content: space-between; font-size: 11px; color: #666; margin-bottom: 8px; }
  .print-notes .stage { width: 100%; aspect-ratio: 16 / 9; border-radius: 4px; }
  .print-notes .pn-body { margin-top: 18px; font-size: 13px; line-height: 1.8; }
  .print-notes .pn-body h4 { margin: 0 0 6px; font-size: 14px; }
  .print-notes .pn-body p { margin: 0 0 8px; }
  .print-notes .pause { background: #eee; color: #c33; }
  .slide .rv { animation: none !important; }
}

/* ---------- 響應式 ---------- */
@media (max-width: 1180px) {
  .studio { grid-template-columns: 190px minmax(0, 1fr) 320px; }
  .thumb .stage { width: 140px; height: 78.75px; }
  .share-grid { grid-template-columns: 1fr; }
  .cover-card { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .topbar { grid-template-columns: auto 1fr; height: auto; padding: 10px 16px; row-gap: 10px; }
  .steps { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; overflow-x: auto; }
  .step { padding: 0 8px; flex: 1; justify-content: center; gap: 6px; font-size: 13px; }
  main { min-height: auto; }
  .seg { grid-template-columns: repeat(3, 1fr); }
  .studio { grid-template-columns: minmax(0, 1fr); height: auto; }
  .studio > * { min-width: 0; }
  .thumbs-col { border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; }
  .thumbs { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 12px 16px; }
  .thumb { grid-template-columns: 1fr; flex: none; }
  .thumb .t-num { text-align: left; }
  .thumb .stage { width: 128px; height: 72px; }
  .add-slide { display: none; }
  .center-col { padding: 14px 16px 90px; overflow: visible; }
  /* 手機：常用操作固定在底部 */
  .quick-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; flex-wrap: nowrap; overflow-x: auto; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(20,20,22,.94); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  }
  .qa { flex: none; }
  .editor-col { border-left: 0; border-top: 1px solid var(--line); }
  .editor { overflow: visible; }
  .share-html { grid-template-columns: 1fr; }
  .presenter.speaker .pr-main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  .presenter.speaker .pr-stage { aspect-ratio: 16 / 9; height: auto; }
  .pr-help { display: none; }
}
@media (max-width: 560px) {
  .step b { display: none; }
  .btn.xl { width: 100%; }
  .material textarea { min-height: 200px; font-size: 16px; }
  .row2 { grid-template-columns: 1fr; }
  .pr-bar { bottom: 12px; gap: 0; }
  .pr-btn { min-width: 36px; }
  #pr-reset, #pr-speaker, #pr-timer-btn { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
