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

body {
    font-family: 'Arial', sans-serif;
    background-color: #000;
    color: #fff;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.game-container {
    position: relative;
    max-width: 100vw;
    max-height: 100vh;
    background-color: #111;
    border: 2px solid #333;
    border-radius: 8px;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 800px;
    max-height: 600px;
    background-color: #001122;
}

.touch-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: none;
    z-index: 100;
}

.touch-controls.hidden {
    display: none !important;
}

.shoot-button {
    background-color: rgba(255, 255, 255, 0.8);
    color: #000;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
}

.shoot-button:active {
    background-color: rgba(255, 255, 255, 0.6);
    transform: scale(0.95);
}

/* モバイル端末での表示調整 */
@media (max-width: 768px) {
    body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        /* ブラウザURL表示を隠すためのスタイル */
        position: fixed;
        width: 100vw;
        height: 100vh;
    }
    
    .game-container {
        width: 100vw;
        /* ブラウザのURL表示領域を考慮 */
        height: 100vh;
        height: calc(100vh - env(safe-area-inset-top));
        border: none;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
    }
    
    #gameCanvas {
        width: 100vw;
        height: 100vh;
        height: calc(100vh - env(safe-area-inset-top));
        object-fit: contain;
        background-color: #001122;
    }
    
    .touch-controls {
        display: block;
    }
}

/* 縦向きモバイル - 横幅基準でアスペクト比保持 */
@media (max-width: 768px) and (orientation: portrait) {
    .game-container {
        /* 画面幅に合わせてアスペクト比4:3で高さを計算、最大90vhに制限 */
        width: 100vw;
        height: min(75vw, 90vh); /* 100vw * (3/4) = 75vw、ただし最大90vh */
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
    
    #gameCanvas {
        /* 画面幅基準でアスペクト比を保持、最大90vhに制限 */
        width: 100vw;
        height: min(75vw, 90vh);
        object-fit: contain;
    }
    
    .touch-controls {
        /* 画面下から固定距離に配置 */
        bottom: 5vh;
        right: 5vw;
    }
    
    .shoot-button {
        width: 12vw;
        height: 12vw;
        font-size: 2.5vw;
    }
}

/* 横向きモバイル - 画面下部切れを防ぐ */
@media (max-width: 768px) and (orientation: landscape) {
    .game-container {
        /* 画面下部10%が見えない問題を考慮してさらに縮小 */
        height: 60vh;
        top: 50%;
        transform: translateY(-50%);
    }
    
    #gameCanvas {
        height: 60vh;
        width: 100vw;
        object-fit: contain;
    }
    
    .touch-controls {
        bottom: 15vh;
        right: 3vw;
    }
    
    .shoot-button {
        width: 6vh;
        height: 6vh;
        font-size: 1.5vh;
    }
}

/* タッチ操作の改善 */
@media (hover: none) and (pointer: coarse) {
    .touch-controls {
        display: block;
    }
}

/* レスポンシブデザイン */
@media (max-aspect-ratio: 4/3) {
    .game-container {
        width: 100vw;
        height: 75vw;
    }
}

@media (min-aspect-ratio: 4/3) {
    .game-container {
        width: 133.33vh;
        height: 100vh;
    }
}