<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>EliteAdult - Premium Adult Content</title>
<meta name="description" content="EliteAdult - High Quality Premium Adult Videos. Search, Watch, Download and Share." />
<meta name="author" content="EliteAdult Team" />
<meta name="robots" content="noindex,nofollow" />
<link rel="icon" href="https://iili.io/3sUCA9s.th.png" />
<!-- TailwindCSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- FontAwesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet" />
<!-- Video.js CSS -->
<link href="https://vjs.zencdn.net/8.6.1/video-js.css" rel="stylesheet" />
<style>
  /* Custom Scrollbar */
  ::-webkit-scrollbar {
    width: 8px; height: 8px;
  }
  ::-webkit-scrollbar-thumb {
    background-color: rgba(236, 72, 153, 0.6);
    border-radius: 8px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }

  /* Accessibility focus */
  :focus-visible {
    outline: 3px solid #ec4899;
    outline-offset: 3px;
  }

  /* Video Thumbnail */
  .video-thumbnail {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border-radius: 0.5rem;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    background: #111;
  }
  .video-thumbnail:hover,
  .video-thumbnail:focus-visible {
    transform: scale(1.05);
    box-shadow: 0 12px 30px rgba(236, 72, 153, 0.7);
    z-index: 5;
  }
  .video-thumbnail img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 0.5rem;
    transition: transform 0.3s ease;
  }
  .video-thumbnail .overlay-gradient {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50%;
    background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.85) 100%);
    border-radius: 0 0 0.5rem 0.5rem;
  }
  .duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.75);
    color: #eee;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 9999px;
    font-weight: 600;
    text-shadow: 0 0 3px #000;
    user-select: none;
  }
  .video-title {
    position: absolute;
    bottom: 12px;
    left: 12px;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2rem;
    max-height: 2.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    width: calc(100% - 80px);
    text-shadow: 0 0 5px #000;
  }

  /* Loading spinner */
  .loading-spinner {
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top: 4px solid #ec4899;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    animation: spin 1s linear infinite;
    margin: auto;
  }
  @keyframes spin {
    0% {transform: rotate(0deg);}
    100% {transform: rotate(360deg);}
  }

  /* Search bar blur background on supported browsers */
  .search-bar {
    background-color: rgba(255 255 255 / 0.12);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
  }

  /* Responsive video player wrapper */
  .video-player-wrapper {
    position: relative;
    padding-top: 56.25%;
    background: #000;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 12px 30px rgba(0,0,0,0.7);
  }
  .video-js {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
  }

  /* Dropdown menu */
  .dropdown-menu {
    background-color: #1f2937;
    border-radius: 0.5rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    min-width: 220px;
    max-width: 320px;
    animation: fadeInScale 0.25s ease forwards;
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
    position: absolute;
    z-index: 50;
  }
  .dropdown:hover > .dropdown-menu,
  .dropdown:focus-within > .dropdown-menu {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
  }
  @keyframes fadeInScale {
    to {
      opacity: 1;
      transform: scale(1);
    }
  }

  /* Progress chapter marker */
  .progress-marker {
    position: absolute;
    width: 2px;
    height: 14px;
    background: #ec4899;
    top: -7px;
    border-radius: 1px;
    cursor: pointer;
    transition: background-color 0.3s ease;
  }
  .progress-marker:hover,
  .progress-marker:focus-visible {
    background-color: #f472b6;
  }
  .progress-marker::after {
    content: attr(data-time);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 4px;
    background: #111;
    color: white;
    font-size: 0.7rem;
    padding: 3px 6px;
    border-radius: 0.25rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    user-select: none;
  }
  .progress-marker:hover::after,
  .progress-marker:focus-visible::after {
    opacity: 1;
  }

  /* Utility: Hide scrollbar but keep scroll */
  .no-scrollbar::-webkit-scrollbar {
    display: none;
  }
  .no-scrollbar {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
  }

  /* Info Tooltip styles */
  #infoTooltip {
    width: max-content !important;
    max-width: 320px !important;
  }
</style>
</head>
<body class="bg-gray-900 text-gray-100 font-sans leading-relaxed selection:bg-pink-500 selection:text-white">

<!-- Skip link for accessibility -->
<a href="#maincontent" class="sr-only focus:not-sr-only focus:absolute focus:top-4 focus:left-4 focus:bg-pink-600 focus:text-white px-3 py-2 rounded z-50">Skip to main content</a>

