:root {
    --bg-color: #050505;
    --sidebar-bg: #0f0f0f;
    --card-bg: #161616;
    --text-primary: #f1f1f1;
    --text-secondary: #aaaaaa;
    --accent: #ff0000;
    /* YouTube Red-ish or just distinct Red */
    --accent-hover: #cc0000;
    --border-color: #2a2a2a;
    --glass: rgba(255, 255, 255, 0.03);
    --border-radius: 12px;
    --transition-speed: 0.2s;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --sidebar-width: 240px;
    --header-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* Layout Structure */
/* Improved Sidebar Scroll */
/* Improved Sidebar Scroll - GRID LAYOUT */
/* Improved Sidebar Scroll - FIXED */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    padding: 1.5rem 1rem;
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Layout: Flex Column */
    display: flex;
    flex-direction: column;

    /* Height: Full Viewport */
    height: 100vh;
    overflow: hidden;
    /* Parent clips children */
}

.sidebar-scroll {
    /* Flex Child: Take all remaining space */
    flex: 1;
    min-height: 0;
    /* Important for preventing overflow out of parent */

    /* Scroll Behavior */
    overflow-y: auto;
    overflow-x: hidden;

    /* Inner Layout: Block (Simple) */
    display: block;

    /* Spacing */
    padding-right: 5px;
    margin-right: -5px;
    padding-bottom: 2rem;
    /* Extra space at bottom of list */

    /* Touch */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* Add spacing for items since we removed flex-gap */
.sidebar-scroll>* {
    margin-bottom: 0.5rem;
    display: block;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 2rem;
    /* width: 100%; removed to prevent overflow with margin-left */
    /* Ensure content doesn't force width */
    min-width: 0;
    transition: margin-left 0.3s ease;
}

/* Sidebar Styles */
/* Global Logo Style */
.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo span {
    color: var(--accent);
}

.sidebar .logo {
    margin-bottom: 2rem;
    padding-left: 0.5rem;
}

.sidebar .logo span {
    color: var(--accent);
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all var(--transition-speed);
    gap: 12px;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(255, 0, 0, 0.1);
    /* Subtle red tint for active */
    color: var(--accent);
    font-weight: 600;
}

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #666;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    padding-left: 1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Overlay for Mobile Sidebar */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 900;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Mobile Toggle */
.menu-toggle {
    display: none;
    /* Hidden on desktop */
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}

/* Search / Header Area */
.search-container {
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
}

.search-form {
    display: flex;
    width: 100%;
    max-width: 600px;
    position: relative;
    gap: 0;
    /* Connected inputs */
}

.search-input {
    width: 100%;
    padding: 12px 20px;
    border-top-left-radius: 24px;
    border-bottom-left-radius: 24px;
    border: 1px solid var(--border-color);
    background: #121212;
    color: #fff;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition-speed);
}

/* Global Input Styles */
input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
    width: 100%;
    padding: 12px 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #121212;
    color: #fff;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition-speed);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
}

.search-input:focus {
    outline: none;
    border-color: #3ea6ff;
    /* YouTube Blue focus */
    z-index: 2;
}

.search-btn {
    padding: 0 24px;
    border-top-right-radius: 24px;
    border-bottom-right-radius: 24px;
    border: 1px solid var(--border-color);
    border-left: none;
    background: #222;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-speed);
}

.search-btn:hover {
    background: #303030;
    color: var(--text-primary);
}

/* Main Grid Layout */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

/* Video Cards */
.card {
    background: transparent;
    /* Cleaner look, no box bg */
    border-radius: var(--border-radius);
    /* Applied to thumb */
    text-decoration: none;
    color: white;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: transform var(--transition-speed);
    position: relative;
}

.card:hover .card-thumb img {
    transform: scale(1.05);
}

.card-thumb {
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    background: #202020;
}

.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.card-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.card-content {
    padding: 0 0.5rem;
}

