/* ===== CSS Variables ===== */
:root {
    --primary: #ef4444;
    --primary-dark: #dc2626;
    --primary-glow: rgba(239, 68, 68, 0.4);
    --accent: #8B5CF6;
    --bg-dark: #0a0a0f;
    --bg-card: rgba(30, 30, 40, 0.8);
    --bg-glass: rgba(20, 20, 30, 0.9);
    --text-primary: #FFFFFF;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border-color: rgba(255, 255, 255, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: all 0.2s ease;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
}

ul {
    list-style: none;
}

/* ===== Animated Background ===== */
.animated-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.3;
    animation: float 30s ease-in-out infinite;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: var(--primary);
    top: -200px;
    right: -150px;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: var(--accent);
    bottom: -150px;
    left: -150px;
    animation-delay: -15s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    50% {
        transform: translate(-40px, 40px) scale(1.1);
    }
}

/* ===== Top Bar ===== */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
}

.logo {
    font-size: 1.4rem;
    font-weight: 800;
    flex-shrink: 0;
}

.logo-skip {
    color: var(--text-primary);
}

.logo-vids {
    color: var(--primary);
}

.search-bar {
    flex: 1;
    display: flex;
    max-width: 600px;
    gap: 0.5rem;
}

.search-bar input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.search-bar input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

.load-btn {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    border-radius: var(--radius-md);
    letter-spacing: 0.5px;
    transition: var(--transition);
    box-shadow: 0 4px 15px var(--primary-glow);
}

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

.load-btn:active {
    transform: scale(0.98);
}

.nav-pills {
    display: flex;
    gap: 0.5rem;
}

.nav-pill {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.nav-pill:hover,
.nav-pill.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* ===== Main Content ===== */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* ===== Player Section ===== */
.player-section {
    margin-bottom: 2rem;
}

.player-container {
    max-width: 800px;
    margin: 0 auto;
}

.video-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    background: #000;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.video-wrapper.audio-mode {
    padding-bottom: 15%;
    /* Shrink for audio mode */
}

.video-wrapper.audio-mode #ytPlayer {
    opacity: 0;
    pointer-events: none;
}

.video-wrapper iframe,
.video-wrapper>div:first-child {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ===== Controls Overlay ===== */
.controls-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through empty areas if needed, but buttons need pointer-events: auto */
}

/* Enable clicks on buttons inside the overlay */
.controls-overlay>* {
    pointer-events: auto;
}

/* Full cover click layer for Play/Pause */
.click-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    cursor: pointer;
    /* Optional: background: transparent; */
}

.video-wrapper:hover .controls-overlay,
.video-wrapper.audio-mode .controls-overlay,
.video-wrapper.paused .controls-overlay {
    /* Show controls when paused too */
    opacity: 1;
}

.progress-section {
    width: 100%;
    padding: 0 0.5rem 0.5rem;
}

/* Custom Range Slider */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
}

input[type=range]:focus {
    outline: none;
}

/* Slider Track */
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

input[type=range]::-moz-range-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* Slider Thumb */
input[type=range]::-webkit-slider-thumb {
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -4px;
    transition: transform 0.1s;
}

input[type=range]::-moz-range-thumb {
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: transform 0.1s;
}

input[type=range]:hover::-webkit-slider-thumb {
    transform: scale(1.3);
}

/* Volume Slider Specifics */
.volume-slider {
    width: 80px;
    margin-left: 8px;
}

.controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.left-controls,
.right-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.volume-container {
    display: flex;
    align-items: center;
    margin-left: 0.5rem;
}

.ctrl-spacer {
    flex: 1;
}

.ctrl-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    /* Prevent squeezing */
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: white;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.ctrl-btn svg {
    width: 20px;
    height: 20px;
}

.play-pause-btn {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    /* Force circle */
    background: var(--primary);
    box-shadow: 0 4px 15px var(--primary-glow);
}

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

