:root { --ymw-image-density: 1; }

@media screen and (min-resolution: 1.25dppx) {
  :root { --ymw-image-density: 1.25; }
}
@media screen and (min-resolution: 1.5dppx) {
  :root { --ymw-image-density: 1.5; }
}
@media screen and (min-resolution: 1.75dppx) {
  :root { --ymw-image-density: 1.75; }
}
@media screen and (min-resolution: 2dppx) {
  :root { --ymw-image-density: 2; }
}
@media screen and (min-resolution: 2.5dppx) {
  :root { --ymw-image-density: 2.5; }
}
@media screen and (min-resolution: 3dppx) {
  :root { --ymw-image-density: 3; }
}
@media screen and (min-resolution: 4dppx) {
  :root { --ymw-image-density: 4; }
}

/* These opt-in limits take precedence over the legacy page layouts. */
[data-ymw-image-fit] {
  --ymw-image-max-width: calc(var(--ymw-image-width) / var(--ymw-image-density));
  max-inline-size: min(100%, var(--ymw-image-max-width)) !important;
}

img[data-ymw-image-fit] {
  height: auto;
}

.guide-body a[data-ymw-image-fit] {
  /* The preview link has a 1px border on each side of the screenshot. */
  max-inline-size: min(100%, calc(var(--ymw-image-max-width) + 2px)) !important;
}

.case_preview-l img[data-ymw-image-fit],
.yw-shot img[data-ymw-image-fit],
.showcase-image-wrap img[data-ymw-image-fit] {
  display: block;
  height: auto;
  margin-inline: auto;
}

.showcase-grid[data-ymw-image-gallery] {
  max-width: calc(330px + 28px + 42px + var(--ymw-image-width) / var(--ymw-image-density));
}

.showcase-frame:has(img[data-ymw-image-fit]) {
  display: flex;
  flex-direction: column;
}

.showcase-frame .showcase-image-wrap:has(img[data-ymw-image-fit]) {
  flex: 1;
  display: grid;
  place-items: center;
}

#special .pc-showcase-window[data-ymw-image-fit] {
  max-inline-size: min(100%, calc(var(--ymw-image-max-width) + 16px)) !important;
  width: 100%;
  justify-self: center;
}
