:root {
  color-scheme: dark;
  --bg: #070a0b;
  --panel: #111719;
  --panel-2: #172022;
  --panel-3: #223033;
  --ink: #f0f7f6;
  --muted: #a6b7b4;
  --quiet: #778b88;
  --border: rgb(175 210 205 / 0.16);
  --border-strong: rgb(var(--accent-rgb) / 0.42);
  --accent: #19d3d8;
  --accent-ink: #061112;
  --accent-soft: rgb(var(--accent-rgb) / 0.16);
  --warning: #e8ac43;
  --danger: #f06f4f;
  --danger-ink: #180704;
  --black: #020303;
  --shadow-soft: 0 18px 42px rgb(0 0 0 / 0.34);
  /* 主題可覆寫的衍生色：淡色一律寫成 rgb(var(--x-rgb) / α)，跟著主色一起換。 */
  --accent-rgb: 25 211 216;
  --accent-bright: #63f5fa;
  --warning-rgb: 232 172 67;
  --danger-rgb: 240 111 79;
  --danger-soft: #ffad99;
  --gold: #ffd36a;
  --gold-rgb: 255 211 106;
  --success: #49e49a;
  --success-rgb: 73 228 154;
  --info: #74c0fc;
  --info-rgb: 34 139 230;
  /* 面板、欄位與覆蓋層底色；淺色主題整組覆寫，--black 是播放區的螢幕黑，兩種主題相同。 */
  --body-bg: linear-gradient(135deg, rgb(7 10 11) 0%, rgb(10 16 16) 46%, rgb(4 5 6) 100%);
  --library-bg: linear-gradient(180deg, rgb(21 30 32 / 0.98), rgb(12 16 17 / 0.98));
  --toolbar-bg: linear-gradient(180deg, rgb(19 27 29 / 0.98), rgb(9 12 13 / 0.98));
  --viewer-bg: linear-gradient(180deg, rgb(14 20 21), rgb(8 12 13) 60%);
  --brand-mark-bg: linear-gradient(160deg, rgb(31 45 48 / 0.92), rgb(5 8 9 / 0.92));
  --menu-bg: linear-gradient(180deg, rgb(16 24 28), rgb(9 12 13));
  --surface-bg: linear-gradient(180deg, rgb(24 35 37 / 0.98), rgb(7 11 12 / 0.98));
  --translucent-panel: rgb(13 18 20 / 0.7);
  --translucent-panel-strong: rgb(13 18 20 / 0.85);
  --field-bg: rgb(3 6 7 / 0.78);
  --well-bg: rgb(3 6 7 / 0.55);
  --well-bg-soft: rgb(3 6 7 / 0.34);
  --well-bg-strong: rgb(5 8 9 / 0.9);
  --well-shade: linear-gradient(180deg, rgb(0 0 0 / 0.08), rgb(0 0 0 / 0.28));
  --tooltip-bg: rgb(6 10 11 / 0.96);
  --tooltip-ink: #f0f7f6;
  --highlight: rgb(255 255 255 / 0.04);
  --hover-wash: rgb(255 255 255 / 0.03);
  --bubble-user-deep: rgb(18 90 94 / 0.28);
  /* 播放器卡片的邊框與投影，以及 Ask AI 面板向左的投影；淺色主題改成淡色調。 */
  --stage-frame-border: rgb(175 210 205 / 0.14);
  --stage-frame-shadow: 0 18px 44px rgb(0 0 0 / 0.5);
  --ask-ai-shadow: -8px 0 28px rgb(0 0 0 / 0.42);
  /* 對話框外框：圓角、投影與遮罩；淺色主題改用帶色調的淺遮罩與較淡的投影。 */
  --dialog-radius: 12px;
  /* 對話框靠上固定錨點的距離：內容變高只往下延伸，使用者正在看的欄位不會跟著重新置中而跳動。 */
  --dialog-offset: clamp(16px, 8dvh, 64px);
  --dialog-shadow: 0 24px 70px rgb(0 0 0 / 0.68);
  --dialog-backdrop: rgb(0 0 0 / 0.68);
  /* 學習筆記的便利貼：深色主題降低亮度，淺色主題用較鮮的黃；字一律深色。 */
  --note-paper: #e6cd63;
  --note-paper-edge: #c7ab3e;
  --note-ink: #2a2310;
  --note-muted: rgb(42 35 16 / 0.64);
  --note-shadow: 0 10px 24px rgb(0 0 0 / 0.42);
  --note-texture: url("/web/assets/note-paper-texture.webp?v=f249b6892341");
  --note-tape: url("/web/assets/note-washi-tape.webp?v=30016b0eb5aa");
  --shelf-bg: linear-gradient(180deg, rgb(255 255 255 / 0.035), rgb(255 255 255 / 0.015));
  --radius-sm: 6px;
  --radius-md: 8px;
  --asset-logo: url("/web/assets/logo-mark-ui.webp?v=ee9d1652e99f");
  --asset-stage: url("/web/assets/stage-backdrop.webp?v=3b6eaf044c10");
  --asset-burn-caption-icon: url("/web/assets/icon-burn-caption.webp?v=54f65a90544f");
  --icon-folder: url("/web/assets/icons/folder.png?v=f6378752ec04");
  --icon-video: url("/web/assets/icons/video-v2.png?v=c013dc7423af");
  --icon-reload: url("/web/assets/icons/reload.png?v=afba79e84d02");
  --sidebar-w: clamp(292px, 24vw, 360px);
  --sidebar-min-w: 260px;
  --sidebar-max-w: 560px;
  --sidebar-collapsed-w: 64px;
  --ask-ai-w: 420px;
  --ask-ai-min-w: 320px;
  --ask-ai-max-w: 960px;
  --video-section-h: 94px;
  --toolbar-min: 86px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --z-content: 1;
  --z-resize: 10;
  --z-menu: 20;
  --z-toast: 30;
  --z-tooltip: 40;
}

/* 淺色主題：只覆寫顏色變數，版面規則不變。深色是預設（<html> 沒有 data-theme），由 theme-toggle.js 切換。 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e9eeee;
  --panel: #f6f9f9;
  --panel-2: #e7eded;
  --panel-3: #d9e2e2;
  --ink: #0f1b1c;
  --muted: #475c5a;
  --quiet: #5a6e6f;
  --border: rgb(12 42 44 / 0.14);
  --border-strong: rgb(var(--accent-rgb) / 0.55);
  --accent: #0b7a7f;
  --accent-rgb: 11 122 127;
  --accent-ink: #ffffff;
  --accent-soft: rgb(var(--accent-rgb) / 0.14);
  --accent-bright: #06666a;
  --warning: #946000;
  --warning-rgb: 148 96 0;
  --danger: #c43d22;
  --danger-ink: #ffffff;
  --danger-rgb: 196 61 34;
  --danger-soft: #a8341c;
  --gold: #8a6000;
  --gold-rgb: 138 96 0;
  --success: #197c50;
  --success-rgb: 25 124 80;
  --info: #1b6fc2;
  --info-rgb: 27 111 194;
  --shadow-soft: 0 18px 42px rgb(15 35 37 / 0.12);
  --body-bg: linear-gradient(135deg, #eef3f3 0%, #e7eded 46%, #e3e9e9 100%);
  --library-bg: linear-gradient(180deg, rgb(255 255 255 / 0.98), rgb(242 246 246 / 0.98));
  --toolbar-bg: linear-gradient(180deg, rgb(255 255 255 / 0.98), rgb(243 247 247 / 0.98));
  --viewer-bg: linear-gradient(180deg, #e6ecec, #dfe6e6 140px);
  --menu-bg: linear-gradient(180deg, #ffffff, #f1f5f5);
  --surface-bg: linear-gradient(180deg, rgb(255 255 255 / 0.98), rgb(240 245 245 / 0.98));
  --translucent-panel: rgb(246 249 249 / 0.8);
  --translucent-panel-strong: rgb(246 249 249 / 0.92);
  --field-bg: rgb(255 255 255 / 0.92);
  --well-bg: rgb(12 42 44 / 0.06);
  --well-bg-soft: rgb(12 42 44 / 0.04);
  --well-bg-strong: rgb(12 42 44 / 0.1);
  --well-shade: linear-gradient(180deg, rgb(255 255 255 / 0.5), rgb(255 255 255 / 0));
  --highlight: rgb(12 42 44 / 0.04);
  --hover-wash: rgb(12 42 44 / 0.05);
  --bubble-user-deep: rgb(var(--accent-rgb) / 0.1);
  --stage-frame-border: rgb(12 42 44 / 0.18);
  --stage-frame-shadow: 0 18px 44px rgb(15 35 37 / 0.18);
  --ask-ai-shadow: -8px 0 28px rgb(15 35 37 / 0.1);
  --dialog-shadow: 0 24px 60px rgb(15 35 37 / 0.22);
  --dialog-backdrop: rgb(10 30 32 / 0.38);
  --note-paper: #fde88a;
  --note-paper-edge: #e5c64a;
  --note-ink: #3a2f0b;
  --note-muted: rgb(58 47 11 / 0.66);
  --note-shadow: 0 10px 22px rgb(60 48 10 / 0.2);
  --shelf-bg: linear-gradient(180deg, rgb(255 255 255 / 0.7), rgb(255 255 255 / 0.45));
}

/* 播放區是「螢幕」：淺色主題下維持深色，字幕、控制列與空狀態文字仍是淺字深底，主色也維持亮青色。 */
:root[data-theme="light"] .stage {
  color-scheme: dark;
  --ink: #f0f7f6;
  --muted: #a6b7b4;
  --quiet: #778b88;
  --accent: #19d3d8;
  --accent-rgb: 25 211 216;
  --accent-ink: #061112;
  --panel-2: #172022;
  --panel-3: #223033;
  --border: rgb(175 210 205 / 0.16);
  --border-strong: rgb(var(--accent-rgb) / 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    var(--body-bg),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Microsoft JhengHei", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 0 minmax(0, 1fr);
  grid-template-areas: "library resize viewer";
  height: 100dvh;
  min-height: 0;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 0 minmax(0, 1fr);
}

.app-shell.is-resizing,
.app-shell.is-resizing-ask-ai {
  cursor: col-resize;
  user-select: none;
  transition: none !important;
}

.app-shell.is-resizing-ask-ai .ask-ai-panel,
.app-shell.is-resizing-ask-ai .viewer-stage-container .stage-column {
  transition: none !important;
}

/* 側欄五列：標題／搜尋列／標籤列／資料夾／影片；標籤列在收合側欄與手機版面會隱藏。 */
.library {
  grid-area: library;
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) minmax(0, var(--video-section-h));
  min-height: 0;
  background:
    var(--library-bg),
    var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.sidebar-resize-handle {
  grid-area: resize;
  position: relative;
  z-index: var(--z-resize);
  width: 12px;
  height: 100%;
  justify-self: center;
  cursor: col-resize;
  touch-action: none;
  outline: 0;
}

.sidebar-resize-handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: transparent;
}

.sidebar-resize-handle:hover::before,
.sidebar-resize-handle:focus-visible::before,
.app-shell.is-resizing .sidebar-resize-handle::before {
  background: var(--accent);
  box-shadow: 0 0 0 1px rgb(var(--accent-rgb) / 0.18), 0 0 18px rgb(var(--accent-rgb) / 0.28);
}

.sidebar-collapsed .sidebar-resize-handle {
  display: none;
}

.library-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--brand-mark-bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 3px;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1,
.brand-copy p,
.section-heading h2,
.now-playing h2,
.now-playing p,
.stage-empty h3,
.stage-empty p {
  margin: 0;
}

.brand-copy h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-copy p {
  margin-top: 2px;
  max-width: 28ch;
  color: var(--quiet);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  margin-left: auto;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}

.sidebar-toggle:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.sidebar-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-toggle span {
  font-size: 22px;
  line-height: 1;
}

.sidebar-collapsed .library {
  grid-template-rows: auto minmax(0, 1fr);
}

.sidebar-collapsed .library-header {
  flex-direction: column;
  gap: 10px;
  padding: 12px 10px;
}

.sidebar-collapsed .brand-copy,
.sidebar-collapsed .library-controls,
.sidebar-collapsed .tag-bar,
.sidebar-collapsed .library-section {
  display: none;
}

.sidebar-collapsed .sidebar-toggle {
  margin-left: 0;
}

.library-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.library-search-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

.search-field {
  min-width: 0;
}

.search-field input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--field-bg);
  color: var(--ink);
  padding: 0 11px;
  outline: 0;
  box-shadow: inset 0 1px 0 var(--highlight);
}

.search-field input::placeholder {
  color: var(--muted);
}

.search-field input:focus-visible,
.add-video-button:focus-visible,
.secondary-button:focus-visible,
.folder-tab:focus-visible,
.tag-chip:focus-visible,
.tag-overflow-button:focus-visible,
.folder-item:focus-visible,
.folder-action:focus-visible,
.folder-restore-btn:focus-visible,
.folder-delete-btn:focus-visible,
.video-item:focus-visible,
.subtitle-chip:focus-visible,
.subtitle-format-toggle:focus-visible,
.action-menu-trigger:focus-visible,
.action-menu-item:focus-visible,
.source-link:focus-visible,
.closed-caption-button:focus-visible,
.finder-button:focus-visible,
.favorite-button:focus-visible,
.reading-button:focus-visible,
.dialog-close:focus-visible,
.reading-tab:focus-visible,
.reading-seek-link:focus-visible,
.reading-transcript-seek:focus-visible,
.reading-speak-button:focus-visible,
.settings-tab:focus-visible,
.settings-choice:focus-visible,
.settings-input:focus-visible,
.settings-select:focus-visible,
.settings-save:focus-visible,
.reading-copy-button:focus-visible,
.reading-content:focus-visible,
.confirm-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.add-video-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: var(--ink);
  padding: 0;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.add-video-button:hover:not([disabled]) {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.add-video-button[disabled] {
  opacity: 0.55;
  cursor: progress;
}

.add-video-button.is-processing::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border: 2px solid var(--panel-2);
  border-radius: 50%;
  background: var(--accent);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.secondary-button:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.secondary-button:disabled,
.confirm-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:active:not(:disabled),
.action-menu-item:active:not([disabled]) {
  filter: brightness(0.9);
}

#refreshBtn::before {
  content: "";
  width: 15px;
  height: 15px;
  background: var(--icon-reload) center / contain no-repeat;
}

.library-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-bottom: 1px solid var(--border);
}

.videos-section {
  border-bottom: 0;
  height: var(--video-section-h);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  color: var(--muted);
}

.section-heading h2 {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.section-heading h2::before {
  content: "";
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  background: center / contain no-repeat;
}

.folders-section .section-heading h2::before {
  width: 20px;
  height: 20px;
  background-image: var(--icon-folder);
}

.videos-section .section-heading h2::before {
  width: 20px;
  height: 20px;
  background-image: var(--icon-video);
}

.count {
  min-width: 24px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 1px 7px;
  text-align: center;
  font-size: 12px;
}

.folder-tabs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.folder-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.folder-tab .count {
  min-width: 20px;
  padding: 0 5px;
}

.folder-tab[aria-selected="true"] {
  border-color: var(--border-strong);
  background: var(--panel-3);
  color: var(--ink);
}

.folder-tab:hover {
  border-color: var(--border-strong);
}

/* 影片清單排序選擇器：沿用頁籤的膠囊外觀；標頭放不下時整組換行，窄螢幕不擠壞資料夾頁籤。 */
.folder-list-heading {
  flex-wrap: wrap;
}

.folder-sort {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  margin-left: auto;
}

#folderSortMode {
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}

