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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #fff;
}

.container {
    text-align: center;
}

.screen {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.hidden {
    display: none !important;
}

#startScreen h1,
#gameOverScreen h1 {
    font-size: 3rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

#startScreen p,
#gameOverScreen p {
    font-size: 1.2rem;
    margin: 10px 0;
    opacity: 0.9;
}

button {
    background: #fff;
    color: #667eea;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    margin-top: 20px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

button:active {
    transform: translateY(0);
}

.score-board {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    font-size: 1.5rem;
    font-weight: bold;
}

.score, .speed {
    background: rgba(255, 255, 255, 0.2);
    padding: 10px 20px;
    border-radius: 10px;
}

#gameCanvas {
    background: #2a2a2a;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    display: block;
    margin: 0 auto;
    /* Internal resolution stays 600×600 (the width/height attrs); CSS scales the
       display so the board fits narrow phone screens instead of overflowing. */
    width: min(600px, 90vw);
    height: auto;
    aspect-ratio: 1 / 1;
    max-width: 100%;
    touch-action: none;
}

.final-score {
    font-size: 2rem !important;
    color: #ffd700;
    margin: 20px 0 !important;
}

#gameOverReason {
    font-size: 1.1rem !important;
    color: #ff6b6b;
    margin-top: 10px !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

kbd {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.9em;
    font-family: inherit;
}

/* The mobile hint and d-pad only make sense on touch devices. */
.touch-hint {
    display: none;
    color: #ffe08a;
}

.dpad {
    display: none;
    margin: 18px auto 0;
    width: 190px;
    height: 190px;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    touch-action: none;
}

.dpad-btn {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-size: 1.6rem;
    line-height: 1;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.dpad-btn:active {
    background: #fff;
    transform: scale(0.94);
}

.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; }

@media (pointer: coarse) {
    .touch-hint { display: block; }
    .dpad { display: grid; }
}

@media (max-width: 640px) {
    .screen { padding: 16px; }
    #startScreen h1,
    #gameOverScreen h1 { font-size: 2rem; }
    #startScreen p,
    #gameOverScreen p { font-size: 1rem; }
    .score-board { font-size: 1.1rem; margin-bottom: 12px; }
    .score, .speed { padding: 8px 14px; }
}
