/* ========================================
   CÁ VOI XANH - GAME STYLESHEET (FINAL)
   ======================================== */

/* --- 1. CSS VARIABLES --- */
:root {
    --color-ocean-deep: #023e8a;
    --color-white: #ffffff;
    --color-shadow: rgba(0, 0, 0, 0.6);
    /* Backgrounds */
    --bg-start: url('../images/common/bg_beach_day.jpg');
    --bg-map: url('../images/map/bg_map.jpg');
    --bg-current: var(--bg-start);
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

/* --- 2. RESET & BASE --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body {
    background-color: #222;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    font-family: 'Arial', sans-serif;
    overflow: hidden;
}

/* --- 3. ROTATE WARNING --- */
#rotate-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--color-ocean-deep);
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--color-white);
    text-align: center;
    font-weight: bold;
}

.rotate-icon {
    font-size: 50px;
    margin-bottom: 20px;
    animation: spin 2s infinite linear;
}

@media screen and (orientation: landscape) and (max-height: 600px) {
    #game-viewport {
        display: none !important;
    }

    #rotate-warning {
        display: flex;
    }
}

/* --- 4. GAME VIEWPORT --- */
#game-viewport {
    position: relative;
    width: 100%;
    max-width: 540px;
    height: 100%;
    background-image: var(--bg-current);
    background-size: cover;
    background-position: center bottom;
    background-repeat: no-repeat;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

/* --- 5. SCREEN SYSTEM --- */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* Buttons */
.btn {
    cursor: pointer;
    transition: transform 0.1s ease;
}

.btn:active {
    transform: scale(0.95);
    filter: brightness(0.9);
}

.btn--pulse {
    animation: pulse 2s infinite ease-in-out;
}

/* --- 6. START SCREEN STYLES --- */
#screen-start {
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 2vh 0 4vh 0;
}

.start-screen__header {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    justify-content: center;
    padding-top: 2vh;
}

.start-screen__logo {
    width: 85%;
    max-width: 400px;
    max-height: 25vh;
    object-fit: contain;
    animation: float 3s infinite ease-in-out;
}

.start-screen__hero {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.start-screen__char {
    width: auto;
    max-width: 90%;
    height: 45vh;
    max-height: 500px;
    object-fit: contain;
    transform: translateY(-2vh);
}

.start-screen__footer {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 2vh;
    z-index: 10;
}

.btn-container img {
    width: 70vw;
    max-width: 320px;
    height: auto;
}

.text-slogan {
    color: var(--color-white);
    margin-top: 12px;
    font-size: 1.1rem;
    font-weight: bold;
    text-shadow: 0 2px 4px var(--color-shadow);
}

/* --- 7. MAP SCREEN STYLES (UPDATED) --- */
#screen-map {
    /* display: block; XÓA HOẶC COMMENT DÒNG NÀY ĐI */
    display: none;
    /* Map không dùng Flex tổng thể để dễ position absolute */
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding-bottom: 20px;
}

#screen-map.active {
    display: block;
}

/* Header */
.map-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    z-index: 999;
    pointer-events: none;
}

.btn-icon {
    width: 45px;
    height: 45px;
    object-fit: contain;
    pointer-events: auto;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}

.map-container {
    position: relative;
    width: 100%;
    height: 100%;
}

/* --- PATH STARS (5 STARS DENSITY) --- */
/* --- PATH STARS (UPDATED) --- */
.path-star {
    position: absolute;
    object-fit: contain;
    opacity: 0.9;
    z-index: 15;
    animation: twinkle 2s infinite alternate;

    /* Mặc định cho sao ở 2 đầu (vị trí a và e) - Nhỏ nhất */
    width: 12px !important;
    height: 12px !important;
    opacity: 0.7;
}

/* Sao ở vị trí trung gian (b và d) - Vừa */
img[class*="-b"],
img[class*="-d"] {
    width: 18px !important;
    height: 18px !important;
    opacity: 0.9;
}

/* Sao ở chính giữa (c) - To nhất và sáng nhất */
img[class*="-c"] {
    width: 28px !important;
    height: 28px !important;
    filter: drop-shadow(0 0 8px rgba(255, 255, 0, 0.8));
    /* Phát sáng */
    z-index: 16;
    /* Nổi lên trên */
    animation: pulseStar 1.5s infinite ease-in-out;
}

