/* ==========================================================================
   COSMEX YouTube Shorts Embed — v2.3.0
   Grid, facade cards, entrance animation, and lightbox player.
   Heights are driven by in-flow content (the card itself), never by
   absolutely-positioned children, so containers always wrap their cards.
   ========================================================================== */

.cosmex-youtube-shorts {
    display: grid;
    grid-template-columns: repeat(var(--cosmex-yts-columns, 3), minmax(0, 1fr));
    gap: var(--cosmex-yts-gap, 18px);
    width: 100%;
    max-width: 100%;
    clear: both;
}

.cosmex-youtube-shorts__item {
    position: relative;
    width: 100%;
}

/* --- Facade card ----------------------------------------------------------
   In normal flow with the aspect-ratio on the card itself: the item and
   grid/carousel always size to the card, even if a theme, page builder,
   or CSS optimizer interferes with the surrounding styles. */

.cosmex-youtube-shorts__card {
    position: relative;
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: var(--cosmex-yts-aspect, 9 / 16);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--cosmex-yts-radius, 12px);
    overflow: hidden;
    background: #0f0f0f;
    cursor: pointer;
    text-align: left;
    font: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease;
}

.cosmex-youtube-shorts--shadow .cosmex-youtube-shorts__card {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.cosmex-youtube-shorts__card:focus-visible {
    outline: 3px solid #ff0033;
    outline-offset: 3px;
}

.cosmex-youtube-shorts__thumb {
    position: absolute;
    inset: 0;
    background-color: #0f0f0f;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), filter 0.35s ease;
}

/* Hover: zoom */
.cosmex-youtube-shorts--hover-zoom .cosmex-youtube-shorts__card:hover .cosmex-youtube-shorts__thumb,
.cosmex-youtube-shorts--hover-zoom .cosmex-youtube-shorts__card:focus-visible .cosmex-youtube-shorts__thumb {
    transform: scale(1.06);
}

/* Hover: glow */
.cosmex-youtube-shorts--hover-glow .cosmex-youtube-shorts__card:hover,
.cosmex-youtube-shorts--hover-glow .cosmex-youtube-shorts__card:focus-visible {
    transform: translateY(-4px);
    box-shadow: 0 14px 34px rgba(255, 0, 51, 0.35);
}

/* --- "Shorts" badge ----------------------------------------------------- */

.cosmex-youtube-shorts__badge {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    padding: 3px 9px;
    border-radius: 999px;
    background: #ff0033;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.5;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

/* --- Gradient overlay --------------------------------------------------- */

.cosmex-youtube-shorts__overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.25) 34%, rgba(0, 0, 0, 0) 58%);
    pointer-events: none;
}

/* --- Play button -------------------------------------------------------- */

.cosmex-youtube-shorts__play {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    transform: translate(-50%, -50%);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s ease;
    pointer-events: none;
}

.cosmex-youtube-shorts__play::before {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.55);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.cosmex-youtube-shorts__card:hover .cosmex-youtube-shorts__play,
.cosmex-youtube-shorts__card:focus-visible .cosmex-youtube-shorts__play {
    background: #ff0033;
    transform: translate(-50%, -50%) scale(1.1);
}

.cosmex-youtube-shorts__card:hover .cosmex-youtube-shorts__play::before,
.cosmex-youtube-shorts__card:focus-visible .cosmex-youtube-shorts__play::before {
    opacity: 1;
    transform: scale(1);
}

/* --- Title -------------------------------------------------------------- */

