/* ========================================
   MEDIA ROOM — Modern Redesign
   ======================================== */

/* ==========================================
   @layer features — sync tab + solo player chrome.
   ========================================== */
@layer features {

/* ================================================
   SOLO PLAYER — used by the movie/show modal.
   Reuses sync-player visual classes (.media-*) but
   lives inside #video-wrapper.solo-player-wrap and
   overrides the sync tab's fixed height so the
   player fills the modal naturally.
   ================================================ */
.solo-player-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
    background: #000;
}
.solo-player-wrap .media-player-area {
    /* Override the sync tab's fixed !important heights — the modal provides its own sizing */
    height: auto !important;
    max-height: none !important;
    flex: 1;
    min-height: 0;
    border-radius: 0;
    border: none;
    background: #000;
    position: relative;
}
.solo-player-wrap video {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
    object-fit: contain;
}
.solo-bottom-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 8;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.45) 55%, transparent 100%);
    padding-bottom: 8px;
}
.solo-player-wrap.media-show .solo-bottom-controls {
    opacity: 1;
    pointer-events: auto;
}
.solo-bottom-controls .media-time-row {
    padding: 8px clamp(10px, 2vw, 24px) 2px;
}
.solo-bottom-controls .media-seekbar-wrap {
    padding: 0 clamp(10px, 2vw, 24px);
}
.solo-bottom-controls .media-transport {
    background: transparent;
    padding: 6px clamp(6px, 1.2vw, 16px) 8px;
    justify-content: stretch;
    position: relative;
    min-height: 46px;
}
.solo-bottom-controls .media-transport-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: clamp(4px, 1vw, 10px);
    position: relative;
    min-height: 46px;
}
/* Fullscreen the modal → make the player edge-to-edge.
   Phase 7.5: add 100dvh fallback so iOS Safari URL-bar collapse
   doesn't leave the player short. 100vh stays as fallback for
   older Safari without dvh support. */
#video-wrapper:fullscreen,
#video-wrapper:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}
#video-wrapper:fullscreen video,
#video-wrapper:-webkit-full-screen video {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

/* iOS fake-fullscreen (Safari doesn't always honor requestFullscreen() on a div on
   older iOS). Our JS adds .solo-fs + body.solo-fs-active for this path. Clears any
   ancestor transform that would break position:fixed on iOS. */
body.solo-fs-active,
body.solo-fs-active > *,
body.solo-fs-active .tab-content,
body.solo-fs-active .video-modal {
    transform: none !important;
    animation: none !important;
}
#video-wrapper.solo-fs {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 9999;
    background: #000;
}
#video-wrapper.solo-fs video {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

/* ============================================================
   KILL EVERY NATIVE VIDEO CONTROL SURFACE
   Runs against <video id="video-player"> AND <video id="media-native-video">
   on the Sync tab. Covers Chrome, Edge, Safari (desktop + iOS),
   Firefox, Android Chrome, Samsung Internet, and WebKit PWAs.
   ============================================================ */
#video-player::-webkit-media-controls,
#video-player::-webkit-media-controls-enclosure,
#video-player::-webkit-media-controls-panel,
#video-player::-webkit-media-controls-overlay-enclosure,
#video-player::-webkit-media-controls-overlay-play-button,
#video-player::-webkit-media-controls-start-playback-button,
#video-player::-webkit-media-controls-play-button,
#video-player::-webkit-media-controls-timeline,
#video-player::-webkit-media-controls-current-time-display,
#video-player::-webkit-media-controls-time-remaining-display,
#video-player::-webkit-media-controls-mute-button,
#video-player::-webkit-media-controls-volume-slider,
#video-player::-webkit-media-controls-fullscreen-button,
#video-player::-webkit-media-controls-toggle-closed-captions-button,
#video-player::-webkit-media-controls-picture-in-picture-button,
#media-native-video::-webkit-media-controls,
#media-native-video::-webkit-media-controls-enclosure,
#media-native-video::-webkit-media-controls-panel,
#media-native-video::-webkit-media-controls-overlay-enclosure,
#media-native-video::-webkit-media-controls-overlay-play-button,
#media-native-video::-webkit-media-controls-start-playback-button,
#media-native-video::-webkit-media-controls-play-button,
#media-native-video::-webkit-media-controls-timeline,
#media-native-video::-webkit-media-controls-current-time-display,
#media-native-video::-webkit-media-controls-time-remaining-display,
#media-native-video::-webkit-media-controls-mute-button,
#media-native-video::-webkit-media-controls-volume-slider,
#media-native-video::-webkit-media-controls-fullscreen-button,
#media-native-video::-webkit-media-controls-toggle-closed-captions-button,
#media-native-video::-webkit-media-controls-picture-in-picture-button {
    display: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Some iOS builds still render a small overlay ::before — kill it */
#video-player::before,
#media-native-video::before {
    display: none !important;
}

/* Block the big first-start play button on mobile (Android Chrome + iOS) */
#video-player,
#media-native-video {
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

.media-room {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--spacing-sm) 0;
    display: flex;
    flex-direction: column;
}

#media-connected:not(.hidden) {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1.2dvh, 12px);
    overflow: visible;
    max-width: 100%;
}

/* --- Player Wrapper (player + chat + controls) --- */
.media-player-wrap {
    position: relative;
    flex-shrink: 0;
}

/* --- Player Area --- */
/* Phase 7.7: !important on overflow stripped — no other rule fights
   .media-player-area's overflow anywhere in the codebase. */
.media-player-area {
    border-radius: 16px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    flex-grow: 0;
    position: relative;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    max-width: 100%;
    /* Smooth transitions between all player modes */
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                border-radius 0.3s ease,
                background 0.3s ease;
}

/* All content inside must fit, never expand the player. Overlays that are
   full-bleed by design (pause, loading, reactions, disconnect) are excluded
   because they use absolute positioning with inset:0 and shouldn't be constrained. */
.media-player-area > *:not(.media-disconnect-overlay):not(.media-paused-overlay):not(.media-loading-overlay) {
    max-height: 100%;
    overflow: hidden;
}


.tiktok-embed-wrapper {
    overflow: hidden !important;
}

/* =============================================
   FIXED PLAYER SIZES — set per screen, NEVER changes
   height is !important so nothing can override it
   ============================================= */

/* ——— Desktop (>1024px) ——— */
.media-player-area                { height: 420px !important; }
.media-player-area.tiktok-mode    { height: 600px !important; max-width: 350px; background: #000; border-radius: 12px; }
.media-player-area.spotify-mode   { height: 352px !important; }

/* ——— Tablet (601–1024px) ——— */
@media (max-width: 1024px) {
    .media-player-area                { height: 360px !important; }
    .media-player-area.tiktok-mode    { height: 540px !important; max-width: 320px; }
    .media-player-area.spotify-mode   { height: 310px !important; }
}

/* ——— Large phone (431–600px) ——— */
/* Video uses clamp() with a dvh floor so on shorter viewports (iPhone SE
   with the URL bar visible) the player shrinks — gives the queue more
   room. 32dvh fits the sync layout where queue needs ~4 items + the
   input/queue-header stack + a little bottom breathing. */
/* breakpoint snap 600px -> 768px (Phase 7.6 ladder) */
@media (max-width: 768px) {
    .media-player-area                { height: clamp(180px, 32dvh, 230px) !important; border-radius: 12px; }
    .media-player-area.tiktok-mode    { height: min(600px, 75dvh) !important; max-width: 92vw; }
    .media-player-area.spotify-mode   { height: clamp(180px, 32dvh, 230px) !important; }
}

/* ——— Small phone (≤480px — snapped from 430 per Phase 7.6 ladder) ——— */
@media (max-width: 480px) {
    .media-player-area                { height: clamp(160px, 30dvh, 210px) !important; }
    .media-player-area.tiktok-mode    { height: min(570px, 73dvh) !important; max-width: 94vw; }
    .media-player-area.spotify-mode   { height: clamp(160px, 30dvh, 210px) !important; }
}

#yt-player-container,
#spotify-player-container {
    width: 100%;
    height: 100%;
}

.media-player-area iframe {
    width: 100% !important;
    height: 100% !important;
    border: none;
}

.media-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
    padding: 24px;
}

.media-empty-logos {
    display: flex;
    align-items: center;
    gap: 20px;
    opacity: 0.55;
}

.media-empty-text {
    /* Phase 8.5 contrast */
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

/* --- URL Input Row --- */
.media-input-row {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.media-url-input {
    flex: 1;
    /* Flex items default to `min-width: auto` = intrinsic placeholder width.
       Without this override, the input refuses to shrink below the width of
       "Paste a URL or browse library...", pushing the rightmost button
       (invite partner) off the viewport on narrow phones. */
    min-width: 0;
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px 16px;
    color: #fff;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.media-url-input:focus {
    border-color: rgba(var(--secondary-alt-rgb),0.45);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb),0.08);
}

.media-url-input::placeholder {
    /* Phase 8.5 contrast — was 0.25 which failed AA hard. */
    color: var(--text-placeholder);
}

