* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Courier New', monospace;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 960px;
    height: 720px;
    border: 4px solid #444;
    background: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#ui-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    color: #fff;
    font-size: 16px;
    text-shadow: 2px 2px #000;
    pointer-events: none;
    z-index: 10;
    gap: 15px;
}

#weapon {
    color: #ff0;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    text-align: center;
}

.screen h1 {
    font-size: 48px;
    color: #ff0;
    text-shadow: 3px 3px #f00;
    margin-bottom: 20px;
}

.screen p {
    font-size: 20px;
    margin: 10px 0;
}

.screen.controls {
    font-size: 14px;
    color: #aaa;
    margin-top: 40px;
}

.hidden {
    display: none !important;
}

.mobile-text {
    display: none;
}

body.is-mobile .mobile-text {
    display: block;
}

body.is-mobile .desktop-text {
    display: none;
}

#touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-between;
    align-items: flex-end;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    pointer-events: none;
    z-index: 100;
}

#d-pad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 60px);
    gap: 5px;
    pointer-events: auto;
}

.d-button {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: white;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    cursor: pointer;
    transition: background 0.1s;
}

.d-button:active, .d-button.active {
    background: rgba(255, 255, 255, 0.4);
}

.d-button[data-direction="up"] {
    grid-column: 2;
    grid-row: 1;
}

.d-row {
    grid-column: 1 / span 3;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(3, 60px);
    gap: 5px;
}

.d-button[data-direction="left"] {
    grid-column: 1;
}

.d-button[data-direction="down"] {
    grid-column: 2;
}

.d-button[data-direction="right"] {
    grid-column: 3;
}

#shoot-button {
    width: 100px;
    height: 100px;
    background: rgba(255, 0, 0, 0.4);
    border: 3px solid rgba(255, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
    color: white;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    cursor: pointer;
    pointer-events: auto;
    transition: background 0.1s;
}

#shoot-button:active, #shoot-button.active {
    background: rgba(255, 0, 0, 0.6);
}

body.is-mobile #game-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border: none;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
}

body.is-mobile #touch-controls {
    display: flex;
}

body.is-mobile .screen h1 {
    font-size: 28px;
}

body.is-mobile .screen p {
    font-size: 14px;
}

body.is-mobile #ui-overlay {
    font-size: 12px;
    padding: 5px;
}

body.is-mobile .screen.controls {
    display: none;
}

body.is-mobile #d-pad {
    grid-template-columns: repeat(3, 55px);
    grid-template-rows: repeat(2, 55px);
}

body.is-mobile .d-button {
    width: 55px;
    height: 55px;
    font-size: 20px;
}

body.is-mobile #shoot-button {
    width: 90px;
    height: 90px;
    font-size: 14px;
}

@media (max-width: 768px) {
    #game-container {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border: none;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
    }

    .screen h1 {
        font-size: 28px;
    }

    .screen p {
        font-size: 14px;
    }

    #ui-overlay {
        font-size: 12px;
        padding: 5px;
    }

    .screen.controls {
        display: none;
    }

    #d-pad {
        grid-template-columns: repeat(3, 55px);
        grid-template-rows: repeat(2, 55px);
    }

    .d-button {
        width: 55px;
        height: 55px;
        font-size: 20px;
    }

    #shoot-button {
        width: 90px;
        height: 90px;
        font-size: 14px;
    }
}
