/* My Library (/library) + profile shelves + inline-playing reel shelves. JS: public/js/media-shelves.js */

/* Page: left rail + one wide column (no right rail) */
@media (min-width: 981px) {
    .social-page-shell.lib-page-shell { grid-template-columns: var(--sv-rail-w, 240px) minmax(0, 1fr) !important; max-width: 1400px !important; }
}
.lib-main { min-width: 0; display: grid; gap: 18px; align-content: start; }
.lib-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lib-head h1 { margin: 0; font-size: 28px; }
.lib-head p { margin: 4px 0 0; color: #64748b; font-size: 14px; }
.lib-upload { display: inline-flex; align-items: center; min-height: 40px; padding: 0 18px; border-radius: 999px; background: #2563eb; color: #fff; font-weight: 700; text-decoration: none; }
.lib-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.lib-tabs a { flex: 0 0 auto; padding: 8px 16px; border-radius: 10px; background: #f1f5f9; color: #0f172a; font-weight: 600; font-size: 14px; text-decoration: none; }
.lib-tabs a small { color: #64748b; font-weight: 500; margin-left: 4px; }
.lib-tabs a.is-active { background: #0f172a; color: #fff; }
.lib-tabs a.is-active small { color: #cbd5e1; }

/* Shelves */
.lib-shelf { display: grid; gap: 12px; }
.lib-shelf > header { display: flex; align-items: center; justify-content: space-between; }
.lib-shelf h2 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.lib-shelf h2 small { font-size: 14px; color: #64748b; font-weight: 500; }
.lib-shelf > header a { font-weight: 600; color: #2563eb; text-decoration: none; font-size: 14px; }
.lib-ico { color: #ef4444; }
.lib-none { margin: 0; padding: 18px; border: 1px dashed #cbd5e1; border-radius: 14px; color: #64748b; text-align: center; }
.lib-none a { color: #2563eb; font-weight: 600; }

.lib-grid { display: grid; gap: 16px 12px; }
.lib-grid-reels { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.lib-grid-videos { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.lib-grid-photos { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; }
.lib-grid-posts { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* Tiles */
.lib-tile { min-width: 0; display: grid; gap: 8px; align-content: start; }
.lib-thumb { position: relative; display: block; width: 100%; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: #0f172a; cursor: pointer; text-decoration: none; color: inherit; }
.lib-video .lib-thumb { aspect-ratio: 16 / 9; }
.lib-reel .lib-thumb { aspect-ratio: 9 / 16; }
.lib-photo .lib-thumb { aspect-ratio: 1 / 1; border-radius: 4px; background: #e2e8f0; }
.lib-thumb img, .lib-thumb video { width: 100%; height: 100%; display: block; }
/* Videos: whole frame visible (1:1, 9:16 or 16:9) on black, like YouTube. Reels fill their 9:16 tile. Photos crop to square. */
.lib-video .lib-thumb img, .lib-video .lib-thumb video { object-fit: contain; }
.lib-reel .lib-thumb img, .lib-reel .lib-thumb video, .lib-photo .lib-thumb img { object-fit: cover; }
.lib-thumb:hover img, .lib-thumb:focus-visible img { transform: scale(1.03); }
.lib-thumb img { transition: transform .25s ease; }
.lib-play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 30px; opacity: 0; background: rgba(0,0,0,.25); transition: opacity .2s; pointer-events: none; }
.lib-thumb:hover .lib-play, .lib-thumb:focus-visible .lib-play { opacity: 1; }
.lib-dur { position: absolute; right: 6px; bottom: 6px; padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,.8); color: #fff; font: 600 12px/1.3 inherit; }
.lib-badge { position: absolute; left: 6px; top: 6px; padding: 3px 8px; border-radius: 6px; background: #f59e0b; color: #111827; font: 700 11px/1.3 inherit; font-style: normal; }
.lib-tile.is-failed .lib-badge { background: #dc2626; color: #fff; }
.lib-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #64748b; font-size: 34px; }
.lib-meta { display: grid; gap: 2px; padding: 0 2px; }
.lib-title { color: #0f172a; font-weight: 600; font-size: 14px; line-height: 1.35; text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-meta small { color: #64748b; font-size: 12.5px; }
.lib-text-thumb { aspect-ratio: 4 / 3; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #eef2ff, #fdf2f8); color: #1e293b; font-weight: 600; line-height: 1.4; text-align: center; }

/* In-page player */
.lib-player { width: min(96vw, 1100px); max-height: 94dvh; padding: 0; border: 0; border-radius: 16px; background: #000; overflow: visible; }
.lib-player::backdrop { background: rgba(2, 6, 23, .85); }
.lib-player-close { position: absolute; right: -6px; top: -44px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #fff; color: #0f172a; font-size: 24px; line-height: 38px; cursor: pointer; }
.lib-player-stage { display: grid; place-items: center; }
.lib-player-stage video, .lib-player-stage img { display: block; max-width: 100%; max-height: 88dvh; width: auto; height: auto; border-radius: 16px; background: #000; }
.lib-player-stage.is-video video { width: 100%; aspect-ratio: var(--ratio, 16 / 9); object-fit: contain; }
.lib-player-stage.is-reel video { height: 88dvh; aspect-ratio: 9 / 16; width: auto; object-fit: cover; }
.lib-player:has(.is-reel), .lib-player:has(.is-photo) { width: auto; }

/* Profile page reuses the shelves */
.lib-in-profile { display: grid; gap: 22px; }

/* Reco shelves (feed / reels): arrows, inline play, sound */
.sv-reco-shelf { position: relative; }
.sv-shelf-arrow { position: absolute; top: 50%; z-index: 3; width: 34px; height: 34px; margin-top: -17px; border: 0; border-radius: 50%; background: rgba(255,255,255,.95); box-shadow: 0 2px 10px rgba(0,0,0,.2); color: #0f172a; font-size: 22px; line-height: 32px; cursor: pointer; opacity: 0; transition: opacity .2s; }
.sv-shelf-arrow.is-prev { left: 4px; }
.sv-shelf-arrow.is-next { right: 4px; }
.sv-reco-carousel:hover .sv-shelf-arrow { opacity: 1; }
@media (hover: none) { .sv-shelf-arrow { display: none; } }
.sv-reco-track { scroll-behavior: auto; scrollbar-width: none; }
.sv-reco-track::-webkit-scrollbar { display: none; }
.sv-reco-reel-card { cursor: pointer; flex-basis: 120px; }
.sv-reco-reel-card video { position: absolute; inset: 0; }
.sv-reel-sound, .sv-reel-open { position: absolute; z-index: 2; width: 28px; height: 28px; border: 0; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 13px; line-height: 28px; text-align: center; text-decoration: none; cursor: pointer; }
.sv-reel-sound { right: 6px; bottom: 44px; display: none; }
.sv-reel-open { left: 6px; top: 6px; }
.sv-reco-reel-card.is-playing .sv-reel-sound { display: block; }
.sv-reco-reel-card.is-playing .sv-reco-reel-play { display: none; }
.sv-reco-reel-card.is-playing { outline: 2px solid #ef4444; outline-offset: -2px; }
.sv-reco-reel-card .sv-reco-reel-views, .sv-reco-reel-card .sv-reco-reel-author { z-index: 1; }

@media (max-width: 640px) {
    .lib-head h1 { font-size: 22px; }
    .lib-grid-reels { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
    .lib-grid-videos { grid-template-columns: 1fr; }
    .lib-grid-photos { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .lib-player-close { right: 6px; top: 6px; z-index: 2; }
    .lib-player-stage.is-reel video { height: 80dvh; }
}
