/* ===== MOBILE TOUCH CONTROLS ===== */
.mobile-only {
    display: none;
}

/* Only show on narrow screens AND touch devices (prevents desktop touch monitors from triggering) */
@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
    .mobile-only {
        display: block;
    }
}

#mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 200px;
    pointer-events: none;
    z-index: 1000;
    display: none;
    /* Hidden by default, shown via JS during gameplay */
}

#mobile-controls.visible {
    display: block;
}

#dpad {
    position: absolute;
    left: 30px;
    bottom: 30px;
    width: 150px;
    height: 150px;
    pointer-events: all;
}

.dpad-center {
    position: absolute;
    width: 50px;
    height: 50px;
    top: 50px;
    left: 50px;
    background: rgba(0, 243, 255, 0.1);
    border-radius: 50%;
    border: 2px solid rgba(0, 243, 255, 0.3);
}

.dpad-btn {
    position: absolute;
    width: 50px;
    height: 50px;
    background: rgba(0, 243, 255, 0.2);
    border: 2px solid var(--neon-blue, #00f3ff);
    border-radius: 8px;
    color: var(--neon-blue, #00f3ff);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.3);
}

.dpad-btn:active {
    background: rgba(0, 243, 255, 0.5);
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.8);
    transform: scale(0.95);
}

.dpad-up {
    top: 0;
    left: 50px;
}

.dpad-down {
    bottom: 0;
    left: 50px;
}

.dpad-left {
    top: 50px;
    left: 0;
}

.dpad-right {
    top: 50px;
    right: 0;
}

#action-buttons {
    position: absolute;
    right: 30px;
    bottom: 30px;
    display: flex;
    gap: 15px;
    pointer-events: all;
}

.action-btn {
    width: 70px;
    height: 70px;
    background: rgba(255, 0, 255, 0.2);
    border: 2px solid var(--neon-pink, #ff00ff);
    border-radius: 50%;
    color: var(--neon-pink, #ff00ff);
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 0 10px rgba(255, 0, 255, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    font-family: 'Orbitron', sans-serif;
}

.action-btn:active {
    background: rgba(255, 0, 255, 0.5);
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.8);
    transform: scale(0.95);
}

#mobile-tnt-btn {
    background: rgba(255, 68, 68, 0.2);
    border-color: #ff4444;
    color: #ff4444;
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.3);
}

#mobile-tnt-btn:active {
    background: rgba(255, 68, 68, 0.5);
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
}

/* MOBILE: Hide keyboard instructions in Game Over screen */
@media (max-width: 768px),
(hover: none) {
    #message-subtitle.keyboard-hint {
        display: none !important;
    }
}

/* MOBILE: RESTART button visibility */
@media (max-width: 768px),
(hover: none) {
    #message-restart-btn {
        display: block !important;
        font-size: 22px !important;
        padding: 15px 50px !important;
        margin: 20px auto !important;
        width: auto !important;
        min-width: 200px;
        pointer-events: all !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(255, 0, 255, 0.3);
        z-index: 9999;
    }

    #message-restart-btn.hidden {
        display: none !important;
    }
}

/* ===== LEVEL SELECTOR MOBILE STYLES ===== */
@media (max-width: 768px),
(hover: none) {
    #level-selector-modal {
        padding: 15px;
        max-width: 95vw;
        max-height: 70vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .level-selector-content {
        display: flex;
        flex-direction: column;
        max-height: 100%;
        overflow: hidden;
    }

    .level-selector-content h2 {
        font-size: 1.2rem;
        margin-bottom: 5px;
        flex-shrink: 0;
    }

    #level-pack-info {
        font-size: 0.7rem;
        margin-bottom: 8px;
        flex-shrink: 0;
    }

    .level-list {
        flex: 1;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        gap: 8px;
        padding: 5px;
        margin-bottom: 10px;
        -webkit-overflow-scrolling: touch;
    }

    .level-item {
        padding: 10px 8px;
        gap: 8px;
        min-height: 50px;
        flex-shrink: 0;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(255, 0, 255, 0.3);
    }

    .level-number {
        font-size: 14px;
        min-width: 22px;
    }

    .level-preview {
        width: 50px;
        height: 25px;
    }

    .level-title {
        font-size: 11px;
    }

    .level-meta {
        font-size: 9px;
        gap: 8px;
    }

    #level-selector-modal .modal-buttons {
        gap: 10px;
        flex-wrap: wrap;
        flex-shrink: 0;
        padding-top: 5px;
    }

    #level-selector-modal .menu-button {
        padding: 10px 20px;
        font-size: 13px;
        min-width: 100px;
    }
}

