/* Basic Style Settings */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1a1a; /* Dark background */
    font-family: 'Press Start 2P', cursive;
    color: #fff;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    zoom: 1.05;
}

/* Game Container */
#game-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    height: 90vh;
    max-height: 800px;
    aspect-ratio: 400/600;
    overflow: hidden;
    border: 4px solid #554CA8;
    border-radius: 15px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
    background-color: #352879;
}

/* Canvas Style */
#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Overlay Screens (Start, Pause, Game Over) */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 100; /* Higher z-index than other elements */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay-screen.active {
    opacity: 1;
    visibility: visible;
}

.overlay-content {
    background: rgba(0, 0, 0, 0.9);
    padding: 30px;
    border-radius: 15px;
    border: 2px solid #554CA8;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

/* Title Styles */
h1, h2 {
    font-size: 2.5rem;
    color: #ffcc00;
    text-shadow: 3px 3px 0 #cc9900;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Button Styles */
button {
    padding: 15px 30px;
    font-size: 1.2rem;
    font-family: inherit;
    background: #ffcc00;
    color: #333;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-shadow: 1px 1px 0 #cc9900;
    box-shadow: 0 4px 0 #cc9900;
    transition: all 0.2s ease;
    margin-top: 20px;
}

button:hover {
    background: #ffd633;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #cc9900;
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #cc9900;
}

/* Pause Screen */
#pauseScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: none; /* Hidden at the start */
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 200; /* Upper than other elements*/
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#pauseScreen.active {
    opacity: 1;
    visibility: visible;
}

#pauseScreen .overlay-content {
    background: rgba(0, 0, 0, 0.9);
    padding: 30px;
    border-radius: 15px;
    border: 2px solid #554CA8;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}


/* Score Display */
#scoreDisplay {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2rem;
    color: white;
    text-shadow: 2px 2px 0 #000;
    z-index: 5;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
}

/* Pause Button */
#pauseButton {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    display: flex; 
    justify-content: center;
    align-items: center; 
    cursor: pointer;
    font-size: 1.5rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    z-index: 10;
    transition: all 0.2s ease;
}

#pauseButton:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.9);
}

/* Loading Screen */
.loading-screen .overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffcc00;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Game Over Screen */
.game-over-screen .overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Game Over Screen Score */
#finalScore {
    font-size: 1.5rem;
    color: #ffcc00;
    text-shadow: 2px 2px 0 #cc9900;
}

/* Game Over Screen Button */
#restartButton {
    padding: 15px 30px;
    font-size: 1.2rem;
    font-family: inherit;
    background: #ffcc00;
    color: #333;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-shadow: 1px 1px 0 #cc9900;
    box-shadow: 0 4px 0 #cc9900;
    transition: all 0.2s ease;
    margin-top: 20px;
}

#restartButton:hover {
    background: #ffd633;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #cc9900;
}

#restartButton:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #cc9900;
}

/* High Score Screen */
.high-score-screen .overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* High Score Screen Score */
#highScore {
    font-size: 1.5rem;
    color: #ffcc00;
    text-shadow: 2px 2px 0 #cc9900;
}

/* High Score Screen Button */
#playAgainButton {
    padding: 15px 30px;
    font-size: 1.2rem;
    font-family: inherit;
    background: #ffcc00;
    color: #333;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-shadow: 1px 1px 0 #cc9900;
    box-shadow: 0 4px 0 #cc9900;
    transition: all 0.2s ease;
    margin-top: 20px;
}

/* Media Queries */
@media screen and (max-width: 768px) {
    html, body {
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100dvh;
        overflow: hidden;
    }

    body {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        touch-action: manipulation;
        background-color: #1a1a1a;
        zoom: 1; /* Reset zoom for smaller screens */
    }

    #game-container {
        width: 100vw;
        height: auto;
        aspect-ratio: 400 / 600;
        max-height: 95dvh;
        border: 4px solid #554CA8; /* Keep purple border */
        border-radius: 15px;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
        background-color: #352879;
        margin: 0 auto;
        display: block;
    }

    h1, h2 {
        font-size: 1.5rem;
        text-shadow: 2px 2px 0 #cc9900;
    }

    button {
        padding: 10px 20px;
        font-size: 1rem;
    }

    #pauseButton {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    #scoreDisplay {
        font-size: 1.4rem;
        padding: 8px 16px;
        top: 10px;
    }
}

@media screen and (max-width: 480px) {
    #game-container {
        max-height: 90dvh;
    }

    h1, h2 {
        font-size: 1.5rem;
    }

    .overlay-content {
        padding: 20px;
        width: 90%;
    }

    button {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    #gameCanvas {
        --player-scale: 0.8;
    }

    .ground {
        height: 60px !important;
    }
}

@media screen and (max-height: 500px) {
    body {
        justify-content: center;
        padding-top: 0;
    }

    #game-container {
        max-height: 90dvh;
    }
}
