/* ===== RESTORED ORIGINAL MOBILE OPTIMIZATIONS ===== */
/* Your custom mobile layout that excludes elements for better space and orientation */

/* ===== ENHANCED MOBILE TOUCH CONTROLS ===== */
@media (max-width: 768px) and (max-device-width: 768px) {
    /* EXPERT MOBILE PERFORMANCE OPTIMIZATION */
    canvas {
        touch-action: none !important; /* Prevent browser touch handling */
        user-select: none !important;  /* Prevent text selection */
        -webkit-touch-callout: none !important; /* Disable iOS callout */
        -webkit-user-select: none !important;
        -webkit-tap-highlight-color: transparent !important; /* Remove tap highlights */
        cursor: none !important; /* Hide cursor on mobile */
        
        /* Hardware acceleration for smoother rendering */
        transform: translateZ(0) !important;
        -webkit-transform: translateZ(0) !important;
        will-change: transform !important;
        
        /* Optimize for touch responsiveness */
        pointer-events: auto !important;
        -ms-touch-action: none !important;
        -webkit-user-drag: none !important;
    }
    
    /* TRADES APP MOBILE OPTIMIZATIONS */
    .trades-app {
        padding: 0 !important;
        margin: 0 !important;
        width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    .trades-main {
        padding: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* MOBILE AGREEMENT DISPLAY */
    .agreement-display-compact {
        margin: 0 0 16px 0 !important;
        padding: 12px !important;
        border-radius: 8px !important;
    }
    
    /* MOBILE FORM ELEMENTS */
    .trades-input, .trades-textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
        padding: 14px 16px !important;
        border-radius: 8px !important;
        min-height: 44px !important;
    }
    
    .trades-button, .trades-button-secondary, .trades-button-danger {
        min-height: 44px !important;
        padding: 12px 20px !important;
        font-size: 16px !important;
        border-radius: 8px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }
    
    /* MOBILE INVENTORY GRID */
    .trades-inventory-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)) !important;
        gap: 8px !important;
    }
    
    .trades-inventory-item {
        min-height: 80px !important;
        padding: 8px !important;
        touch-action: manipulation !important;
    }
    
    /* MOBILE CARDS */
    .trades-card {
        padding: 16px !important;
        margin-bottom: 16px !important;
        border-radius: 12px !important;
    }
    
    /* MOBILE NAVIGATION */
    .trades-header {
        padding: 12px 16px !important;
        position: static !important;
    }
    
    .trades-nav {
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    .trades-nav-links {
        width: 100% !important;
        justify-content: center !important;
        flex-wrap: wrap !important;
    }
    
    .trades-nav-link {
        min-height: 44px !important;
        padding: 12px 16px !important;
        font-size: 14px !important;
        touch-action: manipulation !important;
    }
    
    /* Optimize for touch performance */
    body {
        overscroll-behavior: contain; /* Prevent overscroll */
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y; /* Allow vertical scrolling only */
    }
    
    /* EXPERT BUTTON OPTIMIZATION */
    button, .button {
        min-height: 44px !important; /* iOS recommended touch target */
        min-width: 44px !important;
        padding: 12px 16px !important;
        font-size: 16px !important; /* Prevent zoom on iOS */
        
        /* Hardware acceleration for instant response */
        transform: translateZ(0) !important;
        -webkit-transform: translateZ(0) !important;
        will-change: transform !important;
        
        /* Touch optimization */
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        -webkit-touch-callout: none !important;
        user-select: none !important;
        
        /* Smooth transitions */
        transition: transform 0.1s ease !important;
    }
    
    /* Button active state for immediate visual feedback */
    button:active, .button:active {
        transform: scale(0.95) translateZ(0) !important;
        -webkit-transform: scale(0.95) translateZ(0) !important;
    }
    /* ===== MOBILE LEADERBOARD IMPROVEMENTS ===== */
    
    /* Make expanded leaderboard more mobile-friendly */
    .leaderboard-container.expanded {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 90vh !important;
        padding: 16px !important;
        border-radius: 16px !important;
        margin: 0 !important;
    }
    
    /* Smaller header and entries for mobile */
    .leaderboard-container.expanded h3 {
        font-size: 1.2rem !important;
        margin-bottom: 16px !important;
    }
    
    /* Compact leaderboard entries on mobile */
    .leaderboard-entry {
        padding: 8px 12px !important;
        margin-bottom: 6px !important;
        font-size: 0.9rem !important;
    }
    
    /* Smaller close button on mobile */
    .leaderboard-close {
        width: 28px !important;
        height: 28px !important;
        font-size: 1rem !important;
    }
    
    /* Better toggle button for mobile */
    .leaderboard-toggle {
        width: 32px !important;
        height: 32px !important;
        font-size: 1.1rem !important;
    }
    
    /* Header spacing for mobile */
    .leaderboard-header {
        margin-bottom: 12px !important;
        padding: 0 8px !important;
    }
    
    /* Countdown timer mobile positioning */
    .reset-timer {
        font-size: 0.6rem !important;
        margin: 4px 0 8px 0 !important;
        padding: 2px !important;
        order: 2; /* Place after title */
    }
    
    /* Leaderboard title mobile adjustments */
    .leaderboard-header h3 {
        font-size: 1rem !important;
        margin: 0 0 2px 0 !important;
        order: 1; /* Title first */
    }
    
    /* Scrollable leaderboard list mobile optimizations */
    .leaderboard-list {
        max-height: 180px !important;
        overflow-y: auto !important;
        margin-bottom: 12px !important;
        padding-right: 2px !important;
        scrollbar-width: thin;
        scrollbar-color: rgba(251, 191, 36, 0.6) rgba(255, 255, 255, 0.1);
    }
    
    /* Leaderboard entries mobile spacing */
    .leaderboard-container.compact .leaderboard-entry {
        padding: 6px 8px !important;
        margin: 2px 0 !important;
        font-size: 0.85rem !important;
    }
    
    /* ===== RESTORE ORIGINAL MOBILE HEADER OPTIMIZATIONS ===== */
    
    /* Hide palace title and tagline on mobile for space */
    .palace-title {
        display: none !important;
    }
    
    .palace-tagline {
        display: none !important;
    }
    
    /* MOBILE HEADER: Show only Orders Served stat */
    .restaurant-stats {
        gap: 0px !important;
        flex-shrink: 0 !important;
        justify-content: center !important;
        position: relative !important;
    }
    
    /* Hide all stats except orders served to save space */
    .stat-item:not(:first-child) {
        display: none !important;
    }
    
    .stat-item:first-child {
        padding: var(--space-xs) 6px !important;
        border-width: 2px !important;
        min-width: 60px !important;
        font-size: 10px !important;
    }
    
    .stat-item:first-child .stat-number {
        font-size: 11px !important;
        font-weight: 700 !important;
    }
    
    .stat-item:first-child .stat-label {
        font-size: 7px !important;
    }
    
    /* MOBILE HEADER: Show only Abstract logo */
    .restaurant-hours {
        position: absolute !important;
        right: var(--space-lg) !important;
        gap: 0 !important;
        min-width: 0 !important;
        justify-content: flex-end !important;
        flex-shrink: 0 !important;
        align-items: center !important;
    }
    
    .abstract-logo {
        width: 28px !important;
        height: 28px !important;
        display: block !important;
    }
    
    .abstract-text {
        display: none !important;
    }
    
    /* ===== RESTORE ORIGINAL MOBILE CONTENT OPTIMIZATIONS ===== */
    
    /* Hide Quick Combos on mobile to save space */
    .menu-category:has(.combo-buttons),
    .menu-category .combo-buttons {
        display: none !important;
    }
    
    /* Hide item names on mobile - show only emojis/icons */
    .item-name {
        display: none !important;
    }
    
    /* Mobile-optimized trait grid */
    .menu-grid {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)) !important;
        gap: var(--space-xs) !important;
        max-height: 200px !important;
        overflow-y: auto !important;
    }
    
    /* Mobile trait items - maintain touch targets */
    .menu-item {
        min-height: 75px !important;
        padding: var(--space-xs) !important;
        border-radius: var(--border-radius-sm) !important;
    }
    
    .item-image {
        font-size: 1.5rem !important;
        margin-bottom: var(--space-xs) !important;
    }
    
    /* ===== RESTORE MOBILE LAYOUT ORDER OPTIMIZATION ===== */
    
    /* Preview section goes first on mobile */
    .preview-section {
        order: 1 !important;
    }
    
    /* Franchise info goes second */
    .menu-category.info-category {
        order: 2 !important;
        margin-bottom: var(--space-md) !important;
        border-bottom: 2px solid var(--restaurant-yellow) !important;
        padding-bottom: var(--space-md) !important;
    }
    
    /* Regular trait categories go last */
    .menu-category:not(.info-category) {
        order: 3 !important;
    }
    
    /* Menu section goes after preview */
    .menu-section-compact {
        order: 3 !important;
        max-height: none !important;
        margin-bottom: 0 !important;
        border-right: none !important;
    }
    /* ===== CORE MOBILE LAYOUT ===== */
    * {
        box-sizing: border-box;
    }
    
    body {
        padding: 0 !important;
        margin: 0 !important;
        overflow-x: hidden !important;
        width: 100% !important;
    }
    
    .restaurant-container {
        width: 100% !important;
        padding: var(--space-sm) !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }
    
    /* ===== FIX TAB NAVIGATION ===== */
    .tab-navigation {
        width: calc(100% - var(--space-md)) !important;
        margin: 0 auto var(--space-md) auto !important;
        display: flex !important;
        justify-content: center !important;
    }
    
    .tab-button {
        flex: 1 !important;
        max-width: 180px !important;
        min-width: 120px !important;
        text-align: center !important;
        /* Ensure uniform sizing for both button and anchor elements */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
    }
    
    /* Specific fixes for anchor tab buttons */
    a.tab-button {
        text-decoration: none !important;
        /* Inherit button styling for anchor elements */
        background: rgba(255, 255, 255, 0.1) !important;
        border: 2px solid rgba(255, 255, 255, 0.2) !important;
        border-radius: 12px !important;
        padding: var(--space-sm) var(--space-md) !important;
        font-family: var(--font-display) !important;
        font-size: var(--font-size-sm) !important;
        font-weight: 700 !important;
        color: var(--text-secondary) !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        /* Mobile-specific sizing to match other tab buttons */
        flex: 1 !important;
        min-width: 0 !important;
        max-width: 180px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
    }
    
    /* Ensure anchor tab button hover states match button styling */
    a.tab-button:hover {
        background: rgba(251, 191, 36, 0.15) !important;
        border-color: rgba(251, 191, 36, 0.4) !important;
        color: var(--restaurant-yellow) !important;
        transform: translateY(-2px) !important;
        box-shadow: 0 8px 20px rgba(251, 191, 36, 0.2) !important;
    }
    
    /* ===== FIX PFP GENERATOR MOBILE ===== */
    .pfp-generator {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: var(--space-md) !important;
    }
    
    .generator-content {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: var(--space-md) !important;
    }
    
    .preview-section {
        order: 1 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }
    
    .menu-section-compact {
        order: 2 !important;
        width: 100% !important;
        max-height: none !important;
    }
    
    .canvas-container {
        width: 100% !important;
        max-width: 320px !important;
        margin: 0 auto !important;
        display: flex !important;
        justify-content: center !important;
    }
    
    #pfpCanvas {
        width: 280px !important;
        height: 280px !important;
        max-width: 280px !important;
        max-height: 280px !important;
    }
    
    /* ===== FIX GAME CONTAINER MOBILE ===== */
    .game-container {
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }
    
    .game-canvas-container {
        width: 100vw !important; /* Full width to prevent horizontal clipping */
        max-width: 100% !important;
        margin: 0 auto !important;
        padding: 0px !important; /* Remove padding that causes clipping */
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        overflow: visible !important;
        position: relative !important; /* Ensure overlay positioning works */
        min-height: 450px !important; /* Minimum height for overlay */
        max-height: 80vh !important; /* Prevent extending too tall */
    }
    
    #gameCanvas {
        width: 100% !important;
        height: min(80vh, 650px) !important;
        max-width: 420px !important;
        max-height: 650px !important;
        min-width: 320px !important;
        min-height: 480px !important;
        image-rendering: pixelated !important;
        image-rendering: -moz-crisp-edges !important;
        image-rendering: crisp-edges !important;
        object-fit: contain !important;
    }
    
    /* ===== FIX BUTTONS AND CONTROLS ===== */
    .action-buttons {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: var(--space-sm) !important;
        justify-content: center !important;
        width: 100% !important;
        max-width: 320px !important;
        margin: 0 auto !important;
    }
    
    .action-buttons button {
        flex: 1 !important;
        min-width: 90px !important;
        max-width: 140px !important;
        min-height: 44px !important;
    }
    
    .game-controls {
        display: flex !important;
        flex-direction: column !important;
        gap: var(--space-sm) !important;
        width: 100% !important;
        max-width: 320px !important;
        margin: 0 auto !important;
        align-items: center !important;
    }
    
    .game-btn {
        width: 100% !important;
        max-width: 280px !important;
        min-height: 44px !important;
    }
    
    /* ===== MOBILE OVERLAY FIXES ===== */
    .game-overlay {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 1000 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 10px !important;
        box-sizing: border-box !important;
    }
    
    .overlay-content {
        max-width: 95vw !important; /* Slightly wider for mobile */
        max-height: 70vh !important; /* Reduced height for better fit */
        min-width: 280px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 10px !important; /* Reduced padding for more content space */
        box-sizing: border-box !important;
        margin: 0 auto !important;
        transform: none !important; /* Reset any transforms */
    }
    
    /* ===== FIX MENU GRID ===== */
    .menu-grid {
        display: grid !important;
        grid-template-columns: repeat(auto-fill, minmax(45px, 1fr)) !important;
        gap: var(--space-xs) !important;
        width: 100% !important;
        justify-items: center !important;
    }
    
    .menu-item {
        width: 45px !important;
        height: 45px !important;
        min-height: 44px !important;
    }
    
    /* ===== HIDE ORDER SUMMARY ON MOBILE ===== */
    .order-summary-compact {
        display: none !important;
    }
    
    /* ===== MAKE BUTTON TEXT/ICONS SMALLER ===== */
    .action-buttons button {
        font-size: 11px !important;
        line-height: 1.1 !important;
        padding: 6px 8px !important;
    }
}

