/* ========================================
   CSS Variables & Reset
   ======================================== */
:root {
    /* Colors */
    --bg-primary: #0a0a0a;
    --bg-secondary: #121212;
    --bg-card: rgba(18, 18, 18, 0.8);
    --bg-input: rgba(255, 255, 255, 0.05);

    --youtube-red: #FF0000;
    --youtube-red-hover: #cc0000;
    --youtube-red-glow: rgba(255, 0, 0, 0.3);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);

    --border-color: rgba(255, 255, 255, 0.1);
    --error-color: #ff4757;
    --success-color: #2ed573;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
    --transition-slow: 500ms ease;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px var(--youtube-red-glow);
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-input: rgba(0, 0, 0, 0.05);

    --youtube-red-glow: rgba(255, 0, 0, 0.2);

    --text-primary: #1a1a1a;
    --text-secondary: rgba(0, 0, 0, 0.7);
    --text-muted: rgba(0, 0, 0, 0.5);

    --border-color: rgba(0, 0, 0, 0.1);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.2);
}

/* Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ========================================
   Background Effects
   ======================================== */
.background-glow {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--youtube-red-glow) 0%, transparent 70%);
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
    animation: pulse-glow 8s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.3;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 0.5;
    }
}

/* ========================================
   Container & Card
   ======================================== */
.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 480px;
    padding: var(--spacing-md);
}

.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-lg);
    animation: slide-up 0.6s ease-out;
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   Header
   ======================================== */
/* Header */
.header {
    text-align: left;
    /* Align to left to avoid overlap */
    margin-bottom: var(--spacing-lg);
    position: relative;
    padding-right: 120px;
    /* Reserve space for fixed controls */
}

/* Header Controls Container - Fixed to Top Right Window */
.header-controls {
    position: fixed;
    top: 20px;
    right: 30px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 2000;
}

/* Theme Toggle Button (Updated) */
.theme-toggle {
    position: relative;
    top: auto;
    right: auto;
    width: 40px;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
    color: var(--text-secondary);
}

/* Language Selector */
.lang-selector {
    position: relative;
}

.lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition-normal);
}

.lang-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.lang-btn .chevron-icon {
    width: 16px;
    height: 16px;
    transition: transfrom 0.2s ease;
}

.lang-selector.open .chevron-icon {
    transform: rotate(180deg);
}

.lang-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 9999;
    /* Ensure it's on top of everything */
    background: rgba(18, 18, 18, 0.7);
    /* More translucent for real frosted look */
    backdrop-filter: blur(16px);
    /* Stronger blur */
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    /* Stronger shadow */
    padding: 6px;
    min-width: 150px;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.lang-menu:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    text-align: left;
    transition: background-color 0.2s;
}

.lang-option:hover {
    background: var(--hover-bg);
}

.lang-option.active {
    color: var(--accent-color);
    background: rgba(255, 0, 0, 0.05);
}

.lang-flag {
    font-size: 1.2em;
}

.theme-toggle:hover {
    background: rgba(255, 0, 0, 0.1);
    border-color: var(--youtube-red);
    color: var(--youtube-red);
    transform: rotate(15deg);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    transition: var(--transition-normal);
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .moon-icon {
    display: none;
}

.logo {
    display: block;
    /* Allow block layout for title */
    margin-bottom: var(--spacing-xs);
    /* Logo icon will be absolute */
}

.youtube-icon {
    position: absolute;
    top: 60px;
    /* Below the fixed header controls */
    right: 0;
    width: 80px;
    height: 80px;
    color: var(--youtube-red);
    animation: icon-bounce 2s ease infinite;
    filter: drop-shadow(0 4px 10px var(--youtube-red-glow));
}

@keyframes icon-bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 400;
}

/* ========================================
   Input Section
   ======================================== */
.input-section {
    margin-bottom: var(--spacing-md);
}

.input-wrapper {
    position: relative;
}

.url-input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-sm) var(--spacing-sm) 48px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition-normal);
    outline: none;
}

.url-input::placeholder {
    color: var(--text-muted);
}

.url-input:focus {
    border-color: var(--youtube-red);
    background: rgba(255, 0, 0, 0.05);
    box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.1);
}

