/* SECTION: CSS Reset and Base Styles – Foundation normalisation */
/*
 * Purpose: Resets browser defaults and establishes base styling.
 *
 * - **Box-sizing**: Border-box for predictable dimensions.
 * - **Margin/Padding**: Zeroed for clean slate.
 * - **Font stack**: System fonts with monospace fallback for retro feel.
 */

* {
    /* Purpose: Box model reset */
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* Purpose: Base font sizing and smoothing */
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    /* Purpose: Layout and atmospheric styling */
    background: #0a0a0a;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: 'Courier New', Courier, monospace;
    color: #00ff00;
    overflow: hidden;
}


/* SECTION: Game Arena – Main viewport container */
/*
 * Purpose: Centres the arcade cabinet vertically and horizontally.
 *
 * - **Flex centreing**: Both axes alignment.
 * - **Responsive padding**: Prevents edge touching on small viewports.
 * - **Z-index layering**: Ensures proper stacking context.
 */

#gameArena {
    /* Purpose: Layout centreing */
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    
    /* Purpose: Atmospheric background gradient */
    background: radial-gradient(ellipse at centre, #1a1a2e 0%, #0a0a0a 100%);
}


/* SECTION: Arcade Cabinet – Physical bezel styling */
/*
 * Purpose: Simulates the physical arcade machine housing.
 *
 * - **3D depth**: Multi-layer shadow for raised appearance.
 * - **Rounded corners**: Authentic cabinet aesthetic.
 * - **Inner shadow**: Creates recessed screen effect.
 */

.arcade-cabinet {
    /* Purpose: Structural container */
    position: relative;
    background: #1a1a2e;
    padding: 24px;
    border-radius: 12px;
    
    /* Purpose: 3D depth effects */
    box-shadow: 
        0 0 0 4px #2a2a3e,
        0 0 0 8px #1a1a2e,
        0 20px 60px rgba(0, 0, 0, 0.8),
        inset 0 0 100px rgba(0, 0, 0, 0.5);
    
    /* Purpose: Border styling */
    border: 2px solid #333;
}


/* SECTION: Screen Container – CRT monitor housing */
/*
 * Purpose: Contains canvas and visual effects layers.
 *
 * - **Relative positioning**: Anchor for absolute overlays.
 * - **Overflow hidden**: Clips scanlines to bounds.
 * - **Border radius**: Rounded CRT corners.
 */

.screen-container {
    /* Purpose: Layout and positioning context */
    position: relative;
    width: 400px;
    height: 600px;
    overflow: hidden;
    border-radius: 20px;
    
    /* Purpose: Screen bezel styling */
    background: #000;
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.9),
        0 0 0 12px #111,
        0 0 0 14px #333;
}


/* SECTION: Game Canvas – Rendering surface */
/*
 * Purpose: The HTML5 canvas element for game graphics.
 *
 * - **Pixelated rendering**: Sharp edges for retro sprites.
 * - **Block display**: Removes descender space.
 * - **Background**: Road base colour.
 */

#gameCanvas {
    /* Purpose: Display and rendering mode */
    display: block;
    width: 400px;
    height: 600px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    
    /* Purpose: Base background colour */
    background: #0d1f0d;
}


/* SECTION: Scanline Overlay – CRT monitor effect */
/*
 * Purpose: Simulates cathode ray tube scanlines.
 *
 * - **Pointer events**: Passes through to canvas.
 * - **Repeating gradient**: Horizontal line pattern.
 * - **Opacity**: Subtle effect, not overwhelming.
 */

.scanlines {
    /* Purpose: Positioning over canvas */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
    
    /* Purpose: Scanline pattern */
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0) 50%,
        rgba(0, 0, 0, 0.25) 50%
    );
    background-size: 100% 4px;
    
    /* Purpose: Screen curvature vignette */
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.7);
}


