:root {
    --primary-color: #0078D4; --listening-color: #10B981; --speaking-color: #F59E0B;
    --bg-color: #f0f4f8; --container-bg: #ffffff; --text-color: #333; --subtle-text-color: #6c757d;
}

/* ========================================================= */
/* ==== 關鍵修改：全新的頁面佈局模型 ==== */
/* ========================================================= */
html, body {
    height: 100%;
    margin: 0;
    overflow: hidden; /* 防止頁面本身滾動 */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    /* 將整個頁面設為一個垂直的 Flex 容器 */
    display: flex;
    flex-direction: column;
}

.chat-container {
    text-align: center;
    background-color: var(--container-bg);
    padding: 30px 40px;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
    max-width: 550px;
    width: 90%;
    margin: auto; /* 在桌機上，使其保持垂直置中 */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* ========================================================= */
/* ==== 關鍵修改：字幕區不再是 fixed 定位 ==== */
/* ========================================================= */
#subtitles-container {
    background-color: rgba(0, 0, 0, 0.75);
    color: #fff;
    width: 100%;
    box-sizing: border-box;
    /* 使用 max-height 來控制展開和收合的動畫 */
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, opacity 0.4s ease-in-out, padding 0.4s ease-in-out;
}

/* 當字幕區被啟用時的樣式 */
#subtitles-container.active {
    padding: 15px 20px;
    max-height: 40vh; /* 展開到螢幕高度的 40% */
    opacity: 1;
}

#subtitles-content {
    font-size: 1.2em;
    text-align: left;
    word-wrap: break-word;
    white-space: pre-wrap;
    /* 高度由父層 #subtitles-container 控制，這裡設為 100% */
    height: 100%;
    max-height: none; /* 移除舊的 max-height */
    overflow-y: auto;
    scroll-behavior: smooth;
}
/* ... (其他如 icon, settings, button 的樣式保持不變) ... */
#icon-container { width: 100px; height: 100px; display: flex; justify-content: center; align-items: center; border-radius: 50%; transition: all 0.3s ease; }
#icon-container.idle { color: var(--primary-color); }
#icon-container.listening { color: var(--listening-color); animation: pulse 1.5s infinite; }
#icon-container.speaking { color: var(--speaking-color); }
@keyframes pulse { 0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); } 70% { transform: scale(1.05); box-shadow: 0 0 0 25px rgba(16, 185, 129, 0); } 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } }
.icon-mic { width: 60px; height: 60px; }
#status-text { color: var(--subtle-text-color); font-size: 1.1em; min-height: 1.5em; transition: color 0.3s ease; }
.settings-container { display: flex; gap: 15px 25px; justify-content: center; width: 100%; flex-wrap: wrap; margin-top: 10px; }
.settings-group { color: var(--subtle-text-color); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.settings-group label { font-size: 0.9em; }
.settings-group select { font-size: 1em; padding: 8px; border-radius: 8px; border: 1px solid #ccc; background-color: #fff; }
#session-button { background-color: var(--primary-color); color: white; border: none; padding: 15px 40px; border-radius: 50px; font-size: 1.2em; font-weight: 600; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; margin-top: 20px; }
#session-button:hover { background-color: #005a9e; }
#session-button:active { transform: scale(0.98); }
#session-button.active { background-color: var(--listening-color); }
.ai-reply { margin: 0 0 1em 0; padding: 0; }
.ai-reply:last-child { margin-bottom: 0; }
.footer-controls { position: fixed; bottom: 20px; right: 20px; z-index: 20; }
#subtitles-toggle { background-color: rgba(255, 255, 255, 0.8); border: 1px solid #ccc; border-radius: 50%; width: 50px; height: 50px; cursor: pointer; display: flex; justify-content: center; align-items: center; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
#subtitles-toggle svg { width: 24px; height: 24px; color: #555; }
#subtitles-toggle.active { background-color: var(--primary-color); }
#subtitles-toggle.active svg { color: #fff; }

@media (max-width: 600px) {
    /* 在手機上，讓主操作區佔據所有剩餘空間，並可以內部滾動 */
    .chat-container {
        flex: 1; /* 關鍵：佔據剩餘的所有空間 */
        margin: 0;
        width: 100%;
        max-width: none;
        border-radius: 0;
        box-shadow: none;
        padding: 20px;
        box-sizing: border-box;
        justify-content: center; /* 讓內容在自己的區域內置中 */
        overflow-y: auto; /* 如果內容太多，可以滾動 */
    }
    
    #icon-container { width: 60px; height: 60px; }
    .icon-mic { width: 36px; height: 36px; }
    
    #subtitles-content {
        font-size: 1.0em;
    }
}