#folderSortMode:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

#folderSortMode:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 標籤篩選列：單列晶片條，晶片過多時由右側「＋N」按鈕收合，其餘標籤放進 action-menu。 */
.tag-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 42px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.tag-bar[hidden] {
  display: none;
}

.tag-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.tag-overflow-wrapper {
  flex: 0 0 auto;
  margin-left: auto;
  position: relative;
}

/* 晶片外觀沿用 .folder-tab 的膠囊樣式；寬度不足時整條列裁切，不會把「＋N」推出側欄。 */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 3px 9px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tag-chip:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.tag-chip.is-active {
  border-color: var(--border-strong);
  background: var(--panel-3);
  color: var(--ink);
}

.tag-chip-clear {
  border-color: var(--border);
  color: var(--quiet);
}

/* 標籤文字：寬度不足時優先壓縮文字（保留可讀的一小段並顯示省略號），計數徽章不壓縮。 */
.tag-chip .tag-name,
.tag-chip .tag-chip-label {
  min-width: 1.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 計數徽章：篩選列晶片與標籤選單共用（app.js 目前輸出 .count，規格另稱 .tag-count）。 */
.tag-count,
.tag-chip .count,
.tag-menu-item .count {
  flex: 0 0 auto;
  min-width: 20px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 0 5px;
  text-align: center;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* 標籤編輯對話框內的可移除晶片。 */
.tag-chip-removable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tag-chip-removable .tag-chip-x {
  color: var(--quiet);
  font-size: 14px;
  line-height: 1;
}

.tag-chip-removable:hover .tag-chip-x {
  color: var(--danger);
}

/* app.js 的對話框晶片改用 .tag-chip-remove 按鈕（規格另稱 .tag-chip-x），需清掉瀏覽器預設按鈕外觀。 */
.tag-chip-remove {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--quiet);
  padding: 0;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.tag-chip-remove:hover {
  color: var(--danger);
}

.tag-overflow-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 9px;
  cursor: pointer;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tag-overflow-button:hover {
  border-color: var(--accent);
  color: var(--ink);
}

/* 由 hidden 屬性控制顯示，需覆蓋上面的 display。 */
.tag-overflow-button[hidden] {
  display: none;
}

.tag-bar-empty {
  color: var(--quiet);
  font-size: 11px;
}

.folder-list,
.video-list {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  min-height: 0;
  margin: 0;
  padding: 0 8px 10px;
  list-style: none;
}

.folder-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.folder-item,
.video-item {
  width: 100%;
  min-width: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.folder-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  min-width: 0;
  border-radius: var(--radius-md);
}

.folder-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
}

.folder-item::before,
.video-item::before {
  content: "";
  width: 18px;
  height: 18px;
  background: center / contain no-repeat;
  opacity: 0.82;
}

.folder-item::before {
  width: 22px;
  height: 22px;
  background-image: var(--icon-folder);
  opacity: 1;
}

.folder-item[data-favorite="true"]::before {
  content: "★";
  display: grid;
  place-items: center;
  background-image: none;
  color: var(--gold);
  font-size: 14px;
  line-height: 1;
  opacity: 1;
}

.video-item::before {
  width: 22px;
  height: 22px;
  background-image: var(--icon-video);
}

.folder-row:hover,
.video-item:hover {
  background: var(--panel-2);
}

.folder-row[data-current="true"],
.video-item[aria-current="true"] {
  background:
    linear-gradient(90deg, rgb(var(--accent-rgb) / 0.18), rgb(var(--accent-rgb) / 0.08)),
    var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.folder-row[data-current="true"] .folder-item::before,
.video-item[aria-current="true"]::before {
  opacity: 1;
}

/* custom 排序：資料夾本身就能拖曳（滑鼠按住移動、觸控長按後拖曳），鍵盤用方向鍵。 */
.folder-row.sortable .folder-item {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.folder-row.dragging .folder-item {
  cursor: grabbing;
}

.folder-row.dragging {
  opacity: 0.55;
}

/* 拖曳中的插入位置：畫在兩列間隙正中的分隔線（左端一個圓點），放開＝放到線的位置。
   用偽元素畫在列外，不跟列的圓角與選取框線混在一起。 */
.folder-row.sortable {
  position: relative;
}

.folder-row.drop-before::before,
.folder-row.drop-after::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 4px;
  height: 8px;
  background:
    radial-gradient(circle at 4px 50%, var(--accent) 3px, transparent 3.5px),
    linear-gradient(var(--accent), var(--accent)) right center / calc(100% - 4px) 2px no-repeat;
  pointer-events: none;
  z-index: 1;
}

/* 列與列之間的間隙是 3px：線的中心對齊間隙中央。 */
.folder-row.drop-before::before {
  top: -5.5px;
}

.folder-row.drop-after::after {
  bottom: -5.5px;
}

.folder-name,
.video-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-name {
  font-weight: 650;
}

/* 已備份到 Google Drive 的資料夾：名稱前綴單色 Google Drive 標誌，整理影片時一眼看出備份狀態。 */
.drive-backup-icon {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  fill: currentColor;
  color: var(--accent);
}

.folder-stats,
.video-meta,
.meta-line {
  color: var(--muted);
  font-size: 12px;
}

.folder-stats {
  min-width: 8ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.folder-status {
  min-width: auto;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.folder-status[data-state="failed"] {
  background: rgb(var(--warning-rgb) / 0.12);
  color: var(--warning);
}

.folder-action,
.folder-restore-btn,
.folder-delete-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.folder-row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.folder-action-icon {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.folder-action:hover,
.folder-restore-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.folder-delete-btn {
  border-color: rgb(var(--danger-rgb) / 0.48);
  background: rgb(var(--danger-rgb) / 0.12);
  color: var(--danger);
}

.folder-delete-btn:hover:not(:disabled) {
  border-color: var(--danger);
  background: rgb(var(--danger-rgb) / 0.24);
  color: var(--danger-soft);
}

.folder-delete-btn:disabled {
  opacity: 0.5;
  cursor: progress;
}

.resume-meta {
  color: var(--accent);
}

.video-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
}

.video-item {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 7px 8px;
}

.video-item[data-tooltip]::after,
#activeFolder[data-tooltip]::after,
#activeVideo[data-tooltip]::after,
#readingTitle[data-tooltip]::after,
#readingSubtitle[data-tooltip]::after,
#askAiSubtitle[data-tooltip]::after {
  content: attr(data-tooltip);
  position: fixed;
  z-index: var(--z-tooltip);
  top: var(--video-tooltip-y);
  left: var(--video-tooltip-x);
  width: max-content;
  max-width: min(560px, calc(100vw - 24px));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  box-shadow: 0 4px 8px rgb(0 0 0 / 0.36);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 650;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
  pointer-events: none;
}

.video-item > span:first-of-type {
  min-width: 0;
}

.video-title {
  display: block;
  font-size: 13px;
  font-weight: 650;
}

.video-meta {
  font-size: 11px;
}

.file-badge {
  align-self: start;
  border-radius: var(--radius-sm);
  background: var(--panel-3);
  color: var(--muted);
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

/* 影片列：標籤按鈕固定在列尾，圖示加文字標籤，讓使用者一眼看出可以為這部影片加標籤。 */
.video-row {
  position: relative;
}

.video-item {
  padding-right: 68px;
}

.video-tag-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 資料夾列名稱底下直接顯示前幾個標籤，其餘以「＋N」表示，篩選前就能看出這個資料夾有什麼標籤。 */
.folder-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.folder-tags {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.folder-tag-chip {
  flex: 0 0 auto;
  max-width: 108px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  padding: 1px 7px;
  font-size: 10px;
  line-height: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.folder-tag-more {
  flex: 0 0 auto;
  color: var(--quiet);
  font-size: 10px;
}

/* 資料夾列的標籤按鈕：與封存、刪除等動作同一排；有標籤時顯示數量並以主色標示。 */
.folder-tag-button {
  grid-auto-flow: column;
  gap: 3px;
  width: auto;
  min-width: 30px;
  padding: 0 7px;
}

.folder-tag-button.has-tags {
  color: var(--accent);
  border-color: var(--border-strong);
  background: var(--accent-soft);
}

.folder-tag-count {
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* 影片區標題的「＋ 標籤」按鈕：不必先找到列尾的小按鈕就能新增標籤。 */
.videos-section .section-heading {
  justify-content: flex-start;
}

.video-tags-add {
  flex: 0 0 auto;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 3px 9px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.video-tags-add:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--border-strong);
}

.video-tags-add:disabled {
  cursor: default;
  opacity: 0.5;
}

/* app.js 只在能算出座標時才設定提示位置；未設定時把提示移到畫面外，
   而且要往左上移：往右下會把清單的 scrollHeight 撐大，捲動時出現一大段空白。
   fixed 的提示假元素仍算在最近捲動容器的可捲動範圍內。 */
.video-item[data-tooltip]::after {
  top: var(--video-tooltip-y, -100dvh);
  left: var(--video-tooltip-x, -100vw);
}

.viewer {
  grid-area: viewer;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(var(--toolbar-min), auto) minmax(0, 1fr);
  background:
    var(--viewer-bg),
    var(--black);
}

.viewer-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px 12px;
  background:
    var(--toolbar-bg),
    var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--highlight), 0 4px 8px rgb(0 0 0 / 0.24);
}

.now-playing {
  min-width: 0;
}

.now-playing h2 {
  margin-top: 2px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 750;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 媒體標題是主標題；影片標題（網址匯入時是來源網址）放在上方的小字，過長時截斷。 */
.now-playing #activeVideo {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subtitle-bar {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 2px;
}

.viewer-actions {
  min-width: 0;
  display: flex;
  /* 空間不夠時換行，按鈕永遠不會被裁切到視窗外。 */
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.viewer-actions [data-tooltip] {
  position: relative;
}

.viewer-actions [data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: var(--z-tooltip);
  top: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: min(320px, calc(100vw - 24px));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  box-shadow: 0 4px 8px rgb(0 0 0 / 0.36);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 650;
  white-space: normal;
  overflow-wrap: normal;
  word-break: keep-all;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.viewer-actions [data-tooltip]:hover::after,
.viewer-actions [data-tooltip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

.action-menu .action-menu-item[data-tooltip]::after {
  content: none;
}

.subtitle-mode-group {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 2px;
  align-items: center;
  border-radius: 999px;
  background: var(--panel-2);
  padding: 2px;
  border: 1px solid var(--border);
}

.subtitle-chip {
  flex: 0 0 auto;
  min-width: 42px;
  min-height: 30px;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  padding: 0 10px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

/* 已選取的字幕維持強調色：hover 底色不能蓋過，否則白字落在淺底上看不見。 */
.subtitle-chip:hover:not([disabled]):not([aria-pressed="true"]) {
  background: var(--panel-3);
}

.subtitle-chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}

.subtitle-chip[disabled],
.subtitle-note {
  color: var(--quiet);
  cursor: not-allowed;
}

.subtitle-chip[disabled] {
  opacity: 0.56;
}

.subtitle-chip[disabled][aria-pressed="true"] {
  background: var(--panel-3);
  color: var(--muted);
  opacity: 1;
}

.subtitle-format-toggle {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 0 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.subtitle-format-toggle:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.subtitle-note {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  padding: 8px 11px;
  font-size: 12px;
  white-space: nowrap;
}

.favorite-button,
.reading-button {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgb(var(--accent-rgb) / 0.12), rgb(var(--accent-rgb) / 0.04)),
    var(--panel-2);
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.source-link:hover,
.favorite-button:hover,
.reading-button:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
  color: var(--ink);
}

.favorite-button[aria-pressed="true"] {
  border-color: rgb(var(--gold-rgb) / 0.68);
  background:
    linear-gradient(180deg, rgb(var(--gold-rgb) / 0.2), rgb(var(--gold-rgb) / 0.08)),
    var(--panel-2);
  color: var(--gold);
}

.favorite-button[disabled] {
  opacity: 0.55;
  cursor: progress;
}

.favorite-button svg,
.reading-button svg,
.reading-speak-button svg,
.dialog-close svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.finder-icon {
  fill: none;
  stroke: none;
}

.favorite-button[aria-pressed="true"] svg {
  fill: currentColor;
}

/* 主題切換：圖示顯示切換後的主題（深色時是太陽、淺色時是月亮），兩個圖示疊在同一格做旋轉淡入淡出。 */
.action-menu-wrapper {
  position: relative;
}

.action-menu-trigger {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgb(var(--accent-rgb) / 0.12), rgb(var(--accent-rgb) / 0.04)),
    var(--panel-2);
  color: var(--accent);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

/* app.js places the menu within the visible viewport; the trigger can sit anywhere, including a phone's lower toolbar. */
.action-menu {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-menu);
  min-width: 220px;
  max-height: min(480px, calc(100dvh - 96px));
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--menu-bg);
  box-shadow: 0 4px 8px rgb(0 0 0 / 0.48);
  padding: 6px;
  display: grid;
  gap: 4px;
}

.action-menu[hidden] {
  display: none;
}

.action-menu-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 34px;
  padding: 8px 12px;
  text-align: left;
  text-decoration: none;
  color: var(--ink);
  background: var(--panel-2);
  cursor: pointer;
}

.action-menu-item:hover:not([disabled]) {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.action-menu-item[hidden] {
  display: none;
}

.action-menu-item[disabled] {
  opacity: 0.55;
  cursor: progress;
}

.action-menu-item.is-processing {
  position: relative;
  border-color: rgb(var(--warning-rgb) / 0.64);
  color: var(--warning);
  transition: border-color 240ms var(--ease-out), color 240ms var(--ease-out);
}

.action-menu-item.is-processing::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgb(var(--warning-rgb) / 0.12);
  border-top-color: var(--warning);
  border-radius: 999px;
  pointer-events: none;
  animation: burn-caption-soft 1.6s ease-in-out infinite;
}

#closedCaptionBtn.is-processing::before {
  border: 1px solid rgb(var(--warning-rgb) / 0.08);
  animation: burn-caption-soft-gentle 2s ease-in-out infinite;
}

/* 更多動作選單：依用途分組（來源、字幕、AI 產出、整理、匯出與分享、說明、刪除），每組有小標題、
   組與組之間一條分隔線，每個項目前面有圖示。整組項目都隱藏時，app.js 會連小標題一起藏起來。
   標籤選單與朗讀速度選單也用 .action-menu-item，這裡的扁平列樣式只限 .action-menu-grouped。 */
.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.action-menu-grouped {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 240px;
  padding: 4px 6px;
}

.action-menu-group {
  display: grid;
  gap: 1px;
  padding: 6px 0;
}

.action-menu-group:not(.hidden) ~ .action-menu-group:not(.hidden) {
  border-top: 1px solid var(--border);
}

.action-menu-heading {
  margin: 0;
  padding: 2px 10px 4px;
  color: var(--quiet);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  user-select: none;
}

.action-menu-grouped .action-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  padding: 7px 10px;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  white-space: nowrap;
}

.action-menu-grouped .action-menu-item:hover:not([disabled]) {
  border-color: transparent;
  background: var(--panel-3);
}

.action-menu-icon,
.action-menu-chevron {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action-menu-icon {
  color: var(--muted);
}

.action-menu-grouped .action-menu-item:hover:not([disabled]) .action-menu-icon,
.action-menu-grouped .action-menu-item:focus-visible .action-menu-icon {
  color: currentColor;
}

.action-menu-label {
  flex: 1 1 auto;
  min-width: 0;
}

.action-menu-chevron {
  width: 16px;
  height: 16px;
  color: var(--quiet);
  transition: transform 160ms var(--ease-out);
}

.action-menu-disclosure[aria-expanded="true"] .action-menu-chevron {
  transform: rotate(180deg);
}

.action-menu-shortcut {
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--quiet);
  font: inherit;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

/* 下載的子項目往右縮排，左側一條導引線表示屬於「下載」。 */
.action-menu-submenu {
  display: grid;
  gap: 1px;
  margin: 1px 0 2px 18px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.action-menu-submenu[hidden] {
  display: none;
}

.action-menu-grouped .action-menu-item.is-processing {
  border-color: rgb(var(--warning-rgb) / 0.64);
  color: var(--warning);
}

.action-menu-grouped .action-menu-item.is-processing .action-menu-icon {
  color: currentColor;
}

.action-menu-grouped .action-menu-item.is-danger,
.action-menu-grouped .action-menu-item.is-danger .action-menu-icon {
  color: var(--danger);
}

.action-menu-grouped .action-menu-item.is-danger:hover:not([disabled]) {
  background: rgb(var(--danger-rgb) / 0.12);
}

/* 標籤選單沿用 .action-menu／.action-menu-item 的外觀，只補標題與左右分欄。 */
.tag-menu {
  min-width: 240px;
}

.tag-menu-heading {
  margin: 0;
  padding: 6px 10px 2px;
  color: var(--quiet);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tag-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tag-menu-item .tag-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   對話框共用版面（深淺主題共用變數）
   - 外框：.confirm-dialog／.reading-dialog／.lexicon-dialog／.cloud-dialog（cloud.css）都用
     --dialog-radius、--dialog-shadow、--dialog-backdrop，內容底用 --surface-bg 疊 --panel。
   - 標題列 .dialog-header 只有一列：左邊 .dialog-heading（h2 17px，可選的 .dialog-subtitle 12px 放在標題下方，
     不再放在標題上方當眉標），右邊 .dialog-header-actions（最後一顆是圓形的 .dialog-close）。
     面板型對話框（設定、快速鍵、閱讀、處理工作、詞彙、帳本）加 is-divided 畫分隔線並提供關閉鍵；
     確認型對話框沒有關閉鍵，只用底部的 .confirm-actions。
   - 頁籤：.settings-tabs 與 .cloud-input-tabs 共用底線式樣式；閱讀視窗的 .reading-tabs 是內容篩選，維持膠囊。
   - 穩定性：對話框一律 margin: var(--dialog-offset) auto auto 靠上錨定（不垂直置中），高度上限留同樣的下緣；
     設定視窗更進一步固定高度、內容區自己捲動，切換頁籤或顯示更多欄位都不改變外框大小。
   --------------------------------------------------------------------------- */
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.dialog-header.is-divided {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.dialog-heading {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.dialog-heading h2 {
  margin: 0;
  color: var(--ink);
  font-size: 17px;
  font-weight: 750;
  line-height: 1.3;
}

.dialog-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.dialog-header-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reading-dialog {
  width: min(880px, calc(100vw - 32px));
  margin: var(--dialog-offset) auto auto;
  max-height: min(760px, calc(100dvh - 2 * var(--dialog-offset)));
  border: 1px solid var(--border-strong);
  border-radius: var(--dialog-radius);
  background: transparent;
  color: var(--ink);
  padding: 0;
  box-shadow: var(--dialog-shadow);
}

.reading-dialog::backdrop {
  background: var(--dialog-backdrop);
  backdrop-filter: blur(6px);
}

.confirm-dialog {
  width: min(460px, calc(100vw - 32px));
  margin: var(--dialog-offset) auto auto;
  max-height: calc(100dvh - 2 * var(--dialog-offset));
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border-strong);
  border-radius: var(--dialog-radius);
  background: transparent;
  color: var(--ink);
  padding: 0;
  box-shadow: var(--dialog-shadow);
}

.confirm-dialog::backdrop {
  background: var(--dialog-backdrop);
  backdrop-filter: blur(6px);
}

.subtitle-correction-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  margin: 0;
  transform: translate(-50%, -50%);
}

.subtitle-correction-dialog::backdrop {
  background: rgb(0 0 0 / 0.42);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.ass-style-dialog {
  width: min(860px, calc(100vw - 32px));
  overflow-x: hidden;
}

/* 調整參數時要看得到影片上的字幕即時變化：背景不模糊也不壓暗，否則預覽的顏色會失真。 */
.ass-style-dialog::backdrop {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.ass-style-preview-note {
  font-size: 13px;
}

/* 影片標籤編輯對話框：比一般 confirm-dialog 寬，方便一次看到多個標籤。 */
.video-tags-dialog {
  width: min(560px, calc(100vw - 32px));
}

.tag-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: min(38vh, 260px);
  overflow: auto;
  padding: 2px 0;
}

/* 對話框裡的晶片本身不是控制項（JS 用 span 包一個 ✕ 按鈕），滑鼠游標不該顯示可點擊。 */
.tag-chip-list .tag-chip:not(button) {
  cursor: default;
}

.tag-chip-empty {
  margin: 4px 0 0;
}

/* 「最近使用」：點一下就加到這個資料夾；虛線框與「＋」和上方已套用的標籤區隔。 */
.tag-recent {
  display: grid;
  gap: 6px;
}

.tag-recent[hidden] {
  display: none;
}

.tag-recent-label {
  color: var(--quiet);
  font-size: 12px;
}

.tag-recent-list {
  max-height: none;
}

.tag-recent-chip {
  border: 1px dashed var(--border-strong);
  background: transparent;
  font: inherit;
  font-size: 12px;
}

.tag-recent-chip::before {
  content: "＋";
  margin-right: -2px;
}

/* .confirm-message 在本檔後段把 margin 歸零，需用 id 選擇器補回上方間距。 */
#videoTagsEmpty {
  margin-top: 4px;
}

#videoTagsError {
  color: var(--danger);
}

.shortcuts-dialog {
  width: min(760px, calc(100vw - 32px));
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 18px 28px;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding-right: 4px;
}

.shortcuts-group-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  line-height: 1.4;
}

.shortcut-desc {
  color: var(--muted);
}

.shortcut-keys {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.shortcut-keys kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel-3);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.4), inset 0 1px 0 var(--highlight);
}

/* 設定對話框：外觀與朗讀語音兩個區塊；選項列是分段式單選按鈕，欄位沿用主題變數，深淺主題共用。 */
/* 設定視窗固定高度：切換頁籤或語音來源出現更多欄位時外框不變，內容區自己捲動。 */
.settings-dialog {
  width: min(560px, calc(100vw - 32px));
  height: min(600px, calc(100dvh - 2 * var(--dialog-offset)));
  overflow: hidden;
}

.settings-shell {
  height: 100%;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 0;
}

/* 標題列不畫分隔線，由緊接的頁籤列底線分隔；底線式頁籤也給新增影片對話框的來源頁籤用。 */
.settings-tabs,
.cloud-input-tabs {
  display: flex;
  gap: 4px;
  margin: 12px 0 18px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.cloud-input-tabs {
  margin: 0;
}

.settings-tab,
.cloud-input-tabs button {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  margin-bottom: -1px;
  padding: 8px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

/* 頁籤列為了橫向捲動設了 overflow-x: auto，畫在頁籤外側的焦點框會被裁掉，只剩一側（第一個頁籤只看得到右框線）；
   改畫在頁籤內側。 */
.settings-tab:focus-visible,
.cloud-input-tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.settings-tab:hover,
.cloud-input-tabs button:hover {
  color: var(--ink);
  background: var(--hover-wash);
}

.settings-tab[aria-selected="true"],
.cloud-input-tabs button[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.settings-tab svg {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 每頁高度不同；給一個最低高度，切換頁籤時對話框不會跳動太多。 */
.settings-body {
  display: grid;
  align-content: start;
  min-height: 0;
  overflow-y: auto;
  /* 捲動容器會裁掉超出邊緣的焦點外框（2px 外框＋2px 間距）：左右各往外延伸 6px，再用同樣的內距補回，
     欄位位置不變，焦點框完整可見。 */
  margin: 0 -6px;
  padding: 2px 6px 6px;
}

.settings-section {
  display: grid;
  align-content: start;
  gap: 18px;
}

/* 朗讀語音的欄位群：欄位之間留足夠呼吸空間，欄位內的標籤、輸入列與提示再用較小的間距。 */
.settings-voice-body {
  display: grid;
  gap: 20px;
}

.settings-section[hidden] {
  display: none;
}

.settings-section-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.settings-choice-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  outline: none;
}

.settings-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.settings-choice:hover:not([disabled]) {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.settings-choice[aria-checked="true"] {
  border-color: rgb(var(--accent-rgb) / 0.55);
  background:
    linear-gradient(180deg, rgb(var(--accent-rgb) / 0.18), rgb(var(--accent-rgb) / 0.06)),
    var(--panel-2);
  color: var(--accent);
}

.settings-choice[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 語音來源的標籤較長：手機寬度改為一列一項，不讓文字折行。 */
/* 語音來源三顆固定排同一列（手機也是），所以按鈕用短名。 */
.settings-engine-group {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-choice-icon {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-field {
  display: grid;
  gap: 8px;
}

.settings-field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.settings-field-link {
  color: var(--accent);
  text-decoration: none;
}

.settings-field-link:hover {
  text-decoration: underline;
}

.settings-field-help {
  margin: 0;
  color: var(--quiet);
  font-size: 12px;
  line-height: 1.45;
}

/* 標籤右側的狀態打勾（已提供金鑰）：只用 emoji，不另佔一列，深淺主題都不用改色。 */
.settings-field-badge {
  margin-left: 6px;
  font-size: 13px;
  line-height: 1;
  vertical-align: -1px;
}

.settings-field-separator {
  margin: 0 2px;
  color: var(--quiet);
  font-weight: 400;
}

.settings-field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

/* display: grid 會蓋掉瀏覽器對 [hidden] 的 display: none：自訂 Voice ID 輸入列收起時要真的消失。 */
.settings-field-row[hidden] {
  display: none;
}

.settings-input,
.settings-select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field-bg);
  color: var(--ink);
  font-size: 13px;
}

.settings-input {
  font-family: var(--font-mono, monospace);
}

.settings-select {
  cursor: pointer;
}

.settings-save {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-3);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.settings-save:hover {
  border-color: var(--border-strong);
}

.settings-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.settings-hint.is-warning {
  color: var(--gold);
}

/* 設定 › Google Drive：綁定的帳號以主文字顯示；「解除綁定」用描邊的危險色，不搶過對話框主要動作。 */
.settings-drive-account {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.settings-drive-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-drive-unlink {
  border-color: var(--danger);
  background: transparent;
  color: var(--danger);
}

.settings-drive-unlink:hover:not(:disabled) {
  background: var(--danger);
  color: var(--danger-ink);
}

.settings-drive-unlink:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* 自訂語音的資訊列：名稱與標籤用主色、錯誤用金色，旁邊一顆小的試聽鍵。 */
.settings-voice-info.is-configured {
  color: var(--accent);
}

.settings-voice-info.is-warning {
  color: var(--gold);
}

.settings-inline-button {
  margin-left: 8px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
  cursor: pointer;
}

.settings-inline-button:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.local-settings-button {
  min-width: 0;
}

.confirm-shell {
  display: grid;
  gap: 16px;
  padding: 20px 22px;
  background:
    var(--surface-bg),
    var(--panel);
}

.confirm-message {
  margin: 0;
}

.confirm-message {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

/* 影片正在處理或帳號已有處理工作時，對話框頂端說明為什麼現在不能送出。 */
.confirm-message.busy-notice {
  padding: 8px 12px;
  border: 1px solid rgb(var(--warning-rgb) / 0.32);
  border-radius: 8px;
  background: rgb(var(--warning-rgb) / 0.1);
  color: var(--warning);
}

/* 新增影片時網址已加入過：標題是開啟該影片的連結。 */
.duplicate-source-notice a,
.duplicate-source-notice strong {
  color: inherit;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.duplicate-source-notice a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.confirm-file {
  display: grid;
  gap: 5px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--well-bg);
  padding: 12px;
}

.confirm-file span,
.confirm-file small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.confirm-file strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.add-video-status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--well-bg);
}

.add-video-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.add-video-spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: add-video-spin 0.8s linear infinite;
}

.add-video-status-text {
  flex: 1;
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-video-timer {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid rgb(var(--accent-rgb) / 0.28);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.add-video-detail {
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--well-bg);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes add-video-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .add-video-spinner {
    animation: none;
  }
}

.subtitle-correction-shell {
  min-width: min(460px, calc(100vw - 32px));
}

.subtitle-merge-actions {
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.subtitle-merge-actions .confirm-button {
  min-width: 0;
  padding: 0 10px;
}

/* 只有群組區捲動，標題、套用選項與按鈕維持可見。 */
.ass-style-shell {
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  /* 以對話框內容寬度為上限：對話框的 calc(100vw - 32px) 已含 1px 邊框，
     這裡若用同一算式，窄螢幕上表單會比內容區寬，聚焦輸入框時整個對話框可左右位移。 */
  min-width: min(680px, 100%);
  max-height: min(820px, calc(100dvh - 2 * var(--dialog-offset) - 2px));
}

/* 欄寬固定為清單寬度：預設的 auto 欄會以收合摘要的完整文字寬度為下限，
   窄螢幕上欄位比清單寬，整個清單就能左右滑動。只保留垂直捲動。 */
.ass-style-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.ass-style-group {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--well-bg-soft);
}

.ass-style-group[open] {
  background: var(--well-bg);
}

.ass-style-group.is-modified {
  border-color: var(--border-strong);
}

.ass-style-group-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.ass-style-group-summary::-webkit-details-marker {
  display: none;
}

.ass-style-group-summary::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  margin: 0 2px 0 1px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
}

.ass-style-group[open] > .ass-style-group-summary::before {
  transform: translateY(-2px) rotate(45deg);
}

.ass-style-group-summary:hover {
  background: var(--hover-wash);
}

.ass-style-group-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.ass-style-group-title {
  flex: none;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

/* 收合時顯示目前值，展開後欄位已可見，不重複顯示。 */
.ass-style-group-preview {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--quiet);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ass-style-group[open] .ass-style-group-preview {
  visibility: hidden;
}

.ass-style-preview-text + .ass-style-preview-text::before {
  content: "·";
  margin: 0 6px;
  color: var(--quiet);
}

.ass-style-group-preview .ass-style-swatch {
  margin-right: 5px;
  vertical-align: -2px;
}

.ass-style-group-badge {
  flex: none;
  margin-left: auto;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
}

.ass-style-group-hint {
  margin: 0 12px 8px;
  color: var(--quiet);
  font-size: 12px;
  line-height: 1.5;
}

.ass-style-group-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
  gap: 8px 10px;
  padding: 0 12px 12px;
}

.ass-style-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ass-style-field[data-ass-style-key="Fontname"] {
  grid-column: span 2;
}

.ass-style-field-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ass-style-field.is-modified .ass-style-field-label {
  color: var(--accent);
}

.ass-style-field select,
.ass-style-field input {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field-bg);
  color: var(--ink);
  padding: 0 8px;
  font-size: 12px;
}

.ass-style-field input:focus,
.ass-style-field select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / 0.14);
}

.ass-style-field input[readonly] {
  color: var(--muted);
}

.ass-style-colour-input {
  position: relative;
  display: block;
}

.ass-style-colour-input .ass-style-swatch {
  position: absolute;
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
  pointer-events: none;
}

.ass-style-field .ass-style-colour-input input {
  padding-left: 28px;
}

.ass-style-field.is-colour {
  grid-column: span 2;
}

.ass-style-colour-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ass-style-field .ass-style-colour-controls input[type="color"] {
  flex: none;
  width: 32px;
  min-height: 24px;
  height: 24px;
  padding: 2px;
  cursor: pointer;
}

.ass-style-field .ass-style-colour-controls input[type="range"] {
  flex: 1;
  min-width: 0;
  min-height: 24px;
  border: 0;
  background: none;
  padding: 0;
  accent-color: var(--accent);
}

.ass-style-field .ass-style-colour-controls input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ass-style-opacity-value {
  flex: none;
  min-width: 4ch;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* 棋盤格底紋讓半透明顏色看得出透明度。 */
.ass-style-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background:
    linear-gradient(var(--swatch, transparent), var(--swatch, transparent)),
    repeating-conic-gradient(#8a9493 0 25%, #d9dfde 0 50%) 0 0 / 6px 6px;
}

.ass-style-swatch.is-invalid {
  border-style: dashed;
  background: transparent;
}

@media (prefers-reduced-motion: no-preference) {
  .ass-style-group-summary::before {
    transition: transform 140ms var(--ease-out);
  }
}

@media (max-width: 980px) {
  .ass-style-dialog {
    width: min(760px, calc(100vw - 32px));
  }

}

@media (max-width: 720px) {
  .ass-style-group-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.subtitle-correction-header,
.ass-style-header {
  cursor: move;
  user-select: none;
  touch-action: none;
}

.correction-field {
  display: grid;
  gap: 6px;
}

.correction-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.correction-field input,
.correction-field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field-bg);
  color: var(--ink);
  padding: 0 11px;
  font-size: 14px;
}

.correction-field input:focus,
.correction-field select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / 0.14);
}

