/* --- Global Styles & Fonts --- */
:root {
    --bg: #70D6FF;
    --panel-bg: rgba(255, 255, 255, 0.15); /* Frosted glass effect */
    --panel-border: rgba(255, 255, 255, 0.3);
    --text-color: #FFFFFF;
    --text-dark-shadow: #1D3557;
    --text-light: #E0E0E0;
    --border-color: #E9ECEF;
    --shadow: rgba(29, 53, 87, 0.3);

    --orange: #ff7340;
    --orange-dark: #f0500c;
    --yellow: #f8c647;
    --yellow-dark: #e9a01a;
    --blue: #3a86d8; /* Softer blue from game */
    --red: #FF5252; /* Health color from game */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Exo 2', 'Fredoka One', sans-serif; /* Prioritize Exo 2 for sci-fi feel */
    user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #0f2027; /* Default to night */
    color: var(--text-color);
    transition: background-color 0.5s ease;
}

canvas#game {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

/* --- Menu & Overlay Base Styles --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 20px;
    opacity: 0;
    animation: fadeIn 0.5s forwards;
    z-index: 20;
}

#startScreen {
    opacity: 1;
    animation: none;
    background: transparent;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

/* --- Central Menu Content --- */
.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    animation: slideUp 0.8s 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    opacity: 0;
    margin-top: -10vh; /* Pull content up to make space for rocket */
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(50px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-15px); }
}

.menu-content h1 {
    font-family: 'Fredoka One', sans-serif;
    font-size: clamp(3.5rem, 15vw, 7rem);
    display: flex;
    text-shadow: 0 0 10px rgba(0,0,0,0.3), 0 0 20px rgba(0,0,0,0.2);
    -webkit-text-stroke: 3px var(--text-dark-shadow);
}

.menu-content h1 span {
    animation: float 3s ease-in-out infinite;
    transition: filter 0.2s ease-in-out, text-shadow 0.2s ease-in-out;
}

.menu-content h1:hover span {
    filter: brightness(1.1);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}