/* SECTION: Dashboard HUD – Score and speed display */
/*
 * Purpose: Heads-up display below the screen.
 *
 * - **Flex layout**: Even spacing between panels.
 * - **Monospace font**: Aligned numerical readouts.
 * - **Glowing text**: Phosphor glow effect.
 */

.dashboard {
    /* Purpose: Layout and spacing */
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 8px;
    border: 1px solid #333;
}

.hud-panel {
    /* Purpose: Individual gauge container */
    display: flex;
    flex-direction: column;
    align-items: centre;
    gap: 4px;
}

.hud-label {
    /* Purpose: Label typography */
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    color: #666;
    text-transform: uppercase;
}

.hud-value {
    /* Purpose: Digital readout styling */
    font-size: 1.8rem;
    font-weight: bold;
    color: #00ff00;
    text-shadow: 0 0 10px #00ff00;
    font-variant-numeric: tabular-nums;
}

.hud-unit {
    /* Purpose: Unit suffix styling */
    font-size: 0.7rem;
    color: #666;
    margin-left: 4px;
}


/* SECTION: Controls Hint – Two-line layout with arrow key emphasis */
/*
 * Purpose: Displays control scheme with improved readability and typography.
 *
 * - **Two-line layout**: Separates controls into logical pairs.
 * - **Arrow emphasis**: Larger font for ← → ↑ ↓ symbols.
 * - **Flexible spacing**: Gap element pushes items to edges.
 * - **Consistent text**: Maintains monospace, uppercase styling.
 */

.controls-hint {
    /* Purpose: Container styling */
    margin-top: 15px;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    
    /* Purpose: Vertical stacking of two control lines */
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-line {
    /* Purpose: Horizontal layout within each line */
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 20px;
}

.control-gap {
    /* Purpose: Flexible spacer to push items apart */
    flex: 1;
}

.controls-hint span {
    /* Purpose: Text styling */
    font-size: 0.8rem;
    color: #888;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: center;
    white-space: nowrap;
}

/* SECTION: Arrow Keys – Larger typography for symbols */
/*
 * Purpose: Emphasises arrow symbols for better visual hierarchy.
 *
 * - **Increased size**: 1.2rem vs 0.8rem for regular text.
 * - **Bold weight**: Makes arrows stand out more clearly.
 * - **Baseline alignment**: Maintains vertical rhythm with adjacent text.
 */

.arrow-keys {
    /* Purpose: Typography emphasis */
    font-size: 1.0rem !important;
    font-weight: bold;
    color: #aaa;
    padding: 0 4px;
    vertical-align: baseline;
    color: #00ff00;
    text-shadow: 0 0 8px #00ff00;
}


/* SECTION: Sound Toggle – Text button styling */
/*
 * Purpose: Text-based button for sound on/off toggle.
 *
 * - **Consistent styling**: Matches control text appearance.
 * - **Hover effect**: Subtle glow on interaction.
 * - **No icon**: Maintains text-based UI theme.
 */

.sound-toggle {
    /* Purpose: Button reset and typography */
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: center;
    white-space: nowrap;
    
    /* Purpose: Smooth hover transition */
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

.sound-toggle:hover {
    /* Purpose: Interactive feedback */
    color: #00ff00;
    text-shadow: 0 0 8px #00ff00;
}


/* SECTION: Game Over Message – Crash notification */
/*
 * Purpose: Overlay displayed on collision.
 *
 * - **Centre positioning**: Absolute centre of screen.
 * - **Blinking animation**: Attracts attention.
 * - **Hidden by default**: Toggled via JS.
 */

.game-over-message {
    /* Purpose: Positioning and visibility */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: centre;
    display: none;
    z-index: 20;
    
    /* Purpose: Typography styling */
    font-size: 3rem;
    font-weight: bold;
    color: #ff0040;
    text-shadow: 
        0 0 20px #ff0040,
        0 0 40px #ff0040;
    
    /* Purpose: Blink animation */
    animation: blink 1s infinite;
}

.restart-hint {
    /* Purpose: Secondary instruction styling */
    display: block;
    margin-top: 10px;
    font-size: 0.85rem;
    color: #fff;
    text-shadow: 0 0 50px #fff;
}


/* SECTION: Animations – Keyframe definitions */
/*
 * Purpose: Reusable animation keyframes.
 *
 * - **Blink**: Opacity oscillation for alerts.
 */

@keyframes blink {
    /* Purpose: Opacity cycle for game over text */
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}


/* SECTION: Responsive Adjustments – Mobile adaptation */
/*
 * Purpose: Ensures playability on smaller viewports.
 *
 * - **Scale transformation**: Reduces overall size.
 * - **Maintains aspect ratio**: No distortion.
 */

@media (max-height: 800px) {
    .arcade-cabinet {
        /* Purpose: Scale down for small screens */
        transform: scale(0.85);
        transform-origin: centre;
    }
}


/* SECTION: High Score Entry Overlay & Modal – Retro input and leaderboard */
/* =================================================== */
/*
 * Purpose: Styling for new high-score name entry and top-10 viewer
 * - Centered overlays with CRT glow
 * - Input and buttons match green-on-black theme
*/

.high-score-entry {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    backdrop-filter: blur(4px);
}

.entry-panel {
    background: #000;
    border: 2px solid #00ff00;
    padding: 24px 32px;
    text-align: center;
    box-shadow: 0 0 20px #00ff00;
    max-width: 360px;
}

.entry-panel h3 {
    color: #ff0040;
    margin: 0 0 16px;
    text-shadow: 0 0 10px #ff0040;
}

.entry-panel p {
    margin: 8px 0 16px;
    font-size: 1.1rem;
}

.entry-panel label {
    display: block;
    margin: 12px 0 8px;
    color: #888;
}

#playerNameInput {
    background: #111;
    border: 1px solid #00ff00;
    color: #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    padding: 8px;
    width: 180px;
    text-align: center;
    text-transform: uppercase;
}

#submitScoreBtn {
    margin-top: 16px;
    background: #00ff00;
    color: #000;
    border: none;
    padding: 10px 24px;
    font-size: 1rem;
    cursor: pointer;
    text-transform: uppercase;
}

