/* SPACE QUIZ GAME - IDEAL HEIGHT LAYOUT */
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #000; font-family: 'Arial', sans-serif; color: white; user-select: none; touch-action: none; -webkit-tap-highlight-color: transparent; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 500; }
.hidden { display: none !important; }

/* MULTI-LAYER BACKGROUND (PARALLAX) WITH GPU ACCELERATION */
.bg-layer { 
    position: fixed; 
    inset: 0; 
    background-repeat: repeat-x; 
    background-size: auto 100%; 
    will-change: background-position; 
    transform: translateZ(0); 
    contain: strict; 
    animation-play-state: paused;
}
#bg-layer-sky { 
    z-index: 1; 
    background-image: url("/games/quiz-space/images/shared-0-sheet4.webp"); 
    animation: scroll-sky 150s linear infinite;
}
#bg-layer-mid { 
    z-index: 2; 
    background-image: url("/games/quiz-space/images/tiledbackground2-sheet0.webp"); 
    height: 65%; 
    top: auto; 
    bottom: 25%; 
    background-size: auto 100%; 
    animation: scroll-mid 80s linear infinite;
}
#bg-layer-ground { 
    z-index: 4; 
    background-image: url("/games/quiz-space/images/tiledbackground-sheet0.webp"); 
    height: 45%; 
    top: auto; 
    bottom: 0; 
    background-size: auto 100%; 
    animation: scroll-ground 40s linear infinite;
}

@keyframes scroll-sky {
    from { background-position: 0px 0px; }
    to { background-position: -2000px 0px; }
}
@keyframes scroll-mid {
    from { background-position: 0px 0px; }
    to { background-position: -3000px 0px; }
}
@keyframes scroll-ground {
    from { background-position: 0px 0px; }
    to { background-position: -4000px 0px; }
}

@media screen and (max-height: 500px) {
    #bg-layer-sky { animation-duration: 250s; }
    #bg-layer-mid { animation-duration: 130s; }
    #bg-layer-ground { animation-duration: 70s; }
}

#planes-decor-layer { position: fixed; inset: 0; z-index: 3; pointer-events: none; }

/* START SCREEN AREA */
#start-screen { z-index: 600; background: rgba(0,0,0,0.05); }

.logo-area {
    display: flex; 
    align-items: center; 
    justify-content: center;
    gap: 40px; 
    margin-top: -260px; 
    z-index: 10;
}
.fly-robot { 
    width: 300px; 
    height: 90px; 
    background-repeat: no-repeat; 
    transform: scaleX(-1) scale(1.1); }
.logo-start { 
    max-width: 600px; 
}

.btn-start-game-custom { 
    position: absolute; 
    bottom: 23px; 
    left: 50%; transform: translateX(-50%);
    width: 300px; 
    height: 65px;
    background-image: url("/games/quiz-space/images/update/btn_text.png");
    background-size: 100% 100%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s; z-index: 20;
    font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.start-robot-row { 
    display: flex; 
    align-items: flex-end; 
    position: absolute; 
    bottom: 18%; 
    z-index: 5; 
    transform: scale(1);
}
.start-robot-row > div { /* Xóa transform cũ vì đã xử lý trong JS */ }

/* HUD & GAME STAGE */
#game-stage { display: none; position: relative; width: 100vw; height: 100vh; }
#robot { position: fixed; bottom: 140px; left: 20px; z-index: 100; background-repeat: no-repeat; will-change: transform; transform: translateZ(0); contain: layout; }
#enemy { 
    position: fixed; 
    bottom: 140px; 
    right: 20px; 
    z-index: 100; 
    background-repeat: no-repeat; 
    will-change: transform;
    transform: translateZ(0);
    contain: layout;
}
#clock-container { 
    position: fixed; 
    top: 220px; 
    left: 60px; 
    width: 150px; 
    height: 150px; 
    background-image: url("/games/quiz-space/images/update/clock.png"); 
    background-size: 100% 100%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 3; 
}
#timer-text { font-size: 26px; font-weight: 900; color: #E65100; margin-top: 3px; }

