/**
 * tts-reader.css — 「边朗读边教我」的样式
 *
 * 几条约束：
 *   · 控制条是**输入框上方的一条**，不是 fixed 盖在输入框上（手机上打字会挡）。
 *   · 高亮要能看清：浅色黄底 + 左侧琥珀色竖线；深色下换成半透明琥珀，不刺眼。
 *   · 所有颜色走 chat.css 里的 CSS 变量，深色主题自动跟着变。
 *   · 手机 375 宽：状态文字可省略号，按钮不换行、不横向溢出。
 */

/* ---------- 逐句高亮 ---------- */

.ttsr-mark {
  background: #ffe9a8;
  border-radius: 3px;
  /* 左边框用 inset 阴影：跨行时 box-decoration-break:clone 让每行都有落点 */
  box-shadow: inset 3px 0 0 #e8a33d;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-color .15s ease;
}

/* 公式单独高亮：整个公式块套一层琥珀色轮廓，和正文的"行内底色"区分开 */
.ttsr-mark-formula {
  background: rgba(255, 193, 74, .34);
  border-radius: 6px;
  box-shadow: 0 0 0 2px rgba(232, 163, 61, .38);
}

/* 整块左侧竖线：段落里读哪句，眼睛都能顺着左边找到 */
.ttsr-mark-block {
  box-shadow: inset 3px 0 0 rgba(232, 163, 61, .55);
  transition: box-shadow .15s ease;
}

/* 代码块：不逐字读，只提示"这里有一段代码"，用外框标一下 */
.ttsr-mark-code {
  outline: 2px solid #e8a33d;
  outline-offset: 2px;
}

