/* responsive-scaling.css - Dynamic scaling based on screen size and resolution */

/* === RESPONSIVE SCALING SYSTEM === */
:root {
    /* Base scaling factor - starts at 1.0 for desktop */
    --ui-scale: 1.0;
    --font-scale: 1.0;
    --button-scale: 1.0;
    --spacing-scale: 1.0;
}

/* === SCREEN SIZE BASED SCALING === */

/* Large Desktop: 1920px+ */
@media (min-width: 1920px) {
    :root {
        --ui-scale: 1.2;
        --font-scale: 1.1;
        --button-scale: 1.1;
        --spacing-scale: 1.2;
    }
}

/* Desktop: 1200px - 1919px (default scaling) */
@media (min-width: 1200px) and (max-width: 1919px) {
    :root {
        --ui-scale: 1.0;
        --font-scale: 1.0;
        --button-scale: 1.0;
        --spacing-scale: 1.0;
    }
}

/* Small Desktop/Large Tablet: 768px - 1199px */
@media (min-width: 768px) and (max-width: 1199px) {
    :root {
        --ui-scale: 0.85;
        --font-scale: 0.9;
        --button-scale: 0.8;
        --spacing-scale: 0.9;
    }
}

/* Mobile Landscape: 480px - 767px (aggressive scaling needed) */
@media (min-width: 480px) and (max-width: 767px) and (orientation: landscape) {
    :root {
        --ui-scale: 0.6;
        --font-scale: 0.7;
        --button-scale: 0.5;
        --spacing-scale: 0.6;
    }
}

/* Mobile Portrait: 480px - 767px (gentler scaling - buttons weren't bad before) */
@media (min-width: 480px) and (max-width: 767px) and (orientation: portrait) {
    :root {
        --ui-scale: 0.9;
        --font-scale: 0.95;
        --button-scale: 0.85;
        --spacing-scale: 0.9;
    }
}

/* Small Mobile Portrait: under 480px (moderate scaling) */
@media (max-width: 479px) and (orientation: portrait) {
    :root {
        --ui-scale: 0.8;
        --font-scale: 0.85;
        --button-scale: 0.75;
        --spacing-scale: 0.8;
    }
}

/* Small Mobile Landscape: under 480px (aggressive scaling) */
@media (max-width: 479px) and (orientation: landscape) {
    :root {
        --ui-scale: 0.6;
        --font-scale: 0.7;
        --button-scale: 0.5;
        --spacing-scale: 0.6;
    }
}

/* === APPLY SCALING TO UI ELEMENTS === */

/* Scale buttons only on mobile - keep desktop original */
@media (min-width: 768px) {
    .game-button {
        /* Desktop: use original sizing */
        font-size: clamp(0.8rem, 2.5vw, 1rem) !important;
        padding: 15px 30px !important;
        transform: none !important;
        margin: 8px 4px !important;
    }
}

@media (max-width: 767px) {
    .game-button {
        /* Mobile: use scaled sizing */
        font-size: calc(clamp(0.8rem, 2.5vw, 1rem) * var(--font-scale)) !important;
        padding: calc(15px * var(--spacing-scale)) calc(30px * var(--spacing-scale)) !important;
        transform: scale(var(--button-scale));
        transform-origin: center;
        margin: calc(8px * var(--spacing-scale)) calc(4px * var(--spacing-scale)) !important;
    }
}

/* Fix touch targets for mobile landscape - use direct sizing instead of transform */
@media (max-width: 767px) and (orientation: landscape) {
    .game-button {
        transform: none !important;
        font-size: calc(0.4rem * var(--font-scale)) !important;
        padding: calc(6px * var(--spacing-scale)) calc(12px * var(--spacing-scale)) !important;
        margin: calc(4px * var(--spacing-scale)) calc(2px * var(--spacing-scale)) !important;
        min-height: 32px !important;
        line-height: 1.2 !important;
    }
    
    /* Mobile controls also need direct sizing */
    .mobile-dpad-button, .mobile-action-button {
        transform: none !important;
        width: calc(40px * var(--ui-scale)) !important;
        height: calc(40px * var(--ui-scale)) !important;
        font-size: calc(1.2rem * var(--font-scale)) !important;
    }
    
    /* Level-up dialog buttons - fix touch targets */
    #level-up-dialog .game-button {
        transform: none !important;
        font-size: calc(0.35rem * var(--font-scale)) !important;
        padding: calc(4px * var(--spacing-scale)) calc(8px * var(--spacing-scale)) !important;
        margin: calc(2px * var(--spacing-scale)) !important;
        min-height: 28px !important;
        line-height: 1.2 !important;
    }
    
    /* Desktop action buttons - fix touch targets */
    .action-btn-desktop {
        transform: none !important;
        font-size: calc(0.4rem * var(--font-scale)) !important;
        padding: calc(6px * var(--spacing-scale)) calc(10px * var(--spacing-scale)) !important;
        min-height: 30px !important;
    }
    
    /* Sprite selector buttons - fix touch targets */
    .sprite-selector {
        transform: none !important;
        font-size: calc(0.8rem * var(--font-scale)) !important;
        padding: calc(6px * var(--spacing-scale)) !important;
        min-height: 35px !important;
        min-width: 35px !important;
    }
    
    /* Dialog close buttons - fix touch targets */
    .dialog-close-button {
        transform: none !important;
        font-size: calc(1rem * var(--font-scale)) !important;
        padding: calc(6px * var(--spacing-scale)) !important;
        min-height: 35px !important;
        min-width: 35px !important;
    }
}

