/* ===== 基础变量与重置 ===== */
:root {
  color-scheme: dark;
  --bg: #111317;
  --panel: #1b2028;
  --panel-2: #232a34;
  --surface: #232a34;
  --text: #eef2f6;
  --muted: #a9b4c0;
  --line: #333d4a;
  --accent: #46c2a1;
  --accent-2: #6aa7ff;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
/* 弹窗打开时（html.modalOpen）锁住页面滚动：只让弹窗内部滚，主体纹丝不动。
   scrollbar-gutter 是为了锁定时页面不因滚动条消失而横向抖动。 */
html { scrollbar-gutter: stable; }
html.modalOpen, html.modalOpen body { overflow: hidden; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
button {
  border: 0;
  background: var(--accent);
  color: #07110e;
  padding: 10px 14px;
  border-radius: 7px;
  font-weight: 700;
  cursor: pointer;
}
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: .55; cursor: wait; }
input, textarea {
  width: 100%;
  color: var(--text);
  background: #12161d;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  outline: none;
}
textarea { min-height: 86px; resize: vertical; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 14px; }

/* ===== 全局 select ===== */
select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  outline: none;
}
select:focus { border-color: var(--accent); }
select:hover { border-color: var(--muted); }

/* ===== 布局 ===== */
.shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(18px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: #151922;
}
.headerActions { display: flex; gap: 8px; align-items: center; }
.headerLeft { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
/* 「自动」模式下显示的落点节点提示 */
.autoBackendHint { font-size: 13px; white-space: nowrap; }
h1 { margin: 0; font-size: 19px; letter-spacing: 0; }
main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 28px) 44px;
  display: grid;
  gap: 18px;
}

/* ===== 认证视图（连接 / setup / 登录） ===== */
.authCard {
  width: min(420px, calc(100% - 28px));
  margin: 8vh auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  display: grid;
  gap: 14px;
}
.authCard h1 { font-size: 18px; }
.authCard .muted { font-size: 13px; line-height: 1.5; }

/* ===== 通用 ===== */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 13px;
}
.panel h2 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 22px; }
.hidden { display: none !important; }

/* ===== 后端选择器 ===== */
#backendSelect { width: auto; min-width: 160px; }

/* ===== 任务列表 ===== */
.list { display: grid; gap: 10px; }

/* ===== 缓存库加载动画 ===== */
.listLoading {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 24px 0 28px;
}
.listLoading canvas {
  width: 240px;
  height: 120px;
  display: block;
}
.listLoadingText {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .04em;
}
.library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.sectionHeader {
  grid-column: 1 / -1;
  font-size: 15px;
  font-weight: 800;
  color: var(--muted);
  margin: 8px 0 2px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.mediaCard {
  position: relative;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.mediaCard:hover { border-color: #4a5563; box-shadow: 0 8px 22px rgba(0, 0, 0, .34); transform: translateY(-1px); }
.mediaCard.selected { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(70, 194, 161, .38); }
.thumb {
  aspect-ratio: 16 / 9;
  background: #080b10;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}
.thumb.clickable { cursor: pointer; }
.thumb.clickable::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 11, .3);
  opacity: 0;
  transition: opacity .16s;
  pointer-events: none;
}
.thumb.clickable:hover::after { opacity: 1; }
.thumbFallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, .26);
  background:
    radial-gradient(circle at 30% 22%, rgba(70, 194, 161, .16), transparent 55%),
    radial-gradient(circle at 78% 78%, rgba(106, 167, 255, .16), transparent 55%),
    #0b0f15;
  font-size: 38px;
}
.thumbImage {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
}
.selectBox {
  position: absolute;
  top: 9px;
  left: 9px;
  z-index: 2;
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.folderBadge {
  position: absolute;
  right: 8px;
  top: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(5, 8, 12, .72);
  border: 1px solid rgba(255, 255, 255, .18);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  z-index: 2;
}
.burnBadge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 107, 107, .88);
  border: 1px solid rgba(255, 107, 107, .5);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  z-index: 2;
}
/* 缩略图右下角：这个任务存放在哪个后端节点（多后端时显示） */
.serverBadge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  max-width: calc(100% - 24px);
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(5, 8, 12, .76);
  border: 1px solid rgba(106, 167, 255, .45);
  color: #cfe0ff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 2;
}
/* burnToggle 使用全局 .toggleRow + .toggle 样式，此处仅微调 */
.burnToggle { padding: 4px 0; }
.burnToggle label { font-size: 13px; color: var(--muted); }
/* align-content: start —— 卡片被同行更高的卡片拉高时，多出来的空间留在底部，
   不去拉伸文件行（否则同一张卡在别人旁边行高就不一样了） */