/* ===== HELP MODAL MOBILE STYLES ===== */
@media (max-width: 768px),
(hover: none) {
    #help-modal {
        padding: 15px;
        max-width: 95vw;
        max-height: 75vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        z-index: 500;
    }

    .help-modal-content {
        display: flex;
        flex-direction: column;
        max-height: 100%;
        overflow: hidden;
    }

    .help-modal-content h2 {
        font-size: 1.3rem;
        margin-bottom: 10px;
        flex-shrink: 0;
    }

    .help-scroll-area {
        flex: 1;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        padding: 8px 12px;
        margin-bottom: 10px;
        -webkit-overflow-scrolling: touch;
    }

    .help-section {
        margin-bottom: 18px;
        padding-bottom: 15px;
    }

    .help-section h3 {
        font-size: 0.95rem;
        margin-bottom: 10px;
    }

    .help-item {
        font-size: 0.75rem;
        margin-bottom: 8px;
        gap: 8px;
    }

    .help-icon {
        font-size: 1rem;
        min-width: 24px;
    }

    .help-subsection {
        margin: 10px 0;
        padding-left: 8px;
    }

    .help-subsection h4 {
        font-size: 0.8rem;
        margin-bottom: 8px;
    }

    #help-modal .modal-buttons {
        flex-shrink: 0;
        padding-top: 5px;
        margin-top: 8px;
    }

    #help-modal .menu-button {
        padding: 10px 30px;
        font-size: 14px;
    }
}

/* Landscape mobile - even more compact */
@media (max-height: 500px) {
    #help-modal {
        max-height: 90vh;
        padding: 10px;
    }

    .help-modal-content h2 {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    .help-scroll-area {
        padding: 5px 10px;
        margin-bottom: 5px;
    }

    .help-section {
        margin-bottom: 12px;
        padding-bottom: 10px;
    }

    .help-section h3 {
        font-size: 0.85rem;
        margin-bottom: 8px;
    }

    .help-item {
        font-size: 0.7rem;
        margin-bottom: 5px;
    }

    #help-modal .modal-buttons {
        margin-top: 5px;
        padding-top: 0;
    }

    #help-modal .menu-button {
        padding: 8px 25px;
        font-size: 12px;
    }
}

/* ===== MAIN MENU MOBILE LANDSCAPE STYLES ===== */
@media (max-height: 500px) {
    #menu-screen {
        justify-content: flex-start;
        padding: 10px 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .game-title {
        font-size: 28px;
        margin-bottom: 10px;
        flex-shrink: 0;
    }

    .menu-buttons-container {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        gap: 6px;
        margin-bottom: 8px;
        width: 280px;
        padding: 5px;
        -webkit-overflow-scrolling: touch;
    }

    .menu-button {
        padding: 8px 16px;
        font-size: 13px;
    }

    .menu-hint {
        font-size: 11px;
        margin-top: 5px;
        flex-shrink: 0;
    }
}

/* ===== MOBILE EDITOR STYLES ===== */
#editor-mobile-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-around;
    align-items: center;
    padding: 4px 3px;
    background: rgba(0, 0, 0, 0.95);
    border-top: 1px solid var(--neon-blue, #00f3ff);
    z-index: 1100;
    gap: 3px;
    pointer-events: auto;
    /* Enable clicks - override parent's pointer-events: none */
}

.editor-mobile-btn {
    flex: 1;
    min-width: 32px;
    max-width: 50px;
    padding: 4px 2px;
    font-size: 8px;
    font-family: 'Orbitron', sans-serif;
    text-align: center;
    line-height: 1.1;
    color: var(--neon-blue, #00f3ff);
    background: rgba(0, 243, 255, 0.1);
    border: 1px solid var(--neon-blue, #00f3ff);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 0 5px rgba(0, 243, 255, 0.3);
}

.editor-mobile-btn:active {
    background: rgba(0, 243, 255, 0.4);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.6);
    transform: scale(0.95);
}

.editor-mobile-btn.active {
    background: rgba(255, 68, 68, 0.3);
    border-color: #ff4444;
    color: #ff4444;
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
}

#editor-btn-erase.active {
    background: rgba(255, 68, 68, 0.4);
    border-color: #ff4444;
    color: #ff4444;
}

