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

/* ROOT & BODY SETUP */
body {
    background-color: #1a1a1a;
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100vw;
    overflow: auto; /* Default scroll behavior */
    transition: background-color 0.3s ease;
}

/* --- MOBILE MODE LOCK --- */
/* Applied by JS when fullscreen is active */
body.mobile-mode {
    overflow: hidden; /* Disables scrollbars */
    touch-action: none; /* Disables browser gestures */
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

/* --- THE SCREEN (Fixed Internal Resolution) --- */
#game-container {
    position: relative;
    width: 800px; /* Widened from 600px to comfortably fit the bottom horizontally */
    height: 1000px; /* Base Height */
    background-color: #000;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Important for scaling from the middle */
    transform-origin: center center;
    flex-shrink: 0;
}

#canvas-wrapper {
    width: 100%;
    height: 100%;
    flex-grow: 1;
    overflow: hidden;
    background: #000;
}

canvas {
    display: block;
    outline: none;
}

#ui-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 40px; /* slightly more padding for the wider screen */
    background: linear-gradient(180deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.6) 80%, rgba(0,0,0,0) 100%);
    pointer-events: none;
}

#ui-panel button, #ui-panel .ui-box {
    pointer-events: auto;
}

.ui-box {
    text-align: center;
    width: 120px;
}

.ui-box h2 {
    font-size: 0.9em;
    color: #00d2ff;
    text-shadow: 0 0 5px #00d2ff;
}

.ui-box p {
    font-size: 1.5em;
    color: #ffffff;
    font-weight: bold;
    text-shadow: 0 0 5px #ffffff;
}

#game-controls {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ui-control-button {
    padding: 4px 10px;
    font-size: 0.7em;
    font-family: 'Courier New', Courier, monospace;
    background-color: rgba(50, 50, 50, 0.8);
    color: #ddd;
    border: 1px solid #666;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100px;
    text-transform: uppercase;
}

.ui-control-button:hover {
    background-color: #00d2ff;
    color: #000;
    border-color: #fff;
    box-shadow: 0 0 10px #00d2ff;
}

/* --- TOGGLE BUTTONS --- */
#theme-toggle-button, #mobile-btn {
    position: fixed;
    z-index: 2000;
    padding: 8px 15px;
    background-color: #333;
    color: #fff;
    border: 1px solid #555;
    cursor: pointer;
    font-family: 'Courier New', Courier, monospace;
    text-transform: uppercase;
    font-size: 12px;
}

#theme-toggle-button {
    top: 15px;
    right: 15px;
}

#mobile-btn {
    top: 15px;
    left: 15px;
    border: 2px solid white;
}

/* Hide the fullscreen button when in mobile mode */
body.mobile-mode #mobile-btn { 
    display: none; 
}

#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
}

#game-over-screen h1 {
    font-size: 3.5em;
    color: #ff0055;
    text-shadow: 0 0 15px #ff0055;
    margin-bottom: 20px;
}

#restart-button, #close-help-button {
    padding: 15px 30px;
    font-size: 1.2em;
    font-family: 'Courier New', Courier, monospace;
    background-color: #00d2ff;
    color: #000;
    border: none;
    cursor: pointer;
    box-shadow: 0 0 15px #00d2ff;
    font-weight: bold;
}

#restart-button:hover, #close-help-button:hover {
    background-color: #fff;
    box-shadow: 0 0 25px #fff;
}

.hidden { display: none !important; }

#help-legend {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    max-width: 500px;
    background-color: rgba(20, 20, 20, 0.95);
    border: 2px solid #00d2ff;
    box-shadow: 0 0 20px rgba(0, 210, 255, 0.4);
    padding: 30px;
    z-index: 30;
    color: #fff;
}

#help-legend h2 {
    text-align: center;
    color: #00d2ff;
    margin-bottom: 20px;
}

#help-legend span {
    color: #ff0055;
    font-weight: bold;
}

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

/* Show controls only when in mobile mode */
body.mobile-mode #mobile-controls {
    display: flex;
}

/* --- CONTROL BUTTONS --- */
.mobile-control-btn {
    pointer-events: auto; /* Re-enable clicks for buttons */
    width: 90px; height: 90px;
    background: rgba(255,255,255,0.15);
    border: 3px solid rgba(255,255,255,0.4);
    border-radius: 50%;
    color: white;
    font-size: 40px;
    display: flex; justify-content: center; align-items: center;
    user-select: none;
    backdrop-filter: blur(4px);
    margin-bottom: 20px;
    transition: transform 0.1s, background 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-control-btn:active {
    background: rgba(255,255,255,0.4);
    transform: scale(0.95);
}

#mobile-dpad {
    display: flex;
    gap: 15px; /* Spacing between Left/Right */
    margin-left: 20px;
    margin-bottom: 20px;
}

#mobile-action {
    margin-right: 20px;
    margin-bottom: 20px;
}

/* Light Mode Styles */
body.light-mode { background-color: #e0e0e0; color: #111; }
body.light-mode #game-container { background-color: #fff; box-shadow: 0 0 20px rgba(0,0,0,0.2); }
body.light-mode #ui-panel { background: rgba(255,255,255,0.9); border-bottom: 1px solid #ccc; }
body.light-mode .ui-box h2 { color: #005588; text-shadow: none; }
body.light-mode .ui-box p { color: #333; text-shadow: none; }
