/* --- Root Theme Variables --- */
:root {
    --bg-dark: #03030c;
    --neon-purple: #9d00ff;
    --font-main: 'Outfit', sans-serif;
}

/* --- Base Resets --- */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-main);
    color: #ffffff;
    user-select: none; /* Prevent accidental text selections while dragging touch controls */
}

body.touch-layout {
    position: fixed;
    inset: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

/* --- Viewport Layout --- */
.game-viewport {
    position: relative; /* Set up containment for HUD overlays */
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
    box-sizing: border-box;
    background: radial-gradient(circle at center, #0e0e28 0%, #03030c 100%);
}

body.touch-layout .game-viewport {
    height: 100dvh;
    min-height: 100dvh;
}

/* --- Game Canvas --- */
#game-canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border: 2px solid var(--neon-purple);
    border-radius: 8px;
    box-shadow: 0 0 25px rgba(157, 0, 255, 0.4), inset 0 0 15px rgba(157, 0, 255, 0.1);
    background-color: #010105;
}

body.touch-layout #game-canvas {
    border-width: 0;
    border-radius: 0;
    box-shadow: none;
}

/* --- Diagnostic HUD Overlay --- */
.debug-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 12px 16px;
    background: rgba(4, 4, 12, 0.85);
    border: 1px solid rgba(157, 0, 255, 0.4);
    border-radius: 6px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    color: #00f3ff;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    pointer-events: none; /* Mouse clicks pass through to canvas underneath */
    white-space: pre;
    z-index: 100;
}

body.touch-layout .debug-panel {
    display: none;
}

/* --- Bottom Weapon HUD Overlay --- */
.hud-container {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 420px; /* Expanded for abilities slot UI */
    background: rgba(3, 3, 10, 0.85);
    border: 1px solid rgba(157, 0, 255, 0.3);
    border-radius: 8px;
    padding: 12px 18px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
    pointer-events: none;
    z-index: 100;
    font-family: 'Share Tech Mono', monospace;
    color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

body.touch-layout .hud-container {
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(48vw, 340px);
    padding: 8px 10px;
    gap: 5px;
    opacity: 0.9;
}

.hud-heat-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.hud-heat-label {
    font-size: 0.8rem;
    letter-spacing: 2px;
    color: #8888aa;
    text-shadow: 0 0 5px rgba(136, 136, 170, 0.3);
}

.hud-heat-bar-wrapper {
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(157, 0, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.hud-heat-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(to right, #00f3ff, #ff7700);
    transition: width 0.05s linear;
}

.hud-heat-fill.overheated {
    background: #ff3333;
    box-shadow: 0 0 8px #ff3333;
}

.hud-overheat-alert {
    font-size: 0.8rem;
    font-weight: bold;
    color: #ff3333;
    letter-spacing: 1px;
    text-shadow: 0 0 6px rgba(255, 51, 51, 0.8);
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
}

.hud-overheat-alert.visible {
    opacity: 1;
    animation: flash-red 0.8s infinite alternate;
}

@keyframes flash-red {
    0% { opacity: 0.3; text-shadow: 0 0 2px rgba(255, 51, 51, 0.3); }
    100% { opacity: 1; text-shadow: 0 0 10px rgba(255, 51, 51, 0.9); }
}

.hud-swap-prompt {
    font-size: 0.75rem;
    letter-spacing: 1px;
    color: #00f3ff;
    text-shadow: 0 0 5px rgba(0, 243, 255, 0.4);
    margin-top: 2px;
    text-align: center;
}

/* --- Abilities Panel --- */
.hud-abilities-panel {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
    margin-top: 2px;
    border-top: 1px solid rgba(157, 0, 255, 0.25);
    padding-top: 8px;
}

.hud-ability-slot {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    height: 38px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(0, 243, 255, 0.2);
    border-radius: 4px;
    padding: 0 12px;
    box-sizing: border-box;
}

.hud-ability-key {
    background: #090916;
    border: 1.5px solid #00f3ff;
    border-radius: 4px;
    color: #00f3ff;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    box-shadow: 0 0 6px rgba(0, 243, 255, 0.35);
}

.hud-ability-label {
    font-size: 0.75rem;
    color: #e0e0ff;
    letter-spacing: 0.5px;
    font-weight: bold;
}

.hud-ability-cd {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(3, 3, 12, 0.82);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #ff9d18;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.1s ease;
    pointer-events: none;
    letter-spacing: 1px;
}

.hud-ability-cd.visible {
    opacity: 1;
}

.selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Start from top to support scrolling height */
    background: rgba(3, 3, 12, 0.88);
    z-index: 1000;
    transition: opacity 0.3s ease;
    overflow-y: auto; /* Enable vertical scrolling */
    padding: 30px 15px;
    box-sizing: border-box;
    touch-action: pan-y; /* Enable vertical swipe gestures to scroll */
}

.selection-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.selection-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(8, 8, 22, 0.9);
    border: 2px solid var(--neon-purple);
    border-radius: 12px;
    padding: 25px 35px;
    box-shadow: 0 0 35px rgba(157, 0, 255, 0.45);
    width: 90%;
    max-width: 1150px;
    box-sizing: border-box;
    text-align: center;
}

.selection-title {
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: 3px;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.7);
    margin: 0 0 20px 0;
}