#submitScoreBtn:hover {
    background: #00cc00;
}

/* High Scores Modal */
.high-scores-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.high-scores-modal .modal-content {
    width: min(90vw, 480px);
    background: #000;
    border: 2px solid #00ff00;
    padding: 0;
    box-shadow: 0 0 30px #00ff00;
}

.high-scores-modal .modal-header {
    padding: 16px;
    background: #111;
    border-bottom: 1px solid #00ff00;
    text-align: center;
}

.high-scores-modal h2 {
    margin: 0;
    color: #00ff00;
    text-shadow: 0 0 10px #00ff00;
}

.high-scores-list {
    padding: 16px;
    max-height: 450px;
    overflow-y: auto;
}

.high-scores-list table {
    width: 100%;
    border-collapse: collapse;
    color: #00ff00;
}

.high-scores-list th, .high-scores-list td {
    padding: 8px;
    text-align: center;
    border-bottom: 1px solid #333;
}

.high-scores-list th {
    text-transform: uppercase;
    font-size: 0.9rem;
    color: #888;
}

#clearHighScoresBtn {
    background: #ff0040;
    color: white;
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    text-transform: uppercase;
}

#clearHighScoresBtn:hover {
    background: #cc0033;
}

/* Make BEST value clickable */
#highScoreDisplay {
    cursor: pointer;
}

#highScoreDisplay:hover {
    text-shadow: 0 0 12px #00ff00;
}


/* SECTION: High Scores Link – Text button under BEST */
/* =================================================== */
/*
 * Purpose: Clickable text link to open top-10 leaderboard modal
 * - Matches .sound-toggle styling for UI consistency
 * - Small, subtle, glows on hover
*/

