body {
    background-color: #222;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

#game-container {
    position: relative;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

canvas {
    background-color: #1a1a1a;
    border: 2px solid #444;
    border-radius: 4px;
    display: block;
}

#ui-layer {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
}

#score {
    color: #4CAF50;
}

#lives {
    color: #f44336;
}

#game-over-screen {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    padding: 40px;
    border: 2px solid #fff;
    border-radius: 8px;
    min-width: 300px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

#game-over-screen h1 {
    color: #f44336;
    margin-top: 0;
    font-size: 48px;
    margin-bottom: 20px;
}

#game-over-screen p {
    font-size: 24px;
    margin-bottom: 30px;
}

#restart-btn {
    background-color: #2196F3;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 18px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

#restart-btn:hover {
    background-color: #1976D2;
}

#pause-screen {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(0, 0, 0, 0.8);
    padding: 40px;
    border: 2px solid #fff;
    border-radius: 8px;
    min-width: 300px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    z-index: 100;
}

#pause-screen h1 {
    color: #FFC107;
    margin-top: 0;
    font-size: 48px;
    margin-bottom: 20px;
}

#pause-screen p {
    font-size: 24px;
    color: #fff;
}

#input-preview {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 32px;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 8px;
    min-width: 100px;
    text-align: center;
    border: 1px solid #555;
    text-shadow: 1px 1px 2px black;
}

#virtual-keyboard {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #111;
    padding: 10px 5px;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.5);
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.keyboard-row {
    display: flex;
    justify-content: center;
    width: 100%;
    gap: 4px;
}

.key {
    background: #333;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
    flex: 1;
    max-width: 40px;
    height: 45px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    touch-action: manipulation;
    padding: 0;
}

.key:active {
    background: #555;
    transform: translateY(1px);
}

.key.space-key {
    max-width: 200px;
    flex: 3;
}

.key.esc-key {
    background-color: #f44336;
    /* Red color for visual distinction */
    max-width: 60px;
    flex: 1;
    font-size: 14px;
}

@media (max-width: 800px) {
    body {
        flex-direction: column;
        justify-content: flex-start;
        padding-top: 10px;
    }

    #game-container {
        /* Fit within the viewport minus keyboard space */
        width: 100%;
        height: auto;
        display: flex;
        justify-content: center;
        box-shadow: none;
    }

    canvas {
        /* Maintain aspect ratio but fit width */
        width: 100% !important;
        height: auto !important;
        max-height: calc(100vh - 250px);
        /* Reserve space for keyboard */
        object-fit: contain;
    }

    #ui-layer {
        font-size: 18px;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    #virtual-keyboard {
        display: flex;
    }

    #input-preview {
        bottom: 240px;
        /* Position above keyboard */
        font-size: 24px;
        padding: 5px 15px;
    }
}