/* ============================================
   iOS-inspired design system
   - SF Pro style stack, translucent materials,
     continuous corners, spring-timed transitions
   ============================================ */
:root {
    --ios-blur: 44px;
    --ios-radius-lg: 28px;
    --ios-radius-md: 20px;
    --ios-radius-sm: 14px;
    --ios-green: #30d158;
    --ios-white: #ffffff;
    --ios-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ios-ease: cubic-bezier(0.25, 0.1, 0.25, 1);

    /* Shared timing for every theme-driven colour/material change. */
    --theme-duration: 1100ms;
    --theme-fade: var(--theme-duration) var(--ios-ease);

    /* The sheen gradient stays identical across themes: gradients don't
       interpolate reliably between browsers, so the parts that actually
       change per theme are colours and filters, which do. */
    --glass-tint: linear-gradient(
        140deg,
        rgba(255, 255, 255, 0.14) 0%,
        rgba(255, 255, 255, 0.04) 45%,
        rgba(255, 255, 255, 0.08) 100%
    );
}

/* ============================================
   Themes
   Light is the site's original appearance and
   also the no-JS default; dark only overrides
   the handful of tokens that differ.
   ============================================ */
:root,
[data-theme="light"] {
    --page-base: #121212;

    /* Glass material: a barely-there tint doing the work, with the blur and
       the rim highlights giving the surface its shape instead of opacity. */
    --glass-fill: rgba(255, 255, 255, 0.02);
    --glass-filter: blur(var(--ios-blur)) saturate(145%) brightness(0.82);
    --glass-border: rgba(255, 255, 255, 0.34);
    --glass-rim: inset 0 1px 0 rgba(255, 255, 255, 0.42),
                 inset 0 -1px 1px rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
    --glass-text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

    --sidebar-filter: blur(60px) saturate(150%) brightness(0.7);
    --scrim-color: rgba(0, 0, 0, 0.25);
    --vignette-opacity: 1;
}

[data-theme="dark"] {
    --page-base: #08080a;

    /* The backdrop is already dark here, so the material lifts the panels
       off it instead of darkening them further. */
    --glass-fill: rgba(255, 255, 255, 0.07);
    --glass-filter: blur(var(--ios-blur)) saturate(130%) brightness(1.45);
    --glass-border: rgba(255, 255, 255, 0.22);
    --glass-rim: inset 0 1px 0 rgba(255, 255, 255, 0.28),
                 inset 0 -1px 1px rgba(255, 255, 255, 0.06);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --glass-text-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);

    --sidebar-filter: blur(60px) saturate(140%) brightness(1.2);
    --scrim-color: rgba(0, 0, 0, 0.45);
    --vignette-opacity: 0.55;
}

/* Honour a reduced-motion preference by collapsing the crossfade to a
   near-instant swap rather than a 1.1s cinematic one. */
@media (prefers-reduced-motion: reduce) {
    :root {
        --theme-duration: 1ms;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
        'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-color: var(--page-base);
    transition: background-color var(--theme-fade);
}

/* Without backdrop-filter the tints alone are too faint to read against,
   so fall back to solid-ish panels (older Firefox, some Android browsers). */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    :root {
        --glass-tint: none;
        --glass-fill: rgba(28, 28, 32, 0.72);
    }

    [data-theme="dark"] {
        --glass-fill: rgba(14, 14, 18, 0.82);
    }

    .playlist-sidebar {
        background-image: none;
        background-color: rgba(20, 20, 22, 0.9);
    }
}

/* ---------- Full Screen Background (crossfading layers) ----------
   Both themes' images live in the DOM at once, stacked and identically
   positioned. Switching themes only animates their opacity, because
   background-image itself cannot be transitioned. Keeping both layers
   rendered (opacity 0, never display:none) also means the browser has
   already fetched both files before the first switch. */
.background {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--page-base);
    transition: background-color var(--theme-fade);
    z-index: 1;
}

.bg-layer {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    transition: opacity var(--theme-fade);
    will-change: opacity;
}

.bg-layer-light {
    background-image: url('backgrounds/bg-desktop.png');
}

.bg-layer-dark {
    background-image: url('backgrounds/bg-desktop-dark.png');
}

:root .bg-layer-light,
[data-theme="light"] .bg-layer-light,
[data-theme="dark"] .bg-layer-dark {
    opacity: 1;
}

[data-theme="dark"] .bg-layer-light {
    opacity: 0;
}

/* Subtle vignette overlay for depth, iOS Lock Screen style */
.background::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0) 40%, rgba(0,0,0,0.35) 100%);
    opacity: var(--vignette-opacity);
    transition: opacity var(--theme-fade);
}

@media (max-width: 768px) {
    .bg-layer-light {
        background-image: url('backgrounds/bg-mobile.png');
    }

    .bg-layer-dark {
        background-image: url('backgrounds/bg-mobile-dark.png');
    }
}

/* ---------- Header ---------- */
header {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4vw;
    z-index: 10;
    color: #fff;
}

