/* ========================================
   MOBILE UI STYLES
   Separate file for all mobile-specific CSS
   ======================================== */

/* Mobile Detection & Base Styles */
@media (max-width: 768px) {
    body {
        /* Disable pull-to-refresh on mobile */
        overscroll-behavior-y: contain;
        touch-action: pan-x pan-y;
        -webkit-user-select: none;
        user-select: none;
        justify-content: flex-start !important;
    }

    /* Portrait Mode Layout */
    #game-container {
        gap: 0 !important;
        padding: 0 !important;
        margin: 0 auto !important;
        justify-content: flex-start !important;
        height: 100vh;
        overflow: hidden;
        width: 100% !important;
    }

    /* Title - Smaller and compact on mobile */
    h1 {
        font-size: 1.4rem !important;
        margin: 2px 0 !important;
        padding: 2px 0 !important;
    }

    /* UI Panel - Compact horizontal layout, positioned below canvas */
    #ui-panel {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 4px 8px !important;
        width: 100% !important;
        padding: 8px 5px !important;
        font-size: 0.75rem !important;
        justify-content: center !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: rgba(5, 7, 13, 0.95) !important;
        margin: 0 !important;
        order: 2 !important;
    }

    .ui-section {
        justify-content: center;
        gap: 6px !important;
    }

    /* Stamina bar - smaller on mobile */
    .stamina-bar {
        width: 100px !important;
    }

    /* Canvas - At top of screen, full width */
    #canvas {
        width: 100vw !important;
        height: auto !important;
        aspect-ratio: 1 / 1; /* Keep it square */
        border: none !important;
        max-width: 100vw;
        max-height: calc(100vh - 200px);
        flex-shrink: 0;
        display: block !important;
        margin: 0 auto !important;
        box-shadow: none !important;
        order: 1 !important;
    }

    /* Boss Health Bar - Positioned right below canvas on mobile */
    #bossHealthBarContainer {
        position: fixed !important;
        bottom: auto !important;
        top: calc(100vw + 2px) !important; /* Canvas is 100vw square, position right below it */
        left: 0 !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin: 0 !important;
        padding: 4px 8px !important;
        z-index: 100 !important;
    }

    #bossHealthBarContainer > div {
        padding: 6px 10px !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 4px !important;
        box-shadow: 0 0 15px rgba(255,51,85,0.4), 0 0 30px rgba(255,51,85,0.15) inset !important;
    }

    #bossHealthBarContainer .boss-title {
        font-size: 11px !important;
        margin-bottom: 4px !important;
    }

    #bossHealthBarContainer .boss-bar {
        height: 14px !important;
    }

    #bossHealthBarText {
        font-size: 10px !important;
    }

    /* Instructions - Hide on mobile to save space */
    #instructions {
        display: none !important;
    }

    /* Pause button - smaller */
    #pauseBtn {
        padding: 6px 10px !important;
        font-size: 0.9rem !important;
    }

    /* Show mobile-only elements only on mobile */
    [data-mobile-only] {
        display: block !important;
    }

    /* Overlays - Better mobile sizing */
    .overlay-panel {
        padding: 24px 20px !important;
        width: min(90vw, 400px) !important;
        min-width: unset !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    .overlay-panel h2 {
        font-size: 1.8rem !important;
    }

    .overlay-panel p {
        font-size: 1rem !important;
    }

    .overlay-panel button {
        padding: 12px 20px !important;
        font-size: 1rem !important;
    }

    /* Menu panel - mobile friendly */
    .menu-panel {
        width: min(95vw, 420px) !important;
        padding: 20px 16px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    .menu-title {
        font-size: 2rem !important;
    }

    /* Level grid - 3 columns on mobile */
    .level-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }

    .level-btn {
        padding: 10px 8px !important;
        font-size: 0.95rem !important;
    }
}

/* Hide mobile-only elements on desktop */
@media (min-width: 769px) {
    [data-mobile-only] {
        display: none !important;
    }
}

