/* css/game_style.css */

/* =========================================
   1. CORE & LAYOUT (ตั้งค่าพื้นฐาน)
   ========================================= */
:root {
    font-size: clamp(14px, 1.2vw, 40px);
}

body { 
    margin: 0; 
    overflow: hidden; 
    background-color: #000; /* พื้นหลังดำสนิท (AR Style) */
    font-family: 'Arial', sans-serif; 
    font-size: 1rem; 
}

#input_video, #output_canvas { 
    position: absolute; width: 100%; height: 100%; 
    object-fit: cover; 
    z-index: 1; /* วิดีโออยู่ชั้นล่างสุด */
}

/* =========================================
   2. UI LAYER (หน้าจบเกม / Game Over)
   ========================================= */
#ui-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 10;
    
    /* ซ่อนไว้ก่อน เพื่อไม่ให้มีจอดำบังกล้องตอนเริ่ม */
    display: none; 
    
    flex-direction: column; 
    align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.6); 
    backdrop-filter: blur(4px);
}

.login-box {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    padding: 2rem;
    border-radius: 1.5rem;
    text-align: center;
    width: 80%;
    max-width: 40rem;
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.5);
    border: none;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* =========================================
   3. GAME HUD (ส่วนแสดงโจทย์)
   ========================================= */
#game-hud {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 5; 
    display: none; 
    pointer-events: none;
    display: flex; justify-content: center; align-items: flex-start;
    padding-top: 5vh; 
    
    /* บังคับให้ใสแน่นอน เพื่อไม่ให้มีฟิลเตอร์สีตอนเล่น */
    background: transparent !important; 
    backdrop-filter: none !important;
}

.question-popup {
    background: rgba(255, 255, 255, 0.95);
    padding: 1.5rem 2.5rem;
    border-radius: 1.5rem;
    border: 3px solid white;
    text-align: center;
    box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.3);
    animation: slideDown 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-width: 20rem;
    max-width: 90%;
}

.question-popup h2 {
    margin: 0.5rem 0 1rem 0; font-size: 3rem; 
    color: #333; font-weight: 900; line-height: 1.2;
}

.question-popup p {
    margin: 0; font-size: 1.5rem; color: #555; font-weight: bold;
}

.player-badge {
    display: inline-block; background: #ff4081; color: white;
    padding: 0.4rem 1.2rem; border-radius: 3rem; font-size: 1.2rem;
    margin-bottom: 0.5rem; box-shadow: 0 0.2rem 0.5rem rgba(0,0,0,0.2);
}

/* =========================================
   4. JUMP ZONES (โซนคำตอบแบบสี่เหลี่ยมยาว)
   ========================================= */
.jump-zone {
    position: absolute;
    top: 0;
    height: 100%; /* เต็มความสูงจอ */
    
    /* ✅ แก้ไข: ลดความกว้างเหลือ 35% เพื่อเว้นที่ว่างตรงกลาง */
    width: 35%; 
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    font-size: 6rem; 
    font-weight: 900;
    color: white;
    text-shadow: 0 4px 10px rgba(0,0,0,0.8); 
    
    z-index: 2; 
    opacity: 0.6; 
    transition: all 0.2s ease;
    pointer-events: none; 
}

/* โซนซ้าย (สีส้ม) */
.jump-zone.left {
    left: 0;
    background: linear-gradient(to right, rgba(255, 87, 34, 0.7), rgba(255, 87, 34, 0.1));
    border-right: 4px solid rgba(255, 255, 255, 0.5);
}

/* โซนขวา (สีฟ้า) */
.jump-zone.right {
    right: 0;
    background: linear-gradient(to left, rgba(33, 150, 243, 0.7), rgba(33, 150, 243, 0.1));
    border-left: 4px solid rgba(255, 255, 255, 0.5);
}

/* เอฟเฟกต์เมื่อผู้เล่นกระโดดเข้าไป (Active) */
.jump-zone.active {
    opacity: 0.9; 
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 0 60px rgba(255,255,255,0.8);
}

.zone-label {
    padding: 10px 30px;
    background: rgba(0,0,0,0.4);
    border-radius: 50px;
    border: 2px solid rgba(255,255,255,0.5);
}

/* =========================================
   5. TEACHER CONTROL, COUNTDOWN & TIMER
   ========================================= */

/* Modal ทั่วไป (ใช้กับ Player Ready) */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85); /* พื้นหลังทึบขึ้นหน่อย */
    z-index: 20; /* อยู่บนสุด */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ปุ่มเริ่มเกมใน Modal */
.btn-start {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 24px;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Arial', sans-serif;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
    transition: transform 0.2s;
    margin-top: 20px;
}
.btn-start:hover { transform: scale(1.05); }
.btn-start:active { transform: scale(0.95); }

/* หน้าจอนับถอยหลัง (Countdown) */
#countdown-layer {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999; /* อยู่บนสุดจริงๆ */
    display: flex;
    justify-content: center;
    align-items: center;
}

#countdown-number {
    font-size: 15rem; /* ตัวเลขใหญ่ยักษ์ */
    font-weight: 900;
    color: #FFEB3B;
    text-shadow: 0 0 30px rgba(255, 235, 59, 0.8);
    animation: zoomCount 1s infinite;
}

@keyframes zoomCount {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

/* ✅ ตัวจับเวลา (Game Timer) */
#game-timer {
    position: absolute;
    top: 30px;
    right: 30px;
    
    width: 80px;
    height: 80px;
    
    background: rgba(0, 0, 0, 0.6);
    border: 4px solid #fff;
    border-radius: 50%;
    
    color: #fff;
    font-size: 3rem;
    font-weight: bold;
    font-family: 'Arial', sans-serif;
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    z-index: 20; /* อยู่เหนือทุกอย่าง */
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

/* เอฟเฟกต์ตอนเวลาน้อยกว่า 5 วิ (ตัวแดงกระพริบ) */
#game-timer.urgent {
    background: rgba(255, 0, 0, 0.8);
    border-color: #ff5252;
    animation: pulseTimer 0.5s infinite;
}

@keyframes pulseTimer {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* =========================================
   6. MISC (Restart & Loading)
   ========================================= */
#restart-bubble-container {
    position: relative; width: 8rem; height: 8rem; margin: 0 auto;
}
#restart-bubble { font-size: 3rem !important; }

@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slideDown { from { transform: translateY(-5rem); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

#loading-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #000; 
    z-index: 999999;
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    color: white; transition: opacity 0.5s ease;
    font-size: 1.5rem;
}

.spinner {
    width: 4rem; height: 4rem; 
    border: 0.4rem solid rgba(255,255,255,0.2);
    border-top: 0.4rem solid #2196F3; /* สีฟ้า */
    border-radius: 50%;
    animation: spin 1s linear infinite; margin-bottom: 1rem;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }