* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Press Start 2P', 'Orbitron', 'Courier New', monospace;
    background: linear-gradient(135deg, #0c0c1e 0%, #1a1a2e 50%, #16213e 100%);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 10px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    /* スマホでのスワイプ制御強化 */
    touch-action: pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.game-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    max-width: 100%;
    transform-origin: center center;
    transition: transform 0.3s ease;
}

.game-footer {
    text-align: center;
    margin-top: 10px;
}

.sound-toggle-btn {
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #ffffff;
    color: #ffffff;
    font-size: 0.8rem;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    display: block;
    width: 100%;
    text-align: center;
}

.sound-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.sound-toggle-btn:active {
    transform: scale(0.95);
}

.sound-toggle-btn.muted {
    color: #ff6666;
    border-color: #ff6666;
}

@media (max-width: 768px) {
    .sound-toggle-btn {
        display: block;
    }
}

.game-container {
    text-align: center;
    border: 2px solid #ffffff;
    border-radius: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.8);
    box-shadow: 
        0 0 20px rgba(255, 255, 255, 0.3),
        inset 0 0 20px rgba(255, 255, 255, 0.1);
    max-width: 100%;
    width: fit-content;
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* スマホでのタッチ操作制御 */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

.game-footer {
    text-align: center;
    max-width: 450px;
}

h1 {
    font-size: 1.6rem;
    text-shadow: 0 0 10px #ffffff;
    margin: 0;
    letter-spacing: 2px;
}

.top-stats {
    display: flex;
    justify-content: center;
    font-size: 0.8rem;
    gap: 5px;
    width: 100%;
}

.bottom-stats {
    display: flex;
    justify-content: center;
    font-size: 1rem;
    width: 100%;
}

.score, .base-damage {
    padding: 5px 10px;
}

.base-damage {
    color: #ff6666;
}


#gameCanvas {
    background: radial-gradient(ellipse at center, #000011 0%, #000000 100%);
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    touch-action: none; /* タッチジェスチャーを無効化 */
    -webkit-user-select: none;
    user-select: none; /* テキスト選択を無効化 */
    -webkit-touch-callout: none; /* 長押しメニューを無効化 */
    -webkit-tap-highlight-color: transparent; /* タップハイライトを無効化 */
    /* スマホでのドラッグ・スクロール防止 */
    -webkit-overflow-scrolling: auto;
    overscroll-behavior: none;
    /* タッチ遅延の除去 */
    -ms-touch-action: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

.controls {
    font-size: 0.8rem;
    color: #66ff66;
    line-height: 1.3;
    margin: 0;
}

.start-screen, .game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.60);
    padding: 40px;
    border: 2px solid #ffffff;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
    width: 393px;
    max-width: 393px;
}

.start-screen h2, .game-over h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #ffffff;
}

.start-screen p, .game-over p {
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.rules {
    margin: 20px 0;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
}

.rules p {
    margin: 8px 0;
    font-size: 0.9rem;
    color: #66ff66;
    line-height: 1.3;
}

button {
    font-family: 'Press Start 2P', 'Orbitron', 'Courier New', monospace;
    background: #222222;
    color: #ffffff;
    border: 2px solid #ffffff;
    padding: 12px 20px;
    font-size: 0.8rem;
    font-weight: normal;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 2px 2px 0px #666666;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

button:hover {
    background: #444444;
    color: #ffdd44;
    border-color: #ffdd44;
    box-shadow: 3px 3px 0px #888888;
    transform: translate(-1px, -1px);
}

button:active {
    background: #111111;
    box-shadow: 1px 1px 0px #333333;
    transform: translate(1px, 1px);
}

.hidden {
    display: none;
}

/* モバイル用自動スケーリング */
@media (max-width: 768px) and (orientation: portrait) {
    body {
        padding: 5px;
        justify-content: flex-start;
        min-height: 100vh;
    }
    
    .game-layout {
        gap: 8px;
        width: 100%;
    }
    
    .game-footer h1 {
        font-size: 1.2rem;
        margin-top: 5px;
    }
    
    .game-container {
        padding: 4px;
        gap: 4px;
    }
    
    .top-stats {
        gap: 10px;
        font-size: 0.7rem;
    }
    
    #gameCanvas {
        width: 100% !important;
        height: auto !important;
        max-width: 393px;
    }
    
    .start-screen, .game-over, .name-entry-screen, .ranking-screen, .loading-screen {
        font-size: 0.8rem;
        padding: 15px;
        max-width: 95%;
    }
    
    .start-screen h2, .game-over h2, .name-entry-screen h2, .ranking-screen h2, .loading-screen h2 {
        font-size: 1.2rem;
        margin-bottom: 10px;
    }
    
    .rules p {
        font-size: 0.7rem;
        line-height: 1.3;
        margin-bottom: 8px;
    }
    
    button {
        font-size: 0.7rem;
        padding: 8px 12px;
        margin: 4px;
    }
    
    .name-letters {
        gap: 15px;
        margin-bottom: 15px;
    }
    
    .letter {
        font-size: 1.5rem;
        padding: 12px 16px;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s ease;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    .letter:active {
        transform: scale(1.1);
        box-shadow: 0 0 15px rgba(255, 221, 68, 0.7);
    }
    
    .name-controls {
        font-size: 0.6rem;
        margin-top: 10px;
        margin-bottom: 15px;
    }
    
    #nameOkButton {
        font-size: 0.8rem;
        padding: 12px 24px;
        margin-top: 10px;
        background: #006600;
        border-color: #00ff00;
        color: #ffffff;
    }
    
    #nameOkButton:hover, #nameOkButton:active {
        background: #008800;
        border-color: #44ff44;
        color: #ffffff;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 2px;
        justify-content: center;
        min-height: 100vh;
    }
    
    .game-layout {
        gap: 5px;
        transform: scale(0.8);
    }
    
    .game-footer h1 {
        font-size: 1rem;
        margin-top: 2px;
    }
    
    .top-stats {
        font-size: 0.6rem;
        gap: 8px;
    }
    
    #gameCanvas {
        max-height: 70vh;
    }
}