/* 深色主题：站点用 html[data-theme="dark"]，不是 prefers-color-scheme */
html[data-theme="dark"] .ttsr-mark {
  background: rgba(240, 190, 80, .30);
  color: var(--ink, #e8eaef);
  box-shadow: inset 3px 0 0 #f0b84a;
}
html[data-theme="dark"] .ttsr-mark-formula {
  background: rgba(240, 190, 80, .22);
  box-shadow: 0 0 0 2px rgba(240, 184, 74, .42);
}
html[data-theme="dark"] .ttsr-mark-block {
  box-shadow: inset 3px 0 0 rgba(240, 184, 74, .55);
}
html[data-theme="dark"] .ttsr-mark-code {
  outline-color: #f0b84a;
}

/* ---------- 朗读控制条（输入框上方一条） ---------- */

.ttsr-bar {
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 100%;
  padding: 7px 16px 9px;
  background: var(--bg-side, #f7f8fa);
  border-top: 1px solid var(--line, #e6e8ee);
  box-shadow: 0 -8px 22px -18px rgba(20, 30, 60, .55);
  font-family: var(--font, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif);
}
.ttsr-bar[hidden] { display: none !important; }
.ttsr-bar.is-floating {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 2147483000;
  padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px));
}

.ttsr-bar-top {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ttsr-status {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--ink-soft, #4a5163);
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ttsr-status b { color: var(--brand, #4d6bfe); }

.ttsr-btns {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ttsr-btn {
  box-sizing: border-box;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line, #e6e8ee);
  border-radius: 9px;
  background: var(--bg, #fff);
  color: var(--ink-soft, #4a5163);
  font-family: inherit;
  font-size: .8rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.ttsr-btn:hover { background: var(--bg-hover, #eceef2); color: var(--ink, #1b1e28); }
.ttsr-btn:active { transform: scale(.97); }
.ttsr-btn:focus-visible { outline: 2px solid var(--brand, #4d6bfe); outline-offset: 1px; }

/* 暂停/继续是主操作：和品牌色一致，一眼能找到 */
.ttsr-btn-play {
  min-width: 74px;
  background: var(--brand, #4d6bfe);
  border-color: var(--brand, #4d6bfe);
  color: #fff;
}
.ttsr-btn-play:hover {
  background: var(--brand-strong, #3a56e0);
  border-color: var(--brand-strong, #3a56e0);
  color: #fff;
}
.ttsr-btn-rate { font-variant-numeric: tabular-nums; }
.ttsr-btn-stop { color: var(--muted, #8b93a7); }

.ttsr-progress {
  max-width: 820px;
  height: 4px;
  margin: 6px auto 0;
  border-radius: 999px;
  background: var(--line, #e6e8ee);
  overflow: hidden;
}
.ttsr-progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand, #4d6bfe), #7c8cff);
  transition: width .25s ease;
}

@media (max-width: 480px) {
  .ttsr-bar { padding: 6px 10px 8px; }
  .ttsr-bar-top { gap: 6px; }
  .ttsr-status { font-size: .74rem; }
  .ttsr-btns { gap: 4px; }
  /* 触摸目标别小于 34px（和站点其它图标按钮一致） */
  .ttsr-btn { min-width: 34px; height: 34px; padding: 0 6px; font-size: .76rem; }
  .ttsr-btn-play { min-width: 68px; }
  .ttsr-progress { margin-top: 5px; }
}

/* ---------- 回答下方的「🔊 朗读」按钮 ---------- */

.ttsr-answer-btn { white-space: nowrap; }
.ttsr-answer-btn.is-on {
  color: var(--brand, #4d6bfe);
  border-color: #c3cdf0;
  background: var(--bg-active, #e4e8f5);
}

/* 右键菜单里新增的「🔊 从这读」：和原有的「问 AI」用一条细线隔开 */
.ttsr-sel-item {
  margin-top: 3px;
  border-top: 1px solid var(--line, #e6e8ee);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  padding-top: 10px;
}

/* ---------- 轻提示 ---------- */

.ttsr-toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 10px);
  max-width: min(92vw, 460px);
  padding: 10px 15px;
  border-radius: 10px;
  background: rgba(24, 32, 44, .94);
  color: #fff;
  font-family: var(--font, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif);
  font-size: .84rem;
  line-height: 1.55;
  box-shadow: 0 8px 26px rgba(12, 18, 28, .3);
  z-index: 2147483600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.ttsr-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 断点续读 / 读完追问 卡片 ---------- */

.ttsr-resume,
.ttsr-follow {
  margin-top: 8px;
  padding: 9px 11px;
  border: 1px solid var(--line, #e6e8ee);
  border-radius: 10px;
  background: var(--bg-side, #f7f8fa);
  color: var(--ink-soft, #4a5163);
  font-family: var(--font, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif);
  font-size: .8rem;
  line-height: 1.5;
}
.ttsr-resume {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  border-style: dashed;
}
.ttsr-follow { border-left: 4px solid var(--brand, #4d6bfe); }
.ttsr-follow-head { display: flex; align-items: center; gap: 6px; color: var(--muted, #8b93a7); }
.ttsr-card-icon { flex: 0 0 auto; font-size: .95rem; }
.ttsr-card-text { flex: 1 1 auto; min-width: 0; }

.ttsr-card-close {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted, #8b93a7);
  font: inherit;
  cursor: pointer;
}
.ttsr-card-close:hover { background: var(--bg-hover, #eceef2); color: var(--ink, #1b1e28); }

.ttsr-follow-q {
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin-top: 7px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--bg, #fff);
  color: var(--ink, #1b1e28);
  font: inherit;
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ttsr-follow-q:hover { outline: 2px solid var(--brand, #4d6bfe); outline-offset: -2px; }

.ttsr-mini {
  flex: 0 0 auto;
  padding: 5px 11px;
  border: 1px solid var(--brand, #4d6bfe);
  border-radius: 8px;
  background: var(--brand, #4d6bfe);
  color: #fff;
  font: inherit;
  font-size: .76rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ttsr-mini:hover { background: var(--brand-strong, #3a56e0); border-color: var(--brand-strong, #3a56e0); }
.ttsr-mini-ghost {
  background: transparent;
  color: var(--ink-soft, #4a5163);
  border-color: var(--line, #e6e8ee);
  font-weight: 600;
}
.ttsr-mini-ghost:hover { background: var(--bg-hover, #eceef2); color: var(--ink, #1b1e28); border-color: var(--line, #e6e8ee); }

/* ---------- 朗读设置（塞进侧边栏原来的「🗣 朗读设置」折叠区） ---------- */.ttsr-settings {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--line, #e6e8ee);
}

.ttsr-check {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: .78rem;
  color: var(--ink-soft, #4a5163);
  line-height: 1.45;
  cursor: pointer;
}
.ttsr-check input[type="checkbox"] {
  flex: 0 0 auto;
  margin: 2px 0 0;
  accent-color: var(--brand, #4d6bfe);
}

.ttsr-field { display: block; }
.ttsr-field-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--muted, #8b93a7);
}
.ttsr-rate-val { color: var(--ink-soft, #4a5163); font-variant-numeric: tabular-nums; }
.ttsr-field input[type="range"] {
  width: 100%;
  margin: 3px 0 0;
  accent-color: var(--brand, #4d6bfe);
}
.ttsr-note {
  margin: 0;
  font-size: .72rem;
  line-height: 1.5;
  color: var(--muted, #8b93a7);
}

/* ---------- 减少动态效果 ---------- */

@media (prefers-reduced-motion: reduce) {
  .ttsr-mark,
  .ttsr-mark-block,
  .ttsr-progress-fill,
  .ttsr-toast,
  .ttsr-btn { transition: none; }
  .ttsr-btn:active { transform: none; }
}
