/* Mobile Optimizations
   Performance, usability, and touch interactions */

/* ============================================
   MOBILE PERFORMANCE
   ============================================ */

@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: rgba(255, 144, 0, 0.15);
    }

    body {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }

    img {
        max-width: 100%;
        height: auto;
    }

    .preview-video,
    .preview-container {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* ============================================
   MOBILE HEADER & NAVIGATION
   ============================================ */

@media (max-width: 768px) {
    .header {
        position: relative;
        z-index: var(--z-header, 100);
    }

    .nav {
        position: relative;
        z-index: var(--z-nav, 90);
    }

    .nav::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to left, var(--color-bg-surface, #141414), transparent);
        pointer-events: none;
    }

    .nav .container::-webkit-scrollbar {
        display: none;
    }

    .nav .container {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* ============================================
   MOBILE VIDEO GRID - 2 COLUMNS
   ============================================ */

@media (max-width: 768px) {
    .videos-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 0;
        min-width: 0;
        width: 100%;
    }

    .video-card {
        position: relative;
        touch-action: auto;
        -webkit-user-select: none;
        user-select: none;
    }

    .video-thumbnail,
    .video-thumbnail img,
    .preview-container,
    .preview-video {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        pointer-events: auto;
    }

    .video-thumbnail img,
    .video-thumbnail .thumbnail-img {
        will-change: auto;
        min-height: auto !important;
        height: 100% !important;
        width: 100% !important;
        object-fit: cover !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
    }

    .video-thumbnail {
        min-height: auto !important;
        aspect-ratio: 16 / 9 !important;
        position: relative !important;
        width: 100% !important;
        padding-bottom: 56.25% !important;
        height: 0 !important;
    }

    /* Disable hover effects on mobile */
    .video-card:hover {
        transform: none;
        box-shadow: none;
    }

    /* Press feedback */
    .video-card:active {
        transform: scale(0.985);
        transition: transform 100ms ease;
    }

    /* Enable preview videos on mobile */
    .video-thumbnail .preview-video,
    .video-thumbnail .preview-image,
    .video-thumbnail .preview-gif,
    .hover-video-player {
        display: block;
        pointer-events: auto;
    }

    .preview-container {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
        pointer-events: none;
        display: block;
        background: transparent;
    }

    .preview-container video,
    .preview-video {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 10;
        pointer-events: none;
        border-radius: var(--radius-sm, 6px);
        background: transparent;
        opacity: 1;
        visibility: visible;
    }

    .preview-loading {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 15;
        font-size: 24px;
        display: none;
    }

    .preview-loading.active {
        display: flex;
    }
}

/* ============================================
   MOBILE TYPOGRAPHY
   ============================================ */

@media (max-width: 768px) {
    .section-title {
        display: none;
    }

    .sort-bar {
        padding: 4px 8px;
    }

    .sort-bar select {
        width: 100%;
        font-size: 13px;
        padding: 6px 10px;
    }

    .section-header {
        margin-bottom: 10px;
    }

    .video-title {
        font-size: 12px;
        line-height: 1.3;
        max-height: 2.6em;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .video-channel {
        font-size: 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .video-meta {
        font-size: 10px;
    }

    .nav-link,
    .pagination-btn,
    .search-btn,
    .category-tag,
    .tag-item {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================
   MOBILE TOUCH TARGETS
   ============================================ */

@media (max-width: 768px) {
    .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .search-btn,
    .pagination-btn,
    .load-more-btn {
        min-height: 44px;
        min-width: 44px;
    }

    .video-card {
        min-height: auto;
    }

    .category-card {
        min-height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   MOBILE SEARCH BAR
   ============================================ */

@media (max-width: 768px) {
    .search-bar {
        width: 100%;
        margin-top: 10px;
    }

    .search-bar input {
        font-size: 16px;
        padding: 12px 15px;
        border-radius: var(--radius-md, 10px);
    }

    .search-btn {
        padding: 12px 20px;
        border-radius: var(--radius-md, 10px);
        white-space: nowrap;
    }
}

/* ============================================
   MOBILE PAGINATION
   ============================================ */

@media (max-width: 768px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        padding: 15px 5px;
    }

    .pagination-btn {
        padding: 8px 12px;
        min-width: 40px;
        font-size: 14px;
        border-radius: var(--radius-full, 9999px);
    }

    .pagination-info {
        width: 100%;
        text-align: center;
        order: -1;
        margin-bottom: 10px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .pagination-btn:not(.active):not(:first-child):not(:last-child):not(:nth-child(2)):not(:nth-last-child(2)) {
        display: none;
    }
}

/* ============================================
   MOBILE LANDSCAPE MODE
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    .videos-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .header .container {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .search-bar {
        flex: 1;
        min-width: 250px;
        margin-top: 0;
    }

    .nav-link {
        padding: 10px 12px;
        font-size: 12px;
    }
}

/* ============================================
   LOADING STATES
   ============================================ */

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--color-bg-overlay, #2a2a2a);
    border-top-color: var(--color-accent, #ff9000);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Skeleton loading - directional shimmer */
.video-card.loading {
    background: linear-gradient(110deg,
            var(--color-bg-surface, #141414) 25%,
            var(--color-bg-elevated, #1e1e1e) 37%,
            var(--color-bg-surface, #141414) 63%);
    background-size: 200% 100%;
    animation: shimmer 1.8s ease-in-out infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Safe areas handled in mobile-ultra.css with @supports (padding: max(0px)) wrapper */

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (max-width: 768px) {
    .video-card:focus,
    .nav-link:focus,
    .search-btn:focus,
    .pagination-btn:focus {
        outline: 2px solid var(--color-accent, #ff9000);
        outline-offset: 2px;
    }

    @media (prefers-contrast: high) {
        .video-card,
        .category-card {
            border: 2px solid #fff;
        }

        .nav-link.active {
            background: var(--color-accent, #ff9000);
            color: #000;
        }
    }

    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* ============================================
   WATCH PAGE MOBILE
   ============================================ */

@media (max-width: 768px) {
    .watch-container {
        width: 100%;
        max-width: 100%;
        padding: 0;
        box-sizing: border-box;
    }

    .watch-container * {
        max-width: 100%;
        box-sizing: border-box;
    }

    .video-player-container {
        width: 100%;
        max-width: 100%;
        margin: 0 0 15px 0;
        aspect-ratio: 16 / 9;
        border-radius: 0;
    }

    .video-player-container iframe {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
    }

    #videoIframe,
    iframe[src*="xvideos"],
    iframe[src*="embedframe"] {
        touch-action: manipulation;
        pointer-events: auto;
    }

    .related-videos,
    .related-section {
        padding: 0 10px;
    }

    .video-details {
        margin: 0 10px 15px 10px;
    }
}

/* ============================================
   VIDEO QUALITY BADGES & THUMBNAILS
   ============================================ */

/* Unified badge styles (frosted glass) */
.video-quality {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--color-accent, #ff9000);
    padding: 3px 8px;
    border-radius: var(--radius-sm, 6px);
    font-size: 11px;
    font-weight: bold;
    z-index: 15;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.video-thumbnail img {
    background: var(--color-bg-overlay, #2a2a2a);
    min-height: auto;
    object-fit: cover;
}

.video-thumbnail img[src=""],
.video-thumbnail img:not([src]),
.video-thumbnail img[src*="placeholder"] {
    background: linear-gradient(135deg, var(--color-bg-overlay, #2a2a2a) 0%, var(--color-bg-surface, #141414) 100%);
    position: relative;
}

.video-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #fff;
    padding: var(--spacing-xs, 4px) var(--spacing-sm, 8px);
    border-radius: var(--radius-sm, 6px);
    font-size: 12px;
    font-weight: bold;
    z-index: 15;
}

@media (max-width: 768px) {
    .video-quality {
        font-size: 9px;
        padding: 2px 5px;
        top: 5px;
        left: 5px;
        letter-spacing: 0.3px;
    }

    .video-duration {
        font-size: 10px;
        padding: 2px 5px;
        bottom: 5px;
        right: 5px;
    }
}

/* ============================================
   MOBILE CATEGORY PAGES
   ============================================ */

@media (max-width: 768px) {
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .category-card {
        padding: 15px 10px;
        min-height: 70px;
    }

    .category-name {
        font-size: 13px;
        text-align: center;
    }

    .category-count {
        font-size: 11px;
    }
}

/* ============================================
   MOBILE FOOTER
   ============================================ */

@media (max-width: 768px) {
    .footer {
        padding: 20px 10px;
        margin-top: 30px;
    }

    .footer p {
        font-size: 11px;
        line-height: 1.5;
    }
}

/* ============================================
   TABLET OPTIMIZATIONS (768px - 1024px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    .videos-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 15px;
    }

    .categories-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }

    .container {
        padding: 0 20px;
    }

    .video-title {
        font-size: 14px;
    }

    .search-bar {
        max-width: 500px;
    }
}

/* ============================================
   VERY SMALL SCREENS (< 360px)
   ============================================ */

@media (max-width: 360px) {
    .videos-grid {
        gap: 6px;
    }

    .logo-text {
        font-size: 18px;
    }

    .nav-link {
        padding: 10px;
        font-size: 11px;
    }

    .video-title {
        font-size: 11px;
    }

    .video-info {
        padding: 6px;
    }

    .section-title {
        font-size: 16px;
    }
}

/* ============================================
   NO PLAY BUTTON - PREVIEW ONLY
   ============================================ */

.video-thumbnail::before {
    display: none;
}

/* ============================================
   CHROME MOBILE SCROLLING FIX
   ============================================ */

html {
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    min-height: 100vh;
    margin: 0;
}

.videos-grid,
#videosGrid {
    overflow: visible;
    height: auto;
}

.ad-container,
.ads-row-desktop,
.desktop-ad-wrapper {
    touch-action: pan-y;
    pointer-events: auto;
}
