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

html {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Segoe UI', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    touch-action: none;
    position: fixed;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overscroll-behavior: none;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* 動的ビューポート高さ（キーボード考慮） */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* タイトル画面 */
#titleScreen {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: white;
    overflow: hidden;
    overscroll-behavior: none;
}

.title-container {
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
}

.game-title {
    font-size: 5.5rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    background: linear-gradient(135deg, #4CAF50 0%, #45B7D1 50%, #5F27CD 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(76, 175, 80, 0.3);
    animation: titleGlow 3s ease-in-out infinite;
    margin-bottom: 0.5rem;
}

@keyframes titleGlow {
    0%, 100% {
        filter: brightness(1) drop-shadow(0 0 20px rgba(76, 175, 80, 0.4));
    }
    50% {
        filter: brightness(1.2) drop-shadow(0 0 40px rgba(76, 175, 80, 0.6));
    }
}

.title-subtitle {
    font-size: 1.2rem;
    letter-spacing: 0.3em;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 300;
    text-transform: uppercase;
}

.input-container {
    margin-bottom: 2rem;
}

#playerName {
    padding: 1.3rem 2.5rem;
    font-size: 1.4rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    color: white;
    text-align: center;
    width: 360px;
    max-width: 90vw;
    outline: none;
    transition: all 0.3s;
}

#playerName::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#playerName:focus {
    border-color: #4CAF50;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
    scroll-margin-top: 0;
    scroll-margin-bottom: 0;
}

.start-button {
    padding: 1.5rem 4.5rem;
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 8px 30px rgba(76, 175, 80, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.start-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(76, 175, 80, 0.6);
    background: linear-gradient(135deg, #45a049 0%, #4CAF50 100%);
}

.start-button:active {
    transform: translateY(-1px);
}

.instructions {
    margin-top: 3rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem 2rem;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.instruction-label {
    font-weight: 700;
    color: #4CAF50;
    min-width: 80px;
    font-size: 1.1rem;
}

.instruction-text {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.05rem;
}

/* ゲーム画面 */
#gameScreen {
    background: #1a1a2e;
    position: fixed;
    top: 0;
    left: 0;
}

.debug-button {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 10;
    background: rgba(255, 100, 100, 0.3);
    border: 2px solid rgba(255, 100, 100, 0.5);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.2s;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.debug-button:hover {
    background: rgba(255, 100, 100, 0.5);
    border-color: rgba(255, 100, 100, 0.8);
    transform: scale(1.05);
}

.debug-button:active {
    transform: scale(0.95);
}

#gameCanvas {
    display: block;
    background: #16213e;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    outline: none;
}

#gameUI {
    position: absolute;
    top: 15px;
    left: 15px;
    color: white;
    z-index: 10;
    font-size: 0.9rem;
    opacity: 0.7;
}

#score {
    background: transparent;
    padding: 6px 12px;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

#leaderboard {
    background: transparent;
    padding: 6px 8px;
    width: auto;
    min-width: 130px;
}

.leaderboard-title {
    font-weight: 700;
    margin-bottom: 4px;
    font-size: 0.75rem;
    color: #ffd700;
    text-align: left;
    letter-spacing: 0.05em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

#leaderboardList {
    font-size: 0.72rem;
    line-height: 1.4;
}

.leaderboard-item {
    margin: 2px 0;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.player-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.player-score {
    min-width: 35px;
    text-align: right;
    font-weight: 600;
}

/* ゲームオーバー画面 */
#gameOverScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(10, 10, 20, 0.4);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    color: white;
    z-index: 1000;
    display: none;
}

.gameover-container {
    text-align: center;
}

.gameover-title {
    font-size: 4rem;
    font-weight: 900;
    margin-bottom: 2rem;
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.05em;
}

.final-stat {
    font-size: 1.8rem;
    margin: 1.2rem 0;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 1.4rem 3rem;
    border-radius: 25px;
    font-weight: 600;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.restart-button {
    margin-top: 2rem;
    padding: 1.5rem 4.5rem;
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 8px 30px rgba(76, 175, 80, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.restart-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(76, 175, 80, 0.6);
}

.restart-button:active {
    transform: translateY(-1px);
}

/* スマホ対応 */
@media (max-width: 768px) {
    .game-title {
        font-size: 3.5rem;
    }
    
    .title-subtitle {
        font-size: 1.1rem;
    }
    
    .start-button, .restart-button {
        font-size: 1.5rem;
        padding: 1.3rem 3.5rem;
    }
    
    #playerName {
        width: 300px;
        font-size: 1.3rem;
        padding: 1.1rem 2rem;
    }
    
    #gameUI {
        top: 10px;
        left: 10px;
        font-size: 0.85rem;
    }
    
    .debug-button {
        top: 10px;
        right: 10px;
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    
    #leaderboard {
        min-width: 120px;
    }
    
    .gameover-title {
        font-size: 3rem;
    }
    
    .final-stat {
        font-size: 1.5rem;
        padding: 1.2rem 2.2rem;
    }
    
    .instructions {
        margin-top: 2rem;
    }
    
    .instruction-item {
        padding: 0.8rem 1.5rem;
    }
    
    .instruction-label {
        font-size: 1rem;
        min-width: 70px;
    }
    
    .instruction-text {
        font-size: 0.95rem;
    }
}