.cosmex-youtube-shorts__title {
    position: absolute;
    right: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 2;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

/* --- Playing state (facade swapped for iframe) --------------------------- */

.cosmex-youtube-shorts__item.is-playing {
    border-radius: var(--cosmex-yts-radius, 12px);
    overflow: hidden;
    background: #000;
}

.cosmex-youtube-shorts__item.is-playing iframe {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: var(--cosmex-yts-aspect, 9 / 16);
    border: 0;
}

/* --- Entrance animation -------------------------------------------------- */

.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.55s ease, transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item.is-visible {
    opacity: 1;
    transform: none;
}

/* Stagger the first twelve items */
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(2) { transition-delay: 0.05s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(3) { transition-delay: 0.10s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(4) { transition-delay: 0.15s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(5) { transition-delay: 0.20s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(6) { transition-delay: 0.25s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(7) { transition-delay: 0.30s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(8) { transition-delay: 0.35s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(9) { transition-delay: 0.40s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(10) { transition-delay: 0.45s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(11) { transition-delay: 0.50s; }
.cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item:nth-child(12) { transition-delay: 0.55s; }

@media (prefers-reduced-motion: reduce) {
    .cosmex-youtube-shorts--fade .cosmex-youtube-shorts__item {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .cosmex-youtube-shorts__card,
    .cosmex-youtube-shorts__thumb,
    .cosmex-youtube-shorts__play {
        transition: none;
    }
}

/* --- Notice -------------------------------------------------------------- */

.cosmex-youtube-shorts__notice {
    margin: 0;
    color: #555;
    font-size: 14px;
}

/* --- Lightbox ------------------------------------------------------------ */

.cosmex-yts-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

.cosmex-yts-lightbox[hidden] {
    display: none;
}

.cosmex-yts-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 8, 12, 0.88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.cosmex-yts-lightbox.is-open .cosmex-yts-lightbox__backdrop {
    opacity: 1;
}

.cosmex-yts-lightbox__dialog {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    opacity: 0;
    transform: translateY(14px) scale(0.97);
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.cosmex-yts-lightbox.is-open .cosmex-yts-lightbox__dialog {
    opacity: 1;
    transform: none;
}

.cosmex-yts-lightbox__frame-wrap {
    position: relative;
    height: min(78vh, 1280px);
    aspect-ratio: 9 / 16;
    max-width: calc(100vw - 120px);
    border-radius: 16px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.cosmex-yts-lightbox__frame-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.cosmex-yts-lightbox__caption {
    max-width: min(78vw, 420px);
    margin-top: 12px;
    color: rgba(255, 255, 255, 0.92);
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
}

.cosmex-yts-lightbox__close,
.cosmex-yts-lightbox__nav {
    position: fixed;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.cosmex-yts-lightbox__close:hover,
.cosmex-yts-lightbox__nav:hover,
.cosmex-yts-lightbox__close:focus-visible,
.cosmex-yts-lightbox__nav:focus-visible {
    background: #ff0033;
    transform: scale(1.08);
    outline: none;
}

.cosmex-yts-lightbox__close {
    top: 22px;
    right: 22px;
}

.cosmex-yts-lightbox__nav--prev {
    top: 50%;
    left: 22px;
    transform: translateY(-50%);
}

.cosmex-yts-lightbox__nav--next {
    top: 50%;
    right: 22px;
    transform: translateY(-50%);
}

.cosmex-yts-lightbox__nav--prev:hover,
.cosmex-yts-lightbox__nav--next:hover {
    transform: translateY(-50%) scale(1.08);
}

@media (max-width: 640px) {
    .cosmex-yts-lightbox__nav {
        display: none;
    }

    .cosmex-yts-lightbox__frame-wrap {
        max-width: calc(100vw - 48px);
    }
}

body.cosmex-yts-lightbox-open {
    overflow: hidden;
}

/* --- Responsive layout & carousels -----------------------------------------
   Per breakpoint, the grid either stays a grid (columns = columns per row)
   or becomes a horizontal snap carousel (columns = cards visible per view).
   Shared scrollbar styling lives outside the media queries; the flex/scroll
   behaviour itself is gated per breakpoint so each carousel only activates
   in its own viewport range. */

.cosmex-youtube-shorts--desktop-carousel,
.cosmex-youtube-shorts--tablet-carousel,
.cosmex-youtube-shorts--mobile-carousel {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.25) transparent;
}

.cosmex-youtube-shorts--desktop-carousel::-webkit-scrollbar,
.cosmex-youtube-shorts--tablet-carousel::-webkit-scrollbar,
.cosmex-youtube-shorts--mobile-carousel::-webkit-scrollbar {
    height: 4px;
}

.cosmex-youtube-shorts--desktop-carousel::-webkit-scrollbar-track,
.cosmex-youtube-shorts--tablet-carousel::-webkit-scrollbar-track,
.cosmex-youtube-shorts--mobile-carousel::-webkit-scrollbar-track {
    background: transparent;
}

.cosmex-youtube-shorts--desktop-carousel::-webkit-scrollbar-thumb,
.cosmex-youtube-shorts--tablet-carousel::-webkit-scrollbar-thumb,
.cosmex-youtube-shorts--mobile-carousel::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 999px;
}

/* --- Desktop (min-width: 1025px) ------------------------------------------ */

@media (min-width: 1025px) {
    .cosmex-youtube-shorts--desktop-carousel {
        display: flex;
        flex-wrap: nowrap;
        min-width: 0;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        padding-bottom: 10px;
    }

    .cosmex-youtube-shorts--desktop-carousel .cosmex-youtube-shorts__item {
        flex: 0 0 calc(
            (100% - (var(--cosmex-yts-columns, 3) - 1) * var(--cosmex-yts-gap, 18px))
            / var(--cosmex-yts-columns, 3)
        );
        scroll-snap-align: start;
    }
}

/* --- Tablet (768px–1024px) ------------------------------------------------- */

@media (max-width: 1024px) {
    .cosmex-youtube-shorts:not(.cosmex-youtube-shorts--tablet-carousel) {
        grid-template-columns: repeat(var(--cosmex-yts-columns-tablet, 2), minmax(0, 1fr));
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .cosmex-youtube-shorts--tablet-carousel {
        display: flex;
        flex-wrap: nowrap;
        min-width: 0;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        padding-bottom: 10px;
    }

    .cosmex-youtube-shorts--tablet-carousel .cosmex-youtube-shorts__item {
        flex: 0 0 calc(
            (100% - (var(--cosmex-yts-columns-tablet, 2) - 1) * var(--cosmex-yts-gap, 18px))
            / var(--cosmex-yts-columns-tablet, 2)
        );
        scroll-snap-align: start;
    }
}

/* --- Mobile (max-width: 767px) ----------------------------------------------
   Card width uses --cosmex-yts-mobile-visible; decimals (e.g. 1.5) peek the
   next card. Grid mode (carousel off) uses --cosmex-yts-columns-mobile. */

@media (max-width: 767px) {
    .cosmex-youtube-shorts:not(.cosmex-youtube-shorts--mobile-carousel) {
        grid-template-columns: repeat(var(--cosmex-yts-columns-mobile, 1), minmax(0, 1fr));
    }

    .cosmex-youtube-shorts--mobile-carousel {
        display: flex;
        flex-wrap: nowrap;
        min-width: 0;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        padding-bottom: 10px;
    }

    .cosmex-youtube-shorts--mobile-carousel .cosmex-youtube-shorts__item {
        flex: 0 0 calc(
            (100% - (var(--cosmex-yts-mobile-visible, 1.5) - 1) * var(--cosmex-yts-gap, 18px))
            / var(--cosmex-yts-mobile-visible, 1.5)
        );
        scroll-snap-align: start;
    }
}


/* --- Carousel: click-and-drag + arrows --------------------------------------
   Arrows are appended by JS to .cosmex-youtube-shorts-wrap (outside the
   scroll container, so they don't scroll away). Drag works with a mouse;
   touch devices use native swipe. Arrows display on desktop only. */

.cosmex-youtube-shorts-wrap {
    position: relative;
}

.cosmex-youtube-shorts.is-dragging {
    scroll-snap-type: none;
    cursor: grabbing;
    -webkit-user-select: none;
    user-select: none;
}

.cosmex-youtube-shorts.is-dragging * {
    cursor: grabbing !important;
}

.cosmex-youtube-shorts__arrow {
    position: absolute;
    top: 50%;
    z-index: 5;
    display: none;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    margin: 0;
    padding: 0 0 2px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    color: #111;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transform: translateY(-50%);
    transition: opacity 0.25s ease, background 0.2s ease, color 0.2s ease;
}

.cosmex-youtube-shorts__arrow:hover,
.cosmex-youtube-shorts__arrow:focus-visible {
    background: #ff0033;
    color: #fff;
    outline: none;
}

.cosmex-youtube-shorts__arrow--prev {
    left: 10px;
}

.cosmex-youtube-shorts__arrow--next {
    right: 10px;
}

.cosmex-youtube-shorts__arrow.is-hidden {
    opacity: 0;
    pointer-events: none;
}

@media (min-width: 1025px) {
    .cosmex-youtube-shorts--desktop-carousel {
        cursor: grab;
    }

    .cosmex-youtube-shorts--desktop-carousel.is-dragging {
        cursor: grabbing;
    }

    .cosmex-youtube-shorts-wrap .cosmex-youtube-shorts__arrow {
        display: flex;
    }
}
