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

body {
    background-color: #222222; /* Dark grey background */
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

#game-container {
    position: relative;
    border: 3px solid #aaaaaa;
    box-shadow: 0 0 10px #aaaaaa, 0 0 20px #aaaaaa inset;
    background-color: #3a3a3a;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    /* ADDED: Allow absolutely positioned children to appear outside */
    overflow: visible; 
}

canvas {
    display: block;
    background: radial-gradient(circle, #555555 0%, #3a3a3a 70%);
    transition: background 0.3s ease;
}

#ui-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: #000;
    border-bottom: 3px solid #999999;
    box-shadow: 0 0 10px #999999;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.ui-box {
    text-align: center;
    width: 150px; /* Give a fixed width for alignment */
}

.ui-box h2 {
    font-size: 1em;
    color: #bbbbbb;
    text-shadow: 0 0 5px #bbbbbb;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

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

#game-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
}

.ui-control-button {
    padding: 5px 10px;
    font-size: 0.8em;
    font-family: 'Courier New', Courier, monospace;
    background-color: #555;
    color: #ddd;
    border: 1px solid #999;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 120px;
    text-align: center;
}

.ui-control-button:hover {
    background-color: #777;
    border-color: #fff;
    color: #fff;
}

/* MODIFIED: Style for the theme toggle button outside the game area */
#theme-toggle-button {
    position: fixed; /* Position relative to the viewport */
    top: 15px;
    right: 15px;
    z-index: 50; /* Make sure it's on top of everything */
    padding: 8px 15px; /* Slightly larger padding */
    font-size: 0.9em;
    font-family: 'Courier New', Courier, monospace;
    background-color: #555;
    color: #ddd;
    border: 1px solid #999;
    cursor: pointer;
    transition: all 0.2s ease;
}

#theme-toggle-button:hover {
    background-color: #777;
    color: #fff;
}


#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 10;
    transition: background-color 0.3s ease;
}

#game-over-screen h1 {
    font-size: 4em;
    color: #eeeeee;
    text-shadow: 0 0 10px #eeeeee;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

#game-over-screen p {
    font-size: 1.5em;
    margin-bottom: 20px;
}

#restart-button, #close-help-button {
    padding: 15px 30px;
    font-size: 1.2em;
    font-family: 'Courier New', Courier, monospace;
    background-color: #cccccc;
    color: #000;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 0 10px #cccccc;
    transition: all 0.2s ease;
}

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

.hidden {
    display: none !important;
}

#help-legend {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 450px;
    background-color: rgba(0, 0, 0, 0.9);
    border: 2px solid #fff;
    box-shadow: 0 0 20px #fff;
    padding: 25px;
    text-align: left;
    z-index: 20;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

#help-legend h2 {
    text-align: center;
    font-size: 2em;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #fff;
    transition: text-shadow 0.3s ease;
}

#help-legend p {
    font-size: 1.1em;
    margin: 10px 0;
}

#help-legend span {
    display: inline-block;
    width: 150px; /* Aligns the descriptions */
    font-weight: bold;
    color: #ccc;
    transition: color 0.3s ease;
}

#close-help-button {
    display: block;
    margin: 20px auto 0;
}

/* NEW: Touchscreen Control Buttons */
.touch-button {
    position: absolute;
    width: 80px;
    height: 80px;
    background-color: rgba(100, 100, 100, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    z-index: 100;
    cursor: pointer;
    user-select: none; /* Prevents text selection */
    -webkit-tap-highlight-color: transparent; /* Removes tap highlight on mobile */
    color: rgba(255, 255, 255, 0.8);
    font-size: 2.5em;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Courier New', Courier, monospace;
    transition: background-color 0.1s ease;
}
.touch-button:active {
    background-color: rgba(150, 150, 150, 0.7);
}

#touch-left {
    left: -90px; /* 80px width + 10px gap */
    bottom: -3px; /* Align with bottom of game-container border */
}

#touch-right {
    right: -90px;
    bottom: -3px;
}

#touch-launch {
    right: -90px;
    bottom: 90px; /* 80px height + 10px gap */
}

/* NEW: Styles for Light Mode */
body.light-mode {
    background-color: #cccccc;
    color: #111;
}

body.light-mode #game-container {
    background-color: #f0f0f0;
    border-color: #555555;
    box-shadow: 0 0 10px #555555, 0 0 20px #555555 inset;
}

body.light-mode canvas {
    background: radial-gradient(circle, #ffffff 0%, #dddddd 70%);
}

body.light-mode #ui-panel {
    background-color: #e0e0e0;
    border-bottom-color: #777777;
    box-shadow: 0 0 10px #777777;
}

body.light-mode .ui-box h2 {
    color: #444444;
    text-shadow: none;
}

body.light-mode .ui-box p {
    color: #000000;
    text-shadow: none;
}

body.light-mode .ui-control-button,
body.light-mode #theme-toggle-button {
    background-color: #c5c5c5;
    color: #222;
    border-color: #888;
}

body.light-mode .ui-control-button:hover,
body.light-mode #theme-toggle-button:hover {
    background-color: #bbbbbb;
    color: #000;
    border-color: #333;
}

body.light-mode #game-over-screen {
    background-color: rgba(255, 255, 255, 0.8);
}

body.light-mode #game-over-screen h1 {
    color: #222222;
    text-shadow: 0 0 10px #222222;
}

body.light-mode #restart-button,
body.light-mode #close-help-button {
    background-color: #555;
    color: #fff;
    border-color: #222;
    box-shadow: 0 0 10px #555;
}

body.light-mode #restart-button:hover,
body.light-mode #close-help-button:hover {
    background-color: #333;
    box-shadow: 0 0 20px #222;
}

body.light-mode #help-legend {
    background-color: rgba(255, 255, 255, 0.95);
    border-color: #222;
    box-shadow: 0 0 20px #222;
}

body.light-mode #help-legend h2 {
    text-shadow: 0 0 10px #222;
}

body.light-mode #help-legend span {
    color: #333;
}

/* ADDED: Light mode for touch buttons */
body.light-mode .touch-button {
    background-color: rgba(200, 200, 200, 0.6);
    border-color: rgba(0, 0, 0, 0.5);
    color: rgba(0, 0, 0, 0.7);
}
body.light-mode .touch-button:active {
    background-color: rgba(170, 170, 170, 0.8);
}
