* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Press Start 2P', cursive;
}

body {
    background: linear-gradient(135deg, #6e45e2, #88d3ce);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    overflow: hidden;
    image-rendering: pixelated;
}

:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    touch-action: none;
    background-color: #000;
    font-family: 'Press Start 2P', cursive;
}

/* Base container styles */
.game-container { 
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    max-width: 430px; /* Standard mobile width */
    max-height: 932px; /* Standard mobile height */
    overflow: hidden;
    background-color: #d4efff;
    background-image: 
        linear-gradient(transparent 0%, rgba(0,0,0,0.1) 100%),
        url('data:image/svg+xml;utf8,<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="M10,80 L20,80 L20,90 L10,90 Z" fill="%234CAF50" fill-opacity="0.2"/></svg>');
    box-shadow: 0 0 0 4px #70c5ce, 0 0 0 8px #000;
    z-index: 1;
    margin: 0 auto;
    padding: 0;
}

/* Cloud animation */
@keyframes cloudMove {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

.clouds {
    position: absolute;
    top: 23px;
    left: 0;
    width: 100%;
    height: 25%;
    background-image: url('../images/cloud.png');
    background-size: auto 40%;
    background-repeat: repeat-x;
    background-position: 0 20%;
    animation: cloudMove 75s linear infinite;
    z-index: 0;
    pointer-events: none;
    opacity: 0.4;
    image-rendering: pixelated;
}

#game { 
    position: relative; 
    width: 100%; 
    height: 100%; 
    overflow: hidden; 
}

#bird { 
    position: absolute; 
    width: 103px; 
    height: 64px; 
    left: 50px; 
    top: 50%; 
    transform: translateY(-50%) rotate(0deg); 
    background: url('../images/objekbird.png') center/contain no-repeat;
    z-index: 10;
    transition: transform 0.1s ease-out;
    image-rendering: pixelated;
}

.obstacle { 
    position: absolute; 
    width: 80px; 
    background: #4CAF50; 
    border: 5px solid #2E7D32;
    z-index: 3; /* Ensure obstacles are above trees */
}

#score { 
    position: absolute; 
    top: 20px; 
    left: 50%; 
    transform: translateX(-50%); 
    font-size: 75px; 
    font-weight: bold; 
    color: #fffb00; 
    text-shadow: 1px 1px 5px rgba(0,0,0,0.75); 
    z-index: 100; 
}

/* Mute Button */
.mute-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background: none;
    border: 0px solid #fff;
    color: white;
    width: 60px;
    height: 50px;
    border-radius: 25%;
    cursor: pointer;
    z-index: 1000;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    outline: none;
}

.mute-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Mobile devices */
@media (max-width: 767px) {
    .game-container {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .mute-btn {
        top: calc(20px + var(--safe-area-inset-top));
        right: calc(20px + var(--safe-area-inset-right));
    }
}

/* Tablets and desktops */
@media (min-width: 768px) {
    .game-container {
        border-radius: 20px;
        border: 10px solid #333;
        box-shadow: 0 0 0 4px #70c5ce, 0 0 0 8px #000, 0 0 20px rgba(0,0,0,0.5);
    }
    
    /* Add a nice background pattern for the page */
    body {
        background: repeating-linear-gradient(
            45deg,
            #1a1a1a,
            #1a1a1a 10px,
            #222 10px,
            #222 20px
        );
    }
}

/* Splash Screen */
#splash-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1677dd, #1cccab);
    z-index: 300;
    text-align: center;
    padding: 20px;
    color: #fff;
    text-shadow: 3px 3px 0 #000;
}

.game-title {
    font-size: 1.8em;
    margin-bottom: 10px;
    animation: bounce 1s infinite alternate;
}

.game-subtitle {
    font-size: 0.8em;
    margin-bottom: 60px;
    color: #ffeb3b;
    line-height: 1.6em;
}

.game-pesan {
    font-size: 0.7em;
    margin-bottom: 20px;
    color: #ffeb3b;
}

/* Flying bird animation */
@keyframes float {
    0%, 100% { transform: translateY(0) rotate(5deg); }
    50% { transform: translateY(-20px) rotate(-5deg); }
}

