body {
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    /* Fallback */
    height: 100dvh;
    /* Dynamic viewport height for mobile browsers */
    background-color: #f0f0f0;
    font-family: 'Arial', sans-serif;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 800px;
    height: 400px;
    background-color: #fff;
    border: 2px solid #333;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas/buttons */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#start-screen,
#game-over-screen {
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

h1 {
    margin-top: 0;
    color: #333;
}

button {
    padding: 10px 20px;
    font-size: 18px;
    background-color: #ff5722;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 10px;
}

button:hover {
    background-color: #e64a19;
}

#score-display {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 20px;
    font-weight: bold;
    color: #333;
}

.blast-dialog {
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    background: radial-gradient(circle, #ffeb3b 0%, #ff9800 40%, #f44336 100%);
    padding: 20px 30px;
    border: none;
    /* Jagged edges using clip-path */
    clip-path: polygon(0% 15%, 5% 5%, 15% 0%, 25% 10%, 35% 0%, 45% 10%, 55% 0%, 65% 10%, 75% 0%, 85% 10%, 95% 0%,
            100% 15%, 90% 25%, 100% 35%, 90% 45%, 100% 55%, 90% 65%, 100% 75%, 90% 85%, 100% 95%,
            85% 85%, 75% 100%, 65% 85%, 55% 100%, 45% 85%, 35% 100%, 25% 85%, 15% 100%, 5% 85%, 0% 100%,
            10% 85%, 0% 75%, 10% 65%, 0% 55%, 10% 45%, 0% 35%, 10% 25%);
    transform: rotate(-5deg);
    margin-bottom: 15px;
    box-shadow: 0 0 20px rgba(255, 87, 34, 0.8);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-shadow: 2px 2px 0 #d32f2f;
}

@keyframes popIn {
    0% {
        transform: scale(0) rotate(-5deg);
    }

    100% {
        transform: scale(1) rotate(-5deg);
    }
}

/* Mobile Responsiveness */
@media (max-width: 800px) {
    #game-container {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        /* Fallback */
        height: 100dvh;
        border: none;
    }

    /* Start Screen Mobile Adjustments */
    .bounce-title {
        font-size: 2em;
        /* Smaller title */
        margin-bottom: 10px;
    }

    .start-graphic img,
    .animated-character {
        width: 60px;
        /* Smaller character */
    }

    #start-screen {
        padding: 10px;
        width: 90%;
        /* Ensure it fits */
        max-width: 350px;
        /* Prevent it from being too wide on tablets */
    }

    /* Fire animation mobile adjustments */
    .fire-animation-container {
        width: 80px !important;
        max-width: 80px !important;
        height: 100px !important;
        max-height: 100px !important;
        margin: 10px auto !important;
    }

    .fire-animation-container img {
        max-width: 80px !important;
        max-height: 100px !important;
    }

    .start-graphic {
        margin: 10px 0;
    }
}

/* If the screen is very short (landscape mobile), ensure it fits */
@media (max-height: 400px) {
    #game-container {
        height: 100vh;
        width: auto;
        aspect-ratio: 2 / 1;
    }
}

/* Leaderboard Styles */
#leaderboard-container,
#leaderboard-container-start {
    margin: 15px 0;
    text-align: left;
    display: inline-block;
    background: rgba(255, 255, 255, 0.8);
    padding: 10px;
    border-radius: 5px;
}

#leaderboard-container h3,
#leaderboard-container-start h3 {
    margin-top: 0;
    text-align: center;
    color: #333;
    font-size: 18px;
}

#leaderboard-container ol,
#leaderboard-container-start ol {
    padding-left: 25px;
    margin-bottom: 0;
}

#leaderboard-container li,
#leaderboard-container-start li {
    font-size: 16px;
    margin-bottom: 5px;
    color: #555;
}

/* Modal Styles */
#highscore-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#player-name {
    padding: 10px;
    font-size: 16px;
    margin: 10px 0;
    width: 200px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

/* Start Screen Animations */
.bounce-title {
    animation: bounce 2s infinite;
    font-size: 3em;
    color: #ff5722;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

@keyframes bounce {

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

    40% {
        transform: translateY(-20px);
    }

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

.start-graphic {
    margin: 20px 0;
}

.animated-character {
    width: 80px;
    animation: float 3s ease-in-out infinite;
    filter: drop-shadow(0 10px 5px rgba(0, 0, 0, 0.2));
}

@keyframes float {
    0% {
        transform: translateY(0px) rotate(0deg);
    }

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

    100% {
        transform: translateY(0px) rotate(0deg);
    }
}

.dead-character {
    animation: none;
    /* No float for dead character */
    transform: none;
    /* Fire is upright */
}

.fire-animation-container {
    position: relative;
    width: 120px;
    max-width: 120px;
    height: 150px;
    max-height: 150px;
    margin: 20px auto;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    overflow: hidden;
    /* Changed from visible to hidden to prevent overflow */
}

.fire-animation-container img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
    object-position: bottom;
}

.blood-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background-color: #d32f2f;
    pointer-events: none;
    animation: spurt 1s ease-out forwards;
}

@keyframes spurt {
    0% {
        transform: translate(0, 0);
        opacity: 1;
    }

    100% {
        transform: translate(var(--vx), var(--vy));
        opacity: 0;
    }
}