/* ===== EXTRA SMALL MOBILE (480px and below) ===== */
@media (max-width: 480px) {
    .restaurant-container {
        padding: var(--space-xs) !important;
    }
    
    /* Ensure tab buttons are uniform on smaller screens */
    .tab-button {
        padding: var(--space-xs) var(--space-sm) !important;
        font-size: 0.8rem !important;
        letter-spacing: 0.01em !important;
    }
    
    a.tab-button {
        padding: var(--space-xs) var(--space-sm) !important;
        font-size: 0.8rem !important;
        letter-spacing: 0.01em !important;
    }
    
    #pfpCanvas {
        width: 240px !important;
        height: 240px !important;
        max-width: 240px !important;
        max-height: 240px !important;
    }
    
    #gameCanvas {
        width: 240px !important;
        height: 360px !important;
        max-width: 240px !important;
        max-height: 360px !important;
    }
    
    .canvas-container,
    .game-canvas-container {
        max-width: 280px !important;
    }
    
    .action-buttons,
    .game-controls {
        max-width: 280px !important;
    }
}

/* ===== VERY SMALL MOBILE (360px and below) ===== */
@media (max-width: 360px) {
    /* Ensure tab buttons are uniform on very small screens */
    .tab-button {
        padding: 6px 8px !important;
        font-size: 0.75rem !important;
        font-weight: 600 !important;
        min-width: 80px !important;
    }
    
    a.tab-button {
        padding: 6px 8px !important;
        font-size: 0.75rem !important;
        font-weight: 600 !important;
        min-width: 80px !important;
    }
    
    #pfpCanvas {
        width: 200px !important;
        height: 200px !important;
        max-width: 200px !important;
        max-height: 200px !important;
    }
    
    #gameCanvas {
        width: 200px !important;
        height: 300px !important;
        max-width: 200px !important;
        max-height: 300px !important;
    }
    
    .canvas-container,
    .game-canvas-container,
    .action-buttons,
    .game-controls {
        max-width: 240px !important;
    }
    
    .menu-grid {
        grid-template-columns: repeat(auto-fill, minmax(35px, 1fr)) !important;
    }
    
    .menu-item {
        width: 35px !important;
        height: 35px !important;
    }
}