.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
    transition: var(--transition-normal);
}

.url-input:focus+.input-icon,
.input-wrapper:has(.url-input:focus) .input-icon {
    color: var(--youtube-red);
}

/* Clear Button */
.clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
    opacity: 0;
    visibility: hidden;
    padding: 0;
}

.clear-btn svg {
    width: 14px;
    height: 14px;
}

.clear-btn:hover {
    background: rgba(255, 71, 87, 0.2);
    color: var(--error-color);
}

.clear-btn.visible {
    opacity: 1;
    visibility: visible;
}

.url-input:not(:placeholder-shown)~.clear-btn {
    opacity: 1;
    visibility: visible;
}

.hint {
    margin-top: var(--spacing-xs);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

.controls-row {
    margin-top: var(--spacing-sm);
    display: flex;
    justify-content: flex-end;
}

.quality-select {
    padding: 6px 12px;
    padding-right: 32px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-normal);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
}

.quality-select:hover {
    border-color: var(--text-muted);
}

.quality-select:focus {
    border-color: var(--youtube-red);
    box-shadow: 0 0 0 2px rgba(255, 0, 0, 0.1);
}

.quality-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ========================================
   Download Button
   ======================================== */
.download-btn {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(135deg, var(--youtube-red) 0%, #cc0000 100%);
    border: none;
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    transition: var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.download-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255, 255, 255, 0.1) 50%, transparent 100%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.download-btn:hover::before {
    transform: translateX(100%);
}

.download-btn:hover {
    background: linear-gradient(135deg, #ff3333 0%, var(--youtube-red) 100%);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.download-btn:active {
    transform: translateY(0);
}

.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.download-btn:disabled:hover {
    box-shadow: none;
}

.btn-icon {
    width: 20px;
    height: 20px;
    transition: var(--transition-normal);
}

/* Removed separate icon transform - icon now moves with button */

/* Loading State */
.download-btn.loading .btn-text,
.download-btn.loading .btn-icon {
    opacity: 0;
}

.btn-loader {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    position: absolute;
}

.download-btn.loading .btn-loader {
    display: block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   Search Results
   ======================================== */
.search-results {
    margin-top: var(--spacing-md);
    animation: fade-in 0.3s ease;
}

.search-results.hidden {
    display: none;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-results-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
    text-align: center;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    max-height: 350px;
    overflow-y: auto;
    padding-right: 4px;
}

.results-list::-webkit-scrollbar {
    width: 6px;
}

.results-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.results-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.result-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-normal);
}

.result-item:hover {
    background: rgba(255, 0, 0, 0.1);
    border-color: var(--youtube-red);
    transform: translateX(4px);
}

/* Preview Button */
.preview-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: var(--youtube-red);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
    position: relative;
}

.preview-btn:hover {
    background: var(--youtube-red-hover);
    transform: scale(1.1);
    box-shadow: 0 0 20px var(--youtube-red-glow);
}

.preview-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.preview-btn .pause-icon {
    display: none;
}

.preview-btn.playing {
    background: var(--success-color);
}

.preview-btn.playing .music-icon {
    display: none;
}

.preview-btn.playing .pause-icon {
    display: block;
}

.result-thumbnail {
    width: 70px;
    min-width: 70px;
    height: 40px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--bg-secondary);
}