<!-- Header -->
<header class="bg-gray-800 sticky top-0 z-50 shadow-lg flex flex-col sm:flex-row items-center justify-between container mx-auto px-4 py-3 gap-3">
  <div class="flex items-center space-x-3 flex-shrink-0">
    <a href="/" aria-label="EliteAdult Homepage" class="flex items-center space-x-2 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-500 rounded">
      <img src="https://iili.io/3sUCA9s.th.png" alt="EliteAdult Logo" class="w-10 h-10 rounded-full" />
      <h1 class="text-3xl font-extrabold bg-gradient-to-r from-pink-600 to-pink-900 bg-clip-text text-transparent select-none">EliteAdult</h1>
    </a>
    <!-- Info Button with Tooltip -->
    <div class="relative" tabindex="0">
      <button id="infoBtn" aria-haspopup="true" aria-expanded="false" aria-controls="infoTooltip" class="ml-3 px-3 py-1 rounded bg-pink-700 hover:bg-pink-800 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-500 text-sm font-semibold select-none" type="button">
        Info
        <i class="fas fa-info-circle ml-1"></i>
      </button>
      <div id="infoTooltip" role="tooltip" class="absolute z-50 top-full left-1/2 transform -translate-x-1/2 mt-2 max-w-xs px-4 py-3 rounded bg-pink-700 text-white text-sm shadow-lg opacity-0 pointer-events-none transition-opacity duration-200" style="width: max-content; max-width: 320px;">
        मैं एक 20 साल का बच्चा हूँ
      </div>
    </div>
  </div>

  <form role="search" class="search-bar flex items-center rounded-full px-4 py-2 w-full max-w-2xl" id="searchForm" aria-label="Search videos">
    <label for="searchInput" class="sr-only">Search videos</label>
    <button type="submit" class="text-pink-400 hover:text-pink-500 focus:outline-none focus:ring-2 focus:ring-pink-500 rounded-full">
      <i class="fas fa-search fa-lg"></i>
    </button>
    <input id="searchInput" name="searchInput" type="search" placeholder="Search videos..." autocomplete="off"
      class="flex-grow bg-transparent text-white placeholder-pink-400 ml-3 text-lg focus:outline-none focus:ring-2 focus:ring-pink-500 rounded" />
  </form>

  <nav class="flex items-center space-x-6 text-gray-400 text-sm select-none" aria-label="User menu">
    <button id="refreshBtn" aria-label="Refresh videos" class="hover:text-pink-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-500 rounded" title="Refresh videos"><i class="fas fa-sync-alt fa-lg"></i></button>
  </nav>
</header>

