/* --- 基礎設定 --- */
:root {
    --main-font: 'Freckle Face', 'RocknRoll One', sans-serif;
}

body {
    font-family: var(--main-font);
}

button, input, select, textarea {
    font-family: inherit; 
}

.btn-q {
    font-family: var(--main-font);
}

body, html { 
    margin: 0; padding: 0; width: 100%; height: 100%; 
    overflow: hidden; 
    transition: background-color 2s ease; 
    font-family: 'Freckle Face', 'UoqMunThenKhung', 'Noto Sans TC', sans-serif;
}

.freckle-face-regular {
  font-family: "Freckle Face", system-ui;
  font-weight: 400;
  font-style: normal;
}

.rocknroll-one-regular {
  font-family: "RocknRoll One", sans-serif;
  font-weight: 400;
  font-style: normal;
}

.uoqmunthenkhung-regular {
  font-family: "UoqMunThenKhung", serif;
  font-weight: 400;
  font-style: normal;
}

.noto-sans-tc {
  font-family: "Noto Sans TC", sans-serif;
  font-optical-sizing: auto;
  font-weight: 400;
  font-style: normal;
}

/* --- 畫布層 (底層) --- */
#gameCanvas {
    position: absolute;
    top: 0; left: 0;
    z-index: 5;
    display: block;
}

/* --- 遊戲計分 UI (最頂層) --- */
#ui {
    position: absolute;
    top: 30px; 
    left: 30px;
    z-index: 200; /* 提升層級，確保在 start-screen 之上 */
    font-size: 28px;
    color: #5d4037;
    font-weight: normal;
    letter-spacing: 2px;
    pointer-events: none;
    opacity: 0; /* 初始隱藏，請確保 JS startGame 時有設定 ui.style.opacity = 1 */
    transition: opacity 1s ease; 
}

/* --- 開始畫面容器 --- */
#start-screen {
    position: fixed; 
    top: 0; left: 0; 
    width: 100vw; height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    background-color: rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

#start-bg-decorations {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1;
    pointer-events: none;
}

.start-content-wrapper {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* --- 繞圈 --- */
.vinyl-container {
    position: relative;
    width: 240px;
    height: 240px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.vinyl-container::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    background-color: #222; 
    border-radius: 50%;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
    z-index: 5;
}

#start-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%; 
    box-shadow: 0 0px 15px rgba(62, 62, 62, 0.8);
    animation: spinVinyl 10s linear infinite; 
}

.player-orbit {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 400px;
    height: 400px;
    transform: translate(-50%, -50%);
    z-index: 8;
    pointer-events: none;
    animation: rotateOrbit 10s linear infinite;
}

.orbiting-player {
    position: absolute;
    top: -20px; 
    left: 50%;
    width: 65px;
    transform: translateX(-50%) rotate(90deg); 
    filter: drop-shadow(3px 3px 0px rgba(0,0,0,0.15));
    animation: rotateOrbit 10s linear infinite; 
}

@keyframes spinVinyl {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes rotateOrbit {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* --- 裝飾元素與動畫 --- */
.decor-item {
    position: absolute;
    pointer-events: none;
    z-index: 1;
    filter: drop-shadow(3px 3px 0px rgba(0,0,0,0.08));
    will-change: transform;
}

@keyframes floatingDecor {
    0% { transform: translate(0, 0) rotate(var(--base-rotation)); }
    50% { transform: translate(15px, 10px) rotate(calc(var(--base-rotation) + 5deg)); }
    100% { transform: translate(-10px, 15px) rotate(calc(var(--base-rotation) - 5deg)); }
}

/* --- 標題與按鈕 --- */
.game-title {
    font-size: 4.5rem;
    color: #5d4037;
    margin: 20px 0 10px 0;
    font-weight: 900;
    text-shadow: 4px 4px 0px #fffdf5;
    letter-spacing: 2px;
}

.btn-q {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 160px;
    padding: 15px 40px;
    font-size: 24px;
    font-weight: normal;
    cursor: pointer;
    border-radius: 60px; 
    margin-top: 30px;
    
    background-color: #f6f2e2; 
    color: #8c765c;            
    border: 5px solid #e3dbc3;
    box-shadow: 0 8px 0px #d8d0b5;
    
    transition: all 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    outline: none;
    user-select: none;
}

.btn-q:hover {
    transform: scale(1.05);
    background-color: #fffdf5;
    border-color: #d8d0b5;
}

.btn-q:active {
    transform: translateY(6px) scale(0.98); 
    box-shadow: 0 2px 0px #c7bf9e !important; 
    background-color: #ece6d3;
}

/* --- 遊戲結束層 --- */
#overlay { 
    position: absolute; 
    top: 0; left: 0; 
    width: 100%; height: 100%; 
    display: none; /* JS 控制 flex/none */
    justify-content: center; 
    align-items: center;
    background: rgba(93, 64, 55, 0.3); 
    z-index: 150; 
    backdrop-filter: blur(8px);
}

#overlay-bg-decorations {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1; 
    pointer-events: none;
    overflow: hidden;
    opacity: 0.6;
}