.mech-cards-row {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
    margin-bottom: 20px;
}

.mech-card {
    flex: 1 1 150px;
    max-width: 210px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(0, 243, 255, 0.15);
    border-radius: 8px;
    padding: 12px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
    gap: 8px;
}

.mech-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(0, 243, 255, 0.4);
    transform: translateY(-4px);
}

.mech-card.selected {
    background: rgba(157, 0, 255, 0.1);
    border-color: var(--neon-purple);
    box-shadow: 0 0 18px rgba(157, 0, 255, 0.35);
}

.mech-card-preview-frame {
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    border: 1px solid rgba(157, 0, 255, 0.2);
    margin-bottom: 5px;
    overflow: hidden;
}

.mech-card-img {
    width: 70px;
    height: 70px;
    object-fit: contain;
}

.mech-card-name {
    font-size: 1.05rem;
    font-weight: bold;
    letter-spacing: 1px;
    color: #00f3ff;
    text-shadow: 0 0 5px rgba(0, 243, 255, 0.4);
    margin: 0;
}

.mech-card-stats {
    display: flex;
    justify-content: space-around;
    width: 100%;
    margin-top: 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 8px;
}

.mech-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-lbl {
    font-size: 0.65rem;
    color: #8888aa;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.stat-val {
    font-size: 0.85rem;
    color: #ffffff;
    font-weight: bold;
    margin-top: 2px;
}

.mech-card-abilities {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    text-align: left;
    margin-top: 5px;
    font-family: 'Share Tech Mono', monospace;
}

.card-ability {
    font-size: 0.7rem;
    line-height: 1.35;
    color: #cccccc;
}

.card-ability strong {
    color: #ffffff;
}

.ab-key {
    display: inline-block;
    background: #090916;
    border: 1px solid #00f3ff;
    border-radius: 3px;
    color: #00f3ff;
    width: 14px;
    height: 14px;
    text-align: center;
    line-height: 14px;
    font-size: 0.65rem;
    font-weight: bold;
    margin-right: 4px;
    vertical-align: middle;
    box-shadow: 0 0 3px rgba(0, 243, 255, 0.4);
}

.difficulty-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
}

.difficulty-label {
    font-family: var(--font-main);
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 2px;
    font-weight: bold;
}

.difficulty-options {
    display: flex;
    gap: 6px;
}

.difficulty-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.5);
    font-family: var(--font-main);
    font-weight: bold;
    font-size: 0.65rem;
    letter-spacing: 1.5px;
    padding: 5px 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.difficulty-btn:hover {
    background: rgba(0, 243, 255, 0.1);
    border-color: rgba(0, 243, 255, 0.4);
    color: #00f3ff;
}

.difficulty-btn.selected {
    background: rgba(0, 243, 255, 0.15);
    border-color: #00f3ff;
    color: #00f3ff;
    box-shadow: 0 0 8px rgba(0, 243, 255, 0.3);
}

.difficulty-btn.selected[data-difficulty="easy"] {
    background: rgba(0, 255, 100, 0.12);
    border-color: #00ff66;
    color: #00ff66;
    box-shadow: 0 0 8px rgba(0, 255, 100, 0.3);
}

.difficulty-btn.selected[data-difficulty="hard"] {
    background: rgba(255, 60, 60, 0.12);
    border-color: #ff3c3c;
    color: #ff3c3c;
    box-shadow: 0 0 8px rgba(255, 60, 60, 0.3);
}

.selection-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 12px;
}

.selection-deploy-btn, .selection-train-btn {
    border: none;
    border-radius: 6px;
    color: #ffffff;
    font-family: var(--font-main);
    font-weight: bold;
    font-size: 1.05rem;
    letter-spacing: 1.5px;
    padding: 12px 35px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 5px;
}

