.media-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--media-container-width), 1fr));
  grid-auto-rows: 1fr;
  grid-gap: var(--padding-small);
}

/* Ensure the shape of the image list entries is square
   plus the media header height. */

.media-list:before {
  content: "";
  width: 0;
  padding-bottom: calc(100% + var(--media-box-header-height));
  grid-row: 1 / 1;
  grid-column: 1 / 1;
}

@media (max-width: $max-limited-desktop-width) {
  .media-list {
    grid-template-columns: repeat(auto-fill, minmax(var(--media-small-container-width), 1fr));
  }
}

.media-list--small {
  grid-template-columns: repeat(auto-fill, minmax(var(--media-small-container-width), 1fr));
}

.media-list--small-fixed-size {
  grid-template-columns: repeat(auto-fill, var(--media-small-container-width));
}

.media-list--small-fixed-size.media-list:before {
  padding-bottom: 0 !important;
}

.media-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto;
  grid-gap: var(--padding-small);
}

.media-box {
  overflow: hidden;
  border: var(--media-border);
}

/* Shift the image list by 1 element introduced due to
   the .media-list:before rule */

.media-box:first-child {
  grid-row: 1 / 1;
  grid-column: 1 / 1;
}

.media-box.over {
  border: var(--media-over-border);
}

.media-box__header {
  min-width: 100%;
  background: var(--media-box-color);
  color: var(--foreground-color);
  line-height: var(--media-box-header-height);
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
}

/* Links that take up the whole width of .media-box (title links) should use this class along with .media-box__header (without containers) */
a.media-box__header--link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: bold;
  color: var(--media-box-header-link-text-color);
}

a.media-box__header--link:hover {
  color: var(--media-box-header-link-text-hover-color);
  background-color: var(--media-box-hover-color);
}

/* Containers with a row of links (e.g. image thumbnail header) should use this class. */
.media-box__header--link-row > a {
  display: inline-block;
}

.media-box__header--link-row > a,
.media-box__overlay {
  line-height: var(--media-box-header-height);
  padding: 0 4px;
}

.media-box__header--small {
  width: var(--media-small-container-width);
  font-size: 11px;
}

.media-box__header--small a {
  padding: 0 3px;
}

.media-box__header--unselected {
  background-color: var(--danger-color);
}

.media-box__header--selected {
  background-color: var(--success-color);
}

.media-box__content {
  width: 100%;
  padding-top: 100%;
  position: relative;
  overflow: hidden;
}

.media-box__content .image-container {
  position: absolute;
  inset: 0;
}

.media-box__content--featured {
  width: var(--media-featured-width);
  height: auto;
}

.media-box__content--featured .image-container {
  max-height: var(--media-featured-width);
}

.media-box__content--large {
  max-height: var(--media-medium-container-width);
}

.media-box__content--small {
  max-height: var(--media-small-container-width);
}

.media--featured {
  display: flex;
  justify-content: center;
}

.media--featured .media-box {
  max-width: var(--media-featured-width);
  max-height: calc(var(--media-featured-width) + var(--media-box-header-height));
  margin-bottom: var(--padding-small);
}

.media-box__overlay {
  display: block;
  position: absolute;
  z-index: 4;
  min-width: 95%;
  text-align: left;
  font-weight: bold;
  word-wrap: break-word;
  line-height: var(--media-box-header-height);
  pointer-events: none;
  top: 0;
  color: var(--image-overlay-color);
  background: var(--image-overlay-background-color);
}

.thumb_small .media-box__overlay {
  font-size: 11px;
}

.thumb_tiny .media-box__overlay {
  font-size: 10px;
  line-height: 16px;
}

/* TODO: replace absolute positioning with a more flexible solution */
.media-box__overlay:nth-child(2) {
  top: var(--media-box-header-height);
}
