/* =========================================
   1. 基礎與場景設定 (終極背景防爆版)
   ========================================= */
body, html { 
    margin: 0; 
    padding: 0; 
    width: 100%; 
    min-height: 100vh; 
    font-family: "Microsoft JhengHei", sans-serif; 
    background-color: #2c1e16; 
    background-image: url('../assets/images/bg_table.jpg'); 
    background-size: cover; 
    background-position: center; 
    background-attachment: fixed; 
    background-repeat: no-repeat;
}

#game-container { 
    width: 100%; 
    min-height: 100vh; 
    background: transparent !important; 
    overflow-x: hidden; 
    position: relative; 
}

.hidden { display: none !important; }
.scene { display: none; width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
.scene.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }
#game-board { width: 100%; height: 100%; position: relative; }

/* =========================================
   2. 登入與選單 UI
   ========================================= */
.game-title { text-shadow: 2px 2px 5px rgba(0,0,0,0.5); }
#login-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; gap: 15px; margin-top: 50px; position: relative; z-index: 100; 
}
#login-btn img {
    width: 250px !important; height: 250px !important; object-fit: contain;
    transition: transform 0.2s; filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.4));
}
#login-btn:hover img { transform: scale(1.1); }

.welcome-box { 
    background: rgba(255, 255, 255, 0.8); padding: 20px; border-radius: 15px; 
    text-align: center; position: relative; z-index: 100; 
}
.start-btn { 
    padding: 12px 30px; font-size: 1.2rem; background: #ffd700; border: none; 
    border-radius: 25px; cursor: pointer; font-weight: bold; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); transition: transform 0.2s; 
    position: relative; z-index: 110; 
}
.start-btn:hover { transform: scale(1.05); }

/* =========================================
   3. 牌桌與區域劃分
   ========================================= */
#table-center { 
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); 
    width: 580px; height: 150px; display: flex; align-items: center; 
    justify-content: space-between; z-index: 50; 
}
/* 💡 修正：強制蓋牌堆顯示實體背景，並解除 3D 翻轉的影響 */
#draw-pile {
    position: relative;
    background-color: #fff !important;
    background-image: url('../assets/images/card_back.png') !important;
    background-size: 100% 100% !important;
    border: 1px solid #ccc !important;
    transform: none !important; /* 解除 3D 旋轉 */
    box-shadow: 2px 2px 0px #bbb, 4px 4px 0px #999, 6px 6px 10px rgba(0,0,0,0.6);
}
#table-open-cards {
    display: flex; flex-wrap: wrap; gap: 15px; max-width: 600px; 
    min-height: 120px; justify-content: center; align-items: center;
    perspective: 1000px; /* 3D 攝影機深度 */
}
#player-hand-container {
    position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; z-index: 110;
}
#player-hand { 
    display: flex; justify-content: center; min-width: 400px; height: 120px; 
    perspective: 1000px; /* 3D 攝影機深度 */
}

/* =========================================
   4. ✨ 核心：3D 撲克牌系統 (已合併舊版衝突)
   ========================================= */
.card { 
    width: 80px; height: 110px; flex-shrink: 0; position: absolute; z-index: 100;
    /* 3D 翻轉核心 */
    transform-style: preserve-3d;
    transform: rotateY(180deg); /* 預設為背面 */
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    background-color: transparent !important; 
    border: none !important;
}
.card.is-flipped { transform: rotateY(0deg); }

/* 取消原本的絕對定位，讓卡片排版恢復正常 */
.table-card { position: relative !important; top: auto !important; left: auto !important; }
.player-card { position: relative !important; margin: 0 -15px; cursor: pointer; }
.player-card:hover { transform: translateY(-20px); z-index: 200; }

/* 3D 正反兩面容器 */
.card-inner-face {
    position: absolute; width: 100%; height: 100%; backface-visibility: hidden; 
    border-radius: 8px; box-sizing: border-box; box-shadow: 0 4px 10px rgba(0,0,0,0.5); 
    border: 1px solid #ccc;
}
/* 背面 */
.card-inner-back {
    background-image: url('../assets/images/card_back.png'); background-size: 100% 100%;
    transform: rotateY(180deg); 
}
/* 正面印刷 */
.card-inner-front {
    background-color: #fff; padding: 6px; display: flex; flex-direction: column; 
    justify-content: space-between; font-weight: 900; font-family: Arial, sans-serif;
}
.card-top-left { text-align: left; line-height: 1.1; font-size: 1.2rem; }
.card-bottom-right { text-align: right; line-height: 1.1; font-size: 1.2rem; transform: rotate(180deg); }

/* =========================================
   5. AI 與戰利品區
   ========================================= */
