* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #07090d;
  --bar: rgba(12, 15, 22, .96);
  --border: #232a36;
  --text: #f2f6fb;
  --dim: #7d8899;
  --accent: #4f9cf9;
  --ok: #3fb68b;
  --danger: #f85149;

  /* 字幕字号:投屏时整体放大改这两个值即可 */
  --size-translated: 46px;
  --size-original: 24px;
  /* 左右留白:窗口越窄留白越小,字幕尽量撑满 */
  --pad-x: clamp(14px, 2.2vw, 44px);
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------------------------------------------------------------- 字幕条 */

.subtitle {
  flex-shrink: 0;
  background: var(--bar);
  border-bottom: 1px solid var(--border);
  /* 左右留白跟着窗口收缩,窄窗口下把宽度让给字幕文字 */
  padding: 20px var(--pad-x) 24px;
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  /* 这里刻意不用 backdrop-filter:带 backdrop-filter 的元素会被提升到独立合成层,
     绕过正常 z-index 顺序,结果字幕会画在历史抽屉上面。背景本来就 96% 不透明,
     模糊也看不出来。 */
  position: relative;
  z-index: 1;
}

.line, .line-tr {
  /* 用 block + 浮动标签,而不是 flex 并排:flex 会把整块文字推到标签右边,
     换行后第二行也跟着缩进,左边白白空出一个标签的宽度。浮动只影响首行。 */
  display: block;
  line-height: var(--lh);
  /* 长句最多占 3 行,超出保留末尾(和真实字幕一样跟着最新的字走)。
     3em 要按这一行自己的字号算,所以字号设在行容器上、.txt 继承——
     若把字号只写在 .txt 上,em 会退回继承的 16px,行盒会被压到 1 行多。 */
  max-height: calc(var(--lh) * 3em);
  overflow: hidden;
}

.chip {
  float: left;
  margin: .28em 10px 0 0;
  font-size: 12px;
  line-height: 1.35;
  letter-spacing: .04em;
  color: var(--dim);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  background: rgba(255,255,255,.03);
  white-space: nowrap;
}
.chip.live { color: var(--accent); border-color: rgba(79,156,249,.5); }

.txt {
  /* 中英日混排的关键:允许在任意字符间换行,避免超长英文单词把行撑破 */
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: inherit;
  line-height: var(--lh);
  transition: color .12s;
}

.line.original {
  --lh: 1.35;
  font-size: var(--size-original);
}
.line.original .txt { color: var(--dim); font-weight: 400; }

.lines-translated { display: flex; flex-direction: column; gap: 8px; }
.line-tr {
  --lh: 1.3;
  font-size: var(--size-translated);
}
.line-tr .txt { font-weight: 600; letter-spacing: .01em; }