/* 指定多語時的候選語言勾選區；選單非「指定多語」時以 hidden 隱藏。 */
.language-choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 6px 12px;
  margin: 0;
  padding: 10px 12px;
  min-width: 0;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field-bg);
}

.language-choices[hidden] {
  display: none;
}

.language-choices legend {
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.language-choices label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.language-choices input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.language-choices:disabled {
  opacity: 0.6;
}

.correction-option {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

.correction-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.add-video-auto-confirm {
  min-block-size: 48px;
  cursor: pointer;
}

.add-video-auto-confirm:has(input:disabled) {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 轉成橫式的選項包一層只為了在本機版整組隱藏；顯示時不影響表單原本的間距。 */
.add-video-landscape-option:not([hidden]) {
  display: contents;
}

.lexicon-dialog {
  width: min(740px, calc(100vw - 32px));
  margin: var(--dialog-offset) auto auto;
  max-height: calc(100dvh - 2 * var(--dialog-offset));
  padding: 0;
  color: var(--ink);
  background: var(--panel, #111719);
  border: 1px solid var(--border-strong);
  border-radius: var(--dialog-radius);
  box-shadow: var(--dialog-shadow);
}
.lexicon-dialog::backdrop { background: var(--dialog-backdrop); backdrop-filter: blur(6px); }
.lexicon-form { display: flex; flex-direction: column; max-height: calc(100dvh - 2 * var(--dialog-offset) - 2px); }
.lexicon-header { display: flex; align-items: center; gap: 12px; padding: 20px 22px 14px; border-bottom: 1px solid var(--border); }
.lexicon-header h2 { margin: 0 0 4px; font-size: 17px; font-weight: 750; line-height: 1.3; }
.lexicon-scope, .lexicon-help, .lexicon-details { margin: 0; font-size: 13px; line-height: 1.7; color: var(--muted); }
.lexicon-close { flex: 0 0 34px; width: 34px; height: 34px; margin-left: auto; padding: 0; border: 1px solid var(--border); border-radius: 999px; background: var(--panel-2); color: var(--ink); font-size: 22px; line-height: 1; cursor: pointer; }
.lexicon-close:hover { border-color: var(--border-strong); background: var(--panel-3); }
.lexicon-body { min-height: 0; overflow-y: auto; padding: 18px 22px 22px; }
.lexicon-details { margin-top: 8px; }
.lexicon-details summary { width: fit-content; cursor: pointer; color: var(--ink); }
.lexicon-details p { margin: 8px 0 0; }
.lexicon-status, .lexicon-error { font-size: 13px; line-height: 1.6; margin: 14px 0 0; }
.lexicon-status { color: var(--accent); }
.lexicon-error { color: var(--danger, #f06f4f); }
.lexicon-status:empty, .lexicon-error:empty { display: none; }
.lexicon-fields { border: 0; padding: 0; margin: 20px 0 0; min-width: 0; }
.lexicon-rows { display: grid; gap: 16px; }
.lexicon-row { display: grid; grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.lexicon-arrow { color: var(--muted); line-height: 40px; text-align: center; }
.lexicon-remove { min-height: 40px; }
.lexicon-row input[aria-invalid=true] { border-color: var(--danger, #f06f4f); }
.lexicon-empty { padding: 24px 12px; border: 1px dashed var(--border); border-radius: 6px; color: var(--muted); text-align: center; font-size: 14px; line-height: 1.7; }
.lexicon-list-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; }
.lexicon-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.lexicon-footer { padding: 14px 22px; border-top: 1px solid var(--border); }
.lexicon-save-actions { display: flex; justify-content: flex-end; gap: 10px; }
.lexicon-discard { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-bottom: 16px; font-size: 13px; color: var(--muted); }
.lexicon-discard span { margin-right: auto; }
.lexicon-dialog [hidden] { display: none; }
.lexicon-dialog button:disabled { opacity: 0.45; cursor: default; }
.local-lexicon-button { width: 100%; }
@media (max-width: 560px) {
  .lexicon-header { padding: 18px 16px 14px; }
  .lexicon-body { padding: 16px; }
  .lexicon-footer { padding: 14px 16px; }
  .lexicon-row { grid-template-columns: minmax(0, 1fr) auto; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
  .lexicon-row .correction-field { grid-column: 1; }
  .lexicon-row input { font-size: 16px; min-height: 44px; }
  .lexicon-arrow { display: none; }
  .lexicon-remove { grid-column: 2; grid-row: 2; }
  .lexicon-dialog button { min-height: 44px; }
}

.correction-option code {
  border-radius: 4px;
  background: var(--panel-2);
  padding: 1px 5px;
  font-size: 12px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
}

/* 新增影片（尤其是上傳檔案）的選項多，對話框需要捲動時按鈕列固定在底部，內容在上方捲動。
   捲動的是 dialog 本身；負邊距蓋過 confirm-shell 的左右與底部內距，底色不透明才不會透出底下的欄位。 */
#addVideoDialog .confirm-actions {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin: 0 -22px -20px;
  padding: 14px 22px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.confirm-button {
  min-width: 88px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.confirm-button-secondary {
  background: var(--panel-2);
}

.confirm-button-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.confirm-button-danger {
  border-color: transparent;
  background: var(--danger);
  color: var(--danger-ink);
}

.confirm-button-danger:hover {
  border-color: var(--danger-soft);
}

.confirm-button:hover {
  border-color: var(--border-strong);
}

.reading-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  max-height: min(760px, calc(100dvh - 2 * var(--dialog-offset)));
  height: min(760px, calc(100dvh - 2 * var(--dialog-offset)));
  min-height: 0;
  overflow: hidden;
  background:
    var(--surface-bg),
    var(--panel);
}

/* 閱讀視窗沒有 confirm-shell 的內距，標題列自己帶；其餘沿用 .dialog-header 的共用版面。 */
.reading-header {
  padding: 18px 20px 14px;
}

.reading-heading h2,
.reading-heading .dialog-subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}

.dialog-close:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.reading-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}

.reading-tab {
  flex: 0 0 auto;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.reading-tab:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.reading-tab[aria-selected="true"] {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.reading-content {
  min-height: 280px;
  max-height: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background:
    var(--well-shade),
    var(--well-bg);
}

.reading-seek-link {
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.reading-seek-link:hover {
  color: var(--ink);
}

.reading-content.is-transcript {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reading-transcript-segment {
  display: block;
  margin: 0;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: background-color 120ms ease;
}

.reading-transcript-segment:hover {
  background: var(--hover-wash);
}

.reading-transcript-text {
  white-space: pre-wrap;
}

.reading-transcript-seek {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 5px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  text-decoration: none;
  opacity: 0.36;
  cursor: pointer;
  user-select: none;
  vertical-align: baseline;
  transition: opacity 140ms ease, color 140ms ease, background-color 140ms ease;
}

.reading-transcript-segment:hover .reading-transcript-seek {
  opacity: 0.72;
}

.reading-transcript-seek:hover,
.reading-transcript-seek:focus-visible {
  opacity: 1;
  color: var(--accent);
  background: rgb(var(--accent-rgb) / 0.12);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* 朗讀高亮：::highlight 疊出「目前句」與「起點」兩層；不支援時由 .reading-speech-* 類別補上同樣的底色。 */
::highlight(reading-speech) {
  color: var(--ink);
  background-color: rgb(var(--accent-rgb) / 0.28);
  text-decoration-line: underline;
  text-decoration-color: rgb(var(--accent-rgb) / 0.72);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

::highlight(reading-speech-anchor) {
  background-color: rgb(var(--accent-rgb) / 0.12);
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgb(var(--accent-rgb) / 0.65);
  text-underline-offset: 3px;
}

.reading-speech-active,
.reading-speech-anchor-active {
  padding: 0.1em 0.2em;
  border-radius: var(--radius-sm);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.reading-speech-anchor-active {
  background-color: rgb(var(--accent-rgb) / 0.1);
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgb(var(--accent-rgb) / 0.6);
  text-underline-offset: 3px;
}

.reading-speech-active {
  background-color: rgb(var(--accent-rgb) / 0.24);
  text-decoration-line: underline;
  text-decoration-color: rgb(var(--accent-rgb) / 0.7);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.reading-content-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
}

.reading-speak-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 0;
  cursor: pointer;
}

.reading-speak-button[hidden] {
  display: none;
}

.reading-speak-button:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--panel-3);
}

.reading-speak-button[aria-pressed="true"] {
  border-color: rgb(var(--accent-rgb) / 0.68);
  background:
    linear-gradient(180deg, rgb(var(--accent-rgb) / 0.22), rgb(var(--accent-rgb) / 0.08)),
    var(--panel-2);
  color: var(--accent);
}

.reading-speak-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.reading-speak-rate-menu {
  min-width: 256px;
  max-width: min(320px, calc(100vw - 24px));
}

.reading-speak-rate-group {
  display: grid;
  gap: 4px;
}

.reading-speak-rate-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
}

.reading-speak-rate-item::before {
  content: "";
  flex: none;
  inline-size: 1rem;
  color: var(--accent);
  font-weight: 800;
}

.reading-speak-rate-item[aria-checked="true"] {
  border-color: rgb(var(--accent-rgb) / 0.55);
  background:
    linear-gradient(180deg, rgb(var(--accent-rgb) / 0.18), rgb(var(--accent-rgb) / 0.06)),
    var(--panel-2);
  color: var(--accent);
}

.reading-speak-rate-item[aria-checked="true"]::before {
  content: "✓";
}

.reading-speak-settings-item {
  display: grid;
  gap: 2px;
  font-size: 13px;
  font-weight: 650;
}

.reading-speak-settings-hint {
  color: var(--quiet);
  font-size: 11px;
  font-weight: 600;
}

.reading-copy-button {
  min-width: 52px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--ink);
  padding: 0 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
}

.reading-copy-button:hover {
  border-color: var(--border-strong);
}

.reading-copy-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.reading-audio-button.is-busy {
  border-color: rgb(var(--accent-rgb) / 0.68);
  color: var(--accent);
}

.reading-audio-link {
  color: var(--accent);
  border-color: rgb(var(--accent-rgb) / 0.5);
  text-decoration: none;
}

.reading-audio-link:hover {
  border-color: rgb(var(--accent-rgb) / 0.85);
}

.reading-save-button {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.reading-save-button:hover:not(:disabled) {
  border-color: transparent;
  filter: brightness(1.08);
}

.reading-copy-button[hidden] {
  display: none;
}

.reading-frame-preview-button[aria-pressed="true"] {
  border-color: rgb(var(--accent-rgb) / 0.68);
  background:
    linear-gradient(180deg, rgb(var(--accent-rgb) / 0.22), rgb(var(--accent-rgb) / 0.08)),
    var(--panel-2);
  color: var(--accent);
}

.reading-frame-preview {
  position: absolute;
  z-index: 5;
  width: min(240px, calc(100% - 16px));
  pointer-events: none;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #15191e;
  color: #fff;
  box-shadow: var(--dialog-shadow);
}

.reading-frame-preview[hidden] {
  display: none;
}

.reading-frame-preview-frame {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  background: #080b0c;
}

.reading-frame-preview-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.reading-frame-preview-loading {
  padding: 12px;
  font-size: .8125rem;
  color: #d6dadd;
}

.reading-frame-preview-time {
  display: block;
  padding: 5px 10px 6px;
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* 編輯時文字框取代閱讀內容；格式錯誤的訊息放在文字框上方，儲存鍵同時停用。 */
.reading-content-wrap.is-editing {
  display: flex;
  flex-direction: column;
}

.reading-content-wrap.is-editing .reading-content {
  display: none;
}

.reading-edit-status {
  flex: none;
  margin: 0;
  padding: 8px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.reading-edit-status.is-error {
  color: var(--danger);
}

.reading-edit-status[hidden],
.reading-editor[hidden] {
  display: none;
}

.reading-editor {
  flex: 1 1 auto;
  width: 100%;
  min-height: 280px;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 18px;
  resize: none;
  color: var(--ink);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 14px;
  line-height: 1.6;
  overflow: auto;
  overflow-wrap: anywhere;
  background:
    var(--well-shade),
    var(--well-bg);
}

.reading-editor:focus-visible {
  outline: 2px solid rgb(var(--accent-rgb) / 0.6);
  outline-offset: -2px;
}

.reading-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.reading-content.markdown-body {
  white-space: normal;
  overflow-wrap: break-word;
}

.reading-content.markdown-body > :first-child {
  margin-top: 0;
}

.reading-content.markdown-body > :last-child {
  margin-bottom: 0;
}

.reading-content.markdown-body h1,
.reading-content.markdown-body h2,
.reading-content.markdown-body h3,
.reading-content.markdown-body h4,
.reading-content.markdown-body h5,
.reading-content.markdown-body h6 {
  margin: 1.25em 0 0.45em;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.28;
}

.reading-content.markdown-body h1 {
  font-size: 1.65rem;
}

.reading-content.markdown-body h2 {
  font-size: 1.38rem;
}

.reading-content.markdown-body h3 {
  font-size: 1.15rem;
}

.reading-content.markdown-body p,
.reading-content.markdown-body ul,
.reading-content.markdown-body ol,
.reading-content.markdown-body blockquote,
.reading-content.markdown-body pre {
  margin: 0 0 1em;
}

.reading-content.markdown-body ul,
.reading-content.markdown-body ol {
  padding-left: 1.45em;
}

.reading-content.markdown-body li > ul,
.reading-content.markdown-body li > ol {
  margin: 0.28em 0 0.4em;
  padding-left: 1.25em;
}

.reading-content.markdown-body li + li {
  margin-top: 0.28em;
}

.reading-content.markdown-body a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.reading-content.markdown-body a:hover {
  color: var(--ink);
}

.reading-content.markdown-body code {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--well-bg-soft);
  color: var(--ink);
  padding: 0.12em 0.35em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.reading-content.markdown-body pre {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--well-bg);
  padding: 13px 14px;
}

.reading-content.markdown-body pre code {
  display: block;
  border: 0;
  background: transparent;
  padding: 0;
  white-space: pre;
}

.reading-content.markdown-body blockquote {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: rgb(var(--accent-rgb) / 0.08);
  color: var(--muted);
  padding: 10px 13px;
}

.reading-content.markdown-body blockquote p {
  margin: 0;
}

.reading-content.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.25em 0;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  contain: layout paint;
  isolation: isolate;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgb(0 0 0 / 0.18), rgb(0 0 0 / 0.52)),
    var(--asset-stage) center / cover no-repeat,
    var(--black);
}

.player-container {
  min-width: 0;
  min-height: 0;
  display: grid;
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.player-container:fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  background: var(--black);
}

.video-player {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  background: var(--black);
  object-fit: contain;
}

.video-player::cue {
  color: white;
  background: rgb(0 0 0 / 0.62);
  font-size: 72%;
  line-height: 1.2;
}

.video-player.is-audio-player {
  background: transparent;
}

.audio-backdrop-frame {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  background: var(--black);
  pointer-events: none;
  overflow: hidden;
}

.audio-backdrop-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
}

.audio-backdrop-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid rgb(255 255 255 / 0.22);
  border-radius: var(--radius-sm);
  background: rgb(8 14 20 / 0.72);
  backdrop-filter: blur(8px);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.36);
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.audio-backdrop-btn:hover:not(:disabled),
.audio-backdrop-btn:focus-visible:not(:disabled) {
  background: rgb(14 24 34 / 0.9);
  border-color: rgb(255 255 255 / 0.42);
}

.audio-backdrop-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.audio-backdrop-btn svg {
  width: 15px;
  height: 15px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.audio-backdrop-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: var(--z-tooltip);
  top: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: min(320px, calc(100vw - 28px));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  box-shadow: 0 4px 8px rgb(0 0 0 / 0.36);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 650;
  white-space: normal;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.audio-backdrop-btn[data-tooltip]:hover::after,
.audio-backdrop-btn[data-tooltip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

.player-container canvas.JASSUB {
  position: absolute !important;
  z-index: 2;
  pointer-events: none;
}

/* JASSUB inserts an unsized canvas and positions it on its first resize; showing it earlier counts as a layout shift. */
.player-container canvas.JASSUB:not(.is-placed) {
  display: none;
}

.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: linear-gradient(180deg, rgb(0 0 0 / 0.08), rgb(0 0 0 / 0.28));
}

.stage-empty::before {
  content: "";
  width: 78px;
  height: 78px;
  justify-self: center;
  margin-bottom: 4px;
  background: var(--asset-logo) center / contain no-repeat;
  filter: drop-shadow(0 16px 22px rgb(0 0 0 / 0.45));
}

.stage-empty h3 {
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
}

.stage-empty p {
  width: min(44ch, 100%);
  max-width: 100%;
  justify-self: center;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.empty-row,
.loading-row {
  color: var(--muted);
  padding: 10px;
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: var(--z-toast);
  max-width: min(520px, calc(100vw - 28px));
  transform: translateX(-50%);
  border-radius: var(--radius-md);
  background: var(--panel-3);
  color: var(--ink);
  padding: 10px 13px;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes burn-caption-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes burn-caption-soft {
  0%,
  100% {
    opacity: 0.42;
    transform: scale(0.99);
  }

  50% {
    opacity: 0.74;
    transform: scale(1.02);
  }
}

@keyframes burn-caption-soft-gentle {
  50% {
    opacity: 0.62;
  }

  0%,
  100% {
    opacity: 0.3;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100dvh;
    height: auto;
    grid-template-columns: 1fr;
    grid-template-areas:
      "library"
      "viewer";
    grid-template-rows: minmax(280px, 38dvh) minmax(520px, 62dvh);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 64px minmax(520px, calc(100dvh - 64px));
  }

  .sidebar-resize-handle {
    display: none;
  }

  .library {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    grid-template-rows: auto auto minmax(0, 1fr) minmax(0, var(--video-section-h));
  }

  .sidebar-collapsed .library-header {
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 12px;
  }

  .viewer-toolbar {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 8px;
    padding: 8px 10px;
  }

  .viewer-actions,
  .subtitle-bar {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .reading-dialog {
    width: calc(100vw - 16px);
    margin: max(8px, env(safe-area-inset-top)) auto max(8px, env(safe-area-inset-bottom));
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  }

  .reading-shell {
    height: calc(100dvh - max(16px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  }

  /* 手機版閱讀視窗：第一列放完整標題與右上角關閉鍵，第二列放動作工具列，避免多顆按鈕把標題擠成單字直排。 */
  .reading-header {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 14px 12px;
  }

  .reading-heading {
    padding-right: 52px;
    min-height: 40px;
    align-content: center;
  }

  .reading-heading h2 {
    font-size: 16px;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .reading-header-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
  }

  .reading-header-actions > .dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
  }

  .reading-header-actions > .reading-copy-button {
    flex: 1 1 auto;
    min-width: 64px;
    padding: 0 12px;
    border-radius: var(--radius-md);
  }

  .reading-tabs {
    padding: 10px 14px;
    gap: 8px;
    scroll-padding-inline: 14px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .reading-tabs::-webkit-scrollbar {
    display: none;
  }

  .reading-tab {
    padding: 0 14px;
  }

  .reading-content,
  .reading-editor {
    min-height: 0;
    padding: 16px 14px max(18px, env(safe-area-inset-bottom));
  }

  .reading-content {
    font-size: 15px;
    line-height: 1.75;
  }

  .reading-content.markdown-body h1 {
    font-size: 1.35rem;
  }

  .reading-content.markdown-body h2 {
    font-size: 1.2rem;
  }

  .reading-content.markdown-body h3 {
    font-size: 1.06rem;
  }
}

@media (max-width: 560px) {
  .app-shell {
    grid-template-rows: minmax(310px, 42dvh) minmax(460px, 58dvh);
  }

  .viewer-toolbar {
    padding: 8px 10px;
  }

  .now-playing h2 {
    font-size: 15px;
  }

  .confirm-actions {
    flex-wrap: wrap;
  }

  .confirm-actions .confirm-button {
    flex: 1 1 120px;
  }
}

@media (max-width: 360px) {
  .app-shell {
    grid-template-rows: minmax(400px, 48dvh) minmax(460px, 52dvh);
  }

  .library-controls {
    grid-template-columns: 1fr;
  }
}

@media (pointer: coarse) {
  .sidebar-toggle,
  .add-video-button,
  .favorite-button,
  .reading-button,
  .reading-speak-button,
  .action-menu-trigger,
  .dialog-close {
    width: 44px;
    height: 44px;
  }

  .library-search-row {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .search-field input,
  .secondary-button,
  .subtitle-format-toggle,
  .action-menu-item,
  .action-menu-grouped .action-menu-item,
  .reading-tab,
  .reading-copy-button,
  .confirm-button,
  .ass-style-group-summary,
  .ass-style-field select,
  .ass-style-field input,
  .correction-field input,
  .correction-field select {
    min-height: 44px;
  }

  .folder-tab,
  .tag-chip,
  .tag-overflow-button,
  .subtitle-chip,
  .subtitle-note,
  #folderSortMode {
    min-height: 44px;
  }

  .subtitle-chip {
    min-width: 44px;
  }

  .folder-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .folder-action,
  .folder-restore-btn,
  .folder-delete-btn {
    width: 44px;
    height: 44px;
  }

  .folder-item,
  .video-item,
  .correction-option {
    min-height: 44px;
  }

  .reading-transcript-segment {
    padding: 6px 8px;
  }

  .reading-transcript-seek {
    opacity: 0.78;
    padding: 3px 8px;
    font-size: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
  }

  .section-heading h2,
  .folder-tab,
  .count,
  .folder-stats,
  .meta-line,
  .subtitle-note,
  .subtitle-format-toggle,
  .reading-tab,
  .ass-style-field-label {
    font-size: 13px;
  }

  /* iOS Safari 聚焦字級小於 16px 的文字輸入控制項時會自動放大頁面，收起鍵盤後也不會縮回，
     對話框因此被推出畫面。觸控裝置的輸入框、下拉選單與多行輸入一律使用 16px；
     :is() 取參數中最高的特異度，才能蓋過 .ass-style-field input 等元件規則。 */
  :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"]), select, textarea) {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .folder-item,
  .video-item,
  .add-video-button,
  .secondary-button,
  .sidebar-toggle,
  .source-link,
  .finder-button,
  .closed-caption-button,
  .favorite-button,
  .reading-button,
  .reading-speak-button,
  .ask-ai-button,
  .dialog-close,
  .reading-tab,
  .subtitle-chip,
  .subtitle-format-toggle,
  .ask-ai-mode-option {
    transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out),
      border-color 160ms var(--ease-out);
  }
}

/* ==========================================================================
   Ask AI Panel Styles
   ========================================================================== */

.viewer-stage-container {
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.viewer-stage-container .stage-column {
  flex: 1 1 0%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  transition: flex 220ms var(--ease-out);
}

.viewer-stage-container .stage {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

/* 桌機版面：播放器是面板上的一張卡片，與工具列、側欄和 Ask AI 之間留白，深淺主題都看得出邊界。
   手機版面維持滿版：高度以 56.25vw／100dvh 計算，landscape-alignment.js 也量測 stage 的位置。
   卡片刻意不設圓角：.stage 有 overflow: hidden，圓角會裁切影片，疊上 ASS 字幕畫布（JASSUB）後，
   部分 Windows Chrome 開啟硬體加速時影片會變黑畫面，只剩聲音與字幕。 */
body:not(.mobile-layout) .viewer-stage-container .stage {
  height: auto;
  margin: 14px 16px 16px;
  border: 1px solid var(--stage-frame-border);
  box-shadow: var(--stage-frame-shadow);
}

.ask-ai-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}

.ask-ai-button:hover:not([disabled]) {
  border-color: var(--border-strong);
  background: var(--panel-3);
  color: var(--accent-bright);
}

.ask-ai-button[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  box-shadow: 0 0 12px rgb(var(--accent-rgb) / 0.28);
}

.ask-ai-panel {
  flex: 0 0 var(--ask-ai-w, 420px);
  width: var(--ask-ai-w, 420px);
  min-width: var(--ask-ai-min-w, 320px);
  max-width: min(85vw, var(--ask-ai-max-w, 960px));
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    var(--surface-bg),
    var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--ask-ai-shadow);
  z-index: 15;
  transition: transform 220ms var(--ease-out), opacity 180ms ease;
}

.ask-ai-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -6px;
  width: 12px;
  z-index: var(--z-resize, 10);
  cursor: col-resize;
  touch-action: none;
  outline: 0;
}

.ask-ai-resize-handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 2px;
  background: transparent;
  transition: background 150ms ease, box-shadow 150ms ease;
}

.ask-ai-resize-handle:hover::before,
.ask-ai-resize-handle:focus-visible::before,
.app-shell.is-resizing-ask-ai .ask-ai-resize-handle::before {
  background: var(--accent);
  box-shadow: 0 0 0 1px rgb(var(--accent-rgb) / 0.18), 0 0 18px rgb(var(--accent-rgb) / 0.28);
}

.ask-ai-panel.hidden {
  display: none !important;
}

.ask-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--translucent-panel);
  flex-shrink: 0;
}

.ask-ai-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.ask-ai-badge {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgb(var(--accent-rgb) / 0.2), rgb(var(--accent-rgb) / 0.05));
  border: 1px solid var(--border-strong);
  font-size: 15px;
  flex-shrink: 0;
}

.ask-ai-title-text h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.2px;
}

.ask-ai-title-text p {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--quiet);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.ask-ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* 標題欄讓出空間給操作鈕列：面板縮到 320px 時標題以省略號縮短，不會溢出到鈕縫裡。 */
.ask-ai-title-text {
  flex: 1 1 auto;
  min-width: 0;
}

.ask-ai-title-text h3 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ask-ai-header-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.ask-ai-header-btn:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
  color: var(--ink);
}

.ask-ai-header-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 對話模式分段控件：問答（唯讀）｜編輯（Agent，可改檔）。選中「編輯」用實心琥珀色，比唯讀更醒目。 */
.ask-ai-mode-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 30px;
  padding: 2px;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  flex-shrink: 0;
}

.ask-ai-mode-option {
  height: 24px;
  min-width: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.ask-ai-mode-option:hover:not([aria-checked="true"]):not(:disabled) {
  background: var(--panel-3);
  color: var(--ink);
}

/* 滑過未選取的「編輯」先預告琥珀色，暗示這是會改檔的模式。 */
.ask-ai-mode-option[data-ask-ai-mode="agent"]:hover:not([aria-checked="true"]):not(:disabled) {
  color: var(--warning);
}

.ask-ai-mode-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* 選中「問答」：中性的凸起底色，不搶過「編輯」。 */
.ask-ai-mode-option[aria-checked="true"] {
  background: var(--panel-3);
  color: var(--ink);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: default;
}

/* 選中「編輯」：實心琥珀色、不加光暈。借用 --accent-ink 當字色：深色主題是深字（約 9.5:1），淺色主題是白字（約 5.3:1）。 */
.ask-ai-mode-option[data-ask-ai-mode="agent"][aria-checked="true"] {
  background: var(--warning);
  color: var(--accent-ink);
  box-shadow: none;
}

.ask-ai-mode-option:disabled {
  color: var(--quiet);
  opacity: 0.56;
  cursor: not-allowed;
}

/* 面板層級的編輯模式提示：控件外框、徽章與輸入框都帶琥珀色，捲到底部打字時仍看得到。 */
.ask-ai-panel.is-agent .ask-ai-mode-group {
  border-color: rgb(var(--warning-rgb) / 0.55);
}

.ask-ai-panel.is-agent .ask-ai-badge {
  background: linear-gradient(135deg, rgb(var(--warning-rgb) / 0.24), rgb(var(--warning-rgb) / 0.06));
  border-color: rgb(var(--warning-rgb) / 0.55);
}

.ask-ai-panel.is-agent .ask-ai-input {
  border-color: rgb(var(--warning-rgb) / 0.5);
}

.ask-ai-panel.is-agent .ask-ai-input:focus-visible {
  border-color: var(--warning);
  box-shadow: 0 0 0 1px var(--warning), inset 0 1px 0 var(--highlight);
}

/* Agent 模式的工具步驟清單（edit_file / web_search），置於回答氣泡最上方。 */
.ask-ai-tool-log {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
  padding: 6px 8px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--panel-2);
}

.ask-ai-tool-item {
  font-size: 11px;
  line-height: 1.5;
  color: var(--quiet);
  overflow-wrap: anywhere;
}

.ask-ai-tool-item.is-ok {
  color: var(--success);
}

.ask-ai-tool-item.is-error {
  color: var(--danger);
}

.ask-ai-search-toggle.is-tool-locked {
  cursor: default;
  opacity: 0.85;
  box-shadow: none;
}

.ask-ai-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.ask-ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 12px 16px;
  color: var(--muted);
  gap: 10px;
}

.ask-ai-welcome-icon {
  font-size: 32px;
  filter: drop-shadow(0 4px 12px rgb(var(--accent-rgb) / 0.3));
}

.ask-ai-welcome h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.ask-ai-welcome p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  max-width: 320px;
  color: var(--muted);
}

.ask-ai-quick-chips {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  margin-top: 8px;
}

.ask-ai-chip {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: var(--ink);
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
  line-height: 1.35;
}

.ask-ai-chip:hover {
  border-color: var(--border-strong);
  background: var(--panel-3);
  transform: translateX(2px);
  color: var(--accent);
}

.ask-ai-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 92%;
  word-break: break-word;
  line-height: 1.5;
}

.ask-ai-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.ask-ai-msg-assistant {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 98%;
}

.ask-ai-msg-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--quiet);
  width: 100%;
}