#question-container { 
    position: fixed; 
    top: 100px; 
    left: 50%; 
    transform: translateX(-50%); 
    width: 1000px; 
    height: 300px; 
    background-image: url("/games/quiz-space/images/update/background_content_question.png"); 
    background-size: 100% 100%; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    padding: 20px 50px; 
    box-sizing: border-box; 
    z-index: 200; 
}
#q-text { font-size: 18px; font-weight: bold; text-align: center; line-height: 1.4; color: #E65100; }
.answers-grid { 
    position: fixed; 
    top: 415px; 
    left: 50%; 
    transform: translateX(-50%); 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 15px; 
    z-index: 300; 
}
.answer-item { 
    width: 430px; 
    height: 90px; 
    background-image: url("/games/quiz-space/images/update/background_answer.png"); 
    background-size: 100% 100%; 
    display: flex; 
    flex-direction: column;
    align-items: center; 
    justify-content: center; 
    cursor: pointer; 
    transition: transform 0.15s; /* Chỉ animate transform, không animate tất cả */
    font-size: 16px;
    font-weight: bold; 
    padding: 5px 30px; 
    text-align: center; 
    color: #000;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    contain: layout style; /* Giảm scope reflow */
}

/* Các thành phần khác giữ nguyên */
.hud-top-left { position: fixed; top: 15px; left: 15px; display: flex; align-items: center; gap: 10px; z-index: 300; }
.hud-avatar-box, .hud-info-item { position: relative; display: flex; align-items: center; }
.hud-box-bg { height: 75px; width: auto; display: block; }
.hud-info-item .hud-box-bg { height: 55px; }

.hud-avatar-inner { 
    position: absolute; 
    inset: 0; 
    display: flex; 
    align-items: center; 
    padding-left: 8px; 
}
.hud-avatar-img { 
    width: 60px; 
    height: 60px; 
    background-repeat: no-repeat; 
    background-position: center; 
    background-size: contain;
    flex-shrink: 0;
    transform: scale(1.13);
    margin-left: -5px;
}
.hud-hearts { display: flex; align-items: center; flex-shrink: 0; margin-left: -5px; }
.heart-status-img { 
    margin-left: 20px;
    height: 22px; 
    object-fit: contain; 
}

