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

#game-container {
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    border: 2px solid #333;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex: 1;
    position: relative;
    overflow: hidden;
}

.ad-container {
    width: 100%;
    max-width: 970px;
    max-height: 90px;
    text-align: center;
    margin: 0 auto;
    overflow: hidden;
    flex-shrink: 0;
}

.ad-container ins.adsbygoogle {
    display: block;
    width: 100%;
    max-height: 90px;
}

@media (max-height: 500px), (max-width: 768px) {
    .ad-container {
        max-height: 50px;
    }
    .ad-container ins.adsbygoogle {
        max-height: 50px;
    }
}

/* Collapse ad container completely if Google marks it as unfilled */
ins.adsbygoogle[data-ad-status="unfilled"],
.ad-container:has(ins[data-ad-status="unfilled"]) {
    display: none !important;
}

canvas {
    background-color: #000;
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#dpad-container {
    position: absolute;
    bottom: 30px;
    right: 30px;
    display: grid;
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 60px 60px 60px;
    gap: 10px;
    opacity: 0.6;
    z-index: 100;
}

#dpad-up {
    grid-column: 2;
    grid-row: 1;
}

#dpad-left {
    grid-column: 1;
    grid-row: 2;
}

#dpad-right {
    grid-column: 3;
    grid-row: 2;
}

#dpad-down {
    grid-column: 2;
    grid-row: 3;
}

.dpad-btn {
    background-color: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    color: white;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    cursor: pointer;
}

.dpad-btn:active,
.dpad-btn:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

#action-container {
    position: absolute;
    bottom: 30px;
    left: 30px;
    opacity: 0.6;
    z-index: 100;
}

.action-btn {
    background-color: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    color: white;
    font-size: 20px;
    font-weight: bold;
    width: 80px;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    cursor: pointer;
}

.action-btn:active,
.action-btn:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

#mute-container {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
    display: flex;
    gap: 10px;
}

.mute-btn {
    background-color: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    color: white;
    font-size: 20px;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.mute-btn:active,
.mute-btn:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

@media (orientation: landscape) and (max-width: 1023px) {
    #game-container {
        justify-content: flex-start;
        /* Align canvas to the left */
    }

    canvas {
        /* Restrict canvas width to leave room for controls on the right (approx 230px) */
        max-width: calc(100vw - 230px);
    }

    #dpad-container {
        transform: scale(0.8);
        transform-origin: bottom right;
        bottom: 15px;
        right: 15px;
    }

    #action-container {
        bottom: auto;
        left: auto;
        top: 20px;
        right: 20px;
    }

    #mute-container {
        top: 20px;
        right: 170px;
        left: auto;
        bottom: auto;
        flex-direction: column;
    }
}

@media (min-width: 1024px) {

    #dpad-container,
    #action-container {
        display: none;
    }
}