Styles the nokia-phone div with padding, background color, border-radius, and shadow to look like a phone body.
Styles the nokia-screen and its border with the characteristic greenish background (#c7f0d8) and dark text/element color (#43523d).
Sets image-rendering: pixelated on the canvas to ensure sharp, blocky pixels when scaling isn't 1:1 (important for the retro look).
Uses a monospace font as a fallback for a blocky feel.
Styles the overlay screens for Game Over and Start messages.
Styles the placeholder buttons.
JavaScript Logic (<script> block):
Canvas Setup: Gets the canvas element and its 2D drawing context.
Constants: Defines colors, grid size, canvas dimensions, and grid dimensions.
Game State Variables: Declares variables to hold the snake's position (array of objects), food position, direction (dx, dy), score, high score (using localStorage), game speed, and flags (changingDirection, gameStarted, gameOver).
initGame(): Resets all game variables to their starting state, places the initial snake, creates the first food item, hides overlays, and starts the main game loop.
main(): The core game loop function. Uses setTimeout to run at a specific interval (). It clears the previous timeout, checks for game over, calls functions to clear the canvas, draw food, move the snake, draw the snake, and then schedules itself to run again.
This comprehensive file provides a functional and visually reminiscent Nokia Snake experience directly in a web browser.
clearCanvas(): Fills the canvas with the background color.
drawRect(): Helper to draw a single colored square on the grid.
drawSnakePart(), drawSnake(), drawFood(): Use drawRect to render the game elements.
moveSnake(): Calculates the new head position, checks for collisions, checks if food was eaten (grows snake, increases score, generates new food), or removes the tail segment if no food was eaten.
changeDirection(): Handles keydown events. It checks which arrow key was pressed, prevents immediate 180-degree turns, and updates the dx and dy velocity variables. It also includes the logic to start/restart the game on 'Enter'. The changingDirection flag prevents multiple inputs before the next game tick.
createFood(): Generates random coordinates for the food, ensuring it doesn't spawn directly on top of the snake.
hasGameEnded(): Checks for collisions with the walls or the snake's own body.
showGameOver(): Stops the game loop, updates the high score if necessary, and displays the game over overlay.
Event Listener: Attaches the changeDirection function to the keydown event for the whole document.
Initial State: Calls drawInitialScreen and waits for the 'Enter' key to start the game via the changeDirection handler.