/* AZOTH voice-bubble.css（v6 Phase D3，2026-09-24）
   语音气泡的共同外观：用户语音（.az-vb--user = .az-voice-card）与 AI 语音化回复（.az-vb--ai = .chat-voice-message）。
   · 宽度随时长（--az-vb-w，由 voice-bubble.js 按秒数算，有上下限）；
   · 细波形，每根高度 --az-vb-h（0–1），播放时只让当前这一个气泡的波形起伏；
   · 播放键是图标按钮，播放 / 暂停在键里切换；点气泡其余地方展开转写。
   旧的 .chat-voice-* 规则原先以字符串注入在 script.js（_ensureStreamCSS），已搬到这里。
   时间戳挂载位置（.azoth-voice-time / .azoth-tts-time）仍由 turn-transparency.css 负责。 */

.az-vb {
    display: block;
    --az-vb-bar-h: 22px;
}

.az-vb > summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.6em;
    min-width: min(var(--az-vb-w, 8em), 100%);
    max-width: 100%;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.az-vb > summary::-webkit-details-marker {
    display: none;
}

/* ── 播放键 ─────────────────────────────────────────────────────────── */
#character-chat-screen .az-vb .az-vb-play,
.az-vb .az-vb-play {
    position: relative;
    width: 2em !important;
    height: 2em !important;
    min-width: 2em !important;
    flex: 0 0 auto;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 999px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: none !important;
    cursor: pointer;
    transition: transform 120ms ease, background-color 160ms ease;
}

.az-vb .az-vb-play:active {
    transform: scale(0.92);
}

.az-vb .az-vb-icon {
    width: 1.05em;
    height: 1.05em;
    fill: currentColor;
}

.az-vb .az-vb-icon-pause,
.az-vb.is-playing .az-vb-icon-play {
    display: none;
}

.az-vb.is-playing .az-vb-icon-pause {
    display: block;
}

/* 合成 / 下载中：键外一圈细环在转 */
.az-vb.is-loading .az-vb-play::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 999px;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    opacity: 0.55;
    animation: az-vb-spin 0.9s linear infinite;
}

/* ── 波形 ───────────────────────────────────────────────────────────── */
.az-vb .az-vb-wave {
    flex: 1 1 auto;
    min-width: 2.4em;
    height: var(--az-vb-bar-h);
    display: flex;
    align-items: center;
    gap: 2px;
    overflow: hidden;
}

.az-vb .az-vb-bar {
    display: block;
    flex: 0 0 2.5px;
    width: 2.5px;
    height: calc(var(--az-vb-h, 0.5) * 100%);
    min-height: 3px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.42;
    transform-origin: center;
    transition: opacity 140ms ease;
}

.az-vb .az-vb-bar.is-played {
    opacity: 0.95;
}

/* 播放时：只有这一个气泡的波形起伏（相位按序号错开，像声音在走） */
.az-vb.is-playing .az-vb-bar {
    animation: az-vb-breathe 0.9s ease-in-out infinite;
    animation-delay: calc(var(--az-vb-i, 0) * -71ms);
}

/* ── 时长 N″ ────────────────────────────────────────────────────────── */
.az-vb .az-vb-dur {
    flex: 0 0 auto;
    font-size: 0.86em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    opacity: 0.85;
}

/* AI 并没有真的发语音：没播过之前按字数估算，写明是估算 */
.az-vb .az-vb-dur.is-estimate::before {
    content: '≈';
    margin-right: 1px;
    opacity: 0.7;
}

/* ── 用户语音气泡（自带胶囊外观：voice_message 外层不套聊天气泡）────────── */
.az-vb--user {
    width: fit-content;
    max-width: min(100%, 17em);
    min-width: 0;
    padding: 0.5em 0.85em 0.5em 0.5em;
    border-radius: 1.25em;
    border-bottom-right-radius: 0.45em;
    background: var(--accent);
    color: var(--bg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.az-vb--user > summary {
    width: var(--az-vb-w, 8em);
    max-width: 100%;
    min-height: 2em;
}

#character-chat-screen .az-vb--user .az-vb-play {
    background: rgba(255, 255, 255, 0.22) !important;
    color: inherit !important;
}

.az-vb--user .az-voice-transcript {
    margin-top: 0.55em;
    padding-top: 0.5em;
    border-top: 1px solid rgba(255, 255, 255, 0.28);
    max-width: 15em;
    font-size: 0.9em;
    line-height: 1.55;
}

.az-vb--user .az-voice-transcript-state.is-working {
    opacity: 0.8;
    animation: az-vb-fade 1.4s ease-in-out infinite;
}

/* ── AI 语音气泡（分段模式的整条语音 / 完整模式的句内语音行）──────────── */
.chat-message-bubble.chat-voice-bubble {
    min-width: 0;
}

.az-vb--ai > summary {
    width: var(--az-vb-w, 8em);
}

#character-chat-screen .az-vb--ai .az-vb-play {
    background: rgba(var(--accent-rgb), 0.14) !important;
    color: var(--accent) !important;
}

.az-vb--ai .az-vb-wave {
    color: var(--accent);
}

/* 完整模式的句内语音行：嵌在文字气泡里的一颗小胶囊 */
.az-vb--ai.chat-voice-inline {
    width: fit-content;
    max-width: 100%;
    margin: 0.35em 0;
    padding: 0.35em 0.75em 0.35em 0.35em;
    border-radius: 999px;
    background: rgba(var(--accent-rgb), 0.08);
}

.az-vb--ai.chat-voice-inline[open] {
    border-radius: 1em;
}

.chat-voice-transcript {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(var(--accent-rgb), 0.16);
    opacity: 0.85;
}

/* 仿 ChatGPT / Claude 主题：用户气泡跟主题的用户色，而不是 AZOTH 的强调色 */
.chat-ui-mode-chatgpt .az-vb--user,
.chat-ui-mode-claude .az-vb--user {
    background: var(--user-bubble-bg, rgba(127, 127, 127, 0.14));
    color: inherit;
    box-shadow: none;
}

.chat-ui-mode-chatgpt .az-vb--user .az-vb-play,
.chat-ui-mode-claude .az-vb--user .az-vb-play {
    background: rgba(127, 127, 127, 0.16) !important;
}

.chat-ui-mode-chatgpt .az-vb--user .az-voice-transcript,
.chat-ui-mode-claude .az-vb--user .az-voice-transcript {
    border-top-color: rgba(127, 127, 127, 0.22);
}

@keyframes az-vb-breathe {
    0%, 100% { transform: scaleY(0.55); }
    50% { transform: scaleY(1.08); }
}

@keyframes az-vb-spin {
    to { transform: rotate(360deg); }
}

@keyframes az-vb-fade {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 0.95; }
}

@media (prefers-reduced-motion: reduce) {
    .az-vb.is-playing .az-vb-bar,
    .az-vb.is-loading .az-vb-play::after,
    .az-vb--user .az-voice-transcript-state.is-working {
        animation: none;
    }
}