.media-add-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(var(--secondary-alt-rgb),0.3);
    background: rgba(var(--secondary-alt-rgb),0.15);
    color: var(--secondary-alt);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.media-add-btn:hover {
    background: rgba(var(--secondary-alt-rgb),0.28);
    border-color: rgba(var(--secondary-alt-rgb),0.5);
}

.media-library-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(var(--secondary-alt-rgb),0.3);
    background: rgba(var(--secondary-alt-rgb),0.15);
    color: var(--secondary-alt);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, background-color 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s, filter 0.2s, opacity 0.2s, transform 0.2s;
}
.media-library-btn:hover {
    background: rgba(var(--secondary-alt-rgb),0.28);
    border-color: rgba(var(--secondary-alt-rgb),0.5);
}

.media-invite-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(var(--primary-rgb),0.25);
    background: rgba(var(--primary-rgb),0.1);
    color: rgba(var(--primary-rgb),0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, background-color 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s, filter 0.2s, opacity 0.2s, transform 0.2s;
}
.media-invite-btn:hover {
    background: rgba(var(--primary-rgb),0.2);
    border-color: rgba(var(--primary-rgb),0.45);
    color: var(--primary);
}

/* Library Picker Modal */
.media-library-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483647;   /* max int — guarantees above sync fullscreen */
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}
.media-library-overlay.hidden { display: none; }

/* Fullscreen: make the library modal punchier so it reads clearly on top
   of an active video. Bigger, slightly translucent backdrop. */
body.media-fs-active .media-library-modal {
    max-width: min(90vw, 520px);
    max-height: 80vh;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7),
                0 0 40px rgba(var(--primary-rgb), 0.15);
}

.media-library-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.media-library-modal {
    position: relative;
    width: 90%;
    max-width: 400px;
    max-height: 70vh;
    background: linear-gradient(135deg, rgba(20, 18, 30, 0.98), rgba(15, 12, 25, 0.99));
    border: 1px solid rgba(var(--secondary-alt-rgb),0.2);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 30px rgba(var(--secondary-alt-rgb),0.08);
    animation: modalScaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalScaleIn {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.media-library-modal-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 20px;
    background: rgba(var(--secondary-alt-rgb),0.06);
    border-bottom: 1px solid rgba(var(--secondary-alt-rgb),0.12);
    position: relative;
}

.media-library-modal-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
}

.media-library-close {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s, background-color 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s, filter 0.2s, opacity 0.2s, transform 0.2s;
}
.media-library-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

/* Search input above the library picker tree */
.mlp-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 16px 0;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(var(--secondary-rgb), 0.25);
    border-radius: 10px;
    transition: border-color 0.15s, background 0.15s;
}
.mlp-search-wrap:focus-within {
    border-color: rgba(var(--primary-rgb), 0.55);
    background: rgba(255, 255, 255, 0.06);
}
.mlp-search-icon {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.mlp-search-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 2px 0;
}
.mlp-search-input::placeholder { color: var(--text-muted); }
.mlp-search-clear {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.mlp-search-clear:hover {
    background: rgba(var(--primary-rgb), 0.2);
    color: var(--primary);
}
.mlp-search-clear.hidden { display: none; }
/* Kind badge on search results (Movie / Book / S1E3) */
.mlp-kind-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--primary);
    background: rgba(var(--primary-rgb), 0.14);
    border: 1px solid rgba(var(--primary-rgb), 0.3);
    border-radius: 4px;
    vertical-align: middle;
}
/* Right-edge chevron on show search results — signals "click to drill in" */
.mlp-drill-arrow {
    color: var(--primary);
    font-size: 1.4rem;
    line-height: 1;
    font-weight: 300;
    padding: 0 4px 0 8px;
    opacity: 0.6;
    transition: opacity 0.15s, transform 0.15s;
}
.mlp-item.mlp-show-result { cursor: pointer; }
.mlp-item.mlp-show-result:hover .mlp-drill-arrow { opacity: 1; transform: translateX(3px); }

/* Library-picker drill-down now reuses the queue-add popover classes
   (`.media-queue-add-drill-*`) for a unified look across both surfaces.
   The old `.mlp-drill-header/back/thumb/title` rules were removed in v65. */

.media-library-picker {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--secondary-rgb),0.3) transparent;
}
.media-library-picker::-webkit-scrollbar { width: 5px; }
.media-library-picker::-webkit-scrollbar-thumb { background: rgba(var(--secondary-rgb),0.3); border-radius: 3px; }

.media-library-picker .mlp-section {
    padding: 8px 0 4px;
    font-size: 0.75rem;
    font-weight: 700;
    color: rgba(var(--secondary-alt-rgb),0.8);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
    user-select: none;
}
.media-library-picker .mlp-section:hover { color: rgba(var(--secondary-alt-rgb),1); }
.mlp-collapse-icon {
    font-size: 0.65rem;
    width: 12px;
    display: inline-block;
    transition: transform 0.2s;
}
.mlp-count {
    font-size: 0.65rem;
    font-weight: 500;
    color: rgba(255,255,255,0.25);
    margin-left: auto;
}
.mlp-group.hidden { display: none; }
.mlp-show-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    transition: background 0.2s, background-color 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s, filter 0.2s, opacity 0.2s, transform 0.2s;
    user-select: none;
    border-radius: 10px;
    margin-bottom: 2px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
}
.mlp-show-header:hover {
    background: rgba(var(--secondary-alt-rgb),0.08);
    border-color: rgba(var(--secondary-alt-rgb),0.15);
}
.mlp-thumb-sm {
    width: 28px;
    height: 28px;
    border-radius: 5px;
    object-fit: cover;
    flex-shrink: 0;
}
.mlp-show-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlp-season-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px 5px 36px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255,255,255,0.6);
    user-select: none;
    transition: color 0.15s;
}
.mlp-season-header:hover { color: rgba(255,255,255,0.9); }
.mlp-icon-sm {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.7rem !important;
}

.media-library-picker .mlp-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.2s, background-color 0.2s, border-color 0.2s, box-shadow 0.2s, color 0.2s, filter 0.2s, opacity 0.2s, transform 0.2s;
    border-radius: 12px;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}
.media-library-picker .mlp-item:hover {
    background: rgba(var(--secondary-alt-rgb),0.08);
    border-color: rgba(var(--secondary-alt-rgb),0.2);
}

.media-library-picker .mlp-thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(var(--secondary-alt-rgb),0.15);
}
.media-library-picker .mlp-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--secondary-alt-rgb),0.1);
    font-size: 1.2rem;
    flex-shrink: 0;
    border: 1px solid rgba(var(--secondary-alt-rgb),0.15);
}

.media-library-picker .mlp-info {
    flex: 1;
    min-width: 0;
}
.media-library-picker .mlp-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.media-library-picker .mlp-meta {
    font-size: 0.7rem;
    /* Phase 8.5 contrast */
    color: var(--text-muted);
}

/* --- Transport Controls --- */
.media-transport {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 1vw, 12px);
    flex-shrink: 0;
}

.media-ctrl-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.08);
}

.media-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.15);
}

/* 10s skip buttons — round, solid purple, distinctive. Icon (Material replay_10 /
   forward_10) already has "10" baked into the path, so no separate text span. */
.media-skip10-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    border-color: rgba(var(--secondary-alt-rgb),0.55);
    background: rgba(var(--secondary-alt-rgb),0.28);
    color: #e9d5ff;
    box-shadow: 0 0 8px rgba(var(--secondary-alt-rgb),0.18);
}

.media-skip10-btn svg {
    flex-shrink: 0;
}
/* Legacy text span — icon carries the "10" now, hide any leftover instances */
.media-skip10-text { display: none; }

.media-skip10-btn:hover {
    background: rgba(var(--secondary-alt-rgb),0.42);
    border-color: rgba(var(--secondary-alt-rgb),0.75);
    color: #fff;
    box-shadow: 0 0 14px rgba(var(--secondary-alt-rgb),0.35);
}

/* .media-skip10-text — no longer rendered; the "10" is baked into the SVG icon now */

/* Single play/pause toggle button — gold when paused (▶), purple when playing (⏸) */
.media-playpause-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 2px 12px rgba(var(--primary-rgb),0.35), 0 0 20px rgba(var(--primary-rgb),0.2);
}
.media-playpause-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 20px rgba(var(--primary-rgb),0.5), 0 0 30px rgba(var(--primary-rgb),0.3);
}
/* When playing: purple gradient, show pause icon */
.media-playpause-btn.playing {
    background: linear-gradient(135deg, var(--secondary-alt), var(--secondary-dark));
    box-shadow: 0 2px 12px rgba(var(--secondary-alt-rgb),0.4), 0 0 22px rgba(var(--secondary-alt-rgb),0.25);
}
.media-playpause-btn.playing:hover {
    box-shadow: 0 4px 20px rgba(var(--secondary-alt-rgb),0.55), 0 0 32px rgba(var(--secondary-alt-rgb),0.35);
}
/* Toggle icon visibility */
.media-playpause-btn .media-pp-pause { display: none; }
.media-playpause-btn.playing .media-pp-play { display: none; }
.media-playpause-btn.playing .media-pp-pause { display: block; }

