* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --background-color: #ffffff;
    --surface-color: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --hover-color: #f1f5f9;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --border-radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --container-max-width: 1200px;
    --container-padding: 1rem;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-color);
}

.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 var(--container-padding);
}

/* Header & Navigation */
.header {
    background-color: var(--background-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 var(--container-padding);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.nav-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.25rem;
}

.logo-img {
    width: 32px;
    height: 32px;
    margin-right: 0.5rem;
}

.nav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-menu li {
    margin-left: 2rem;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    transition: color 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-color);
}

.nav-toggle {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

.nav-toggle span {
    width: 24px;
    height: 2px;
    background-color: var(--text-primary);
    margin: 2px 0;
    transition: 0.3s;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 4rem 0;
    position: relative;
    overflow: hidden;
}

.hero-content {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 var(--container-padding);
    text-align: center;
    position: relative;
    z-index: 2;
}

.hero-title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.hero-subtitle {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.hero-cta {
    display: inline-block;
    background-color: white;
    color: var(--primary-color);
    padding: 0.75rem 2rem;
    text-decoration: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}

.hero-cta:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.hero-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.1;
    z-index: 1;
}

.hero-bg-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
    font-size: 1rem;
}

.btn:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-primary {
    background-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

/* Sections */
.section-title {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 2rem;
    text-align: center;
    color: var(--text-primary);
}

.featured,
.categories-preview {
    padding: 4rem 0;
}

.categories-preview {
    background-color: var(--surface-color);
}

/* Video Grid */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.video-card {
    background-color: var(--background-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
}

.video-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.video-thumbnail {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background-color: var(--surface-color);
}

.video-info {
    padding: 1.5rem;
}

.video-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.video-creator {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.video-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.video-category {
    background-color: var(--primary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.video-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.category-card {
    background-color: var(--background-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
    text-align: center;
}

.category-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.category-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.category-card p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.category-detail-card {
    background-color: var(--background-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.category-detail-card h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.category-stats {
    margin: 1rem 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Filters */
.filters {
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
}

.search-bar {
    margin-bottom: 1rem;
}

.search-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
}

.filter-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--background-color);
    font-size: 0.875rem;
}

/* Page Header */
.page-header {
    text-align: center;
    padding: 3rem 0;
}

.page-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.page-header p {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

/* Video Detail */
.video-detail {
    max-width: 800px;
    margin: 0 auto;
}

.video-embed {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
    margin-bottom: 2rem;
    border-radius: var(--border-radius);
    overflow: hidden;
}

.video-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.video-detail-info {
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
}

.video-detail-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.video-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0;
}

.topic-tag {
    background-color: var(--primary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.content-disclaimer {
    background-color: var(--warning-color);
    color: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    text-align: center;
}

/* Content Section */
.content-section {
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.8;
}

.content-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 2rem 0 1rem 0;
    color: var(--text-primary);
}

.content-section h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.5rem 0 0.75rem 0;
    color: var(--text-primary);
}

.content-section ul {
    margin: 1rem 0;
    padding-left: 2rem;
}

.content-section li {
    margin-bottom: 0.5rem;
}

/* Contact */
.contact-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    margin-top: 2rem;
}

.contact-info h2,
.contact-form h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.contact-item {
    margin-bottom: 2rem;
}

.contact-item h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.contact-item a {
    color: var(--primary-color);
    text-decoration: none;
}

.contact-item a:hover {
    text-decoration: underline;
}

/* Forms */
.form {
    display: flex;
    flex-direction: column;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-message {
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-top: 1rem;
}

.form-message.success {
    background-color: var(--success-color);
    color: white;
}

.form-message.error {
    background-color: var(--error-color);
    color: white;
}

/* Footer */
.footer {
    background-color: var(--text-primary);
    color: white;
    padding: 3rem 0 1rem 0;
    margin-top: 4rem;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-section h3,
.footer-section h4 {
    margin-bottom: 1rem;
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: 0.5rem;
}

.footer-section a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-section a:hover {
    color: white;
}

.footer-bottom {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
}

/* Utility Classes */
.no-results {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.not-found {
    text-align: center;
    padding: 3rem;
}

.not-found h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-menu {
        display: none;
    }
    
    .nav-toggle {
        display: flex;
    }
    
    .hero-title {
        font-size: 2rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
    }
    
    .video-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .category-grid {
        grid-template-columns: 1fr;
    }
    
    .categories-grid {
        grid-template-columns: 1fr;
    }
    
    .contact-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .filter-controls {
        flex-direction: column;
    }
    
    .filter-select {
        width: 100%;
    }
    
    .page-header h1 {
        font-size: 2rem;
    }
    
    .container {
        padding: 0 1rem;
    }
    
    .hero {
        padding: 2rem 0;
    }
    
    .featured,
    .categories-preview {
        padding: 2rem 0;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 1.75rem;
    }
    
    .video-card {
        margin-bottom: 1rem;
    }
    
    .video-info {
        padding: 1rem;
    }
    
    .category-detail-card {
        padding: 1.5rem;
    }
    
    .video-detail-info {
        padding: 1.5rem;
    }
}

/* FILE: assets/app.js -->
// Video Data
const videoData = {
    1: {
        id: 1,
        title: "Introduction to Machine Learning",
        creator: "MIT OpenCourseWare",
        category: "lectures",
        duration: "45:32",
        views: "1.2M",
        shortDesc: "Comprehensive introduction to machine learning concepts and algorithms.",
        longDesc: "This lecture provides a thorough introduction to machine learning, covering fundamental concepts, various algorithms, and practical applications. Perfect for beginners looking to understand the basics of AI and machine learning.",
        topics: ["Machine Learning", "AI", "Algorithms", "Data Science"],
        embedUrl: "https://www.youtube-nocookie.com/embed/h0e2HAPTGF4",
        image: "/assets/video-01.svg"
    },
    2: {
        id: 2,
        title: "Advanced JavaScript Concepts",
        creator: "FreeCodeCamp",
        category: "tutorials",
        duration: "1:23:45",
        views: "856K",
        shortDesc: "Deep dive into advanced JavaScript programming concepts.",
        longDesc: "Explore advanced JavaScript concepts including closures, prototypes, async/await, and modern ES6+ features. This comprehensive tutorial is designed for developers looking to master JavaScript.",
        topics: ["JavaScript", "Programming", "Web Development", "ES6"],
        embedUrl: "https://www.youtube-nocookie.com/embed/Mus_vwhTCq0",
        image: "/assets/video-02.svg"
    },
    3: {
        id: 3,
        title: "The Science of Climate Change",
        creator: "National Geographic",
        category: "documentaries",
        duration: "52:18",
        views: "2.1M",
        shortDesc: "Scientific exploration of climate change causes and effects.",
        longDesc: "A comprehensive documentary examining the scientific evidence for climate change, its causes, effects on our planet, and potential solutions. Features interviews with leading climate scientists and researchers.",
        topics: ["Climate Change", "Environment", "Science", "Sustainability"],
        embedUrl: "https://www.youtube-nocookie.com/embed/dcYlytyuKsc",
        image: "/assets/video-03.svg"
    },
    4: {
        id: 4,
        title: "How to Build a Professional Website",
        creator: "Web Dev Simplified",
        category: "how-to",
        duration: "2:15:30",
        views: "643K",
        shortDesc: "Step-by-step guide to creating a professional website from scratch.",
        longDesc: "Complete tutorial on building a professional website using modern web technologies. Covers HTML, CSS, JavaScript, responsive design, and deployment strategies.",
        topics: ["Web Development", "HTML", "CSS", "Responsive Design"],
        embedUrl: "https://www.youtube-nocookie.com/embed/D-h8L5hgW-w",
        image: "/assets/video-04.svg"
    },
    5: {
        id: 5,
        title: "Photography Fundamentals",
        creator: "Peter McKinnon",
        category: "tutorials",
        duration: "38:22",
        views: "1.8M",
        shortDesc: "Essential photography techniques for beginners and intermediates.",
        longDesc: "Master the fundamentals of photography including composition, lighting, camera settings, and post-processing techniques. Suitable for both beginners and intermediate photographers.",
        topics: ["Photography", "Visual Arts", "Composition", "Lighting"],
        embedUrl: "https://www.youtube-nocookie.com/embed/V7z7BAZdt2M",
        image: "/assets/video-05.svg"
    },
    6: {
        id: 6,
        title: "Best Productivity Apps 2026 Review",
        creator: "Tech Review Pro",
        category: "reviews",
        duration: "28:47",
        views: "425K",
        shortDesc: "Comprehensive review of the top productivity applications.",
        longDesc: "Detailed review and comparison of the best productivity apps available in 2026. Covers features, pricing, pros and cons, and recommendations for different use cases.",
        topics: ["Productivity", "Apps", "Technology", "Reviews"],
        embedUrl: "https://www.youtube-nocookie.com/embed/example6",
        image: "/assets/video-06.svg"
    },
    7: {
        id: 7,
        title: "The History of Ancient Rome",
        creator: "History Channel",
        category: "documentaries",
        duration: "1:45:12",
        views: "3.2M",
        shortDesc: "Comprehensive documentary on ancient Roman civilization.",
        longDesc: "Explore the rise and fall of the Roman Empire through this detailed documentary. Covers major events, key figures, culture, and lasting impact on modern civilization.",
        topics: ["History", "Ancient Rome", "Civilization", "Culture"],
        embedUrl: "https://www.youtube-nocookie.com/embed/example7",
        image: "/assets/video-07.svg"
    },
    8: {
        id: 8,
        title: "Quantum Physics Explained",
        creator: "MinutePhysics",
        category: "lectures",
        duration: "1:02:35",
        views: "1.5M",
        shortDesc: "Clear explanation of quantum physics principles for beginners.",
        longDesc: "Demystify quantum physics with clear explanations of complex concepts. This lecture makes quantum mechanics accessible to students and curious minds without advanced physics background.",
        topics: ["Physics", "Quantum Mechanics", "Science", "Education"],
        embedUrl: "https://www.youtube-nocookie.com/embed/example8",
        image: "/assets/video-08.svg"
    }
};

// Get all videos as array
function getAllVideos() {
    return Object.values(videoData);
}

// Get video by ID
function getVideoById(id) {
    return videoData[id] || null;
}

// Filter videos by category
function getVideosByCategory(category) {
    if (!category) return getAllVideos();
    return getAllVideos().filter(video => video.category === category);
}

// Search videos
function searchVideos(query) {
    if (!query) return getAllVideos();
    const searchTerm = query.toLowerCase();
    return getAllVideos().filter(video => 
        video.title.toLowerCase().includes(searchTerm) ||
        video.creator.toLowerCase().includes(searchTerm) ||
        video.shortDesc.toLowerCase().includes(searchTerm) ||
        video.topics.some(topic => topic.toLowerCase().includes(searchTerm))
    );
}

// Sort videos
function sortVideos(videos, sortBy) {
    const sorted = [...videos];
    switch (sortBy) {
        case 'views':
            return sorted.sort((a, b) => {
                const aViews = parseFloat(a.views.replace(/[KM]/g, match => match === 'K' ? 'e3' : 'e6'));
                const bViews = parseFloat(b.views.replace(/[KM]/g, match => match === 'K' ? 'e3' : 'e6'));
                return bViews - aViews;
            });
        case 'title':
            return sorted.sort((a, b) => a.title.localeCompare(b.title));
        case 'newest':
        default:
            return sorted.reverse();
    }
}

// Get category counts
function getCategoryCounts() {
    const counts = {};
    getAllVideos().forEach(video => {
        counts[video.category] = (counts[video.category] || 0) + 1;
    });
    return counts;
}

// Render video card
function renderVideoCard(video) {
    return `
        <a href="/video/?id=${video.id}" class="video-card">
            <img src="${video.image}" alt="${video.title}" class="video-thumbnail">
            <div class="video-info">
                <h3 class="video-title">${video.title}</h3>
                <div class="video-creator">${video.creator}</div>
                <div class="video-meta">
                    <span class="video-duration">${video.duration}</span>
                    <span class="video-views">${video.views} views</span>
                </div>
                <span class="video-category">${video.category}</span>
                <p class="video-description">${video.shortDesc}</p>
            </div>
        </a>
    `;
}

// Render video detail
function renderVideoDetail(video) {
    return `
        <div class="video-embed">
            <iframe src="${video.embedUrl}" frameborder="0" allowfullscreen></iframe>
        </div>
        <div class="video-detail-info">
            <h1 class="video-detail-title">${video.title}</h1>
            <div class="video-creator">By ${video.creator}</div>
            <div class="video-meta">
                <span class="video-duration">${video.duration}</span>
                <span class="video-views">${video.views} views</span>
                <span class="video-category">${video.category}</span>
            </div>
            <div class="video-topics">
                ${video.topics.map(topic => `<span class="topic-tag">${topic}</span>`).join('')}
            </div>
            <p>${video.longDesc}</p>
        </div>
        <div class="content-disclaimer">
            Content provided by original creators via public embed.
        </div>
    `;
}

// Get URL parameters
function getURLParameter(name) {
    const urlParams = new URLSearchParams(window.location.search);
    return urlParams.get(name);
}

// Initialize mobile navigation
function initMobileNav() {
    const navToggle = document.querySelector('.nav-toggle');
    const navMenu = document.querySelector('.nav-menu');
    
    if (navToggle && navMenu) {
        navToggle.addEventListener('click', () => {
            navMenu.classList.toggle('active');
        });
    }
}

// Initialize contact form
function initContactForm() {
    const form = document.getElementById('contact-form');
    const message = document.getElementById('form-message');
    
    if (form && message) {
        form.addEventListener('submit', (e) => {
            e.preventDefault();
            
            // Simulate form submission
            message.textContent = 'Thank you for your message! We will get back to you soon.';
            message.className = 'form-message success';
            message.style.display = 'block';
            
            // Reset form
            form.reset();
            
            // Hide message after 5 seconds
            setTimeout(() => {
                message.style.display = 'none';
            }, 5000);
        });
    }
}

// Initialize search and filters
function initFilters() {
    const searchInput = document.getElementById('search-input');
    const categoryFilter = document.getElementById('category-filter');
    const sortFilter = document.getElementById('sort-filter');
    const videosContainer = document.getElementById('all-videos');
    const noResults = document.getElementById('no-results');
    
    if (!videosContainer) return;
    
    function filterAndRenderVideos() {
        const searchQuery = searchInput ? searchInput.value : '';
        const selectedCategory = categoryFilter ? categoryFilter.value : '';
        const sortBy = sortFilter ? sortFilter.value : 'newest';
        
        let videos = getAllVideos();
        
        // Apply search
        if (searchQuery) {
            videos = searchVideos(searchQuery);
        }
        
        // Apply category filter
        if (selectedCategory) {
            videos = videos.filter(video => video.category === selectedCategory);
        }
        
        // Apply sorting
        videos = sortVideos(videos, sortBy);
        
        // Render results
        if (videos.length > 0) {
            videosContainer.innerHTML = videos.map(renderVideoCard).join('');
            if (noResults) noResults.style.display = 'none';
        } else {
            videosContainer.innerHTML = '';
            if (noResults) noResults.style.display = 'block';
        }
    }
    
    // Add event listeners
    if (searchInput) {
        searchInput.addEventListener('input', filterAndRenderVideos);
    }
    
    if (categoryFilter) {
        categoryFilter.addEventListener('change', filterAndRenderVideos);
        
        // Set initial category from URL
        const urlCategory = getURLParameter('category');
        if (urlCategory) {
            categoryFilter.value = urlCategory;
        }
    }
    
    if (sortFilter) {
        sortFilter.addEventListener('change', filterAndRenderVideos);
    }
    
    // Initial render
    filterAndRenderVideos();
}

// Page-specific initialization
function initPage() {
    const path = window.location.pathname;
    
    // Home page
    if (path === '/' || path === '/index/' || path.endsWith('/index.html')) {
        const featuredContainer = document.getElementById('featured-videos');
        if (featuredContainer) {
            const featuredVideos = getAllVideos().slice(0, 6);
            featuredContainer.innerHTML = featuredVideos.map(renderVideoCard).join('');
        }
    }
    
    // Videos page
    else if (path === '/videos/' || path.includes('/videos/')) {
        initFilters();
    }
    
    // Video detail page
    else if (path === '/video/' || path.includes('/video/')) {
        const videoId = parseInt(getURLParameter('id'));
        const video = getVideoById(videoId);
        const detailContainer = document.getElementById('video-detail');
        const notFound = document.getElementById('video-not-found');
        const pageTitle = document.getElementById('page-title');
        
        if (video && detailContainer) {
            detailContainer.innerHTML = renderVideoDetail(video);
            if (pageTitle) {
                pageTitle.textContent = `${video.title} - Premium Video Craft`;
            }
        } else if (notFound) {
            notFound.style.display = 'block';
            if (detailContainer) detailContainer.style.display = 'none';
        }
    }
    
    // Categories page
    else if (path === '/categories/' || path.includes('/categories/')) {
        const counts = getCategoryCounts();
        
        // Update category counts
        Object.keys(counts).forEach(category => {
            const element = document.getElementById(`${category}-count`);
            if (element) {
                const count = counts[category] || 0;
                element.textContent = `${count} video${count !== 1 ? 's' : ''} available`;
            }
        });
    }
    
    // Contact page
    else if (path === '/contact/' || path.includes('/contact/')) {
        initContactForm();
    }
}

// Initialize everything when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
    initMobileNav();
    initPage();
});