/* Collapse Grid Game - Optimized Layout */

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background-color: #222;
    color: white;
    min-height: 100vh;
    overflow-x: hidden;
}

.main-container {
    display: flex;
    min-height: 100vh;
    gap: 20px;
    padding: 10px;
}

.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0; /* Allow flex shrinking */
}

.enemy-hp {
    width: 100%;
    max-width: 800px;
    height: 35px;
    background-color: #444;
    border: 2px solid #666;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: #ff6666;
    margin-bottom: 5px;
    border-radius: 5px;
}

canvas {
    border: 2px solid #555;
    background-color: #333;
    cursor: pointer;
    max-width: calc(100vw - 300px); /* Reserve space for sidebar + padding */
    max-height: calc(100vh - 100px); /* Reduced reserved space for 20% more scaling room */
    width: auto;
    height: auto;
    border-radius: 5px;
    /* Maintain aspect ratio while scaling */
    object-fit: contain;
}

.player-hp {
    width: 100%;
    max-width: 800px;
    height: 35px;
    background-color: #444;
    border: 2px solid #666;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: #66ff66;
    margin-top: 5px;
    border-radius: 5px;
}

.turn-info {
    margin-top: 8px;
    text-align: center;
    font-size: 14px;
    color: #ffff99;
    max-width: 800px;
}

.stats-sidebar {
    width: 250px;
    background-color: #333;
    border: 2px solid #555;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: fit-content;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
}

.stats-section {
    background-color: #444;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #666;
}

.stats-section h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #ffff99;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-section div {
    font-size: 12px;
    margin: 3px 0;
    line-height: 1.3;
}

.guide-item {
    font-size: 11px !important;
    margin: 2px 0 !important;
}

.controls {
    text-align: center;
}

button {
    background-color: #555;
    color: white;
    border: 1px solid #777;
    padding: 8px 16px;
    cursor: pointer;
    margin: 3px;
    font-size: 12px;
    border-radius: 4px;
    width: 100%;
}

button:hover {
    background-color: #666;
}

.game-over {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #111;
    border: 3px solid #777;
    padding: 40px;
    text-align: center;
    font-size: 24px;
    z-index: 1000;
    display: none;
}

.victory {
    color: #66ff66;
}

.defeat {
    color: #ff6666;
}

/* Responsive Design for Mobile and Smaller Screens */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        padding: 5px;
        gap: 10px;
    }
    
    .stats-sidebar {
        width: 100%;
        max-height: none;
        order: 2; /* Move sidebar below game area */
    }
    
    .game-area {
        order: 1;
    }
    
    canvas {
        max-width: calc(100vw - 20px);
        max-height: calc(60vh);
    }
    
    .stats-section {
        padding: 8px;
    }
    
    .stats-section h3 {
        font-size: 13px;
    }
    
    .enemy-hp, .player-hp {
        height: 30px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .main-container {
        padding: 2px;
        gap: 5px;
    }
    
    canvas {
        max-width: calc(100vw - 10px);
        max-height: calc(55vh);
        touch-action: manipulation;
    }
    
    .stats-sidebar {
        padding: 10px;
    }
    
    .stats-section {
        padding: 6px;
    }
    
    .stats-section div {
        font-size: 11px;
    }
    
    .guide-item {
        font-size: 10px !important;
    }
    
    button {
        padding: 6px 12px;
        font-size: 11px;
        min-height: 40px;
        touch-action: manipulation;
    }
    
    /* Mobile-specific modal optimizations */
    [id*="Modal"] {
        padding: 5px !important;
    }
    
    /* Touch feedback improvements */
    button:active,
    [id*="upgradeCard"]:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

/* Mobile touch optimizations for all screen sizes */
@media (hover: none) and (pointer: coarse) {
    /* Prevent text selection on touch devices */
    body {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Improve touch targets */
    button {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }
    
    /* Canvas touch optimizations */
    canvas {
        touch-action: none;
        -webkit-touch-callout: none;
    }
    
    /* Prevent zoom on double tap for game elements */
    .game-area,
    .stats-sidebar {
        touch-action: manipulation;
    }
}

/* Prevent scrolling when modal is open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Responsive Upgrade Card Layouts */
@media (max-width: 768px) {
    /* Hide desktop layout and show mobile layout on tablets and phones */
    .upgrade-card .desktop-layout {
        display: none !important;
    }
    
    .upgrade-card .mobile-layout {
        display: flex !important;
    }
    
    /* Adjust upgrade card container for mobile */
    .upgrade-card {
        max-width: none !important;
        width: 100% !important;
        margin-bottom: 10px !important;
    }
    
    /* Adjust upgrade cards container */
    #upgradeCards {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }
}

@media (max-width: 480px) {
    /* Further mobile optimizations for small phones */
    .upgrade-card {
        padding: 12px !important;
    }
    
    .upgrade-card .mobile-layout {
        gap: 10px !important;
        min-height: 60px !important;
    }
    
    .upgrade-card .mobile-layout h3 {
        font-size: 13px !important;
    }
    
    .upgrade-card .mobile-layout p {
        font-size: 10px !important;
    }
    
    .upgrade-card .mobile-layout .stats-row {
        padding: 4px 6px !important;
    }
    
    .upgrade-card .mobile-layout .stats-row span {
        font-size: 9px !important;
    }
    
    .upgrade-card .mobile-layout .select-button {
        font-size: 11px !important;
        padding: 6px 8px !important;
    }
}