/* Transport occupancy colors — grey alone, green one, purple both (play button untouched) */
.media-transport.occupancy-alone .media-ctrl-btn,
.media-transport.occupancy-alone .media-skip10-btn {
    opacity: 0.45;
    filter: grayscale(0.6);
}
.media-transport.occupancy-alone .media-playpause-btn {
    opacity: 0.45;
}
.media-transport.occupancy-one .media-ctrl-btn {
    border-color: rgba(46, 213, 115, 0.25);
    color: rgba(46, 213, 115, 0.8);
}
.media-transport.occupancy-one .media-skip10-btn {
    border-color: rgba(46, 213, 115, 0.5);
    background: rgba(46, 213, 115, 0.22);
    color: #b8f7cc;
}
.media-transport.occupancy-both .media-ctrl-btn {
    border-color: rgba(var(--secondary-alt-rgb),0.3);
    color: rgba(200, 170, 255, 0.9);
}
.media-transport.occupancy-both .media-skip10-btn {
    border-color: rgba(var(--secondary-alt-rgb),0.6);
    background: rgba(var(--secondary-alt-rgb),0.3);
    color: #e9d5ff;
}

/* Book mode — hide everything that doesn't apply to a static book item:
   - play/pause (Open Book replaces it)
   - ±10s skips (no timeline to seek)
   - volume + slider (no audio)
   - seekbar (no elapsed time)
   - video-only settings rows (Speed/Quality/Subtitles/Cast)
   Keeps: prev, next, chat input, emoji, settings (Sync now only),
   fullscreen, queue + button. */
/* Phase 7.7: !important stripped across the book-mode hide-set —
   1,2,0 / 1,2,1 specificity already beats every other rule targeting
   these buttons/rows. */
.media-transport.book-mode #media-playpause-btn,
.media-transport.book-mode #media-back10-btn,
.media-transport.book-mode #media-fwd10-btn,
.media-transport.book-mode #media-vol-btn,
.media-transport.book-mode #media-vol-slider {
    display: none;
}
/* Seekbar sits OUTSIDE .media-transport in the DOM, so scope to the room
   instead — the renderPlayer flips .book-mode on .media-room too. */
.media-room.book-mode #media-seekbar-wrap,
.media-room.book-mode .media-time-row {
    display: none;
}
/* Settings menu rows that only make sense for video — keep "Sync now"
   visible since it's useful even on books (resyncs playback state). */
.media-room.book-mode #media-settings-menu [data-action="open-speed"],
.media-room.book-mode #media-settings-menu [data-action="open-quality"],
.media-room.book-mode #media-settings-menu [data-action="open-subs"],
.media-room.book-mode #media-settings-menu [data-action="cast"],
.media-room.book-mode #media-settings-menu [data-view="speed"],
.media-room.book-mode #media-settings-menu [data-view="quality"],
.media-room.book-mode #media-settings-menu [data-view="subs"] {
    display: none;
}
/* The separator between "Sync now" and the speed row is now dangling at
   the bottom — hide it so the menu doesn't end on a lonely divider. */
.media-room.book-mode #media-settings-menu [data-view="main"] .msm-sep {
    display: none;
}

/* --- Sync button inside transport bar --- */
.media-sync-transport {
    border-color: rgba(var(--primary-rgb),0.2);
    background: rgba(var(--primary-rgb),0.06);
    color: rgba(var(--primary-rgb),0.7);
    box-shadow: 0 0 8px rgba(var(--primary-rgb),0.1);
}
.media-sync-transport:hover {
    background: rgba(var(--primary-rgb),0.15);
    border-color: rgba(var(--primary-rgb),0.4);
    color: var(--primary);
    box-shadow: 0 0 14px rgba(var(--primary-rgb),0.2);
}

/* --- Chat messages floating above the seek bar --- */
/* ==========================================
   PAUSED STATE OVERLAY — big centered play icon when video is paused
   (Shown only on .is-paused; set by _updatePlayPauseBtn in media.js for
   playerType === 'video' | 'youtube'.)
   ========================================== */
.media-paused-overlay {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.media-player-area.is-paused .media-paused-overlay {
    opacity: 1;
    /* Backdrop stays pass-through — only the icon catches clicks, so bottom controls,
       chat, fullscreen, volume, settings all remain usable while paused, and clicking
       anywhere in the dim area doesn't auto-resume playback. */
    pointer-events: none;
    animation: mediaPausedIn 0.3s ease;
}
/* Minimalist outline-only play icon in themed primary color — very transparent.
   NO ring around it; the triangle itself is the icon. Flex-centers the SVG with
   no optical offset so it lines up exactly with the bottom playpause button
   (which also flex-centers its triangle with no offset). */
.media-paused-icon {
    width: clamp(80px, 10vw, 120px);
    height: clamp(80px, 10vw, 120px);
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.48;
    transform: scale(1);
    transition: transform 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
    pointer-events: auto;
    cursor: pointer;
    /* No filter: drop-shadow() on the idle state — it was recomputing every
       pulse frame (2.6s × 60fps). Hover glow (below) provides the lit feel. */
}
.media-paused-icon svg {
    width: 100%;
    height: 100%;
    /* No margin-left: keep triangle flex-centered so it aligns vertically with
       the bottom play button's triangle (which also has no offset). */
}
/* Override inline fill=currentColor to make the triangle outline-only */
.media-paused-icon svg path {
    fill: none !important;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
/* Hover: dramatic layered glow + scale + full opacity. Three stacked
   drop-shadows of increasing radius give the halo a soft falloff that reads
   as an actual "light source" behind the triangle, much more alive than a
   single shadow. Pulse animation pauses at the bright state (rule below). */
.media-player-area.is-paused .media-paused-overlay:hover .media-paused-icon {
    opacity: 1;
    transform: scale(1.12);
    filter:
        drop-shadow(0 0 10px rgba(var(--primary-rgb), 0.85))
        drop-shadow(0 0 28px rgba(var(--primary-rgb), 0.65))
        drop-shadow(0 0 60px rgba(var(--primary-rgb), 0.4));
    /* Slightly brighter stroke on hover — primary-light if the theme defines it */
    color: var(--primary-light, var(--primary));
}
/* Fill the triangle path with a faint primary tint on hover so the glyph
   feels "lit from within" instead of just outlined. Overrides the global
   .media-paused-icon svg path { fill: none !important } with a specificity
   bump, using rgba so unhovered state stays outline-only. */
.media-player-area.is-paused .media-paused-overlay:hover .media-paused-icon svg path {
    fill: rgba(var(--primary-rgb), 0.18) !important;
    stroke-width: 2.5;
}
/* (Halo ring removed per design — triple-stacked drop-shadow + fill-on-hover
   give enough visual pop without the extra pulsing circle around the icon.) */
@keyframes mediaPausedIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes mediaPausedPulse {
    0%, 100% { transform: scale(1); opacity: 0.48; }
    50% { transform: scale(1.025); opacity: 0.62; }
}
.media-player-area.is-paused .media-paused-icon {
    animation: mediaPausedPulse 2.6s ease-in-out infinite;
}
/* Hover pauses the pulse at the bright state */
.media-player-area.is-paused .media-paused-overlay:hover .media-paused-icon {
    animation-play-state: paused;
}

/* ==========================================
   LOADING / BUFFERING OVERLAY — branded SalmasFLIX spinner
   Shown during: initial load, seeking-triggered buffer, network stall.
   Three concentric rings spinning at different speeds in themed gradient,
   with the "SalmasFLIX" wordmark pulsing underneath.
   ========================================== */
.media-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 14; /* below pause overlay (15) so it defers if both would show */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.35), rgba(0,0,0,0.55));
    /* backdrop-filter removed — expensive GPU work on every frame of the video
       behind it; the radial-gradient background alone gives enough contrast. */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    /* Skip rendering the whole subtree (3 spinning rings + text) when offscreen
       or not-loading — browser treats it as display:none for perf. */
    content-visibility: auto;
    contain: layout paint size;
}
.media-loading-overlay.is-loading {
    opacity: 1;
}

/* Three concentric rings — each a CSS-only spinner at a different speed/direction.
   PERF NOTES:
   • Animations are PAUSED by default; only run when parent has .is-loading.
     Previously they ran infinitely even when the overlay was invisible, burning
     GPU for no reason whenever the user's tab was open.
   • No filter: drop-shadow() on the spinning elements — drop-shadow recomputes
     every rotation frame and was the single biggest GPU hog (3 rings × 60fps).
     The colored borders alone read clearly against the dark backdrop. */
