* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #0a0e1a;
    --bg2: #0d1225;
    --neon-blue: #00d4ff;
    --neon-purple: #a855f7;
    --neon-green: #00ff88;
    --neon-gold: #ffd700;
    --wall-color: #1a6bff;
    --wall-glow: rgba(26, 107, 255, 0.6);
    --floor: #0f1528;
    --text: #c0d0f0;
    --font: 'Press Start 2P', monospace;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    overflow: hidden;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game-container {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

#canvas {
    display: block;
    flex: 1;
    max-width: 100%;
    image-rendering: auto;
}

#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: linear-gradient(to bottom, rgba(10,14,26,0.95), rgba(10,14,26,0));
    pointer-events: none;
    z-index: 10;
    flex-wrap: wrap;
    gap: 4px;
}

#hud-left, #hud-right {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

#title {
    font-size: 10px;
    color: var(--neon-blue);
    text-shadow: 0 0 10px var(--neon-blue), 0 0 20px rgba(0,212,255,0.4);
}

#level-display {
    font-size: 9px;
    color: var(--neon-purple);
    text-shadow: 0 0 8px var(--neon-purple);
}

#timer {
    font-size: 11px;
    color: var(--neon-gold);
    text-shadow: 0 0 10px var(--neon-gold);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { text-shadow: 0 0 10px var(--neon-gold); }
    50% { text-shadow: 0 0 20px var(--neon-gold), 0 0 30px rgba(255,215,0,0.5); }
}

#moves, #best-time {
    font-size: 8px;
    color: var(--text);
    opacity: 0.8;
}

#controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 6px 10px;
    background: var(--bg2);
    border-top: 1px solid rgba(26,107,255,0.2);
    width: 100%;
    flex-wrap: wrap;
    z-index: 10;
}

#controls-left, #controls-center, #controls-right {
    display: flex;
    gap: 6px;
    align-items: center;
}

.ctrl-btn {
    font-family: var(--font);
    font-size: 7px;
    padding: 6px 10px;
    border: 1px solid var(--neon-blue);
    background: rgba(0,212,255,0.08);
    color: var(--neon-blue);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap;
}

.ctrl-btn:hover {
    background: rgba(0,212,255,0.2);
    box-shadow: 0 0 12px rgba(0,212,255,0.3);
}

.ctrl-btn:active {
    transform: scale(0.95);
}

.solve-btn {
    border-color: var(--neon-purple);
    color: var(--neon-purple);
    background: rgba(168,85,247,0.08);
}

.solve-btn:hover {
    background: rgba(168,85,247,0.2);
    box-shadow: 0 0 12px rgba(168,85,247,0.3);
}

#difficulty {
    font-family: var(--font);
    font-size: 7px;
    padding: 5px 8px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    cursor: pointer;
    outline: none;
}

.toggle-label {
    font-size: 7px;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
}

.toggle-label input {
    accent-color: var(--neon-blue);
    cursor: pointer;
}

#dpad {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px;
    z-index: 20;
    background: var(--bg2);
    border-top: 1px solid rgba(26,107,255,0.15);
    width: 100%;
}

.dpad-row {
    display: flex;
    gap: 2px;
}

.dpad-btn {
    width: 50px;
    height: 50px;
    font-size: 18px;
    background: rgba(0,212,255,0.1);
    border: 1px solid rgba(0,212,255,0.3);
    color: var(--neon-blue);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.dpad-btn:active {
    background: rgba(0,212,255,0.3);
    box-shadow: 0 0 15px rgba(0,212,255,0.4);
}

.dpad-center {
    background: transparent;
    border-color: transparent;
}

#victory-screen {
    position: absolute;
    inset: 0;
    background: rgba(10,14,26,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

#victory-screen.hidden {
    display: none;
}

#victory-box {
    text-align: center;
    padding: 30px;
    border: 2px solid var(--neon-gold);
    border-radius: 12px;
    background: rgba(15,21,40,0.95);
    box-shadow: 0 0 40px rgba(255,215,0,0.2);
    max-width: 340px;
    width: 90%;
}

#victory-title {
    font-size: 14px;
    color: var(--neon-gold);
    text-shadow: 0 0 20px var(--neon-gold);
    margin-bottom: 8px;
}

#victory-msg {
    font-size: 7px;
    color: var(--text);
    opacity: 0.7;
    margin-bottom: 16px;
    line-height: 1.6;
}

#victory-stats p {
    font-size: 8px;
    margin: 6px 0;
    color: var(--neon-blue);
}

#v-best {
    color: var(--neon-gold) !important;
    text-shadow: 0 0 10px rgba(255,215,0,0.5);
}

#victory-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 18px;
}

#victory-buttons .ctrl-btn {
    font-size: 8px;
    padding: 8px 14px;
    border-color: var(--neon-gold);
    color: var(--neon-gold);
    background: rgba(255,215,0,0.08);
}

#victory-buttons .ctrl-btn:hover {
    background: rgba(255,215,0,0.2);
    box-shadow: 0 0 15px rgba(255,215,0,0.3);
}

footer {
    font-family: var(--font);
    font-size: 7px;
    padding: 6px 12px;
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: center;
    background: var(--bg2);
    width: 100%;
    border-top: 1px solid rgba(26,107,255,0.1);
    z-index: 5;
}

footer span {
    opacity: 0.5;
}

footer a {
    color: var(--neon-blue);
    text-decoration: none;
    opacity: 0.7;
}

footer a:hover {
    opacity: 1;
    text-shadow: 0 0 8px var(--neon-blue);
}

@media (max-width: 600px) {
    #title { font-size: 8px; }
    #timer { font-size: 9px; }
    #level-display { font-size: 7px; }
    #moves, #best-time { font-size: 7px; }
    #dpad { display: flex; }
    .dpad-btn { width: 44px; height: 44px; font-size: 16px; }
}

@media (hover: none) and (pointer: coarse) {
    #dpad { display: flex; }
}