/* YouTube videos that load on click (see assets/js/video.js).
   A bookmark card whose link points to a YouTube video is shown as the video's still with a play button.
   Nothing here needs JavaScript: without it the still is simply a link to YouTube. */

.gh-content .kg-bookmark-card:has(> .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"])) {
    width: 100%;
}

.gh-content .kg-bookmark-card > .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: visible;
    color: inherit;
    text-decoration: none;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-thumbnail {
    position: relative;
    flex: none;
    order: 1;
    width: 100%;
    min-width: 0;
    max-height: none;
    aspect-ratio: 16 / 9;
    background-color: #000000;
}

.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-thumbnail img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
}

/* Play button: a white disc with a dark triangle */
.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-thumbnail::before,
.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-thumbnail::after {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 1;
    content: "";
}

.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-thumbnail::before {
    width: 84px;
    height: 84px;
    margin: -42px 0 0 -42px;
    background-color: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 24px rgba(0, 0, 0, 0.5);
    transition: transform 0.15s;
}

.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-thumbnail::after {
    margin: -16px 0 0 -9px;
    border-color: transparent transparent transparent #15171a;
    border-style: solid;
    border-width: 16px 0 16px 26px;
}

.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]):hover .kg-bookmark-thumbnail::before {
    transform: scale(1.08);
}

/* Under the still: the video's title only */
.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-content {
    display: block;
    flex: none;
    order: 2;
    padding: 12px 0 0;
}

.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) .kg-bookmark-title {
    font-size: 1.6rem;
    font-weight: 600;
    color: inherit;
}

.gh-content .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"]) :is(.kg-bookmark-description, .kg-bookmark-metadata) {
    display: none;
}

/* The player that replaces the still after the click */
.gh-video-player {
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #000000;
}

.gh-video-player iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

/* On a Book page the video uses the full width of the page, not the narrower text column */
#main-content .gh-book-content > hr ~ .kg-bookmark-card:has(> .kg-bookmark-container:is([href*="youtube.com/watch"], [href*="youtu.be/"])),
#main-content .gh-book-content > hr ~ .kg-bookmark-card:has(> .gh-video-player) {
    max-width: none;
}

@media (prefers-reduced-motion: reduce) {
    .gh-content .kg-bookmark-container .kg-bookmark-thumbnail::before {
        transition: none;
    }
}
