/* ==========================================================================
   📱 VYNL MOBILE VINYL TOUCH LAYOUT (≤ 768px only)
   Loaded last; everything is scoped to @media (max-width: 768px) + body.mvt-active,
   so desktop & tablet layouts stay exactly as they are.
   ========================================================================== */

/* Elements injected by js/mobile_vinyl_touch.js are invisible outside mobile */
#mvtTransportBar,
#mvtAzToggle { display: none; }

/* Universal Touch Long-Press & Vinyl Extraction Visuals (Phones + Foldables like Pixel 10 Pro Fold) */
#coverFlow .flow-card.mvt-pressing .sleeve,
#crateInlineListView .lib-structured-row.mvt-pressing .lib-row-cover {
    transform: scale(0.965);
    transition: transform 0.42s ease-out;
}
#coverFlow .flow-card.mvt-vinyl-out .sleeve,
#crateInlineListView .lib-structured-row.mvt-vinyl-out .lib-row-cover {
    opacity: 0.5 !important;
    transition: opacity 0.2s ease !important;
}
#drag-disc-clone.mvt-drag-clone {
    box-shadow: 0 22px 48px rgba(0, 0, 0, 0.88), 0 0 0 2.5px rgba(198, 138, 76, 0.92) !important;
}
body.vynl-square-display #coverFlowDrawer.dragging-active:not(.crate-drawer-open) {
    transform: translateX(-100%) !important;
    pointer-events: none !important;
    transition: transform 0.36s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.36s ease !important;
}
body.vynl-square-display #coverFlowDrawer.dragging-active.crate-drawer-open {
    transform: translateX(0) !important;
}
body.vynl-square-display #coverFlowDrawer.dragging-active .drawer-header,
body.vynl-square-display #coverFlowDrawer.dragging-active .card-info,
body.vynl-square-display #coverFlowDrawer.dragging-active .flow-card:not(.card-being-dragged),
body.vynl-square-display #coverFlowDrawer.dragging-active .flow-card:not(.card-being-dragged) .sleeve {
    opacity: 1 !important;
}
body.vynl-square-display #playerDeckSection.drag-hover #platter,
body.vynl-square-display #vinyl-deck.drag-hover #platter {
    box-shadow: 0 0 0 5px rgba(198, 138, 76, 0.8), 0 0 38px rgba(198, 138, 76, 0.65) !important;
}

