/**
 * MOBILE DEVICE DETECTION & RESPONSIVE CSS
 * Automatic styling based on device type detected by visitor-tracker-advanced.js
 * 
 * Attributes injected by tracker:
 * - data-device: "mobile", "tablet", "desktop"
 * - data-os: "iOS", "Android", "Windows", "macOS", "Linux"
 * - data-browser: "Chrome", "Firefox", "Safari", "Edge", "Opera"
 * - data-screen-size: "small-mobile", "mobile", "tablet", "desktop"
 * - data-connection: "4g", "3g", "2g", "unknown"
 */

/* ==================== MOBILE-SPECIFIC OPTIMIZATIONS ==================== */

/* Small Mobile (320px - 479px) */
@media (max-width: 479px) {
    html[data-device="mobile"] {
        --touch-target: 44px;
        --font-scale: 0.95;
    }
    
    html[data-device="mobile"] body {
        padding-top: 100px;
        font-size: clamp(14px, 3vw, 16px);
    }
    
    html[data-device="mobile"] .home-navbar {
        width: calc(100% - 15px);
        height: 65px;
        padding: 0 20px;
        top: 10px;
    }
    
    html[data-device="mobile"] .nav-time {
        font-size: 11px;
        letter-spacing: 0px;
    }
    
    html[data-device="mobile"] .menu-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    html[data-device="mobile"] .menu-box {
        width: 85%;
        max-width: 100%;
        padding: 15px;
        gap: 8px;
    }
    
    html[data-device="mobile"] .menu-box a {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    html[data-device="mobile"] .container {
        padding: 20px 10px;
        max-width: 100%;
    }
    
    html[data-device="mobile"] .page-title {
        font-size: 28px;
        margin: 20px 0;
    }
    
    html[data-device="mobile"] .filters {
        flex-direction: column;
        gap: 10px;
    }
    
    html[data-device="mobile"] .filters input,
    html[data-device="mobile"] .filters select {
        width: 100%;
        padding: 12px;
        font-size: 14px;
        min-height: 44px;
    }
    
    html[data-device="mobile"] .results-count {
        width: 100%;
        text-align: center;
        margin-top: 10px;
    }
    
    html[data-device="mobile"] .projects-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    html[data-device="mobile"] .project-card {
        border-radius: 12px;
    }
    
    html[data-device="mobile"] .project-image-container {
        height: 180px;
    }
    
    html[data-device="mobile"] .project-title {
        font-size: 16px;
        margin: 12px 0 8px;
    }
    
    html[data-device="mobile"] .project-desc {
        font-size: 13px;
        line-height: 1.4;
        max-lines: 2;
    }
    
    html[data-device="mobile"] .project-tech {
        gap: 6px;
        margin: 8px 0;
    }
    
    html[data-device="mobile"] .tech-tag {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    html[data-device="mobile"] .project-link {
        padding: 12px;
        font-size: 13px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    html[data-device="mobile"] .modal {
        padding: 10px;
    }
    
    html[data-device="mobile"] .modal-content {
        border-radius: 12px;
        padding: 10px;
    }
    
    html[data-device="mobile"] #modalImage {
        max-height: 60vh;
    }
    
    html[data-device="mobile"] .image-nav {
        gap: 8px;
        margin-top: 10px;
    }
    
    html[data-device="mobile"] .image-nav button {
        font-size: 13px;
        padding: 10px;
        min-height: 44px;
        flex: 1;
    }
}

/* Mobile (480px - 767px) */
@media (min-width: 480px) and (max-width: 767px) {
    html[data-device="mobile"] {
        --touch-target: 44px;
    }
    
    html[data-device="mobile"] body {
        padding-top: 110px;
    }
    
    html[data-device="mobile"] .home-navbar {
        width: 95%;
        height: 70px;
        padding: 0 25px;
        top: 12px;
    }
    
    html[data-device="mobile"] .nav-time {
        font-size: 12px;
    }
    
    html[data-device="mobile"] .menu-box {
        width: 90%;
        max-width: 400px;
    }
    
    html[data-device="mobile"] .projects-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    html[data-device="mobile"] .project-image-container {
        height: 200px;
    }
}

/* ==================== TABLET-SPECIFIC OPTIMIZATIONS ==================== */

@media (min-width: 768px) and (max-width: 1024px) {
    html[data-device="tablet"] body {
        padding-top: 120px;
    }
    
    html[data-device="tablet"] .home-navbar {
        width: 92%;
        max-width: 900px;
    }
    
    html[data-device="tablet"] .projects-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
    
    html[data-device="tablet"] .project-image-container {
        height: 220px;
    }
    
    html[data-device="tablet"] .container {
        max-width: 100%;
        padding: 30px 20px;
    }
}

/* ==================== DESKTOP OPTIMIZATIONS ==================== */

@media (min-width: 1025px) {
    html[data-device="desktop"] body {
        padding-top: 130px;
    }
    
    html[data-device="desktop"] .home-navbar {
        width: 85%;
        max-width: 1200px;
    }
    
    html[data-device="desktop"] .projects-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 25px;
    }
    
    html[data-device="desktop"] .project-image-container {
        height: 250px;
    }
    
    html[data-device="desktop"] .container {
        max-width: 1400px;
        padding: 40px 20px;
    }
}

/* ==================== OS-SPECIFIC OPTIMIZATIONS ==================== */

/* iOS Specific */
html[data-os="iOS"] {
    /* Add safe area support for notched devices */
    padding-top: max(env(safe-area-inset-top), 10px);
}

html[data-os="iOS"] body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html[data-os="iOS"] .home-navbar {
    top: max(env(safe-area-inset-top), 10px);
}

html[data-os="iOS"] .menu-btn {
    -webkit-appearance: none;
    appearance: none;
}

/* Android Specific */
html[data-os="Android"] {
    /* Use hardware acceleration */
    transform: translateZ(0);
}

html[data-os="Android"] .home-navbar {
    will-change: transform;
}

html[data-os="Android"] .menu-overlay {
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
}

/* ==================== BROWSER-SPECIFIC OPTIMIZATIONS ==================== */

/* Safari Specific */
html[data-browser="Safari"] ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

html[data-browser="Safari"] ::-webkit-scrollbar-track {
    background: transparent;
}

html[data-browser="Safari"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

html[data-browser="Safari"] input,
html[data-browser="Safari"] select {
    -webkit-appearance: none;
    appearance: none;
    -webkit-border-radius: 0;
    border-radius: 0;
}

html[data-browser="Safari"] .project-image-container {
    -webkit-mask-image: -webkit-radial-gradient(white, black);
    mask-image: radial-gradient(white, black);
}

/* Chrome Specific */
html[data-browser="Chrome"] .project-image {
    image-rendering: -webkit-optimize-contrast;
}

/* Firefox Specific */
html[data-browser="Firefox"] input::-moz-selection {
    background-color: rgba(59, 130, 246, 0.3);
}

html[data-browser="Firefox"] .menu-overlay::-webkit-scrollbar {
    width: 6px;
}

html[data-browser="Firefox"] .menu-overlay::-webkit-scrollbar-track {
    background: transparent;
}

html[data-browser="Firefox"] .menu-overlay::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* ==================== CONNECTION-AWARE STYLING ==================== */

/* Slow Connection (2G/3G) - Reduce animations and optimize images */
html[data-connection="2g"],
html[data-connection="3g"] {
    /* Disable heavy animations */
    --animation-duration: 150ms;
    --animation-easing: linear;
}

html[data-connection="2g"] *,
html[data-connection="3g"] * {
    transition-duration: 150ms !important;
    animation-duration: 150ms !important;
}

html[data-connection="2g"] .project-image,
html[data-connection="3g"] .project-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Fast Connection (4G/5G) - Enable high-quality rendering */
html[data-connection="4g"],
html[data-connection="5g"] {
    --animation-duration: 300ms;
    --animation-easing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== DEVICE-SPECIFIC TOUCH INTERACTIONS ==================== */

/* Touch-enabled devices */
html[data-device="mobile"],
html[data-device="tablet"] {
    --touch-device: true;
}

html[data-device="mobile"] input:focus,
html[data-device="mobile"] select:focus,
html[data-device="mobile"] button:focus,
html[data-device="mobile"] a:focus,
html[data-device="tablet"] input:focus,
html[data-device="tablet"] select:focus,
html[data-device="tablet"] button:focus,
html[data-device="tablet"] a:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

html[data-device="mobile"] button:active,
html[data-device="mobile"] a:active,
html[data-device="tablet"] button:active,
html[data-device="tablet"] a:active {
    transform: scale(0.98);
}

/* ==================== ACCESSIBILITY IMPROVEMENTS ==================== */

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    html[data-device="mobile"],
    html[data-device="tablet"] {
        --animation-duration: 0s;
    }
    
    html[data-device="mobile"] *,
    html[data-device="tablet"] * {
        animation-duration: 0s !important;
        transition-duration: 0s !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: more) {
    html[data-device="mobile"] .home-navbar,
    html[data-device="tablet"] .home-navbar {
        border-width: 2px;
    }
    
    html[data-device="mobile"] .menu-btn,
    html[data-device="tablet"] .menu-btn {
        border-width: 2px;
    }
}

/* Dark mode (already dark, but respecting system preference) */
@media (prefers-color-scheme: dark) {
    html[data-device="mobile"] body,
    html[data-device="tablet"] body,
    html[data-device="desktop"] body {
        background: #0a0a0a;
        color: #ffffff;
    }
}

/* ==================== UTILITY CLASSES FOR DEVICE DETECTION ==================== */

.mobile-only {
    display: none;
}

html[data-device="mobile"] .mobile-only,
html[data-device="mobile"][data-screen-size="small-mobile"] .mobile-only {
    display: block;
}

.tablet-only {
    display: none;
}

html[data-device="tablet"] .tablet-only {
    display: block;
}

.desktop-only {
    display: none;
}

html[data-device="desktop"] .desktop-only {
    display: block;
}

.touch-device {
    display: none;
}

html[data-device="mobile"] .touch-device,
html[data-device="tablet"] .touch-device {
    display: block;
}

.no-touch {
    display: none;
}

html[data-device="desktop"] .no-touch {
    display: block;
}

/* Hide scrollbars on mobile, show on desktop */
html[data-device="mobile"] ::-webkit-scrollbar,
html[data-device="tablet"] ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

html[data-device="mobile"] ::-webkit-scrollbar-track,
html[data-device="tablet"] ::-webkit-scrollbar-track {
    background: transparent;
}

html[data-device="mobile"] ::-webkit-scrollbar-thumb,
html[data-device="tablet"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

html[data-device="desktop"] ::-webkit-scrollbar {
    width: 10px;
}

html[data-device="desktop"] ::-webkit-scrollbar-track {
    background: transparent;
}

html[data-device="desktop"] ::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.3);
    border-radius: 5px;
}

/* ==================== VIEWPORT-SPECIFIC FIXES ==================== */

/* Fix for mobile Safari address bar */
@supports (padding: max(0px)) {
    html[data-os="iOS"] body {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* Fix for notched devices */
html[data-os="iOS"] .home-navbar {
    margin-top: env(safe-area-inset-top);
}

/* Fix for landscape orientation on mobile */
@media (max-height: 500px) {
    html[data-device="mobile"] body {
        padding-top: 70px;
    }
    
    html[data-device="mobile"] .home-navbar {
        height: 50px;
        padding: 0 15px;
    }
    
    html[data-device="mobile"] .nav-time {
        font-size: 10px;
    }
    
    html[data-device="mobile"] .menu-btn {
        width: 36px;
        height: 36px;
    }
}

/* ==================== IMAGE LOADING OPTIMIZATION ==================== */

/* Note: loading and decoding attributes should be applied directly to img elements in HTML:
   - For slow connections: <img loading="lazy" decoding="async" ...>
   - For fast connections: <img loading="eager" decoding="sync" ...>
*/

html[data-connection="2g"] .project-image,
html[data-connection="3g"] .project-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

html[data-connection="4g"] .project-image,
html[data-connection="5g"] .project-image {
    image-rendering: -webkit-optimize-contrast;
}

/* ==================== PERFORMANCE OPTIMIZATIONS ==================== */

/* Reduce animations on low-end devices */
html[data-device="mobile"][data-screen-size="small-mobile"] {
    --prefer-reduced-animations: true;
}

html[data-device="mobile"][data-screen-size="small-mobile"] .menu-overlay {
    animation-duration: 150ms;
}

html[data-device="mobile"][data-screen-size="small-mobile"] .menu-box {
    animation-duration: 150ms;
}