.selection-deploy-btn {
    background: linear-gradient(135deg, var(--neon-purple), #5d00a8);
    box-shadow: 0 0 15px rgba(157, 0, 255, 0.35);
}

.selection-deploy-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 0 25px rgba(157, 0, 255, 0.6);
}

.selection-deploy-btn:active {
    transform: scale(0.98);
}

.selection-train-btn {
    background: linear-gradient(135deg, #00f3ff, #0055ff);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.35);
}

.selection-train-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 0 25px rgba(0, 243, 255, 0.6);
}

.selection-train-btn:active {
    transform: scale(0.98);
}

.map-selector-row {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
    margin: 10px 0 20px 0;
}

.map-card {
    background: rgba(10, 10, 20, 0.75);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    width: 140px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.map-card:hover {
    transform: translateY(-3px);
    border-color: rgba(0, 243, 255, 0.4);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
}

.map-card.selected {
    border-color: #00f3ff;
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.5);
    background: rgba(0, 243, 255, 0.05);
}

.map-card-preview {
    height: 70px;
    border-radius: 4px;
    background-size: cover;
    background-position: center;
    margin-bottom: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.map-card-name {
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: bold;
    color: #ffffff;
    text-align: center;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   MULTIPLAYER LOBBY & MAIN MENU STYLES
   ========================================================================== */
.selection-subtitle {
    font-family: var(--font-main);
    font-size: 0.8rem;
    letter-spacing: 3px;
    color: var(--neon-cyan);
    margin-top: -15px;
    margin-bottom: 25px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.4);
}

.main-menu-box {
    max-width: 480px;
    padding: 40px;
}

.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.menu-btn {
    border: none;
    border-radius: 6px;
    color: #ffffff;
    font-family: var(--font-main);
    font-weight: bold;
    font-size: 1.05rem;
    letter-spacing: 1.5px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.solo-btn {
    background: linear-gradient(135deg, #333, #111);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.05);
}

.solo-btn:hover {
    transform: scale(1.02);
    border-color: rgba(255, 255, 255, 0.35);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.15);
}

.create-btn {
    background: linear-gradient(135deg, var(--neon-purple), #5d00a8);
    box-shadow: 0 0 15px rgba(157, 0, 255, 0.35);
}

.create-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 0 25px rgba(157, 0, 255, 0.6);
}

.menu-divider {
    display: flex;
    align-items: center;
    width: 100%;
    margin: 25px 0;
    color: rgba(255, 255, 255, 0.3);
    font-family: var(--font-main);
    font-size: 0.75rem;
    letter-spacing: 1.5px;
    font-weight: bold;
}

.menu-divider::before, .menu-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
}

.menu-divider span {
    padding: 0 15px;
}

.menu-join-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.menu-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(0, 243, 255, 0.2);
    border-radius: 6px;
    color: #ffffff;
    font-family: var(--font-mono);
    font-size: 1.05rem;
    letter-spacing: 2px;
    padding: 12px;
    text-align: center;
    outline: none;
    transition: all 0.2s ease;
}

.menu-input:focus {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.25);
    background: rgba(0, 0, 0, 0.6);
}

.join-btn {
    background: linear-gradient(135deg, #00f3ff, #0055ff);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.35);
    padding: 12px 25px;
    width: auto;
    font-size: 0.95rem;
}

.join-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 0 25px rgba(0, 243, 255, 0.6);
}

.menu-status {
    font-family: var(--font-main);
    font-size: 0.8rem;
    color: #ff3c3c;
    margin-top: 15px;
    min-height: 18px;
    font-weight: bold;
    letter-spacing: 0.5px;
}

/* Room Details Panel inside Selection Box */
.lobby-room-details {
    width: 100%;
    margin-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 20px;
}

.room-code-header {
    font-family: var(--font-main);
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    letter-spacing: 1.5px;
    text-align: center;
}

.room-code-value {
    font-family: var(--font-mono);
    color: var(--neon-cyan);
    font-weight: bold;
    font-size: 1.6rem;
    letter-spacing: 3px;
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.5);
    margin-left: 8px;
}

.room-players-panel {
    margin-top: 15px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 15px;
    max-height: 150px;
    overflow-y: auto;
}

.room-players-title {
    font-family: var(--font-main);
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 2px;
    font-weight: bold;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 5px;
}

.room-players-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    padding: 8px 12px;
    font-family: var(--font-main);
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: bold;
}

.player-card.is-local {
    border-color: rgba(0, 243, 255, 0.35);
    background: rgba(0, 243, 255, 0.03);
}

