﻿:root {
  --bg: #101318;
  --bg2: #171c24;
  --bg3: #1f2630;
  --line: #2c3542;
  --text: #e8ecf2;
  --text-dim: #93a0b2;
  --accent: #d6b16a;
  --accent-dark: #b3903f;
  --blue: #5b9bd5;
  --red: #e06c6c;
  --green: #6cc08b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; overflow: hidden;
}

header {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-size: 20px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.brand .sub { font-size: 12px; font-weight: 400; color: var(--text-dim); margin-left: 6px; }
.folder-bar { display: flex; gap: 8px; flex: 1; }
.folder-bar input {
  flex: 1; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 14px;
}
.folder-bar input:focus { outline: none; border-color: var(--accent); }

main { flex: 1; display: flex; min-height: 0; }

/* ---------- 側欄 ---------- */
#sidebar {
  width: 380px; min-width: 320px; display: flex; flex-direction: column;
  background: var(--bg2); border-right: 1px solid var(--line); overflow-y: auto;
}
.panel { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1 0 auto; display: flex; flex-direction: column; }
.panel h2 { font-size: 13px; color: var(--text-dim); letter-spacing: 1px; margin-bottom: 10px; }
#list-summary { font-weight: 400; }

.mode-option {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer;
}
.mode-option:has(input:checked) { border-color: var(--accent); background: rgba(214,177,106,.07); }
.mode-option input { margin-top: 4px; accent-color: var(--accent); }
.mode-option b { display: block; font-size: 15px; }
.mode-option span { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

.list-actions { display: flex; gap: 8px; margin-bottom: 8px; }
#video-list { list-style: none; overflow-y: auto; flex: 1; min-height: 120px; }
#video-list .empty { color: var(--text-dim); font-size: 13px; padding: 20px 0; text-align: center; }
.video-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; font-size: 14px;
}
.video-item:hover { background: var(--bg3); }
.video-item.active { background: rgba(91,155,213,.15); outline: 1px solid var(--blue); }
.video-item input { accent-color: var(--accent); }
.video-item .vname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: 11px; padding: 2px 7px; border-radius: 10px; white-space: nowrap;
  background: var(--bg3); color: var(--text-dim);
}
.badge.has { background: rgba(108,192,139,.15); color: var(--green); }

button {
  font-family: inherit; font-size: 14px; border: none; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; color: var(--text); background: var(--bg3);
}
button:hover { filter: brightness(1.15); }
button.primary { background: var(--accent-dark); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent); color: #1a1a1a; }
button.big { width: 100%; padding: 12px; font-size: 15px; margin-top: 10px; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text-dim); }
button.ghost:hover { color: var(--text); border-color: var(--text-dim); }
button.mini { padding: 3px 8px; font-size: 12px; }

/* ---------- 批次進度 ---------- */
#job-list { list-style: none; font-size: 13px; }
#job-list li { display: flex; gap: 8px; padding: 4px 0; align-items: center; }
#job-list .j-time { color: var(--text-dim); font-size: 11px; white-space: nowrap; margin-left: auto; }
#job-summary { font-weight: 400; color: var(--text-dim); }
#job-list .st { font-size: 11px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.st.queued { background: var(--bg3); color: var(--text-dim); }
.st.running { background: rgba(91,155,213,.2); color: var(--blue); }
.st.done { background: rgba(108,192,139,.2); color: var(--green); }
.st.error { background: rgba(224,108,108,.2); color: var(--red); }
#job-log {
  margin-top: 8px; max-height: 180px; overflow-y: auto; font-size: 12px;
  color: var(--text-dim); background: var(--bg); border-radius: 8px; padding: 8px 10px;
  white-space: pre-wrap; word-break: break-all;
}

