/* 1. Make the anchor a block element sized strictly by its contents */
figure.captioned > a {
  display: block;
  width: fit-content;
  max-width: 100%;
}

/* 2. Remove inline gaps and keep the image responsive */
figure.captioned picture,
figure.captioned img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* 3. Tell the browser to ignore caption text when calculating parent width */
figure.captioned figcaption {
  contain: inline-size;
}