:root {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --accent-color: #ffcc00;
    --hud-bg: rgba(0, 0, 0, 0.8);
    --font-family: 'Courier New', Courier, monospace;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0d0d0d, #2a2a2a);
    color: var(--text-color);
    font-family: var(--font-family);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none; /* Prevent default touch scrolling */
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 600px; /* Optional constraint for desktop */
    max-height: 800px;
    background: #000;
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
    border-radius: 4px;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated; /* Essential for pixel art */
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to canvas if needed, but buttons will override */
}

#hud {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    background: var(--hud-bg);
    padding: 8px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    border: 1px solid #444;
}

.stat {
    font-weight: bold;
}

#message-log {
    position: absolute;
    bottom: 60px; /* Above controls */
    left: 10px;
    width: calc(100% - 20px);
    max-height: 80px;
    overflow-y: hidden;
    color: #ccc;
    font-size: 12px;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
    display: flex;
    flex-direction: column-reverse; /* Newest at bottom */
}

.log-entry {
    margin-top: 2px;
    opacity: 0.8;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    pointer-events: auto;
    z-index: 10;
}

.screen.hidden {
    display: none;
}

h1 {
    font-size: 32px;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 #000;
}

p {
    margin: 10px 0;
    font-size: 16px;
}

button {
    margin-top: 30px;
    padding: 12px 24px;
    font-family: var(--font-family);
    font-size: 18px;
    font-weight: bold;
    color: #000;
    background: var(--accent-color);
    border: none;
    border-radius: 2px;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

button:hover {
    background: #ffdb4d;
    transform: scale(1.05);
}

button:active {
    transform: scale(0.95);
}

/* Mobile Controls */
.mobile-only {
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    .mobile-only {
        display: block;
    }

    #controls-hint {
        position: absolute;
        bottom: 20px;
        right: 20px;
        pointer-events: auto;
    }

    .d-pad {
        display: grid;
        grid-template-columns: 50px 50px 50px;
        grid-template-rows: 50px 50px;
        gap: 5px;
    }

    .d-btn {
        width: 50px;
        height: 50px;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 8px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 20px;
        user-select: none;
    }

    .d-btn:active {
        background: rgba(255, 255, 255, 0.3);
    }

    .up { grid-column: 2; grid-row: 1; }
    .left { grid-column: 1; grid-row: 2; }
    .right { grid-column: 3; grid-row: 2; }
    .down { grid-column: 2; grid-row: 2; }
}

/* Animations */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.shake {
    animation: shake 0.5s;
    animation-iteration-count: 1;
}