<main id="maincontent" tabindex="-1" class="container mx-auto px-4 py-6 max-w-screen-2xl">
  <!-- Featured Video Section -->
  <section id="featuredVideo" class="mb-12 hidden" aria-label="Featured video player">
    <article class="bg-gray-800 rounded-lg shadow-lg p-4 relative">
      <div class="video-player-wrapper mb-4" aria-live="polite" aria-atomic="true" aria-relevant="additions removals">
        <video id="mainVideoPlayer" class="video-js vjs-default-skin" controls preload="auto" poster="" aria-label="Video player"></video>
      </div>
      <header class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 mb-4">
        <div>
          <h2 id="videoTitle" class="text-3xl font-extrabold tracking-tight leading-tight max-w-xl line-clamp-3" tabindex="0">Loading...</h2>
          <div id="videoStats" class="flex space-x-6 text-pink-400 mt-1 text-sm font-semibold select-none" aria-live="polite" aria-atomic="true">
            <span aria-label="Views"><i class="fas fa-eye mr-1"></i><span id="videoViews">--</span></span>
            <span aria-label="Likes"><i class="fas fa-thumbs-up mr-1"></i><span id="videoLikes">--</span></span>
            <span aria-label="Dislikes"><i class="fas fa-thumbs-down mr-1"></i><span id="videoDislikes">--</span></span>
          </div>
        </div>
        <div class="flex flex-wrap gap-3">
          <button id="downloadBtn" class="btn-primary flex items-center gap-2 px-5 py-2 rounded bg-gradient-to-r from-pink-600 to-pink-800 hover:from-pink-700 hover:to-pink-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-400">
            <i class="fas fa-download"></i> Download
          </button>
          <button id="telegramBtn" class="btn-secondary flex items-center gap-2 px-5 py-2 rounded bg-gradient-to-r from-blue-600 to-blue-800 hover:from-blue-700 hover:to-blue-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400">
            <i class="fab fa-telegram-plane"></i> Send to Telegram
          </button>
        </div>
      </header>

      <!-- Download Options -->
      <div id="downloadOptions" class="hidden bg-gray-900 rounded-lg p-4 space-y-3" aria-label="Download options" role="region" tabindex="0" aria-live="polite">
        <h3 class="text-xl font-bold mb-2 text-pink-400">Download Options</h3>
        <div class="flex flex-wrap gap-3">
          <a href="#" id="downloadLink" class="btn-link text-pink-400 hover:text-pink-600 font-medium flex items-center gap-2 rounded border border-pink-600 px-4 py-2 transition" role="button" aria-disabled="false"><i class="fas fa-video"></i> MP4 Standard</a>
          <a href="#" id="downloadHD" class="btn-link text-pink-400 hover:text-pink-600 font-medium flex items-center gap-2 rounded border border-pink-600 px-4 py-2 transition hidden" role="button" aria-disabled="false"><i class="fas fa-hd"></i> HD Quality</a>
          <a href="#" id="download480p" class="btn-link text-pink-400 hover:text-pink-600 font-medium flex items-center gap-2 rounded border border-pink-600 px-4 py-2 transition hidden" role="button" aria-disabled="false"><i class="fas fa-video"></i> 480p</a>
          <a href="#" id="download720p" class="btn-link text-pink-400 hover:text-pink-600 font-medium flex items-center gap-2 rounded border border-pink-600 px-4 py-2 transition hidden" role="button" aria-disabled="false"><i class="fas fa-video"></i> 720p</a>
          <a href="#" id="download1080p" class="btn-link text-pink-400 hover:text-pink-600 font-medium flex items-center gap-2 rounded border border-pink-600 px-4 py-2 transition hidden" role="button" aria-disabled="false"><i class="fas fa-video"></i> 1080p</a>
        </div>
      </div>

      <!-- Telegram Section -->
      <section id="telegramSection" class="hidden mt-6 bg-gray-900 rounded-lg p-6" aria-label="Telegram bot video sending">
        <h3 class="text-xl font-bold mb-4 text-blue-400">Send Video to Telegram</h3>
        <form id="telegramForm" class="grid grid-cols-1 md:grid-cols-2 gap-5" novalidate>
          <div>
            <label for="telegramUserId" class="block mb-2 font-semibold">Your Telegram User ID</label>
            <input type="text" id="telegramUserId" name="telegramUserId" inputmode="numeric" pattern="\d+" autocomplete="off" placeholder="Enter your Telegram User ID"
              class="w-full bg-gray-700 text-white px-3 py-2 rounded focus:outline-none focus:ring-2 focus:ring-blue-500" required />
            <p class="text-xs text-gray-400 mt-1">Find it by messaging <a href="https://t.me/userinfobot" target="_blank" rel="noopener" class="underline text-blue-400 hover:text-blue-500">@userinfobot</a> on Telegram.</p>
          </div>
          <div>
            <label for="telegramQuality" class="block mb-2 font-semibold">Select Quality</label>
            <select id="telegramQuality" name="telegramQuality" class="w-full bg-gray-700 text-white px-3 py-2 rounded focus:outline-none focus:ring-2 focus:ring-blue-500" required>
              <option value="best">Best Quality</option>
              <option value="720p">720p</option>
              <option value="480p">480p</option>
              <option value="360p">360p</option>
            </select>
          </div>
          <div class="md:col-span-2">
            <button type="submit" id="sendToTelegramBtn" class="w-full flex items-center justify-center gap-3 bg-gradient-to-r from-blue-600 to-blue-800 hover:from-blue-700 hover:to-blue-900 text-white font-bold py-3 rounded focus:outline-none focus-visible:ring-4 focus-visible:ring-blue-500">
              <i class="fab fa-telegram-plane fa-lg"></i> Send to Telegram
            </button>
            <p id="telegramStatus" class="mt-3 text-center text-sm font-semibold" role="alert" aria-live="polite" aria-atomic="true"></p>
          </div>
        </form>
      </section>

      <!-- Video Chapters -->
      <section id="videoChapters" class="hidden mt-8 bg-gray-900 rounded-lg p-4" aria-label="Video chapters" tabindex="0">
        <h3 class="text-xl font-bold mb-4 text-pink-400">Video Chapters</h3>
        <div class="relative h-3 bg-gray-700 rounded-full mb-4 overflow-visible" aria-hidden="true">
          <div id="progressBar" class="absolute top-0 left-0 h-full bg-pink-600 rounded-full w-0 transition-width duration-200 ease-in-out"></div>
          <div id="chapterMarkers" class="absolute top-1/2 left-0 w-full h-0 pointer-events-auto"></div>
        </div>
        <div id="chapterList" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3 max-h-52 overflow-y-auto no-scrollbar" aria-live="polite" aria-atomic="true"></div>
      </section>
    </article>
  </section>

  <!-- Video Grid -->
  <section id="videoGrid" aria-label="Video gallery">
    <header class="flex items-center justify-between mb-6">
      <h2 id="sectionTitle" class="text-3xl font-extrabold tracking-tight text-pink-400" tabindex="0">Recommended Videos</h2>
      <button id="refreshBtnGrid" aria-label="Refresh videos" class="text-pink-400 hover:text-pink-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-400 rounded" title="Refresh videos">
        <i class="fas fa-sync-alt fa-lg"></i>
      </button>
    </header>

    <div id="loadingSpinner" role="status" aria-live="polite" aria-busy="true" class="flex justify-center items-center py-24">
      <div class="loading-spinner" aria-hidden="true"></div>
      <span class="sr-only">Loading videos...</span>
    </div>

    <ul id="videosContainer" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6 list-none" aria-live="polite" aria-relevant="additions" aria-atomic="true"></ul>

    <div id="scrollLoader" class="text-center py-6 text-pink-400 text-sm cursor-default select-none" aria-hidden="true">Scroll down to load more videos...</div>
  </section>
</main>