/* --- 卡片主體 --- */
.game-card {
    background-color: #fcfaf2; 
    border: 6px solid #e3dbc3;  
    background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23e8e4d0' fill-opacity='0.4' fill-rule='evenodd'%3E%3Ccircle cx='10' cy='10' r='2'/%3E%3Ccircle cx='30' cy='30' r='2'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 40px 40px;
    border-radius: 40px;      
    padding: 40px 50px;
    position: relative;
    z-index: 10;               /* 確保在裝飾層之上 */
    box-shadow: 0 15px 0px rgba(0, 0, 0, 0.05); /* 卡片下沉陰影 */
    max-width: 450px;
    width: 85%;
    text-align: center;
    
    /* 出現時的彈跳動畫 */
    animation: cardPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.result-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.card-title {
    color: #8c765c;
    margin: 10px 0;
    font-weight: normal;
    line-height: 1.5;
}

.score-board .label {
    color: #a69076;
    font-size: 24px; 
    font-weight: normal;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.score-board .value {
    color: #8c765c;
    font-size: 48px; 
    font-weight: normal;
    line-height: 1;
}

.score-board .value small {
    font-size: 24px;
    margin-left: 4px;
    opacity: 0.8;
}

/* 彈跳動畫定義 */
@keyframes cardPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.result-buttons {
    display: flex;
    gap: 20px; /* 按鈕間距 */
    margin-top: 30px;
}

/* --- 通用置底樣式 --- */
.mobile-br {
    display: none;
}

.game-rule {
    font-family: "RocknRoll One", serif; 
    font-size: 16px;   
    font-weight: normal;
    text-align: center;
    color: #5d4037;  
}

.page-footer {
    position: absolute; 
    bottom: 30px;       
    left: 50%;
    transform: translateX(-50%); /* 水平居中核心 */
    width: 100%;
    text-align: center;
    color: #5d4037;        
    z-index: 160;       
    pointer-events: none;
}

.start-footer {
    font-family: "Noto Sans TC", sans-serif;
    font-size: 14px;
    font-weight: normal;
}

.result-footer {
    font-family: "Noto Sans TC", serif; 
    font-size: 14px;   
    font-weight: normal;
    color: #5d4037;  
}

.footer-link {
    color: #5d4037;        
    text-decoration: none;  
    pointer-events: auto; 
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(93, 64, 55, 0.3);
}

.footer-link:hover {
    opacity: 1;           
    color: #8c765c;        
    border-bottom: 1px solid #8c765c; 
}

/* --- 響應式 --- */
@media (max-width: 600px) {
    .vinyl-container { width: 180px; height: 180px; }
    .player-orbit { width: 245px; height: 245px; }
    .orbiting-player { width: 40px; top: -15px; }
    .game-title { font-size: 2.5rem; }
    #ui { font-size: 20px; top: 20px; left: 20px; }
  
    .game-card {
        width: 76%;           
        padding: 30px 20px;    
        border-width: 4px;     
        border-radius: 30px;   
    }

    .card-title {
        font-size: 22px;       
    }
    
    .score-board .label {
        font-size: 20px;       
    }

    .score-board .value {
        font-size: 38px;    
    }

    .result-buttons {
        flex-direction: column; 
        gap: 18px;        
        margin-top: 20px;
    }

    .btn-q {     
        padding: 12px 0;      
        font-size: 22px;      
        margin-top: 0;         
    }

    html, body, #start-screen {
        height: 100dvh; 
        margin: 0;
        padding: 0;
    }
    .mobile-br {
        display: block; 
    }
    .page-footer {
        bottom: 20px;  
    }
    .start-footer {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); 
        width: 100%;
        left: 50%;
        transform: translateX(-50%);
        font-size: 13px;
        padding: 0 20px;
        box-sizing: border-box;
    }
    .result-footer {
        font-size: 13px;
    }
}