/* ============================================
   YT Stream Player — Design System & Styles
   ============================================ */

:root {
    /* Color Palette */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --bg-glass: rgba(18, 18, 26, 0.85);
    --bg-player: rgba(12, 12, 18, 0.95);

    --text-primary: #f0f0f5;
    --text-secondary: #8b8ba0;
    --text-muted: #5a5a70;

    --accent-purple: #a78bfa;
    --accent-pink: #f472b6;
    --accent-blue: #60a5fa;
    --accent-gradient: linear-gradient(135deg, #a78bfa 0%, #f472b6 100%);
    --accent-gradient-subtle: linear-gradient(135deg, rgba(167,139,250,0.15) 0%, rgba(244,114,182,0.15) 100%);

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 64px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 30px rgba(167,139,250,0.15);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    --player-height: 88px;
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    line-height: 1.5;
    padding-top: env(safe-area-inset-top);
}

button {
    font-family: var(--font);
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    outline: none;
}

input {
    font-family: var(--font);
    outline: none;
    border: none;
}

img {
    display: block;
    max-width: 100%;
}

.hidden {
    display: none !important;
}

/* ============================================
   Background Orbs
   ============================================ */

.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.3;
    pointer-events: none;
    z-index: 0;
    animation: float 20s ease-in-out infinite;
}

.bg-orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #a78bfa 0%, transparent 70%);
    top: -150px;
    right: -100px;
    animation-delay: 0s;
}

.bg-orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #f472b6 0%, transparent 70%);
    bottom: 20%;
    left: -100px;
    animation-delay: -7s;
}

.bg-orb-3 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, #60a5fa 0%, transparent 70%);
    top: 50%;
    right: 20%;
    animation-delay: -14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(15px, 10px) scale(1.02); }
}

/* ============================================
   App Layout
   ============================================ */

.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   Header
   ============================================ */

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 32px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.search-container {
    flex: 1;
    max-width: 640px;
    margin: 0 auto;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 6px 8px 6px 16px;
    transition: var(--transition);
}

.search-box:focus-within {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(167,139,250,0.15);
    background: rgba(255,255,255,0.08);
}

.search-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: var(--transition);
}

.search-icon-btn:hover {
    color: var(--text-secondary);
}

.search-icon-btn .icon-clear {
    color: var(--text-secondary);
}

.search-icon-btn:hover .icon-clear {
    color: var(--text-primary);
}

#searchInput {
    flex: 1;
    background: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    padding: 6px 0;
}

#searchInput::placeholder {
    color: var(--text-muted);
}

.search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: white;
    transition: var(--transition);
    flex-shrink: 0;
}

.search-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-glow);
}

.search-btn:active {
    transform: scale(0.95);
}

/* ============================================
   Main Content
   ============================================ */

.main {
    flex: 1;
    padding: 32px;
    padding-bottom: calc(var(--player-height) + 48px);
}

/* Welcome Section (now just trending container) */
.welcome {
    width: 100%;
}

/* Trending Section */
.trending-section {
    width: 100%;
}

.trending-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.trending-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.trending-loading .loader-ring.small {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

.trending-section .results-grid {
    margin-top: 0;
}

/* ============================================
   Search Results
   ============================================ */

.section-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.result-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    animation: fadeInUp 0.4s ease-out backwards;
}

.result-card:hover {
    border-color: var(--accent-purple);
    background: var(--bg-card-hover);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-thumb-wrapper {
    position: relative;
    aspect-ratio: 16/9;
    overflow: hidden;
}

.result-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition-slow);
}

.result-card:hover .result-thumb {
    transform: scale(1.05);
}

.result-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.8);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}

.result-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.3);
    opacity: 0;
    transition: var(--transition);
}

.result-card:hover .result-play-overlay {
    opacity: 1;
}

.result-play-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transform: scale(0.8);
    transition: var(--transition);
}

.result-card:hover .result-play-icon {
    transform: scale(1);
}

.result-info {
    padding: 12px 14px;
}

.result-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    margin-bottom: 4px;
}

.result-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.result-author {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   Loading State
   ============================================ */

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    gap: 20px;
}

.loader {
    position: relative;
    width: 60px;
    height: 60px;
}

.loader-ring {
    position: absolute;
    inset: 0;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
}

.loader-ring:nth-child(1) {
    border-top-color: var(--accent-purple);
    animation-duration: 1.5s;
}

.loader-ring:nth-child(2) {
    inset: 6px;
    border-right-color: var(--accent-pink);
    animation-duration: 2s;
    animation-direction: reverse;
}

.loader-ring:nth-child(3) {
    inset: 12px;
    border-bottom-color: var(--accent-blue);
    animation-duration: 1s;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ============================================
   Player Bar
   ============================================ */

.player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--bg-player);
    backdrop-filter: blur(30px) saturate(1.8);
    -webkit-backdrop-filter: blur(30px) saturate(1.8);
    border-top: 1px solid var(--border-subtle);
    box-shadow: 0 -4px 30px rgba(0,0,0,0.4);
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    padding-bottom: env(safe-area-inset-bottom);
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Progress Bar */
.player-progress-bar {
    position: relative;
    height: 4px;
    background: rgba(255,255,255,0.08);
    cursor: pointer;
    transition: height var(--transition);
}

.player-progress-bar:hover {
    height: 6px;
}

.player-progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 0 2px 2px 0;
    width: 0%;
    transition: width 0.1s linear;
    position: relative;
}