/* 非常に小さな画面用 */
@media (max-height: 800px) {
    .game-layout {
        transform: scale(0.85);
    }
}

@media (max-height: 600px) {
    .game-layout {
        transform: scale(0.75);
    }
    
    body {
        padding: 2px;
    }
}

/* ローディング画面のスタイル */
.loading-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.90);
    color: #00ff00;
    border: 2px solid #00ff00;
    border-radius: 15px;
    padding: 40px;
    text-align: center;
    max-width: 393px;
    width: 90%;
    z-index: 1000;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #003300;
    border-top: 4px solid #00ff00;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-detail {
    font-size: 0.9rem;
    color: #00cc00;
    margin: 0;
}

/* ランキング関連のスタイル */
.name-entry-screen, .ranking-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.70);
    padding: 20px;
    border: 2px solid #ffffff;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
    max-width: 380px;
    width: 90%;
}

.name-entry-screen h2, .ranking-screen h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    text-shadow: 0 0 10px #ffffff;
    color: #ffdd44;
    word-break: break-word;
}

.name-input {
    margin: 20px 0;
}

.name-letters {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
}

.letter {
    font-size: 1.8rem;
    font-weight: bold;
    padding: 8px 12px;
    border: 2px solid #666666;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border-radius: 5px;
    min-width: 45px;
    text-align: center;
}

.letter.active {
    border-color: #ffdd44;
    background: rgba(255, 221, 68, 0.2);
    box-shadow: 0 0 10px rgba(255, 221, 68, 0.5);
    animation: letterBlink 1s infinite;
}

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

.name-controls {
    font-size: 0.8rem;
    color: #cccccc;
    line-height: 1.4;
}

.ranking-list {
    margin: 20px 0;
    text-align: left;
}

.ranking-header {
    display: grid;
    grid-template-columns: 60px 100px 1fr;
    gap: 20px;
    padding: 10px 0;
    border-bottom: 2px solid #ffffff;
    font-weight: bold;
    color: #ffdd44;
    text-align: center;
}

.ranking-entry {
    display: grid;
    grid-template-columns: 60px 100px 1fr;
    gap: 20px;
    padding: 8px 0;
    border-bottom: 1px solid #666666;
    text-align: center;
}

.ranking-entry:nth-child(1) { color: #ffdd44; } /* 1位 */
.ranking-entry:nth-child(2) { color: #cccccc; } /* 2位 */
.ranking-entry:nth-child(3) { color: #cd7f32; } /* 3位 */

.ranking-entry.current-score {
    background: rgba(255, 221, 68, 0.2);
    border: 1px solid #ffdd44;
    animation: scoreHighlight 2s infinite;
}

@keyframes scoreHighlight {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

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

.blink {
    animation: blink 1s infinite;
}

/* スマホ対応 */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    .game-layout {
        gap: 10px;
    }
    
    .game-container {
        padding: 5px;
        border-radius: 5px;
    }
    
    .game-footer {
        max-width: 350px;
    }
    
    h1 {
        font-size: 1.2rem;
        letter-spacing: 1px;
    }
    
    .top-stats, .bottom-stats {
        font-size: 0.8rem;
        gap: 3px;
    }
    
    .score, .base-damage {
        padding: 3px 8px;
        font-size: 0.7rem;
    }
    
    .controls {
        font-size: 0.7rem;
    }
}

/* スマートフォン画面幅対応 (393px基準) */
@media (max-width: 393px) {
    .game-layout {
        width: 100vw;
        margin: 0;
        padding: 0;
    }
    
    .game-container {
        width: 100%;
        max-width: 100%;
        padding: 0;
        margin: 0;
    }
    
    #gameCanvas {
        width: 100vw;
        height: auto;
        max-width: 100%;
    }
    
    .game-footer {
        margin-top: 5px;
    }
    
    .game-footer h1 {
        font-size: 0.9rem;
    }
}

/* 小さめのスマートフォン対応 */
@media (max-width: 360px) {
    .top-stats {
        font-size: 0.6rem;
        gap: 2px;
    }
    
    .score, .base-damage {
        padding: 2px 6px;
        font-size: 0.65rem;
    }
}
    .start-screen, .game-over, .name-entry-screen, .ranking-screen {
        padding: 15px;
        width: 350px;
        max-width: 95%;
    }
    
    .start-screen h2, .game-over h2, .name-entry-screen h2, .ranking-screen h2, .loading-screen h2 {
        font-size: 1.2rem;
        margin-bottom: 10px;
    }
    
    button {
        padding: 10px 16px;
        font-size: 0.7rem;
        box-shadow: 1px 1px 0px #666666;
    }
    
    button:hover {
        box-shadow: 2px 2px 0px #888888;
    }
    
    .rules {
        margin: 15px 0;
        padding: 10px;
    }
    
    .rules p {
        margin: 6px 0;
        font-size: 0.75rem;
    }
    
    .name-letters {
        gap: 10px;
    }
    
    .letter {
        font-size: 1.3rem;
        padding: 10px 14px;
        min-width: 40px;
    }
    
    .name-controls {
        font-size: 0.65rem;
        margin: 8px 0;
    }
    
    #nameOkButton {
        font-size: 0.75rem;
        padding: 10px 20px;
        margin-top: 8px;
    }
}