:root {
    --bg-color: #1a1013;
    --card-bg: #2b1b26;
    --pink-main: #ff8eaa;
    --pink-light: #ffc4d6;
    --text-color: #f5e6eb;
    --text-muted: #a88b96;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.page { display: none; height: 100%; flex-direction: column; width: 100%; }
.page.active { display: flex; }

#setup-page { justify-content: center; align-items: center; background: radial-gradient(circle at top, #2b1b26, #110a0d); }
.setup-card { background: rgba(255,255,255,0.05); padding: 30px; border-radius: 20px; width: 85%; max-width: 350px; text-align: center; box-shadow: 0 10px 30px rgba(255,142,170,0.1); }
.setup-card h1 { color: var(--pink-main); margin-bottom: 10px; font-weight: 500; }
.setup-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 25px; }
#nickname-input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--pink-main); background: transparent; color: #fff; text-align: center; margin-bottom: 20px; font-size: 16px; }
.gender-select { display: flex; gap: 10px; margin-bottom: 25px; }
.gender-btn { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--text-muted); background: transparent; color: var(--text-muted); cursor: pointer; transition: 0.3s; }
.gender-btn.active { background: var(--pink-main); color: #fff; border-color: var(--pink-main); }
#enter-btn { width: 100%; padding: 14px; border-radius: 12px; border: none; background: var(--pink-main); color: #fff; font-size: 16px; font-weight: bold; opacity: 0.5; transition: 0.3s; cursor: not-allowed; }
#enter-btn:not(:disabled) { opacity: 1; cursor: pointer; box-shadow: 0 5px 15px rgba(255,142,170,0.4); }

.topbar { padding: 15px; text-align: center; font-size: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); color: var(--pink-light); }
.system-banner { text-align: center; font-size: 12px; color: var(--text-muted); padding: 10px; background: rgba(255, 142, 170, 0.1); margin: 10px 15px 0; border-radius: 10px; border: 1px dashed rgba(255,142,170,0.3); }
#messages { flex: 1; padding: 20px 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }

/* --- 气泡与布局 --- */
.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg.ai { align-self: flex-start; align-items: flex-start; }
.msg.user { align-self: flex-end; align-items: flex-end; }

/* 🌟 新增：发送者名字 */
.sender-name {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding: 0 4px;
}

/* 气泡行（包含气泡和转文字按钮） */
.bubble-row {
    display: flex;
    align-items: center; /* 垂直居中 */
    gap: 8px; /* 气泡和按钮的间距 */
}
.msg.user .bubble-row {
    flex-direction: row-reverse; /* 用户的转文字按钮如果在左边可以反转，不过用户用不到 */
}