<!-- Footer -->
<footer class="bg-gray-800 mt-16 py-8 text-gray-400 text-sm container mx-auto px-4 rounded-t-lg select-none" aria-label="Site footer">
  <div class="flex flex-col md:flex-row md:justify-between md:items-center space-y-4 md:space-y-0">
    <div class="flex items-center space-x-3">
      <img src="https://iili.io/3sUCA9s.th.png" alt="EliteAdult Logo" class="w-8 h-8 rounded-full" />
      <h2 class="text-pink-400 font-extrabold text-xl select-text">EliteAdult</h2>
    </div>
    <nav class="flex space-x-8 text-gray-400">
      <a href="#" class="hover:text-pink-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-400 rounded">Terms</a>
      <a href="#" class="hover:text-pink-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-400 rounded">Privacy</a>
      <div class="relative dropdown">
        <button class="flex items-center gap-1 hover:text-pink-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-400 rounded" aria-haspopup="true" aria-expanded="false" id="contactMenuBtn" aria-controls="contactDropdown">
          Contact <i class="fas fa-chevron-down text-xs"></i>
        </button>
        <div id="contactDropdown" role="menu" aria-labelledby="contactMenuBtn" class="dropdown-menu hidden mt-2 py-2">
          <a href="https://t.me/DARKDATAOfficial" target="_blank" rel="noopener" role="menuitem" tabindex="-1" class="block px-4 py-2 hover:bg-pink-700 focus:bg-pink-700 focus:outline-none text-pink-400 flex items-center gap-2 whitespace-nowrap">
            <i class="fab fa-telegram-plane"></i> Telegram
          </a>
          <a href="mailto:support@eliteadult.example" role="menuitem" tabindex="-1" class="block px-4 py-2 hover:bg-pink-700 focus:bg-pink-700 focus:outline-none text-pink-400 flex items-center gap-2 whitespace-nowrap">
            <i class="fas fa-envelope"></i> Email
          </a>
        </div>
      </div>
    </nav>
  </div>
  <div class="border-t border-gray-700 mt-6 pt-6 text-center">
    <p>© 2023 EliteAdult. All rights reserved. Content is provided by third parties.</p>
    <p class="mt-2 font-semibold">This website is for adults only. By accessing this site you certify that you are 18 years or older.</p>
  </div>
</footer>

<!-- Video.js -->
<script src="https://vjs.zencdn.net/8.6.1/video.min.js"></script>