h1 span:nth-child(1) { color: #e74a4a; animation-delay: 0s; }
h1 span:nth-child(2) { color: #3a86d8; animation-delay: 0.1s; }
h1 span:nth-child(3) { color: #f5c542; animation-delay: 0.2s; }
h1 span:nth-child(4) { color: #43b86b; animation-delay: 0.3s; }
h1 span:nth-child(5) { color: #9c4fad; animation-delay: 0.4s; }
h1 span:nth-child(7) { color: #e74a4a; animation-delay: 0.5s; }
h1 span:nth-child(8) { color: #3a86d8; animation-delay: 0.6s; }
h1 span:nth-child(9) { color: #f5c542; animation-delay: 0.7s; }
h1 span:nth-child(10) { color: #43b86b; animation-delay: 0.8s; }

#startBtn {
    font-family: 'Exo 2', sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    padding: 18px 60px;
    color: #fff;
    background-color: var(--orange);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.2);
    border-bottom: 8px solid var(--orange-dark);
    box-shadow: 0 0 20px var(--orange), 0 0 30px var(--orange-dark);
    transition: all 0.2s ease-in-out;
    animation: buttonPulse 2s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

@keyframes buttonPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 10px var(--orange), 0 0 20px var(--orange-dark); }
    50% { transform: scale(1.05); box-shadow: 0 0 20px var(--orange), 0 0 35px var(--orange-dark); }
}

#startBtn:hover {
    transform: translateY(-4px) scale(1.05);
    border-bottom-width: 12px;
    animation-play-state: paused;
}

#startBtn:active {
    transform: translateY(0) scale(1);
    border-bottom-width: 8px;
}

/* --- Theme Chooser --- */
.theme-chooser {
    margin-top: 20px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 15px 20px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

.theme-chooser h3 {
    text-align: center;
    margin-bottom: 15px;
    font-size: 1rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.theme-options {
    display: flex;
    gap: 15px;
}

.theme-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px;
    border-radius: 15px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.theme-btn:hover {
    transform: translateY(-5px);
}

.theme-preview {
    width: 70px;
    height: 45px;
    border-radius: 10px;
    border: 2px solid rgba(255,255,255,0.4);
}

.theme-btn span {
    color: var(--text-light);
    transition: color 0.3s ease;
    font-weight: 700;
}

.theme-btn:hover span {
    color: var(--text-color);
}

.theme-btn.active {
    border-color: var(--orange);
    transform: scale(1.1);
}

.theme-btn.active span {
    color: var(--orange);
}

/* UPDATED: auto-preview button now shows light to darkest theme */
#theme-auto { background: linear-gradient(180deg, #87CEEB 0%, #2c5364 100%); }
#theme-day { background: linear-gradient(180deg, #87CEEB 0%, #B0E0E6 100%); }
#theme-dusk { background: linear-gradient(180deg, #56317a 0%, #2c214d 100%); }
#theme-night { background: linear-gradient(180deg, #0f2027 0%, #2c5364 100%); }

/* --- Corner UI --- */
.top-left-hud, .top-right-controls {
    position: absolute;
    padding: 20px;
    z-index: 15;
}

.top-left-hud {
    top: 0;
    left: 0;
}

.top-right-controls {
    top: 0;
    right: 0;
    display: flex;
    gap: 15px;
}

.score-display, .icon-btn {
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    font-weight: 700;
    filter: drop-shadow(2px 2px 3px rgba(29, 53, 87, 0.5));
}

.score-display {
    font-size: 1.5rem;
    color: var(--text-color);
    padding: 10px 20px;
    border-radius: 15px;
}

#highestScoreContainer span {
    color: var(--yellow);
}

.icon-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    transform: translateY(-2px) scale(1.1);
}

.icon-btn:active {
    transform: translateY(0);
}

.icon-btn svg {
    width: 28px;
    height: 28px;
    fill: var(--text-color);
}

.icon-off {
    display: none;
}

.icon-btn.muted .icon-on {
    display: none;
}

.icon-btn.muted .icon-off {
    display: block;
}

.icon-btn.muted svg {
    fill: #9E9E9E;
}

/* --- Game Over Popup --- */
#gameOverScreen {
    background: rgba(15, 32, 39, 0.4);
    backdrop-filter: blur(8px);
}

#gameOverScreen .popup {
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    border-radius: 25px;
    padding: 30px 40px;
    width: clamp(300px, 90%, 500px);
    display: flex;
    flex-direction: column;
    gap: 20px;
    transform: scale(0.95);
    animation: fadeInScale 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes fadeInScale {
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.popup-title {
    font-size: 3.5rem;
    color: var(--text-color);
    text-align: center;
}

.new-high-score {
    font-size: 1.8rem;
    font-weight: 700;
    text-align: center;
    background: linear-gradient(45deg, #f8c647, #e74a4a, #f8c647);
    background-size: 200% 200%;
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    animation: newScorePulse 1s infinite, rainbow-text 3s ease infinite;
}

@keyframes newScorePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes rainbow-text {
    0% { background-position:0% 50% }
    50% { background-position:100% 50% }
    100% { background-position:0% 50% }
}

.score-summary {
    display: flex;
    justify-content: space-around;
    gap: 20px;
    margin: 10px 0;
    padding: 20px;
    background: rgba(0,0,0,0.2);
    border-radius: 15px;
}

.score-box {
    text-align: center;
}

.score-label {
    font-size: 1.2rem;
    color: var(--text-light);
    margin-bottom: 5px;
}

.score-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-color);
}

#gameOverHighestScoreValue {
    color: var(--yellow);
}

#finalScoreValue {
    color: var(--blue);
}

.popup-buttons {
    display: flex;
    gap: 20px;
    margin-top: 10px;
    justify-content: center;
    align-items: center;
}

.popup-buttons button {
    font-family: 'Exo 2', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 15px 35px;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    color: white;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.2);
}

.popup-buttons button:active {
    transform: translateY(0) scale(1);
}

