* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #0a0b0e;
    font-family: 'JetBrains Mono', monospace;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* accounts for mobile browser toolbar showing/hiding */
    color: #e0e0e0;
    /* was touch-action: none, which (because touch-action's *used* value is
       the intersection of an element's value and all its ancestors') blocked
       ALL touch scrolling on the page, including inside .dashboard-wrapper's
       "CONTROLS" panel. pan-y still blocks pinch-zoom/double-tap-zoom
       (so the game stays locked at 100%) but allows normal vertical scroll. */
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    background: #0a0b0e;
}

.arena-wrapper {
    flex: 0 0 65%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    border-right: 1px solid rgba(0, 255, 255, 0.15);
}

.dashboard-wrapper {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    background: rgba(18, 20, 29, 0.6);
    overflow-y: auto;
}

#gameWrapper {
    position: relative;
    background: #111;
    border: 1px solid #333;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0, 150, 255, 0.1);
    width: 100%;
    max-width: 800px;
    overflow: hidden;
}

canvas {
    display: block;
    background: #000;
    width: 100%;
    height: auto;
    touch-action: none;
}

/* TOUCH ZONES - INSIDE THE GAME BUT ON THE SIDES */
.touch-zone {
    position: absolute;
    top: 0;
    height: 100%;
    width: 50%;
    z-index: 5;
    touch-action: none;
}

#touch-left {
    left: 0;
    background: rgba(0, 243, 255, 0.03);
}

#touch-right {
    right: 0;
    background: rgba(255, 0, 64, 0.03);
}

/* MOBILE CONTROL BUTTONS
   No longer absolutely positioned over the canvas - it now lives outside
   #gameWrapper (see index.html) and only appears on mobile via the media
   query below, laid out as a normal centered flex row under the control bar. */
#mobile-controls {
    display: none;
    justify-content: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.8);
    padding: 12px 20px;
    border-radius: 50px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: fit-content;
    margin: 12px auto 0;
}

.mobile-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.mobile-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.2);
}

/* OVERLAYS */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    z-index: 20;
    padding: 30px;
    backdrop-filter: blur(5px);
    /* Safety net: if content is ever taller than the overlay, allow it to
       scroll instead of being clipped by #gameWrapper's overflow:hidden */
    overflow-y: auto;
}

.overlay h1 {
    color: #00f3ff;
    font-size: 48px;
    margin-bottom: 10px;
    text-shadow: 0 0 40px rgba(0, 243, 255, 0.3);
}

.overlay p {
    color: #888;
    font-size: 14px;
    margin-bottom: 30px;
}

.overlay h2 {
    color: #fff;
    font-size: 24px;
    margin-bottom: 20px;
}

.menu-btn {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid rgba(0, 243, 255, 0.4);
    padding: 14px 30px;
    margin: 8px;
    font-size: 14px;
    cursor: pointer;
    width: 220px;
    font-family: inherit;
    letter-spacing: 1px;
    border-radius: 4px;
    transition: all 0.3s;
}

.menu-btn:hover {
    background: rgba(0, 243, 255, 0.15);
    border-color: #00f3ff;
    box-shadow: 0 0 30px rgba(0, 243, 255, 0.15);
    transform: scale(1.02);
}

.menu-btn:active {
    transform: scale(0.95);
}

.settings-btn {
    border-color: rgba(255, 170, 0, 0.4);
}

.settings-btn:hover {
    border-color: #ffaa00;
    box-shadow: 0 0 30px rgba(255, 170, 0, 0.15);
}

.back-btn {
    border-color: rgba(255, 255, 255, 0.2);
    margin-top: 20px;
}

.back-btn:hover {
    border-color: #fff;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.1);
}

.setting-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 250px;
    margin: 10px 0;
}

.setting-group label {
    color: #aaa;
    font-size: 12px;
    letter-spacing: 1px;
}

.setting-group input[type="color"] {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
}

.setting-group select {
    background: #1a1a2e;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 15px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    cursor: pointer;
    width: 100px;
}

.setting-group select:focus {
    outline: none;
    border-color: #00f3ff;
}

.setting-group select option {
    background: #1a1a2e;
    color: #fff;
}

