/* The newest Instagram posts as pictures of the website itself:
   3 columns, 2 below 600px, portrait 3:4, 20px apart. */
.instagram-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.instagram-grid a {
    display: block;
    overflow: hidden;
}

.instagram-grid img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    transition: transform 0.4s ease, opacity 0.4s ease;
}

.instagram-grid a:hover img,
.instagram-grid a:focus-visible img {
    transform: scale(1.04);
    opacity: 0.85;
}

@media (min-width: 600px) {
    .instagram-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* A post opened large: picture and its text, dark as on Instagram.
   The page's reset takes the margins, so the dialog is centred here. */
.instagram-popup {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(1100px, calc(100vw - 32px));
    height: fit-content;
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 0;
    background: #0b1120;
    color: #fff;
    overflow: visible;
}

/* While a post is open, the page behind stays where it is. */
html:has(.instagram-popup[open]) {
    overflow: hidden;
}

.instagram-popup button:focus {
    outline: none;
}

.instagram-popup button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.instagram-popup::backdrop {
    background: rgba(2, 6, 23, 0.9);
}

.instagram-popup__body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    max-height: calc(100dvh - 32px);
    margin: 0;
}

.instagram-popup__body img {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: 60dvh;
    object-fit: contain;
    background: #000;
}

.instagram-popup figcaption {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding: 20px 24px 24px;
}

.instagram-popup time {
    font-size: 12px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    opacity: 0.6;
}

.instagram-popup figcaption p {
    margin: 0;
    overflow-y: auto;
    white-space: pre-line;
    line-height: 1.6;
    font-size: 15px;
}

.instagram-popup figcaption a {
    align-self: flex-start;
    color: var(--color-neon-pink, #c63995);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    text-decoration: none;
}

.instagram-popup figcaption a:hover {
    color: #fff;
}

.instagram-popup__close,
.instagram-popup__prev,
.instagram-popup__next {
    position: absolute;
    z-index: 1;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(2, 6, 23, 0.7);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.instagram-popup__close:hover,
.instagram-popup__prev:hover,
.instagram-popup__next:hover {
    background: var(--color-neon-pink, #c63995);
}

.instagram-popup__close {
    top: 8px;
    right: 8px;
}

.instagram-popup__prev,
.instagram-popup__next {
    top: 30dvh;
    transform: translateY(-50%);
}

.instagram-popup__prev {
    left: 8px;
}

.instagram-popup__next {
    right: 8px;
}

@media (min-width: 900px) {
    .instagram-popup__body {
        grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
        grid-template-rows: minmax(0, 1fr);
        height: min(760px, calc(100dvh - 32px));
    }

    .instagram-popup__body img {
        height: 100%;
        max-height: none;
    }

    .instagram-popup figcaption {
        padding: 56px 28px 28px;
    }

    .instagram-popup__prev,
    .instagram-popup__next {
        top: 50%;
    }
}

/* Wide enough: the arrows sit beside the post. */
@media (min-width: 1240px) {
    .instagram-popup__prev {
        left: -60px;
    }

    .instagram-popup__next {
        right: -60px;
    }
}