.player-card-meta {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.45);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.lobby-start-btn {
    border: none;
    border-radius: 6px;
    color: #ffffff;
    font-family: var(--font-main);
    font-weight: bold;
    font-size: 1.1rem;
    letter-spacing: 2px;
    padding: 14px 40px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: block;
    margin: 20px auto 0 auto;
    background: linear-gradient(135deg, var(--neon-purple), #9d00ff);
    box-shadow: 0 0 15px rgba(157, 0, 255, 0.45);
}

.lobby-start-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 0 25px rgba(157, 0, 255, 0.7);
}

.lobby-waiting-msg {
    font-family: var(--font-main);
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    margin-top: 20px;
    letter-spacing: 1px;
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.4; }
    to { opacity: 0.8; }
}

/* ==========================================================================
   MOBILE VIRTUAL TOUCH CONTROLS
   ========================================================================== */
.touch-controls {
    display: none; /* Auto-shown only on touch devices by touch_controls.js */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let touches fall through to controls zone */
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.touch-controls.is-active {
    display: block;
}

.touch-target-zone {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    touch-action: none;
}

.touch-controls.targeting .touch-target-zone {
    pointer-events: auto;
    background:
        radial-gradient(circle at center, rgba(255, 215, 0, 0.10), rgba(255, 215, 0, 0.02) 38%, transparent 64%);
}

/* Left Half Joystick Area */
.joystick-zone {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 50%;
    height: 60%;
    pointer-events: auto; /* Active touch capture zone */
}

.joystick-base {
    position: fixed;
    left: max(22px, env(safe-area-inset-left));
    bottom: max(22px, env(safe-area-inset-bottom));
    width: 120px;
    height: 120px;
    background: rgba(0, 0, 0, 0.35);
    border: 2px solid rgba(0, 243, 255, 0.4);
    border-radius: 50%;
    box-shadow: 0 0 12px rgba(0, 243, 255, 0.2);
    opacity: 0.4;
    transition: opacity 0.2s ease;
    pointer-events: none; /* Handled by coordinate tracking */
    touch-action: none;
}

.joystick-knob {
    position: absolute;
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    left: 32px;
    top: 32px;
}

/* Right Side Button Panel */
.touch-action-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 50%;
    height: 70%;
    display: flex;
    pointer-events: none;
}

/* Whole background drag zones to aim */
.touch-side-drag-zone {
    flex: 1;
    height: 100%;
    pointer-events: auto; /* Active touch aim zone */
}

.aim-stick-base {
    position: fixed;
    right: max(118px, calc(env(safe-area-inset-right) + 118px));
    bottom: max(112px, calc(env(safe-area-inset-bottom) + 112px));
    z-index: 1;
    width: 112px;
    height: 112px;
    background: rgba(0, 0, 0, 0.28);
    border: 2px solid rgba(255, 215, 0, 0.38);
    border-radius: 50%;
    box-shadow: 0 0 14px rgba(255, 215, 0, 0.18);
    opacity: 0.45;
    pointer-events: none;
    touch-action: none;
    transition: opacity 0.12s ease;
}

.aim-stick-knob {
    position: absolute;
    left: 30px;
    top: 30px;
    width: 50px;
    height: 50px;
    background: rgba(255, 215, 0, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.42), 0 0 12px rgba(255, 215, 0, 0.34);
    pointer-events: none;
}

.touch-buttons-row {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 200px;
    height: 200px;
    pointer-events: auto; /* Active touch buttons zone */
    z-index: 4;
}