.flying-bird {
    position: absolute;
    top: 48%;
    left: 28%;
    transform: translateX(-50%);
    width: 90px;
    height: 90px;
    animation: float 3s ease-in-out infinite;
    z-index: 5;
}

.flying-bird img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.3));
}

.press-start {
    font-size: 0.8em;
    padding: 20px 15px;
    background: #ff4081;
    border: 4px solid #000;
    color: white;
    cursor: pointer;
    animation: blink 1.5s infinite;
    box-shadow: 4px 4px 0 #000;
    margin-top: 75px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

#start-screen, #game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(55, 102, 130, 0.7);
    color: white;
    z-index: 200;
    text-align: center;
    padding: 20px;
    text-shadow: 2px 2px 0 #000;
}

#game-over { 
    display: none;
    z-index: 1000; /* Higher z-index to ensure it's above other elements */
    position: relative;
}

#restart-btn {
    padding: 15px 30px;
    font-size: 1.2em;
    background: #ffd700;
    border: 4px solid #000;
    color: #000;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    z-index: 1001; /* Higher than game-over container */
    position: relative;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

h1, h2 { 
    margin-bottom: 20px; 
    font-size: 1.5em; 
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5); 
}

p { 
    margin-bottom: 30px; 
    font-size: 1.2em; 
}

button { 
    padding: 10px 30px; 
    font-size: 1.2em; 
    background: #3ed7d7; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    transition: background 0.3s; 
    margin-top: 10px;
}

button:hover { 
    background: #ffc107; 
}

.ground { 
    position: absolute; 
    bottom: 0; 
    width: 100%; 
    height: 40px; 
    background-color: #8B4513;
    background-image: 
        linear-gradient(45deg, #8B4513 25%, #9c5a2c 25%, #9c5a2c 50%, #8B4513 50%, #8B4513 75%, #9c5a2c 75%, #9c5a2c 100%);
    background-size: 20px 20px;
    z-index: 5;
    border-top: 4px solid #5c2d09;
}

/* 8-bit trees with smooth animation */
@keyframes treeMove {
    0% {
        transform: translateX(0);
        animation-timing-function: linear;
    }
    100% {
        transform: translateX(-50%);
        animation-timing-function: linear;
    }
}

.trees {
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 2500%;
    height: 250px;
    background-image: url('../images/trees.png');
    background-size: auto 100%;
    background-repeat: repeat-x;
    background-position: 0 100%;
    animation: treeMove 60s linear infinite;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); /* Smooth easing */
    z-index: 1;
    pointer-events: none;
    opacity: 0.9;
    image-rendering: pixelated;
    will-change: transform;
    backface-visibility: hidden; /* Prevents flickering */
    transform: translate3d(0, 0, 0); /* Hardware acceleration */
}

/* Seamless looping with smooth transition */
.trees::after {
    content: '';
    position: absolute;
    top: 0;
    left: 85%;
    width: 100%;
    height: 100%;
    background-image: inherit;
    background-size: inherit;
    background-repeat: inherit;
    background-position: inherit;
    backface-visibility: hidden;
}

.obstacle {
    position: absolute;
    width: 80px;
    background: #4CAF50;
    border: 5px solid #2E7D32;
    z-index: 3; /* Ensure obstacles are above trees */
}

@media (max-width: 600px) {
    .game-container { 
        max-width: 100%; 
        height: 100vh; 
        max-height: 100%; 
        touch-action: manipulation;
    }
    #bird { 
        width: 110px !important; 
        height: 75px !important; 
    }
    .obstacle { 
        width: 80px; 
        border-radius: 5px;
    }
    h1 { 
        font-size: 1.5em; 
    }
    h2 { 
        font-size: 1.3em; 
        margin-bottom: 30px;
        letter-spacing: -2.5px;
    }
    .flying-bird {
        width: 160px !important;
        height: 100px !important;
    }
    #restart-btn {
        padding: 15px 30px;
        font-size: 1em;
        z-index: 300;
        position: relative;
        -webkit-tap-highlight-color: transparent;
    }
    #game-over {
        z-index: 250;
        pointer-events: auto; /* Make sure it can receive touch events */
    }
    #final-score {
        font-size: 25px;
    }
}
