/**
 * =======================================
 * 自訂樣式檔案 - 心理測驗專案
 * v1.6.0 - 主選單優化版
 * * [Gemini 修正版]
 * - 修正了影片與 UI 的 z-index 衝突問題。
 * - 移除了可能導致行動裝置黑屏的 CSS hack。
 * - 完整保留所有原始樣式設定。
 * =======================================
 **/

/**
 * ===========================
 * 基礎設定
 * ===========================
**/
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/**
 * ===========================
 * 主選單背景設定
 * ===========================
**/
main-screen {
    /*
     * ▼▼▼ 【monogatari 改】架構修正 v5.0 (最終架構) ▼▼▼
     *
     * 1. 檔案位置：
     * 封面圖被固定命名為 'main_menu_bg.png'
     * 並固定放置於 /assets/ui/ 資料夾。
     *
     * 2. 控制點：
     * 此 CSS 檔案為「唯一」控制點。
     *
     * 3. AI 工作流程：
     * AI/自動化工具僅需 覆蓋 /assets/ui/main_menu_bg.png 檔案，
     * 無需修改任何程式碼。
     */
    background-image: url('../assets/ui/main_menu_bg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

main-screen main-menu {
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 2;
    
    /* [核心修改] 增加 padding，在容器內部創造 10px 的邊界 */
    padding: 10px; 
    
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* 按鈕依然靠右對齊 */
    
    /* [優化] 使用 box-sizing 確保 padding 不會影響容器的總大小 */
    box-sizing: border-box; 
}

main-screen main-menu button {
    background-color: rgba(0, 0, 0, 0.7) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    margin: 8px 0;
    min-width: 150px;
}

main-screen main-menu button:hover {
    background-color: rgba(0, 0, 0, 0.9) !important;
    color: #ffffff !important;
}

/**
 * ===========================
 * 隱藏不必要的主選單按鈕
 * （互動式影片遊戲專用配置）
 * ===========================
**/

/* 隱藏讀取按鈕 - Quick Menu 已隱藏，玩家無法存檔 */
main-screen main-menu button[data-action="open-screen"][data-open="load"] {
    display: none !important;
}

/* 隱藏存檔按鈕 - 沒有 Quick Menu 入口，此功能無意義 */
main-screen main-menu button[data-action="open-screen"][data-open="save"] {
    display: none !importanT;
}

/* 隱藏畫廊按鈕 - 如果沒有畫廊內容可以隱藏 */
main-screen main-menu button[data-action="open-screen"][data-open="gallery"] {
    display: none !important;
}

/* 隱藏對話紀錄按鈕 - 影片遊戲中此功能較不實用 */
main-screen main-menu button[data-action="open-screen"][data-open="dialog-log"] {
    display: none !important;
}

/**
 * ===========================
 * 動態標題系統
 * ===========================
**/
.dynamic-title-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.dynamic-main-title {
    font-size: 5rem;
    font-weight: 900;
    margin: 0;
    color: #ffffff;
    text-shadow:
        3px 3px 6px rgba(0, 0, 0, 0.8),
        0 0 30px rgba(255, 255, 255, 0.3);
    font-family: 'Microsoft JhengHei', 'PingFang TC', 'Noto Sans TC', sans-serif;
    letter-spacing: 0.1em;
    animation: titleSlideIn 1.2s ease-out;
}

@keyframes titleSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/**
 * ===========================
 * 隱藏 Quick Menu
 * ===========================
**/
quick-menu,
[data-component="quick-menu"] {
    display: none !important;
}

/**
 * ===========================
 * 對話框與選項智能顯示控制（狀態監控版）
 * v1.5.0 - 加入選項保護
 * ===========================
**/

/* 【新增】明確定義 UI 元素的 Z-Index，確保它們在影片之上 */
[data-component="choice-container"],
[data-component="text-box"] {
    z-index: 100;
}

/* 預設隱藏對話框 */
[data-component="text-box"] {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* 當有對話時才顯示 */
[data-component="text-box"]:not([data-speaking=""]) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* 🎯 關鍵：當 body 有 video-playing class 時隱藏對話框 */
body.video-playing [data-component="text-box"] {
    opacity: 0 !important;
    transform: translateY(20px) !important;
    pointer-events: none !important;
}

/* 選項出現時隱藏對話框 */
body:has([data-component="choice-container"] button) [data-component="text-box"] {
    opacity: 0 !important;
    transform: translateY(20px) !important;
    pointer-events: none !important;
}

[data-component="choice-container"]:not(:empty) ~ [data-component="text-box"] {
    opacity: 0 !important;
    transform: translateY(20px) !important;
    pointer-events: none !important;
}

/**
 * ===========================
 * 🔥 影片播放期間禁用選項按鈕
 * ===========================
**/

/* 隱藏選項容器 */
body.video-playing [data-component="choice-container"] {
    opacity: 0 !important;
    transform: translateY(20px) !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transition: opacity 0.3s ease, transform 0.3s ease !important;
}

/* 禁用選項按鈕 */
body.video-playing [data-component="choice-container"] button {
    pointer-events: none !important;
    cursor: not-allowed !important;
    opacity: 0 !important;
}

/* 備用選擇器：直接針對選項按鈕 */
body.video-playing [data-choice] {
    pointer-events: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* 額外保護：禁用所有按鈕互動 */
body.video-playing button[data-do] {
    pointer-events: none !important;
    cursor: default !important;
}

/**
 * ===========================
 * 多選題模組樣式（備用）
 * ===========================
**/
.mc-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    padding: 20px;
    box-sizing: border-box;
}

.mc-container {
    background: white;
    border-radius: 12px;
    padding: clamp(20px, 4vw, 40px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: min(800px, 90vw);
    max-height: min(90vh, 800px);
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

.mc-question {
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    font-weight: bold;
    color: #333;
    margin-bottom: clamp(15px, 3vh, 25px);
    line-height: 1.4;
    word-wrap: break-word;
}

.mc-options-container {
    flex: 1;
    overflow-y: auto;
    margin-bottom: clamp(15px, 3vh, 25px);
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.5vh, 12px);
    padding-right: 5px;
}

.mc-option-wrapper {
    display: flex;
    align-items: center;
    padding: clamp(10px, 2vw, 15px);
    background: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    min-height: 50px;
    box-sizing: border-box;
}

.mc-option-wrapper:hover {
    background: #e9e9e9;
    border-color: #cccccc;
}

.mc-option-wrapper.is-selected {
    background: #4a90e2;
    border-color: #2c5aa0;
}

.mc-option-wrapper.is-selected .mc-option-label {
    color: white;
}

.mc-option-checkbox {
    width: clamp(18px, 3vw, 24px);
    height: clamp(18px, 3vw, 24px);
    cursor: pointer;
    margin-right: clamp(10px, 2vw, 15px);
    flex-shrink: 0;
}

.mc-option-label {
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    color: #333;
    line-height: 1.4;
    word-wrap: break-word;
    flex: 1;
    transition: color 0.3s ease;
}

.mc-submit-button {
    background: #28a745;
    color: white;
    border: none;
    padding: clamp(10px, 2vw, 15px) clamp(20px, 4vw, 30px);
    border-radius: 6px;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.mc-submit-button:hover {
    background: #218838;
    transform: translateY(-2px);
}

/**
 * ===========================
 * 響應式設計
 * ===========================
**/
@media screen and (max-width: 768px) {
    .dynamic-main-title {
        font-size: 3.5rem;
    }
}

@media screen and (max-width: 480px) {
    .dynamic-main-title {
        font-size: 2.5rem;
    }
}

/**
 * ===========================
 * iOS Safari 影片播放修復
 * ===========================
**/

/* 強制內嵌播放 */
video {
    /* 【關鍵修改】移除以下三行，它們是 Android 黑屏的主要嫌疑犯 */
    /*
    -webkit-transform: translateZ(0) !important;
    -webkit-backface-visibility: hidden !important;
    -webkit-perspective: 1000 !important;
    */
    object-fit: contain !important;
}

/* 確保影片容器正確 */
[data-ui="video"],
[data-component="video-layer"] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    /* 【關鍵修改】z-index 從 9999 改為 10，確保在 UI 之下 */
    z-index: 10 !important;
}

/* iOS 特定修復 */
@supports (-webkit-touch-callout: none) {
    video {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }
}

/**
 * ===========================
 * 版本資訊
 * * v1.6.0 - 2025-10-20
 * - ✅ 隱藏不必要的主選單按鈕（讀取、存檔、畫廊、對話紀錄）
 * - ✅ 優化按鈕間距和樣式
 * - ✅ 保留核心功能：開始、設定、製作人員、幫助
 * * v1.5.0 - 2025-10-20
 * - ✅ 加入選項按鈕的完整隱藏保護
 * - ✅ 防止影片播放期間點擊選項
 * - ✅ 多重選擇器確保跨瀏覽器兼容
 * * v1.4.0 - 2025-10-14
 * - ✅ 改用 JavaScript 狀態監控（video-playing class）
 * - ✅ 精確控制對話框顯示時機
 * - ✅ 移除不可靠的 CSS :has() 選擇器
 * ===========================
**/