/* ============================================================
   🎨 1. 核心設定與字體 (Core & Fonts)
============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@400;700&display=swap');

:root {
    /* 這裡只保留最基礎的變數，具體數值由 scene1.css 覆蓋 */
    --dialogue-height: 25vh;       
    --dialogue-min-height: 200px;
    --dialogue-bottom: 60px;       
    --text-color: #ffffff;
    --bg-overlay: rgba(20, 15, 15, 0.85);
}

/* 通用隱藏類別 */
.hidden, [hidden] {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: "Shippori Mincho", "Noto Serif TC", serif;
    overflow: hidden;
    background-color: #000;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   🎮 2. 遊戲主畫面
============================================================ */
#game-screen {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-size: cover;
    background-position: center;
}

/* 預設遮罩層 (scene1.css 會用來做雜訊或紋理) */
#game-screen::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 900;
}

/* ============================================================
   bust 3. 立繪層 (Avatars) - 基礎定位
   (具體縮放與濾鏡由 Theme 控制)
============================================================ */
#avatar-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    pointer-events: none; 
}

.avatar {
    position: relative;
    max-height: 100%;
    width: auto;
    transition: all 0.4s ease-out;
}

/* ============================================================
   💬 4. 對話框 (Dialogue Box) - 基礎定位
============================================================ */
#dialogue-box {
    position: absolute;
    left: 50%;
    bottom: var(--dialogue-bottom);
    transform: translateX(-50%);
    
    width: 90%;
    max-width: 90%;
    height: var(--dialogue-height);
    min-height: var(--dialogue-min-height);
    
    z-index: 100;
    display: block;
    
    /* 這裡只留基礎樣式，顏色與邊框交給 Theme */
}

/* 名字牌基礎定位 (Theme 會覆蓋顏色) */
#name-plate {
    position: absolute;
    top: -32px;
    left: 0;
    min-width: 60px;
    text-align: center;
    font-weight: bold;
    z-index: 102;
}

#dialogue-text {
    position: absolute;
    inset: 0;
    padding: 40px 80px 30px 40px; 
    color: var(--text-color);
    font-size: 1.3rem;
    line-height: 1.7;
    overflow: hidden;

    /* ★★★ 新增這兩行 ★★★ */
    white-space: pre-wrap;  /* 關鍵：讓 \n 換行符號生效 */
    word-break: break-word; /* 保險：避免超長英文單字撐開版面 */
}

/* ❌ 已刪除：#back-btn, #log-btn, .menu-controls 的舊設定 */
/* 這些現在全部交由 scene1.css 的 .side-controls 統一管理 */

/* ============================================================
   📱 5. 手機版適配 (RWD) - 基礎調整
============================================================ */
@media (max-width: 768px) {
    :root {
        --dialogue-height: 32vh;
        --dialogue-bottom: 20px;
    }

    #dialogue-box { width: 80%; }

    #dialogue-text {
        font-size: 1rem;
        padding: 30px 20px 10px 20px; 
    }

    #name-plate {
        font-size: 1rem;
        padding: 3px 15px;
        top: -26px;
    }
    
    /* 手機版按鈕位置微調交給 scene1.css 處理 */
}

/* ============================================================
   🗂️ 6. 系統視窗 (Log / Popup)
============================================================ */
#log-window, #popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s;
}

.log-panel, #popup-box {
    width: 80%;
    max-width: 800px;
    height: 70%;
    background: #1a1515;
    border: 1px solid #555;
    padding: 20px;
    color: #fff;
    display: flex;
    flex-direction: column;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

#log-content {
    flex: 1;
    overflow-y: auto;
    line-height: 1.6;
    padding-right: 10px;
}

#log-content::-webkit-scrollbar { width: 6px; }
#log-content::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================================
   🔖 7. Chapter Menu (章節選單)
============================================================ */
#chapter-menu {
    position: fixed;
    inset: 0; 
    background: rgba(0, 0, 0, 0.85); 
    backdrop-filter: blur(5px);
    z-index: 2000;
    
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px; 
    
    opacity: 0;
    pointer-events: none; 
    transition: opacity 0.3s ease;
}

#chapter-menu.active {
    opacity: 1;
    pointer-events: auto;
}

#chapter-menu h2 {
    color: #fff;
    font-size: 2rem;
    margin-bottom: 30px;
    border-bottom: 1px solid #aaa;
    padding-bottom: 10px;
    letter-spacing: 0.2em;
}

.chapter-item {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    padding: 15px 40px;
    font-family: "Shippori Mincho", serif;
    font-size: 1.2rem;
    cursor: pointer;
    width: 300px;
    text-align: center;
    transition: all 0.3s;
    position: relative;
}

.chapter-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
    letter-spacing: 0.1em;
}

#close-chapter-btn {
    margin-top: 40px;
    background: none;
    border: none;
    color: #aaa;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: underline;
}
#close-chapter-btn:hover {
    color: #fff;
}