.ask-ai-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  transition: all 140ms var(--ease-out);
  margin-left: auto;
}

.ask-ai-copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.ask-ai-copy-btn.copied {
  border-color: var(--success);
  color: var(--success);
  background: rgb(var(--success-rgb) / 0.14);
}

.ask-ai-copy-btn .copy-icon,
.ask-ai-copy-btn .check-icon {
  display: block;
  flex-shrink: 0;
}

.ask-ai-msg-user .ask-ai-msg-bubble {
  background: linear-gradient(135deg, rgb(var(--accent-rgb) / 0.18), var(--bubble-user-deep));
  border: 1px solid rgb(var(--accent-rgb) / 0.35);
  border-radius: 14px 14px 2px 14px;
  color: var(--ink);
  padding: 10px 14px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
}

/* 多行提問（例如範本插入的長提示詞）保留換行與縮排，長句自動斷行。 */
.ask-ai-msg-user .ask-ai-msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 2px;
  color: var(--ink);
  padding: 12px 14px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
  width: 100%;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble h1,
.ask-ai-msg-assistant .ask-ai-msg-bubble h2,
.ask-ai-msg-assistant .ask-ai-msg-bubble h3,
.ask-ai-msg-assistant .ask-ai-msg-bubble h4 {
  margin: 12px 0 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble h1:first-child,
.ask-ai-msg-assistant .ask-ai-msg-bubble h2:first-child,
.ask-ai-msg-assistant .ask-ai-msg-bubble h3:first-child {
  margin-top: 0;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble p {
  margin: 6px 0;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble p:first-child {
  margin-top: 0;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble p:last-child {
  margin-bottom: 0;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble ul,
.ask-ai-msg-assistant .ask-ai-msg-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble li {
  margin: 3px 0;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble li > ul,
.ask-ai-msg-assistant .ask-ai-msg-bubble li > ol {
  margin: 3px 0 4px;
  padding-left: 18px;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble pre {
  margin: 8px 0;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--well-bg-strong);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: rgb(var(--accent-rgb) / 0.1);
  color: var(--accent);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 12px;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble blockquote {
  margin: 8px 0;
  padding: 4px 10px;
  border-left: 3px solid var(--accent);
  background: rgb(var(--accent-rgb) / 0.05);
  color: var(--muted);
}

.markdown-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 10px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.ask-ai-msg-assistant .ask-ai-msg-bubble .markdown-table-wrap,
.reading-content.markdown-body .markdown-table-wrap {
  margin: 10px 0;
}

.markdown-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.45;
}

.markdown-table-wrap th,
.markdown-table-wrap td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  vertical-align: top;
}

.markdown-table-wrap th {
  background: rgb(var(--accent-rgb) / 0.08);
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.markdown-table-wrap tr:nth-child(even) td {
  background: var(--hover-wash);
}

.markdown-table-wrap tr:hover td {
  background: rgb(var(--accent-rgb) / 0.04);
}

.ask-ai-seek-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: rgb(var(--accent-rgb) / 0.12);
  color: var(--accent);
  padding: 1px 7px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  transition: all 120ms var(--ease-out);
}

.ask-ai-seek-link:hover {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 8px rgb(var(--accent-rgb) / 0.4);
}

.ask-ai-msg-img {
  max-width: 240px;
  max-height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 140ms var(--ease-out);
}

.ask-ai-msg-img:hover {
  transform: scale(1.03);
  border-color: var(--accent);
}

.ask-ai-typing-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--accent);
  margin-left: 3px;
  vertical-align: middle;
  animation: typing-blink 0.8s infinite;
}

@keyframes typing-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.ask-ai-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  background: var(--translucent-panel-strong);
  flex-shrink: 0;
}

.ask-ai-context-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 28px;
}

.ask-ai-time-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 3px 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
}

