/* Layout and motion for the movie and show grids and their details drawer.
   Colours live in palette.css. */

/* Gaps are the old tile margins, which made 7 movies or 6 shows exactly fill the old 1386px page. */
#movie-list,
#show-list
{
    display: grid;

    margin-top: 80px;
    margin-bottom: 55px;

    justify-content: space-between;
}

#movie-list
{
    grid-template-columns: repeat(auto-fill, 174px);
    gap: 0 2em;
}

#show-list
{
    grid-template-columns: repeat(auto-fill, 213px);
    gap: 0 1.53em;
}

/* Thousands of movie tiles made every drawer frame slow; skipped tiles keep their 174x303 size so the page doesn't jump. */
#movie-list > .index-preview
{
    content-visibility: auto;
    contain-intrinsic-size: 174px 303px;
}

/* content-visibility clips a tile to its box, and the open tile draws outside it: the scaled poster, its shadow, the pointer and the ribbon. */
#movie-list > .index-preview.open
{
    content-visibility: visible;
}

/* A 0fr row grows to the content's real height as it becomes 1fr, so no height has to be guessed. */
.info
{
    display: grid;
    grid-column: 1 / -1;
    /* A plain column would grow to its widest unbreakable child, pushing the details off a narrow screen. */
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 0fr;

    margin-top: 0;
    /* Out through the page's side margins to the window's edges; 100vw would also count a scrollbar and scroll sideways. */
    margin-inline: calc(-1 * var(--gutter));

    transition: grid-template-rows .25s ease-in, margin-top .25s ease-in, border-color .25s ease-in;

    border-top: 1px solid transparent;
    border-bottom: 1px solid transparent;
}

.info.open
{
    grid-template-rows: 1fr;

    margin-top: 20px;

    transition: grid-template-rows .35s cubic-bezier(.2, .8, .2, 1), margin-top .35s cubic-bezier(.2, .8, .2, 1), border-color .35s;
}

.info-wrapper
{
    overflow: hidden;

    min-height: 0;
    /* The drawer spans the window; its content keeps the page's side margins. */
    padding-inline: var(--gutter);

    transition: height .35s cubic-bezier(.2, .8, .2, 1);
}

/* Transforms don't affect layout, so the open poster grows without moving its neighbours. */
.index-preview img,
.index-preview-show img
{
    transition: transform .3s ease-in-out, box-shadow .3s ease-in-out;
    transform-origin: top center;
}

.index-preview.open img,
.index-preview-show.open img
{
    position: relative;
    z-index: 2;

    transform: translateY(-10px) scale(1.115);
}

.index-preview .truncate
{
    transition: opacity .2s;
}

.index-preview.open .truncate
{
    opacity: 0;
}

.pointer,
.show-pointer
{
    position: absolute;
    /* Under the open poster, so its shadow darkens the pointer along with the drawer edge around it. */
    z-index: 1;
    bottom: -28px;
    left: 50%;

    width: 15px;
    height: 15px;

    transition: opacity .2s;
    transform: translateX(-50%) rotate(45deg);
    pointer-events: none;

    opacity: 0;
    border-radius: 2px;
}

.open .pointer,
.open .show-pointer
{
    transition-delay: .15s;

    opacity: 1;
}

.open .new-label
{
    top: 10px;
    right: -10px;

    width: 70px;
    height: 70px;
}

.open .new-text
{
    font-size: 16px;
}

/* A fixed shape, so the details don't move when the poster loads; the background is the image already on screen until then.
   Chrome draws a failed or empty image inline as its alt text, ignoring its size, unless it is a block. */
#meta-data .description-poster img
{
    display: block;
    aspect-ratio: 2 / 3;
    object-fit: contain;

    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

/* After the movie rule, which matches a show's poster too. Show posters come square or, from TMDB, portrait. */
#info-header > .description-poster img
{
    aspect-ratio: 1;
}

@media (prefers-reduced-motion: reduce)
{
    .info,
    .info.open,
    .info-wrapper,
    .index-preview img,
    .index-preview-show img,
    .index-preview .truncate,
    .pointer,
    .show-pointer,
    .open .pointer,
    .open .show-pointer,
    .new-label,
    .new-text
    {
        transition: none;
    }
}