.card-title {
    font-size: 0.95rem;
    /* Slightly smaller for cleaner list */
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
    line-height: 1.4;

    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    /* Standard property for compatibility */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Player Styles */
.player-container {
    width: 100%;
    background: #000;
    border-radius: var(--border-radius);
    overflow: hidden;
    aspect-ratio: 16/9;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    margin-bottom: 1.5rem;
}

video {
    width: 100%;
    height: 100%;
    display: block;
}

/* Video Page Info */
.video-title {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.video-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.video-info {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-top: 1rem;
}

.subtitle-controls {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    color: var(--text-secondary);
}

@media (max-width: 900px) {
    .video-info {
        flex-direction: column;
    }

    .video-info>div {
        width: 100%;
    }
}

/* Buttons */
.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-speed);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 50vh;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Error Message */
.error-msg {
    background: rgba(255, 68, 68, 0.1);
    color: #ff6b6b;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 68, 68, 0.2);
    text-align: center;
}

/* Responsive / Mobile Styles */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        width: 250px;
        /* Standard mobile drawer width */
        background: #111;
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .menu-toggle {
        display: block;
    }

    /* Mobile Header Layout */
    .header-mobile-wrapper {
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    /* Adjust Grid for Mobile */
    .grid {
        grid-template-columns: repeat(2, 1fr);
        /* 2 Columns on mobile is standard now */
        gap: 10px;
    }

    /* Allow single column on very small screens */
    @media (max-width: 480px) {
        .grid {
            grid-template-columns: 1fr;
        }
    }

    .card-thumb {
        border-radius: 8px;
    }

    /* ... existing mobile styles ... */
    .search-container {
        margin-bottom: 1rem;
    }
}

/* Hero Slider */
.hero-slider {
    position: relative;
    width: 100%;
    height: 400px;
    /* Desktop height */
    overflow: hidden;
    border-radius: var(--border-radius);
    margin-bottom: 3rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.slider-wrapper {
    display: flex;
    transition: transform 0.5s ease-in-out;
    height: 100%;
}

.slide {
    min-width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    position: relative;
    cursor: pointer;
}

.slide::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.2) 60%, rgba(0, 0, 0, 0.4) 100%);
}

.slide-content {
    position: absolute;
    bottom: 0;
    left: 0;
    padding: 3rem;
    width: 100%;
    color: white;
}

.slide-content h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.play-btn {
    padding: 10px 24px;
    background: var(--accent);
    border: none;
    color: white;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.2s;
}

.play-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.slider-dots {
    position: absolute;
    bottom: 20px;
    right: 30px;
    display: flex;
    gap: 10px;
    z-index: 10;
}

.dot {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s;
}

.dot.active {
    background: var(--accent);
    transform: scale(1.2);
}

@media (max-width: 768px) {
    .hero-slider {
        height: 250px;
        margin-bottom: 2rem;
        border-radius: 0;
        margin-left: -1rem;
        margin-right: -1rem;
        width: calc(100% + 2rem);
    }

    .slide-content {
        padding: 1.5rem;
    }

    .slide-content h2 {
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
    }
}

/* Playlist Headers */
.playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.playlist-name {
    font-size: 2rem;
    font-weight: 700;
}

/* Utility Classes */
.mobile-only {
    display: none !important;
}

@media (max-width: 900px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }
}

/* --- Improved Search Bar Styles --- */
.search-wrapper {
    flex: 1;
    margin: 0 1rem;
    position: relative;
    max-width: 500px;
    /* Limit width on desktop */
    display: flex;
    align-items: center;
}

.search-wrapper form {
    width: 100%;
    position: relative;
    /* Anchor for the icon */
    display: flex;
    align-items: center;
}

.search-input-public {
    width: 100%;
    padding: 10px 16px 10px 42px;
    /* Space for icon */
    border-radius: 50px;
    border: 1px solid #333;
    background: #1a1a1a;
    color: #fff;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.search-input-public:focus {
    outline: none;
    border-color: var(--accent);
    background: #252525;
    box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.15);
    /* Soft glow */
}

.search-icon-public {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #777;
    pointer-events: none;
    z-index: 5;
    /* Ensure it stays on top */
}

/* Header Adjustments for Search */
.header-mobile-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    /* Allow wrapping on mobile */
    gap: 10px;
}

/* Mobile Specific Overrides */
@media (max-width: 768px) {
    .header-mobile-wrapper {
        padding-bottom: 0.5rem;
        /* Space for search */
    }

    .search-wrapper {
        order: 3;
        /* Push to bottom on mobile */
        width: 100%;
        /* Full width */
        max-width: 100%;
        margin: 0.5rem 0 0 0;
        /* Add top margin */
    }

    .search-input-public {
        padding-top: 12px;
        padding-bottom: 12px;
        font-size: 1rem;
        /* Better touch target */
        background: #151515;
        /* Slightly darker on mobile */
    }
}