.media-loading-ring {
    position: relative;
    width: clamp(72px, 9vw, 108px);
    height: clamp(72px, 9vw, 108px);
}
.media-loading-ring span {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
    box-sizing: border-box;
    animation-play-state: paused;
    /* `will-change: transform` was here but allocated a persistent GPU layer
       per ring (×3 rings × 2 players = 6 permanent layers ≈ extra RAM the
       browser never freed). Only promote to a layer WHILE the overlay is
       actually animating; when it's paused the browser can recycle the layer. */
}
.media-loading-overlay.is-loading .media-loading-ring span {
    animation-play-state: running;
    will-change: transform;
}
/* Outer ring — primary arc, clockwise, slowest */
.media-loading-ring span:nth-child(1) {
    border-top-color: var(--primary);
    border-right-color: rgba(var(--primary-rgb), 0.35);
    animation: mediaLoadSpin 1.6s linear infinite;
}
/* Middle ring — secondary arc, counter-clockwise, medium */
.media-loading-ring span:nth-child(2) {
    inset: 10px;
    border-bottom-color: var(--secondary);
    border-left-color: rgba(var(--secondary-rgb), 0.35);
    animation: mediaLoadSpin 1.1s linear infinite reverse;
}
/* Inner ring — primary-light arc, clockwise, fastest */
.media-loading-ring span:nth-child(3) {
    inset: 20px;
    border-top-color: var(--primary-light);
    border-right-color: rgba(var(--primary-rgb), 0.45);
    animation: mediaLoadSpin 0.7s linear infinite;
}
@keyframes mediaLoadSpin {
    to { transform: rotate(360deg); }
}

/* "SalmasFLIX" wordmark — same split as the site logo, breathing pulse.
   Animation paused by default; only runs when overlay has .is-loading. */
.media-loading-brand {
    display: flex;
    align-items: baseline;
    font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    font-weight: 800;
    letter-spacing: 0.02em;
    font-size: clamp(0.95rem, 1.4vw, 1.25rem);
    animation: mediaLoadPulse 1.8s ease-in-out infinite;
    animation-play-state: paused;
    user-select: none;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.media-loading-overlay.is-loading .media-loading-brand {
    animation-play-state: running;
}
.media-loading-brand .ml-salmas {
    background: linear-gradient(180deg, #fff 0%, rgba(255,255,255,0.65) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.media-loading-brand .ml-flix {
    background: linear-gradient(135deg, var(--primary), var(--secondary), var(--secondary-dark));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
@keyframes mediaLoadPulse {
    0%, 100% { opacity: 0.7; letter-spacing: 0.02em; }
    50%      { opacity: 1;   letter-spacing: 0.05em; }
}

/* In fullscreen, scale up the ring a touch for readability on big screens */
.media-fs .media-loading-ring {
    width: clamp(96px, 11vw, 140px);
    height: clamp(96px, 11vw, 140px);
}
.media-fs .media-loading-brand {
    font-size: clamp(1.05rem, 1.6vw, 1.45rem);
}

/* ── Surface mutex banner (paired with extension overlay banner) ────
   Covers the sync tab when the user has the extension overlay open
   and watching. Banner is fixed-position center. Only renders when
   .sfx-mutex-locked is on body. */
.sfx-mutex-banner {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    padding: 14px 22px;
    background: rgba(13, 11, 30, 0.94);
    border: 1px solid rgba(var(--secondary-rgb), 0.5);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.4;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    backdrop-filter: blur(14px) saturate(180%);
    text-align: center;
    max-width: 380px;
}
.sfx-mutex-banner.visible {
    display: inline-flex;
}
.sfx-mutex-banner .sfx-mutex-icon {
    color: var(--secondary-soft);
    flex-shrink: 0;
}
/* Dim the sync tab transport when locked. Body class ensures it
   propagates to the right scope without depending on which subtree
   the user is in. */
body.sfx-mutex-locked .media-bottom-controls,
body.sfx-mutex-locked #media-player-area {
    opacity: 0.35;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* ── Reaction burst overlay (Strategy item #3 — partner reactions) ───
   Emoji float-up animation triggered by tapping #media-reaction-btn or
   receiving a `media-reaction-burst` socket event. Bursts are transient
   children of #media-reactions; each cleans itself up on animationend.
   Pure-CSS keyframe — no JS animation loop. */
.media-reactions {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 80px;
    height: 60vh;
    pointer-events: none;
    z-index: 19;
    overflow: hidden;
}
.media-reaction {
    position: absolute;
    bottom: 0;
    font-size: clamp(2rem, 3.5vw, 2.8rem);
    line-height: 1;
    text-align: center;
    pointer-events: none;
    will-change: transform, opacity;
    animation: media-reaction-rise 2.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.65);
}
@keyframes media-reaction-rise {
    0%   { transform: translate(-50%, 0) scale(0.4); opacity: 0; }
    10%  { transform: translate(-50%, -8vh) scale(1.1); opacity: 1; }
    50%  { transform: translate(-50%, -32vh) scale(1.0); opacity: 0.95; }
    100% { transform: translate(-50%, -56vh) scale(0.9); opacity: 0; }
}

/* Reaction button — heart icon styled to match the other transport
   ctrl buttons. Slight secondary-color tint when idle so it reads as
   distinct from playback controls (it's an emotion thing, not a
   playback thing). */
.media-reaction-btn {
    color: var(--secondary-soft) !important;
}
.media-reaction-btn:hover {
    color: var(--secondary) !important;
    transform: scale(1.08);
}
.media-reaction-btn:active {
    transform: scale(0.94);
}

.media-chat-messages-wrap {
    position: absolute;
    bottom: 80px;
    left: 8px;
    width: 320px;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.media-player-wrap.media-show .media-chat-messages-wrap,
.media-fs.media-fs-show .media-chat-messages-wrap {
    opacity: 1;
}

.media-chat-overlay-messages {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 10px 4px;
    /* STABLE height — does NOT grow on hover / media-show. Previously it
       expanded from 12vh to 18vh when controls appeared and shrank back
       on auto-hide, producing a jarring resize every ~2.5s. Locked with
       !important so nothing can override; hover rule below only flips
       pointer-events + scrollability. */
    max-height: clamp(90px, 14vh, 140px) !important;
    font-size: 0.8rem;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
    scrollbar-width: none;
    overflow-y: auto;
    pointer-events: auto;
}
.media-chat-overlay-messages::-webkit-scrollbar { display: none; }

/* Chat input inline in the transport row */
.media-chat-inline {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 1;
    min-width: 0;
    max-width: 200px;
}


.media-chat-msg {
    display: flex;
    gap: 5px;
    padding: 2px 0;
    font-size: 0.75rem;
    background: none;
    width: fit-content;
    max-width: 90%;
    opacity: 1;
}
.media-chat-msg .mcm-name {
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}
.media-chat-msg.mcm-me .mcm-name {
    color: var(--secondary-soft);
}
.media-chat-msg .mcm-text {
    color: rgba(255, 255, 255, 0.85);
    word-break: break-word;
}
.media-chat-msg .mcm-time { display: none; }
.media-chat-msg .mcm-tag {
    display: inline-block;
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--secondary-soft);
    background: rgba(var(--secondary-rgb), 0.18);
    padding: 1px 5px;
    border-radius: 4px;
    margin-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@keyframes chatMsgFade {
    0% { opacity: 0; transform: translateY(6px); }
    8% { opacity: 1; transform: translateY(0); }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

.media-chat-overlay-input {
    display: flex;
    gap: 6px;
    padding: 2px 8px 3px;
}
.media-chat-overlay-input-field {
    flex: 1;
    min-width: 0;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(var(--primary-rgb), 0.12);
    border-radius: 18px;
    color: #fff;
    font-family: inherit;
    font-size: 0.75rem;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
.media-chat-overlay-input-field:focus {
    border-color: rgba(var(--primary-rgb), 0.3);
    background: rgba(255, 255, 255, 0.06);
}
.media-chat-overlay-input-field::placeholder {
    /* Phase 8.5 contrast — was 0.3 (well below AA). */
    color: var(--text-placeholder);
}
.media-chat-overlay-emoji-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.06);
}
.media-chat-overlay-emoji-btn:hover,
.media-chat-overlay-emoji-btn.active {
    background: rgba(255, 255, 255, 0.2);
    color: var(--primary);
    box-shadow: 0 0 12px rgba(var(--primary-rgb),0.2);
}
/* Phones: no room for an emoji picker, and the native keyboard already has
   one. Hide the emoji button so the chat input + playback controls breathe. */
/* breakpoint snap 600px -> 768px (Phase 7.6 ladder) */
/* Phase 7.7: !important stripped — media query is later in source at
   same specificity as the base .media-chat-overlay-emoji-btn rule;
   #media-chat-emoji-picker has no competing rule. */
@media (max-width: 768px) {
    .media-chat-overlay-emoji-btn,
    #media-chat-emoji-picker {
        display: none;
    }
}
.media-chat-overlay-send {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    flex-shrink: 0;
}
.media-chat-overlay-send:hover { transform: scale(1.1); }

/* Emoji picker — FLOATS as a popover anchored to the bottom of the chat wrap
   (just above the chat input). Absolute-positioned so it doesn't push the
   messages list. */
.media-chat-overlay-emoji-picker {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(20, 18, 30, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-height: 150px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;   /* wrap has pointer-events:none by default */
}
.media-chat-overlay-emoji-picker span {
    font-size: 1.2rem;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s;
}
.media-chat-overlay-emoji-picker span:hover { background: rgba(255, 255, 255, 0.12); }
.media-chat-overlay-emoji-picker::-webkit-scrollbar { width: 4px; }
.media-chat-overlay-emoji-picker::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* Floating emoji reaction bubbles intentionally removed — emojis from
   chat now just render as regular messages in the chat overlay. */

/* --- Queue Section --- */
.media-queue-section {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-width: 100%;
    overflow: hidden;
}

/* breakpoint snap 600px -> 768px (Phase 7.6 ladder) */
@media (max-width: 768px) {
    .media-queue-list {
        /* Show max 4 cards on phone */
        max-height: calc(4 * 56px + 3 * 4px);
    }
    .media-queue-scroll-wrapper {
        max-height: calc(4 * 56px + 3 * 4px);
    }
}

/* ==========================================================================
   Sync tab viewport lock (matches games / therapy convention).
   --------------------------------------------------------------------------
   When the sync tab is the active tab, `.gallery-section.lock-layout` is
   applied by gallery.js (same toggle used for games + therapy). This sets
   `display: flex; flex-direction: column; height: 100dvh; overflow: hidden`
   on the gallery-section. For the LOCK to cascade correctly into the sync
   content, every wrapper between `#gallery-section` and the scrollable
   queue list must be `flex: 1; min-height: 0` — otherwise the queue keeps
   its old fixed max-height and the overflow bleeds out the bottom of the
   screen.

   Guarded by `body[data-active-tab="sync"]` so these rules never affect
   media/diary/therapy/games (where .media-room is referenced but laid out
   differently). Also scoped to `.lock-layout` so desktop visitors who
   haven't triggered the lock (if any path skips it) still see the old
   natural-flow layout.
   ========================================================================== */
body[data-active-tab="sync"] .gallery-section.lock-layout #sync-content {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* .tab-content has `padding: 0 16px 16px` by default — the bottom
       pad eats viewport height. Keep the horizontal breathing room but
       drop the bottom pad so the queue can reach the viewport floor.
       Phase 7.7: !important stripped — selector specificity 1,3,1 beats
       the `.tab-content` default (0,1,0) and the fs-active rule (0,2,1). */
    padding-bottom: 0;
}
body[data-active-tab="sync"] .gallery-section.lock-layout .media-room {
    flex: 1 1 auto;
    min-height: 0;
    padding: 4px 0 0;
    overflow: hidden;
}
body[data-active-tab="sync"] .gallery-section.lock-layout #media-connected:not(.hidden) {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
/* Queue section: grows to fill remaining space. Queue list itself handles
   the scroll via overflow-y:auto, but its old fixed max-height must be
   cleared so it can expand/contract with the flexbox. */
body[data-active-tab="sync"] .gallery-section.lock-layout .media-queue-section {
    flex: 1 1 auto;
    min-height: 60px;
    overflow: hidden;
    /* Lift last queue item above iOS home indicator (env() = 0 on non-iOS)
       + a tiny 8px breathing gap so the wrapper never touches the screen
       floor / home indicator even when the queue is long. Applied at ALL
       breakpoints so landscape phones / small tablets also clear. */
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}
body[data-active-tab="sync"] .gallery-section.lock-layout .media-queue-scroll-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    /* Phase 7.7: !important stripped — 0,4,1 specificity beats the
       phone media-query rule at 0,1,0 that pins max-height. */
    max-height: none;
    /* IMPORTANT: keep default flex-direction (row). The wrapper holds the
       queue list + an iOS custom-drawn scrollbar track as side-by-side
       children. An earlier version set `flex-direction: column` here
       which stacked the track BELOW the list, putting the scrollbar in
       the bottom-left of the queue on iPhone. */
}
body[data-active-tab="sync"] .gallery-section.lock-layout .media-queue-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

/* ----- Phone-specific sync-tab tightening -----
   On phones even after the player shrinks to clamp(180px, 32dvh, 230px)
   the remaining stack (input row + dedication + queue header + items)
   can still be too crowded. This block:
     1. Drops the inter-row gap from clamp(6, 1.2dvh, 12) to 4px so we
        reclaim ~12-16px across 3 gaps.
     2. Hides .media-dedication-row ("Add a note") — it's an optional
        nice-to-have; dedications can still be added from the dedication
        toggle when on desktop. Saves ~24px of vertical on phone.
     3. Adds a 12px bottom gap inside the queue section so the last queue
        item doesn't touch the viewport floor — gives the "space at the
        bottom" breathing room.
     4. Trims the queue-header's margin-bottom from 8 to 6.                 */
/* Subtle glass "card" framing on the queue list wrapper — applies at
   ALL viewport sizes (laptop + phone). Very light hairline border +
   translucent background tint; border-radius so it reads as a contained
   surface. Internal padding keeps the first/last queue items from
   touching the border. */
body[data-active-tab="sync"] .gallery-section.lock-layout .media-queue-scroll-wrapper {
    border: 1px solid rgba(var(--secondary-rgb), 0.18);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
    padding: 4px;
    box-sizing: border-box;
}

/* breakpoint snap 600px -> 768px (Phase 7.6 ladder) */
@media (max-width: 768px) {
    body[data-active-tab="sync"] .gallery-section.lock-layout #media-connected:not(.hidden) {
        gap: 4px;
    }
    /* Phase 7.7: !important stripped — 0,4,1 specificity already beats
       all other .media-dedication-row rules. */
    body[data-active-tab="sync"] .gallery-section.lock-layout .media-dedication-row {
        display: none;
    }
    body[data-active-tab="sync"] .gallery-section.lock-layout .media-queue-section {
        /* Lift last queue item above iOS home indicator (env() = 0 on non-iOS,
           so desktop/Android keep the same 12px breathing room). */
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    body[data-active-tab="sync"] .gallery-section.lock-layout .media-queue-header {
        margin-bottom: 6px;
    }
}

/* When TikTok is playing, show fewer queue cards to save space */
.media-player-area.tiktok-mode ~ .media-queue-section .media-queue-list {
    max-height: calc(3 * 56px + 2 * 4px);
}
.media-player-area.tiktok-mode ~ .media-queue-section .media-queue-scroll-wrapper {
    max-height: calc(3 * 56px + 2 * 4px);
}

.media-queue-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.media-queue-label {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 0;
}

.media-queue-count {
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.7rem;
}

.media-queue-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    /* Show max 5 cards on desktop, scroll for the rest */
    max-height: calc(5 * 56px + 4 * 4px);
    padding: 2px;
    /* Always-visible purple scrollbar — never auto-hide */
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--secondary-rgb),0.6) rgba(13, 11, 30, 0.3);
}