/* Specific fixes for main menu buttons */
#main-start-menu .game-button {
    margin: calc(10px * var(--spacing-scale)) auto !important;
    display: block;
    width: fit-content;
}

/* Scale dialog content */
.dialog-content {
    padding: calc(clamp(8px, 2vw, 20px) * var(--spacing-scale)) !important;
    border-width: calc(12px * var(--ui-scale)) !important;
}

/* Scale specific problem areas */

/* Shop screen - make scrollable on mobile */
#shop-screen .dialog-content {
    width: calc(95vw * var(--ui-scale)) !important;
    height: calc(85vh * var(--ui-scale)) !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
}

/* Mobile Landscape: Make shop full screen and fix leave button */
@media (max-width: 767px) and (orientation: landscape) {
    #shop-screen .dialog-content {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        max-width: 100vw !important;
        padding: 10px !important;
        border-width: 0 !important; /* Remove border on fullscreen */
    }
    
    /* Make leave button much smaller and position at bottom */
    #close-shop-button {
        font-size: 0.5rem !important;
        padding: 4px 8px !important;
        margin: 10px auto !important;
        display: block !important;
        width: auto !important;
        min-width: 60px !important;
        max-width: 100px !important;
        position: sticky !important;
        bottom: 10px !important;
        z-index: 10 !important;
        transition: opacity 0.3s ease !important;
        opacity: 0;
        pointer-events: none;
    }
}

.shop-panels-container {
    gap: calc(20px * var(--spacing-scale)) !important;
}

#shop-screen .shop-item {
    font-size: calc(0.8rem * var(--font-scale)) !important;
    padding: calc(8px * var(--spacing-scale)) !important;
    margin: calc(4px * var(--spacing-scale)) 0 !important;
}

.shop-item-button {
    font-size: calc(0.6rem * var(--font-scale)) !important;
    padding: calc(4px * var(--spacing-scale)) calc(8px * var(--spacing-scale)) !important;
}

/* Level up dialog buttons */
#level-up-dialog .game-button {
    font-size: calc(0.7rem * var(--font-scale)) !important;
    padding: calc(8px * var(--spacing-scale)) calc(16px * var(--spacing-scale)) !important;
    margin: calc(3px * var(--spacing-scale)) !important;
}

#level-up-dialog .dialog-content {
    max-height: 90vh !important;
    overflow-y: auto !important;
}

#level-up-dialog .stat-buttons-container {
    display: flex;
    flex-wrap: wrap;
    gap: calc(5px * var(--spacing-scale)) !important;
    justify-content: center;
}

/* Cutscene skip button - position better */
#skip-cutscene-button {
    position: absolute !important;
    bottom: calc(20px * var(--spacing-scale)) !important;
    right: calc(20px * var(--spacing-scale)) !important;
    font-size: calc(0.6rem * var(--font-scale)) !important;
    padding: calc(6px * var(--spacing-scale)) calc(12px * var(--spacing-scale)) !important;
    z-index: 120 !important;
}

/* Settings button */
#open-settings-button {
    width: calc(50px * var(--ui-scale)) !important;
    height: calc(50px * var(--ui-scale)) !important;
    font-size: calc(1.8rem * var(--font-scale)) !important;
}

/* Mobile controls scaling */
.mobile-dpad-button, .mobile-action-button {
    font-size: calc(1.5rem * var(--font-scale)) !important;
    width: calc(50px * var(--ui-scale)) !important;
    height: calc(50px * var(--ui-scale)) !important;
}

/* Text scaling */
body, p, div, span {
    font-size: calc(1rem * var(--font-scale));
}