/* DASHBOARD */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.dashboard-header h3 {
    font-size: 14px;
    letter-spacing: 2px;
    color: #aaa;
}

.status-badge {
    font-size: 10px;
    color: #00ff00;
    background: rgba(0, 255, 0, 0.1);
    padding: 4px 14px;
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 0, 0.2);
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 25px;
}

.metric-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 6px;
}

.metric-card label {
    display: block;
    font-size: 10px;
    color: #666;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-card span {
    font-size: 20px;
    font-weight: 700;
    color: #00f3ff;
}

.viz-wrapper {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: 10px;
}

.viz-wrapper h4 {
    font-size: 11px;
    color: #666;
    margin-bottom: 15px;
    letter-spacing: 2px;
}

.controls-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.controls-box div {
    color: #aaa;
    font-size: 13px;
    line-height: 1.6;
}

.controls-box strong {
    color: #00f3ff;
}

.control-bar {
    width: 100%;
    max-width: 800px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding: 0 10px;
    flex-wrap: wrap;
    gap: 10px;
}

.mono-text {
    font-size: 14px;
    color: #888;
    font-family: inherit;
    letter-spacing: 1px;
}

#score-display {
    color: #00f3ff;
    font-weight: 700;
}

/* MOBILE RESPONSIVE */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .arena-wrapper {
        flex: 1;
        padding: 10px;
        border-right: none;
        border-bottom: 1px solid rgba(0, 255, 255, 0.15);
        min-height: 0; /* lets this flex child actually size to its real available space */
    }

    #gameWrapper {
        width: auto;
        flex: 1;
        min-height: 0;
        max-width: 100%;
    }

    canvas {
        width: auto;
        height: 100%;
        max-width: 100%;
        margin: 0 auto;
    }

    .dashboard-wrapper {
        flex: 0 0 auto;
        max-height: 35vh;
        padding: 12px;
    }

    .touch-zone {
        width: 50%;
    }

    #mobile-controls {
        display: flex !important;
        padding: 10px 16px;
        gap: 12px;
    }

    .mobile-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    /* Hide keyboard-only (WASD) instructions - not relevant on touch devices */
    .desktop-only {
        display: none;
    }

    /* The settings menu was clipped because #gameWrapper's height is driven by
       the canvas aspect ratio and can be quite short on phones, while
       #gameWrapper also has overflow:hidden. Making the settings overlay
       "fixed" takes it out of that box entirely so it covers the full
       viewport and the CLOSE button (and everything else) is always visible. */
    #settings-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        z-index: 100;
        padding: 20px 20px 40px;
        overflow-y: auto;
    }

    .overlay h1 {
        font-size: 36px;
    }

    .menu-btn {
        width: 200px;
        padding: 12px 20px;
        font-size: 13px;
        margin: 6px;
    }

    .metrics-grid {
        gap: 10px;
    }

    .metric-card {
        padding: 10px;
    }

    .metric-card span {
        font-size: 16px;
    }

    .mono-text {
        font-size: 12px;
    }

    .setting-group {
        width: 200px;
    }

    .controls-box div {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .arena-wrapper {
        padding: 5px;
    }

    .dashboard-wrapper {
        padding: 8px;
        max-height: 30vh;
    }

    .overlay h1 {
        font-size: 28px;
    }

    .overlay p {
        font-size: 12px;
        margin-bottom: 20px;
    }

    .menu-btn {
        width: 170px;
        padding: 10px 16px;
        font-size: 12px;
        margin: 5px;
    }

    #mobile-controls {
        padding: 8px 14px;
        gap: 10px;
    }

    .mobile-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .metrics-grid {
        grid-template-columns: 1fr 1fr;
        gap: 5px;
    }

    .metric-card {
        padding: 8px;
    }

    .metric-card span {
        font-size: 14px;
    }

    .metric-card label {
        font-size: 8px;
    }

    .control-bar {
        gap: 5px;
        padding: 0 5px;
    }

    .mono-text {
        font-size: 10px;
    }

    .setting-group {
        width: 160px;
    }

    .setting-group label {
        font-size: 10px;
    }

    .setting-group select {
        font-size: 12px;
        padding: 5px 10px;
        width: 80px;
    }

    .setting-group input[type="color"] {
        width: 32px;
        height: 32px;
    }
}