/* Desktop/Android: native custom scrollbar */
.media-queue-list::-webkit-scrollbar {
    width: 6px;
    display: block;
}

.media-queue-list::-webkit-scrollbar-track {
    background: rgba(13, 11, 30, 0.3);
    border-radius: 10px;
}

.media-queue-list::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(var(--secondary-rgb),0.7), rgba(100, 50, 150, 0.9));
    border-radius: 10px;
    min-height: 30px;
}

/* Scroll wrapper: list + custom scrollbar side by side */
.media-queue-scroll-wrapper {
    display: flex;
    position: relative;
    max-height: calc(5 * 56px + 4 * 4px);
}

.media-queue-scroll-wrapper .media-queue-list {
    flex: 1;
    min-width: 0;
}

/* Custom scrollbar track — hidden on desktop (native scrollbar works), shown on iOS */
.media-queue-scrollbar-track {
    display: none;
}

@supports (-webkit-touch-callout: none) {
    /* iOS Safari: hide native scrollbar by clipping it off */
    .media-queue-scroll-wrapper .media-queue-list {
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        -ms-overflow-style: none;
        padding-right: 10px;
        margin-right: -10px;
        clip-path: inset(0 10px 0 0);
    }
    .media-queue-list::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }
    .media-queue-scrollbar-track {
        display: block;
        width: 6px;
        background: rgba(13, 11, 30, 0.3);
        border-radius: 10px;
        margin-left: 4px;
        flex-shrink: 0;
        position: relative;
    }
    .media-queue-scrollbar-thumb {
        width: 100%;
        background: linear-gradient(180deg, rgba(var(--secondary-rgb),0.7), rgba(100, 50, 150, 0.9));
        border-radius: 10px;
        position: absolute;
        top: 0;
        min-height: 20px;
        transition: top 0.1s ease-out;
    }
    /* Hide custom track when queue doesn't overflow */
    .media-queue-scrollbar-track.hidden {
        display: none;
    }
}

.media-playlist-empty {
    color: rgba(255, 255, 255, 0.2);
    text-align: center;
    padding: var(--spacing-lg);
    font-size: 0.85rem;
}

.media-queue-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    min-height: 52px;
    flex-shrink: 0;
    /* iOS PWA / Safari fix: kill the 300ms double-tap-zoom delay so a
       single tap fires `click` immediately. Without this, tapping a
       queue item on iPhone PWA either felt unresponsive or didn't
       switch at all (the click was being eaten by the gesture-detect
       window). `manipulation` enables pan + pinch zoom but disables
       double-tap zoom on the element itself. */
    touch-action: manipulation;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.media-queue-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Alone-locked queue rows: visual signal that tapping won't change
   the playing item — only Together mode can mutate the shared queue.
   Slight desaturation + not-allowed cursor + dimmed hover so the
   click affordance is suppressed at every level (visual, semantic,
   AND functional via the toast-only onclick in player-render.ts). */