/* Hiệu ứng nhịp đập riêng cho ngôi sao chính */
@keyframes pulseStar {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* 1. Start -> Node 1 (Up-Right) */
.s-start-1-a {
    bottom: 12%;
    left: 58%;
    animation-delay: 0.0s;
}

.s-start-1-b {
    bottom: 15%;
    left: 63%;
    animation-delay: 0.2s;
}

.s-start-1-c {
    bottom: 18%;
    left: 68%;
    animation-delay: 0.4s;
}

.s-start-1-d {
    bottom: 21%;
    left: 73%;
    animation-delay: 0.6s;
}

.s-start-1-e {
    bottom: 24%;
    left: 78%;
    animation-delay: 0.8s;
}

/* 2. Node 1 -> Node 2 (Leftwards) */
.s-1-2-a {
    top: 65%;
    right: 25%;
    animation-delay: 0.0s;
}

.s-1-2-b {
    top: 62%;
    right: 35%;
    animation-delay: 0.2s;
}

.s-1-2-c {
    top: 59%;
    right: 45%;
    animation-delay: 0.4s;
}

.s-1-2-d {
    top: 56%;
    right: 55%;
    animation-delay: 0.6s;
}

.s-1-2-e {
    top: 53%;
    right: 65%;
    animation-delay: 0.8s;
}

/* 3. Node 2 -> Node 3 (Rightwards) */
.s-2-3-a {
    top: 45%;
    left: 25%;
    animation-delay: 0.0s;
}

.s-2-3-b {
    top: 42%;
    left: 35%;
    animation-delay: 0.2s;
}

.s-2-3-c {
    top: 39%;
    left: 45%;
    animation-delay: 0.4s;
}

.s-2-3-d {
    top: 36%;
    left: 55%;
    animation-delay: 0.6s;
}

.s-2-3-e {
    top: 33%;
    left: 65%;
    animation-delay: 0.8s;
}

/* 4. Node 3 -> Node 4 (Leftwards) */
.s-3-4-a {
    top: 25%;
    right: 25%;
    animation-delay: 0.0s;
}

.s-3-4-b {
    top: 22%;
    right: 35%;
    animation-delay: 0.2s;
}

.s-3-4-c {
    top: 19%;
    right: 45%;
    animation-delay: 0.4s;
}

.s-3-4-d {
    top: 16%;
    right: 55%;
    animation-delay: 0.6s;
}

.s-3-4-e {
    top: 13%;
    right: 65%;
    animation-delay: 0.8s;
}

/* --- LEVEL NODES (ISLANDS) --- */
.level-node {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    z-index: 20;
    width: 35%;
    max-width: 140px;
    /* Kích thước đảo */
}

.island-img {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.4));
    animation: floatIsland 3s infinite ease-in-out;
}

.level-label {
    position: absolute;
    bottom: -5px;
    background-color: #d38c56;
    color: #fff;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: bold;
    border: 2px solid #5a3a2a;
    white-space: nowrap;
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Tọa độ Đảo */
.node-4 {
    top: 8%;
    left: 10%;
}

/* Quiz - Trên Trái */
.node-3 {
    top: 28%;
    right: 10%;
}

/* Runner - Giữa Phải */
.node-2 {
    top: 48%;
    left: 10%;
}

/* Gym - Giữa Trái */
.node-1 {
    top: 68%;
    right: 10%;
}

/* Shop - Dưới Phải */

/* --- START NODE (SMALLER) --- */
.start-node {
    position: absolute;
    bottom: 2%;
    /* Neo sát đáy */
    left: 50%;
    transform: translateX(-50%);
    width: 35%;
    /* ĐÃ THU NHỎ (Trước là 60%) */
    max-width: 160px;
    z-index: 30;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.podium-img {
    width: 100%;
    height: auto;
    z-index: 1;
}

.char-img {
    position: absolute;
    bottom: 35%;
    width: 55%;
    /* Tăng tỉ lệ so với bục vì bục đã nhỏ */
    z-index: 5;
    animation: float 2s infinite ease-in-out;
}

.start-btn-label {
    position: absolute;
    bottom: 12%;
    background: linear-gradient(to bottom, #ff7e5f, #feb47b);
    color: #fff;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 900;
    border: 2px solid #fff;
    box-shadow: 0 3px 0 #c0392b;
    z-index: 10;
    cursor: pointer;
}

.character-light {
    position: absolute;
    bottom: 20%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 70%);
    z-index: 0;
    animation: pulse 2s infinite;
}

/* --- ANIMATIONS --- */
@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.03);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes floatIsland {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(-90deg);
    }
}

@keyframes twinkle {
    0% {
        opacity: 0.5;
        transform: scale(0.8);
    }

    100% {
        opacity: 1;
        transform: scale(1.2) rotate(20deg);
    }
}

/* --- 10. LOCKED LEVEL STATES (TRẠNG THÁI KHOÁ) --- */
.level-node.locked {
    cursor: not-allowed;
}

.level-node.locked .island-img {
    filter: grayscale(1) brightness(0.6);
    /* Làm xám và tối đi */
}

/* Thêm icon ổ khoá bằng CSS (hoặc dùng ảnh nếu muốn đẹp hơn) */
.level-node.locked::after {
    content: '🔒';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -120%);
    font-size: 24px;
    z-index: 25;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* Hiệu ứng rung khi bấm vào level bị khoá */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.shake-lock {
    animation: shake 0.3s ease-in-out;
}

/* --- 11. POPUP SYSTEM (BẢNG THÔNG BÁO) --- */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    /* Nền tối mờ */
    z-index: 2000;
    display: none;
    /* Mặc định ẩn */
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.popup-overlay.active {
    display: flex;
    opacity: 1;
}

