/* ---- Videos --------------------------------------------------------------
   The cards (tools/lib/videos.mjs) and the player (js/videos.js).

   Standalone: loaded by the home page, which carries etalon.css, and by the
   litter pages, which carry style.css and carrousel.css. So nothing here leans
   on either — only on tokens.css, which every page has. */

/* The band on a litter page, between the tree and the share card. The home
   page and /archives use their own .block for width and heading. */
.videos:not(.block) {
    max-width: 60rem;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-md) 0;
}

.videos-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 400;
    text-align: center;
    margin: 0 0 var(--space-lg);
    color: var(--color-ink);
}

.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: var(--space-lg) var(--space-md);
    list-style: none;
    margin: 0;
    padding: 0;
}

.video-card-link {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    color: var(--color-ink);
    text-decoration: none;
    border-radius: 0.75rem;
}

.video-card-link:focus-visible {
    outline: 3px solid var(--heart-1);
    outline-offset: 4px;
}

/* One shape for every card, so a grid of mixed clips stays a grid. 4:3 crops
   a landscape clip lightly; an upright one is not cropped at all — see
   .video-card--tall. The whole clip always plays in the player. */
.video-card-frame {
    position: relative;
    display: block;
    aspect-ratio: 4 / 3;
    border-radius: 0.75rem;
    overflow: hidden;
    background: var(--color-surface);
    box-shadow: 0 6px 18px rgb(58 47 42 / 14%);
}

.video-card-frame img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    transition: transform var(--motion-base) var(--ease-out);
}

/* Upright and square clips: whole, centred, over their own still blurred to
   fill the card (tools/lib/videos.mjs decides which). The URL is root-relative
   because a url() carried in a custom property resolves against the stylesheet
   that USES it in some browsers and the element that sets it in others. */
.video-card--tall .video-card-frame img {
    position: relative;
    object-fit: contain;
}

.video-card--tall .video-card-frame::before {
    content: '';
    position: absolute;
    inset: -12%;
    background: var(--poster) center / cover no-repeat;
    filter: blur(18px) brightness(0.72) saturate(1.1);
}

.video-card-link:hover .video-card-frame img,
.video-card-link:focus-visible .video-card-frame img {
    transform: scale(1.04);
}

/* The play mark: a disc with a triangle, drawn rather than shipped. */
.video-card-play {
    position: absolute;
    inset: 50% auto auto 50%;
    width: 3.5rem;
    height: 3.5rem;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgb(20 14 10 / 55%);
    box-shadow: 0 0 0 2px rgb(255 255 255 / 85%) inset;
    transition: background var(--motion-base) var(--ease-out);
}

.video-card-play::after {
    content: '';
    position: absolute;
    inset: 50% auto auto 54%;
    transform: translate(-50%, -50%);
    border-style: solid;
    border-width: 0.65rem 0 0.65rem 1.05rem;
    border-color: transparent transparent transparent #fff;
}

.video-card-link:hover .video-card-play,
.video-card-link:focus-visible .video-card-play {
    background: rgb(20 14 10 / 78%);
}

.video-card-time {
    position: absolute;
    right: 0.5rem;
    bottom: 0.5rem;
    padding: 0.1rem 0.45rem;
    border-radius: 0.4rem;
    background: rgb(20 14 10 / 68%);
    color: #fff;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.video-card-title {
    font-size: var(--text-base);
    line-height: 1.3;
    text-wrap: balance;
}

/* In the archive: which litter a clip comes from. */
.video-card-origin {
    margin-top: -0.2rem;
    font-size: var(--text-sm);
    color: var(--color-ink-soft);
}

.video-card .sr-only,
.video-dialog .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.videos-more {
    margin: var(--space-md) 0 0;
    text-align: center;
    font-weight: 700;
}

.videos-more a {
    color: var(--color-field);
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

.videos-empty {
    color: var(--color-ink-soft);
}

/* ---- The player ---------------------------------------------------------- */

.video-dialog {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgb(0 0 0 / 92%);
    color: #fff;
}

.video-dialog::backdrop {
    background: transparent;
}

.video-open body {
    overflow: hidden;
}

.video-dialog-body {
    position: relative;
    box-sizing: border-box;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 3.5rem var(--space-sm) var(--space-md);
}

.video-dialog-player {
    display: block;
    width: auto;
    height: auto;
    max-width: min(100%, 72rem);
    /* Room under it for the caption and the paws. */
    max-height: calc(100% - 4.5rem);
    border-radius: 0.6rem;
    background: #000;
}

.video-dialog-close {
    position: absolute;
    top: 0.25rem;
    right: 0.5rem;
    width: 3rem;
    height: 3rem;
    border: 0;
    background: none;
    color: #fff;
    font-size: 2.5rem;
    line-height: 1;
    cursor: pointer;
}

.video-dialog-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    max-width: 100%;
}

.video-dialog-caption {
    margin: 0;
    text-align: center;
    font-size: 1.05rem;
    text-wrap: balance;
}

.video-dialog-count {
    color: rgb(255 255 255 / 60%);
    font-variant-numeric: tabular-nums;
}

.video-dialog-step {
    flex: none;
    width: 3rem;
    height: 3rem;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgb(255 255 255 / 18%);
    cursor: pointer;
    transition: background var(--motion-base) var(--ease-out);
}

.video-dialog-step[hidden] {
    display: none;
}

.video-dialog-step:hover {
    background: rgb(255 255 255 / 34%);
}

.video-dialog-paw {
    width: 1.6rem;
    height: 1.6rem;
    filter: brightness(0) invert(1);
}

.video-dialog-paw.is-prev { transform: rotate(270deg); }
.video-dialog-paw.is-next { transform: rotate(90deg); }

.video-dialog-close:focus-visible,
.video-dialog-step:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* ---- The album's video slide (js/carouselBuilder.js) -------------------- */

.carousel-item--video .carousel-img-container {
    position: relative;
}

.carousel-item--video .video-card-play {
    z-index: 1;
    pointer-events: none;
}

/* An upright clip in the album's wide frame: whole, over its blurred still,
   exactly like its card. */
.carousel-item--tall .carousel-img-container {
    overflow: hidden;
}

.carousel-item--tall .carousel-img-container::before {
    content: '';
    position: absolute;
    inset: -12%;
    background: var(--poster) center / cover no-repeat;
    filter: blur(18px) brightness(0.72) saturate(1.1);
}

.carousel-item--tall .carousel-img {
    position: relative;
    object-fit: contain;
}

/* ...and the same clip in the photo lightbox. */
.zoom-video {
    display: none;
    /* auto, not the width/height attributes: those give the element its aspect
       ratio before metadata arrives, but as sizes they made an upright clip a
       720px square with black bars down both sides. */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 80vh;
    border-radius: 10px;
    background: #000;
}

.image-container.is-video .zoom-video {
    display: block;
}

.image-container.is-video .zoom-image {
    display: none;
}

@media screen and (max-width: 40rem) {
    .zoom-video {
        max-height: min(58svh, 100svh - 17rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .video-card-frame img,
    .video-card-play {
        transition: none;
    }
}