.header-left {
    display: flex;
    align-items: center;
    background-color: var(--glass-fill);
    background-image: var(--glass-tint);
    backdrop-filter: var(--glass-filter);
    -webkit-backdrop-filter: var(--glass-filter);
    border: 0.5px solid var(--glass-border);
    padding: 7px 16px;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.2px;
    text-shadow: var(--glass-text-shadow);
    box-shadow: var(--glass-shadow), var(--glass-rim);
    transition: background-color var(--theme-fade),
                border-color var(--theme-fade),
                box-shadow var(--theme-fade),
                backdrop-filter var(--theme-fade),
                -webkit-backdrop-filter var(--theme-fade);
}

.header-right {
    display: flex;
    gap: 10px;
}

.tab {
    display: flex;
    align-items: center;
    gap: 7px;
    color: inherit;
    background-color: var(--glass-fill);
    background-image: var(--glass-tint);
    backdrop-filter: var(--glass-filter);
    -webkit-backdrop-filter: var(--glass-filter);
    border: 0.5px solid var(--glass-border);
    padding: 9px 18px;
    border-radius: 100px;
    cursor: pointer;
    transition: transform 0.2s var(--ios-spring),
                background-image 0.2s var(--ios-ease),
                background-color var(--theme-fade),
                border-color var(--theme-fade),
                box-shadow var(--theme-fade),
                backdrop-filter var(--theme-fade),
                -webkit-backdrop-filter var(--theme-fade);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -0.2px;
    text-shadow: var(--glass-text-shadow);
    box-shadow: var(--glass-shadow), var(--glass-rim);
}

.tab svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.tab:hover {
    background-image: linear-gradient(
        140deg,
        rgba(255, 255, 255, 0.26) 0%,
        rgba(255, 255, 255, 0.12) 45%,
        rgba(255, 255, 255, 0.18) 100%
    );
}

.tab:active {
    transform: scale(0.94);
}

.tab:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.85);
    outline-offset: 2px;
}

/* ---------- Theme toggle ----------
   Icon-only pill; height comes from the sibling tab because .header-right
   stretches its children, so the header layout is unchanged. */
.theme-toggle {
    position: relative;
    justify-content: center;
    width: 42px;
    padding: 9px 0;
    overflow: hidden;
}

.theme-toggle svg {
    position: absolute;
    width: 17px;
    height: 17px;
    transition: opacity var(--theme-fade), transform var(--theme-fade);
}

.theme-toggle .icon-moon {
    opacity: 0;
    transform: rotate(-70deg) scale(0.5);
}

[data-theme="dark"] .theme-toggle .icon-sun {
    opacity: 0;
    transform: rotate(70deg) scale(0.5);
}

[data-theme="dark"] .theme-toggle .icon-moon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* ---------- Playlist Sidebar ---------- */
.playlist-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: min(400px, 88vw);
    height: 100%;
    transform: translateX(100%);
    background-color: var(--glass-fill);
    background-image: linear-gradient(
        200deg,
        rgba(255, 255, 255, 0.14) 0%,
        rgba(28, 28, 32, 0.34) 55%,
        rgba(18, 18, 22, 0.42) 100%
    );
    backdrop-filter: var(--sidebar-filter);
    -webkit-backdrop-filter: var(--sidebar-filter);
    border-left: 0.5px solid var(--glass-border);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.3), var(--glass-rim);
    transition: transform 0.45s var(--ios-spring),
                background-color var(--theme-fade),
                border-color var(--theme-fade),
                box-shadow var(--theme-fade),
                backdrop-filter var(--theme-fade),
                -webkit-backdrop-filter var(--theme-fade);
    z-index: 20;
    display: flex;
    flex-direction: column;
    color: white;
    padding: max(28px, env(safe-area-inset-top)) 18px 24px;
}

.playlist-sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding: 0 6px 18px;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.12);
}

.sidebar-header h3 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.4px;
    text-shadow: var(--glass-text-shadow);
}

.sidebar-header button {
    background: rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 0.5px solid rgba(255, 255, 255, 0.22);
    color: rgba(255,255,255,0.85);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s var(--ios-ease), transform 0.15s var(--ios-spring);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header button:hover {
    background: rgba(255, 255, 255, 0.26);
}

.sidebar-header button:active {
    transform: scale(0.88);
}

.sidebar-tracks {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 2px;
}

.sidebar-tracks::-webkit-scrollbar { width: 4px; }
.sidebar-tracks::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.track-item {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 9px 10px;
    border-radius: var(--ios-radius-sm);
    cursor: pointer;
    transition: background 0.15s var(--ios-ease);
}

.track-item:hover { background: rgba(255, 255, 255, 0.06); }
.track-item:active { background: rgba(255, 255, 255, 0.1); }

.track-item.active {
    background: rgba(48, 209, 88, 0.14);
}

.track-item.active .track-item-title { color: var(--ios-green); }

.track-item.restricted {
    opacity: 0.35;
    pointer-events: none;
    filter: grayscale(100%);
}

.track-item img {
    width: 46px;
    height: 46px;
    border-radius: 9px;
    object-fit: cover;
    background: #222;
    flex-shrink: 0;
}

.track-item-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
}