/* Message log scaling */
#message-log {
    font-size: calc(0.8rem * var(--font-scale)) !important;
}

/* Character sheet and info panels */
.character-info, .stat-display {
    font-size: calc(0.9rem * var(--font-scale)) !important;
}

/* Version display */
#version-display {
    font-size: calc(0.7rem * var(--font-scale)) !important;
}

/* === CHARACTER SHEET REDESIGN === */
.character-sheet-header {
    text-align: center;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--grey-border);
    padding-bottom: 10px;
}

.character-sheet-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--main-gold);
}

/* Three column layout - desktop */
.character-sheet-container {
    display: flex;
    gap: 20px;
    flex-grow: 1;
    align-items: flex-start;
}

.character-sheet-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Stats panel - column 1 */
.stats-panel {
    flex: 1;
}

.transfer-code-section, .achievements-section {
    margin-top: 15px;
}

.transfer-code-section button, .achievements-section button {
    width: 100%;
}

/* Equipment panel - column 2 */
.equipment-panel {
    flex: 1;
}

/* Inventory panel - column 3 */
.inventory-panel {
    flex: 1.2; /* Slightly wider for inventory list */
}

.inventory-close-section {
    margin-top: 15px;
    border-top: 1px solid var(--grey-border);
    padding-top: 10px;
}

.inventory-close-section button {
    width: 100%;
}

/* Achievements popup styling */
.achievements-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--grey-border);
    padding-bottom: 10px;
}

.achievements-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--main-gold);
    flex: 1;
    text-align: center;
}

#achievements-content {
    padding: 10px 0;
    width: 100%;
    box-sizing: border-box;
}

/* Mobile responsive character sheet */
@media (max-width: 1024px) {
    .character-sheet-container {
        flex-direction: column;
        gap: 15px;
    }
    
    .transfer-code-section button, 
    .achievements-section button,
    .inventory-close-section button {
        width: auto;
        min-width: 150px;
    }
    
    .character-sheet-header h2 {
        font-size: calc(1.2rem * var(--font-scale, 1));
    }
}

/* === MAIN MENU LAYOUT === */

/* Mobile portrait: Stack columns vertically */
@media (max-width: 767px) and (orientation: portrait) {
    .main-menu-columns {
        flex-direction: column !important;
        gap: 20px !important;
        align-items: center !important;
    }
    
    .single-player-column, .multiplayer-column {
        width: 100% !important;
        max-width: 300px !important;
    }
    
    #main-start-menu h1 {
        font-size: 2.5rem !important;
        margin-bottom: 15px !important;
    }
    
    .single-player-column h2, .multiplayer-column h2 {
        font-size: 1.3rem !important;
    }
}

/* Very small screens */
@media (max-width: 479px) {
    #main-start-menu h1 {
        font-size: 2rem !important;
    }
    
    .main-menu-columns {
        gap: 15px !important;
    }
    
    .help-section {
        margin-top: 15px !important;
        gap: 8px !important;
    }
    
    .help-section .game-button {
        font-size: 0.7rem !important;
        padding: 6px 12px !important;
    }
}

/* Tablet landscape: Keep columns but reduce spacing */
@media (min-width: 768px) and (max-width: 1024px) {
    .main-menu-columns {
        gap: 25px !important;
    }
    
    #main-start-menu h1 {
        font-size: 2.5rem !important;
    }
}

/* Additional mobile-specific improvements */

/* Make all buttons more touch-friendly on mobile */
@media (max-width: 767px) {
    .game-button, .mobile-dpad-button, .mobile-action-button {
        min-height: 44px !important; /* iOS touch target recommendation */
        min-width: 44px !important;
    }
    
    /* Ensure dialog close buttons are touchable */
    .dialog-close-button {
        font-size: calc(1.5rem * var(--font-scale)) !important;
        padding: calc(8px * var(--spacing-scale)) !important;
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* Compact character sheet on mobile */
    #character-sheet-screen .dialog-content {
        padding: calc(10px * var(--spacing-scale)) !important;
    }
    
    /* Make message log more readable */
    #message-log {
        line-height: 1.4 !important;
        padding: calc(5px * var(--spacing-scale)) !important;
    }
    
    /* Better inventory spacing */
    .inventory-item {
        margin: calc(2px * var(--spacing-scale)) !important;
        padding: calc(4px * var(--spacing-scale)) !important;
    }
}

/* High DPI screens - scale up slightly */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    :root {
        --ui-scale: calc(var(--ui-scale) * 1.05);
        --font-scale: calc(var(--font-scale) * 1.02);
    }
}