.touch-btn {
    position: absolute;
    border: none;
    border-radius: 50%;
    color: #ffffff;
    font-family: var(--font-main);
    font-weight: 900;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.05s ease, background 0.1s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

/* Fire button - placed in bottom-right of cluster */
.touch-btn-fire {
    width: 82px;
    height: 82px;
    right: 10px;
    bottom: 10px;
    font-size: 2.2rem;
    background: rgba(255, 80, 0, 0.25);
    border: 3.5px solid #ff5000;
    box-shadow: 0 0 20px rgba(255, 80, 0, 0.5);
    text-shadow: 0 0 5px rgba(255, 80, 0, 0.6);
}

/* Q Button - placed to the left of the fire button */
.touch-btn-q {
    width: 58px;
    height: 58px;
    right: 110px;
    bottom: 15px;
    font-size: 1.3rem;
    background: rgba(0, 243, 255, 0.2);
    border: 2.5px solid #00f3ff;
    box-shadow: 0 0 12px rgba(0, 243, 255, 0.4);
    text-shadow: 0 0 4px rgba(0, 243, 255, 0.5);
}

/* E Button - placed above the fire button */
.touch-btn-e {
    width: 58px;
    height: 58px;
    right: 35px;
    bottom: 110px;
    font-size: 1.3rem;
    background: rgba(255, 215, 0, 0.2);
    border: 2.5px solid #ffd700;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
    text-shadow: 0 0 4px rgba(255, 215, 0, 0.5);
}

/* Button pressed feedbacks */
.touch-btn.pressed {
    transform: scale(0.88);
}
.touch-btn-fire.pressed {
    background: rgba(255, 80, 0, 0.5) !important;
}
.touch-btn-q.pressed {
    background: rgba(0, 243, 255, 0.45) !important;
}
.touch-btn-e.pressed {
    background: rgba(255, 215, 0, 0.45) !important;
}

.touch-btn.targeting {
    transform: scale(1.05);
    filter: brightness(1.25);
}

@media (hover: none), (pointer: coarse), (max-width: 1180px), (max-height: 820px) {
    html,
    body {
        height: 100dvh;
    }

    body.touch-layout .game-viewport {
        height: 100dvh;
        min-height: 100dvh;
    }

    body.touch-layout #game-canvas {
        border-width: 0;
        border-radius: 0;
        box-shadow: none;
    }

    body.touch-layout .debug-panel {
        display: none;
    }

    body.touch-layout .selection-overlay {
        padding: max(12px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
    }

    body.touch-layout .selection-box {
        width: min(96vw, 780px);
        padding: 18px 14px;
    }

    body.touch-layout .main-menu-box {
        max-width: min(92vw, 460px);
        padding: 26px 18px;
    }

    body.touch-layout .selection-title {
        font-size: clamp(1.05rem, 4vw, 1.45rem);
        letter-spacing: 1.5px;
        margin-bottom: 12px;
    }

    body.touch-layout .selection-subtitle {
        margin-top: -5px;
        margin-bottom: 18px;
        font-size: 0.68rem;
        letter-spacing: 1.5px;
    }

    body.touch-layout .menu-join-row {
        flex-direction: column;
    }

    body.touch-layout .join-btn {
        width: 100%;
    }

    body.touch-layout .mech-cards-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
        gap: 8px;
    }

    body.touch-layout .mech-card {
        max-width: none;
        padding: 9px 8px;
    }

    body.touch-layout .mech-card-preview-frame {
        width: 68px;
        height: 68px;
    }

    body.touch-layout .mech-card-img {
        width: 54px;
        height: 54px;
    }

    body.touch-layout .mech-card-name {
        font-size: 0.82rem;
    }

    body.touch-layout .card-ability {
        font-size: 0.68rem;
        line-height: 1.18;
    }

    body.touch-layout .map-selector-row {
        gap: 8px;
    }

    body.touch-layout .hud-container {
        bottom: max(8px, env(safe-area-inset-bottom));
        width: min(48vw, 340px);
        padding: 8px 10px;
        gap: 5px;
        opacity: 0.9;
    }

    body.touch-layout .hud-heat-label {
        font-size: 0.62rem;
        letter-spacing: 1px;
    }

    body.touch-layout .hud-abilities-panel {
        gap: 6px;
        padding-top: 6px;
    }

    body.touch-layout .hud-ability-slot {
        height: 32px;
        gap: 6px;
        padding: 0 7px;
    }

    body.touch-layout .hud-ability-key {
        width: 18px;
        height: 18px;
        font-size: 0.68rem;
    }

    body.touch-layout .hud-ability-label,
    body.touch-layout .hud-ability-cd {
        font-size: 0.62rem;
        letter-spacing: 0;
    }
}

@media (max-width: 700px), (max-height: 480px) {
    body.touch-layout .hud-container {
        width: min(44vw, 270px);
        padding: 6px 7px;
    }

    body.touch-layout .hud-heat-panel {
        gap: 4px;
    }

    body.touch-layout .hud-heat-label {
        display: none;
    }

    body.touch-layout .hud-heat-bar-wrapper {
        height: 8px;
    }

    body.touch-layout .touch-buttons-row {
        right: max(14px, env(safe-area-inset-right));
        bottom: max(18px, env(safe-area-inset-bottom));
    }

    body.touch-layout .aim-stick-base {
        right: max(92px, calc(env(safe-area-inset-right) + 92px));
        bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px));
    }
}

@media (orientation: portrait) and (max-width: 820px) {
    body.touch-layout .hud-container {
        top: max(8px, env(safe-area-inset-top));
        bottom: auto;
        width: min(88vw, 360px);
    }

    body.touch-layout .touch-buttons-row {
        bottom: max(18px, env(safe-area-inset-bottom));
    }
}