@media (max-width: 768px),
(hover: none) and (pointer: coarse) {
    #editor-mobile-toolbar {
        display: flex;
    }

    #editor-info {
        display: none !important;
    }

    #editor-toolbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1050;
        padding: 5px;
        background: rgba(0, 0, 0, 0.95);
        border-bottom: 2px solid var(--neon-blue, #00f3ff);
    }

    #editor-palette {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: center;
        max-height: 80px;
        overflow-y: auto;
    }

    #editor-palette .palette-item {
        min-width: 48px;
        min-height: 36px;
        width: 48px;
        height: 36px;
        font-size: 8px;
        padding: 2px;
    }

    /* Shift game canvas for palette at top and toolbar at bottom */
    #game-container {
        margin-top: 80px;
        margin-bottom: 70px;
    }

    #editor-export {
        display: none;
    }

    #editor-overlay {
        padding-bottom: 100px;
    }
}

/* ===== MOBILE PAUSE MENU COMPACT STYLES ===== */
@media (max-width: 768px),
(hover: none) {
    #pause-overlay {
        padding: 20px 30px;
    }

    #pause-overlay h1 {
        font-size: 2rem;
        margin-bottom: 10px;
    }

    .pause-menu-buttons {
        gap: 8px;
        margin-top: 10px;
    }

    .pause-menu-buttons .menu-button {
        padding: 8px 16px;
        font-size: 12px;
    }
}

/* Landscape - even more compact */
@media (max-height: 500px) {
    #pause-overlay {
        padding: 15px 25px;
    }

    #pause-overlay h1 {
        font-size: 1.5rem;
        margin-bottom: 5px;
    }

    .pause-menu-buttons {
        gap: 5px;
        margin-top: 5px;
    }

    .pause-menu-buttons .menu-button {
        padding: 6px 12px;
        font-size: 11px;
    }
}

/* ===== SETTINGS MODAL MOBILE STYLES ===== */
@media (max-width: 768px),
(hover: none) {

    /* Settings floating button - reposition to not overlap HUD */
    .settings-float-btn {
        top: 60px;
        right: 10px;
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    #settings-modal {
        padding: 15px;
        max-width: 95vw;
        max-height: 85vh;
        width: 95%;
    }

    .settings-modal-content h2 {
        font-size: 1.2rem;
        margin-bottom: 12px;
    }

    .settings-section {
        margin: 10px 0;
        padding: 10px;
    }

    .settings-section h3 {
        font-size: 0.8rem;
        margin-bottom: 8px;
    }

    .setting-row {
        margin: 8px 0;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .setting-row label {
        flex: 0 0 65px;
        font-size: 0.7rem;
    }

    .setting-row input[type="range"] {
        height: 8px;
        min-width: 80px;
    }

    .setting-row input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    .setting-row select {
        padding: 8px 6px;
        font-size: 0.7rem;
        min-width: 100px;
    }

    .setting-row span {
        flex: 0 0 35px;
        font-size: 0.7rem;
    }

    .settings-toggle-btn {
        padding: 8px 12px;
        font-size: 0.65rem;
    }

    #settings-modal .modal-buttons {
        margin-top: 12px;
    }

    #settings-modal .menu-button {
        padding: 10px 25px;
        font-size: 13px;
    }
}

/* Settings in landscape mode */
@media (max-height: 500px) {
    .settings-float-btn {
        top: 8px;
        right: 8px;
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    #settings-modal {
        max-height: 95vh;
        padding: 10px;
    }

    .settings-section {
        margin: 6px 0;
        padding: 8px;
    }

    .settings-section h3 {
        font-size: 0.75rem;
        margin-bottom: 5px;
    }

    .setting-row {
        margin: 5px 0;
    }

    #settings-modal .menu-button {
        padding: 8px 20px;
        font-size: 12px;
    }
}