/* Mobile-specific fixes and touch optimizations */

/* FORCE MOBILE LAYOUT - wszystko musi się mieścić */
@media (max-width: 768px) {
    * {
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }
    
    html, body {
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    body {
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
        overflow: auto !important;
        height: auto !important;
        min-height: 100vh;
        padding: 5px !important;
    }
    
    .window {
        width: calc(100vw - 10px) !important;
        max-width: calc(100vw - 10px) !important;
        height: auto !important;
        min-height: calc(100vh - 20px) !important;
        max-height: none !important;
        margin: 5px auto !important;
        position: relative !important;
        transform: none !important;
        left: auto !important;
        top: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Ukryj desktop elementy które mogą powodować problemy */
    .desktop-icons {
        display: none !important;
    }
    
    .awge-footer {
        display: none !important;
    }
    
    .media-player {
        display: none !important;
    }
    
    /* CRT effects - zmniejsz intensywność na mobile */
    .crt-overlay,
    .crt-glow,
    .crt-flicker,
    .glitch-effect {
        opacity: 0.3 !important;
    }
}

/* Fix iOS viewport issues */
@supports (-webkit-touch-callout: none) {
    .window {
        -webkit-overflow-scrolling: touch;
    }
}

/* Touch-friendly interactions */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .icon:hover {
        background: var(--window-bg);
        transform: none;
        box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.2);
    }
    
    .icon:active {
        background: #d0d0d0;
        transform: scale(0.98);
    }
    
    .contact-link:hover,
    .menu-item:hover {
        background: initial;
        color: initial;
    }
    
    .contact-link:active,
    .menu-item:active {
        background: var(--accent-blue);
        color: white;
    }
    
    /* Larger touch targets */
    .icon {
        min-height: 80px;
        padding: 1rem;
    }
    
    .window-button {
        min-width: 44px;
        min-height: 44px;
    }
    
    .back-button {
        min-height: 44px;
        padding: 0.8rem 1.5rem;
    }
}

/* Prevent zoom on input focus (iOS) */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important;
        transform: none !important;
    }
}

/* Fix for mobile Safari address bar */
@media screen and (max-width: 768px) {
    .window {
        height: auto !important;
        min-height: calc(100vh - 120px);
        max-height: none;
    }
    
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    html {
        height: -webkit-fill-available;
    }
}

/* Landscape orientation fixes */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .window {
        min-height: calc(100vh - 60px);
        margin: 0.5rem auto;
    }
    
    .content-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: 1fr;
        gap: 0.5rem;
        padding: 0.5rem;
    }
    
    .icon {
        max-height: 80px;
        padding: 0.4rem;
    }
    
    .icon-image {
        width: 30px;
        height: 30px;
        font-size: 1rem;
        margin-bottom: 0.4rem;
    }
    
    .icon-label {
        font-size: 0.7rem;
    }
}

/* Android Chrome specific fixes */
@media screen and (max-width: 768px) {
    /* Fix for Android Chrome viewport */
    .window {
        height: auto;
        max-height: calc(100vh - 100px);
    }
    
    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden;
        width: 100%;
    }
    
    .window {
        max-width: 100vw;
        box-sizing: border-box;
    }
}

/* KOMPLETNE PRZEPISANIE DLA MOBILE */
@media screen and (max-width: 768px) {
    /* RESET wszystkiego dla mobile */
    .window {
        width: calc(100vw - 10px) !important;
        max-width: calc(100vw - 10px) !important;
        height: auto !important;
        min-height: calc(100vh - 20px) !important;
        margin: 5px auto !important;
        border-radius: 8px !important;
        border: 1px solid #000 !important;
        box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3) !important;
        position: relative !important;
        transform: none !important;
        left: auto !important;
        top: auto !important;
    }
    
    .title-bar {
        padding: 0.5rem !important;
        font-size: 0.8rem !important;
        min-height: 40px !important;
    }
    
    .title-bar-text {
        font-size: 0.9rem !important;
    }
    
    .window-button {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.8rem !important;
        min-width: 30px !important;
        min-height: 30px !important;
    }
    
    .menu-bar {
        padding: 0.3rem !important;
        font-size: 0.75rem !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
    }
    
    .menu-item {
        padding: 0.3rem 0.8rem !important;
        display: inline-block !important;
    }
    
    .content-grid {
        padding: 1rem !important;
        gap: 1rem !important;
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: auto auto !important;
        min-height: auto !important;
        max-height: none !important;
    }
    
    .icon {
        width: 100% !important;
        height: auto !important;
        min-height: 100px !important;
        max-height: 120px !important;
        max-width: none !important;
        padding: 0.8rem !important;
        border: 1px solid #808080 !important;
        box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2) !important;
    }
    
    .icon-image {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.3rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .icon-label {
        font-size: 0.8rem !important;
        line-height: 1.2 !important;
    }
    
    .status-bar {
        padding: 0.4rem !important;
        font-size: 0.7rem !important;
        overflow-x: auto !important;
    }
    
    .status-item {
        white-space: nowrap !important;
    }
}

/* Bardzo małe ekrany - jeszcze bardziej kompaktowe */
@media screen and (max-width: 375px) {
    .content-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto auto auto auto !important;
        gap: 0.8rem !important;
        padding: 0.8rem !important;
    }
    
    .icon {
        min-height: 80px !important;
        max-height: 90px !important;
        padding: 0.6rem !important;
    }
    
    .icon-image {
        width: 35px !important;
        height: 35px !important;
        font-size: 1.1rem !important;
    }
    
    .icon-label {
        font-size: 0.75rem !important;
    }
    
    .title-bar {
        padding: 0.4rem !important;
    }
    
    .title-bar-text {
        font-size: 0.8rem !important;
    }
    
    .window-button {
        width: 25px !important;
        height: 25px !important;
        font-size: 0.7rem !important;
    }
}

/* Fix for pages content on mobile */
@media screen and (max-width: 768px) {
    .page-container {
        padding: 1rem;
        box-sizing: border-box;
    }
    
    .page-content {
        max-width: 100%;
        padding: 1rem;
        margin: 0;
    }
    
    .page-header {
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
    }
    
    .page-title {
        font-size: 1.5rem;
    }
    
    /* About page specific fixes */
    .profile-section {
        flex-direction: column;
        gap: 1.5rem;
    }
    
    .profile-avatar {
        text-align: center;
    }
    
    .profile-details {
        text-align: left;
    }
    
    .skills-section h3 {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }
    
    .skills-grid {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }
    
    .skill-item {
        padding: 0.8rem;
        text-align: center;
        font-size: 0.9rem;
    }
}

/* Smooth scrolling for mobile */
@media screen and (max-width: 768px) {
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    .window,
    .page-container,
    .terminal-content {
        scroll-behavior: smooth;
    }
}

/* Prevent text selection on touch */
@media (hover: none) and (pointer: coarse) {
    .icon,
    .window-button,
    .menu-item,
    .title-bar {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

/* Loading state for slow connections */
@media (max-width: 768px) {
    .page-container.loading {
        background: var(--window-bg);
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 200px;
    }
    
    .page-container.loading::before {
        content: "Loading...";
        font-family: var(--font-family);
        font-size: 1.2rem;
        color: var(--accent-blue);
    }
}