.player-progress-fill::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 0 8px rgba(167,139,250,0.5);
    transition: transform var(--transition);
}

.player-progress-bar:hover .player-progress-fill::after {
    transform: translateY(-50%) scale(1);
}

.player-progress-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

/* Player Content */
.player-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    gap: 16px;
    height: calc(var(--player-height) - 4px);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.player-thumb-wrapper {
    position: relative;
    flex-shrink: 0;
}

.player-thumb {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    box-shadow: var(--shadow-sm);
}

.player-thumb-pulse {
    position: absolute;
    inset: -3px;
    border-radius: var(--radius-md);
    border: 2px solid var(--accent-purple);
    opacity: 0;
    animation: none;
}

.player-thumb-pulse.active {
    animation: thumb-pulse 2s ease-in-out infinite;
}

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

.player-meta {
    min-width: 0;
}

.player-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.player-artist {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

/* Controls */
.player-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: var(--transition);
}

.ctrl-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
}

.ctrl-btn:active {
    transform: scale(0.9);
}

.play-btn {
    width: 48px;
    height: 48px;
    background: var(--accent-gradient);
    color: white !important;
    box-shadow: 0 4px 15px rgba(167,139,250,0.3);
}

.play-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 25px rgba(167,139,250,0.5);
    background: var(--accent-gradient);
}

.play-btn:active {
    transform: scale(0.95);
}

/* Player Right */
.player-right {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.player-time {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

.volume-btn {
    width: 32px;
    height: 32px;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.15);
    cursor: pointer;
    transition: var(--transition);
}

.volume-slider:hover {
    background: rgba(255,255,255,0.25);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    transition: var(--transition);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.player-badge {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient-subtle);
    color: var(--accent-purple);
    border: 1px solid rgba(167,139,250,0.2);
    white-space: nowrap;
}

/* Stream Mode Toggle */
.stream-mode-toggle {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 2px;
    gap: 2px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: var(--transition);
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.mode-btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.06);
}

.mode-btn.active {
    background: var(--accent-gradient-subtle);
    color: var(--accent-purple);
    border: 1px solid rgba(167,139,250,0.2);
    box-shadow: 0 0 12px rgba(167,139,250,0.1);
}

.mode-btn svg {
    flex-shrink: 0;
}

/* ============================================
   Error Toast
   ============================================ */

.toast {
    position: fixed;
    bottom: calc(var(--player-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition-slow);
    z-index: 300;
    backdrop-filter: blur(10px);
    max-width: 90vw;
    text-align: center;
}

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

.toast.success {
    background: rgba(34, 197, 94, 0.9);
}

/* ============================================
   Scrollbar
   ============================================ */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding: 10px 12px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .logo {
        gap: 6px;
        font-size: 1rem;
    }

    .logo span {
        display: none;
    }

    .search-container {
        flex: 1;
        min-width: 0;
        max-width: none;
        order: 1;
    }

    .search-box {
        padding: 4px 4px 4px 12px;
        gap: 6px;
    }

    .search-btn {
        width: 32px;
        height: 32px;
    }

    #searchInput {
        padding: 4px 0;
        font-size: 0.82rem;
    }

    .stream-mode-toggle {
        order: 2;
        flex-shrink: 0;
    }

    .mode-btn span {
        display: none;
    }

    .mode-btn {
        padding: 4px 8px;
    }

    .main {
        padding: 16px 12px;
        padding-top: 70px;
        padding-bottom: 120px;
    }

    .section-title {
        font-size: 1.1rem;
        margin-bottom: 14px;
    }

    .results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .result-card {
        border-radius: var(--radius-sm);
    }

    .result-info {
        padding: 8px 10px;
    }

    .result-title {
        font-size: 0.8rem;
        -webkit-line-clamp: 2;
    }

    .result-meta {
        font-size: 0.7rem;
    }

    .result-play-icon {
        width: 36px;
        height: 36px;
    }

    .result-play-icon svg {
        width: 16px;
        height: 16px;
    }

    /* Player Bar Mobile */
    .player-bar {
        height: auto;
    }

    .player-content {
        padding: 10px 12px;
        gap: 10px;
        height: auto;
    }

    .player-thumb {
        width: 48px;
        height: 48px;
    }

    .player-title {
        font-size: 0.8rem;
        max-width: 120px;
    }

    .player-artist {
        font-size: 0.72rem;
        max-width: 120px;
    }

    .player-time,
    .volume-control,
    .player-badge {
        display: none;
    }

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

    .play-btn {
        width: 42px;
        height: 42px;
    }

    .player-controls {
        gap: 4px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 8px 10px;
    }

    .search-container {
        width: 100%;
        order: 3;
    }

    .results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .result-thumb {
        border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    }

    .result-info {
        padding: 6px 8px;
    }

    .result-title {
        font-size: 0.75rem;
    }

    .result-duration {
        font-size: 0.65rem;
        padding: 1px 4px;
    }

    .player-thumb {
        width: 40px;
        height: 40px;
    }

    .player-title {
        max-width: 100px;
    }

    .player-artist {
        max-width: 100px;
    }

    .play-btn {
        width: 38px;
        height: 38px;
    }

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

@media (max-width: 360px) {
    .results-grid {
        grid-template-columns: 1fr;
    }

    .player-controls .ctrl-btn:not(.play-btn) {
        display: none;
    }
}