.play-pause-btn svg {
    width: 24px;
    height: 24px;
}

.bg-play-btn.active {
    background: var(--accent);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.ctrl-btn.saved svg {
    fill: var(--primary);
    stroke: var(--primary);
}

/* Audio Mode Active State */
#audioModeBtn.active {
    background: var(--primary);
    color: white;
}

#loopBtn.active {
    color: var(--primary);
    background: rgba(239, 68, 68, 0.15);
    box-shadow: 0 0 0 1px var(--primary);
}

.video-title {
    margin-top: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

/* ===== Section Titles ===== */
.section-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* ===== Video Grid ===== */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
}

.video-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
}

.video-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.2);
}

.video-thumb {
    position: relative;
    aspect-ratio: 16/9;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.play-overlay {
    position: absolute;
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.video-card:hover .play-overlay {
    opacity: 1;
    transform: scale(1.1);
}

.play-overlay svg {
    width: 22px;
    height: 22px;
}

.duration {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.85);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.video-meta {
    padding: 0.75rem;
}

.video-meta h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-meta p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.empty-message {
    color: var(--text-muted);
    font-style: italic;
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-glass);
    border: 1px solid var(--primary);
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: var(--transition);
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .top-bar {
        flex-wrap: wrap;
        padding: 0.75rem 1rem;
        gap: 0.75rem;
    }

    .logo {
        font-size: 1.2rem;
    }

    .search-bar {
        order: 3;
        flex: 0 0 100%;
        max-width: 100%;
    }

    .nav-pills {
        margin-left: auto;
    }

    .nav-pill {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .main-content {
        padding: 1rem;
    }

    .video-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.75rem;
    }

    .video-meta {
        padding: 0.5rem;
    }

    .video-meta h4 {
        font-size: 0.75rem;
    }

    .video-meta p {
        font-size: 0.65rem;
    }

    .controls-overlay {
        opacity: 1;
        padding: 0.75rem;
    }

    .volume-slider {
        width: 60px;
    }

    .ctrl-btn {
        width: 36px;
        height: 36px;
    }

    .play-pause-btn {
        width: 44px;
        height: 44px;
    }

    .section-title {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .video-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .load-btn {
        padding: 0.75rem 1rem;
        font-size: 0.8rem;
    }
}

/* ===== SLIDER OVERRIDES & NEW STYLES ===== */
/* Remove default appearance */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
}

/* Slider Track */
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

input[type=range]::-moz-range-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

/* Slider Thumb */
input[type=range]::-webkit-slider-thumb {
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -5px;
    /* Center thumb on track */
    transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 0 10px var(--primary-glow);
}

input[type=range]::-moz-range-thumb {
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 0 10px var(--primary-glow);
}

input[type=range]:hover::-webkit-slider-thumb {
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--primary);
}

/* Active State for Buttons */
#loopBtn.active {
    color: var(--primary);
    background: rgba(220, 38, 38, 0.2);
    box-shadow: 0 0 0 1px var(--primary);
}

.active-mode {
    background: var(--primary) !important;
    color: white !important;
}

/* ===== USER REQUESTED FIXES ===== */

/* Blur Removed as per request */
.video-wrapper.paused iframe {
    filter: none !important;
}

/* Ensure Audio Mode keeps exact 16:9 size */
.video-wrapper.audio-mode {
    background: #000;
    aspect-ratio: 16/9;
    /* Force 16:9 if padding hack fails or to be robust */
}

/* Ensure controls are visible when paused */
.video-wrapper.paused .controls-overlay {
    opacity: 1;
    background: rgba(0, 0, 0, 0.4);
    /* Darken slightly more */
}

/* Hide Volume Slider on Mobile */
@media (max-width: 768px) {
    .volume-container {
        display: none !important;
    }
}

/* Ensure Click Layer is always clickable and on top of iframe */
.click-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    /* Above iframe (z-0/1), below controls (z-10) */
    cursor: pointer;
    background: transparent;
    /* Explicit transparent background */
    pointer-events: auto !important;
}

