:root {
    --bg-color: #050505;
    --pac-yellow: #FFFF00;
    --pac-pink: #FFB8FF; 
    --neon-blue: #2121de;
    --text-white: #dedede;
    --danger-red: #ff0000;
    --hud-green: #00ff00;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #000; /* Outer background */
    font-family: 'Press Start 2P', cursive;
    color: var(--text-white);
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
}

/* --- MOBILE MODE LOCK --- */
body.mobile-mode {
    overflow: hidden; 
    touch-action: none; 
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

#game-container { 
    position: relative; 
    display: flex;
    justify-content: center;
    /* Forces the game to stick to the very top edge of the browser window */
    align-items: flex-start; 
    width: 100%; 
    height: 100%; 
}

/* --- THE SCREEN (Fixed Internal Resolution) --- */
#screen {
    width: 960px;  
    height: 720px; 
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden;
    /* Anchors the zoom scaling to the top so it perfectly stretches downward */
    transform-origin: top center; 
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    flex-shrink: 0;
}

canvas { display: block; width: 100%; height: 100%; outline: none; }

/* --- TOGGLE BUTTON --- */
#mobile-btn {
    position: fixed;
    top: 15px; left: 15px; 
    z-index: 2000;
    background: #222;
    color: white;
    border: 2px solid var(--pac-yellow);
    font-size: 10px;
    padding: 8px 12px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
}
body.mobile-mode #mobile-btn { display: none; }

/* --- MOBILE CONTROLS OVERLAY --- */
#mobile-controls {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; 
    z-index: 3000;
    display: none; 
    justify-content: space-between;
    align-items: flex-end;
    padding: 20px;
    box-sizing: border-box;
}

body.mobile-mode #mobile-controls {
    display: flex;
}

.mobile-control-btn {
    pointer-events: auto; 
    width: 60px; height: 60px;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 50%;
    color: white;
    font-size: 20px;
    display: flex; justify-content: center; align-items: center;
    user-select: none;
    backdrop-filter: blur(4px);
    transition: transform 0.1s, background 0.1s;
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
}
.mobile-control-btn:active {
    background: rgba(255,255,255,0.4);
    transform: scale(0.95);
}
#mobile-action-btn { width: 80px; height: 80px; font-size: 10px; }

#mobile-dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-left: 20px;
    margin-bottom: 20px;
}
.dpad-row { display: flex; gap: 8px; }
#mobile-action { margin-right: 20px; margin-bottom: 20px; }

#ui-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 10;
    display: flex; flex-direction: column; justify-content: space-between;
}

/* Notifications */
#gamepad-notify {
    position: absolute; top: 100px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%;
}
.gp-toast {
    background: rgba(0, 50, 0, 0.9); border: 2px solid var(--hud-green); color: var(--hud-green);
    padding: 10px 20px; font-size: 10px; text-transform: uppercase;
    box-shadow: 0 0 10px var(--hud-green); animation: fadeUp 3s forwards;
}
@keyframes fadeUp {
    0% { opacity: 0; transform: translateY(20px); }
    10% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Scoreboard */
.score-board { display: flex; justify-content: space-around; padding-top: 10px; text-shadow: 2px 2px 0px #000; width: 100%; }
.score-box { text-align: center; }
.label { font-size: 14px; margin-bottom: 8px; color: #fff; }
#score-p1 { color: var(--pac-yellow); font-size: 20px; }
#score-p2 { color: var(--pac-pink); font-size: 20px; }
#high-score { color: #fff; font-size: 20px; }
.lives { margin-top: 8px; font-size: 14px; min-height: 14px; color: var(--pac-yellow); letter-spacing: 4px; }
#lives-p2 { color: var(--pac-pink); }

/* Menus (Main, Options, Help) */
#center-message, #options-menu, #help-menu {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    text-align: center; background: rgba(0, 0, 0, 0.95); padding: 40px;
    border: 4px double var(--neon-blue); pointer-events: auto;
    box-shadow: 0 0 20px var(--neon-blue), inset 0 0 20px rgba(33, 33, 222, 0.2);
    min-width: 400px;
    box-sizing: border-box;
}

#main-title {
    color: var(--pac-yellow); font-size: 35px; margin: 0 0 20px 0;
    text-shadow: 4px 4px var(--neon-blue); text-transform: uppercase;
}

#sub-message {
    font-size: 12px; color: #ffb8ae; margin-bottom: 20px; text-transform: uppercase;
    animation: pulse 1.5s infinite alternate;
}