.high-scores-link {
    /* Purpose: Button reset and typography */
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.75rem;           /* Slightly smaller than main HUD */
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 4px;              /* Small gap below BEST number */
    display: block;
    width: 100%;
    text-align: center;
    
    /* Purpose: Smooth hover transition */
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

.high-scores-link:hover {
    /* Purpose: Interactive feedback */
    color: #00ff00;
    text-shadow: 0 0 8px #00ff00;
}


/* SECTION: Start Game Overlay – Title screen before gameplay begins */
/* =================================================== */
/*
 * Purpose: Full-screen overlay shown on load until player starts
 * - Dark semi-transparent backdrop
 * - Centered panel with glow effects
 * - Retro typography and green accents
*/

.start-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    backdrop-filter: blur(4px);
}

.start-panel {
    background: #000;
    border: 3px solid #00ff00;
    padding: 40px 60px;
    text-align: center;
    box-shadow: 0 0 40px #00ff00;
    max-width: 500px;
}

.start-title {
    color: #00ff00;
    font-size: 3.2rem !important;
    margin: 0 0 20px;
    text-shadow: 0 0 20px #00ff00;
}

.start-best {
    margin: 20px 0 30px;
}

.start-label {
    font-size: 1.4rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

.start-value {
    font-size: 3rem;
    color: #00ff00;
    text-shadow: 0 0 15px #00ff00;
    display: block;
    margin-top: 8px;
}

.start-button {
    background: #00ff00;
    color: #000;
    border: none;
    padding: 16px 48px;
    font-size: 1.8rem;
    font-family: 'Courier New', monospace;
    text-transform: uppercase;
    cursor: pointer;
    margin: 20px 0 30px;
    box-shadow: 0 0 20px #00ff00;
    transition: all 0.2s ease;
}

.start-button:hover {
    background: #00cc00;
    box-shadow: 0 0 30px #00ff00;
    transform: scale(1.05);
}

.start-controls {
    color: #888;
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 20px;
}

.start-hint {
    color: #666;
    font-size: 0.9rem;
    margin: 0;
}

/* Purpose: Style for BEST name + date below score */
.start-best-info {
    display: block;
    margin-top: 8px;
    font-size: 1.3rem;
    color: #00ff88;
    text-shadow: 0 0 10px #00ff88;
    font-weight: bold;
    letter-spacing: 0.05em;
}

.start-best {
    margin: 20px 0 30px;
    min-height: 80px; /* Reserve space even if no score yet */
}

/* Show "Loading..." before data arrives */
.start-best-info:empty::before {
    content: "Loading best score...";
    color: #888;
    font-style: italic;
}

.start-best-name {
    display: block;
    margin-top: 8px;
    font-size: 2rem;
    color: #00ff88;
    text-shadow: 0 0 10px #00ff88;
    font-weight: bold;
    letter-spacing: 0.05em;
}

.start-best-date {
    display: block;
    margin-top: 4px;
    font-size: 1.3rem;
    color: #00ff88;
    text-shadow: 0 0 10px #00ff88;
    letter-spacing: 0.03em;
}



/* SECTION: Countdown Overlay – First-time start sequence styling */
/*
 * Purpose: Full-screen animated countdown shown only once per session
 * - Dark semi-transparent backdrop covering entire viewport
 * - Large centred number/text with retro green glow
 * - Smooth fade-in + scale-up animation per step
 * - High z-index to sit above game but below modals if needed
 * - Pointer-events enabled to block clicks during sequence
 */
.countdown-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 45;                    /* Above game canvas/HUD, below modals */
    pointer-events: all;            /* Blocks interaction during countdown */
}

/* Purpose: The animated number or "GO!" text element */
.countdown-number {
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(10rem, 20vw, 18rem);
    font-weight: bold;
    color: #00ff88;
    text-shadow: 
        0 0 30px #00ff88,
        0 0 60px #00ff44;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

/* Purpose: Active state that triggers the animation */
.countdown-number.visible {
    opacity: 1;
    transform: scale(1);
}