.ai-area { position: absolute; width: 120px; text-align: center; color: white; text-shadow: 1px 1px 3px #000; }
.ai-area img { width: 70px; height: 70px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 10px rgba(0,0,0,0.5); }
.ai-area.top { top: 20px; left: 50%; transform: translateX(-50%); }
.ai-area.left { left: 20px; top: 35%; }
.ai-area.right { right: 20px; top: 35%; }

.captured-pool { position: absolute; width: 45px; height: 62px; z-index: 60; }
#pool-ai_hard { top: 110px; left: calc(50% + 60px); } 
#pool-ai_easy { left: 110px; top: 40%; }
#pool-ai_mid  { right: 110px; top: 40%; }
#pool-player  { left: calc(50% + 220px); bottom: 30px; }

.captured-card {
    width: 45px !important; height: 62px !important; position: absolute !important; 
    margin: 0 !important; transform: none !important; 
}
.captured-card .card-top-left, .captured-card .card-bottom-right {
    font-size: 11px !important; line-height: 1 !important;
}

/* =========================================
   6. 排行榜與結算畫面
   ========================================= */
.result-box { 
    background: rgba(0, 0, 0, 0.85); padding: 30px; border-radius: 20px; 
    border: 3px solid #ffd700; color: white; text-align: center; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.8); width: 80%; max-width: 450px; 
}
#score-table { width: 100%; margin: 20px 0; border-collapse: collapse; }
#score-table th, #score-table td { padding: 12px; border-bottom: 1px solid #444; font-size: 1.1rem; color: #ffffff !important; }
#score-table th { background-color: #ffd700; color: #333333 !important; border-radius: 4px; }
#score-table tr.my-rank-row td { color: #333333 !important; }
.rank-1 { color: #ffd700; font-weight: bold; font-size: 1.3rem; }

.leaderboard-tabs { display: flex; justify-content: center; gap: 10px; margin-top: 10px; margin-bottom: 5px; }
.tab-btn { 
    padding: 6px 12px; border: 2px solid #f39c12; border-radius: 20px; background: transparent; 
    color: #f39c12; font-weight: bold; font-size: 0.9rem; cursor: pointer; transition: all 0.2s ease; 
}
.tab-btn.active { background: #f39c12; color: #fff !important; box-shadow: 0 3px 6px rgba(243, 156, 18, 0.4); }

/* =========================================
   7. 🎯 遊戲特效 (呼吸燈與過場)
   ========================================= */
#transition-layer { position: fixed; top: 0; left: -100%; width: 100%; height: 100%; z-index: 9999; pointer-events: none; }
#swipe-paw { width: 100%; height: 100%; object-fit: contain; }

@keyframes avatar-glow {
    0% { box-shadow: 0 0 5px #f1c40f, 0 0 10px #f39c12; transform: scale(1); }
    50% { box-shadow: 0 0 20px #f1c40f, 0 0 30px #e67e22; transform: scale(1.15); }
    100% { box-shadow: 0 0 5px #f1c40f, 0 0 10px #f39c12; transform: scale(1); }
}
.ai-area img.active-turn { border-color: #f1c40f !important; animation: avatar-glow 1.5s infinite ease-in-out; z-index: 150; position: relative; }

@keyframes player-glow {
    0% { filter: drop-shadow(0 0 2px #f1c40f); }
    50% { filter: drop-shadow(0 0 15px #f39c12); }
    100% { filter: drop-shadow(0 0 2px #f1c40f); }
}
#player-hand.active-turn { animation: player-glow 1.5s infinite ease-in-out; }

/* =========================================
   8. 🚫 廣告防爆與自動遮罩阻擋 (修正版)
   ========================================= */
.google-auto-placed, .adsbygoogle-noablate { display: none !important; }
.ad-container { 
    width: 100%; 
    max-width: 728px; 
    /* 💡 修正：使用絕對定位釘在最底下，這樣就不會把選單往上擠了！ */
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    text-align: center; 
    min-height: 100px; 
    max-height: 100px; 
    overflow: hidden; 
    z-index: 50;
}

/* =========================================
   9. 📱 手機版 RWD 響應式
   ========================================= */
@media (max-width: 768px) {
    #login-btn img { width: 150px !important; height: 150px !important; }
    
    .card { width: 42px !important; height: 60px !important; border-radius: 4px !important; }
    .card-top-left, .card-bottom-right { font-size: 10px !important; line-height: 1.0 !important; }
    .card-inner-front { padding: 2px !important; }
    
    #table-center { width: 100% !important; flex-direction: column !important; gap: 10px; top: 45% !important; }
    #table-open-cards { width: 100% !important; gap: 4px !important; }
    
    .ai-area { width: 60px; z-index: 70; }
    .ai-area img { width: 45px; height: 45px; }
    
    #pool-ai_hard { top: 85px !important; left: calc(50% + 35px) !important; transform: none !important; } 
    #pool-ai_easy { left: 15px !important; top: calc(50% + 45px) !important; transform: none !important; }
    #pool-ai_mid  { right: 15px !important; top: calc(50% + 45px) !important; transform: none !important; }
    
    .captured-card { width: 30px !important; height: 42px !important; }
    .captured-card .card-top-left, .captured-card .card-bottom-right { font-size: 8px !important; }
    
    #player-hand-container { bottom: 110px !important; width: 100vw; }
    #player-hand { min-width: 100%; height: 60px; }
    .player-card { margin: 0 -6px; }
    #pool-player { right: auto !important; left: 25px !important; bottom: 190px !important; }
}