.hud-info-text { 
    position: absolute;
    inset: 0;
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 18px; 
    font-weight: 900; 
    color: #E65100; 
    padding: 3px 15px 0 15px;
    box-sizing: border-box;
}
.top-right-btns { position: absolute; top: 15px; right: 15px; display: flex; gap: 10px; z-index: 1000; }
.btn-mini { 
    width: 50px; 
    height: 50px; 
    cursor: pointer; 
    transition: 0.2s; 
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

#sound-btn.unmuted { background-image: url("/games/quiz-space/images/update/btn_unmute.png"); }
#sound-btn.unmuted:hover { background-image: url("/games/quiz-space/images/update/btn_unmute_hover.png"); }
#sound-btn.muted { background-image: url("/games/quiz-space/images/update/btn_mute.png"); }
#sound-btn.muted:hover { background-image: url("/games/quiz-space/images/update/btn_mute_hover.png"); }

#fs-btn.off { background-image: url("/games/quiz-space/images/update/btn_fullscreen.png"); }
#fs-btn.off:hover { background-image: url("/games/quiz-space/images/update/btn_fullscreen_hover.png"); }
#fs-btn.on { background-image: url("/games/quiz-space/images/update/btn_unfullscreen.png"); }
#fs-btn.on:hover { background-image: url("/games/quiz-space/images/update/btn_unfullscreen_hover.png"); }

/* LOADING & ORIENTATION & SELECTION */
#loading-screen { background: #000; z-index: 2000; }
.loading-logo { max-width: 250px; margin-bottom: 20px; }
.progress-container { width: 250px; height: 8px; background: #222; border-radius: 5px; overflow: hidden; }
.progress-bar { width: 0%; height: 100%; background: #00d2ff; }
#touch-screen { background: #000; z-index: 1500; cursor: pointer; }
.touch-text { font-size: 32px; font-weight: 900; letter-spacing: 5px; animation: blink 1.5s infinite; }
#orientation-overlay { background: #000; z-index: 3000; display: none; text-align: center; }
.rotate-icon { width: 120px; margin-bottom: 20px; animation: rotate90 2s infinite; }
#selection-screen { z-index: 700; justify-content: flex-start; padding-top: 30px; }
.hero-selection-container { 
    position: relative; 
    width: 1000px; 
    height: 455px; 
    background-image: url("/games/quiz-space/images/update/background_select_avatar_hero.png"); 
    background-size: 100% 100%; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    padding: 40px; 
    box-sizing: border-box;
}
.hero-selection-container h1 { 
    position: absolute; top: 16px; left: 50%; transform: translateX(-50%); margin: 0; color: #fff; font-size: 18px; font-weight: 900; }
.hero-grid { 
    display: grid; 
    grid-template-columns: 
    repeat(5, 1fr); 
    /* gap: 10px;     */
    height: 80%; 
}
.hero-card { 
    position: relative; 
    width: 170px; 
    height: 170px; 
    background: rgba(255,255,255,0.05); 
    border-radius: 10px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}
.hero-card .active-overlay { 
    position: absolute; 
    inset: 0; 
    background-image: url("/games/quiz-space/images/update/select-avatar-hero.png"); 
    background-size: 100% 100%;
    background-repeat: no-repeat; /* Không lặp lại hình ảnh */
    background-position: center;
    
    z-index: 5; 
    display: none; 
}
.hero-card.active .active-overlay { display: block; }
.hero-avatar { width: 70px; height: 70px; z-index: 2; background-repeat: no-repeat; }
#hero-preview { 
    position: fixed; 
    bottom: 140px; 
    left: 20px; 
    width: 160px; 
    height: 130px; 
    background-repeat: no-repeat; 
    z-index: 800; 
}
.btn-play-custom { position: absolute; bottom: -30px; left: 50%; transform: translateX(-50%); width: 170px; height: 65px; background-image: url("/games/quiz-space/images/update/btn_text.png"); background-size: 100% 100%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; z-index: 20; font-size: 22px; font-weight: 900; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }

/* NEW ANIMATIONS & FEEDBACK */
@keyframes blink-correct {
    0%, 100% { background-image: url("/games/quiz-space/images/update/background_answer_true.png"); }
    50% { background-image: url("/games/quiz-space/images/update/background_answer.png"); }
}
@keyframes blink-wrong {
    0%, 100% { background-image: url("/games/quiz-space/images/update/background_answer_false.png"); }
    50% { background-image: url("/games/quiz-space/images/update/background_answer.png"); }
}

.answer-item.correct-blink { animation: blink-correct 0.3s infinite; }
.answer-item.wrong-blink { animation: blink-wrong 0.3s infinite; }
.answer-item.correct-highlight { background-image: url("/games/quiz-space/images/update/background_answer_true.png") !important; }

.ui-hidden { opacity: 0; pointer-events: none; }

/* ENDGAME OVERLAY */
#endgame-overlay, #leaderboard-overlay { background: rgba(0,0,0,0.6); }

.endgame-panel, .leaderboard-panel {
    position: relative;
    width: 750px;
    max-width: 95vw;
    background-image: url("/games/quiz-space/images/update/bg_endgame.png");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    padding: 60px 50px 40px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: zoomInEndgame 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes zoomInEndgame {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

.endgame-title, .leaderboard-title {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 22px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    white-space: nowrap;
    z-index: 5;
}

.endgame-stats {
    display: flex;
    gap: 25px;
    justify-content: center;
    margin: 20px 0;
}

.endgame-stat-card {
    width: 180px;
    height: 170px;
    background-image: url("/games/quiz-space/images/update/card-1.png");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    box-sizing: border-box;
}
.endgame-stat-value {
    font-size: 36px;
    font-weight: 900;
    color: #E65100;
    margin-bottom: 30px;
}
.endgame-stat-label {
    font-size: 14px;
    font-weight: 700;
    color: #fff;   
}

.endgame-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;   
    margin-bottom: -55px;
}

.endgame-btn {
    width: 100px;
    height: 100px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    cursor: pointer;
    transition: transform 0.2s;
}
.endgame-btn:hover { transform: scale(1.1); }
.endgame-btn:active { transform: scale(0.95); }

#btn-replay { background-image: url("/games/quiz-space/images/update/btn_replay_hover.png"); }
#btn-replay:hover { background-image: url("/games/quiz-space/images/update/btn_replay.png"); }
#btn-rank { background-image: url("/games/quiz-space/images/update/btn_rank_hover.png"); }
#btn-rank:hover { background-image: url("/games/quiz-space/images/update/btn_rank.png"); }
#btn-home { background-image: url("/games/quiz-space/images/update/btn_home_hover.png"); }
#btn-home:hover { background-image: url("/games/quiz-space/images/update/btn_home.png"); }
#btn-back-endgame { background-image: url("/games/quiz-space/images/update/btn_home_hover.png"); }
#btn-back-endgame:hover { background-image: url("/games/quiz-space/images/update/btn_home.png"); }

/* LEADERBOARD */
.leaderboard-list {
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
    padding: 5px 10px;
    box-sizing: border-box;
}
.leaderboard-list::-webkit-scrollbar { width: 6px; }
.leaderboard-list::-webkit-scrollbar-thumb { background: #E65100; border-radius: 10px; }

.lb-row {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    border-radius: 12px;
    margin-bottom: 6px;
    background: rgba(230, 81, 0, 0.08);
    transition: background 0.2s;
}
.lb-row:hover { background: rgba(230, 81, 0, 0.15); }
.lb-row.lb-me { background: rgba(255, 165, 0, 0.2); border: 1px solid #E65100; }

.lb-rank {
    width: 35px;
    height: 35px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 16px;
    color: #8B4513;
    background: rgba(230, 81, 0, 0.1);
    flex-shrink: 0;
}
.lb-row:nth-child(1) .lb-rank { background: linear-gradient(135deg, #f3d45a, #d4af37); color: #000; }
.lb-row:nth-child(2) .lb-rank { background: linear-gradient(135deg, #c0c0c0, #a0a0a0); color: #000; }
.lb-row:nth-child(3) .lb-rank { background: linear-gradient(135deg, #cd7f32, #a0522d); color: #fff; }

.lb-name {
    flex: 1;
    margin-left: 12px;
    font-size: 15px;
    font-weight: 700;
    color: #5D3510;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lb-score {
    font-size: 18px;
    font-weight: 900;
    color: #E65100;
}

/* MOBILE RESPONSIVE - LANDSCAPE */
@media screen and (max-height: 500px) {
    /* START SCREEN */
    .logo-start { max-width: 400px; }
    .logo-area { margin-top: -160px; gap: 20px; }
    .fly-robot { width: 180px; height: 55px; transform: translateY(-80px) scaleX(-1) scale(1.1); }
    .start-robot-row { bottom: 23%; }
    
    /* SELECTION SCREEN */
    #selection-screen { padding-top: 10px; }
    .hero-selection-container { 
        width: 560px; 
        height: 260px; 
        padding: 20px; 
    }
    .hero-selection-container h1 { 
        top: 7px; 
        font-size: 16px; 
    }
    .hero-grid { gap: 5px; }
    .hero-card { width: 90px; height: 90px; }
    .hero-avatar { width: 42px; height: 42px; }
    #hero-preview { 
        position: absolute; 
        bottom: 90px; 
        left: 0px; 
        width: 150px; 
        height: 120px; 
        z-index: 800;
    }
    .btn-play-custom { 
        width: 150px; 
        height: 40px; 
        font-size: 18px; 
        bottom: -17px; 
    }

    /* GAME STAGE */
    #question-container { 
        top: 55px; 
        width: 530px; 
        height: 180px; 
        padding: 10px 30px; 
    }
    #q-text { font-size: 12px; }
    #q-image { max-height: 40px; }
    
    .answers-grid { top: 240px; gap: 8px; }
    .answer-item { 
        width: 220px; 
        height: 45px; 
        font-size: 9px; 
        padding: 5px 20px; 
    }
    
    #clock-container { 
        top: 150px; 
        left: 75px; 
        width: 70px; 
        height: 70px; 
    }
    #timer-text { font-size: 16px; }
    
    #robot { left: 0px; bottom: 85px; }
    #enemy { right: 0px; bottom: 85px; }
    
    /* HUD */
    .hud-box-bg { height: 40px; }
    .hud-info-item .hud-box-bg { height: 32px; }
    .hud-avatar-box { gap: 3px; }
    .hud-avatar-img { width: 32px; height: 32px; }
    .heart-status-img { height: 14px; margin-left: 12px; }
    .hud-info-text { font-size: 12px; }
    
    .top-right-btns { top: 5px; right: 5px; gap: 5px; }
    .btn-mini { width: 35px; height: 35px; }

    /* ENDGAME MOBILE */
    .endgame-panel, .leaderboard-panel { 
        width: 550px; 
        padding: 40px 30px 25px; 
    }
    .endgame-title, .leaderboard-title { font-size: 16px; top: 7px; }
    .endgame-stats { gap: 12px; margin: 50px 0; }
    .endgame-stat-card { width: 130px; height: 120px; }
    .endgame-stat-value { font-size: 24px; }
    .endgame-stat-label { 
        font-size: 11px; 
        color: #fff; 
    }
    .endgame-buttons { gap: 12px;}
    .endgame-btn { width: 70px; height: 70px; }
    .leaderboard-list { max-height: 180px; }
    .lb-row { padding: 5px 10px; }
    .lb-rank { width: 28px; height: 28px; font-size: 13px; }
    .lb-name { font-size: 13px; }
    .lb-score { font-size: 15px; }
}