.media-queue-item.alone-locked {
    cursor: not-allowed;
    opacity: 0.72;
}
.media-queue-item.alone-locked:hover {
    background: rgba(255, 255, 255, 0.025);
    border-color: rgba(255, 255, 255, 0.04);
}
.media-queue-item.alone-locked.active {
    /* Active item still highlighted, just slightly dimmer than full
       Together-mode active styling so it's clear the queue isn't
       editable right now. */
    opacity: 0.85;
}

.media-queue-item.active {
    border-color: rgba(var(--primary-rgb),0.4);
    background: linear-gradient(135deg, rgba(var(--primary-rgb),0.1), rgba(var(--primary-rgb),0.04));
    box-shadow: 0 0 8px rgba(var(--primary-rgb),0.1);
}

.media-queue-num {
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.media-queue-thumb {
    width: 48px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    /* Themed placeholder tile so still-loading / broken images look
       intentional instead of showing the browser's broken-image icon. */
    background:
        linear-gradient(135deg,
            rgba(var(--primary-rgb), 0.18),
            rgba(var(--secondary-rgb), 0.22));
    border: 1px solid rgba(var(--secondary-rgb), 0.18);
}
/* When YouTube / oEmbed fails, JS sets data-broken="1" so we paint a ▶
   glyph over the gradient tile — no more browser broken-image icon. */
.media-queue-thumb[data-broken="1"] {
    position: relative;
}
.media-queue-thumb[data-broken="1"]::after {
    content: '▶';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 0.82rem;
    opacity: 0.75;
}

.media-queue-id,
.media-queue-title {
    flex: 1;
    min-width: 0;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.media-queue-remove {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.2);
    font-size: 0.85rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.media-queue-remove:hover {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.15);
}

/* ========================================
   GAMES NO-SESSION PROMPTS
   ======================================== */
.games-no-session {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-height: 0;
    gap: var(--spacing-md);
    text-align: center;
    padding: var(--spacing-lg);
}

.games-no-session p {
    color: rgba(255,255,255,0.5);
    font-size: 1rem;
    max-width: 300px;
}

.games-no-session.hidden,
.games-no-session-redesign.hidden {
    display: none;
}

/* Games no-session redesign — dimmed cards with connect overlay */
.games-no-session-redesign {
    position: relative;
    text-align: center;
    padding: clamp(4px, 1dvh, var(--spacing-lg));
    display: flex;
    flex-direction: column;
    max-width: min(97%, 800px);
    margin: 0 auto;
    overflow: visible;
}

.games-no-session-subtitle {
    color: rgba(255, 255, 255, 0.5);
    font-size: clamp(0.65rem, 1.5dvh, 1rem);
    margin-bottom: clamp(2px, 0.8dvh, var(--spacing-md));
}

.games-preview-grid {
    position: relative;
}

.game-card-locked {
    pointer-events: none;
    opacity: 0.35;
    filter: grayscale(0.4) brightness(0.6);
    cursor: default;
}

.games-connect-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(4px, 1dvh, var(--spacing-sm));
    margin-top: clamp(12px, 2.5dvh, 2rem);
    padding: clamp(8px, 1.5dvh, var(--spacing-lg));
    background: rgba(25, 20, 50, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(var(--secondary-rgb),0.15);
    border-radius: var(--radius-lg);
}

.games-lock-icon {
    font-size: clamp(1rem, 2.5dvh, 2rem);
}

.games-connect-overlay p {
    color: rgba(255, 255, 255, 0.5);
    font-size: clamp(0.65rem, 1.5dvh, 0.9rem);
}

.games-connect-overlay .ttt-btn {
    font-size: clamp(0.6rem, 1.4dvh, 0.85rem);
    padding: clamp(4px, 0.8dvh, 8px) clamp(10px, 2vw, 20px);
}

/* Old media playback controls removed — now using .media-transport */

#yt-player-container iframe {
    border-radius: var(--radius-lg);
}

.tiktok-embed-wrapper {
    width: 100%;
    height: 100%;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

/* Phase 7.7: !important stripped — same specificity as .media-player-area
   iframe above, later source order wins. */
.tiktok-embed-wrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 12px;
}

.tiktok-embed-wrapper:fullscreen,
.tiktok-embed-wrapper:-webkit-full-screen {
    background: #000;
}

.tiktok-embed-wrapper:fullscreen iframe,
.tiktok-embed-wrapper:-webkit-full-screen iframe {
    height: 100vh !important;
    max-width: 100vw;
    border-radius: 0;
}

/* Hide native fullscreen button on video — we use our own */
#media-native-video::-webkit-media-controls-fullscreen-button { display: none !important; }
#media-native-video::-webkit-media-controls-toggle-closed-captions-button { display: none !important; }

/* Custom fullscreen button overlay */
.media-fs-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 20;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.media-player-area:hover .media-fs-btn {
    opacity: 1;
}
.media-fs-btn:hover { background: rgba(0, 0, 0, 0.7); }
.media-player-area:fullscreen .media-fs-btn,
.media-player-area:-webkit-full-screen .media-fs-btn {
    top: 16px;
    right: 16px;
}

/* Player area fullscreen (fallback for YouTube) */
.media-player-area:fullscreen,
.media-player-area:-webkit-full-screen {
    background: #000;
}

/* Phase 7.7: !important stripped — adding :fullscreen pseudo to the
   parent bumps specificity by 1, beating the unpseudo'd
   .media-player-area iframe sibling without !important. */
.media-player-area:fullscreen iframe,
.media-player-area:-webkit-full-screen iframe {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
}
.media-player-area:fullscreen video,
.media-player-area:-webkit-full-screen video {
    width: 100vw;
    height: 100vh;
}
.media-player-area:fullscreen {
    position: relative;
}

/* ============================================================
   SKIP PULSE (mobile double-tap left/right for ±10s + key feedback)
   Triggered by .media-skip-pulse-show class, auto-removed after
   ~600ms animation. Shown on both native and YT players.
   ============================================================ */
.media-skip-pulse {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 22;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100px;
    height: 100px;
    justify-content: center;
    border-radius: 50%;
    background: radial-gradient(circle,
        rgba(var(--primary-rgb), 0.35),
        rgba(var(--primary-rgb), 0.08) 60%,
        transparent 75%);
    color: var(--primary);
    pointer-events: none;
    opacity: 0;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.3px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    filter: drop-shadow(0 0 10px rgba(var(--primary-rgb), 0.4));
}
.media-skip-pulse-back { left: 12%; }
.media-skip-pulse-fwd  { right: 12%; }
.media-skip-pulse.media-skip-pulse-show {
    animation: mediaSkipPulse 0.6s ease-out;
}
@keyframes mediaSkipPulse {
    0%   { opacity: 0; transform: translateY(-50%) scale(0.6); }
    25%  { opacity: 1; transform: translateY(-50%) scale(1.1); }
    60%  { opacity: 1; transform: translateY(-50%) scale(1);   }
    100% { opacity: 0; transform: translateY(-50%) scale(0.9); }
}
/* Smaller on narrow phones so the pulse doesn't overlap the other side */
/* breakpoint snap 500px -> 480px (Phase 7.6 ladder — narrows 481-500
   slightly; those phones fall through to 768 bucket, visually equivalent) */
@media (max-width: 480px) {
    .media-skip-pulse { width: 80px; height: 80px; font-size: 0.7rem; }
    .media-skip-pulse-back { left: 8%; }
    .media-skip-pulse-fwd  { right: 8%; }
}

/* ============================================================
   VOLUME / MUTE PULSE — centered bar + icon + % shown briefly
   Triggered on ↑, ↓, M key presses.
   ============================================================ */
.media-vol-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    z-index: 23;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 26px;
    background: rgba(10, 7, 22, 0.85);
    border: 1.5px solid rgba(var(--primary-rgb), 0.5);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5),
                0 0 24px rgba(var(--primary-rgb), 0.25);
    color: var(--primary);
    pointer-events: none;
    opacity: 0;
    font-family: 'Outfit', sans-serif;
}
.media-vol-pulse.media-vol-pulse-show {
    animation: mediaVolPulseAnim 0.9s ease-out;
}
@keyframes mediaVolPulseAnim {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.88); }
    20%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    75%  { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}
.media-vol-pulse-icon svg {
    width: 30px;
    height: 30px;
    color: var(--primary);
    filter: drop-shadow(0 0 6px rgba(var(--primary-rgb), 0.6));
}
.media-vol-pulse-bar {
    width: 140px;
    height: 5px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    overflow: hidden;
}
.media-vol-pulse-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 3px;
    transform-origin: left center;
    transition: width 0.2s ease;
    box-shadow: 0 0 8px rgba(var(--primary-rgb), 0.5);
}
.media-vol-pulse-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
/* Muted state: fill is empty + icon/label turn red-muted tint */
.media-vol-pulse.media-vol-pulse-muted .media-vol-pulse-fill {
    width: 0 !important;
}
.media-vol-pulse.media-vol-pulse-muted .media-vol-pulse-icon svg {
    color: #ff6b6b;
    filter: drop-shadow(0 0 6px rgba(255, 107, 107, 0.5));
}
.media-vol-pulse.media-vol-pulse-muted .media-vol-pulse-label {
    color: #ff6b6b;
}
/* breakpoint snap 500px -> 480px (Phase 7.6 ladder — narrows 481-500
   slightly; those phones fall through to 768 bucket, visually equivalent) */
