/**
 * =======================================
 * 自訂樣式檔案 - 心理測驗專案
 * v1.7.0 - 參考 v4.2.0 優化版
 * 
 * 此檔案合併了自訂實作和Monogatari範本結構
 * 基礎設定參考 v4.2.0 的成功經驗
 * =======================================
 **/

/**
 * ===========================
 * Foundational Styling
 * ===========================
**/
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    /* 確保字體設定 */
    font-family: 'Microsoft JhengHei', 'PingFang TC', 'Noto Sans TC', sans-serif;
}

/**
 * ===========================
 * General Styling
 * ===========================
**/
main-screen {
    /* 確保使用正確的 assets/ui 路徑 */
    background-image: url('../assets/ui/main_menu_bg.webp');
    /* [User Request] "Responsive" 模式：使用 cover 填滿視窗 */
    background-size: cover;
    background-position: center center;
    width: 100vw;
    height: 100vh;
    background-repeat: no-repeat;
    background-color: #000;
    /* 黑邊補底 */
}

/* [User Request] 場景圖也強制拉伸填滿 */
[data-ui="background"] {
    /* [User Request] "Responsive" 模式：使用 cover 填滿視窗，保持比例但會裁切兩側 */
    background-size: cover !important;
    background-position: center center !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    background-color: #000;
    width: 100vw;
    height: 100vh;
}

main-screen main-menu {
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 2;
    padding: 10px;
    /* 保留一點 padding 避免貼死邊緣 */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    box-sizing: border-box;
}

@media screen and (orientation: portrait) {
    main-screen main-menu {
        width: 100%;
        align-items: center;
        bottom: 5vh;
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
}

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

main-screen main-menu button:hover {
    background-color: rgba(0, 0, 0, 0.9) !important;
    opacity: 1 !important;
    color: #ffffff !important;
    transform: translateX(-5px);
    /* 微小動畫回饋 */
}

/* 隱藏不必要的按鈕 (依據需求) */
main-screen main-menu button[data-action="open-screen"][data-open="load"],
main-screen main-menu button[data-action="open-screen"][data-open="save"],
main-screen main-menu button[data-action="open-screen"][data-open="gallery"],
main-screen main-menu button[data-action="open-screen"][data-open="dialog-log"] {
    display: none !important;
}


/**
 * ===========================
 * Game Elements Styling
 * ===========================
**/

/* 對話框樣式優化 */
[data-component="text-box"] {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    /* 🔥 [Mobile Fix] LINE/Facebook 瀏覽器底部安全區域避讓 */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/**
 * ===========================
 * Quick Menu Styling
 * ===========================
**/
/* 隱藏 Quick Menu (依據先前需求) */
quick-menu,
[data-component="quick-menu"] {
    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);
    pointer-events: none;
    /* 避免擋住點擊 */
}

.dynamic-main-title {
    font-size: 5rem;
    font-weight: 900;
    margin: 0;
    max-width: 90vw;
    /* Prevent overflow on small screens */
    word-wrap: break-word;
    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);
    }
}

/**
 * ===========================
 * 響應式設計
 * ===========================
**/
@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;
    }

    main-screen main-menu button {
        min-width: 120px;
        font-size: 0.9rem;
    }
}

/**
 * ===========================
 * Dashboard 樣式覆蓋 (確保正確顯示)
 * ===========================
**/
/* Dashboard styles are now handled in js/dashboard.js */

/**
 * ===========================
 * Ending Screen Styling (Settlement)
 * ===========================
**/
.ending-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    /* Above everything */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    /* Ensure no scroll on body when this is open */
}

.ending-screen.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.ending-screen__background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: -1;
}

.ending-screen__card {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 450px;
    /* Flexible height, but try to fit in viewport */
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    position: relative;
    overflow: hidden;
    animation: slideUp 0.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Image Container: Square and Flexible */
.ending-screen__image-container {
    /* Driven by Height to ensure it fits vertically */
    height: 38vh;
    /* Enforce Square */
    aspect-ratio: 1 / 1;
    /* Width will be calculated from height (38vh) */
    width: auto;

    /* Safety: Never exceed container width */
    max-width: 100%;

    /* Center in the flex column (prevent stretch) */
    align-self: center;
    margin: 0 auto;
    flex-shrink: 1;
    /* Allow shrinking if needed */
    background-color: #000;
}

.ending-screen__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    transition: transform 0.5s ease;
}

.ending-screen__content-container {
    padding: 15px;
    /* Reduced from 20px */
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 1;
    justify-content: center;
    /* Center content vertically */
    gap: 5px;
    /* Use gap for consistent spacing */
    overflow-y: hidden;
    /* Strict no scroll */
}

.ending-screen__title {
    margin: 0;
    font-size: 1.4rem;
    color: #5bff5b;
    text-shadow: 0 0 10px rgba(91, 255, 91, 0.3);
    font-weight: bold;
    flex-shrink: 0;
}

/* Score Display Style */
.ending-screen__score {
    font-size: 2.8rem;
    font-weight: 800;
    color: #ffd700;
    text-shadow: 0 2px 10px rgba(255, 215, 0, 0.4);
    margin: 0;
    font-family: 'Helvetica Neue', 'Arial', sans-serif;
    letter-spacing: 1px;
    line-height: 1.2;
    flex-shrink: 0;
}

.ending-screen__quote {
    color: rgba(255, 255, 255, 0.8);
    font-style: italic;
    margin: 5px 0 10px 0;
    line-height: 1.3;
    font-size: 0.85rem;
    max-width: 95%;
}

.ending-screen__buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 5px;
    flex-shrink: 0;
}

.ending-screen__icon-button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    outline: none;
}

.ending-screen__icon-button:hover {
    background: white;
    color: black;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.2);
}

.ending-screen__icon-button svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}