/* Mobile-specific optimizations */
@media (max-width: 768px) {
    body {
        font-size: 16px; /* Prevent zoom on focus */
    }
    
    /* App Banner Mobile */
    #app-banner {
        padding: 0 16px;
    }
    
    .app-banner-content {
        height: 44px;
    }
    
    .app-title {
        font-size: 18px;
    }
    
    .install-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* Step 3 mobile layout adjustments - three columns */
    #controls-3 .control-row {
        gap: 4px; /* Smaller gap on mobile for three columns */
        flex-wrap: wrap; /* Allow wrapping on very small screens */
    }
    
    #controls-3 .control-third {
        min-width: calc(50% - 2px); /* Two columns on mobile */
        margin-bottom: 8px;
    }
    
    #controls-3 .control-third .control-label {
        font-size: 10px; /* Smaller labels on mobile */
        gap: 3px;
    }
    
    #controls-3 .control-third .control-label input[type="checkbox"] {
        width: 12px;
        height: 12px;
    }
    
    #controls-3 .reset-btn {
        font-size: 12px;
        padding: 6px 8px;
        margin-top: 12px;
    }
    
    /* Startup screen mobile optimization */
    .startup-content {
        padding: 20px;
        max-width: 280px;
    }
    
    .startup-content h1 {
        font-size: 24px;
        margin-bottom: 20px;
    }
    
    #startup-message {
        font-size: 14px;
    }
    
    /* Ensure startup spinner centers on mobile */
    .startup-content .spinner {
        margin: 0 auto 15px auto;
        display: block;
    }
    
    /* Prevent horizontal scroll */
    body, html {
        overflow-x: hidden;
    }
    
    /* iOS Safari specific fixes */
    body {
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Touch-friendly targets */
    .btn, .corner-handle {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Improved touch feedback */
    .btn:active, .upload-area:active {
        transform: scale(0.95);
    }
    
    .corner-handle:active {
        transform: translate(-50%, -50%) scale(1.3);
    }
    
    /* Prevent selection on touch */
    .step-container, .controls-container {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* Better focus states for accessibility */
    .btn:focus, .slider:focus, select:focus {
        outline: 2px solid #007AFF;
        outline-offset: 2px;
    }
    
    /* Optimize for small screens */
    #main-content {
        padding: 16px;
    }
    
    .upload-area, .image-placeholder {
        width: calc(100vw - 64px);
        max-width: 300px;
        height: auto;
        aspect-ratio: 4/3;
    }
    
    .painting-sample {
        width: 80%;
        height: 80%;
    }
    
    /* Adjust controls for thumb navigation */
    #controls-panel {
        max-height: 220px;
        padding: 16px;
    }
    
    .control-group {
        margin-bottom: 20px;
    }
    
    /* Mobile adjustments for inline controls */
    .control-group.inline-control {
        gap: 6px;
        margin-bottom: 10px;
    }
    
    .control-label.inline-label {
        font-size: 12px;
        min-width: 60px;
    }
    
    .size-selector.inline-select {
        font-size: 12px;
        padding: 8px;
    }
    
    .slider {
        height: 8px;
        margin: 12px 0;
    }
    
    .slider::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }
    
    .slider::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }
    
    /* Navigation adjustments */
    #navigation {
        padding: 16px;
        gap: 16px;
    }
    
    /* Ensure buttons fill available space */
    #navigation .btn {
        min-width: 0;
    }
    
    #navigation .btn {
        padding: 16px 12px;
        font-size: 16px;
    }
    
    /* Toast notifications */
    #error-toast, #success-toast {
        top: 16px;
        left: 16px;
        right: 16px;
    }
    
    /* Loading overlay */
    #loading-overlay {
        padding: 20px;
    }
    
    .spinner {
        width: 48px;
        height: 48px;
        border-width: 5px;
    }
    
    #loading-message {
        font-size: 16px;
        text-align: center;
    }
}

/* Portrait orientation optimizations */
@media (orientation: portrait) and (max-width: 480px) {
    #main-content {
        padding: 12px;
    }
    
    .step-text {
        font-size: 14px;
    }
    
    #step-indicator {
        padding: 12px 16px;
    }
    
    .progress-bar {
        height: 3px;
        margin-bottom: 8px;
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    #main-content {
        padding: 8px;
    }
    
    .upload-area, .image-placeholder {
        width: 240px;
        height: 180px;
    }
    
    .painting-sample {
        width: 160px;
        height: 120px;
    }
    
    #controls-panel {
        max-height: 120px;
        padding: 12px;
    }
    
    .control-group {
        margin-bottom: 8px;
    }
    
    #navigation {
        padding: 8px 16px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .upload-icon {
        font-size: 20px;
    }
    
    .corner-handle {
        width: 18px;
        height: 18px;
        border-width: 3px;
    }
    
    .before-after-toggle {
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1c1c1e;
        --surface-color: #2c2c2e;
        --text-color: #ffffff;
        --text-secondary: #8e8e93;
        --border-color: #3a3a3c;
    }
    
    /* Note: Dark mode implementation would go here */
    /* Keeping light mode for now as per specs */
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .spinner {
        animation: none;
        border: 4px solid rgba(255,255,255,0.3);
        border-top: 4px solid white;
    }
}

/* High contrast support */
@media (prefers-contrast: high) {
    .btn-primary {
        background: #0000ff;
    }
    
    .btn-secondary {
        background: #ffffff;
        border: 2px solid #000000;
        color: #000000;
    }
    
    .progress-fill {
        background: #0000ff;
    }
    
    .corner-handle {
        background: #ff0000;
        border: 3px solid #ffffff;
    }
}