/* ============================================================
   Mini Player Widget (YouTube-style floating player)
   Self-contained styles (no Tailwind dependency) so this sheet
   can be copied verbatim into the Document PiP window (Tier 3).
   ============================================================ */

#mini-player-widget {
    position: fixed;
    z-index: 90; /* above #discovery-mode (z-80), below true modals (z-100+) */
    display: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#mini-player-widget.mpw-visible {
    display: block;
}

#mini-player-widget.mpw-snapping {
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                top 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mpw-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 31rem;
    max-width: calc(100vw - 2rem);
    padding: 0.5rem 0.75rem 0.5rem 0.5rem;
    border-radius: 1.1rem;
    background: color-mix(in srgb, var(--theme-surface, #0f141e) 90%, transparent);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid color-mix(in srgb, var(--theme-primary, #D4AF37) 22%, rgba(255, 255, 255, 0.12));
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), 0 0 24px -2px color-mix(in srgb, var(--theme-primary, #D4AF37) 18%, transparent);
    color: var(--theme-text, #fff);
    font-family: 'Inter', system-ui, sans-serif;
    cursor: grab;
    position: relative;
    overflow: hidden;
    transition: background-color 0.45s ease, border-color 0.45s ease, box-shadow 0.45s ease;
}

.mpw-transport,
.mpw-actions {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    flex-shrink: 0;
}

.mpw-actions {
    padding-left: 0.35rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.mpw-card:active {
    cursor: grabbing;
}

.mpw-art {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: color-mix(in srgb, var(--theme-primary, #D4AF37) 70%, transparent);
    font-size: 1rem;
}

.mpw-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.mpw-title {
    font-size: 0.72rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.mpw-subtitle {
    font-size: 0.6rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mpw-btn {
    border: none;
    background: transparent;
    color: #94a3b8;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.72rem;
    transition: color 0.2s, transform 0.15s, background 0.2s;
}

.mpw-btn:focus-visible {
    outline: 2px solid var(--theme-primary, #D4AF37);
    outline-offset: 2px;
}

.mpw-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.mpw-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.mpw-btn:disabled:hover {
    color: #94a3b8;
    background: transparent;
}

.mpw-btn:active {
    transform: scale(0.88);
}

.mpw-play {
    width: 2.9rem;
    height: 2.9rem;
    background: var(--theme-text, #fff);
    color: var(--theme-bg, #000);
    font-size: 0.8rem;
    box-shadow: 0 0 20px color-mix(in srgb, var(--theme-primary, #D4AF37) 32%, transparent);
}

.mpw-play:hover {
    background: var(--theme-text, #fff);
    color: var(--theme-bg, #000);
    transform: scale(1.08);
    box-shadow: 0 0 26px color-mix(in srgb, var(--theme-primary, #D4AF37) 45%, transparent);
}

.mpw-progress-track {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.06);
}

.mpw-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right,
        color-mix(in srgb, var(--theme-primary, #D4AF37) 50%, transparent),
        var(--theme-primary, #D4AF37));
    transition: width 0.3s linear;
}

/* Compact in-app bubble. A tap on the bubble restores the full mini-player. */
#mini-player-widget.mpw-collapsed .mpw-card {
    width: 3.5rem;
    height: 3.5rem;
    padding: 0;
    gap: 0;
    border-radius: 50%;
    cursor: pointer;
    background: var(--theme-surface, #0f141e);
    border-color: color-mix(in srgb, var(--theme-primary, #D4AF37) 40%, rgba(255, 255, 255, 0.1));
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 20px -2px color-mix(in srgb, var(--theme-primary, #D4AF37) 30%, transparent);
}

#mini-player-widget.mpw-collapsed .mpw-card > :not(.mpw-art) {
    display: none;
}

#mini-player-widget.mpw-collapsed .mpw-art {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 50%;
    color: var(--theme-primary, #D4AF37);
    font-size: 1.15rem;
    box-shadow: inset 0 0 0 2px color-mix(in srgb,
        var(--theme-primary, #D4AF37) 55%, transparent);
}

/* One-click PiP button, sits above the full-size player */
#mpw-player-pip-btn {
    position: absolute;
    top: -0.75rem;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: color-mix(in srgb, var(--theme-surface, #1e2634) 90%, transparent);
    border: 1px solid color-mix(in srgb, var(--theme-primary, #D4AF37) 20%, rgba(255, 255, 255, 0.1));
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    font-size: 0.6rem;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    transition: color 0.2s, background 0.2s, transform 0.2s;
}

#mpw-player-pip-btn {
    right: 5.5rem;
}

#mpw-player-pip-btn:hover {
    color: var(--theme-primary, #D4AF37);
    background: color-mix(in srgb, var(--theme-primary, #D4AF37) 15%, rgba(30, 38, 52, 0.9));
    transform: scale(1.08);
}

/* ---------- Mobile: full-width bar pinned above the bottom edge ---------- */
@media (max-width: 640px) {
    #mini-player-widget {
        left: 0.75rem !important;
        right: 0.75rem !important;
        top: auto !important;
        bottom: 1rem !important;
        width: auto;
    }

    .mpw-card {
        width: 100%;
        max-width: none;
    }

    .mpw-meta { max-width: 7rem; }

    #mini-player-widget.mpw-collapsed {
        left: auto !important;
        right: 0.75rem !important;
        width: 3.5rem;
    }

    #mini-player-widget.mpw-collapsed .mpw-card {
        width: 3.5rem;
    }
}

/* ---------- Inside the Document PiP window ----------
   The card must fill the whole window edge-to-edge: set explicit
   heights on html/body (min-height alone leaves the card unresolved
   at height:100% and dark gutters appear around it). */
body.mpw-pip-body {
    margin: 0;
    height: 100vh;
    background: var(--theme-bg, #0a101b);
    color: var(--theme-text, #fff);
    overflow: hidden;
}

body.mpw-pip-body .mpw-card {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    height: 100%;
    border-radius: 1.25rem;
    border: 1px solid color-mix(in srgb, var(--theme-primary, #D4AF37) 24%, rgba(255,255,255,0.14));
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255,255,255,0.08);
    cursor: default;
    gap: 0.6rem;
    padding: 0.85rem 1rem 1rem;
    background:
        radial-gradient(circle at 92% 8%, color-mix(in srgb, var(--theme-primary, #D4AF37) 22%, transparent), transparent 38%),
        linear-gradient(135deg, var(--theme-bg, #0a101b) 0%, var(--theme-surface, #101827) 58%, var(--theme-surface-high, #122a35) 100%);
    overflow: hidden;
}

/* The native video PiP controls playback. Document PiP keeps the same clean
   transport controls but removes actions that would open another window. */
body.mpw-pip-body #mpw-pip-btn,
body.mpw-pip-body #mpw-collapse-btn,
body.mpw-pip-body #mpw-close-btn {
    display: none;
}

body.mpw-pip-body .mpw-art {
    display: none;
}

/* Title gets two lines in PiP instead of one truncated line */
body.mpw-pip-body .mpw-title {
    font-size: 0.76rem;
    line-height: 1.25;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

body.mpw-pip-body .mpw-subtitle {
    display: none;
}

body.mpw-pip-body .mpw-meta {
    gap: 0.15rem;
}

body.mpw-pip-body .mpw-btn {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 0.78rem;
}

body.mpw-pip-body .mpw-play {
    width: 3rem;
    height: 3rem;
    font-size: 0.9rem;
}

body.mpw-pip-body .mpw-progress-track {
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
}

/* Light Theme Specific Support */
[data-theme="sepia"] .mpw-card,
[data-theme="paper"] .mpw-card,
body.mpw-pip-body[data-theme="sepia"] .mpw-card,
body.mpw-pip-body[data-theme="paper"] .mpw-card {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.12);
}
[data-theme="sepia"] .mpw-btn:hover,
[data-theme="paper"] .mpw-btn:hover,
body.mpw-pip-body[data-theme="sepia"] .mpw-btn:hover,
body.mpw-pip-body[data-theme="paper"] .mpw-btn:hover {
    color: var(--theme-primary);
    background: rgba(0, 0, 0, 0.06);
}
[data-theme="sepia"] .mpw-play,
[data-theme="paper"] .mpw-play,
body.mpw-pip-body[data-theme="sepia"] .mpw-play,
body.mpw-pip-body[data-theme="paper"] .mpw-play {
    background: var(--theme-primary) !important;
    color: #fff !important;
    box-shadow: 0 0 20px color-mix(in srgb, var(--theme-primary) 35%, transparent);
}

/* Mobile Responsiveness for Floating Mini Player Widget */
@media (max-width: 640px) {
    .mpw-card {
        width: calc(100vw - 1.25rem);
        max-width: 25rem;
        padding: 0.4rem 0.5rem;
        border-radius: 1rem;
        gap: 0.35rem;
    }
    .mpw-art {
        width: 2.15rem;
        height: 2.15rem;
        border-radius: 0.5rem;
        font-size: 0.85rem;
    }
    .mpw-title {
        font-size: 0.68rem;
    }
    .mpw-subtitle {
        font-size: 0.55rem;
    }
    .mpw-btn {
        width: 2rem;
        height: 2rem;
        font-size: 0.65rem;
    }
    .mpw-play {
        width: 2.35rem;
        height: 2.35rem;
        font-size: 0.72rem;
    }
    .mpw-actions {
        padding-left: 0.2rem;
    }
}