.mediaBody { padding: 12px; display: grid; gap: 8px; align-content: start; }
.mediaTitle {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  word-break: break-word;
}
.mediaMeta {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 文件列表：整块面板，行内「文件名 · 大小」+ 右侧极简操作，避免一个个按钮堆成墙 */
.folderFiles {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #141922;
  overflow: hidden;
}
/* 弹窗里的全量文件列表：外观与卡片内的面板一致，只是自己滚动、不占用卡片高度 */
.filesModalList {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #141922;
  overflow-y: auto;
  max-height: 56vh;
  scrollbar-width: thin;
}
.folderFiles::-webkit-scrollbar,
.filesModalList::-webkit-scrollbar { width: 8px; }
.folderFiles::-webkit-scrollbar-thumb,
.filesModalList::-webkit-scrollbar-thumb { background: #2c3542; border-radius: 4px; }
.folderFiles::-webkit-scrollbar-thumb:hover,
.filesModalList::-webkit-scrollbar-thumb:hover { background: #3b4757; }

/* ===== 多视频种子：选择要下载的文件（默认全选 + 反选） ===== */
.pickToolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pickToolbar button { padding: 4px 10px; font-size: 12px; }
#pickSummary { margin-left: auto; font-size: 12px; }
.pickList {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #141922;
  overflow-y: auto;
  max-height: 52vh;
  scrollbar-width: thin;
}
.pickList::-webkit-scrollbar { width: 8px; }
.pickList::-webkit-scrollbar-thumb { background: #2c3542; border-radius: 4px; }
.pickList::-webkit-scrollbar-thumb:hover { background: #3b4757; }
.pickRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
}
.pickRow:last-child { border-bottom: none; }
.pickRow:hover { background: rgba(255, 255, 255, .04); }
.pickRow input { width: 16px; height: 16px; flex: 0 0 auto; accent-color: var(--accent); }
.pickName { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.pickSize { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.pickActions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 16px; }

.fileRow {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 2px;
  padding-right: 4px;
  min-width: 0;
  /* 行背景兼作「该文件的缓存进度条」：宽度由 JS 写 --fill，颜色按是否正在播放区分 */
  background-image: linear-gradient(to right,
    var(--fillColor, rgba(255, 255, 255, .07)) var(--fill, 0%),
    transparent var(--fill, 0%));
}
.fileRow + .fileRow { border-top: 1px solid rgba(255, 255, 255, .055); }
.fileRow:hover { background-color: rgba(255, 255, 255, .045); }
.fileRow.active { --fillColor: rgba(106, 167, 255, .26); }

.file {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}
.file:disabled { color: var(--muted); cursor: default; }
.fileGlyph { font-size: 10px; color: var(--muted); }
.fileName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fileMeta { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.file.active { color: #cfe2ff; }
.file.active .fileGlyph { color: var(--accent-2); }
.file.active .fileMeta { color: #9fc4ff; }

.fileAction {
  padding: 4px 7px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.fileAction:hover:not(:disabled) { background: rgba(255, 255, 255, .08); color: var(--text); }
.fileAction.primary { color: var(--accent); border-color: rgba(70, 194, 161, .38); }
.fileAction.primary:hover:not(:disabled) { background: rgba(70, 194, 161, .14); }
.fileAction.danger:hover:not(:disabled) { color: #ff9090; background: rgba(255, 107, 107, .13); }
.fileAction:disabled { opacity: .38; cursor: not-allowed; }
/* 已完整缓存：不再显示「下载中」，改成安静的「已下载」 */
.fileAction.done,
.fileAction.done:disabled { opacity: .8; color: var(--accent); cursor: default; }

.filesToggle {
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}
.filesToggle:hover { color: var(--text); border-color: var(--accent); background: rgba(70, 194, 161, .06); }

/* 视频缓冲动画：居中盖在画面上（.customControls 是 absolute，不计入高度，
   所以这里的 inset:0 中心就是画面中心）。pointer-events:none —— 不能挡住「点画面播放/暂停」 */
.playerBuffering {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  background: rgba(5, 6, 8, .35);
  pointer-events: none;
}
.playerBuffering.hidden { display: none; }
.playerBuffering canvas { width: 96px; height: 96px; display: block; }
.playerBufferingText { font-size: 12px; color: var(--muted); letter-spacing: .06em; }

/* ===== 播放器 ===== */
.playerFrame {
  position: relative;
  background: #050608;
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.playerFrame:fullscreen {
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  display: grid;
  place-items: center;
  background: #000;
}
.playerFrame:fullscreen video,
.playerFrame:fullscreen audio { max-height: 100vh; }
video, audio {
  width: 100%;
  max-height: 68vh;
  background: #050608;
  display: block;
}
/* 元数据还没到位时先按 16:9 占位（见 playFile 里加的 .preload）。
   否则 <video> 会退回默认的 300x150（2:1）尺寸，先撑出一个怪形状、加载完再跳一下。 */
video.preload { aspect-ratio: 16 / 9; }
audio { min-height: 180px; }
.customControls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 8px;
  padding: 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.78) 30%, rgba(0,0,0,.92));
  transition: opacity .3s;
  opacity: 1;
}
.playerFrame.ctrl-hidden .customControls { opacity: 0; pointer-events: none; }
.playerFrame:fullscreen { cursor: none; }
.playerFrame:fullscreen.ctrl-shown { cursor: default; }
/* 控件行：不允许把按钮文字挤成竖排；真放不下时整块换行，而不是压扁 */
.controlRow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; row-gap: 6px; }
.iconBtn {
  flex: 0 0 auto;
  white-space: nowrap;
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  border-radius: 7px;
  background: rgba(255,255,255,.12);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.16);
}
/* 音量条：需覆盖全局 input 的 width/padding/边框，保持暗色风格统一 */
.volumeSlider {
  width: 110px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.volumeLabel {
  color: var(--muted);
  font-size: 13px;
  min-width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.controlSpacer { flex: 1 1 auto; min-width: 0; }
.subtitleSelect {
  flex: 0 1 auto;
  min-width: 0;
  width: 152px;
  max-width: 190px;
  height: 34px;
  padding: 0 8px;
  border-radius: 7px;
  background: rgba(255,255,255,.12);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.16);
  font-size: 13px;
  cursor: pointer;
}
.subtitleSelect option { background: var(--surface); color: var(--text); }
.subtitleResults {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.subtitleResultItem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.subtitleResultItem:hover { border-color: var(--accent); }
/* 当前已挂载的那一条：左手高亮 + 按钮变「已挂载」 */
.subtitleResultItem.applied {
  border-color: var(--accent);
  background: rgba(70, 194, 161, .12);
  box-shadow: inset 3px 0 0 var(--accent);
}
.subtitleResultInfo { flex: 1; min-width: 0; }
.subtitleResultName { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subtitleResultMeta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.subtitleResultLang {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,.1);
  color: var(--muted);
  white-space: nowrap;
}
.subtitleDownloadBtn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 5px;
  background: var(--accent);
  color: #000;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}
.subtitleDownloadBtn.applied {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(70, 194, 161, .5);
}
.subtitleDownloadBtn:disabled { opacity: .5; cursor: not-allowed; }
/* 自定义字幕渲染层：用 DOM 渲染代替浏览器原生 <track>，才能自由调字号/位置/颜色 */
.subtitleOverlay {
  position: absolute;
  left: 4%;
  right: 4%;
  /* 实际 bottom 由 JS 按「用户设定比例 + 控件避让高度」算成 px 覆盖 */
  bottom: 8%;
  text-align: center;
  pointer-events: none;
  transition: bottom .18s ease;
}
.subtitleOverlay.hidden { display: none; }
#subtitleText {
  display: inline-block;
  max-width: 100%;
  white-space: pre-line;
  line-height: 1.35;
  font-weight: 600;
}
/* 本地 AI 翻译开着且已有译文时：原文一行、译文一行（译文略小、略淡，便于对照） */
.subLine { display: block; }
/* 卡片里「没有选择要缓存的视频 / 缓存已清理」的提示 */
.mediaEmpty { padding: 6px 2px 2px; font-size: 12px; }
.subTrans { font-size: .88em; opacity: .88; }
/* 语音转写里「正在识别的半句」：还没定稿，画淡一点 */
.subPending { opacity: .58; font-weight: 500; }
.speedSelect {
  flex: 0 0 auto;
  width: 76px;
  height: 34px;
  padding: 0 6px;
  border-radius: 7px;
  background: rgba(255,255,255,.12);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.16);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}
.speedSelect option { background: var(--surface); color: var(--text); }
.styleRange {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== 在线搜索资源 ===== */
.searchRow { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.searchRow input { flex: 1 1 220px; min-width: 0; box-sizing: border-box; }
.searchRow button { flex: 0 0 auto; }
.torrentResults {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 460px;
  overflow-y: auto;
}
.torrentResultItem {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 11px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.torrentResultItem:hover { border-color: var(--accent); }
.torrentResultThumb {
  flex: 0 0 auto;
  width: 104px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #0b0f15;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.torrentResultThumb .thumbImg { display: block; width: 100%; height: 100%; object-fit: cover; }
.torrentResultThumb .thumbSpin { display: block; width: 26px; height: 26px; }
.torrentResultThumb .thumbFail {
  padding: 0 5px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.25;
  text-align: center;
}
.torrentResultInfo { flex: 1 1 180px; min-width: 0; }
.torrentResultName { font-size: 14px; word-break: break-word; }
.torrentResultMeta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.torrentResultActions { display: flex; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; }
.torrentResultActions button {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 5px;
  white-space: nowrap;
  background: rgba(255,255,255,.12);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.16);
  cursor: pointer;
}
.torrentResultActions button.primary { background: var(--accent); color: #000; border-color: transparent; }
.torrentResultActions button:disabled { opacity: .45; cursor: not-allowed; }
.seedGood { color: #7ee787; }
.seedNone { color: var(--muted); }

/* 搜索结果里的关键词高亮 */
mark.kwHit {
  background: rgba(70,194,161,.30);
  color: #d9fff3;
  font-weight: 600;
  border-radius: 3px;
  padding: 0 2px;
}

/* ===== 字幕偏移面板（放在播放器内，全屏也能用） ===== */
.subOffsetPanel {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 96px;
  z-index: 3;
  min-width: 236px;
  padding: 10px 12px;
  text-align: center;
  background: rgba(12,16,22,.96);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 8px 28px rgba(0,0,0,.6);
}
.subOffsetPanel.hidden { display: none; }
.subOffsetTitle { font-size: 13px; margin-bottom: 8px; }
.subOffsetBtns { display: flex; gap: 6px; justify-content: center; }
.subOffsetBtns button {
  flex: 1 1 0;
  padding: 6px 0;
  font-size: 12px;
  border-radius: 6px;
  background: rgba(255,255,255,.12);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.16);
  cursor: pointer;
}
.subOffsetReset {
  margin-top: 8px;
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  cursor: pointer;
}
.subOffsetHint { margin-top: 7px; font-size: 11px; color: var(--muted); }

/* 字幕样式浮层：复用偏移面板的壳，但内容左对齐、更宽，超高时自己滚动 */
.subStylePanel {
  min-width: 276px;
  text-align: left;
  max-height: calc(100% - 116px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.subStylePanel::-webkit-scrollbar { width: 8px; }
.subStylePanel::-webkit-scrollbar-thumb { background: #2c3542; border-radius: 4px; }
.subStyleRow {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 9px 0 3px;
  font-size: 12px;
  color: var(--muted);
}
.subStylePanel select {
  width: 100%;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  background: #12161d;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.subStylePanel .subOffsetReset { width: 100%; }
/* AI 翻译面板：自检 + 开关并排 */
.subAiBtns { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.subAiBtns .subOffsetReset { margin-top: 0; flex: 1 1 auto; }
.subAiBtns .secondary { flex: 0 0 auto; padding: 5px 12px; font-size: 12px; }
/* 本地 AI 面板里「翻译」与「转写探针」之间的分隔 */
.aiDivider { margin: 12px 0 4px; border-top: 1px solid var(--line); }
/* 转写探针输出框（只显示文本，用于判断识别质量） */
.asrOut {
  margin-top: 8px;
  padding: 8px;
  max-height: 140px;
  overflow-y: auto;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  background: #050608;
  border: 1px solid var(--line);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
}
.asrOut.hidden { display: none; }
.asrOut .asrMeta { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.asrOut .asrInterim { color: var(--muted); }
.subStylePreview {
  margin-top: 10px;
  padding: 14px 10px;
  text-align: center;
  background: #050608;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.playerBar { display: grid; gap: 8px; }
.timeline {
  position: relative;
  height: 22px;
  border-radius: 7px;
  background: #0b0f15;
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
}
.segment {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 4px;
  background: #ffbf3f;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.playhead {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 3px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.65), 0 0 10px rgba(255,255,255,.42);
  pointer-events: none;
}
.timeRow, .statRow {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
}
.meter {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #11161d;
  border: 1px solid var(--line);
}
.meter > span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ===== 音量/手势指示器 ===== */
.volIndicator {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 7px;
  background: rgba(0,0,0,.8);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text);
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.volIndicator.show { opacity: 1; }
.volBar { width: 50px; height: 5px; border-radius: 999px; background: #11161d; overflow: hidden; }
.volFill { height: 100%; width: 100%; background: var(--accent); transition: width .1s; }
.gestureIndicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  display: grid;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 10px;
  background: rgba(0,0,0,.82);
  border: 1px solid var(--line);
  font-size: 15px;
  color: var(--text);
  text-align: center;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  min-width: 140px;
}
.gestureIndicator.show { opacity: 1; }
.gestureIndicator .volBar { width: 120px; }

/* ===== 设置弹窗（三 tab） ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}
.modalOverlay { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modalContent {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: min(760px, calc(100% - 32px));
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;   /* 滚到尽头也别把滚动传给页面主体 */
}
.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modalHeader h2 { margin: 0; font-size: 16px; }
.modalBody { padding: 18px; display: grid; gap: 14px; }

/* 自定义提示 / 确认弹窗（替代原生 alert / confirm）。用 id 提权，免得被移动端的
   `.modalContent { width: calc(100% - 12px) }` 覆盖成整屏 */
#dialogModal .modalContent { width: min(420px, calc(100% - 32px)); }
.dialogText {
  white-space: pre-wrap;   /* 文案里带 \n 的地方要真的换行 */
  word-break: break-word;
  line-height: 1.6;
  font-size: 14px;
  color: var(--text);
}
.dialogActions { display: flex; justify-content: flex-end; gap: 10px; }
.dialogActions button { min-width: 84px; }

/* 非阻塞提示（toast）：右上角浮出、几秒后自动消失。
   放右上角是为了避开右下角（那里有移动端的统计药丸和桌面端的悬浮统计面板）。
   容器 pointer-events: none，只有单条提示可点，绝不挡住下层的点击。 */
.toastHost {
  position: fixed;
  right: 12px;
  top: calc(12px + env(safe-area-inset-top));
  z-index: 105;   /* 高于 .modal(100)，弹窗开着时也看得见 */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: min(360px, calc(100vw - 24px));
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(27, 32, 40, .97);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;   /* 文案里带 \n 的地方要真的换行 */
  word-break: break-word;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .5);
  cursor: pointer;
  animation: toastIn .18s ease-out;
}
.toast-error { border-left-color: var(--danger); }
/* 从上方滑入 / 向上淡出（在右上角，方向要跟着走） */
.toastOut { opacity: 0; transform: translateY(-6px); transition: opacity .2s, transform .2s; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* Tab 导航 */
.tabNav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  padding: 0 18px;
}
.tabBtn {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.tabBtn.active { color: var(--text); border-bottom-color: var(--accent); }
.tabPanel { display: none; }
.tabPanel.active { display: grid; gap: 14px; }

/* 设置区块 */
.settingsSection { display: grid; gap: 8px; }
.settingsSection h3 { margin: 0; font-size: 14px; color: var(--muted); }
.settingsSection p { margin: 0; }

/* ===== Toggle 开关 ===== */
.toggleRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
}
.toggleRow label { display: inline; color: var(--text); font-size: 14px; }
/* 用户配额行：label 在左，输入框 + 「GB · 已用 X」在右 */
.quotaBox { display: flex; align-items: center; gap: 8px; }
/* 「可用后端节点」勾选框：多个节点小标签，靠右排、自动换行 */
.backendRow { align-items: flex-start; }
.backendPick { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: flex-end; max-width: 62%; }
.backendItem { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap; min-width: 0; max-width: 100%; }
.backendItem input { margin: 0; cursor: pointer; flex: 0 0 auto; }
/* 节点名过长时省略号：不让它顶破「可用后端节点」那一行（窄屏 / 长名字会溢出重叠） */
.backendName { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 新增用户表单里那组勾选框：靠左、占满一行，别跟着用户管理行的靠右布局 */
#newUserBackends { justify-content: flex-start; max-width: none; margin: 6px 0; }
.quotaInput { width: 88px; }
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex: 0 0 40px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle .slider {
  position: absolute;
  inset: 0;
  background: #11161d;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: .2s;
}
.toggle .slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(18px); background: #07110e; }

/* ===== 用户/后端列表项 ===== */
.manageItem {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.manageItemHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.manageItemName { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manageItemMeta { color: var(--muted); font-size: 12px; }
.manageItemPerms { display: grid; gap: 4px; }
.adminBadge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(70, 194, 161, .2);
  border: 1px solid rgba(70, 194, 161, .4);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}
.tokenMask {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--muted);
  background: #11161d;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  user-select: all;
}

/* 健康状态指示灯 */
.healthDot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
  flex: 0 0 8px;
}
.healthDot.online { background: var(--accent); box-shadow: 0 0 6px rgba(70, 194, 161, .6); }
.healthDot.offline { background: var(--danger); box-shadow: 0 0 6px rgba(255, 107, 107, .5); }
.healthDot.restarting { background: #ffbf3f; animation: pulse 1s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.addForm {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.addForm h4 { margin: 0 0 4px; font-size: 14px; color: var(--muted); }
.formRow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.permChecks { display: grid; gap: 6px; }
.permChecks label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
.permChecks input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

/* ===== I/O 统计面板 ===== */
#statsPanel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 14px;
  font-size: 14px;
}
#statsPanel.hidden { display: none !important; }
#statsPanel.floating {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 90;
  width: 280px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,.55);
}
.statsGroup { display: grid; gap: 10px; }
.statsGroup + .statsGroup { border-top: 1px solid var(--line); padding-top: 14px; }
.statsHeader { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 15px; }
.statsHeader svg, .statsSubHeader svg { width: 16px; height: 16px; flex: 0 0 16px; }
.statsSubgroup { display: grid; gap: 6px; padding-left: 24px; }
.statsSubHeader { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.statsLine {
  color: var(--muted);
  padding-left: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.statsLabel { flex: 0 0 auto; }
/* 迷你走势图：preserveAspectRatio="none" 让它随容器宽度拉伸，高度固定，不用管 DPR */
.statsLine .spark { flex: 1 1 auto; min-width: 32px; height: 18px; display: block; overflow: visible; }
.statsValue {
  flex: 0 0 auto;
  min-width: 72px;
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* 移动端：悬浮统计收成右下角药丸（默认不显示，窄屏且选中「悬浮窗」时才由 JS 放出来） */
.statsFab {
  display: none;
  align-items: center;
  gap: 6px;
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 96;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(27, 32, 40, .96);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .5);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.statsFab.hidden { display: none !important; }
.statsFab svg { width: 16px; height: 16px; flex: 0 0 16px; color: var(--accent); }
.statsFab.open { border-color: var(--accent); }
.statsFab:active { transform: scale(.97); }

/* ===== 响应式 ===== */
/* 窄屏（竖屏手机 / 手机「桌面版网站」模式 / 竖屏平板）：先把所有并排布局塌成单列。
   注意断点必须盖住 820~1000 这一段 —— 手机在「桌面版网站」模式下布局宽度约 860~980px，
   以前只到 820px，结果手机上看到的还是桌面那套挤成一团的布局。 */
@media (max-width: 1000px) {
  /* 头部：标题 / 节点选择 / 按钮各自占一行，不要挤成一条 */
  header { flex-direction: column; align-items: stretch; gap: 10px; }
  .headerLeft { flex-direction: column; align-items: stretch; gap: 8px; }
  #backendSelect { width: 100%; min-width: 0; }
  .headerActions { gap: 8px; }
  .headerActions button { flex: 1 1 0; }

  /* 磁力 / 种子 两栏并排 → 上下堆叠 */
  .grid { grid-template-columns: 1fr; }
  .formRow { grid-template-columns: 1fr; }

  /* 搜索结果：缩略图收窄，三个按钮换到下一行平分整行（手指点得准） */
  .torrentResultItem { padding: 8px; gap: 8px; }
  .torrentResultThumb { width: 84px; }
  .torrentResultActions { width: 100%; }
  .torrentResultActions button { flex: 1 1 0; }
  .torrentResults { max-height: 62vh; }

  /* 任务工具栏：排序下拉独占一行 */
  #sortSelect { flex: 1 1 100%; min-width: 0; }

  /* 任务卡片：minmax(250px) 在 860px 左右会挤出 3 列、每列 270px，文件名全被切碎 →
     窄屏放大到 300px（830px 宽 ≈ 2 列，430px 宽自动 1 列） */
  .library { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

  /* 「可用后端节点」勾选框：窄屏一行一个、铺满整行。
     原来 .backendPick 是 max-width:62% + 子项 nowrap，长节点名会把这一行顶到溢出重叠。 */
  .backendRow { flex-direction: column; align-items: stretch; gap: 6px; }
  .backendPick, #newUserBackends { flex-direction: column; align-items: stretch; justify-content: flex-start; max-width: none; gap: 6px; }
  .backendItem { width: 100%; }

  /* 设置弹窗移动端全屏化 */
  .modalContent { width: calc(100% - 12px); max-height: 94vh; border-radius: 8px; }
  .modalHeader { padding: 12px 14px; }
  .modalBody { padding: 14px; gap: 12px; }
  .tabNav { padding: 0 14px; }
  .tabBtn { padding: 8px 10px; font-size: 13px; }
  /* 播放控件紧凑化 */
  .customControls { padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 5px; }
  .iconBtn { min-width: 32px; height: 30px; padding: 0 7px; font-size: 12px; border-radius: 6px; }
  .timeline { height: 18px; border-radius: 5px; }
  .playerBar { gap: 5px; }
  .controlRow { gap: 5px; row-gap: 5px; }
  .volumeSlider { width: 58px; height: 18px; }
  .volumeLabel { display: none; }   /* 移动端隐藏百分比文字，拖动时用悬浮指示器显示 */
  .subtitleSelect { width: 100px; max-width: 116px; height: 30px; font-size: 11px; padding: 0 4px; }
  .speedSelect { width: 56px; height: 30px; font-size: 11px; padding: 0 2px; }
  .listLoading canvas { width: 190px; height: 95px; }
  video, audio { max-height: 60vh; }
  audio { min-height: 140px; }
}

/* 横屏手机 / 矮窗口：宽度可能超过 820px，但播放控件同样要紧凑 */
@media (max-height: 520px) {
  .customControls { padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); gap: 5px; }
  .iconBtn { min-width: 32px; height: 30px; padding: 0 7px; font-size: 12px; border-radius: 6px; }
  .timeline { height: 18px; }
  .playerBar { gap: 5px; }
  .controlRow { gap: 7px; row-gap: 5px; }
  .volumeSlider { width: 64px; height: 18px; }
  .subtitleSelect { width: 122px; max-width: 142px; height: 30px; font-size: 12px; }
  .speedSelect { width: 62px; height: 30px; font-size: 12px; }
}

/* 极窄竖屏：再压一档，保证控件一行放得下 */
@media (max-width: 400px) {
  .iconBtn { min-width: 28px; height: 28px; padding: 0 5px; font-size: 11px; }
  .controlRow { gap: 4px; row-gap: 4px; }
  .volumeSlider { width: 44px; }
  .subtitleSelect { width: 84px; max-width: 96px; height: 28px; }
  .speedSelect { width: 52px; height: 28px; }
}

/* ===== 竖屏手机：单独一套更合适的布局 ===== */
/* 只动页面骨架与卡片，不碰播放控件的尺寸（那部分由上面两档负责） */
@media (max-width: 640px) {
  /* 悬浮统计不再常驻：只留右下角药丸，点开才展开成底部浮层，不会整块盖住页面 */
  .statsFab { display: flex; }
  #statsPanel.floating { display: none; }
  #statsPanel.floating.sheetOpen {
    display: grid;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(66px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 58vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 12px;
    padding: 14px;
    gap: 12px;
    z-index: 96;
  }

  /* 头部：标题 + 按钮各占一行，后端选择独占一行，避免挤成一团 */
  header { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 14px; }
  .headerLeft { flex-direction: column; align-items: stretch; gap: 8px; }
  h1 { font-size: 15px; line-height: 1.35; }
  #backendSelect { width: 100%; min-width: 0; }
  .headerActions { gap: 8px; }
  .headerActions button { flex: 1 1 0; }

  main { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); gap: 12px; }
  .grid { gap: 12px; }
  .panel { padding: 13px; gap: 11px; border-radius: 10px; }
  .panel h2 { font-size: 15px; }
  .authCard { padding: 18px; }

  /* 搜索区：输入框独占一行，两个按钮平分整行（手指好点） */
  .searchRow { gap: 6px; }
  .searchRow input { flex: 1 1 100%; }
  .searchRow button { flex: 1 1 0; }

  /* 搜索结果：缩略图再小一档（一行能塞下更多结果），文字各收一档 */
  .torrentResultItem { padding: 7px; gap: 7px; }
  .torrentResultThumb { width: 64px; }
  .torrentResultThumb .thumbFail { font-size: 9.5px; line-height: 1.15; }
  .torrentResultName { font-size: 13px; }
  .torrentResultMeta { font-size: 11px; }
  .torrentResultActions { width: 100%; }
  .torrentResultActions button { flex: 1 1 0; }

  /* 卡片文件行：字号收一点，把宽度让给文件名 */
  .file { font-size: 12.5px; padding: 7px 6px; gap: 6px; }
  .fileMeta { font-size: 11px; }
  .fileAction { padding: 4px 5px; }
  /* 任务卡片一列铺满；卡片元信息与焚毁开关说明也收一档 */
  .library { grid-template-columns: 1fr; }
  .mediaMeta { font-size: 11.5px; }
  .burnToggle label { font-size: 12.5px; line-height: 1.3; }
  #statsPanel { padding: 14px; }
  .statsValue { min-width: 64px; }

  /* 字幕样式浮层：窄屏下铺满宽度 */
  .subStylePanel { left: 10px; right: 10px; min-width: 0; transform: none; }
}