/* ---------- 編輯器 ---------- */
#editor { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#editor-placeholder { margin: auto; text-align: center; color: var(--text-dim); font-size: 16px; }
#editor-placeholder .hint { font-size: 13px; margin-top: 8px; }
#editor-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#player-wrap { position: relative; background: #000; flex: 0 0 auto; }
#player { display: block; width: 100%; max-height: 44vh; background: #000; }
#overlay-sub {
  /* left/width/bottom/font-size 由 JS 依「影片實際畫面框」計算——
     直式影片有左右黑邊時，字幕必須限制在畫面內並自動換行（燒出來也是這樣）。
     顏色/邊框/底色等樣式由 JS 依「樣式」下拉選單套在 #overlay-text 上。 */
  position: absolute; left: 0; right: auto; bottom: 12%; text-align: center;
  font-size: 20px; font-weight: 700; pointer-events: none; line-height: 1.35;
}
#overlay-text {
  display: inline-block; white-space: pre-wrap; overflow-wrap: break-word;
  max-width: 100%; border-radius: 6px;
}
#overlay-title {
  /* 置頂標題：left/width/top/font-size 由 JS 依畫面框計算 */
  position: absolute; left: 0; right: auto; top: 8%; text-align: center;
  pointer-events: none; color: #fff; line-height: 1.3;
  text-shadow: 0 2px 6px rgba(0,0,0,.6), 0 0 2px rgba(0,0,0,.5);
}
#overlay-title span { white-space: pre-wrap; overflow-wrap: break-word; }
#burn-title {
  width: 180px; background: var(--bg2, #181825); color: inherit;
  border: 1px solid var(--line, #45475a); border-radius: 6px; padding: 4px 8px;
}
#style-panel, #burn-panel {
  background: var(--bg2, #181825); border-top: 1px solid var(--line, #45475a);
  padding: 8px 12px; font-size: 13px;
}
.sp-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 4px 0; }
.sp-row label { display: flex; gap: 6px; align-items: center; }
.sp-row input[type=range] { width: 90px; }
.sp-row input[type=text] {
  background: var(--bg, #11111b); color: inherit;
  border: 1px solid var(--line, #45475a); border-radius: 6px; padding: 4px 8px;
}
#st-saved-list { display: inline-flex; gap: 6px; flex-wrap: wrap; }
/* ── 時間軸（取代單純波形）：波形當背景 ＋ 字幕區塊 ＋ 秒數刻度 ＋ 播放頭 ── */
#timeline {
  position: relative; width: 100%; height: 62px; background: #0b0b12;
  cursor: pointer; border-top: 1px solid var(--line, #45475a); overflow: hidden;
  user-select: none;
}
#waveform {
  position: absolute; inset: 0 0 18px 0; display: block;
  width: 100%; height: calc(100% - 18px); object-fit: fill; opacity: .5;
}
#tl-cues { position: absolute; left: 0; right: 0; top: 4px; height: 14px; }
.tl-cue {
  position: absolute; top: 0; height: 14px; border-radius: 3px;
  background: rgba(214,177,106,.55); border: 1px solid rgba(214,177,106,.9);
}
.tl-cue:hover { background: rgba(214,177,106,.85); }
.tl-cue.sel { background: var(--blue, #5b9bd5); border-color: #fff; }
#tl-ticks { position: absolute; left: 0; right: 0; bottom: 0; height: 18px; }
.tl-tick { position: absolute; bottom: 0; transform: translateX(-50%); text-align: center; }
.tl-tick i { display: block; width: 1px; height: 6px; margin: 0 auto;
  background: var(--text-dim, #93a0b2); opacity: .6; }
.tl-tick b { font-size: 10px; font-weight: 400; color: var(--text-dim, #93a0b2);
  font-variant-numeric: tabular-nums; }
#tl-head {
  position: absolute; top: 0; bottom: 18px; width: 2px; left: 0;
  background: #ff5b5b; box-shadow: 0 0 6px rgba(255,91,91,.8); pointer-events: none;
}
#tl-hover {
  position: absolute; top: 20px; display: none; transform: translateX(-50%);
  background: rgba(0,0,0,.85); color: #fff; font-size: 11px; padding: 1px 6px;
  border-radius: 4px; pointer-events: none; font-variant-numeric: tabular-nums;
}
#video-notice {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(16,19,24,.92); border: 1px solid var(--line); color: var(--text);
  padding: 14px 22px; border-radius: 10px; font-size: 14px; text-align: center;
  max-width: 80%; line-height: 1.6;
}

#player-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--bg2); border-top: 1px solid var(--line); font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#seek { flex: 1; accent-color: var(--accent); }
#rate { background: var(--bg3); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px; }

#editor-toolbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
#editing-name { font-weight: 600; font-size: 15px; }
#dirty-flag { color: var(--accent); font-size: 13px; }
.spacer { flex: 1; }

#issues-bar {
  padding: 8px 16px; background: rgba(224,108,108,.1); color: var(--red);
  font-size: 13px; border-bottom: 1px solid var(--line); max-height: 90px; overflow-y: auto;
}
#issues-bar .warn { color: var(--accent); }

#cue-list { flex: 1; overflow-y: auto; padding: 10px 16px 40px; }
.cue-row {
  display: grid; grid-template-columns: 34px 210px 1fr 82px; gap: 10px;
  padding: 8px 10px; border-radius: 10px; margin-bottom: 6px;
  background: var(--bg2); border: 1px solid transparent; align-items: start;
}
.cue-row.active { border-color: var(--blue); background: rgba(91,155,213,.08); }
.cue-row.selected { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(214,177,106,.35) inset; }
.cue-main { display: flex; flex-direction: column; gap: 3px; }
.cue-meta { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.cue-meta.warn { color: var(--accent); }
button.ghost.active { border-color: var(--accent); color: var(--accent); }
.cue-row.error { border-color: var(--red); }
.cue-idx { color: var(--text-dim); font-size: 12px; padding-top: 8px; text-align: right; }
.cue-times { display: flex; flex-direction: column; gap: 4px; }
.cue-times .trow { display: flex; gap: 4px; align-items: center; }
.cue-times input {
  width: 96px; padding: 5px 6px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums;
}
.cue-times input:focus { outline: none; border-color: var(--accent); }
.cue-text {
  width: 100%; min-height: 56px; resize: vertical; padding: 8px 10px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  color: var(--text); font-size: 15px; font-family: inherit; line-height: 1.5;
}
.cue-text:focus { outline: none; border-color: var(--accent); }
.cue-ops { display: flex; flex-direction: column; gap: 4px; }

/* ---------- 紀錄面板 ---------- */
#history-panel h2 { display: flex; justify-content: space-between; align-items: center; }
#history-list { list-style: none; max-height: 240px; overflow-y: auto; font-size: 12px; }
#history-list .empty { color: var(--text-dim); padding: 10px 0; text-align: center; }
.history-item {
  display: grid; grid-template-columns: 76px 56px 1fr; gap: 4px 8px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer; align-items: center;
}
.history-item:hover { background: var(--bg3); }
.history-item.failed { opacity: .75; }
.history-item.failed .h-detail { color: var(--red); }
.h-ts { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.h-act { font-size: 11px; padding: 1px 6px; border-radius: 8px; text-align: center; }
.h-act.generate { background: rgba(91,155,213,.18); color: var(--blue); }
.h-act.export { background: rgba(108,192,139,.18); color: var(--green); }
.h-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-detail { grid-column: 2 / 4; color: var(--text-dim); }

/* ---------- 系統狀態 ---------- */
#diag-panel h2 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
#diag-list { list-style: none; font-size: 12px; }
#diag-list .empty { color: var(--text-dim); padding: 8px 0; text-align: center; }
.diag-item { display: flex; gap: 8px; padding: 5px 4px; align-items: flex-start; }
.d-icon { flex: 0 0 auto; }
.d-body { display: flex; flex-direction: column; gap: 1px; }
.d-body b { font-weight: 600; }
.d-body span { color: var(--text-dim); }
.diag-item.bad .d-body b { color: var(--red); }
.diag-item.warn .d-body b { color: var(--accent); }
.d-fix { color: var(--accent) !important; }
#diag-log { margin-top: 6px; font-size: 11px; color: var(--text-dim); }
#diag-log summary { cursor: pointer; }
#diag-log pre {
  margin-top: 6px; max-height: 160px; overflow: auto; white-space: pre-wrap;
  word-break: break-all; background: var(--bg); border-radius: 6px; padding: 8px;
}

footer {
  display: flex; justify-content: space-between; padding: 6px 20px;
  background: var(--bg2); border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-dim);
}

#toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--accent); color: var(--text);
  padding: 10px 22px; border-radius: 10px; font-size: 14px; z-index: 99;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

/* ===== SubtitleHub 多人版擴充 ===== */

/* header 右側控制 */
.hub-controls { display: flex; gap: 8px; align-items: center; }
.hub-controls .ghost { white-space: nowrap; }

/* 老師模式：藏資料夾列（固定看自己的上傳區） */
body.teacher .folder-bar { display: none; }
body.teacher #btn-pick { display: none; }

/* 分隔線（拖曳調大小） */
#split-side { width: 6px; cursor: col-resize; background: transparent; flex: 0 0 auto; }
#split-side:hover, #split-main:hover { background: var(--accent, #89b4fa); opacity: .45; }
#editor-body:not(.layout-side) #split-main { height: 6px; cursor: row-resize; flex: 0 0 auto; }
#editor-body.layout-side #split-main { width: 6px; cursor: col-resize; flex: 0 0 auto; }

/* 影片區大小（上下模式高度可拖） */
#player { max-height: var(--player-h, 44vh); }

/* 左右佈局：影片在左、字幕編輯在右 */
#editor-body.layout-side { flex-direction: row; }
#editor-body.layout-side #player-wrap {
  width: var(--player-w, 55%); flex: 0 0 auto; min-width: 280px;
  display: flex; flex-direction: column; min-height: 0;
}
#editor-body.layout-side #player { max-height: none; flex: 1; min-height: 0;
  object-fit: contain; width: 100%; }
