[data-gallery] a[aria-haspopup="dialog"] {
  position: relative;
  display: inline-block;
  max-inline-size: 100%;
  vertical-align: middle;
  line-height: 0;
  cursor: pointer;
}
/* Size the link with its thumbnail so the zoom icon stays on the image. */
.post a[aria-haspopup="dialog"]:has(> img[width="500"]) { inline-size: 500px; }
.post a[aria-haspopup="dialog"] > img[width="500"] { inline-size: 100%; block-size: auto; }
@media (650px < width <= 950px) {
  .post a[aria-haspopup="dialog"]:has(> img[width="500"]) { inline-size: 275px; }
}
@media (650px < width <= 905px) {
  .post a[aria-haspopup="dialog"]:has(> img[width="500"]) { inline-size: 250px; }
}
@media (650px < width <= 790px) {
  .post a[aria-haspopup="dialog"]:has(> img[width="500"]) { inline-size: 210px; }
}
[data-gallery] a[aria-haspopup="dialog"]::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url('https://i.simonenko.xyz/gallery-zoom.svg') center / 90px 90px no-repeat;
  opacity: 0;
  pointer-events: none;
}
[data-gallery] a[aria-haspopup="dialog"]:is(:hover, :focus-visible)::after { opacity: 1; }
.instagram [data-gallery] a[aria-haspopup="dialog"]::after { inset: 4px 4px 16px; }
html:has(.gallery[open]) { overflow: hidden; }
.gallery {
  --focus-color: #82e0ff;
  box-sizing: border-box;
  inline-size: 100%;
  block-size: 100dvh;
  max-inline-size: none;
  max-block-size: none;
  margin: 0;
  padding: 50px 50px 40px;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.gallery[open] { display: grid; place-items: center; }
.gallery::backdrop { background: rgb(0 0 0 / 80%); }
.gallery p, .gallery form, .gallery figure { margin: 0; }
.gallery form, .gallery-navigation { display: contents; }
.gallery figure { inline-size: 100%; min-inline-size: 0; }
.gallery-caption {
  overflow: hidden;
  margin-block-end: 10px;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  font-size: 1.4rem;
  line-height: 1.7rem;
}
.gallery-caption:empty { display: none; }
.gallery-stage { position: relative; min-block-size: 1.7rem; touch-action: pan-y pinch-zoom; }
.gallery-image {
  display: block;
  inline-size: auto;
  block-size: auto;
  max-inline-size: 100%;
  max-block-size: calc(100dvh - 100px - 1.7rem);
  margin-inline: auto;
  object-fit: contain;
}
.gallery-stage[data-pending] .gallery-image { visibility: hidden; }
.gallery-status { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.gallery-status:empty { display: none; }
.gallery button {
  position: absolute;
  inset-block-start: 8px;
  inline-size: 44px;
  block-size: 44px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #fff;
  font: 28px / 1 sans-serif;
}
.gallery-prev { inset-inline-start: 8px; }
.gallery-next { inset-inline-end: 8px; }
.gallery-prev, .gallery-next { opacity: .5; }
.gallery :is(.gallery-prev, .gallery-next):is(:hover, :focus-visible):enabled { opacity: 1; }
.gallery-prev::before, .gallery-next::before {
  content: '';
  display: inline-block;
  border-block: 8px solid transparent;
}
.gallery-prev::before { border-inline-end: 8px solid currentColor; }
.gallery-next::before { border-inline-start: 8px solid currentColor; }
.gallery-close { inset-inline-start: calc(50% - 22px); }
.gallery-original { position: absolute; inset-block-end: 12px; inset-inline-start: 50%; transform: translateX(-50%); color: #fff; }
.gallery-counter, .gallery-close:not(:focus-visible), .gallery-original:not(:focus-visible) {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (max-width: 600px) {
  .gallery { padding-inline: 20px; }
}