@media (max-width: 480px) {
    .media-vol-pulse { padding: 16px 20px; gap: 8px; }
    .media-vol-pulse-bar { width: 110px; }
    .media-vol-pulse-icon svg { width: 26px; height: 26px; }
}

/* Temp toast: fade in, stay visible briefly, fade out (6s) */
.media-chat-msg.mcm-temp {
    animation: chatMsgFade 6s ease forwards;
}


/* Queue panel — overlays top-right */
.media-fs .media-queue-section {
    position: absolute;
    top: 0;
    right: 0;
    width: 280px;
    max-height: 60vh;
    background: rgba(var(--secondary-rgb),0.06);
    border: none;
    border-radius: 0 0 0 10px;
    /* Notch-safe top-right (landscape flipped orientation's notch). */
    padding: calc(10px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 10px 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 8;
}
.media-fs .media-queue-section .media-queue-list {
    max-height: none;
    flex: 1;
    overflow-y: auto;
}
.media-fs .media-queue-header {
    flex-shrink: 0;
}

/* "+" button in the queue header — hidden by default (the URL bar below the
   player already serves this purpose in normal mode). Only shown in fullscreen
   where the URL bar is invisible. */
.media-queue-add-btn {
    margin-left: auto;
    width: 24px;
    height: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(var(--primary-rgb), 0.4);
    background: rgba(var(--primary-rgb), 0.15);
    color: var(--primary);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}
.media-fs .media-queue-add-btn {
    display: inline-flex;
}
/* Popover is also only relevant when the button is visible */
.media-queue-add-popover { display: none; }
.media-fs .media-queue-add-popover:not(.hidden) { display: flex; }
.media-queue-add-btn:hover {
    background: rgba(var(--primary-rgb), 0.3);
    transform: scale(1.08);
}

/* Clear-queue button — sibling of the add button. Same circular shape /
   size for visual consistency, but red-tinted to signal destructive
   intent. Auto-hidden when queue is empty (toggled in JS). The
   `margin-left: auto` only fires on whichever of the two siblings is
   the FIRST visible one — drop it here so the add button keeps its
   "push to far right" anchor. */
.media-queue-clear-btn {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, border-color 0.15s;
    flex-shrink: 0;
    margin-left: 6px;
}
/* If clear button is visible AND comes BEFORE the add button in DOM,
   give it the "push to right" anchor instead so add-btn sits next. */
.media-queue-header .media-queue-clear-btn[style*="inline-flex"] {
    margin-left: auto;
}
.media-queue-header .media-queue-clear-btn[style*="inline-flex"] + .media-queue-add-btn {
    margin-left: 6px;
}
.media-queue-clear-btn:hover {
    /* No scale transform — the parent .media-queue-section has
       `overflow: hidden` (needed for the queue-list scroll) which
       clipped the button's top edge when it grew on hover. Color
       emphasis is the SOTA pattern for small icon affordances anyway:
       brighter red bg + ring + slightly stronger border. */
    background: rgba(239, 68, 68, 0.28);
    border-color: rgba(239, 68, 68, 0.7);
    color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}
.media-queue-clear-btn:active {
    background: rgba(239, 68, 68, 0.4);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.18);
}

/* Popover dropped below the queue header — smart command center.
   Typing a URL adds it directly; typing anything else filters the library
   inline with live results. Prominent "Browse full library" fallback. */
.media-queue-add-popover {
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    margin-top: 8px;
    background: linear-gradient(160deg, rgba(20, 14, 38, 0.95), rgba(12, 8, 24, 0.97));
    border: 1px solid rgba(var(--primary-rgb), 0.35);
    border-radius: 14px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: relative;
    z-index: 9;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5),
                0 0 24px rgba(var(--primary-rgb), 0.18);
    animation: mediaQueueAddIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 320px;
    width: 280px;
}
@keyframes mediaQueueAddIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.media-queue-add-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 0 2px;
}
.media-queue-add-header-icon {
    width: 13px;
    height: 13px;
    color: var(--primary);
}

/* Input field with inline search icon on left + add-URL arrow button on right */
.media-queue-add-inputwrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 6px 0 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 9px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.media-queue-add-inputwrap:focus-within {
    border-color: rgba(var(--primary-rgb), 0.55);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}
.media-queue-add-inputicon {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.media-queue-add-url {
    flex: 1;
    min-width: 0;
    padding: 9px 0;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
}
.media-queue-add-url::placeholder {
    /* Phase 8.5 contrast */
    color: var(--text-placeholder);
}
.media-queue-add-commit {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(var(--primary-rgb), 0.2);
    color: var(--primary);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, transform 0.12s ease;
    flex-shrink: 0;
}
.media-queue-add-commit:hover {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    transform: scale(1.08);
}

/* Live-search results — hidden when empty */
.media-queue-add-results {
    display: none;
    flex-direction: column;
    max-height: 280px;
    overflow-y: auto;
    padding: 4px 0;
    margin: 0 -4px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.media-queue-add-results.open {
    display: flex;
}
.media-queue-add-result {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 8px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    background: transparent;
    border: none;
    color: #fff;
    text-align: left;
    transition: background 0.12s ease;
}
.media-queue-add-result:hover,
.media-queue-add-result:focus-visible {
    background: rgba(var(--primary-rgb), 0.15);
    outline: none;
}
.media-queue-add-result img {
    width: 32px;
    height: 44px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
}
.media-queue-add-result-body {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.media-queue-add-result-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.media-queue-add-result-meta {
    font-size: 0.68rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2px;
    display: flex;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.media-queue-add-result-type {
    color: var(--primary);
    font-weight: 600;
}
.media-queue-add-result-empty {
    padding: 12px 10px;
    text-align: center;
    font-size: 0.76rem;
    /* Phase 8.5 contrast */
    color: var(--text-muted);
}

/* Right-edge chevron on show search results — signals "click to drill in" */
.media-queue-add-result-chev {
    color: var(--primary);
    font-size: 1.2rem;
    line-height: 1;
    font-weight: 300;
    padding: 0 4px 0 6px;
    opacity: 0.6;
    transition: opacity 0.15s, transform 0.15s;
    flex-shrink: 0;
}
.media-queue-add-result-show:hover .media-queue-add-result-chev,
.media-queue-add-result-show:focus-visible .media-queue-add-result-chev {
    opacity: 1;
    transform: translateX(3px);
}

/* Drill-down view header (Back + show thumb + title) inside queue-add popover */
.media-queue-add-drill-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px 8px;
    border-bottom: 1px solid rgba(var(--primary-rgb), 0.18);
    margin-bottom: 6px;
}
.media-queue-add-drill-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    background: rgba(var(--secondary-rgb), 0.18);
    border: 1px solid rgba(var(--secondary-rgb), 0.4);
    border-radius: 50%;
    color: var(--secondary);
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, background-color 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s, filter 0.15s, opacity 0.15s, transform 0.15s;
    flex-shrink: 0;
}
.media-queue-add-drill-back:hover {
    background: rgba(var(--secondary-rgb), 0.3);
    border-color: rgba(var(--secondary-rgb), 0.6);
    transform: translateX(-1px);
}
.media-queue-add-drill-back svg { display: block; }
.media-queue-add-drill-thumb {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    object-fit: cover;
    flex-shrink: 0;
}
.media-queue-add-drill-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
/* Collapsible season header inside the drill-down. Rendered as a button
   so the whole row is tappable on mobile. Chevron rotates / flips text
   based on aria-expanded. Mirrors the library picker's mlp-season-header
   for a unified feel between the two surfaces (normal + fullscreen). */
.media-queue-add-drill-season-wrap {
    margin-top: 2px;
}
.media-queue-add-drill-season-wrap:first-of-type { margin-top: 0; }
.media-queue-add-drill-season {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 8px;
    margin: 0;
    background: rgba(var(--primary-rgb), 0.08);
    border: 1px solid rgba(var(--primary-rgb), 0.18);
    border-radius: 8px;
    color: var(--primary);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
    text-align: left;
}
.media-queue-add-drill-season:hover,
.media-queue-add-drill-season:focus-visible {
    background: rgba(var(--primary-rgb), 0.16);
    border-color: rgba(var(--primary-rgb), 0.32);
    outline: none;
}
.media-queue-add-drill-season-chev {
    font-size: 0.82rem;
    line-height: 1;
    width: 12px;
    text-align: center;
    color: var(--primary);
    flex-shrink: 0;
}
.media-queue-add-drill-season-label { flex: 1; }
.media-queue-add-drill-season-count {
    font-size: 0.62rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.55);
    background: rgba(var(--primary-rgb), 0.12);
    padding: 2px 7px;
    border-radius: 10px;
    letter-spacing: 0;
    text-transform: none;
}
.media-queue-add-drill-eps {
    display: flex;
    flex-direction: column;
    padding: 4px 0 4px 10px;
}
.media-queue-add-drill-eps.hidden { display: none; }
/* Episode row inside the drill-down — square "E1" chip instead of poster */
.media-queue-add-result-ep {
    padding-left: 8px;
}
.media-queue-add-result-epnum {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--primary-rgb), 0.14);
    border: 1px solid rgba(var(--primary-rgb), 0.3);
    border-radius: 6px;
    color: var(--primary);
    font-weight: 700;
    font-size: 0.74rem;
    flex-shrink: 0;
}