.track-item-title {
    font-size: 14.5px;
    font-weight: 590;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.track-item-artist {
    font-size: 12.5px;
    font-weight: 450;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-item-playing-icon {
    display: none;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--ios-green);
}

.track-item.active .track-item-playing-icon { display: block; }

.loading-text {
    text-align: center;
    color: rgba(255,255,255,0.4);
    margin-top: 24px;
    font-size: 14px;
    font-weight: 500;
}

.error-text {
    text-align: center;
    color: rgba(255, 120, 120, 0.75);
    margin-top: 24px;
    font-size: 13px;
    font-weight: 500;
    padding: 0 12px;
}

/* Sidebar backdrop dim */
.sidebar-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    pointer-events: none;
    transition: background 0.4s var(--ios-ease);
    z-index: 19;
}

.sidebar-scrim.visible {
    background: var(--scrim-color);
    pointer-events: auto;
}

/* ---------- Bottom Music Player (iOS "Now Playing" pill) ---------- */
.player-container {
    position: fixed;
    bottom: max(22px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: min(94vw, 560px);
    background-color: var(--glass-fill);
    background-image: var(--glass-tint);
    backdrop-filter: var(--glass-filter);
    -webkit-backdrop-filter: var(--glass-filter);
    border: 0.5px solid var(--glass-border);
    border-radius: 34px;
    display: flex;
    align-items: center;
    padding: 10px 10px 10px 12px;
    z-index: 10;
    color: white;
    text-shadow: var(--glass-text-shadow);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28), var(--glass-rim);
    transition: background-color var(--theme-fade),
                border-color var(--theme-fade),
                box-shadow var(--theme-fade),
                backdrop-filter var(--theme-fade),
                -webkit-backdrop-filter var(--theme-fade);
}

.album-art {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, #30d158 0%, #1c2b1f 100%);
    margin-right: 12px;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}

.album-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.track-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    padding-right: 10px;
    min-width: 0;
}

.track-title {
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -0.2px;
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-artist {
    font-size: 11.5px;
    font-weight: 450;
    color: rgba(255, 255, 255, 0.65);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-wrapper {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 10px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.55);
}

.progress-bar {
    flex-grow: 1;
    height: 14px;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
}

.progress-bar.disabled {
    cursor: default;
}

.progress-track {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 2px;
    pointer-events: none;
}

.progress-fill {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 3px;
    width: 0%;
    background: #fff;
    border-radius: 2px;
    transition: width 0.1s linear;
}

.progress-thumb {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.15s var(--ios-ease);
}

.progress-bar:hover .progress-thumb { opacity: 1; }

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.ctrl-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.9;
    transition: opacity 0.15s var(--ios-ease), transform 0.15s var(--ios-spring);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
}

.ctrl-btn:hover { opacity: 1; background: rgba(255,255,255,0.08); }
.ctrl-btn:active { transform: scale(0.85); }

.ctrl-btn:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.ctrl-btn svg {
    width: 19px;
    height: 19px;
    fill: currentColor;
}

.play-btn {
    width: 42px;
    height: 42px;
    background: #fff;
    color: #111;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}

.play-btn:hover {
    background: #f2f2f2;
}

.play-btn svg {
    width: 17px;
    height: 17px;
    fill: #111;
}

.play-btn:disabled {
    background: rgba(255,255,255,0.6);
}

/* Active toggle state (repeat on / repeat one) */
.ctrl-btn.mode-active {
    color: var(--ios-green);
    opacity: 1;
}

.ctrl-btn.mode-active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
}

.ctrl-btn {
    position: relative;
}

/* ---------- Volume ---------- */
.volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 4px;
}

.volume-control.disabled {
    opacity: 0.35;
    pointer-events: none;
}

input[type="range"].volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 72px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.25);
    outline: none;
    cursor: pointer;
}

input[type="range"].volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.45);
    cursor: pointer;
}

input[type="range"].volume-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border: none;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.45);
    cursor: pointer;
}

#yt-player-container {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

/* Small screens: tighten the player pill */
@media (max-width: 480px) {
    .player-container { padding: 9px 8px 9px 10px; }
    .album-art { width: 44px; height: 44px; }
    .ctrl-btn { width: 32px; height: 32px; }
    .ctrl-btn svg { width: 17px; height: 17px; }
    .play-btn { width: 38px; height: 38px; }
    .controls { gap: 0; }
    .volume-control { gap: 2px; padding-right: 0; }
    input[type="range"].volume-slider { width: 52px; }
}

/* Very narrow phones: the pill can't fit both the slider and a
   readable title, so the mute button carries volume duty alone. */
@media (max-width: 380px) {
    input[type="range"].volume-slider { display: none; }
}
