.ig-yt {
    --ig-yt-gap: 25px;
    --ig-yt-border: #dce0e4;
    --ig-yt-placeholder: #eef0f2;
    --ig-yt-radius: 10px;
    --ig-yt-columns: var(--ig-yt-desktop, 5);
    position: relative;
    width: 100%;
    min-width: 0;
}

/* Same reason as the Instagram carousel: a builder column centring widgets would size
   the section to its captions, so the tiles changed with title length. */
.elementor-widget:has(.ig-yt) {
    width: 100%;
    align-self: stretch;
    flex-shrink: 999;
}

.ig-yt[data-desktop="1"] { --ig-yt-desktop: 1; }
.ig-yt[data-desktop="2"] { --ig-yt-desktop: 2; }
.ig-yt[data-desktop="3"] { --ig-yt-desktop: 3; }
.ig-yt[data-desktop="4"] { --ig-yt-desktop: 4; }
.ig-yt[data-desktop="6"] { --ig-yt-desktop: 6; }

.ig-yt[data-tablet="1"] { --ig-yt-tablet: 1; }
.ig-yt[data-tablet="2"] { --ig-yt-tablet: 2; }
.ig-yt[data-tablet="4"] { --ig-yt-tablet: 4; }
.ig-yt[data-tablet="5"] { --ig-yt-tablet: 5; }
.ig-yt[data-tablet="6"] { --ig-yt-tablet: 6; }

.ig-yt[data-mobile="2"] { --ig-yt-mobile: 2; }
.ig-yt[data-mobile="3"] { --ig-yt-mobile: 3; }

.ig-yt .ig-yt-track {
    display: grid;
    grid-template-columns: repeat(var(--ig-yt-columns), minmax(0, 1fr));
    gap: var(--ig-yt-gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ig-yt-carousel .ig-yt-viewport {
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x mandatory;
    overscroll-behavior-inline: contain;
}

.ig-yt-carousel .ig-yt-track {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - (var(--ig-yt-columns) - 1) * var(--ig-yt-gap)) / var(--ig-yt-columns));
}

.ig-yt .ig-yt-card {
    min-width: 0;
    margin: 0;
    padding: 0;
    scroll-snap-align: start;
}

.ig-yt .ig-yt-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.ig-yt-cover {
    position: relative;
    display: block;
    aspect-ratio: 9 / 16;
    overflow: hidden;
    border: 1px solid var(--ig-yt-border);
    border-radius: var(--ig-yt-radius);
    background: var(--ig-yt-placeholder);
}

.ig-yt-play {
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    display: grid;
    place-items: center;
    /* Measured from Instagram's own badge: ~29% of the card width, black at .38. */
    width: 29%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: rgb(0 0 0 / .38);
    color: #fff;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.ig-yt-play svg {
    width: 74%;
    height: 74%;
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 1;
    stroke-linejoin: round;
}

.ig-yt .ig-yt-cover img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    object-fit: cover;
}

/* Same type, spacing and arrow as the Instagram carousel's .ig-post-link. */
.ig-yt .ig-yt-caption,
.ig-yt .ig-yt-all {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 2px;
    box-sizing: border-box;
    color: #171b20;
    font: 500 12px/1.4 system-ui, sans-serif;
}

/* Titles: at most two lines, and every caption reserves two so a row stays even. */
.ig-yt-titles .ig-yt-caption {
    align-items: flex-start;
    min-height: calc(2 * 1.4em + 16px);
}

.ig-yt-titles .ig-yt-caption > span {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.ig-yt-caption {
    justify-content: space-between;
    overflow-wrap: anywhere;
}

.ig-yt-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 20px;
    margin-top: 4px;
}

.ig-yt .ig-yt-all {
    padding: 8px 16px;
    border: 1px solid #dce0e4;
    border-radius: 999px;
    background: #fff;
    text-decoration: none;
}

.ig-yt .ig-yt-all:hover {
    background: #eef0f2;
}

.ig-yt-link:hover .ig-yt-caption {
    text-decoration: underline;
}

.ig-yt :is(.ig-yt-caption, .ig-yt-all) svg {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}

.ig-yt-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.ig-yt-controls[hidden] { display: none; }

.ig-yt-position {
    color: #626972;
    font: 500 12px/1.2 system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
    letter-spacing: .06em;
}

/* Same arrows as the Instagram carousel: solid ink, white chevron, soft shadow. */
.ig-yt .ig-yt-controls button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #171b20;
    color: #fff;
    box-shadow: 0 2px 10px rgb(23 27 32 / .22);
    cursor: pointer;
    transition: background .15s ease, opacity .2s ease, visibility .2s;
}

.ig-yt .ig-yt-controls button:hover:not([aria-disabled="true"]) {
    background: #3a414b;
}

.ig-yt .ig-yt-controls button[aria-disabled="true"] {
    opacity: .25;
    cursor: default;
}

.ig-yt-controls svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.ig-yt:dir(rtl) .ig-yt-controls svg {
    transform: rotate(180deg);
}

.ig-yt :is(a, button, .ig-yt-viewport):focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.ig-yt .ig-yt-link:focus-visible {
    outline-offset: -3px;
}

/* Wider screens: arrows sit on the card edges at mid-height (set by youtube.js), as on Instagram. */
@media (min-width: 768px) {
    .ig-yt .ig-yt-controls button {
        position: absolute;
        z-index: 2;
        top: var(--ig-yt-mid, 40%);
        width: 46px;
        height: 46px;
        transform: translateY(-50%);
    }
    .ig-yt .ig-yt-controls [data-move="-1"] { inset-inline-start: 8px; }
    .ig-yt .ig-yt-controls [data-move="1"] { inset-inline-end: 8px; }
    .ig-yt .ig-yt-controls button[aria-disabled="true"] {
        opacity: 0;
        visibility: hidden;
    }
}

@media (min-width: 1025px) {
    .ig-yt[data-fits-desktop] .ig-yt-controls { display: none; }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .ig-yt { --ig-yt-columns: var(--ig-yt-tablet, 3); }
    .ig-yt[data-fits-tablet] .ig-yt-controls { display: none; }
}

@media (max-width: 767px) {
    .ig-yt {
        --ig-yt-columns: var(--ig-yt-mobile, 1);
        --ig-yt-gap: 14px;
    }
    .ig-yt[data-fits-mobile] .ig-yt-controls { display: none; }
}