/* ===== REDESIGNED CONTROLS ===== */

/* Top Right Fullscreen Button */
.fs-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 20;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0;
    pointer-events: auto;
}

.video-wrapper:hover .fs-btn,
.video-wrapper.paused .fs-btn {
    opacity: 1;
}

.fs-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.fs-btn svg {
    width: 24px;
    height: 24px;
}

/* Prettier Play/Pause Button */
.play-pause-btn {
    /* Reset old styles */
    background: rgba(255, 255, 255, 0.15) !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.3s ease !important;
}

.play-pause-btn:hover {
    background: var(--primary) !important;
    /* Only red on hover */
    border-color: var(--primary) !important;
    transform: scale(1.1) !important;
    box-shadow: 0 0 20px var(--primary-glow) !important;
}

.play-pause-btn svg {
    /* Ensure icon size is good */
    width: 28px;
    height: 28px;
    fill: white;
}

/* ===== NEW TOP CONTROLS ===== */
.player-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.bg-play-pill {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    background: rgba(255, 255, 255, 0.08);
    /* Subtle background */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.bg-play-pill:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.bg-play-pill.active {
    background: rgba(34, 197, 94, 0.2);
    /* Green tint */
    border-color: #22c55e;
    color: #22c55e;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.25);
}

.bg-play-pill .pill-icon svg {
    width: 20px;
    height: 20px;
}

/* ===== FIXES FOR MOBILE & AUDIO MODE ===== */

/* 1. Mobile Volume Control: Show Button, Hide Slider */
@media (max-width: 768px) {
    .volume-container {
        display: flex !important;
        /* Override previous hide */
        width: auto !important;
    }

    .volume-slider {
        display: none !important;
        /* Hide only the slider */
    }

    .vol-btn {
        margin-right: 0 !important;
    }
}

/* 2. Audio Mode Fixes */
/* Ensure wrapper has background and height */
.video-wrapper.audio-mode {
    background: #111;
}

/* Hide iframe but keep layout */
.video-wrapper.audio-mode iframe {
    opacity: 0;
    pointer-events: none;
}

/* Ensure controls overlay is fully visible */
.video-wrapper.audio-mode .controls-overlay {
    opacity: 1;
    background: rgba(0, 0, 0, 0.2);
}

/* Ensure progress bar is visible and formatted */
.video-wrapper.audio-mode .progress-section {
    display: block !important;
    opacity: 1 !important;
    margin-bottom: 2rem;
    /* Give space */
}

/* Audio Visualizer Placeholder */
.video-wrapper.audio-mode::after {
    content: '';
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    color: var(--primary);
    opacity: 0.5;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.5;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 0.8;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.5;
    }
}

/* Fix for Audio Mode Slider on Mobile: Keep standard 16:9 ratio, don't bloat height */
@media (max-width: 768px) {
    .video-wrapper.audio-mode {
        min-height: unset !important;
        /* Revert bloat */
        display: block;
        /* Standard layout */
    }

    /* Position progress bar in visible area */
    .video-wrapper.audio-mode .progress-section {
        position: absolute;
        bottom: 35% !important;
        left: 5% !important;
        width: 90% !important;
        z-index: 9999 !important;
        opacity: 1 !important;
    }
}

/* ===== DIV CROPPING (HIDE YOUTUBE UI) ===== */
.crop-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    /* Let clicks pass to click-layer? No, we need click-layer to catch them. */
}

.crop-shift {
    margin-top: -51%;
    margin-bottom: -20%;
}

.crop-sizer {
    position: relative;
    padding-bottom: 128.25%;
    /* Needs to be padding-bottom for aspect ratio trick if height is 0 */
    height: 0;
}

.crop-sizer iframe,
.crop-sizer #ytPlayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 124%;
    pointer-events: none;
    /* User shouldn't interact with internal YouTube controls anyway */
}