.result-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.result-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.result-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.result-channel {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-duration {
    background: rgba(0, 0, 0, 0.6);
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    white-space: nowrap;
}

/* ========================================
   Status Message
   ======================================== */
.status-message {
    margin-top: var(--spacing-md);
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    text-align: center;
    opacity: 0;
    transform: translateY(-10px);
    transition: var(--transition-normal);
}

.status-message.visible {
    opacity: 1;
    transform: translateY(0);
}

.status-message.error {
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid rgba(255, 71, 87, 0.3);
    color: var(--error-color);
}

.status-message.success {
    background: rgba(46, 213, 115, 0.1);
    border: 1px solid rgba(46, 213, 115, 0.3);
    color: var(--success-color);
}

.status-message.info {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

/* ========================================
   Progress Section
   ======================================== */
.progress-section {
    margin-top: var(--spacing-md);
    transition: var(--transition-normal);
}

.progress-section.hidden {
    display: none;
}

.progress-bar {
    height: 6px;
    background: var(--bg-input);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--youtube-red) 0%, #ff3333 100%);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.progress-text {
    margin-top: var(--spacing-xs);
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

/* ========================================
   Footer
   ======================================== */
.footer {
    margin-top: var(--spacing-md);
    text-align: center;
}

.footer p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.footer strong {
    color: var(--youtube-red);
    font-weight: 500;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    .card {
        padding: 20px 16px;
        border-radius: 16px;
    }

    /* Header Controls - Separate row for mobile */
    .header-controls {
        position: relative;
        /* Not absolute anymore */
        top: auto;
        right: auto;
        justify-content: flex-end;
        /* Align right */
        width: 100%;
        margin-bottom: 10px;
    }

    .lang-btn {
        padding: 0 8px;
        height: 32px;
        font-size: 0.8rem;
    }

    .theme-toggle {
        width: 32px;
        height: 32px;
    }

    .theme-toggle svg {
        width: 16px;
        height: 16px;
    }

    .header {
        display: flex;
        flex-direction: column;
        padding-right: 0;
        margin-bottom: 20px;
        text-align: center;
    }

    .logo {
        display: flex;
        justify-content: center;
        /* Center logo and title */
        align-items: center;
        gap: 10px;
        margin-bottom: 4px;
        position: relative;
    }

    .logo h1 {
        font-size: 1.5rem;
        text-align: center;
        width: auto;
    }

    .youtube-icon {
        position: relative;
        /* Normal flow */
        top: auto;
        right: auto;
        width: 36px;
        height: 36px;
    }

    .subtitle {
        text-align: center;
        font-size: 0.85rem;
    }

    /* Queue Panel - Mobile - Strict Centering */
    .queue-panel {
        position: fixed;
        /* Ensure fixed positioning */
        top: 20px !important;
        /* Position near top, but below header/controls */
        left: 50% !important;
        bottom: auto !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        /* Center horizontally only */
        width: 90%;
        max-width: 320px;
        margin: 0;
        z-index: 20000 !important;
        /* Force on top of everything */
        display: block;
        /* Ensure it's not hidden by layout quirks */
    }

    /* Search Result - Compact View */
    .result-item {
        padding: 8px;
        gap: 10px;
    }

    .preview-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
    }

    .preview-btn svg {
        width: 12px;
        height: 12px;
    }

    .result-thumbnail {
        width: 50px;
        min-width: 50px;
        height: 50px;
        /* Square looks better small */
    }

    .result-info {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .result-title {
        font-size: 0.9rem;
        /* Larger text */
        line-height: 1.2;
        margin-bottom: 4px;
        -webkit-line-clamp: 2;
        /* Allow 2 lines */
    }

    .result-meta {
        font-size: 0.75rem;
    }

    .favorite-btn {
        padding: 4px;
    }

    .favorite-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* ========================================
   Accessibility
   ======================================== */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard users */
.url-input:focus-visible,
.download-btn:focus-visible {
    outline: 2px solid var(--youtube-red);
    outline-offset: 2px;
}

/* ========================================
   Confetti Animation
   ======================================== */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 0;
    animation: confetti-fall 3s ease-out forwards;
}

.confetti-piece.circle {
    border-radius: 50%;
}

.confetti-piece.square {
    border-radius: 2px;
}

@keyframes confetti-fall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg) scale(0.5);
    }
}

/* ========================================
   Success Checkmark Animation
   ======================================== */
.success-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999;
    pointer-events: none;
    animation: success-pop 0.6s ease-out forwards;
}

.success-checkmark {
    width: 80px;
    height: 80px;
    background: var(--success-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 40px rgba(46, 213, 115, 0.5);
}

.success-checkmark svg {
    width: 40px;
    height: 40px;
    stroke: white;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.success-checkmark svg path {
    stroke-dasharray: 50;
    stroke-dashoffset: 50;
    animation: checkmark-draw 0.4s ease-out 0.2s forwards;
}

@keyframes success-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }

    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }

    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes checkmark-draw {
    to {
        stroke-dashoffset: 0;
    }
}