.popup-board {
    width: 85%;
    max-width: 350px;
    background: linear-gradient(to bottom, #fff9c4, #fff);
    border: 4px solid #d38c56;
    border-radius: 20px;
    padding: 20px;
    text-align: center;
    position: relative;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.popup-overlay.active .popup-board {
    transform: scale(1);
}

/* Nút tắt popup */
.btn-close {
    position: absolute;
    top: -15px;
    right: -10px;
    width: 35px;
    height: 35px;
    background-color: #e74c3c;
    color: white;
    border-radius: 50%;
    font-weight: bold;
    line-height: 35px;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.popup-title {
    font-size: 1.5rem;
    color: #e67e22;
    margin-bottom: 10px;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 #fff;
}

.popup-mission {
    font-size: 1rem;
    color: #555;
    margin-bottom: 20px;
    line-height: 1.4;
}

/* Nút Chơi trong popup */
.btn-play-level {
    background: linear-gradient(to bottom, #2ecc71, #27ae60);
    border: none;
    padding: 10px 30px;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 0 #1e8449;
    transition: transform 0.1s;
}

.btn-play-level:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #1e8449;
}

/* --- GAMEPLAY SCREEN (IFRAME) --- */
#screen-gameplay {
    background-color: #000;
    z-index: 2000;
    /* Luôn nằm trên cùng */
    display: none;
    flex-direction: column;
}

#screen-gameplay.active {
    display: flex;
}

#game-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* Nút thoát nổi */
.btn-mute {
    position: absolute;
    top: var(--safe-top);
    right: 20px;
    margin-top: 20px;
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.8);
    border: 2px solid #2980b9;
    border-radius: 50%;
    color: #2980b9;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 2002;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.btn-mute:active {
    transform: scale(0.95);
}

.btn-back-floating {
    position: absolute;
    top: var(--safe-top);
    right: 20px;
    margin-top: 20px;
    background-color: rgba(231, 76, 60, 0.9);
    color: white;
    border: 2px solid white;
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
    /* Nổi trên iframe */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.btn-back-floating:active {
    transform: scale(0.95);
}

/* --- GIỮ NGUYÊN PHẦN CŨ VÀ THAY THẾ/THÊM PHẦN SAO NÀY VÀO CUỐI --- */

/* --- HIỆU ỨNG NGÔI SAO CẦU VỒNG (STAR PATH) --- */
.path-star {
    position: absolute;
    object-fit: contain;
    z-index: 15;
    /* Mặc định cho sao ở 2 đầu (vị trí a và e) - Nhỏ nhất */
    width: 12px !important;
    height: 12px !important;
    opacity: 0.6;
    animation: twinkle 3s infinite alternate;
}

/* Sao ở vị trí trung gian (b và d) - Vừa */
img[class*="-b"],
img[class*="-d"] {
    width: 18px !important;
    height: 18px !important;
    opacity: 0.8;
    animation-delay: 0.5s;
}

/* Sao ở chính giữa (c) - To nhất và sáng nhất */
img[class*="-c"] {
    width: 28px !important;
    height: 28px !important;
    filter: drop-shadow(0 0 10px rgba(255, 235, 59, 0.8));
    /* Phát sáng vàng */
    z-index: 16;
    opacity: 1;
    animation: pulseStar 1.5s infinite ease-in-out;
}

@keyframes pulseStar {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 5px rgba(255, 235, 59, 0.5));
    }

    50% {
        transform: scale(1.3);
        filter: drop-shadow(0 0 15px rgba(255, 235, 59, 1));
    }

    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 5px rgba(255, 235, 59, 0.5));
    }
}

@keyframes twinkle {
    0% {
        opacity: 0.6;
        transform: rotate(0deg);
    }

    100% {
        opacity: 0.9;
        transform: rotate(20deg);
    }
}

/* --- 12. LOADING OVERLAY (PRELOADER) --- */
/* Popup Icons */
.popup-icon-container {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: -50px auto 10px;
    /* Pull up to overlap header */
    border: 4px solid white;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    background: linear-gradient(135deg, #a8e6cf, #dcedc1);
}

.popup-icon {
    width: 80%;
    height: 80%;
    object-fit: contain;
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

/* Loading Overlay Styles (Existing) */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #2c3e50;
    /* Match body bg */
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

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

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #3498db;
    animation: spin-loader 1s ease-in-out infinite;
    margin-bottom: 20px;
}

.loading-text {
    color: white;
    font-family: 'Arial', sans-serif;
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 1px;
    animation: pulse 1.5s infinite;
}

@keyframes spin-loader {
    to {
        transform: rotate(360deg);
    }
}
/* --- Map High Score Display --- */
.map-high-score {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 25px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50px;
    border: 3px solid #f1c40f;
    box-shadow: 0 4px 15px rgba(241, 196, 15, 0.5);
    z-index: 20;
    transition: all 0.3s ease;
    animation: floatScore 3s ease-in-out infinite;
}

.map-high-score .trophy {
    font-size: 2.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.map-high-score .score-text {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.map-high-score .label {
    font-family: 'Nunito', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: #e67e22;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.map-high-score .value {
    font-family: 'Baloo 2', cursive;
    font-size: 1.8rem;
    font-weight: 800;
    color: #2c3e50;
    line-height: 1;
}

@keyframes floatScore {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-5px); }
}

.hidden {
    display: none !important;
}