<script>
  (() => {
    'use strict';

    // Info tooltip toggle
    const infoBtn = document.getElementById('infoBtn');
    const infoTooltip = document.getElementById('infoTooltip');

    function toggleInfo() {
      const expanded = infoBtn.getAttribute('aria-expanded') === 'true';
      infoBtn.setAttribute('aria-expanded', String(!expanded));
      if(!expanded){
        infoTooltip.classList.remove('opacity-0', 'pointer-events-none');
        infoTooltip.classList.add('opacity-100');
      } else {
        infoTooltip.classList.add('opacity-0', 'pointer-events-none');
        infoTooltip.classList.remove('opacity-100');
      }
    }

    infoBtn.addEventListener('click', toggleInfo);
    // Close tooltip when focus is lost
    infoBtn.addEventListener('blur', () => {
      setTimeout(() => {
        if (!infoBtn.contains(document.activeElement) && !infoTooltip.contains(document.activeElement)) {
          infoBtn.setAttribute('aria-expanded', 'false');
          infoTooltip.classList.add('opacity-0', 'pointer-events-none');
          infoTooltip.classList.remove('opacity-100');
        }
      }, 150);
    });

    // DOM Elements
    const videosContainer = document.getElementById('videosContainer');
    const loadingSpinner = document.getElementById('loadingSpinner');
    const featuredVideoSection = document.getElementById('featuredVideo');
    const mainVideoPlayerEl = document.getElementById('mainVideoPlayer');
    const videoTitle = document.getElementById('videoTitle');
    const videoViews = document.getElementById('videoViews');
    const videoLikes = document.getElementById('videoLikes');
    const videoDislikes = document.getElementById('videoDislikes');
    const downloadBtn = document.getElementById('downloadBtn');
    const downloadOptions = document.getElementById('downloadOptions');
    const downloadLink = document.getElementById('downloadLink');
    const downloadHD = document.getElementById('downloadHD');
    const download480p = document.getElementById('download480p');
    const download720p = document.getElementById('download720p');
    const download1080p = document.getElementById('download1080p');
    const searchInput = document.getElementById('searchInput');
    const searchForm = document.getElementById('searchForm');
    const refreshBtn = document.getElementById('refreshBtn');
    const refreshBtnGrid = document.getElementById('refreshBtnGrid');
    const sectionTitle = document.getElementById('sectionTitle');
    const telegramBtn = document.getElementById('telegramBtn');
    const telegramSection = document.getElementById('telegramSection');
    const sendToTelegramBtn = document.getElementById('sendToTelegramBtn');
    const telegramUserId = document.getElementById('telegramUserId');
    const telegramQuality = document.getElementById('telegramQuality');
    const telegramStatus = document.getElementById('telegramStatus');
    const videoChapters = document.getElementById('videoChapters');
    const chapterList = document.getElementById('chapterList');
    const progressBar = document.getElementById('progressBar');
    const chapterMarkers = document.getElementById('chapterMarkers');

    // Telegram Bot Token - (KEEP PRIVATE in real environment!)
    const TELEGRAM_BOT_TOKEN = '<TRUFFLEHOG_REDACTED_TELEGRAMBOTTOKEN>';

    // State
    let currentVideoData = null;
    let videoQualities = [];
    let videoChaptersData = [];
    let videoPlayer = null;
    let loadingMore = false;
    let currentCategory = '';
    let pageCount = 1;
    const VIDEOS_PER_PAGE = 20; // Hypothetical pagination

    // Categories for random
    const categories = [
      'sister', 'teen', 'milf', 'anal', 'lesbian', 'creampie',
      'blowjob', 'hardcore', 'amateur', 'orgasm', 'threesome',
      'bukkake', 'bondage', 'oral', 'cumshot', 'gangbang',
      'public', 'interracial', 'fetish', 'asian', 'voyeur',
      'double penetration', 'foot fetish', 'squirting', 'rimming',
      'bdsm', 'strap-on', 'cuckold', 'solo', 'massage',
      'hairy', 'mature', 'big tits', 'small tits', 'big ass',
      'latina', 'ebony', 'lesbian tribbing', 'milf orgy', 'group sex',
      'blonde', 'redhead', 'hard fuck', 'deep throat', 'anal creampie',
      'oral creampie', 'public sex', 'teen anal', 'lesbian sex',
      'fingering', 'titfuck', 'dildo', 'vibrator', 'cum in mouth',
      'cum in pussy', 'cum in ass', 'facial', 'deep anal',
      'interracial gangbang', 'blowjob compilation', 'cock worship',
      'gaping', 'chubby', 'bbw', 'petite', 'college',
      'teacher', 'student', 'stepmom', 'stepsister', 'big cock',
      'small cock', 'transgender', 'shemale', 'milf double penetration',
      'teen blowjob', 'anal blowjob', 'spanking', 'bondage sex',
      'lesbian domination', 'lesbian submission', 'femdom',
      'fisting', 'gangbang compilation', 'cumshot compilation',
      'ass worship', 'rimjob', 'strap-on sex', 'hair pulling',
      'forced', 'bizarre', 'latex', 'leather', 'latex fetish',
      'cosplay', 'roleplay', 'daddy', 'baby girl', 'incest',
      'feet', 'stockings', 'leggings', 'blowjob deep throat',
      'double blowjob', 'handjob', 'ass to mouth',
    ];

    // Utility: debounce function
    function debounce(func, wait) {
      let timeout;
      return function(...args) {
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(this, args), wait);
      };
    }

    // Initialize Video.js player
    videoPlayer = videojs('mainVideoPlayer', {
      controls: true,
      autoplay: false,
      fluid: true,
      preload: 'auto',
      playbackRates: [0.5, 1, 1.25, 1.5, 2],
      controlBar: {
        volumePanel: {inline: false},
        children: [
          'playToggle',
          'currentTimeDisplay',
          'progressControl',
          'durationDisplay',
          'remainingTimeDisplay',
          'volumePanel',
          'playbackRateMenuButton',
          'fullscreenToggle'
        ]
      },
      responsive: true,
    });

    // Keyboard shortcuts on video player
    document.addEventListener('keydown', (e) => {
      if (!videoPlayer) return;
      if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') return;
      switch (e.key) {
        case ' ':
          e.preventDefault();
          videoPlayer.paused() ? videoPlayer.play() : videoPlayer.pause();
          break;
        case 'ArrowLeft':
          videoPlayer.currentTime(Math.max(videoPlayer.currentTime() - 5, 0));
          break;
        case 'ArrowRight':
          videoPlayer.currentTime(Math.min(videoPlayer.currentTime() + 5, videoPlayer.duration()));
          break;
        case 'm':
        case 'M':
          videoPlayer.muted(!videoPlayer.muted());
          break;
        case 'f':
        case 'F':
          videoPlayer.isFullscreen() ? videoPlayer.exitFullscreen() : videoPlayer.requestFullscreen();
          break;
      }
    });

    // Fetch videos from API, with pagination support
    async function fetchVideos(query = '', isRandom = false, page = 1) {
      try {
        loadingMore = true;
        if(page === 1) {
          loadingSpinner.classList.remove('hidden');
          videosContainer.innerHTML = '';
        }

        // If random category, pick one
        let searchTerm = query || currentCategory;
        if (isRandom || !searchTerm) {
          searchTerm = categories[Math.floor(Math.random() * categories.length)];
          currentCategory = searchTerm;
        }
        sectionTitle.textContent = query ? `Search Results for "${query}"` : `${capitalize(searchTerm)} Videos`;

        // API URL with pagination support if available
        let url = `https://api.agatz.xyz/api/xvideo?message=${encodeURIComponent(searchTerm)}`;
        if(page > 1){
          url += `&page=${page}`;
        }

        const res = await fetch(url);
        const data = await res.json();

        if(data.status === 200 && data.data?.length > 0){
          if(page === 1){
            displayVideos(data.data);
          } else {
            appendVideos(data.data);
          }
          pageCount = page;
          loadingSpinner.classList.add('hidden');
        } else {
          if(page === 1){
            showError("No videos found. Try another search.");
          }
          loadingSpinner.classList.add('hidden');
        }
      } catch(e){
        console.error(e);
        showError("Failed to load videos. Please try again.");
        loadingSpinner.classList.add('hidden');
      } finally {
        loadingMore = false;
      }
    }

    // Display videos replacing container's content
    function displayVideos(videos) {
      videosContainer.innerHTML = '';
      videos.forEach(video => {
        const videoCard = createVideoCard(video);
        videosContainer.appendChild(videoCard);
      });
    }

    // Append videos to existing container
    function appendVideos(videos) {
      videos.forEach(video => {
        const videoCard = createVideoCard(video);
        videosContainer.appendChild(videoCard);
      });
    }

    // Create video card element with accessibility considerations
    function createVideoCard(video) {
      const videoCard = document.createElement('li');
      videoCard.className = 'video-thumbnail focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-pink-500';
      videoCard.tabIndex = 0;
      videoCard.setAttribute('role', 'button');
      videoCard.setAttribute('aria-label', `${video.title}. Duration: ${video.duration}`);

      videoCard.innerHTML = /* html */`
        <img src="${video.thumb}" alt="Video thumbnail for ${escapeHTML(video.title)}" loading="lazy" decoding="async" />
        <div class="overlay-gradient" aria-hidden="true"></div>
        <span class="duration-badge">${video.duration}</span>
        <span class="video-title">${escapeHTML(video.title)}</span>
      `;

      videoCard.addEventListener('click', () => playVideo(video));
      videoCard.addEventListener('keydown', e => {
        if(e.key === 'Enter' || e.key === ' ') {
          e.preventDefault();
          playVideo(video);
        }
      });

      return videoCard;
    }

    // Escape HTML special chars to prevent injection
    function escapeHTML(text) {
      return text.replace(/[&<>"']/g, (m) => ({
        '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'
      }[m]));
    }

    // Play selected video in featured player
    async function playVideo(video) {
      currentVideoData = video;
      featuredVideoSection.classList.remove('hidden');
      downloadOptions.classList.add('hidden');
      telegramSection.classList.add('hidden');
      videoChapters.classList.add('hidden');
      downloadBtn.setAttribute('aria-expanded', 'false');
      telegramBtn.setAttribute('aria-expanded', 'false');

      window.scrollTo({
        top: featuredVideoSection.offsetTop - 80,
        behavior: 'smooth',
      });

      videoTitle.textContent = video.title || 'Loading...';
      videoViews.textContent = 'Loading...';
      videoLikes.textContent = 'Loading...';
      videoDislikes.textContent = 'Loading...';

      if(videoPlayer) {
        videoPlayer.poster(video.thumb || '');
        videoPlayer.src({ src: '', type: 'video/mp4' });
      }

      await fetchVideoDetails(video.url);
    }

    // Fetch video details such as quality URLs, views, chapters etc.
    async function fetchVideoDetails(videoUrl) {
      try {
        const res = await fetch(`https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(videoUrl)}`);
        const data = await res.json();

        if(data.status === 200 && data.data) {
          const details = data.data;

          videoViews.textContent = details.views ?? 'N/A';
          videoLikes.textContent = details.like_count ?? 'N/A';
          videoDislikes.textContent = details.dislike_count ?? 'N/A';

          currentVideoData.details = details;

          // Setup video source and qualities
          videoQualities = [];
          if(details.url) {
            // Video.js source update
            videoPlayer.src({ src: details.url, type: 'video/mp4' });
            videoPlayer.poster(details.thumb || currentVideoData.thumb);

            // Quality selector setup
            updateQualitySelector(details.qualities || []);

            // Chapters
            if(details.chapters?.length) {
              videoChaptersData = details.chapters.map(chap => ({
                title: chap.title,
                startTime: chap.startTime || 0
              }));
              generateVideoChapters();
              videoChapters.classList.remove('hidden');
            }
          } else {
            videoPlayer.poster(currentVideoData.thumb);
            videoPlayer.error(null);
          }
        } else {
          videoPlayer.poster(currentVideoData.thumb);
          videoPlayer.error(null);
        }
      } catch(e) {
        console.error(e);
        videoPlayer.error(null);
      }
    }

    // Update quality select element and supporting data
    function updateQualitySelector(qualities) {
      const videoQualitySelect = document.getElementById('videoQuality');
      if(!videoQualitySelect) return;

      videoQualitySelect.innerHTML = `<option value="auto" selected>Auto Quality</option>`;
      videoQualities = [];

      qualities.forEach((quality, idx) => {
        if(quality.label && quality.url) {
          const option = document.createElement('option');
          option.value = quality.label;
          option.textContent = quality.label;
          videoQualitySelect.appendChild(option);
          videoQualities.push({ label: quality.label, src: quality.url, index: idx });
        }
      });

      // On quality change, switch video source
      videoQualitySelect.onchange = () => {
        const selected = videoQualitySelect.value;
        if(selected === 'auto') {
          videoPlayer.src({ src: currentVideoData.details.url, type: 'video/mp4' });
        } else {
          const q = videoQualities.find(q => q.label === selected);
          if(q) {
            videoPlayer.src({ src: q.src, type: 'video/mp4' });
            videoPlayer.play();
          }
        }
      };
    }

    // Generate chapter markers and list with accessibility
    function generateVideoChapters() {
      chapterList.innerHTML = '';
      chapterMarkers.innerHTML = '';

      const dur = videoPlayer.duration();

      if(!dur || !videoChaptersData.length) return;

      videoChaptersData.forEach((chap, idx) => {
        // Chapter list item
        const chapterElem = document.createElement('button');
        chapterElem.type = 'button';
        chapterElem.className = 'bg-pink-700 hover:bg-pink-600 rounded p-2 text-left text-white text-sm font-medium focus:outline-none focus-visible:ring-2 focus-visible:ring-pink-400 truncate';
        chapterElem.textContent = chap.title || `Chapter ${idx + 1}`;
        chapterElem.setAttribute('aria-label', `Jump to chapter: ${chap.title || `Chapter ${idx + 1}`}, time: ${formatTime(chap.startTime)}`);
        chapterElem.onclick = () => {
          videoPlayer.currentTime(chap.startTime);
          videoPlayer.play();
        };
        chapterList.appendChild(chapterElem);

        // Marker on progress bar
        const markerPosPercent = (chap.startTime / dur) * 100;
        const marker = document.createElement('div');
        marker.className = 'progress-marker';
        marker.style.left = `${markerPosPercent}%`;
        marker.tabIndex = 0;
        marker.setAttribute('title', `Chapter: ${chap.title || `Chapter ${idx + 1}`} (${formatTime(chap.startTime)})`);
        marker.setAttribute('data-time', formatTime(chap.startTime));
        marker.setAttribute('role', 'button');
        marker.setAttribute('aria-label', `Chapter marker: ${chap.title || `Chapter ${idx + 1}`}, jump to ${formatTime(chap.startTime)}`);

        marker.addEventListener('click', () => {
          videoPlayer.currentTime(chap.startTime);
          videoPlayer.play();
        });
        marker.addEventListener('keydown', (e) => {
          if(e.key === 'Enter' || e.key === ' ') {
            e.preventDefault();
            videoPlayer.currentTime(chap.startTime);
            videoPlayer.play();
          }
        });

        chapterMarkers.appendChild(marker);
      });

      videoPlayer.on('timeupdate', () => {
        const cur = videoPlayer.currentTime();
        const progressPercent = (cur / dur) * 100;
        progressBar.style.width = `${progressPercent}%`;
      });
    }

    // Human readable time mm:ss
    function formatTime(seconds) {
      seconds = Math.floor(seconds || 0);
      const m = Math.floor(seconds / 60);
      const s = seconds % 60;
      return `${m}:${s < 10 ? '0' : ''}${s}`;
    }

    // Fetch download URLs and update download links display
    async function fetchDownloadUrl(videoUrl) {
      try {
        const res = await fetch(`https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(videoUrl)}`);
        const data = await res.json();

        if(data.status === 200 && data.data){
          const videoData = data.data;

          if(videoData.url) {
            downloadLink.href = videoData.url;
            downloadLink.setAttribute('download', `${videoData.title || 'video'}.mp4`);
            downloadLink.innerHTML = `<i class="fas fa-video"></i> MP4 (${videoData.quality || 'Standard'})`;
            downloadLink.classList.remove('text-gray-400');
            downloadLink.setAttribute('aria-disabled', 'false');
            downloadLink.tabIndex = 0;
          } else {
            downloadLink.href = '#';
            downloadLink.innerHTML = `<i class="fas fa-times-circle"></i> Download unavailable`;
            downloadLink.classList.add('text-gray-500');
            downloadLink.setAttribute('aria-disabled', 'true');
          }

          if(videoData.hd_url){
            downloadHD.href = videoData.hd_url;
            downloadHD.classList.remove('hidden');
            downloadHD.setAttribute('download', `${videoData.title || 'video'}_HD.mp4`);
          } else {
            downloadHD.classList.add('hidden');
            downloadHD.href = '#';
          }

          const qualitiesMap = {
            '480': download480p,
            '720': download720p,
            '1080': download1080p
          };
          for(const key in qualitiesMap){
            qualitiesMap[key].classList.add('hidden');
            qualitiesMap[key].href = '#';
          }

          if(Array.isArray(videoData.qualities)){
            videoData.qualities.forEach(quality => {
              if(!quality.label || !quality.url) return;
              if(quality.label.includes("480")){
                download480p.href = quality.url;
                download480p.classList.remove('hidden');
                download480p.setAttribute('download', `${videoData.title || 'video'}_480p.mp4`);
              } else if(quality.label.includes("720")){
                download720p.href = quality.url;
                download720p.classList.remove('hidden');
                download720p.setAttribute('download', `${videoData.title || 'video'}_720p.mp4`);
              } else if(quality.label.includes("1080")){
                download1080p.href = quality.url;
                download1080p.classList.remove('hidden');
                download1080p.setAttribute('download', `${videoData.title || 'video'}_1080p.mp4`);
              }
            });
          }
        } else {
          downloadLink.href = '#';
          downloadLink.innerHTML = `<i class="fas fa-times-circle"></i> Download unavailable`;
          downloadLink.classList.add('text-gray-500');
          downloadLink.setAttribute('aria-disabled', 'true');
          downloadHD.classList.add('hidden');
          download480p.classList.add('hidden');
          download720p.classList.add('hidden');
          download1080p.classList.add('hidden');
        }
      } catch(e){
        console.error(e);
        downloadLink.href = '#';
        downloadLink.innerHTML = `<i class="fas fa-times-circle"></i> Error loading download`;
        downloadLink.classList.add('text-gray-500');
        downloadLink.setAttribute('aria-disabled', 'true');
        downloadHD.classList.add('hidden');
        download480p.classList.add('hidden');
        download720p.classList.add('hidden');
        download1080p.classList.add('hidden');
      }
    }

    // Send video download link to Telegram bot
    async function sendToTelegram(event) {
      event.preventDefault();
      const userId = telegramUserId.value.trim();
      const quality = telegramQuality.value;

      telegramStatus.textContent = '';
      telegramStatus.classList.remove('text-red-500','text-blue-500','text-green-500');

      if(!userId.match(/^\d+$/)) {
        telegramStatus.textContent = 'Please enter a valid numeric Telegram User ID.';
        telegramStatus.classList.add('text-red-500');
        telegramUserId.focus();
        return;
      }
      telegramStatus.textContent = 'Sending video to Telegram...';
      telegramStatus.classList.add('text-blue-500');

      try {
        // Save userId in localStorage
        localStorage.setItem('telegramUserId', userId);
        // Fetch download info first
        const res = await fetch(`https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(currentVideoData.url)}`);
        const data = await res.json();

        if(data.status !== 200 || !data.data){
          telegramStatus.textContent = 'Failed to get video download link.';
          telegramStatus.classList.replace('text-blue-500','text-red-500');
          return;
        }

        let downloadUrl = data.data.url;

        if(quality !== 'best' && data.data.qualities?.length > 0) {
          const selectedQuality = data.data.qualities.find(q =>
            (quality === '720p' && q.label.includes('720')) ||
            (quality === '480p' && q.label.includes('480')) ||
            (quality === '360p' && q.label.includes('360'))
          );
          if(selectedQuality) {
            downloadUrl = selectedQuality.url;
          }
        } else if(quality === 'best' && data.data.hd_url) {
          downloadUrl = data.data.hd_url;
        }

        const textMessage = `Here's your video:\n${currentVideoData.title}\nDownload link: ${downloadUrl}`;

        const sendRes = await fetch(`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage`, {
          method: 'POST',
          headers: {'Content-Type': 'application/json'},
          body: JSON.stringify({
            chat_id: userId,
            text: textMessage,
            disable_web_page_preview: false,
          })
        });
        const botData = await sendRes.json();

        if(botData.ok){
          telegramStatus.textContent = 'Video sent successfully to Telegram!';
          telegramStatus.classList.replace('text-blue-500','text-green-500');
        } else {
          telegramStatus.textContent = 'Failed to send video. Please check your User ID.';
          telegramStatus.classList.replace('text-blue-500','text-red-500');
        }

      } catch(e) {
        console.error(e);
        telegramStatus.textContent = 'Error sending video. Please try again.';
        telegramStatus.classList.replace('text-blue-500','text-red-500');
      }
    }

    // Show error message on grid
    function showError(message) {
      videosContainer.innerHTML =
        `<li class="col-span-full text-center py-10" role="alert" aria-live="assertive" tabindex="0">
          <i class="fas fa-exclamation-triangle text-4xl text-pink-500 mb-4" aria-hidden="true"></i>
          <p class="text-xl">${escapeHTML(message)}</p>
        </li>`;
    }

    // Capitalize string helper
    function capitalize(str) {
      return str.charAt(0).toUpperCase() + str.slice(1);
    }

    // On search form submit
    searchForm.addEventListener('submit', e => {
      e.preventDefault();
      const query = searchInput.value.trim();
      if (query.length < 2) return;

      currentCategory = query;         // <<<<<<<<<<<<<< IMPORTANT FIX: Set currentCategory here to enable scroll loading for searches
      pageCount = 1;
      fetchVideos(query, false, 1);
    });

    // Refresh buttons load random category videos
    refreshBtn.addEventListener('click', () => {
      currentCategory = '';
      pageCount = 1;
      fetchVideos('', true);
      searchInput.value = '';
    });
    refreshBtnGrid.addEventListener('click', () => {
      currentCategory = '';
      pageCount = 1;
      fetchVideos('', true);
      searchInput.value = '';
    });

    // Download button toggle
    downloadBtn.addEventListener('click', () => {
      const expanded = downloadOptions.classList.toggle('hidden');
      telegramSection.classList.add('hidden');
      telegramBtn.setAttribute('aria-expanded', 'false');
      downloadBtn.setAttribute('aria-expanded', expanded ? 'true' : 'false');
      if (!downloadOptions.classList.contains('hidden') && currentVideoData?.url) {
        fetchDownloadUrl(currentVideoData.url);
      }
    });

    // Telegram button toggle
    telegramBtn.addEventListener('click', () => {
      const expanded = telegramSection.classList.toggle('hidden');
      downloadOptions.classList.add('hidden');
      downloadBtn.setAttribute('aria-expanded', 'false');
      telegramBtn.setAttribute('aria-expanded', expanded ? 'true' : 'false');
      if (expanded) {
        const savedId = localStorage.getItem('telegramUserId');
        if(savedId) telegramUserId.value = savedId;
        telegramStatus.textContent = '';
      }
    });

    // Send to Telegram submit
    sendToTelegramBtn.addEventListener('click', sendToTelegram);

    // Infinite scroll for loading more videos
    window.addEventListener('scroll', debounce(() => {
      if(loadingMore) return;
      if(!currentCategory) return;   // Prevent loading when no category/search

      const nearBottom = window.innerHeight + window.scrollY >= document.body.offsetHeight - 800;
      if(nearBottom){
        fetchVideos(currentCategory, false, pageCount + 1);
      }
    }, 250));

    // Initial load random videos
    fetchVideos('', true);

  })();
</script>

</body>
</html>