:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #5f6368;
  --ink-3: #9aa0a6;
  --line: #e4e2dc;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #188038;
  --err: #c5221f;
  --warn: #b06000;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: not-allowed; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }

.topbar { padding: 18px 28px 6px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.privacy { color: var(--ok); }
.version { font-size: 12px; color: var(--ink-3); white-space: nowrap; padding-top: 6px; }
.banner { margin: 8px 28px 0; padding: 12px 16px; border-radius: 12px; background: #fdecea; color: var(--err); font-size: 14px; border: 1px solid #f5c2be; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr minmax(360px, 400px); gap: 18px; padding: 14px 28px 28px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 small { font-weight: normal; color: var(--ink-3); font-size: 13px; }
.num { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.grip-inline { font-weight: 700; }

/* ---------- 步驟 1：素材 ---------- */
.media-card { min-height: 420px; }
.media-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.media-head h2 { margin: 0; }
.media-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tool-label { font-size: 13px; color: var(--ink-2); }

.dropzone { border: 2px dashed #c9c6bd; border-radius: 12px; padding: 34px 12px; text-align: center; cursor: pointer; color: var(--ink-2); transition: .15s; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); outline: none; }
.dropzone.compact { padding: 12px; }
.dropzone.compact .drop-icon, .dropzone.compact .drop-sub { display: none; }
.dropzone.compact .drop-title { font-size: 14px; margin: 0; }
.drop-icon { width: 46px; height: 46px; }
.drop-title { font-size: 17px; font-weight: 600; margin-top: 6px; color: var(--ink); }
.dropzone:hover .drop-title { color: var(--accent); }
.drop-sub { font-size: 13px; margin-top: 4px; }
.link { color: var(--accent); text-decoration: underline; }

.bulk-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.btn-small { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 11px; font-size: 13px; }
.btn-small:hover { border-color: var(--accent); color: var(--accent); }
.btn-text { border: none; background: none; color: var(--accent); padding: 4px 2px; font-size: 13px; }
.btn-text:hover { text-decoration: underline; }
.btn-text.danger { color: var(--ink-3); margin-left: 6px; }
.btn-text.danger:hover { color: var(--err); }

.grid { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.item { position: relative; border: 1px solid var(--line); border-radius: 12px; background: #faf9f7; padding: 8px; display: flex; flex-direction: column; gap: 7px; transition: border-color .12s, opacity .12s; }
.item.dragging { opacity: .35; }
.item.drop-before::before, .item.drop-after::after { content: ""; position: absolute; top: 6px; bottom: 6px; width: 4px; border-radius: 2px; background: var(--accent); }
.item.drop-before::before { left: -8px; }
.item.drop-after::after { right: -8px; }
.item.bad { border-color: #f0b4b0; background: #fff6f5; }
.item-top { display: flex; align-items: center; gap: 6px; }
.grid, .item-top, .thumb, .seg { -webkit-user-select: none; user-select: none; }
body.is-dragging { -webkit-user-select: none; user-select: none; cursor: grabbing; }
.grip { border: none; background: none; padding: 2px 4px; font-size: 16px; line-height: 1; color: var(--ink-3); cursor: grab; border-radius: 6px; touch-action: none; }
.grip:hover { background: #ecebe6; color: var(--ink); }
.grip:active { cursor: grabbing; }
.idx { font-size: 12px; font-weight: 700; color: #fff; background: var(--ink); border-radius: 6px; padding: 1px 7px; font-variant-numeric: tabular-nums; }
.fname { flex: 1; min-width: 0; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rm { border: none; background: none; color: var(--ink-3); font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.rm:hover { background: #eee; color: var(--err); }
.thumb { height: 150px; border-radius: 8px; background: repeating-conic-gradient(#efede8 0% 25%, #f7f6f3 0% 50%) 50% / 16px 16px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.thumb canvas { max-width: 100%; max-height: 100%; display: block; box-shadow: 0 1px 6px rgba(0,0,0,.18); }
.thumb .ph { font-size: 12px; color: var(--ink-3); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { flex: 1; border: none; background: #fff; padding: 5px 4px; font-size: 12.5px; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }

.dur { display: flex; align-items: center; gap: 6px; font-size: 12.5px; min-height: 28px; }
.dur-label { color: var(--ink-2); }
.dur-auto { border: 1px dashed #c9c6bd; background: #fff; border-radius: 8px; padding: 4px 8px; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.dur-auto:hover { border-color: var(--accent); color: var(--accent); }
.dur input { width: 52px; padding: 3px 6px; border: 1.5px solid var(--accent); border-radius: 8px; background: #fff; font-size: 13px; font-weight: 700; text-align: center; }
.dur .tag { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 7px; }
.dur .btn-text { font-size: 12px; margin-left: auto; }
.opt { display: flex; align-items: center; gap: 6px; min-height: 22px; font-size: 12.5px; color: var(--ink-2); }
.opt-dim { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.opt-dim input { margin: 0; accent-color: var(--accent); width: 14px; height: 14px; }
.opt-pan { color: var(--ink-3); }
.opt .btn-text { font-size: 12px; margin-left: auto; padding: 0 2px; }
.thumb.pannable { cursor: grab; touch-action: none; }
.thumb.pannable.panning { cursor: grabbing; }
.thumb.pannable canvas { outline: 2px solid transparent; transition: outline-color .12s; }
.thumb.pannable:hover canvas, .thumb.panning canvas { outline-color: var(--accent); }
.item.bad .dur-auto { color: var(--err); border-color: #f0b4b0; }

/* ---------- 步驟 2：總長 ---------- */
.total-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.total-row input { width: 64px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 10px; font-size: 18px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.total-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.step-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 18px; line-height: 1; padding: 0; }
.step-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.step-btn:disabled { opacity: .4; }
.unit { font-size: 14px; color: var(--ink-2); }


/* ---------- 步驟 3：尺寸 ---------- */
.size-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.size { --c: var(--accent); position: relative; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 2px solid var(--line); border-radius: 12px; background: #fff; text-align: left; transition: .12s; }
.size:hover { border-color: color-mix(in srgb, var(--c) 45%, #fff); }
.size.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, #fff); }
.size .shape-wrap { width: 30px; height: 34px; display: flex; align-items: center; justify-content: center; flex: none; }
.size .shape { background: color-mix(in srgb, var(--c) 30%, #fff); border-radius: 3px; }
.size.on .shape { background: var(--c); }
.size .t1 { font-weight: 700; font-size: 15px; }
.size .t2 { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.size .t3 { font-size: 11px; color: var(--ink-3); }
.size .check { position: absolute; top: 6px; right: 7px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #c9c6bd; background: #fff; }
.size.on .check { border-color: var(--c); background: var(--c); }
.size.on .check::after, .mini-check.on::after { content: ""; position: absolute; left: 3.5px; top: 0.5px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }

.custom-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; padding: 9px 10px; border: 2px dashed var(--line); border-radius: 12px; font-size: 14px; color: var(--ink-2); }
.custom-row.on { border-style: solid; border-color: #444; background: #f6f6f6; }
.custom-label { font-weight: 700; color: var(--ink); margin-right: 2px; }
.custom-row input { width: 68px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-align: center; font-variant-numeric: tabular-nums; }
.mini-check { position: relative; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #c9c6bd; background: #fff; padding: 0; flex: none; }
.mini-check.on { border-color: #444; background: #444; }
.custom-note { flex-basis: 100%; font-size: 12px; color: var(--ink-3); }
.custom-note:empty { display: none; }
.custom-note.err { color: var(--err); }

/* ---------- 步驟 4：匯出 ---------- */
.start-card { display: flex; flex-direction: column; }
.name-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); }
.name-row input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; }
.name-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.file-names { margin-top: 8px; font-size: 12px; color: var(--ink-3); line-height: 1.6; word-break: break-all; }
.file-names:empty { display: none; }
.errors { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.errors:empty { display: none; }
.errors div { font-size: 13px; line-height: 1.5; padding: 8px 10px; border-radius: 10px; background: #fdecea; color: var(--err); border: 1px solid #f5c2be; }
.errors div.info { background: #f3f2ee; color: var(--ink-2); border-color: var(--line); }
.start-actions { display: flex; gap: 10px; margin-top: 12px; }
.btn-primary { flex: 1; border: none; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; padding: 13px; border-radius: 12px; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-primary:disabled { background: #c9ced6; filter: none; }
.btn-secondary { border: 1px solid var(--line); background: #fff; font-size: 15px; padding: 12px 18px; border-radius: 12px; }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { color: var(--ink-3); }

/* ---------- 共用：分頁籤 ---------- */
.tabs { display: flex; gap: 5px; flex-wrap: wrap; }
.tabs button { --c: var(--ink); display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 3px 11px; font-size: 13px; }
.tabs .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tabs button.on { background: var(--c); border-color: var(--c); color: #fff; }
.tabs button.on .dot { background: #fff; }

/* ---------- 視窗 ---------- */
.sheet { position: fixed; inset: 0; background: rgba(20,20,20,.4); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.sheet-panel { width: min(600px, 100%); max-height: 92vh; display: flex; flex-direction: column; background: #fff; border-radius: 18px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.sheet-panel h2 { margin: 0; font-size: 20px; }
.preview-panel { width: min(960px, 100%); }
.preview-head { display: flex; align-items: center; gap: 14px; }
.preview-head .tabs { flex: 1; }
.close-btn { border: none; background: #f1f0ec; width: 34px; height: 34px; border-radius: 50%; font-size: 20px; line-height: 1; padding: 0; color: var(--ink-2); flex: none; }
.close-btn:hover { background: #e4e2dc; color: var(--ink); }
.preview-box { position: relative; margin-top: 14px; height: min(64vh, 640px); border-radius: 12px; background: #1b1b1d; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.preview-box canvas { display: block; box-shadow: 0 4px 24px rgba(0,0,0,.4); }
.preview-loading { position: absolute; color: #fff; font-size: 15px; background: rgba(0,0,0,.55); padding: 10px 18px; border-radius: 10px; }
.player { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.pbtn { flex: none; width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.pbtn:hover { background: var(--accent); }
.pbtn svg { width: 20px; height: 20px; }
.pbtn .i-pause, .pbtn.playing .i-play { display: none; }
.pbtn.playing .i-pause { display: block; }
#seek { flex: 1; min-width: 0; height: 24px; accent-color: var(--accent); }
.time { flex: none; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 96px; text-align: right; }
.preview-note { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-3); }

.run-sub { margin: 6px 0 14px; color: var(--ink-2); font-size: 14px; }
.overall { height: 10px; background: #eceae4; border-radius: 6px; overflow: hidden; flex: none; }
.overall div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.job-list { list-style: none; padding: 0; margin: 16px 0; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; }
.job-list li { display: grid; grid-template-columns: 1fr 120px 70px; align-items: center; gap: 12px; font-size: 14px; }
.job-list .jn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-list .jbar { height: 6px; background: #eceae4; border-radius: 4px; overflow: hidden; }
.job-list .jbar div { height: 100%; width: 0; background: var(--accent); }
.job-list .js { font-size: 13px; color: var(--ink-2); text-align: right; }
.job-list li.done .js { color: var(--ok); }
.job-list li.done .jbar div { background: var(--ok); }
.job-list li.error .js, .job-list li.error .jn { color: var(--err); }
.job-list .jerr { grid-column: 1 / -1; font-size: 12px; color: var(--err); margin-top: -4px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.sheet-actions .btn-primary { flex: none; padding: 12px 22px; font-size: 15px; }

.drag-overlay { position: fixed; inset: 0; background: rgba(31,111,235,.12); border: 4px dashed var(--accent); display: flex; align-items: center; justify-content: center; z-index: 20; pointer-events: none; }
.drag-overlay div { background: var(--accent); color: #fff; font-size: 20px; font-weight: 600; padding: 16px 28px; border-radius: 14px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #323232; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: 80vw; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 24px; }
  .side { position: static; }
  .topbar { padding: 16px 16px 4px; }
  .banner { margin: 8px 16px 0; }
}
@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .thumb { height: 120px; }
  .size-grid { grid-template-columns: 1fr; }
}
