/* --- 基礎設定 --- */
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #111;
    font-family: "Microsoft JhengHei", "Heiti TC", sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 576px; /* 手機比例限制 */
    margin: 0 auto;
    background-color: #222;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

/* --- 圖層系統 --- */
#bg-layer, #character-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* contain：確保整張圖都顯示，不會被切頭切腳 */
    background-size: contain; 
    /* center bottom：置中靠下，讓腳對齊底部 */
    background-position: center bottom;
    background-repeat: no-repeat;
    transition: background-image 0.2s;
}

#bg-layer { z-index: 1; }
#character-layer { 
    z-index: 5; 
    pointer-events: none; /* 讓點擊穿透到 Hitbox */
}

/* --- Hitbox (感應區) --- */
.hitbox {
    position: absolute;
    z-index: 10;
    cursor: pointer;
    border: none;
    background-color: transparent;
}
.hitbox.completed { display: none; } /* 拔除後消失 */

/* --- UI 元件 --- */
#speech-bubble {
    position: absolute;
    /* 改為置底居中，避開臉部與四肢 */
    top: auto;       
    bottom: 15%;     /* 設定距離底部 15% */
    left: 50%;       
    right: auto;
    transform: translateX(-50%); /* 修正居中偏移 */
    
    background-color: #fff;
    color: #000;
    padding: 15px 25px;
    border-radius: 30px;
    font-weight: bold;
    font-size: 18px;
    max-width: 80%; /* 寬度設寬一點 */
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s; /* 動畫改為 bottom */
    z-index: 20;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    pointer-events: none;
    white-space: pre-wrap;
    border: 3px solid #333;
}

/* 對話框小尾巴：改成在上方，指向五條悟 */
#speech-bubble::after {
    content: '';
    position: absolute;
    top: -10px;    /* 移到泡泡上方 */
    bottom: auto;  
    left: 50%;     
    right: auto; 
    transform: translateX(-50%);
    
    /* 繪製向上指的三角形 */
    border-width: 0 10px 10px 10px;
    border-color: transparent transparent #333 transparent;
}

/* 顯示時稍微往上浮一點 */
#speech-bubble.show { 
    opacity: 1; 
    bottom: 17%; 
}

#timer-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 8px;
    background: linear-gradient(90deg, #ff0055, #ff6b6b);
    width: 100%;
    z-index: 50;
    transition: width 0.1s linear;
}

/* --- 全螢幕遮罩 (Loading / Title / Ending) --- */
#loading-screen, #title-screen, #ending-screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
}

/* 標題畫面 */
#title-img {
    width: 80%;
    max-width: 400px;
    margin-bottom: 50px;
}

/* 按鈕樣式 */
.btn {
    padding: 15px 60px;
    font-size: 22px;
    font-weight: bold;
    background-color: #ff0055;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(255, 0, 85, 0.6);
    transition: transform 0.1s;
}
.btn:active { transform: scale(0.95); }

/* 製作者資訊樣式 */
.credits {
    position: absolute;
    bottom: 30px; 
    width: 100%;
    text-align: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    z-index: 101;
    letter-spacing: 1px;
}

.credits a {
    color: #37fa9f; /* 淺綠色 */
    text-decoration: none;
    font-weight: bold;
    border-bottom: 1px dashed #37fa9f;
}

.credits a:hover {
    color: #fff;
    border-bottom: 1px solid #fff;
}

/* --- 前導劇情 (AVG 風格) --- */
#intro-screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: #000;
    z-index: 90;
    display: flex;
    flex-direction: column;
}

#intro-image {
    width: 100%;
    height: 80%; /* 上 80% */
    background-size: contain; 
    background-position: center;
    background-repeat: no-repeat;
}

#intro-dialog-box {
    width: 100%;
    height: 20%; /* 下 20% */
    background: rgba(0, 0, 0, 0.6); /* 半透明 */
    border-top: 4px solid #ff0055;
    padding: 20px;
    box-sizing: border-box;
    position: relative;
    cursor: pointer;
    text-shadow: 1px 1px 2px black;
    overflow-y: auto; 
}

#intro-text {
    color: #fff;
    font-size: 24px; /* 大字體 */
    line-height: 1.5; 
    white-space: pre-wrap; 
}

.next-indicator {
    position: absolute;
    bottom: 15px;
    right: 20px;
    font-size: 14px;
    color: #ff0055;
    animation: blink 1s infinite;
}

/* --- 結局樣式 (圖文分離) --- */
#ending-screen {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    background-color: #000;
}

#ending-image {
    width: 100%;
    height: 80%; /* 上 80% 放圖 */
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

.ending-content {
    width: 100%;
    height: 20%; /* 下 20% 放字 */
    background: rgba(0, 0, 0, 0.6);
    border-top: 4px solid #ff0055;
    padding: 20px;
    box-sizing: border-box;
    text-align: left;
    position: relative; 
}

#end-desc-box { 
    text-align: left; 
    width: 100%;
    height: 100%;
    overflow-y: auto; 
}

#end-desc { 
    font-size: 22px; /* 大字體 */
    line-height: 1.6; 
    color: #ddd; 
    margin: 0;
}

/* 重新開始按鈕 */
#restart-btn {
    position: absolute;
    bottom: 15px;
    right: 20px;
    padding: 8px 20px;
    font-size: 16px;
    z-index: 10;
}

/* --- 動畫 --- */

@keyframes bounce-squeeze {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    70% { transform: scale(0.9, 1.1); }
    85% { transform: scale(1.05, 0.95); }
    100% { transform: scale(1); opacity: 1; }
}
.bounce-once {
    animation: bounce-squeeze 0.8s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}
.shaking {
    animation: shake 0.5s;
    /* 淺藍色光暈 */
    filter: drop-shadow(0 0 10px #00d2ff) hue-rotate(0deg); 
}

@keyframes blink { 50% { opacity: 0; } }