.ask-ai-time-badge:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: var(--panel-3);
}

.ask-ai-snapshot-wrapper {
  display: inline-flex;
  align-items: center;
  position: relative;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  height: 26px;
}

.ask-ai-snapshot-wrapper.hidden,
.ask-ai-snapshot-wrapper[hidden] {
  display: none !important;
}

.ask-ai-snapshot-thumb {
  width: 44px;
  height: 26px;
  object-fit: cover;
  display: block;
}

.ask-ai-remove-snapshot {
  position: absolute;
  top: 0;
  right: 0;
  width: 16px;
  height: 16px;
  background: rgb(0 0 0 / 0.75);
  color: #fff;
  border: 0;
  font-size: 11px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.ask-ai-remove-snapshot:hover {
  background: var(--danger);
  color: #fff;
}

.ask-ai-snapshot-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
  color-scheme: light dark;
  transition: all 140ms var(--ease-out);
}

.ask-ai-snapshot-toggle:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: var(--panel-3);
}

.ask-ai-snapshot-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  margin: 0;
  cursor: pointer;
}

@supports not (accent-color: var(--accent)) {
  .ask-ai-snapshot-toggle input[type="checkbox"].visually-hidden {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  .ask-ai-snapshot-toggle {
    position: relative;
    padding-left: 22px;
  }

  .ask-ai-snapshot-toggle input[type="checkbox"] + span::before {
    content: "";
    position: absolute;
    left: 7px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--border-strong);
    background: var(--panel);
    border-radius: 3px;
    box-sizing: border-box;
  }

  .ask-ai-snapshot-toggle input[type="checkbox"]:focus-visible + span::before {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .ask-ai-snapshot-toggle input[type="checkbox"]:checked + span::before {
    background-color: var(--accent);
    border-color: var(--accent);
  }

  .ask-ai-snapshot-toggle input[type="checkbox"]:checked + span::after {
    content: "✓";
    position: absolute;
    left: 8.5px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent-ink);
    font-weight: 700;
    font-size: 10px;
  }
}