/* 未定稿的句子:压暗 + 光标,定稿后转为高亮白字 */
.txt.partial { color: #9fb0c6; }
.txt.partial::after {
  content: "▌";
  margin-left: 3px;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* 新句子进场:轻微上移淡入,避免字幕硬跳 */
.line-tr.enter, .line.original.enter { animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* 上一句的译文:新句子已开口但它的译文还没到,压暗但保留可读,
   避免译文刚出现就被清掉 */
.line-tr.stale { opacity: .45; transition: opacity .3s; }

.subtitle.empty .line, .subtitle.empty .lines-translated { display: none; }
.subtitle:not(.empty) .placeholder { display: none; }
.placeholder { color: var(--dim); font-size: 16px; text-align: center; }

.subtitle.hide-original .line.original { display: none; }

/* ---------------------------------------------------------------- 舞台 */

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  /* 窗口压矮时 stage 会被挤到比内容还小,不裁掉的话地球和标题会溢出去
     压在字幕和控制条上面 */
  overflow: hidden;
}
.stage-inner { text-align: center; opacity: .5; }
.mark { font-size: 62px; margin-bottom: 14px; }
.stage-inner h1 { font-size: 30px; font-weight: 600; letter-spacing: .02em; }
.tagline { color: var(--dim); margin-top: 8px; font-size: 15px; }
.auto-note { color: var(--dim); margin-top: 20px; font-size: 13px; }

/* ---------------------------------------------------------------- 控制条 */

.controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--bar);
}
.ctl-group { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ctl-group.right { justify-content: flex-end; }
.ctl-label { font-size: 13px; color: var(--dim); white-space: nowrap; }

.chips { display: flex; gap: 6px; }
.chip-btn {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.chip-btn:hover { border-color: var(--dim); }
.chip-btn.active {
  background: rgba(79,156,249,.14);
  border-color: var(--accent);
  color: var(--accent);
}
.chip-btn:disabled { opacity: .4; cursor: not-allowed; }

.ctl-label.sep { margin-left: 6px; }
.ctl-select {
  background: transparent; color: var(--dim);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 6px 8px; font-size: 13px; font-family: inherit; cursor: pointer;
}
.ctl-select:hover { border-color: var(--dim); }
.ctl-select:disabled { opacity: .4; cursor: not-allowed; }

.mic-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 26px;
  padding: 12px 30px;
  font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: all .15s;
  white-space: nowrap;
}
.mic-btn:hover { filter: brightness(1.1); }
.mic-btn.live { background: var(--danger); animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(248,81,73,.5); }
  50% { box-shadow: 0 0 0 10px rgba(248,81,73,0); }
}

.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dim); cursor: pointer; }
.toggle input { accent-color: var(--accent); cursor: pointer; }

.badge {
  font-size: 12px; color: var(--dim);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 12px; white-space: nowrap;
}
.badge.mock { color: #d29922; border-color: #d29922; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.dot.ok { background: var(--ok); }

/* ---------------------------------------------------------------- 实时回看 */

.stage { position: relative; }

.scrollback {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.scrollback[hidden] { display: none; }
.stage:has(.scrollback:not([hidden])) .stage-inner { display: none; }

.sb-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px var(--pad-x); border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--dim); flex-shrink: 0;
}
.sb-head em { color: var(--text); font-style: normal; font-weight: 600; }

.sb-list {
  flex: 1; overflow-y: auto; padding: 12px var(--pad-x);
  display: flex; flex-direction: column; gap: 10px;
}
.sb-list::-webkit-scrollbar { width: 6px; }
.sb-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sb-empty { padding: 30px; text-align: center; color: var(--dim); font-size: 14px; }
.scrollback.has-rows .sb-empty { display: none; }

.utt {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 12px; line-height: 1.5;
}
.utt .u-meta { font-size: 11px; color: var(--dim); margin-bottom: 2px; }
.utt .u-orig { font-size: 15px; color: var(--dim); }
.utt .u-tr { font-size: 17px; font-weight: 600; }
.utt .u-tr + .u-tr { margin-top: 2px; }

/* ---------------------------------------------------------------- 历史抽屉 */

.drawer {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(4, 6, 10, .72);
  display: flex; justify-content: center; align-items: center;
}
.drawer[hidden] { display: none; }

.drawer-panel {
  width: min(1000px, 94vw); height: min(680px, 88vh);
  background: #10141c; border: 1px solid var(--border); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.drawer-head h3 { font-size: 16px; font-weight: 600; }
.drawer-note { flex: 1; font-size: 12px; color: var(--dim); }
.chip-btn.danger { color: var(--danger); border-color: rgba(248,81,73,.4); }

.drawer-body { flex: 1; display: flex; min-height: 0; }

.sess-list {
  width: 280px; flex-shrink: 0; overflow-y: auto;
  border-right: 1px solid var(--border); list-style: none;
}
.sess-list li {
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; font-size: 13px;
}
.sess-list li:hover { background: rgba(255,255,255,.03); }
.sess-list li.active { background: rgba(79,156,249,.12); }
.sess-list .s-time { color: var(--text); }
.sess-list .s-sub { color: var(--dim); font-size: 12px; margin-top: 3px; }
.sess-list .s-empty { padding: 24px 16px; color: var(--dim); cursor: default; }

.sess-detail { flex: 1; overflow-y: auto; padding: 16px 20px; min-width: 0; }
.sess-hint { color: var(--dim); font-size: 14px; }
.sess-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.sess-rows { display: flex; flex-direction: column; gap: 12px; }

/* ---------------------------------------------------------------- 口令登录 */

.login-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(7, 9, 13, .97);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
}
.login-mask[hidden] { display: none; }