/* Hide desktop-only elements on mobile */
@media (max-width: 768px) {
    [data-desktop-only] {
        display: none !important;
    }
}

/* ========================================
   MOBILE CONTROLS - Virtual D-Pad & Buttons
   ======================================== */

/* Controls Container - simple block element stacked below canvas */
#mobile-controls {
    display: none; /* Hidden by default, shown via JS on mobile */
    position: relative;
    width: 100%;
    height: 150px; /* Must specify height since children are position:absolute */
    margin-top: 10px; /* Small cushion between canvas and controls */
    pointer-events: auto;
    z-index: 500;
    touch-action: none;
}

/* Show controls on mobile when game is active */
@media (max-width: 768px) {
    body.game-active #mobile-controls {
        display: block;
        order: 3 !important;
    }
}

/* D-Pad Container (Left Side) - Rotated 45deg to create vertical diamond */
.mobile-dpad {
    position: absolute;
    top: 50px;
    left: 60px;
    width: 80px;
    height: 80px;
    pointer-events: none;
    transform: rotate(0deg);
}

/* D-Pad Center - Hidden */
.dpad-center {
    display: none;
}

/* D-Pad Buttons - Positioned at corners of square rotated 45deg to form diamond */
.dpad-btn {
    position: absolute;
    width: 55px;
    height: 55px;
    background: linear-gradient(135deg, rgba(255, 123, 0, 0.7), rgba(255, 123, 0, 0.5));
    border: 2px solid rgba(255, 123, 0, 0.8);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    user-select: none;
    touch-action: auto;
    pointer-events: auto;
    transition: all 0.1s ease;
    transform: rotate(45deg);
}

.dpad-btn:active {
    background: linear-gradient(135deg, rgba(255, 123, 0, 0.9), rgba(255, 123, 0, 0.7));
    box-shadow: 0 0 15px rgba(255, 123, 0, 0.6);
}

/* Counter-rotate arrow icons to face correct direction */
.dpad-btn span {
    transform: rotate(-45deg);
    display: block;
}

/* D-Pad Positions - Diamond orientation with buttons touching edge-to-edge */
.dpad-up {
    top: -27.5px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
}

.dpad-up:active {
    transform: translateX(-50%) rotate(45deg);
}

.dpad-down {
    bottom: -27.5px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
}

.dpad-down:active {
    transform: translateX(-50%) rotate(45deg);
}