.ask-ai-refresh-snapshot.hidden,
.ask-ai-refresh-snapshot[hidden] {
  display: none !important;
}

.ask-ai-refresh-snapshot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--quiet);
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
}

.ask-ai-refresh-snapshot:hover {
  border-color: var(--border-strong);
  color: var(--accent);
  background: var(--panel-2);
}

.ask-ai-search-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  margin-left: auto;
  transition: all 140ms var(--ease-out);
}

.ask-ai-search-toggle:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: var(--panel-3);
}

.ask-ai-search-toggle[aria-pressed="true"] {
  border-color: rgb(var(--info-rgb) / 0.8);
  background: linear-gradient(135deg, rgb(var(--info-rgb) / 0.22), rgb(var(--info-rgb) / 0.1));
  color: var(--info);
  box-shadow: 0 0 10px rgb(var(--info-rgb) / 0.28);
}

.ask-ai-subtitle-status {
  color: var(--quiet);
  font-size: 10px;
  white-space: nowrap;
}

.ask-ai-template-wrap {
  position: relative;
  display: inline-flex;
}

.ask-ai-template-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: min(300px, 80vw);
  max-height: min(60vh, 460px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-bg), var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.75), 0 0 16px rgb(var(--accent-rgb) / 0.12);
  padding: 10px 12px;
  z-index: 30;
}

.ask-ai-template-menu[hidden] {
  display: none !important;
}

.ask-ai-template-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--ink);
  padding: 8px 10px;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
}

.ask-ai-template-item:hover {
  border-color: var(--accent);
  background: var(--panel-3);
}

.ask-ai-template-item strong {
  font-size: 12px;
  font-weight: 700;
}

.ask-ai-template-item span {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

.popover-subtitle {
  font-size: 10px;
  font-weight: 700;
  color: var(--quiet);
  margin-top: 2px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  letter-spacing: 0.04em;
}

.ask-ai-template-empty {
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
  padding: 2px 2px 4px;
}

.ask-ai-template-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.ask-ai-template-row .ask-ai-template-item {
  flex: 1;
  min-width: 0;
}

.ask-ai-template-row .ask-ai-template-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ask-ai-template-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ask-ai-template-icon-btn {
  flex: 1;
  min-width: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
}

.ask-ai-template-icon-btn:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.ask-ai-template-icon-btn.is-armed,
.ask-ai-template-delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.ask-ai-template-add {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
}

.ask-ai-template-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.ask-ai-template-name,
.ask-ai-template-prompt {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
}

.ask-ai-template-prompt {
  min-height: 140px;
  resize: vertical;
  line-height: 1.5;
}

.ask-ai-template-editor-actions {
  display: flex;
  gap: 6px;
}

.ask-ai-template-save,
.ask-ai-template-cancel {
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 140ms var(--ease-out);
}

.ask-ai-template-save {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.ask-ai-template-save:hover {
  filter: brightness(1.08);
}

.ask-ai-template-cancel {
  background: var(--panel-2);
  color: var(--muted);
}

.ask-ai-template-cancel:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.ask-ai-grounding-card {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgb(var(--accent-rgb) / 0.05);
  border: 1px solid rgb(var(--accent-rgb) / 0.2);
  font-size: 11px;
}

.ask-ai-grounding-header {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 5px;
}

.ask-ai-grounding-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.ask-ai-grounding-item a {
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  word-break: break-all;
  transition: color 120ms ease;
}

.ask-ai-grounding-item a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.ask-ai-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: flex-end;
  position: relative;
}

/* @ 檔名提及選單：輸入 @ 從影片資料夾挑選檔案（排除影音檔）插入提示詞。 */
.ask-ai-mention-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: min(360px, 92%);
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface-bg), var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.75), 0 0 16px rgb(var(--accent-rgb) / 0.12);
  padding: 6px;
  z-index: 30;
}

.ask-ai-mention-menu[hidden] {
  display: none !important;
}

.ask-ai-mention-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.ask-ai-mention-item:hover,
.ask-ai-mention-item.is-active {
  border-color: var(--accent);
  background: var(--panel-3);
}

.ask-ai-mention-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ask-ai-mention-match {
  color: var(--accent);
  font-weight: 600;
}

.ask-ai-mention-ext {
  flex: none;
  color: var(--quiet);
  font-size: 10px;
}

.ask-ai-mention-hint {
  color: var(--quiet);
  font-size: 11px;
  padding: 6px 8px;
}

.ask-ai-input {
  width: 100%;
  min-height: 38px;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--field-bg);
  color: var(--ink);
  padding: 8px 12px;
  outline: 0;
  resize: none;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: inset 0 1px 0 var(--highlight);
}

.ask-ai-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), inset 0 1px 0 var(--highlight);
}

.ask-ai-input::placeholder {
  color: var(--quiet);
}

.ask-ai-send-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: linear-gradient(135deg, rgb(var(--accent-rgb) / 0.25), rgb(var(--accent-rgb) / 0.12));
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  transition: all 140ms var(--ease-out);
}

.ask-ai-send-button:hover:not(:disabled) {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 12px rgb(var(--accent-rgb) / 0.35);
}

.ask-ai-send-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ask-ai-send-button.is-generating {
  border-color: var(--danger);
  background: rgb(var(--danger-rgb) / 0.2);
  color: var(--danger);
}

.ask-ai-send-button.is-generating:hover {
  background: var(--danger);
  color: #fff;
}

.ask-ai-footer-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--quiet);
  padding: 0 2px;
}

.ask-ai-token-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  outline: none;
  cursor: default;
}

.ask-ai-cache-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-size: 10px;
  border-bottom: 1px dotted rgb(var(--accent-rgb) / 0.4);
  padding-bottom: 1px;
}

.ask-ai-cache-status.has-cache {
  color: var(--success);
  border-bottom-color: rgb(var(--success-rgb) / 0.4);
}

.ask-ai-token-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 250px;
  background: var(--surface-bg), var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.75), 0 0 16px rgb(var(--accent-rgb) / 0.12);
  padding: 10px 12px;
  z-index: 25;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.ask-ai-token-wrap:hover .ask-ai-token-popover,
.ask-ai-token-wrap:focus-within .ask-ai-token-popover {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.popover-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.popover-grid {
  display: grid;
  gap: 5px;
  font-size: 11px;
}

.popover-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--ink);
}

.popover-subrow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  padding-left: 10px;
  font-size: 10.5px;
}

.row-val {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
}

.cached-val {
  color: var(--success);
}

.popover-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.popover-total {
  font-weight: 700;
  color: var(--accent);
}

@media (max-width: 860px) {
  .ask-ai-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(440px, 100%);
    box-shadow: -12px 0 36px rgb(0 0 0 / 0.7);
  }
}