/* 文字气泡 */
.text-bubble { padding: 10px 15px; border-radius: 18px; font-size: 15px; line-height: 1.4; word-break: break-all; }
.msg.ai .text-bubble { background: var(--card-bg); border-bottom-left-radius: 4px; border: 1px solid rgba(255,142,170,0.2); }
.msg.user .text-bubble { background: var(--pink-main); border-bottom-right-radius: 4px; color: #fff; }

/* 语音气泡（粉色） */
.voice-bubble { 
    position: relative;
    display: flex; align-items: center; justify-content: center;
    background: var(--pink-main); 
    color: #fff;
    padding: 10px 20px; 
    border-radius: 18px; 
    cursor: pointer;
    width: fit-content;
    min-width: 70px;
}
.msg.ai .voice-bubble { border-bottom-left-radius: 4px; }
.msg.user .voice-bubble { border-bottom-right-radius: 4px; }

/* 波形线 */
.wave { display: flex; align-items: center; gap: 3px; margin-right: 8px; }
.wave span { display: block; width: 2px; background: #fff; border-radius: 2px; }
.wave span:nth-child(1) { height: 8px; }
.wave span:nth-child(2) { height: 14px; }
.wave span:nth-child(3) { height: 10px; }

/* 语音红点 */
.red-dot {
    position: absolute;
    top: -4px; right: -4px;
    width: 10px; height: 10px;
    background-color: #ff0000;
    border-radius: 50%;
    display: none;
}
.red-dot.active { display: block; }

/* 🌟 转文字按钮：变成了极其低调的小字，放在气泡右边 */
.trans-btn { 
    font-size: 11px; 
    color: var(--text-muted); 
    cursor: pointer; 
    background: rgba(255,255,255,0.05);
    padding: 4px 6px;
    border-radius: 6px;
    white-space: nowrap;
}

/* 展开的文字区域 */
.trans-text { 
    font-size: 13px; 
    color: var(--pink-light); 
    margin-top: 6px; 
    display: none; 
    background: rgba(0,0,0,0.2); 
    padding: 8px 12px; 
    border-radius: 8px; 
    max-width: 100%; 
    word-break: break-all; 
}

/* --- 底部输入区 --- */
.input-area { padding: 15px; background: rgba(26,16,19,0.9); border-top: 1px solid rgba(255,255,255,0.05); display: flex; align-items: center; gap: 10px; }
.input-wrapper { flex: 1; position: relative; display: flex; align-items: center; }
.chat-input {
    width: 100%;
    padding: 12px 70px 12px 15px;
    background: var(--card-bg);
    border: 1px solid rgba(255,142,170,0.3);
    border-radius: 12px;
    color: var(--text-color);
    font-size: 14px;
}
.send-btn {
    position: absolute;
    right: 6px;
    height: 32px;
    padding: 0 12px;
    background: var(--pink-main);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    display: none;
}
.voice-btn {
    width: 90px;
    flex-shrink: 0;
    height: 44px;
    background: transparent;
    color: var(--pink-main);
    border: 1px solid var(--pink-main);
    border-radius: 12px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: all 0.2s;
}
.voice-btn.recording { background: var(--pink-main); color: #fff; }
.voice-btn.canceling { background: #444; color: #ff4d4d; border-color: #ff4d4d; }

.footer-sign { text-align: center; padding: 8px; font-size: 11px; color: #ff8eaa; opacity: 0.7; }

/* 将输入框 placeholder 提示语改成粉色 */
.chat-input::placeholder {
    color: var(--pink-main);
    opacity: 0.7; /* 加一点透明度，看起来更柔和 */
}

/* ============================================================
   Cloudflare 版新增样式
   ============================================================ */

/* 字幕默认展开：语音合成被浏览器拦截时，用户仍能看到文字 */
.trans-text.show { display: block; }

/* 正在朗读 / 正在输入 / 系统提示 */
.voice-bubble:focus-visible { outline: 2px solid var(--pink-light); outline-offset: 3px; }
.voice-bubble.playing { box-shadow: 0 0 0 3px rgba(255, 142, 170, 0.25); }

@keyframes pink-wave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1.4); }
}
.voice-bubble.playing .wave span { animation: pink-wave 0.8s ease-in-out infinite; }
.voice-bubble.playing .wave span:nth-child(2) { animation-delay: 0.12s; }
.voice-bubble.playing .wave span:nth-child(3) { animation-delay: 0.24s; }

.typing {
    align-self: center;
    font-size: 12px;
    color: var(--pink-main);
    padding: 2px 10px;
    opacity: 0.8;
}

.msg.system { align-self: center; max-width: 92%; }
.system-note {
    font-size: 12px;
    line-height: 1.5;
    color: var(--pink-light);
    background: rgba(255, 142, 170, 0.08);
    border: 1px dashed rgba(255, 142, 170, 0.25);
    padding: 7px 12px;
    border-radius: 9px;
    text-align: center;
    word-break: break-all;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 92px;
    transform: translate(-50%, 10px);
    max-width: 82%;
    padding: 9px 15px;
    border-radius: 20px;
    background: rgba(43, 27, 38, 0.96);
    border: 1px solid rgba(255, 142, 170, 0.35);
    color: var(--text-color);
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.voice-btn:disabled,
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

#messages { overscroll-behavior: contain; }

.install-btn {
    width: 100%;
    margin-top: 12px;
    padding: 10px;
    border: 1px solid rgba(255, 142, 170, 0.45);
    border-radius: 10px;
    background: transparent;
    color: var(--pink-light);
    font-size: 13px;
    cursor: pointer;
}
.install-btn[hidden] { display: none; }