.login-box {
  width: min(340px, 86vw);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 34px 30px;
  background: var(--panel, #12161f);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
}
.login-logo { font-size: 40px; }
.login-box h2 { font-size: 19px; font-weight: 600; }
.login-sub { font-size: 13px; color: var(--dim); margin-bottom: 4px; }

.login-box input {
  width: 100%;
  background: #0b0e14; color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 14px; font-size: 15px; font-family: inherit;
  text-align: center; letter-spacing: .08em;
}
.login-box input:focus { outline: none; border-color: var(--accent); }

.login-box button {
  width: 100%;
  background: var(--accent); color: #fff; border: none;
  border-radius: 9px; padding: 11px; font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.login-box button:hover { filter: brightness(1.1); }
.login-box button:disabled { opacity: .55; cursor: not-allowed; }

.login-err { font-size: 13px; color: var(--danger); min-height: 18px; }

.chip-btn.logout { color: var(--dim); }
.chip-btn.logout[hidden] { display: none; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: #fff;
  padding: 11px 22px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 20;
  max-width: 80vw;
}

/* 窗口变矮:这是"把窗口压成一条字幕带挂在屏幕顶上"的用法。
   舞台装饰先让位,字号和留白收紧,把高度全留给字幕。
   注意用 max-height 而不是 max-width —— 压矮的宽窗口才是这里的主场景。 */
@media (max-height: 620px) {
  /* 字号跟着窗口高度走:窗口越矮字越小,越高字越大,文字尽量把字幕带吃满,
     而不是固定字号在一条矮带里留一大块空 */
  :root {
    --size-translated: clamp(28px, 11vh, 46px);
    --size-original: clamp(16px, 5.8vh, 24px);
  }
  /* 装饰让位。字幕带贴着文字收缩(而不是撑满整块高度再让文字漂在中间),
     多出来的空间留在带子外面,视觉上就是一条紧贴字幕的横带。 */
  .stage { display: none; }
  .subtitle {
    flex: 0 0 auto;
    min-height: 0;
    justify-content: flex-start;
    padding: 12px var(--pad-x);
    gap: 6px;
  }
  .controls { margin-top: auto; }   /* stage 没了,靠这个把控制条钉在底部 */
  /* 原文让位给译文:原文压到 2 行,译文仍保留 3 行 */
  .line.original { max-height: calc(var(--lh) * 2em); }
  .controls { padding: 8px 16px; }
  .mic-btn { padding: 9px 22px; font-size: 14px; }
}

/* 真正放不下 3 行译文时才砍到 2 行(粗算:控制条 55 + 内边距 24 + 原文 2 行
   + 译文 3 行,约 300px 是分界) */
@media (max-height: 320px) {
  .line-tr { max-height: calc(var(--lh) * 2em); }
  .subtitle { padding: 8px var(--pad-x); gap: 4px; }
  .ctl-label, .badge { display: none; }
}

/* 窗口变窄:语种标签占的横向空间开始显眼,收小它,并允许控制条换行 */
@media (max-width: 820px) {
  :root { --size-translated: 28px; --size-original: 17px; }
  .chip { font-size: 11px; padding: 2px 7px; margin-right: 7px; }
  .controls { flex-wrap: wrap; justify-content: center; gap: 12px; }
  .ctl-group, .ctl-group.right { flex: none; justify-content: center; }
  .stage-inner h1 { font-size: 22px; }
  .tagline, .auto-note { font-size: 12px; }
}

@media (max-width: 520px) {
  :root { --size-translated: 21px; --size-original: 14px; }
  .ctl-label, .badge { display: none; }
}
