/* ===== 角色聊天 - 聊天界面 ===== */
#chat-screen { 
    display: none; 
    flex: 1; 
    flex-direction: column; 
    height: 100vh; 
    position: relative; 
    overflow: hidden;
}

/* 聊天内容区域 */
.chat-header,
.chat-messages,
.chat-input-area,
.generation-controls {
    position: relative;
    z-index: 1;
}

/* 顶部标题栏 - 固定锁定 */
.chat-header {
    padding: 12px 16px; 
    background: rgba(26, 35, 50, 0.65);
    border-bottom: 1px solid rgba(45, 58, 74, 0.5);
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    gap: 12px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
}
.chat-header .header-left { flex: 1; min-width: 0; }
.chat-header .story-title {
    font-weight: 700; font-size: 0.95rem; color: #ffffff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header .story-summary {
    font-size: 0.75rem; color: var(--text-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.chat-header .header-actions { display: flex; gap: 8px; flex-shrink: 0; }
.chat-header .header-actions button {
    background: transparent; 
    border: 1px solid rgba(45, 58, 74, 0.5); 
    color: var(--text-dim);
    padding: 6px 10px; 
    border-radius: 6px; 
    cursor: pointer; 
    font-size: 0.8rem;
}
.chat-header .header-actions button:hover { border-color: var(--primary); color: var(--text); }

/* 消息列表 - 上下留出固定栏位空间 */
.chat-messages {
    flex: 1; 
    overflow-y: auto; 
    padding: 72px 16px 320px 16px;
    display: flex; 
    flex-direction: column; 
    gap: 12px;
}
.msg { display: flex; gap: 10px; max-width: 85%; }
.msg.char { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.system { align-self: stretch; }
.msg.system .bubble { 
    background: rgba(26, 35, 50, 0.65); 
    border: 1px solid rgba(45, 58, 74, 0.5); 
    border-radius: 12px; 
    padding: 10px 14px; 
    font-size: 0.9rem; 
    line-height: 1.6; 
    white-space: pre-wrap; 
    text-align: center; 
    opacity: 0.65; 
}
.msg .avatar {
    width: 32px; height: 32px; border-radius: 50%; background: rgba(26, 35, 50, 0.65);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; flex-shrink: 0; cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}
.msg .avatar:hover {
    box-shadow: 0 0 0 2px var(--primary);
    transform: scale(1.1);
}
.msg .avatar img {
    width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
    display: block;
}
.msg .bubble {
    padding: 10px 14px; border-radius: 12px; font-size: 0.9rem;
    line-height: 1.6; white-space: pre-wrap;
}
.msg.char .bubble { 
    background: rgba(26, 35, 50, 0.65); 
    border: 1px solid rgba(45, 58, 74, 0.5); 
    border-top-left-radius: 4px;
}
.msg.user .bubble { 
    background: rgba(124, 58, 237, 0.65); 
    border-top-right-radius: 4px;
}
.msg .bubble .format-scene { color: var(--accent); font-style: italic; font-size: 0.82rem; }
.msg .bubble .format-action { color: var(--text-dim); }
.msg .bubble .format-speak { color: var(--text); }
.msg .bubble .format-thought { color: #a78bfa; font-style: italic; }
.msg.img-msg .bubble img { max-width: 100%; border-radius: 8px; margin-top: 8px; cursor: pointer; }

/* 场景消息（独立气泡） */
.msg.scene-msg .bubble.scene-bubble {
    background: rgba(124, 58, 237, 0.65);
    border: 1px dashed rgba(124, 58, 237, 0.4);
    border-radius: 8px;
    font-style: italic;
    color: var(--accent);
    font-size: 0.85rem;
    text-align: center;
    padding: 8px 12px;
}

/* 多角色消息：角色名标签 */
.msg .bubble .char-label {
    font-weight: 700;
    color: var(--primary);
    font-size: 0.8rem;
    display: block;
    margin-bottom: 2px;
}

/* 内心想法按钮 & TTS 音频胶囊 */
.msg .bubble .thought-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    margin-left: 6px;
    padding: 3px 10px;
    background: rgba(167, 139, 250, 0.15);
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 12px;
    color: #a78bfa;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    box-sizing: border-box;
}
.msg .bubble .thought-btn:hover {
    background: rgba(167, 139, 250, 0.3);
    border-color: #a78bfa;
}
.msg .bubble .thought-btn:disabled {
    cursor: default;
    opacity: 0.7;
}
.msg .bubble .thought-btn:disabled:hover {
    background: rgba(167, 139, 250, 0.15);
    border-color: rgba(167, 139, 250, 0.3);
}

/* 内心想法内容 */
.msg .bubble .thought-content {
    margin-top: 4px;
    padding: 6px 10px;
    background: rgba(167, 139, 250, 0.08);
    border-left: 2px solid #a78bfa;
    border-radius: 4px;
    font-style: italic;
    color: #c4b5fd;
    font-size: 0.82rem;
}

/* 快捷回复选项 - 独立气泡区域，固定在输入区上方 */
.reply-options {
    padding: 8px 16px 12px 16px;
    display: flex; flex-wrap: wrap;
    gap: 8px;
    min-height: 0;
    border-top: 1px solid rgba(45, 58, 74, 0.3);
    background: rgba(26, 35, 50, 0.3);
    border-radius: 12px 12px 0 0;
    position: fixed;
    bottom: 76px;
    left: 0;
    right: 0;
    z-index: 15;
}
.reply-option-btn {
    padding: 6px 16px; 
    background: rgba(124, 58, 237, 0.12);
    border: 1px solid rgba(124, 58, 237, 0.4);
    border-radius: 16px; color: var(--text); font-size: 0.82rem; cursor: pointer;
    transition: all 0.2s; white-space: nowrap;
}
.reply-option-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.reply-option-btn:active { transform: scale(0.95); }
.reply-option-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 废弃：气泡内 inline-replies（保留以防兼容） */
.msg .bubble .inline-replies { display: none; }

/* 兼容：未解析的 <> 建议回复纯文本显示 */
.msg .bubble .format-suggested-replies {
    display: none;
}

/* 底部输入区 - 固定锁定 */
.chat-input-area {
    padding: 12px 16px; 
    background: rgba(26, 35, 50, 0.65);
    border-top: 1px solid rgba(45, 58, 74, 0.5);
    display: flex; gap: 8px; 
    position: fixed;
    bottom: 22px;
    left: 0;
    right: 0;
    z-index: 20;
}
.chat-input-area textarea {
    flex: 1; padding: 10px 12px; 
    background: transparent; 
    border: 1px solid rgba(45, 58, 74, 0.5);
    border-radius: 10px; color: var(--text); font-size: 0.9rem; resize: none;
    outline: none; font-family: inherit; min-height: 42px; max-height: 120px;
}
.chat-input-area textarea:focus { border-color: var(--primary); }
.chat-input-area .send-btn {
    width: 42px; height: 42px; border-radius: 10px; background: var(--primary);
    border: none; color: #fff; font-size: 1.2rem; cursor: pointer; flex-shrink: 0;
}
.chat-input-area .send-btn:hover { background: var(--primary-dark); }
.chat-input-area .send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
