:root {
    --bg-dark: #000000;
    --text-light: #ffffff;
    --pacman-yellow: #ffff00;
    --ghost-red: #ff0000;
    --ghost-pink: #ffb8ff;
    --ghost-cyan: #00ffff;
    --ghost-orange: #ffb852;
    --wall-blue: #2121de;
    --font-primary: 'Outfit', sans-serif;
    --font-retro: 'Press Start 2P', cursive;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: var(--font-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    touch-action: none;
    /* Prevent scroll on mobile */
}

/* --- Persistent Quit Button --- */
.quit-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 10px 15px;
    background-color: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    text-decoration: none;
    font-family: var(--font-retro);
    font-size: 0.7rem;
    border-radius: 8px;
    z-index: 100;
    transition: all 0.2s;
}

.quit-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: white;
}

.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    padding: 10px;
}

/* UI Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 448px;
    margin-bottom: 10px;
    font-family: var(--font-retro);
    font-size: 0.8rem;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-box .label {
    color: #fff;
    margin-bottom: 5px;
    font-size: 0.6rem;
}

.stat-box .value {
    color: var(--pacman-yellow);
}

.lives-container {
    display: flex;
    gap: 5px;
}

.life-icon {
    width: 15px;
    height: 15px;
    background-color: var(--pacman-yellow);
    border-radius: 50%;
    clip-path: polygon(100% 74%, 44% 48%, 100% 21%, 100% 0, 74% 0, 0 0, 0 100%, 100% 100%);
    transform: rotate(0deg);
}

/* Game Area */
.game-wrapper {
    position: relative;
    background-color: #000;
    border: 2px solid var(--wall-blue);
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(33, 33, 222, 0.4);
    overflow: hidden;
    width: 448px;
    height: 496px;
}

canvas {
    display: block;
    image-rendering: pixelated;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.logo {
    font-family: var(--font-retro);
    font-size: 2.5rem;
    margin-bottom: 2rem;
}

.glow-yellow {
    color: var(--pacman-yellow);
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

.glow-red {
    color: var(--ghost-red);
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

.btn {
    font-family: var(--font-retro);
    padding: 15px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    margin-bottom: 15px;
    transition: transform 0.1s, filter 0.2s;
    text-transform: uppercase;
    text-decoration: none;
    display: inline-block;
}

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

.btn-yellow {
    background-color: var(--pacman-yellow);
    color: #000;
    font-weight: 800;
}

.btn-yellow:hover {
    box-shadow: 0 0 15px rgba(255, 255, 0, 0.5);
}

.btn-secondary {
    background-color: transparent;
    border: 2px solid #555;
    color: #fff;
    padding: 10px 20px;
    font-size: 0.8rem;
}

.btn-secondary:hover {
    border-color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
}

.instruction-text {
    color: #aaa;
    margin-top: 1rem;
    text-align: center;
    font-size: 0.9rem;
}

/* Mobile Controls */
.mobile-controls {
    display: none;
    width: 100%;
    max-width: 448px;
    margin-top: 20px;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.pause-btn {
    position: absolute;
    top: 0;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    cursor: pointer;
}

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

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

.center-row {
    align-items: center;
}

.dpad-center {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
}

.dpad-btn {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
}

.dpad-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

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

    .game-wrapper {
        width: 100%;
        max-width: 448px;
        /* maintain aspect ratio essentially */
        height: auto;
        aspect-ratio: 448 / 496;
    }

    canvas {
        width: 100%;
        height: 100%;
    }
}