.popup-btn-primary {
    background: var(--orange);
    border-bottom: 6px solid var(--orange-dark);
    animation: buttonPulse 2s 0.5s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

.popup-btn-primary:hover {
    transform: scale(1.05) translateY(-3px);
    filter: brightness(1.1);
}

.popup-btn-primary:active {
    transform: scale(1);
    border-bottom-width: 6px;
}

.popup-btn-secondary {
    background: var(--blue);
    border-bottom: 6px solid #2c5364;
}

.popup-btn-secondary:hover {
    transform: scale(1.05) translateY(-3px);
    filter: brightness(1.1);
}

/* --- In-game HUD --- */
#hud {
    position: fixed;
    top: 20px;
    left: 20px;
    width: calc(100% - 40px);
    display: none;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    pointer-events: none;
}

.hud-left, .hud-center, .hud-right {
    flex: 1;
    text-shadow: 3px 3px 5px rgba(0,0,0,0.25);
}

.hud-center { text-align: center; }
.hud-left { text-align: left; }
.hud-right { text-align: right; }

#score {
    font-size: 48px;
    font-weight: 700;
    transition: color 0.5s ease;
    color: white;
    white-space: nowrap;
}

#health {
    display: flex;
    gap: 8px;
}

#powerup-status {
    font-size: 32px;
    font-weight: 700;
    color: var(--yellow);
}

.heart-icon {
    width: 48px;
    height: 48px;
    stroke-width: 2;
    filter: drop-shadow(3px 3px 5px rgba(0,0,0,0.3));
}

.heart-filled {
    fill: var(--red);
    stroke: #fff;
}

.heart-empty {
    fill: rgba(0, 0, 0, 0.2);
    stroke: rgba(255,255,255,0.6);
}

/* --- Mobile Friendliness --- */
@media (max-width: 768px) {
    .menu-content h1 {
        font-size: clamp(3rem, 15vw, 5rem);
        -webkit-text-stroke-width: 2px;
    }

    #startBtn {
        font-size: 1.8rem;
        padding: 15px 50px;
    }

    .theme-chooser {
        padding: 10px 15px;
        transform: scale(0.9);
    }

    .theme-preview {
        width: 60px;
        height: 35px;
    }

    .top-left-hud, .top-right-controls {
        padding: 15px;
    }

    .score-display {
        font-size: 1.5rem;
        color: var(--text-color);
        padding: 10px 20px;
        border-radius: 15px;
        text-shadow: 2px 2px 4px rgba(29, 53, 87, 0.7);
    }

    .icon-btn {
        width: 45px;
        height: 45px;
    }

    .icon-btn svg {
        width: 24px;
        height: 24px;
    }

    #gameOverScreen .popup {
        padding: 20px;
        gap: 15px;
    }

    .popup-title {
        font-size: 2.5rem;
    }

    .new-high-score {
        font-size: 1.5rem;
    }

    .score-summary {
        padding: 15px;
        gap: 10px;
    }

    .score-label {
        font-size: 1rem;
    }

    .score-value {
        font-size: 2.5rem;
    }

    .popup-buttons {
        gap: 15px;
    }

    .popup-buttons button {
        font-size: 1.2rem;
        padding: 12px 25px;
    }

    #hud {
        top: 15px;
        left: 15px;
        width: calc(100% - 30px);
    }

    #score {
        font-size: 32px;
        margin-left: 10px;
    }

    .heart-icon {
        width: 36px;
        height: 36px;
    }

    #powerup-status {
        font-size: 24px;
    }
}

@media (max-width: 480px) {
    .menu-content h1 {
        font-size: clamp(2.5rem, 18vw, 4rem);
        -webkit-text-stroke-width: 1.5px;
    }
    .theme-chooser {
        transform: scale(0.85);
    }
    .popup-buttons {
        flex-direction: column;
    }
    #score {
        font-size: 24px;
    }
    .heart-icon {
        width: 30px;
        height: 30px;
    }
}

@media (max-height: 650px) {
    .menu-content {
        margin-top: 0;
    }
}