/* Mobile-specific styles */
/* Hide mobile elements on desktop by default */
/* Hide assign-magnet-icon by default (will be shown on mobile) */
.assign-magnet-mobile {
    display: none !important;
}
#mobileActionModal {
    display: none !important; /* Hide on desktop by default - with !important */
}

@media (max-width: 768px) {
    /* On mobile devices, reset to normal display:none so JavaScript can control it */
    #mobileActionModal {
        display: none !important; /* Start hidden */
    }
    
    /* This more specific rule allows JavaScript's inline style to work */
    #mobileActionModal[style*="display: flex"] {
        display: flex !important; /* Override with !important when JS sets display:flex */
    }

    /* Rate Limits Container - Mobile Disable */
    .rate-limits-section {
        display: none !important;
        pointer-events: none;
        visibility: hidden;
        position: absolute;
        z-index: -1;
    }

    .rate-limits-container {
        display: none !important;
        pointer-events: none;
        visibility: hidden;
        position: absolute;
        z-index: -1;
    }

    /* Overlay and Container Styles */
    .overlay-content {
        position: fixed;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        margin: 0 auto;
        max-width: 100%;
        max-height: 90vh;
        border-radius: 16px 16px 0 0;
        padding-bottom: calc(20px + var(--safe-area-inset-bottom));
        top: 10%;
    }

    .close-btn {
        top: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
        font-size: 28px;
    }

    /* Prevent horizontal scrolling but allow vertical */
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
        width: 100%;
        position: relative;
        overscroll-behavior-x: none;
        -webkit-overflow-scrolling: touch;
    }

    /* Search Results Styles */
    #searchResult {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    #searchResult > div {
        width: 100%;
        padding-top: 15px;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }

    .sresult {
        width: 150px;
        max-width: calc(50% - 10px);
        margin: 0;
    }

    .sresult img {
        width: 100%;
        height: auto;
        max-width: 100%;
    }

    h2.searchresult-item {
        font-size: 0.8rem;
        line-height: 1.1rem;
        padding-top: 5px;
        padding-bottom: 5px;
    }

    /* Season Info and Backdrop Styles */
    #seasonResults {
        position: relative;
    }

    .season-info-container {
        padding: 0;
        padding-top: 0;
        margin-bottom: 0;
        position: relative;
        z-index: 1;
        min-height: 200px;
        display: flex;
        flex-direction: column;
        align-items: left;
        justify-content: flex-end;
    }

    .season-bg-image {
        position: absolute;
        top: 60px;
        left: 0;
        height: 600px;
        width: 100%;
        z-index: -1;
        background-size: cover;
        background-position: center 20%;
        background-repeat: no-repeat;
        transform: none;
        margin-top: -180px;
    }

    .season-bg-image::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(to bottom, 
            rgba(0, 0, 0, 1) 0%,
            rgba(0, 0, 0, 0.7) 15%,
            rgba(0, 0, 0, 0) 40%,
            rgba(0, 0, 0, 0.6) 60%,
            rgba(0, 0, 0, 1) 100%
        );    }

    .season-details {
        position: relative;
        z-index: 2;
        color: white;
        text-shadow: 0 2px 4px rgba(0,0,0,0.5);
        text-align: center;
        background-color: rgba(0,0,0,0);
    }

    .season-details p {
        display: none;
    }

    .season-poster {
        display: none;
    }

    /* Episode Results Styles */
    #episodeResults > div {
        position: inherit !important;
        z-index: 50;
        width: 100% !important;
        max-width: 100% !important;
        top: 50px;
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
        padding: 10px;
        margin: 0 !important;
        box-sizing: border-box;
    }

    .episode {
        width: 100% !important;
        margin: 0;
        display: flex;
        flex-direction: column;
        min-width: 0; /* Prevents flex items from overflowing */
    }

    .episode img {
        width: 100% !important;
        height: auto !important;
        object-fit: cover;
        aspect-ratio: 16/9;
    }

    .episode button {
        width: 100% !important;
        font-size: 0.9rem;
        padding: 8px;
        border: 1px solid #2b2b2b;
    }

    h2.episode-title {
        font-size: 0.8rem;
        line-height: 1.1rem;
        margin: 4px 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    p.episode-sub {
        font-size: 0.7rem;
        line-height: 1.2rem;
        margin: 2px 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Season Controls */
    .season-controls {
        margin-top: 0;
        position: relative;
        z-index: 2;
        margin-top: 120px;
        display: flex;
        /*flex-direction: column;*/
        gap: 7px;
        align-items: left !important;
        /*width: 50px;*/
        /*margin-left: 110px;*/
    }

    .search-results-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    button#seasonPackButton {
        min-width: auto !important;
    }
    
    /* Replace "Season Pack" with "Pack" on mobile */
    button#seasonPackButton {
        font-size: 0;
    }
    
    button#seasonPackButton::before {
        content: "Pack";
        font-size: 16px;
    }
    
    /* Replace "Request Season" with "Request" on mobile */
    button#requestSeasonButton {
        font-size: 0;
    }
    
    button#requestSeasonButton::before {
        content: "Request";
        font-size: 16px;
    }

    select#seasonDropdown,
    button#seasonPackButton {
        position: static;
        margin: 10px 0;
        min-width: 183px;
        min-height: 38px;
    }

    /* iOS dropdown styling */
    input, select, #search-form button {
        -webkit-appearance: none;
        appearance: none;
        height: 35px;  /* Standard iOS button height */
        padding: 0 30px 0 10px;  /* Right padding for arrow */
        background-size: 20px;
        font-size: 16px;  /* Prevent iOS zoom on focus */
        border-radius: 3px;
    }
    
    select {
        background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
        background-repeat: no-repeat;
        background-position: right 5px center;
    }

    /* Ensure buttons match the dropdown height */
    #search-form button {
        padding: 0 5px 0 5px;  /* Right padding for arrow */
        background-color: #4CAF50;
    }

    /* Trending Section Styles */
    .trending-container {
        padding-top: 10px;
        overscroll-behavior-x: none;
        -webkit-overflow-scrolling: touch;
    }

    .trending-movies,
    .trending-shows,
    .trending-anime {
        padding: 10px;
        overscroll-behavior: none;
        margin-bottom: 15px;
    }

    .media-card {
        width: 120px;
    }

    .show-rating {
        display: none;
    }

    .episode-rating {
        display: none;
    }

    .season-overview {
        display: none;
    }

    /* Lock scrolling in containers */
    .movie-list, .show-list, .anime-list {
        display: flex;
        overflow-x: auto;  /* Restore horizontal scroll */
        scroll-behavior: smooth;
        scrollbar-width: none;
        -ms-overflow-style: none;
        gap: 10px;
        padding: 10px;
        margin: 0;
        width: 100%;
        flex-wrap: nowrap;
        touch-action: manipulation;  /* Allow both horizontal and vertical scrolling */
        cursor: grab;
        will-change: transform;
        overscroll-behavior-x: none;  /* Prevent bounce */
        -webkit-overflow-scrolling: touch;  /* Smooth scrolling on iOS */
    }

    .scroll-container {
        overflow-x: auto;
        overscroll-behavior-x: none;
        touch-action: manipulation;
        -webkit-overflow-scrolling: touch;
    }

    .movie-list::-webkit-scrollbar, 
    .show-list::-webkit-scrollbar,
    .anime-list::-webkit-scrollbar,
    .scroll-container::-webkit-scrollbar {
        display: none;
    }

    .media-card {
        flex: 0 0 120px;
        min-width: 120px;
        margin-right: 5px;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
        touch-action: manipulation;
    }

    .media-poster-img {
        width: 120px;
        height: 180px;
        border-radius: 8px;
        object-fit: cover;
    }

    /* Overlay Content */
    #overlayContentRes > div {
        min-width: 200px;
    }

    /* Torrent Results Mobile Styles */
    .torresult {
        width: 100% !important;
        max-width: calc(100% - 20px) !important;
        margin: 10px auto !important;
        box-sizing: border-box;
        position: relative; /* to place absolute positioned assign icon */
    }

    .torresult button {
        width: 100%;
        padding: 15px 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .torresult-info {
        width: 100%;
        text-align: center;
    }

    /* Assign Magnet button on mobile torrent cards */
    .torresult .assign-magnet-icon {
        position: absolute;
        bottom: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        background-color: #FFC107; /* Yellow */
        border: 2px solid rgba(0,0,0,0.3);
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10;
        box-shadow: 0 2px 4px rgba(0,0,0,0.3);
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .torresult .assign-magnet-icon:hover {
        background-color: #FFA000;
        transform: scale(1.05);
        box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    }

    .torresult .assign-magnet-icon svg {
        width: 20px;
        height: 20px;
        color: #333;
        /* fill: currentColor; */
        pointer-events: none;
    }

    p.torresult-title {
        font-size: 1rem;
        text-align: center;
        margin: 5px 0;
        word-break: break-word;
    }

    p.torresult-item {
        font-size: 0.9rem;
        margin: 5px 0;
        word-break: normal;
        overflow-wrap: anywhere;
        white-space: normal;
        hyphens: none;
    }

    .cache-status {
        margin: 10px auto 5px auto;
        display: block;
        width: auto;
    }



    #overlayContent > div {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 10px;
    }

    #overlayContent h3 {
        text-align: center;
        width: 100%;
        margin: 10px 0;
        padding: 0 20px;
        box-sizing: border-box;
    }

    /* Mobile torrent controls */
    .mobile-torrent-controls {
        width: 100%;
        padding: 15px;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 12px;
        margin-bottom: 15px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .mobile-torrent-controls .torrent-version-dropdown-wrapper,
    .mobile-torrent-controls .torrent-folder-dropdown-wrapper {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        width: 100%;
    }

    /* Add bottom padding when version dropdown is the last child (Plex mode) */
    .mobile-torrent-controls .torrent-version-dropdown-wrapper:last-child {
        padding-bottom: 10px;
    }

    /* Add bottom padding to folder dropdown (Symlink mode) */
    .mobile-torrent-controls .torrent-folder-dropdown-wrapper {
        padding-bottom: 10px;
    }

    .mobile-torrent-controls label {
        color: #d4d4d4;
        font-size: 0.9rem;
        font-weight: 500;
        white-space: nowrap;
        min-width: 60px;
    }

    .mobile-torrent-controls select {
        flex: 1;
        padding: 12px 40px 12px 12px;
        background: #1a1a1a;
        border: 1px solid #404040;
        border-radius: 8px;
        color: #fff;
        font-size: 0.9rem;
        min-height: 44px;
        -webkit-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
        background-repeat: no-repeat;
        background-position: right 10px center;
        background-size: 20px;
    }

    .mobile-torrent-controls select:focus {
        outline: none;
        border-color: #f97316;
    }

    /* Form Styles */
    form#search-form {
        display: flex;
        width: 95%;
        flex-direction: row;
        gap: 8px;
        padding: 10px;
        align-items: center;
        justify-content: center;
        margin: 0;
        box-sizing: border-box;
    }
    
    form#search-form input,
    form#search-form select,
    form#search-form button {
        margin: 0;
        box-sizing: border-box;
        min-height: 44px; /* Increased touch target size */
        padding: 0 10px;
    }

    form#search-form input {
        width: 40%;
        min-width: 120px;
    }

    form#search-form select {
        width: 30%;
        min-width: 90px;
        padding-right: 25px;
    }

    form#search-form button {
        width: 20%;
        min-width: 70px;
    }

    /* Override base.css background gradient with fixed height */
    body {
        background: linear-gradient(to bottom, #333 0px, #333 450px, #000 650px) !important;
        background-attachment: initial !important;
        padding-top: 35px;
    }

    /* Override any potential positioning from the base styles */
    #scraper-container {
        padding-top: 0;
    }

    form#search-form {
        position: static;
        transform: none;
        top: auto;
        left: auto;
    }

    form#search-form input,
    form#search-form select,
    form#search-form button {
        position: static;
        transform: none;
    }

    /* Media Card Reset and Mobile Styles */
    .media-card,
    .sresult {
        width: 140px !important;
        min-width: 140px !important;
        max-width: 140px !important;
        padding: 0 !important;
        margin: 0 !important;
        transform: none !important;
        touch-action: manipulation !important;
    }

    /* Hide request-icon and tester-icon on mobile devices */
    .media-card .poster-container .request-icon,
    .media-card .poster-container .tester-icon,
    .sresult .poster-container .request-icon,
    .sresult .poster-container .tester-icon {
        display: none !important;
    }

    /* Show assign-magnet-icon on mobile devices - positioned at bottom right (only for scrape results) */
    .torresult .assign-magnet-mobile {
        display: block !important;
        position: absolute;
        bottom: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        background-color: #FFC107; /* Yellow color */
        border: 2px solid rgba(0, 0, 0, 0.3);
        border-radius: 6px;
        cursor: pointer;
        z-index: 10;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        pointer-events: auto; /* Ensure pointer events work */
    }

    .torresult .assign-magnet-mobile:hover {
        background-color: #FFA000; /* Darker yellow on hover */
        transform: scale(1.1);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    }

    .torresult .assign-magnet-mobile svg {
        width: 20px;
        height: 20px;
        color: #333; /* Dark text for better contrast */
        fill: currentColor;
    }

    /* Ensure containers are positioned relatively for absolute positioning */
    .sresult .media-poster,
    .torresult {
        position: relative !important;
    }

    /* Override any button styles that might interfere */
    .torresult .assign-magnet-mobile:active,
    .torresult .assign-magnet-mobile:focus {
        outline: none !important;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4) !important;
    }

    .media-poster,
    .sresult button {
        width: 140px !important;
        min-width: 140px !important;
        max-width: 140px !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
        position: relative !important;
    }

    .media-poster-img,
    .sresult img {
        width: 140px !important;
        height: 210px !important;
        transform: none !important;
        box-shadow: none !important;
        border-radius: var(--border-radius-lg);
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
    }

    .poster-container {
        width: 140px !important;
        height: 210px !important;
        transform: none !important;
        margin: 0 !important;
        padding: 0 !important;
        touch-action: manipulation !important;
    }

    .poster-overlay {
        position: absolute !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        opacity: 1 !important;
        transform: none !important;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.7) 60%, transparent 100%) !important;
        padding: 30px 8px 8px !important;
        min-height: auto;
        width: 140px !important;
        text-align: center;
        margin: 0 !important;
        border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
    }

    .poster-overlay h3 {
        font-size: 0.9rem;
        line-height: 1.2;
        margin: 0;
        padding: 0;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: center;
        color: #fff !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    .poster-overlay p {
        font-size: 0.8rem;
        margin: 4px 0 0;
        padding: 0;
        width: 100%;
        text-align: center;
        color: rgba(255, 255, 255, 0.8) !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    .media-title,
    .searchresult-info {
        position: absolute !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        opacity: 1 !important;
        transform: none !important;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.7) 60%, transparent 100%) !important;
        padding: 30px 8px 8px !important;
        min-height: auto;
        width: 140px !important;
        text-align: center;
        margin: 0 !important;
        border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
    }

    .media-title h2,
    .searchresult-info h2,
    .searchresult-item {
        font-size: 0.9rem;
        line-height: 1.2;
        margin: 0;
        padding: 0;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: center;
        color: #fff !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    .media-title p,
    .searchresult-info p,
    .searchresult-year {
        font-size: 0.8rem;
        margin: 4px 0 0;
        padding: 0;
        width: 100%;
        text-align: center;
        color: rgba(255, 255, 255, 0.8) !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    /* Movie, Show, and Anime List Container Adjustments */
    .movie-list,
    .show-list,
    .anime-list {
        padding: 10px 0;
        margin: 0;
        gap: 10px;
    }

    .movie-list,
    .show-list {
        margin-bottom: 10px;
    }

    input[name="versions"], input[name="selection-type"], input[name="seasons"], input[name="scrape-versions"] {
        height: auto !important;
        appearance: auto !important;
    }

    .scroll-container {
        padding: 10px;
        margin: 0;
        gap: 10px;
    }

    /* Disable hover effects and glow */
    .media-poster:hover .media-poster-img,
    .media-poster:hover .media-title,
    .sresult:hover img,
    .sresult:hover .searchresult-info,
    .media-poster:hover .poster-container,
    .sresult:hover .poster-container,
    .media-card:hover,
    .sresult:hover {
        transform: none !important;
        opacity: 1 !important;
        box-shadow: none !important;
    }

    /* Remove all glow and enhanced shadows on mobile */
    .poster-container,
    .media-poster-img,
    .sresult img,
    .media-card,
    .sresult {
        box-shadow: none !important;
    }

    /* Disable hover pseudo-effects */
    .media-poster:hover::after,
    .sresult:hover::after {
        content: none !important;
        display: none !important;
    }

    .media-title {
        display: none;
    }

    /* Trending sections adjustments */
    .trending-movies,
    .trending-shows,
    .trending-anime {
        padding: 0;
        margin: 0;
        margin-bottom: 20px;
    }

    /* Remove bottom margin from last trending section */
    .trending-anime {
        margin-bottom: 10px;
    }

    .trending-header {
        padding: 10px;
        margin: 0;
    }

    .trending-title {
        font-size: 1.2rem;
        margin: 0;
    }

    /* Adjust navigation buttons */
    .trending-navigation {
        gap: 8px;
    }

    .trending-nav-button {
        width: 32px;
        height: 32px;
        padding: 4px;
    }
}

/* Mobile Action Modal Styles */
@media (max-width: 768px) {
    .mobile-action-modal {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.8);
        z-index: 1001;
        justify-content: center;
        align-items: center;
    }
    
    .mobile-action-content {
        background-color: #2d2d2d;
        border-radius: 16px;
        padding: 24px;
        width: 90%;
        max-width: 350px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
        color: white;
    }
    
    .mobile-action-title {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 16px;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .mobile-action-year {
        text-align: center;
        font-size: 14px;
        color: rgba(255, 255, 255, 0.7);
        margin-bottom: 24px;
    }
    
    .mobile-action-buttons {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    .mobile-action-button {
        padding: 14px;
        border-radius: 8px;
        border: none;
        color: white;
        font-size: 16px;
        font-weight: bold;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
    }
    
    .mobile-scrape-button {
        background-color: #4CAF50;
    }
    
    .mobile-scrape-button:hover, .mobile-scrape-button:active {
        background-color: #45a049;
    }
    
    .mobile-request-button {
        background-color: #3498db;
    }
    
    .mobile-request-button:hover, .mobile-request-button:active {
        background-color: #2980b9;
    }
    
    .mobile-cancel-button {
        background-color: rgba(255, 255, 255, 0.1);
        margin-top: 8px;
    }
    
    .mobile-cancel-button:hover, .mobile-cancel-button:active {
        background-color: rgba(255, 255, 255, 0.2);
    }
}