/* Fade out animation for cleanup */
.success-overlay.fade-out {
    animation: fade-out 0.5s ease-out forwards;
}

@keyframes fade-out {
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* ========================================
   Playlist Selector
   ======================================== */
.playlist-selector {
    margin-top: var(--spacing-md);
    animation: fade-in 0.3s ease;
}

.playlist-selector.hidden {
    display: none;
}

.playlist-header {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-sm);
}

.playlist-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
}

.playlist-actions {
    display: flex;
    justify-content: center;
    gap: var(--spacing-xs);
}

.select-btn {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-normal);
}

.select-btn:hover {
    background: rgba(255, 0, 0, 0.1);
    border-color: var(--youtube-red);
    color: var(--youtube-red);
}

.playlist-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    max-height: 350px;
    overflow-y: auto;
    padding-right: 4px;
    margin-bottom: var(--spacing-sm);
}

.playlist-list::-webkit-scrollbar {
    width: 6px;
}

.playlist-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.playlist-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.playlist-item {
    display: flex;
    align-items: center;
    gap: 8px;
    /* Compact gap */
    padding: 6px;
    /* Compact padding */
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-normal);
}

.playlist-item:hover {
    background: rgba(255, 0, 0, 0.05);
    border-color: rgba(255, 0, 0, 0.3);
}

.playlist-item.selected {
    background: rgba(255, 0, 0, 0.1);
    border-color: var(--youtube-red);
}

.playlist-checkbox {
    width: 16px;
    /* Compact checkbox */
    height: 16px;
    min-width: 16px;
    accent-color: var(--youtube-red);
    cursor: pointer;
}

.playlist-thumbnail {
    width: 44px;
    /* Compact thumbnail */
    min-width: 44px;
    height: 44px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--bg-secondary);
}

.playlist-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.playlist-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.1;
    /* Tighter line height */
}

.playlist-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.playlist-channel {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-duration {
    background: rgba(0, 0, 0, 0.6);
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    white-space: nowrap;
}

.download-selected-btn {
    margin-top: var(--spacing-sm);
}

.download-selected-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================
   Download History
   ======================================== */
.history-section {
    margin-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    padding-top: var(--spacing-md);
}

.history-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-normal);
}

.history-toggle:hover {
    background: rgba(255, 0, 0, 0.05);
    border-color: rgba(255, 0, 0, 0.3);
    color: var(--text-primary);
}

.history-toggle .history-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.history-toggle .chevron-icon {
    width: 16px;
    height: 16px;
    margin-left: auto;
    transition: transform var(--transition-normal);
}

.history-toggle.open .chevron-icon {
    transform: rotate(180deg);
}

.history-count {
    background: var(--youtube-red);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    min-width: 24px;
    text-align: center;
}

.history-content {
    margin-top: var(--spacing-sm);
    animation: fade-in 0.3s ease;
}

.history-content.hidden {
    display: none;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    max-height: 300px;
    overflow-y: auto;
    padding-right: 4px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-normal);
}

.history-item:hover {
    background: rgba(255, 0, 0, 0.1);
    border-color: var(--youtube-red);
    transform: translateX(4px);
}

.history-thumbnail {
    width: 50px;
    min-width: 50px;
    height: 28px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--bg-secondary);
}

.history-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.history-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.7rem;
    color: var(--text-muted);
}

.history-date {
    white-space: nowrap;
}

.history-download-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    background: var(--youtube-red);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
}

.history-download-btn:hover {
    background: var(--youtube-red-hover);
    transform: scale(1.1);
}

.history-download-btn svg {
    width: 14px;
    height: 14px;
    stroke: white;
}

.clear-history-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-normal);
}

.clear-history-btn:hover {
    background: rgba(255, 71, 87, 0.1);
    border-color: var(--error-color);
    color: var(--error-color);
}

.clear-history-btn svg {
    width: 14px;
    height: 14px;
}

.history-empty {
    text-align: center;
    padding: var(--spacing-md);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ========================================
   Favorites Section & Buttons
   ======================================== */
.favorite-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
}

.favorite-btn:hover {
    color: var(--youtube-red);
    background: rgba(255, 0, 0, 0.1);
    transform: scale(1.1);
}