/* Browse full library — prominent call-to-action for the modal experience */
.media-queue-add-browse {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    padding: 9px 12px;
    border-radius: 9px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    background: linear-gradient(135deg,
        rgba(var(--secondary-rgb), 0.2),
        rgba(var(--secondary-rgb), 0.1));
    color: var(--secondary);
    border: 1px solid rgba(var(--secondary-rgb), 0.4);
    cursor: pointer;
    transition: background 0.18s ease, transform 0.12s ease, border-color 0.18s ease;
}
.media-queue-add-browse:hover {
    background: linear-gradient(135deg, var(--secondary), var(--secondary-dark, var(--secondary)));
    color: #fff;
    border-color: var(--secondary);
    transform: translateY(-1px);
}

/* Mobile: make the popover nearly full-width inside the fullscreen overlay
   so tap targets are comfortable. */
/* breakpoint snap 600px -> 768px (Phase 7.6 ladder) */
@media (max-width: 768px) {
    .media-queue-add-popover {
        width: calc(100vw - 40px);
        max-width: 380px;
        right: 10px;
    }
    .media-queue-add-url { font-size: 0.86rem; padding: 10px 0; }
    .media-queue-add-commit { width: 32px; height: 32px; }
}

/* Fullscreen: queue hidden by default, shown via JS.
   Using `visibility: hidden` (in addition to opacity:0) prevents the
   translucent background from bleeding through on some iOS Safari builds
   where opacity animations briefly expose the panel during transitions.
   The transition is staged: visibility waits until after opacity animates. */
.media-fs .media-queue-section {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
    pointer-events: none;
}
.media-fs.media-fs-show .media-queue-section {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.3s ease, visibility 0s linear 0s;
}

/* When controls visible: scrollable chat.
   Normal mode is bounded by player height (not viewport) so chat doesn't spill above the video.
   Fullscreen can use 40vh since the player fills the screen. */
/* Hover / controls-shown: chat keeps the SAME max-height (stable — no
   resize jump) as idle state. Only scroll + interactivity flip on. */
.media-player-wrap.media-show .media-chat-overlay-messages {
    overflow-y: auto;
    pointer-events: auto;
}
/* Hovered in fullscreen: overlay scroll + pointer-events flip, but the
   max-height stays locked via the !important rule on .media-fs above. */
.media-fs.media-fs-show .media-chat-overlay-messages {
    overflow-y: auto;
    pointer-events: auto;
}
/* Phase 7.7: !important stripped — 0,3,0 specificity wins over .media-chat-msg
   (0,1,0 base) and .media-chat-msg.mcm-temp (0,2,0 temp toast) naturally. */
.media-player-wrap.media-show .media-chat-msg,
.media-fs.media-fs-show .media-chat-msg {
    opacity: 1;
    animation: none;
}

/* Bottom controls — overlay inside the player wrapper */
.media-bottom-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 8;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.media-player-wrap.media-show .media-bottom-controls,
.media-fs.media-fs-show .media-bottom-controls {
    opacity: 1;
    pointer-events: auto;
}

/* Time row above seekbar — time pinned to the right */
.media-time-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 0 clamp(10px, 2vw, 24px) 4px;
}

/* Compact sync button living in the time row */
.media-time-sync-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid rgba(var(--primary-rgb),0.32);
    background: rgba(var(--primary-rgb),0.08);
    color: rgba(var(--primary-rgb),0.85);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    line-height: 1;
    transition: background 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, filter 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}
.media-time-sync-btn svg { flex-shrink: 0; }
.media-time-sync-btn:hover {
    background: rgba(var(--primary-rgb),0.18);
    border-color: rgba(var(--primary-rgb),0.55);
    color: var(--primary);
    box-shadow: 0 0 10px rgba(var(--primary-rgb),0.22);
}
.media-time-sync-btn:active {
    transform: scale(0.95);
}
.media-time-sync-btn.syncing svg {
    animation: media-sync-spin 0.8s linear infinite;
}
@keyframes media-sync-spin {
    to { transform: rotate(360deg); }
}

.media-bottom-controls .media-seekbar-wrap {
    padding: 0 clamp(10px, 2vw, 24px);
}

.media-bottom-controls .media-transport {
    background: transparent;
    padding: 6px clamp(6px, 1.2vw, 16px) 8px;
    justify-content: stretch;
}
.media-bottom-controls .media-transport-row {
    width: 100%;
}

/* Subtle glow on buttons for visibility over video.
   NOTE: drop-shadow() on these buttons was recomputing on every video frame
   (expensive GPU composite). Dropped the filter — the existing translucent
   backgrounds + borders give plenty of contrast, and the time/control pills
   below already stand out against the video.
   (Kept the selector for future use if we want a cheap box-shadow instead.) */

/* Seek bar — softer muted tones.
   Phase 7.7: !important stripped — no JS applies `.hidden` to the
   seekbar wrap, so the base `display: none !important` on `.hidden`
   doesn't compete. Book-mode hide rules (1,2,1 specificity) can now
   properly win over this base `display: block`. */
.media-seekbar-wrap {
    display: block;
    padding: 10px 0 4px;
    cursor: pointer;
    z-index: 10;
}
.media-seekbar {
    width: 100%;
    height: 5px;
    background: rgba(var(--secondary-rgb),0.28);
    border-radius: 3px;
    position: relative;
    transition: height 0.15s, background 0.15s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.media-seekbar-wrap:hover .media-seekbar {
    height: 8px;
    background: rgba(var(--secondary-rgb),0.4);
}
.media-seekbar-fill {
    height: 100%;
    background: rgba(var(--primary-rgb),0.6);
    border-radius: 3px;
    width: 0%;
    position: relative;
}
.media-seekbar-wrap:hover .media-seekbar-fill {
    background: rgba(var(--primary-rgb),0.8);
}
.media-seekbar-fill::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(var(--primary-rgb),0.85);
    box-shadow: 0 0 6px rgba(var(--primary-rgb),0.35);
    transition: opacity 0.15s, transform 0.15s;
}
.media-seekbar-wrap:hover .media-seekbar-fill::after {
    background: var(--primary);
    box-shadow: 0 0 8px rgba(var(--primary-rgb),0.55);
}

/* Transport row layout — position:relative so the absolutely-centered
   playback group can pin itself to the row's geometric center. */
.media-transport-row {
    display: flex;
    align-items: center;
    gap: clamp(4px, 1vw, 10px);
    position: relative;
    min-height: 46px; /* holds the row height when center group is absolute */
}

/* Playback controls (prev/back10/play/fwd10/next) — absolute-centered so
   they line up with the big pause overlay regardless of how wide chat or
   the right-hand controls are. */
.media-transport-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: clamp(4px, 1vw, 10px);
    pointer-events: auto;
    z-index: 2;
}
/* Time display — glass pill with themed current-time highlight */
.media-time-display {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    /* Was rgba(0,0,0,0.32) + backdrop-filter: blur(6px). The blur was painted
       over a continually-changing video → re-blurred every frame by the GPU.
       Dropped to a darker opaque-enough bg; still reads as a glass pill visually. */
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(var(--primary-rgb), 0.18);
    border-radius: 999px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.85);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.media-time-display:empty {
    display: none;
}
.media-time-display .mt-current {
    color: var(--primary);
    text-shadow: 0 0 8px rgba(var(--primary-rgb), 0.35);
}
.media-time-display .mt-sep {
    color: rgba(255, 255, 255, 0.35);
    margin: 0 1px;
    font-weight: 400;
}
.media-time-display .mt-duration {
    color: var(--secondary);
    text-shadow: 0 0 8px rgba(var(--secondary-rgb), 0.3);
}
/* In fullscreen, ramp it up a touch for readability */
.media-fs .media-time-display {
    font-size: 0.82rem;
    padding: 4px 12px;
    border-color: rgba(var(--primary-rgb), 0.28);
}
.media-transport-spacer { flex: 1; }

/* ==========================================
   ACCESSIBILITY + PERF — respect user motion preferences.
   When the user's OS reports `prefers-reduced-motion: reduce`, kill all the
   infinite animations and heavy filters. This is both an accessibility win
   (no vestibular discomfort) and a perf escape hatch (laptop users can flip
   the OS setting to tame an overheating browser). Industry-standard guard.
   ========================================== */
@media (prefers-reduced-motion: reduce) {
    .media-loading-ring span,
    .media-loading-brand,
    .media-paused-icon {
        animation: none !important;
    }
    .media-paused-icon,
    .media-loading-ring span {
        filter: none !important;
    }
    * {
        transition-duration: 0.01ms !important;
    }
}


} /* end @layer features */