/* A phone starts with the player. Library/account controls live in a modal drawer. */
.mobile-navigation {display:none}
.mobile-library-shortcut {display:none}
.video-player.native-subtitles ~ canvas.JASSUB {visibility:hidden}
.mobile-library-dialog {padding:0;border:0;color:var(--ink);background:var(--panel)}
.mobile-library-dialog::backdrop {background:rgb(0 0 0 / 0.65)}
@media (max-width:980px) {
  .mobile-layout {overflow:auto;padding:0 0 env(safe-area-inset-bottom)}
  .mobile-layout.mobile-library-open {overflow:hidden}
  .mobile-layout .app-shell,.mobile-layout .app-shell.sidebar-collapsed {display:block;min-height:100dvh;height:auto}
  /* First paint already matches what mobile-layout.js builds (library in the drawer, toolbar below the film), so its DOM moves never shift the page. */
  .mobile-layout .app-shell > .library {display:none}
  /* 標籤列是桌機版面功能；手機改由抽屜內的影片列標籤按鈕操作。 */
  .mobile-layout .tag-bar {display:none}
  .mobile-navigation {display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:56px;padding:4px max(8px,env(safe-area-inset-right)) 4px max(8px,env(safe-area-inset-left));background:var(--panel);border-bottom:1px solid var(--border)}
  .mobile-navigation span {min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;font-weight:700}
  .mobile-navigation button {flex:none;min-height:44px;padding:8px 12px;color:var(--ink);background:var(--panel-2);border-radius:var(--radius-sm);cursor:pointer}
  .mobile-navigation button.is-processing {color:var(--accent);border-color:rgb(var(--accent-rgb) / 0.42)}
  .mobile-navigation :focus-visible {outline:2px solid var(--accent);outline-offset:2px}
  .mobile-layout .viewer {display:flex;flex-direction:column;min-height:0}
  .mobile-layout .viewer-stage-container {flex:none;width:100%;height:min(56.25vw,calc(100dvh - 56px));min-height:0}
  .mobile-layout .viewer-toolbar {order:1;flex:none;display:flex;flex-direction:column;align-items:stretch;gap:12px;padding:12px max(12px,env(safe-area-inset-right)) 16px max(12px,env(safe-area-inset-left));box-shadow:none}
  .mobile-layout .now-playing #activeFolder {font-size:16px;color:var(--ink);font-weight:650;white-space:normal;overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
  .mobile-layout .now-playing #activeMeta {font-size:12px}
  .mobile-layout .viewer-actions {flex-wrap:wrap;justify-content:flex-start;gap:8px}
  .mobile-layout .subtitle-bar {flex:1 0 100%;display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;padding:0}
  .mobile-layout .subtitle-mode-group {justify-content:space-between;border-radius:var(--radius-md)}
  .mobile-layout .subtitle-chip {flex:1;min-width:44px;min-height:44px;border-radius:var(--radius-sm)}
  .mobile-layout .subtitle-format-toggle {min-height:44px;border-radius:var(--radius-md)}
  .mobile-layout .viewer-actions > button,.mobile-layout .action-menu-trigger {flex:0 0 44px;width:44px;height:44px}
  .mobile-layout .viewer-actions [data-tooltip]::after {display:none}
  .mobile-layout .viewer > .ask-ai-panel {order:2}
  .mobile-layout .ask-ai-panel {position:relative;inset:auto;flex:none;width:100%;min-width:0;max-width:none;height:min(640px,85dvh);min-height:320px;border:0;border-top:1px solid var(--border);box-shadow:none}
  .mobile-layout .ask-ai-resize-handle {display:none}
  .mobile-layout .ask-ai-header-btn,.mobile-layout .ask-ai-send-button {min-width:44px;min-height:44px}
  .mobile-layout .ask-ai-mode-group {height:44px}
  .mobile-layout .ask-ai-mode-option {height:38px;min-width:48px}
  .mobile-layout #askAiInput {font-size:16px}
  .mobile-layout .stage-empty {gap:8px;padding:16px;text-align:center}
  .mobile-layout .stage-empty::before {display:none}
  .mobile-layout .stage-empty h3 {font-size:18px}
  .mobile-layout .stage-empty p {font-size:14px}
  .mobile-library-dialog {position:fixed;inset:0 auto 0 0;margin:0;width:min(400px,calc(100vw - 16px));height:100dvh;max-width:none;max-height:100dvh;overflow:auto;overscroll-behavior:contain;border-right:1px solid var(--border)}
  .mobile-library-dialog .library {height:100%;min-height:440px;display:grid;grid-template-rows:auto auto minmax(80px,1fr) minmax(90px,auto);border:0;box-shadow:none}
  .mobile-library-dialog .library-header {padding-top:max(12px,env(safe-area-inset-top))}
  .mobile-library-dialog .library-controls {grid-template-columns:1fr auto;gap:8px}
  .mobile-library-dialog .library-search-row {grid-template-columns:44px minmax(0,1fr)}
  .mobile-library-dialog .library-header .sidebar-toggle {flex:none;width:44px;height:44px}
  .mobile-library-dialog .add-video-button {width:44px;height:44px}
  .mobile-library-dialog .search-field input {min-height:44px;font-size:16px}
  .mobile-library-dialog .secondary-button {min-height:44px;padding:8px}
  .mobile-library-dialog .folder-tab {min-height:44px}
  .mobile-library-dialog .folder-item,.mobile-library-dialog .folder-action {min-height:44px}
  .mobile-library-dialog .video-item {min-height:56px}
  .mobile-library-dialog .folder-list {overflow:auto;overscroll-behavior:contain}
  .mobile-library-dialog .video-list {max-height:160px;overflow:auto}
}

/* Short landscape viewports prioritize the film; controls remain below it. */
@media (max-width:980px) and (max-height:600px) and (orientation:landscape) {
  .mobile-layout .mobile-navigation {display:none}
  .mobile-layout .viewer-stage-container {height:100dvh}
  .mobile-layout .viewer-actions .mobile-library-shortcut {display:block;flex:none;width:auto;min-height:44px;padding:8px 16px;background:var(--panel-2);color:var(--ink);border:1px solid var(--border);border-radius:var(--radius-sm);cursor:pointer}
}