.favorite-btn.active {
    color: var(--youtube-red);
}

.favorite-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    transition: all 0.3s ease;
}

.favorite-btn.active svg {
    fill: currentColor;
}

/* Adjustments for different contexts */
.result-item .favorite-btn,
.playlist-item .favorite-btn {
    margin-right: var(--spacing-xs);
    flex-shrink: 0;
}

.history-item .favorite-btn {
    margin-right: var(--spacing-xs);
}


.result-item {
    gap: var(--spacing-sm);
}

.load-more-container {
    display: flex;
    justify-content: center;
    margin-top: var(--spacing-md);
    padding-bottom: var(--spacing-md);
}

.load-more-btn {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition-normal);
}

.load-more-btn:hover {
    background-color: var(--hover-bg);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* ========================================
   Floating Queue Panel
   ======================================== */
.queue-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 320px;
    z-index: 10000;
    /* Ensure on top of header (2000) and everything else */
    pointer-events: none;
    /* Let clicks pass through empty areas */
}

.queue-panel.hidden {
    display: none;
}

.active-downloads {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    /* Space for the stack below */
    pointer-events: auto;
}

/* Base Card Style */
.queue-card {
    background: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

/* Animations */
@keyframes slide-in-right {
    from {
        transform: translateX(100%) scale(0.8);
        opacity: 0;
    }

    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

@keyframes pop-out {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0);
        opacity: 0;
    }
}

@keyframes stack-up {
    from {
        transform: translateY(20px) scale(0.9);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.queue-card.entering {
    animation: slide-in-right 0.5s forwards;
}

.queue-card.leaving {
    animation: pop-out 0.4s forwards;
}

/* Content Layout */
.q-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.q-thumb {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.q-info {
    flex: 1;
    min-width: 0;
}

.q-title {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #ffffff;
}

.q-status {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
}

/* Cancel Button */
.q-cancel-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: rgba(255, 71, 87, 0.15);
    border: 1px solid rgba(255, 71, 87, 0.3);
    border-radius: 8px;
    color: var(--error-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    margin-left: auto;
}

.q-cancel-btn svg {
    width: 18px;
    height: 18px;
}

.q-cancel-btn:hover {
    background: rgba(255, 71, 87, 0.3);
    color: var(--error-color);
    transform: scale(1.1);
}

.q-cancel-btn:active {
    transform: scale(0.95);
}

.q-cancel-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Cancelled state animation */
.queue-card.cancelled {
    animation: fade-out-cancelled 0.3s forwards;
}

@keyframes fade-out-cancelled {
    to {
        opacity: 0;
        transform: translateX(-20px) scale(0.9);
    }
}

/* Progress Bar */
.q-progress-bg {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.q-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--youtube-red), #ff4757);
    border-radius: 2px;
    transition: width 0.3s ease, background-color 0.3s ease;
}

.q-progress-fill.completed {
    background: var(--success-color);
    box-shadow: 0 0 10px var(--success-color);
}

/* ========================================
   Stacked Effect for Pending
   ======================================== */
.pending-queue {
    position: relative;
    height: 60px;
    /* Space reserved for the stack */
    margin-top: -10px;
    pointer-events: auto;
}

.queue-card.pending {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    /* Stack look */
    background: rgba(30, 30, 30, 0.95);
    border-color: rgba(255, 255, 255, 0.05);
    transform-origin: center bottom;
    transition: all 0.5s ease;
}

/* The first 3 pending items get special stacking styles via JS or nth-child logic if possible.
   Since implementation will be dynamic, we'll use CSS classes like .pending-1, .pending-2 */

.queue-card.pending.p-1 {
    transform: translateY(0) scale(0.95);
    z-index: 3;
    opacity: 0.9;
}

.queue-card.pending.p-2 {
    transform: translateY(10px) scale(0.9);
    z-index: 2;
    opacity: 0.7;
}

.queue-card.pending.p-3 {
    transform: translateY(20px) scale(0.85);
    z-index: 1;
    opacity: 0.5;
}

.queue-card.pending.hidden-stack {
    opacity: 0;
    transform: translateY(30px) scale(0.8);
    pointer-events: none;
}


/* Global Utilities */
.hidden {
    display: none !important;
}