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

body {
    font-family: 'Bangers', cursive;
    min-height: 100vh;
    background: linear-gradient(180deg, #0a0a1a 0%, #000033 50%, #00001a 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.game-container {
    width: 100%;
    max-width: 500px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 0 10px;
}

h1 {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(16px, 4vw, 24px);
    color: #FFD700;
    text-shadow: 2px 2px 0 #FF4444;
}

.score, .lives {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(10px, 2.5vw, 14px);
    color: #fff;
}

#game-board {
    width: 100%;
    aspect-ratio: 1;
    max-width: 400px;
    max-height: 400px;
    background: #000;
    border: 4px solid #1919A6;
    border-radius: 10px;
    position: relative;
    display: grid;
    grid-template-columns: repeat(21, 1fr);
    grid-template-rows: repeat(21, 1fr);
}

.cell {
    display: flex;
    justify-content: center;
    align-items: center;
}

.wall {
    background: #1919A6;
    border-radius: 2px;
}

.dot {
    width: 30%;
    height: 30%;
    background: #FFB8AE;
    border-radius: 50%;
}

.power-pellet {
    width: 60%;
    height: 60%;
    background: #FFB8AE;
    border-radius: 50%;
    animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(0.6); opacity: 0.7; }
}

.pacman {
    width: 80%;
    height: 80%;
    background: #FFD700;
    border-radius: 50%;
    position: relative;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    transition: transform 0.1s;
}

.pacman.right { transform: rotate(0deg); }
.pacman.down { transform: rotate(90deg); }
.pacman.left { transform: rotate(180deg); }
.pacman.up { transform: rotate(270deg); }

.ghost {
    width: 80%;
    height: 80%;
    border-radius: 50% 50% 0 0;
    position: relative;
}

.ghost::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30%;
    background: inherit;
    clip-path: polygon(0% 100%, 20% 50%, 40% 100%, 60% 50%, 80% 100%, 100% 50%);
}

.ghost.red { background: #FF0000; }
.ghost.pink { background: #FFB8FF; }
.ghost.cyan { background: #00FFFF; }
.ghost.orange { background: #FFB852; }

.ghost.scared {
    background: #2222FF;
    animation: shake 0.3s ease-in-out infinite;
}

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

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(180deg, #1919A6 0%, #000033 100%);
    border: 4px solid #FFD700;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
}

.modal-content h2 {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(18px, 5vw, 28px);
    color: #FFD700;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 #FF4444;
}

.modal-content p {
    font-size: clamp(14px, 3vw, 18px);
    color: #fff;
    margin-bottom: 30px;
}

.modal-content button {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(12px, 3vw, 16px);
    padding: 15px 30px;
    background: linear-gradient(180deg, #FFD700 0%, #FF8800 100%);
    border: none;
    border-radius: 10px;
    color: #000;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
}

.modal-content button:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.controls {
    margin-top: 20px;
    display: none;
}

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

.d-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.d-row {
    display: flex;
    gap: 5px;
}

.d-btn {
    width: 60px;
    height: 60px;
    font-size: 24px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s;
}

.d-btn:active {
    background: rgba(255, 215, 0, 0.4);
}

.sound-toggle {
    position: fixed;
    top: 15px;
    right: 15px;
}

#sound-btn {
    font-size: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 10px;
}

@media (min-width: 769px) {
    .controls {
        display: none;
    }
}
