:root {
    --bg-dark: #050314;
    --neon-blue: #00f2fe;
    --neon-pink: #ff0844;
    --neon-green: #00ff87;
    --text-main: #ffffff;
    --text-muted: #a0a5ba;
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Montserrat', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-body);
    color: var(--text-main);
    touch-action: none; /* Prevent default touch actions like pull-to-refresh */
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #1b0a3a 0%, var(--bg-dark) 100%);
}

/* Background grid */
#background-layer {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1;
    perspective: 1000px;
}

.grid-floor {
    width: 200%;
    height: 200%;
    position: absolute;
    left: -50%;
    top: 0%;
    background-image: 
        linear-gradient(rgba(0, 242, 254, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 242, 254, 0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    transform: rotateX(60deg) translateY(-100px);
    animation: gridMove 5s linear infinite;
}

@keyframes gridMove {
    0% { background-position: 0 0; }
    100% { background-position: 0 50px; }
}

/* Canvas */
#gameCanvas {
    position: absolute;
    z-index: 5;
    /* Maintain aspect ratio or fill screen depending on device, JS will handle sizing */
    box-shadow: 0 0 50px rgba(0, 242, 254, 0.2);
    border-radius: 10px;
    border: 1px solid rgba(0, 242, 254, 0.3);
    background: rgba(5, 3, 20, 0.8);
}

/* UI Layer */
#ui-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 10;
    pointer-events: none; /* Let clicks pass through to canvas when appropriate */
}

.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    transition: opacity 0.4s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* Title Screen */
#screen-title {
    background: rgba(5, 3, 20, 0.85);
    backdrop-filter: blur(10px);
}

.logo-container {
    text-align: center;
    margin-bottom: 50px;
}

.title-main {
    font-family: var(--font-heading);
    font-size: clamp(3rem, 8vw, 6rem);
    font-weight: 900;
    color: transparent;
    -webkit-text-stroke: 2px var(--neon-blue);
    position: relative;
    text-shadow: 0 0 20px rgba(0, 242, 254, 0.5);
}

.title-main::before {
    content: "MAZE ESCAPE";
    position: absolute;
    left: 0; top: 0; width: 100%; height: 100%;
    color: var(--neon-blue);
    filter: blur(15px);
    z-index: -1;
}

.title-sub {
    font-size: clamp(1.5rem, 4vw, 3rem);
    color: var(--neon-pink);
    letter-spacing: 15px;
    margin-top: -10px;
    text-shadow: 0 0 15px rgba(255, 8, 68, 0.8);
}

/* Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 300px;
}

.premium-btn {
    position: relative;
    padding: 15px 30px;
    border: none;
    background: linear-gradient(45deg, #0f0c29, #302b63);
    color: #fff;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.premium-btn::before {
    content: '';
    position: absolute;
    top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.premium-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px var(--neon-blue);
}

.premium-btn:hover::before {
    left: 100%;
}

.premium-btn.secondary {
    background: transparent;
    border: 2px solid var(--neon-pink);
    color: var(--neon-pink);
    box-shadow: 0 0 10px rgba(255, 8, 68, 0.2);
}

.premium-btn.secondary:hover {
    box-shadow: 0 0 20px rgba(255, 8, 68, 0.6);
    background: rgba(255, 8, 68, 0.1);
}

.btn-text {
    position: relative;
    z-index: 2;
}

/* Modals */
.modal {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.panel {
    background: linear-gradient(135deg, rgba(36,36,62,0.95), rgba(15,12,41,0.95));
    border: 2px solid var(--neon-blue);
    border-radius: 15px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 242, 254, 0.3);
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel h2 {
    font-family: var(--font-heading);
    color: var(--neon-blue);
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(0, 242, 254, 0.5);
}

.panel h2.danger-text {
    color: var(--neon-pink);
    text-shadow: 0 0 10px rgba(255, 8, 68, 0.5);
    border-color: var(--neon-pink);
}

/* Instructions */
.instructions {
    text-align: left;
    margin-bottom: 20px;
}

.inst-item {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.icon {
    width: 20px; height: 20px;
    border-radius: 50%;
    margin-right: 15px;
}
.player-icon { background: var(--neon-blue); box-shadow: 0 0 10px var(--neon-blue); }
.exit-icon { background: var(--neon-green); box-shadow: 0 0 10px var(--neon-green); }
.enemy-icon { background: var(--neon-pink); box-shadow: 0 0 10px var(--neon-pink); }
.powerup-icon { background: #ffd700; box-shadow: 0 0 10px #ffd700; }

/* HUD */
#screen-hud {
    pointer-events: none;
    justify-content: space-between;
}

.hud-top {
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: auto;
}

.hud-box {
    background: rgba(15, 12, 41, 0.8);
    border: 1px solid rgba(0, 242, 254, 0.3);
    border-radius: 8px;
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.hud-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 2px;
}

.hud-value {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--neon-blue);
    text-shadow: 0 0 5px rgba(0, 242, 254, 0.5);
}

.icon-btn {
    background: rgba(15, 12, 41, 0.8);
    border: 1px solid var(--neon-blue);
    color: var(--neon-blue);
    width: 45px; height: 45px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
}

.icon-btn:hover {
    background: var(--neon-blue);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.6);
}

/* Joystick */
.hud-bottom {
    width: 100%;
    padding: 30px;
    display: flex;
    justify-content: flex-start; /* left align for joystick */
    pointer-events: auto;
}

#joystick-zone {
    width: 120px;
    height: 120px;
    position: relative;
    display: none; /* Hidden on desktop by default, JS toggles it */
}

#joystick-base {
    width: 100px;
    height: 100px;
    background: rgba(0, 242, 254, 0.1);
    border: 2px solid rgba(0, 242, 254, 0.3);
    border-radius: 50%;
    position: absolute;
    bottom: 20px;
    left: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 20px rgba(0,0,0,0.5), inset 0 0 20px rgba(0, 242, 254, 0.1);
}

#joystick-stick {
    width: 40px;
    height: 40px;
    background: var(--neon-blue);
    border-radius: 50%;
    box-shadow: 0 0 15px var(--neon-blue);
    position: absolute;
    transform: translate(0, 0);
    transition: transform 0.1s ease-out; /* Smooth return to center */
}
#joystick-stick.active {
    transition: none; /* No transition while dragging */
}

@media (max-width: 768px) {
    .panel h2 { font-size: 2rem; }
    .title-main { font-size: 3.5rem; }
    .hud-box { padding: 5px 10px; }
    .hud-value { font-size: 1.2rem; }
    #joystick-zone { display: block; } /* Show joystick on small screens */
}