/* Chapter-aware controls share the video's containing block, including fullscreen. */
.player-controls {
  position: absolute;
  inset: auto 0 0;
  z-index: 3;
  padding: 24px 14px 8px;
  color: #fff;
  background: linear-gradient(transparent, rgb(0 0 0 / .88));
  opacity: 1;
  transition: opacity 160ms ease-out;
}
.player-controls-idle .player-controls { opacity: 0; pointer-events: none; }
.player-controls:has(:focus-visible) { opacity: 1; pointer-events: auto; }
.player-timeline { position: relative; height: 28px; touch-action: none; }
.player-segments { position: absolute; inset: 11px 0; pointer-events: none; }
.player-segment { position: absolute; height: 100%; overflow: hidden; border-radius: 2px; background: rgb(255 255 255 / .25); }
.player-segment-buffer, .player-segment-progress, .player-buffer-range { position: absolute; inset: 0 auto 0 0; height: 100%; }
.player-segment-buffer { width: 100%; }
.player-buffer-range { background: rgb(255 255 255 / .32); }
.player-segment-progress { background: var(--accent); }
.player-segment.is-previewed { filter: brightness(1.4); }
.player-timeline:hover .player-segments, .player-timeline:focus-within .player-segments { inset-block: 9px; }
.player-seek { position: absolute; inset: 0; width: 100%; height: 28px; margin: 0; padding: 0; appearance: none; -webkit-appearance: none; background: transparent; cursor: pointer; touch-action: none; }
.player-seek::-webkit-slider-runnable-track { height: 6px; background: transparent; border: 0; }
.player-seek::-moz-range-track { height: 6px; background: transparent; border: 0; }
.player-seek::-moz-range-progress { background: transparent; }
.player-seek::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 12px; height: 12px; margin-top: -3px; border-radius: 50%; border: 0; background: var(--accent); }
.player-seek::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; border: 0; background: var(--accent); }
.player-seek:disabled { cursor: default; }
.player-control-row { display: flex; align-items: center; gap: 8px; min-width: 0; height: 36px; font: 500 .8125rem/1.3 var(--font-sans, system-ui); }
.player-control-button { display: inline-grid; place-items: center; flex: 0 0 36px; width: 36px; height: 36px; min-width: 0; padding: 8px; color: #fff; background: transparent; border: 0; border-radius: 6px; cursor: pointer; }
.player-control-button:hover { background: rgb(255 255 255 / .16); }
.player-control-button svg { width: 20px; height: 20px; }
.player-clock { flex-shrink: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.player-volume { width: 64px; flex: 0 1 64px; min-width: 32px; height: 24px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.player-current-chapter { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
.player-speed { flex: 0 0 auto; width: auto; max-width: 76px; min-height: 32px; padding: 4px; border: 0; border-radius: 4px; background: #20252b; color: #fff; font: inherit; cursor: pointer; }
.player-seek:focus-visible, .player-control-button:focus-visible, .player-speed:focus-visible, .player-volume:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.player-preview { position: absolute; bottom: 86px; z-index: 4; width: min(240px, calc(100% - 16px)); max-width: calc(100% - 16px); pointer-events: none; overflow: hidden; border-radius: 8px; border: 1px solid rgb(255 255 255 / .5); background: #15191e; color: #fff; text-align: center; }
.player-preview[hidden] { display: none; }
.player-preview-frame { width: 100%; aspect-ratio: 16 / 9; display: grid; place-items: center; background: #080b0c; }
.player-preview-frame[hidden] { display: none; }
.player-preview-frame canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
.player-preview-loading { padding: 12px; font-size: .8125rem; color: #d6dadd; }
.player-preview-time { display: block; padding: 7px 10px 2px; font-size: .8125rem; font-variant-numeric: tabular-nums; }
.player-preview-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; padding: 2px 10px 8px; font-size: .875rem; line-height: 1.4; font-weight: 600; overflow-wrap: anywhere; }
.player-preview-title[hidden] { display: none; }
@media (max-width: 600px) {
  .player-controls { padding-inline: 8px; padding-bottom: 6px; }
  .player-control-row { gap: 4px; font-size: .75rem; }
  .player-volume { display: none; }
  .player-control-button { flex-basis: 32px; width: 32px; height: 36px; padding: 6px; }
  .player-speed { max-width: 64px; }
  .player-preview { width: 192px; }
}
@media (prefers-reduced-motion: reduce) { .player-controls { transition: none; } }

.problem-report-dialog { width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); margin: 16px auto auto; padding: 0; border: 1px solid var(--border-strong); border-radius: var(--dialog-radius); background: var(--panel); color: var(--ink); overflow: auto; overscroll-behavior: contain; }
.problem-report-dialog [hidden] { display: none; }
.problem-report-dialog::backdrop { background: var(--dialog-backdrop); overflow: hidden; overscroll-behavior: contain; }
.problem-report-dialog h2 { margin: 0; font-size: 1.125rem; }
.problem-report-body { padding: 16px 20px; line-height: 1.6; }
.problem-report-body > p:first-child { margin-top: 0; }
.problem-report-status { font-weight: 650; }
.problem-report-error { color: var(--danger); overflow-wrap: anywhere; }
.problem-report-result label { display: block; margin-bottom: 6px; font-weight: 650; }
.problem-report-result input, .problem-report-data { box-sizing: border-box; width: 100%; padding: 10px; color: var(--ink); background: var(--field-bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: .875rem/1.6 ui-monospace, monospace; }
.problem-report-data { height: 220px; resize: vertical; }
.problem-report-dialog footer { display: flex; flex-wrap: wrap; gap: 8px; }
.problem-report-dialog summary { cursor: pointer; }
.problem-report-dialog button { min-height: 40px; }

/* ==========================================================================
   學習筆記：時間軸按鈕與標記、播放器下方的筆記列、可拖曳縮放的便利貼
   ========================================================================== */
/* 時間軸：標記在進度條上方的一小段，不擋住拖曳進度；點擊跳轉、滑鼠移上去由播放器預覽框顯示內容。 */
.player-note-markers { position: absolute; inset: 0 0 auto; height: 11px; z-index: 2; pointer-events: none; }
.player-note-marker { position: absolute; top: 0; width: 14px; height: 13px; margin: 0; padding: 0; background: transparent; border: 0; transform: translateX(-50%); cursor: pointer; pointer-events: auto; }
.player-note-marker::before { content: ""; position: absolute; left: 50%; top: 1px; width: 8px; height: 9px; background: var(--note-paper); border-radius: 2px 2px 2px 0; box-shadow: 0 0 0 1px rgb(0 0 0 / .5); transform: translateX(-50%); transition: transform 120ms ease; }
.player-note-marker::after { content: ""; position: absolute; left: 50%; top: 10px; width: 2px; height: 6px; background: var(--note-paper); transform: translateX(-50%); }
.player-note-marker:hover::before { transform: translateX(-50%) scale(1.35); }
.player-note-preview { position: absolute; bottom: 86px; z-index: 4; box-sizing: border-box; width: min(260px, calc(100% - 16px)); padding: 14px 14px 12px; color: var(--note-ink); background: linear-gradient(180deg, rgb(0 0 0 / .05), transparent 22px), var(--note-texture) center / 240px, var(--note-paper); background-blend-mode: normal, multiply, normal; border-radius: 2px 2px 12px 2px; box-shadow: 0 12px 28px rgb(0 0 0 / .5); pointer-events: none; transform: rotate(-1deg); }
.player-note-preview[hidden] { display: none; }
.player-note-preview::before { content: ""; position: absolute; top: -7px; left: 50%; width: 76px; height: 15px; background: var(--note-tape) center / 100% 100% no-repeat; transform: translateX(-50%) rotate(-3deg); }
.player-note-preview-time { font: 700 12px/1.2 var(--font-mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; color: var(--note-muted); }
.player-note-preview-text { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; margin: 6px 0 0; font: 14px/1.55 var(--font-sans, system-ui); overflow-wrap: anywhere; }
.player-note-add { position: absolute; bottom: calc(100% + 4px); z-index: 3; display: grid; place-items: center; width: 32px; height: 32px; padding: 6px; color: var(--note-ink); background: var(--note-texture) center / 160px, var(--note-paper); background-blend-mode: multiply; border: 1px solid var(--note-paper-edge); border-radius: 6px; box-shadow: 0 4px 12px rgb(0 0 0 / .45); transform: translateX(-50%); cursor: pointer; }
.player-note-add[hidden] { display: none; }
.player-note-add::after { content: ""; position: absolute; top: 100%; left: 50%; width: 2px; height: 6px; background: var(--note-paper); transform: translateX(-50%); }
.player-note-add svg { width: 18px; height: 18px; }
.player-note-add:hover { filter: brightness(1.06); transform: translateX(-50%) translateY(-1px); }
.player-note-add:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* 筆記列：與播放器卡片同寬對齊，收合時只剩一列（時間標籤仍可點擊跳轉）。 */
.study-notes-shelf { position: relative; flex: none; min-width: 0; margin: -6px 16px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--shelf-bg), var(--panel); }
.study-notes-shelf[hidden] { display: none; }
.study-notes-bar { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 44px; padding: 4px 8px 4px 4px; }
.study-notes-heading { flex: none; margin: 0; font-size: 13px; }
.study-notes-toggle { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 4px 10px 4px 6px; color: var(--ink); background: transparent; border: 0; border-radius: 8px; font: inherit; font-weight: 700; cursor: pointer; }
.study-notes-toggle:hover { background: var(--hover-wash); }
.study-notes-toggle:focus-visible, .study-notes-add:focus-visible, .study-note-tab:focus-visible, .study-note-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.study-notes-toggle svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.study-notes-chevron { color: var(--muted); transition: transform 160ms var(--ease-out); }
.study-notes-shelf.is-collapsed .study-notes-chevron { transform: rotate(-90deg); }
.study-notes-icon { color: var(--note-paper-edge); }
.study-notes-chips { display: flex; flex: 1 1 auto; gap: 6px; min-width: 0; margin: 0; padding: 2px; list-style: none; overflow-x: auto; scrollbar-width: none; }
.study-notes-chips::-webkit-scrollbar { display: none; }
.study-note-chip, .study-note-tab { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 7px; color: var(--ink); background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; font: 600 12px/1.4 var(--font-mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; cursor: pointer; }
.study-note-chip::before, .study-note-tab::before { content: ""; width: 0; height: 0; border-block: 4px solid transparent; border-left: 6px solid var(--accent); }
.study-note-chip:hover, .study-note-tab:hover { border-color: var(--border-strong); background: var(--accent-soft); }
.study-notes-add { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; margin-left: auto; padding: 4px 12px 4px 9px; color: var(--note-ink); background: var(--note-texture) center / 160px, var(--note-paper); background-blend-mode: multiply; border: 1px solid var(--note-paper-edge); border-radius: 8px; font: 650 13px/1.2 var(--font-sans, system-ui); cursor: pointer; box-shadow: 0 2px 6px rgb(0 0 0 / .18); }
.study-notes-add[hidden] { display: none; }
.study-notes-add svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.study-notes-add:hover { filter: brightness(1.05); }
.study-notes-body { border-top: 1px dashed var(--border); }
.study-notes-body[hidden] { display: none; }
.study-notes-list { display: flex; gap: 18px; margin: 0; padding: 12px 14px 14px; list-style: none; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
.study-notes-list[hidden] { display: none; }
.study-note-item { flex: none; display: grid; justify-items: start; gap: 6px; }
.study-note-card { position: relative; width: 168px; height: 82px; padding: 12px 12px 10px; overflow: hidden; color: var(--note-ink); background: var(--note-texture) center / 220px, var(--note-paper); background-blend-mode: multiply; border: 0; border-radius: 2px 2px 12px 2px; box-shadow: var(--note-shadow); text-align: left; font: 13px/1.45 var(--font-sans, system-ui); cursor: pointer; transform: rotate(-1deg); transition: transform 140ms var(--ease-out), box-shadow 140ms ease; }
.study-note-card-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.study-note-card::before { content: ""; position: absolute; top: -3px; left: 50%; width: 54px; height: 11px; background: var(--note-tape) center / 100% 100% no-repeat; opacity: .9; transform: translateX(-50%) rotate(-3deg); }
.study-note-item:nth-child(even) .study-note-card { transform: rotate(.8deg); }
.study-note-card:hover, .study-note-card:focus-visible { transform: translateY(-3px) rotate(0deg) !important; }
.study-note-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.study-notes-empty { display: flex; align-items: center; gap: 18px; padding: 12px 18px 14px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.study-notes-empty[hidden] { display: none; }
.study-notes-empty img { flex: none; width: 120px; height: auto; }
.study-notes-empty p { margin: 0; max-width: 420px; }
.study-notes-empty strong { color: var(--ink); }
.study-note-time { font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--note-muted); }

/* 便利貼：同一個對話框負責檢視與編輯；--note-zoom 同時放大外框與字級；拖曳後改用 left/top 定位。 */
.study-note-dialog { --note-zoom: 1; position: fixed; inset: auto; top: 50%; left: 50%; box-sizing: border-box; width: min(calc(460px * var(--note-zoom)), calc(100vw - 16px)); max-width: none; max-height: calc(100dvh - 16px); margin: 0; padding: 0; overflow: visible; color: var(--note-ink); background: transparent; border: 0; transform: translate(-50%, -50%); }
.study-note-dialog.is-placed { transform: none; }
.study-note-dialog::backdrop { background: var(--dialog-backdrop); backdrop-filter: blur(3px); }
.study-note-dialog [hidden] { display: none !important; }
.study-note-paper { position: relative; box-sizing: border-box; display: grid; gap: 12px; max-height: calc(100dvh - 16px); padding: 20px 20px 16px; color: var(--note-ink); background: linear-gradient(180deg, rgb(0 0 0 / .05), transparent 30px), var(--note-texture) center / 320px, var(--note-paper); background-blend-mode: normal, multiply, normal; border-radius: 3px 3px 18px 3px; box-shadow: 0 24px 60px rgb(0 0 0 / .45); }
/* 頂端的紙膠帶也是拖曳把手，與標題列一樣可以移動便利貼。 */
.study-note-tape { position: absolute; top: -14px; left: 50%; z-index: 1; width: 132px; height: 26px; background: var(--note-tape) center / 100% 100% no-repeat; transform: translateX(-50%) rotate(-2deg); cursor: grab; touch-action: none; }
.study-note-tape:hover { filter: brightness(1.08); }
.study-note-dialog.is-dragging .study-note-tape { cursor: grabbing; }
/* 右下角折角就是縮放把手：拖曳時外框與字級一起放大縮小，角落短暫顯示目前比例。 */
.study-note-zoom-badge { position: absolute; right: 0; bottom: -30px; padding: 2px 7px; color: var(--note-paper); background: var(--note-ink); border-radius: 999px; font: 700 12px/1.4 var(--font-mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; pointer-events: none; }
.study-note-resize { position: absolute; right: 0; bottom: 0; width: 28px; height: 28px; border-radius: 0 0 18px 0; background: linear-gradient(135deg, transparent 50%, rgb(0 0 0 / .12) 50%); cursor: nwse-resize; touch-action: none; }
.study-note-resize::after { content: ""; position: absolute; right: 7px; bottom: 7px; width: 9px; height: 9px; background: linear-gradient(135deg, transparent 0 40%, var(--note-muted) 40% 48%, transparent 48% 64%, var(--note-muted) 64% 72%, transparent 72%); opacity: .8; }
.study-note-resize:hover { background: linear-gradient(135deg, transparent 50%, rgb(0 0 0 / .2) 50%); }
.study-note-dialog.is-resizing, .study-note-dialog.is-resizing * { cursor: nwse-resize !important; user-select: none; }
.study-note-paper-header { display: flex; align-items: center; gap: 8px; min-width: 0; margin: -6px -6px 0; padding: 4px 4px 4px 6px; border-radius: 6px; cursor: grab; user-select: none; touch-action: none; }
.study-note-dialog.is-dragging .study-note-paper-header { cursor: grabbing; }
.study-note-paper-header:hover { background: rgb(0 0 0 / .04); }
.study-note-paper-header h2 { margin: 0; font-size: 16px; font-weight: 750; color: var(--note-ink); white-space: nowrap; }
.study-note-seek { padding: 2px 8px; background: rgb(255 255 255 / .38); border: 1px solid rgb(0 0 0 / .14); border-radius: 999px; color: var(--note-ink); cursor: pointer; }
.study-note-seek:disabled { cursor: inherit; opacity: 1; }
.study-note-seek:not(:disabled):hover, .study-note-seek:focus-visible { background: rgb(255 255 255 / .62); }
.study-note-position { color: var(--note-muted); font-size: 12px; white-space: nowrap; }
.study-note-icon-button:focus-visible, .study-note-seek:focus-visible { outline: 2px solid var(--note-ink); outline-offset: 1px; }
.study-note-icon-button { margin-left: auto; display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; color: var(--note-ink); background: transparent; border: 0; border-radius: 7px; cursor: pointer; }
.study-note-icon-button svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.study-note-icon-button:hover:not(:disabled) { background: rgb(0 0 0 / .08); }
.study-note-icon-button:disabled { opacity: .35; cursor: default; }
.study-note-body, .study-note-input { box-sizing: border-box; width: 100%; min-height: calc(170px * var(--note-zoom)); max-height: min(calc(420px * var(--note-zoom)), calc(100dvh - 180px)); font: calc(16px * var(--note-zoom))/1.65 var(--font-sans, system-ui); overflow-wrap: anywhere; }
.study-note-body { overflow: auto; padding: 2px 2px 6px; }
.study-note-body:focus-visible { outline: 2px solid var(--note-ink); outline-offset: 4px; border-radius: 4px; }
.study-note-input { padding: 10px 12px; color: var(--note-ink); background: rgb(255 255 255 / .38); border: 1px solid rgb(0 0 0 / .14); border-radius: 6px; resize: vertical; }
.study-note-input::placeholder { color: var(--note-muted); }
.study-note-input:focus-visible { outline: 2px solid var(--note-ink); outline-offset: 1px; }
.study-note-dialog[data-mode="view"] .study-note-input, .study-note-dialog[data-mode="view"] .study-note-edit-only { display: none; }
.study-note-dialog[data-mode="edit"] .study-note-body, .study-note-dialog[data-mode="edit"] .study-note-view-only, .study-note-dialog[data-mode="edit"] .study-note-position { display: none; }
.study-note-error { margin: 0; color: #8a1c10; font-size: 13px; font-weight: 600; }
.study-note-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.study-note-spacer { flex: 1; }
.study-note-hint { color: var(--note-muted); font-size: 12px; }
.study-note-dialog .confirm-button-secondary { min-width: 40px; color: var(--note-ink); background: rgb(255 255 255 / .34); border-color: rgb(0 0 0 / .16); }
.study-note-dialog .confirm-button-secondary:hover:not(:disabled) { background: rgb(255 255 255 / .55); }
.study-note-save { color: var(--note-paper); background: var(--note-ink); border-color: var(--note-ink); }
.study-note-save:hover:not(:disabled) { filter: brightness(1.25); }
.study-note-dialog .confirm-button:hover:not(:disabled) { border-color: rgb(0 0 0 / .3); }
.study-note-dialog .study-note-save:hover:not(:disabled) { border-color: var(--note-ink); }
.study-note-dialog .confirm-button:focus-visible { outline-color: var(--note-ink); }
/* 「確定刪除？」的紅底要蓋過便利貼按鈕的淺色 hover，否則滑過時白字會看不到。 */
.study-note-dialog .study-note-delete[data-confirm="1"] { color: #fff; background: #a3271a; border-color: #a3271a; }
.study-note-dialog .study-note-delete[data-confirm="1"]:hover:not(:disabled) { color: #fff; background: #8a1f14; border-color: #8a1f14; }

.reading-study-note { display: flex; align-items: baseline; gap: 10px; padding-block: 6px; }
.reading-study-note + .reading-study-note { border-top: 1px dashed var(--border); }
.reading-study-note .reading-transcript-seek { flex: none; margin-left: 0; opacity: 0.8; }
.reading-study-note .study-note-markdown { flex: 1; min-width: 0; }

/* 筆記內容的 Markdown：便利貼（紙面配色）與閱讀視窗的筆記分頁（跟著主題配色）共用版面，字級用 em 才會跟著便利貼縮放。 */
.study-note-body, .study-note-markdown { white-space: normal; }
:is(.study-note-body, .study-note-markdown) > :first-child { margin-top: 0; }
:is(.study-note-body, .study-note-markdown) > :last-child { margin-bottom: 0; }
:is(.study-note-body, .study-note-markdown) :is(p, ul, ol, blockquote, pre) { margin: 0 0 .7em; }
:is(.study-note-body, .study-note-markdown) :is(h1, h2, h3, h4, h5, h6) { margin: .9em 0 .35em; font-weight: 800; line-height: 1.3; }
:is(.study-note-body, .study-note-markdown) h1 { font-size: 1.3em; }
:is(.study-note-body, .study-note-markdown) h2 { font-size: 1.18em; }
:is(.study-note-body, .study-note-markdown) :is(h3, h4, h5, h6) { font-size: 1.05em; }
:is(.study-note-body, .study-note-markdown) :is(ul, ol) { padding-left: 1.4em; }
:is(.study-note-body, .study-note-markdown) li > :is(ul, ol) { margin: .2em 0 .3em; padding-left: 1.2em; }
:is(.study-note-body, .study-note-markdown) li + li { margin-top: .2em; }
:is(.study-note-body, .study-note-markdown) strong { font-weight: 800; }
:is(.study-note-body, .study-note-markdown) a { text-decoration-thickness: 1px; text-underline-offset: 3px; }
:is(.study-note-body, .study-note-markdown) code { padding: .1em .32em; border-radius: 4px; font-family: var(--font-mono, ui-monospace, monospace); font-size: .9em; }
:is(.study-note-body, .study-note-markdown) pre { overflow: auto; padding: .6em .75em; border-radius: 6px; }
:is(.study-note-body, .study-note-markdown) pre code { display: block; padding: 0; background: transparent; border: 0; white-space: pre; }
:is(.study-note-body, .study-note-markdown) blockquote { padding: .1em 0 .1em .8em; border-left: 3px solid; }
:is(.study-note-body, .study-note-markdown) blockquote p { margin: 0; }
:is(.study-note-body, .study-note-markdown) hr { margin: .9em 0; border: 0; border-top: 1px solid; }
:is(.study-note-body, .study-note-markdown) .markdown-table-wrap { margin: .5em 0 .7em; }
.study-note-body a { color: inherit; }
.study-note-body :is(code, pre) { background: rgb(0 0 0 / .08); }
.study-note-body blockquote { color: var(--note-muted); border-color: rgb(0 0 0 / .22); }
.study-note-body hr { border-color: rgb(0 0 0 / .18); }
.study-note-body .markdown-table-wrap { border-color: rgb(0 0 0 / .16); }
.study-note-body .markdown-table-wrap :is(th, td) { border-color: rgb(0 0 0 / .16); }
.study-note-body .markdown-table-wrap th { background: rgb(0 0 0 / .06); color: inherit; }
.study-note-body .markdown-table-wrap tr:nth-child(even) td, .study-note-body .markdown-table-wrap tr:hover td { background: rgb(255 255 255 / .2); }
.study-note-markdown a { color: var(--accent); }
.study-note-markdown a:hover { color: var(--ink); }
.study-note-markdown :is(code, pre) { background: var(--well-bg-soft); border: 1px solid var(--border); }
.study-note-markdown blockquote { color: var(--muted); border-color: var(--border-strong); }
.study-note-markdown hr { border-color: var(--border); }
/* 卡片與時間軸滑過的預覽只有行內樣式。 */
:is(.study-note-card-text, .player-note-preview-text) strong { font-weight: 800; }
:is(.study-note-card-text, .player-note-preview-text) code { padding: 0 .25em; border-radius: 3px; background: rgb(0 0 0 / .08); font-family: var(--font-mono, ui-monospace, monospace); font-size: .9em; }

@media (max-width: 980px) {
  .mobile-layout .study-notes-shelf { margin: 0; border-inline: 0; border-radius: 0; }
  .mobile-layout .study-notes-bar { min-height: 52px; padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
  .mobile-layout .study-notes-add, .mobile-layout .study-notes-toggle { min-height: 44px; }
  .mobile-layout .study-notes-add span { display: none; }
  .study-note-hint { display: none; }
  .study-note-paper-header h2 { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .study-note-card, .player-note-add, .study-notes-chevron, .player-note-marker::before { transition: none; }
}

/* 國語配音：影片清單的標記、播放器的「原音／國語配音」切換、配音對話框。 */
.dub-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 0 5px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.6;
  vertical-align: 1px;
}

.dub-dialog {
  width: min(560px, calc(100vw - 32px));
}

.dub-summary {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 14px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--well-bg);
  font-size: 13px;
  line-height: 1.5;
}

.dub-summary dt {
  color: var(--muted);
}

.dub-summary dd {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.dub-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.dub-field select {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
}

.dub-field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dub-note {
  font-size: 13px;
}

.dub-progress {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--well-bg);
}

.dub-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: dub-step;
}

.dub-steps li {
  counter-increment: dub-step;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.dub-steps li::before {
  content: counter(dub-step);
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 11px;
}

.dub-steps li[data-state="active"] {
  color: var(--ink);
}

.dub-steps li[data-state="active"]::before {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--panel);
}

.dub-steps li[data-state="done"]::before {
  content: "✓";
  border-color: var(--accent);
  color: var(--accent);
}

.dub-progress progress {
  width: 100%;
  height: 6px;
  accent-color: var(--accent);
}

.dub-progress-text {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.dub-error {
  padding: 8px 12px;
  border: 1px solid rgb(var(--warning-rgb) / 0.32);
  border-radius: 8px;
  background: rgb(var(--warning-rgb) / 0.1);
  color: var(--warning);
}

@media (max-width: 520px) {
  .dub-steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