@media (max-width: 768px) {

    /* ---------- 1. Vertical compression & order: Turntable → Crate → Library ---------- */
    /* --mvt-deck-scale is set numerically on <body> by js/mobile_vinyl_touch.js (fallback ≈ 375px phones) */
    html body.mvt-active,
    html body.mvt-active #coverFlowDrawer,
    html body.mvt-active #coverFlowCarousel,
    html body.mvt-active #coverFlow { --crate-card-size: 176px !important; }

    html body.mvt-active .app-container {
        padding: 4px 6px calc(18px + env(safe-area-inset-bottom, 0px)) 6px !important;
        gap: 6px !important;
    }
    html body.mvt-active .main-layout {
        gap: 8px !important;
    }
    html body.mvt-active .main-layout > .player-column { order: 1 !important; }
    html body.mvt-active .main-layout > #coverFlowDrawer { order: 2 !important; }
    html body.mvt-active .main-layout > .details-column { order: 3 !important; }

    /* Turntable: no section header, tight padding, exact phone-width scale */
    html body.mvt-active #playerDeckSection.deck-card {
        padding: 4px 4px 6px 4px !important;
        margin: 0 !important;
        gap: 0 !important;
        min-height: 0 !important;
        height: auto !important;
    }
    html body.mvt-active #playerDeckSection > .deck-header { display: none !important; }
    html body.mvt-active #playerDeckSection .deck-wrapper {
        position: relative !important;
        display: block !important;
        width: 100% !important;
        height: calc(460px * var(--mvt-deck-scale, 0.65)) !important;
        min-height: calc(460px * var(--mvt-deck-scale, 0.65)) !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
    }
    html body.mvt-active #playerDeckSection #vinyl-deck {
        position: absolute !important;
        top: 0 !important;
        left: 50% !important;
        margin: 0 0 0 -270px !important;
        transform: scale(var(--mvt-deck-scale, 0.65)) !important;
        transform-origin: top center !important;
    }

    /* Full studio deck & duplicate bottom dock hidden – slim bar replaces them (⋯ re-opens the deck) */
    html body.mvt-active #vynlFixedBottomDock { display: none !important; }
    html body.mvt-active #playerStudioDeck { display: none !important; }
    html body.mvt-active.mvt-show-studio #playerStudioDeck {
        display: flex !important;
        position: static !important;
        inset: auto !important;
        width: 100% !important;
        margin: 6px 0 0 0 !important;
        border-radius: 8px !important;
        box-shadow: none !important;
        z-index: auto !important;
    }

    /* ---------- 6. Slim transport bar directly under the turntable ---------- */
    html body.mvt-active #mvtTransportBar { display: none; }
    html body.mvt-active.mvt-record-on #mvtTransportBar {
        display: flex;
        flex-direction: column;
        gap: 0;
        width: 100%;
        margin: 4px 0 0 0;
        background: rgba(14, 14, 20, 0.96);
        color: #f5ecdf;
        border: 1px solid rgba(198, 138, 76, 0.4);
        border-radius: 10px;
        overflow: hidden;
        box-sizing: border-box;
        animation: mvtBarIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }
    @keyframes mvtBarIn {
        from { opacity: 0; transform: translateY(-6px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .mvt-tr-progress { height: 3px; background: rgba(255, 255, 255, 0.1); }
    .mvt-tr-progress-fill {
        height: 100%; width: 0%;
        background: linear-gradient(90deg, #fae0b5, #c68a4c);
        transition: width 0.25s linear;
    }
    .mvt-tr-row {
        display: flex; align-items: center; justify-content: space-between;
        gap: 8px; padding: 5px 8px 5px 12px;
    }
    .mvt-tr-info { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
    .mvt-tr-title {
        font-size: 0.78rem; font-weight: 700; line-height: 1.2;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .mvt-tr-time {
        font-size: 0.68rem; color: rgba(250, 224, 181, 0.75);
        font-variant-numeric: tabular-nums; line-height: 1.2;
    }
    .mvt-tr-btns { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
    .mvt-tr-btn {
        width: 36px; height: 36px; border-radius: 50%;
        display: inline-flex; align-items: center; justify-content: center;
        background: rgba(255, 255, 255, 0.07); color: #f5ecdf;
        border: 1px solid rgba(255, 255, 255, 0.12);
        padding: 0; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    .mvt-tr-btn:active { transform: scale(0.92); }
    .mvt-tr-play {
        width: 42px; height: 42px;
        background: linear-gradient(135deg, #fae0b5 0%, #c68a4c 100%);
        color: #111; border: none;
        box-shadow: 0 3px 12px rgba(198, 138, 76, 0.45);
    }
    .mvt-tr-more { font-size: 1.1rem; font-weight: 800; line-height: 1; }
    html body.mvt-active.mvt-show-studio .mvt-tr-more { background: rgba(198, 138, 76, 0.35); }

    /* ---------- Crate: compact header ---------- */
    html body.mvt-active #coverFlowDrawer.inline-crate-section {
        padding: 6px 6px 8px 6px !important;
        min-height: 0 !important;
    }
    html body.mvt-active #coverFlowDrawer .drawer-header {
        margin: 0 0 2px 0 !important;
        padding: 0 !important;
        gap: 4px !important;
        min-height: 0 !important;
    }
    html body.mvt-active #coverFlowDrawer .crate-header-top-row {
        gap: 6px !important; margin: 0 !important; padding: 0 !important;
        flex-wrap: nowrap !important; align-items: center !important;
    }
    html body.mvt-active #coverFlowDrawer .crate-main-title {
        font-size: 0.76rem !important; letter-spacing: 1.5px !important; margin: 0 !important;
    }
    html body.mvt-active #coverFlowDrawer .view-switch-btn {
        padding: 3px 8px !important; font-size: 0.62rem !important;
    }
    html body.mvt-active #coverFlowDrawer .crate-filter-group {
        display: flex !important; flex-wrap: nowrap !important;
        overflow-x: auto !important; scrollbar-width: none !important;
        gap: 4px !important; margin: 0 !important; padding: 0 !important;
        -webkit-overflow-scrolling: touch;
    }
    html body.mvt-active #coverFlowDrawer .crate-filter-group::-webkit-scrollbar { display: none; }
    html body.mvt-active #coverFlowDrawer .crate-filter-btn {
        flex: 0 0 auto !important; padding: 3px 9px !important; font-size: 0.62rem !important;
        min-height: 0 !important;
    }
    html body.mvt-active #coverFlowDrawer .crate-actions-toolbar {
        gap: 4px !important; margin: 0 !important; padding: 0 !important;
    }
    html body.mvt-active #coverFlowDrawer .crate-actions-toolbar .sort-dropdown-btn,
    html body.mvt-active #coverFlowDrawer .crate-actions-toolbar .sync-crate-highlight-btn {
        padding: 4px 6px !important; font-size: 0.6rem !important; min-height: 0 !important;
    }

    /* Cover Flow: smaller cards, no dead space above */
    html body.mvt-active #coverFlowDrawer:not(.crate-fullscreen-grid) .carousel-section {
        margin-top: 2px !important;
        min-height: calc(var(--crate-card-size) + 34px);
        height: auto !important;
        padding: 0 !important;
    }
    html body.mvt-active #coverFlowDrawer:not(.crate-fullscreen-grid) .flow-card { top: 6px !important; }
    /* -webkit-box-reflect clips the overhanging album info box and costs GPU time on phones */
    html body.mvt-active #coverFlow .flow-card {
        -webkit-box-reflect: unset !important;
        transform-style: flat !important;
        -webkit-transform-style: flat !important;
    }
    html body.mvt-active #coverFlowDrawer #coverFlow.cover-flow-container {
        transform-style: flat !important;
        -webkit-transform-style: flat !important;
        perspective: 900px !important;
    }
    html body.mvt-active #coverFlow .flow-card .card-info {
        z-index: 200 !important;
        transform: translateX(-50%) translateZ(0) !important;
    }

    /* ---------- 3. Long-press visuals ---------- */
    html body.mvt-active #coverFlow .flow-card {
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
    }
    html body.mvt-active #coverFlow .flow-card.mvt-pressing .sleeve {
        transform: scale(0.965);
        transition: transform 0.45s ease-out;
    }
    html body.mvt-active #coverFlow .flow-card.card-being-dragged .sleeve,
    html body.mvt-active #coverFlow .flow-card.mvt-vinyl-out .sleeve {
        opacity: 0.5 !important;
        transition: opacity 0.2s ease !important;
    }
    html body.mvt-active #coverFlow .flow-card.card-being-dragged .vinyl-disc { opacity: 0 !important; }
    /* Desktop drag fades the whole crate to 5% – on phones keep the crate visible, only the source cover dims */
    html body.mvt-active #coverFlowDrawer.dragging-active {
        transform: none !important;
        opacity: 1 !important;
    }
    html body.mvt-active #coverFlowDrawer.dragging-active .drawer-header,
    html body.mvt-active #coverFlowDrawer.dragging-active .card-info,
    html body.mvt-active #coverFlowDrawer.dragging-active .flow-card:not(.card-being-dragged),
    html body.mvt-active #coverFlowDrawer.dragging-active .flow-card:not(.card-being-dragged) .sleeve {
        opacity: 1 !important;
    }
    html body.mvt-active #coverFlowDrawer.dragging-active .flow-card.card-being-dragged .sleeve {
        opacity: 0.5 !important;
        transform: scale(0.96) !important;
    }
    html body.mvt-active #drag-disc-clone.mvt-drag-clone {
        box-shadow: 0 18px 40px rgba(0, 0, 0, 0.85), 0 0 0 2px rgba(198, 138, 76, 0.9) !important;
    }
    html body.mvt-active #playerDeckSection.drag-hover #platter,
    html body.mvt-active #vinyl-deck.drag-hover #platter {
        box-shadow: 0 0 0 4px rgba(198, 138, 76, 0.75), 0 0 30px rgba(198, 138, 76, 0.55) !important;
    }

    /* ---------- 2. Collapsible A–Z bar ---------- */
    html body.mvt-active #crateArtistOverview.crate-artist-overview {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 6px !important;
        margin: 2px 0 0 0 !important;
        padding: 0 !important;
        min-height: 0 !important;
    }
    html body.mvt-active #mvtAzToggle {
        display: inline-flex;
        align-items: center; gap: 4px;
        flex: 0 0 auto;
        height: 30px; padding: 0 11px;
        border-radius: 999px;
        border: 1px solid rgba(198, 138, 76, 0.55);
        background: rgba(198, 138, 76, 0.12);
        color: var(--text-primary, #2b2b36);
        font-size: 0.72rem; font-weight: 800; letter-spacing: 0.5px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    html body.mvt-active #crateArtistOverview.mvt-az-open #mvtAzToggle {
        background: var(--accent, #c68a4c); color: #fff;
    }
    html body.mvt-active #crateArtistNavigator {
        flex: 1 1 0 !important; min-width: 0 !important;
        margin: 0 !important; padding: 0 !important; gap: 4px !important;
    }
    html body.mvt-active #crateArtistNavigator .artist-name { display: none !important; }
    html body.mvt-active #crateArtistNavigator .artist-nav-btn,
    html body.mvt-active #crateArtistNavigator .artist-nav-current {
        min-height: 30px !important; height: 30px !important; padding: 0 8px !important;
    }
    html body.mvt-active #crateArtistNavigator .artist-nav-current { flex: 1 1 auto !important; min-width: 0 !important; }
    html body.mvt-active #crateArtistNavigator .artist-name-active {
        white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
    }

    /* Collapsed by default */
    html body.mvt-active #crateArtistOverview #alphabet-nav,
    html body.mvt-active #crateArtistOverview #crateArtistChipsTrack {
        display: none !important;
    }
    /* Open: single-row horizontal scroll strips */
    html body.mvt-active #crateArtistOverview.mvt-az-open #alphabet-nav,
    html body.mvt-active #crateArtistOverview.mvt-az-open #crateArtistChipsTrack {
        display: flex !important;
        flex: 1 1 100% !important;
        width: 100% !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scrollbar-width: none !important;
        -webkit-overflow-scrolling: touch;
        gap: 4px !important;
        margin: 0 !important;
        padding: 2px 0 !important;
        animation: mvtBarIn 0.22s ease;
    }
    html body.mvt-active #crateArtistOverview.mvt-az-open #alphabet-nav::-webkit-scrollbar,
    html body.mvt-active #crateArtistOverview.mvt-az-open #crateArtistChipsTrack::-webkit-scrollbar { display: none; }
    html body.mvt-active #crateArtistOverview.mvt-az-open #alphabet-nav > span {
        flex: 0 0 auto !important;
        min-width: 30px !important; height: 30px !important;
        display: inline-flex !important; align-items: center !important; justify-content: center !important;
        touch-action: manipulation;
    }
    html body.mvt-active #crateArtistOverview.mvt-az-open #crateArtistChipsTrack > * { flex: 0 0 auto !important; }

    /* Library below stays freely scrollable */
    html body.mvt-active .details-column { gap: 10px !important; }
}