#edit-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#editor-body.layout-side #edit-pane { border-left: 1px solid var(--line); }

/* 面板隱藏 */
body.hide-sidebar #sidebar, body.hide-sidebar #split-side { display: none; }
body.hide-history #history-panel { display: none; }
body.hide-diag #diag-panel { display: none; }
body.hide-tools #btn-loop, body.hide-tools #btn-add-cue, body.hide-tools #btn-find,
body.hide-tools #btn-split, body.hide-tools #btn-merge, body.hide-tools #btn-shift,
body.hide-tools #btn-proof, body.hide-tools #btn-fix-terms, body.hide-tools #btn-ai-menu,
body.hide-tools #btn-more { display: none; }

/* 匯入面板 */
#import-panel input[type="text"], #import-panel #import-url {
  width: 100%; padding: 8px 10px; margin-bottom: 6px;
}
.import-actions { display: flex; gap: 6px; }
.import-actions .primary { flex: 1; }
#upload-progress { margin-top: 8px; }
.up-bar { height: 8px; background: #26263a; border-radius: 4px; overflow: hidden; }
.up-fill { height: 100%; width: 0%; background: var(--accent, #89b4fa); transition: width .2s; }
.up-text { font-size: 12px; color: var(--text-dim); }

/* 任務列的步驟/剩餘時間 */
#job-list .j-step { display: block; font-size: 11px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#job-list .j-user { color: var(--accent, #89b4fa); font-size: 11px; margin-right: 4px; }

/* 登入 */
#login-overlay { position: fixed; inset: 0; background: rgba(10,10,18,.92);
  display: flex; align-items: center; justify-content: center; z-index: 999; }
.login-card { background: #16162a; border: 1px solid var(--line); border-radius: 14px;
  padding: 34px 38px; width: min(420px, 92vw); text-align: center; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-hint { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }
#login-users { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.login-user { padding: 12px; font-size: 16px; border-radius: 10px; cursor: pointer;
  background: #20203a; border: 1px solid var(--line); color: var(--text); }
.login-user:hover { background: #2a2a4a; }
.login-new { display: flex; gap: 6px; }
.login-new input { flex: 1; padding: 10px; }
.login-error { color: #f38ba8; font-size: 13px; margin-top: 12px; }

/* 彈出選單 */
.popup-menu { position: fixed; top: 54px; right: 12px; z-index: 900;
  background: #16162a; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; width: 340px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.popup-menu h3 { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.popup-menu hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.lm-row { display: flex; align-items: center; gap: 8px; padding: 4px 0;
  font-size: 14px; justify-content: space-between; }
.lm-row input[type="radio"], .lm-row input[type="checkbox"] { margin-right: 4px; }
label.lm-row { justify-content: flex-start; cursor: pointer; }
.lm-hint { font-size: 12px; color: var(--text-dim); margin-top: 8px; line-height: 1.5; }
.um-user { border-bottom: 1px dashed #26263a; }

/* 共享 */
.import-share { display: flex; align-items: flex-start; gap: 6px; margin-top: 8px;
  font-size: 12px; color: var(--text-dim); cursor: pointer; line-height: 1.5; }
.share-btn { background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 6px; cursor: pointer; font-size: 12px; color: var(--text-dim); }
.share-btn.on { border-color: var(--accent, #89b4fa); color: var(--accent, #89b4fa); }
.badge.shared { background: #2a2a4a; color: #89b4fa; }

/* ===== 手機響應式（2026-08-20 Vic 手機實測：版面擠壓重疊、按播放跳全螢幕）===== */
#btn-drawer { display: none; }

@media (max-width: 1024px) {
  header { flex-wrap: wrap; gap: 6px; padding: 6px 8px; }
  #btn-drawer { display: inline-block; font-size: 18px; padding: 4px 10px; }
  .folder-bar { display: none; }         /* 手機用抽屜裡的清單即可 */
  .brand .sub { display: none; }

  /* 左側欄變成抽屜：☰ 開關，蓋在內容上 */
  #sidebar {
    position: fixed; left: 0; top: 46px; bottom: 0; z-index: 800;
    width: min(86vw, 380px) !important;
    background: #12121e; border-right: 1px solid var(--line);
    transform: translateX(-105%); transition: transform .2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.5); overflow-y: auto;
  }
  body.drawer-open #sidebar { transform: none; }
  #split-side, #split-main { display: none; }

  /* 影片固定高度、不跳版 */
  #player { max-height: 38vh; }
  #editor-body.layout-side { flex-direction: column; }   /* 手機一律上下 */
  #editor-body.layout-side #player-wrap { width: 100% !important; }

  /* 播放列與工具列換行、縮小 */
  #player-bar { flex-wrap: wrap; row-gap: 4px; height: auto; padding: 6px; }
  #player-bar #seek { min-width: 120px; flex: 1 1 100%; order: -1; }
  #editor-toolbar { flex-wrap: wrap; row-gap: 4px; padding: 6px; max-height: none; }
  #editor-toolbar button { font-size: 12px; padding: 4px 8px; }
  #burn-title { width: 120px; }

  /* 逐句列表窄版：勾選+時間窄欄+內容 */
  .cue-row { grid-template-columns: 24px 88px 1fr; gap: 6px; padding: 6px 4px; }
  .cue-times input { font-size: 11px; padding: 2px 4px; }
  .cue-ops { flex-direction: row; grid-column: 2 / 4; }
  #cue-list { padding: 6px 8px 60px; }

  .popup-menu { width: min(92vw, 340px); }
  .login-card { padding: 24px 20px; }
}

/* 手機：樣式調整/進階按鈕預設收合，⚙️ 工具展開（2026-08-20 Vic：佔太大看不到字幕編輯） */
#btn-tools { display: none; }
@media (max-width: 1024px) {
  #btn-tools { display: inline-block; }
  body:not(.tools-open) #player-bar > :is(#rate, .sub-pos-label, #sub-pos, #sub-pos-val,
    #sub-size, #sub-size-val, #sub-font, #sub-style, #btn-style-panel, #btn-quality) { display: none; }
  body:not(.tools-open) #editor-toolbar > :is(#btn-loop, #btn-add-cue, #btn-find, #btn-split,
    #btn-merge, #btn-shift, #btn-proof, #btn-fix-terms, #btn-ai-menu, #btn-more,
    #burn-title, #btn-burn-opt, #btn-burn, #btn-burn-reveal, #btn-burn-social) { display: none; }
  body.tools-open #btn-tools { border-color: var(--accent, #89b4fa); color: var(--accent, #89b4fa); }
}

/* 講師選擇 */
#teacher-select { max-width: 150px; padding: 3px 6px; font-size: 12px;
  background: #20203a; color: var(--text); border: 1px solid var(--line); border-radius: 6px; }