#demo-countdown {
    color: var(--danger-red); font-size: 10px; margin-bottom: 10px; height: 15px; letter-spacing: 1px;
}
#demo-countdown.hidden, #options-menu.hidden, #help-menu.hidden { 
    visibility: hidden; pointer-events: none; opacity: 0; display: none; 
}

/* Buttons */
#mode-select { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-bottom: 20px; }

.menu-btn, .action-btn, #options-menu button, #help-menu button {
    background: none; border: none; font-family: 'Press Start 2P', cursive;
    color: #555; font-size: 14px; cursor: pointer; text-transform: uppercase; transition: all 0.1s ease;
}

.menu-btn.selected {
    color: var(--pac-yellow); text-shadow: 0 0 8px var(--pac-yellow); transform: scale(1.1);
}
.menu-btn.selected::before { content: "► "; }
.menu-btn.selected::after { content: " ◄"; }

.action-btn {
    border: 2px solid #555; padding: 10px 20px; color: #fff; margin-top: 10px; background: #222;
}
.action-btn.small-btn {
    font-size: 10px; padding: 8px 16px; margin-top: 5px; border-color: #333;
}
.action-btn:hover {
    border-color: var(--pac-yellow); color: var(--pac-yellow); background: #333;
}

/* Options Menu Specifics */
#options-menu { z-index: 20; display: flex; flex-direction: column; gap: 15px; border-color: var(--pac-pink); box-shadow: 0 0 20px var(--pac-pink); }
#options-menu h2 { color: var(--pac-pink); margin-bottom: 20px; font-size: 18px; }
.opt-row { display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: 12px; }
.opt-controls { display: flex; align-items: center; gap: 10px; }
.opt-row button { color: #fff; background: #333; padding: 5px 10px; min-width: 30px; }
.opt-row button:hover { background: #555; }
.opt-row span { color: var(--pac-yellow); min-width: 30px; text-align: center; }

#opt-algo-toggle, #opt-color-toggle { min-width: 120px; }

.controls-hint { border-top: 1px solid #333; padding-top: 15px; color: #888; font-size: 9px; line-height: 1.8; margin-top: 20px; }

/* Help Menu Specifics */
#help-menu { 
    z-index: 25; 
    border-color: var(--hud-green); 
    box-shadow: 0 0 20px var(--hud-green);
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

#help-menu h2 { color: var(--hud-green); margin-bottom: 20px; font-size: 18px; text-transform: uppercase; }

.help-content {
    text-align: left;
    overflow-y: auto;
    padding-right: 10px;
    flex-grow: 1;
    margin-bottom: 20px;
}

.help-section { margin-bottom: 25px; }
.help-section h3 { color: #fff; font-size: 12px; border-bottom: 1px solid #333; padding-bottom: 5px; margin-bottom: 10px; }
.help-section ul { list-style: none; padding: 0; margin: 0; }
.help-section li { font-size: 10px; line-height: 1.8; color: #aaa; margin-bottom: 5px; }
.help-section p { font-size: 10px; line-height: 1.6; color: #aaa; margin-bottom: 10px; }
.help-section .key { color: var(--pac-yellow); display: inline-block; width: 80px; }
.help-section .license { color: #666; font-size: 8px; margin-top: 15px; font-style: italic; }

.help-content::-webkit-scrollbar { width: 8px; }
.help-content::-webkit-scrollbar-track { background: #111; }
.help-content::-webkit-scrollbar-thumb { background: #333; border: 1px solid #555; }
.help-content::-webkit-scrollbar-thumb:hover { background: var(--hud-green); }

@keyframes pulse {
    0% { opacity: 1; text-shadow: 0 0 5px #ffb8ae; }
    100% { opacity: 0.6; text-shadow: none; }
}
