:root {
    --bg-color: #1a1a2e;
    --primary-text: #e0e0e0;
    --hud-bg: rgba(0, 0, 0, 0.5);
    --btn-bg: rgba(255, 255, 255, 0.15);
    --btn-active-bg: rgba(255, 255, 255, 0.4);
}

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

html, body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--primary-text);
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- TOGGLE BUTTON --- */
#fullscreen-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 2000;
    background: #333;
    color: white;
    border: 2px solid white;
    border-radius: 4px;
    font-size: 12px;
    padding: 8px 12px;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.2s;
}

#fullscreen-btn:hover { background: #555; }

/* --- GAME CONTAINER & SCREEN --- */
#game-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

#screen {
    width: 100%;
    max-width: 960px;
    aspect-ratio: 16 / 9;
    background: #000;
    position: relative;
    overflow: hidden;
    transform-origin: center center;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    flex-shrink: 0;
}

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

#hud {
    position: fixed;
    top: 10px;
    right: 10px;
    background-color: var(--hud-bg);
    padding: 10px;
    border-radius: 5px;
    font-size: 14px;
    text-align: right;
    pointer-events: none;
    z-index: 10;
}

.overlay-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--hud-bg);
    padding: 25px;
    border: 1px solid var(--primary-text);
    border-radius: 8px;
    z-index: 100;
    text-align: left;
    line-height: 1.6;
    max-width: min(700px, 90vw);
    max-height: 90vh;
    overflow-y: auto;
}

.overlay-panel.hidden { display: none; }
.overlay-panel h2, .overlay-panel h3 { text-align: center; margin-top: 1em; margin-bottom: 0.5em; }
.overlay-panel h2:first-child { margin-top: 0; }
.overlay-panel ul { list-style-position: inside; padding-left: 10px; }
.overlay-panel li { margin-bottom: 0.5em; }
.overlay-panel table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.overlay-panel th, .overlay-panel td { border: 1px solid var(--primary-text); padding: 8px; text-align: left; }
.overlay-panel th { background-color: var(--btn-bg); }
.overlay-panel a { color: #9cf; text-decoration: none; }
.overlay-panel a:hover { text-decoration: underline; }
.overlay-panel hr { border: 0; border-top: 1px solid var(--primary-text); margin: 1.5em 0; }
.overlay-panel button { display: block; margin: 20px auto 0; padding: 10px 20px; font-size: 1em; background: var(--btn-bg); color: var(--primary-text); border: 1px solid var(--primary-text); border-radius: 5px; cursor: pointer; }
.overlay-panel button:hover { background: var(--btn-active-bg); }

/* --- MOBILE CONTROLS OVERLAY --- */
#mobile-controls {
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    width: 100%;
    display: none; /* Hidden by default */
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 40px;
    pointer-events: none; /* Let touches pass through the blank space */
    z-index: 3000;
}

.mobile-left, .mobile-right {
    display: flex;
    gap: 15px;
}

.mobile-btn {
    width: 85px;
    height: 85px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.4);
    background-color: var(--btn-bg);
    color: var(--primary-text);
    font-size: 20px;
    font-weight: bold;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto; /* Re-enable clicks on the buttons themselves */
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    transition: transform 0.05s, background-color 0.05s;
    touch-action: none;
}

/* Updated feedback to use JS toggled class for consistency across touch & mouse */
.mobile-btn:active, .mobile-btn.active {
    background-color: var(--btn-active-bg);
    transform: scale(0.92);
}

#help-toggle-button {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background-color: var(--hud-bg);
    padding: 8px 12px;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    z-index: 50;
    transition: background-color 0.2s;
}
#help-toggle-button:hover { background-color: rgba(0, 0, 0, 0.7); }

/* --- DISPLAY LOGIC --- */
/* Show mobile controls via OS Detection OR if the app is in Fullscreen mode */
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
    #mobile-controls { display: flex; }
    #help-toggle-button { display: none; }
}

body.is-fullscreen #mobile-controls { display: flex; }
body.is-fullscreen #help-toggle-button { display: none; }
body.is-fullscreen #fullscreen-btn { display: none; }

/* --- CSS Update --- */
body.is-fullscreen #screen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    aspect-ratio: auto !important;
    transform: none !important; /* Disable the JS scaling */
    border-radius: 0;
}

body.is-fullscreen #game-container {
    width: 100vw;
    height: 100vh;
}