.dpad-left {
    left: -27.5px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

.dpad-left:active {
    transform: translateY(-50%) rotate(45deg);
}

.dpad-right {
    right: -27.5px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

.dpad-right:active {
    transform: translateY(-50%) rotate(45deg);
}

/* Action Buttons Container (Right Side) */
.mobile-actions {
    position: absolute;
    top: 0;
    right: 20px;
    width: 170px;
    height: 170px;
    pointer-events: auto;
}

/* Action Button Base Style */
.action-btn {
    position: absolute;
    width: 55px;
    height: 55px;
    background: linear-gradient(135deg, rgba(97, 218, 251, 0.8), rgba(97, 218, 251, 0.6));
    border: 2px solid rgba(97, 218, 251, 0.9);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    user-select: none;
    touch-action: none;
    transition: all 0.1s ease;
}

.action-btn:active {
    background: linear-gradient(135deg, rgba(97, 218, 251, 1), rgba(97, 218, 251, 0.8));
    box-shadow: 0 0 20px rgba(97, 218, 251, 0.7);
}

.action-btn-label {
    font-size: 0.65rem;
    font-weight: bold;
    margin-top: 2px;
    opacity: 0.9;
}

/* Action Button Positions (4-button diamond + 1 conditional) */
.action-shield {
    top: 5px;
    right: 50%;
    transform: translateX(50%);
    background: linear-gradient(135deg, rgba(255, 119, 170, 0.8), rgba(255, 119, 170, 0.6));
    border-color: rgba(255, 119, 170, 0.9);
}

.action-shield:active {
    background: linear-gradient(135deg, rgba(255, 119, 170, 1), rgba(255, 119, 170, 0.8));
    box-shadow: 0 0 20px rgba(255, 119, 170, 0.7);
    transform: translateX(50%);
}

.action-sprint {
    bottom: 5px;
    right: 50%;
    transform: translateX(50%);
    background: linear-gradient(135deg, rgba(255, 209, 102, 0.8), rgba(255, 209, 102, 0.6));
    border-color: rgba(255, 209, 102, 0.9);
}

.action-sprint:active {
    background: linear-gradient(135deg, rgba(255, 209, 102, 1), rgba(255, 209, 102, 0.8));
    box-shadow: 0 0 20px rgba(255, 209, 102, 0.7);
    transform: translateX(50%);
}

.action-interact {
    left: 5px;
    top: 50%;
    transform: translateY(-50%);
}

.action-interact:active {
    transform: translateY(-50%);
}

.action-trap {
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
}

.action-trap:active {
    transform: translateY(-50%);
}

.action-reload {
    display: none; /* Hidden by default, shown via JS when bazooka is available */
    top: 50%;
    right: 50%;
    transform: translate(50%, -50%);
    background: linear-gradient(135deg, rgba(130, 200, 255, 0.8), rgba(100, 170, 255, 0.6));
    border-color: rgba(130, 200, 255, 0.9);
    font-size: 0.9rem;
    width: 50px;
    height: 50px;
}

.action-reload:active {
    background: linear-gradient(135deg, rgba(130, 200, 255, 1), rgba(100, 170, 255, 0.8));
    box-shadow: 0 0 20px rgba(130, 200, 255, 0.7);
    transform: translate(50%, -50%);
}

/* Sprint button - "hold" indicator when active */
.action-sprint.holding {
    background: linear-gradient(135deg, rgba(255, 140, 0, 1), rgba(255, 165, 0, 0.9));
    box-shadow: 0 0 25px rgba(255, 165, 0, 0.8);
    animation: pulse-sprint 0.5s infinite;
}

@keyframes pulse-sprint {
    0%, 100% { transform: translateX(50%) scale(1); }
    50% { transform: translateX(50%) scale(1.05); }
}

/* ========================================
   LANDSCAPE WARNING OVERLAY
   ======================================== */

#landscape-warning {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    text-align: center;
    padding: 20px;
}

#landscape-warning .rotate-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: rotate-phone 2s ease-in-out infinite;
}

@keyframes rotate-phone {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-90deg); }
    75% { transform: rotate(-90deg); }
}

#landscape-warning h2 {
    font-size: 1.5rem;
    color: #ff7b00;
    margin-bottom: 10px;
}

#landscape-warning p {
    font-size: 1rem;
    color: #ccc;
}

/* Show warning when in landscape on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #landscape-warning {
        display: flex !important;
    }

    #game-container,
    #mobile-controls,
    #mainMenu,
    #overlay,
    #pauseOverlay,
    #winOverlay,
    #loseOverlay {
        display: none !important;
    }
}

/* ========================================
   ADDITIONAL MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
    /* Prevent text selection during gameplay */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Better touch targets for buttons */
    button {
        min-width: 44px;
        min-height: 44px;
    }

    /* Disable double-tap zoom */
    button, .dpad-btn, .action-btn {
        touch-action: manipulation;
    }

    /* Hide scrollbars on mobile */
    body::-webkit-scrollbar {
        display: none;
    }

    body {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    /* Fix hint/alert positioning on mobile - ensure it's above controls */
    #bottomAlertBox {
        bottom: 170px !important;
        max-width: 90% !important;
        font-size: 14px !important;
        padding: 12px 20px !important;
    }

    @keyframes slideUp {
        from { bottom: 100px !important; opacity: 0; }
        to { bottom: 170px !important; opacity: 1; }
    }
}
