/* AllMedias album themes (layouts/allmedias/theme.php). --am-cols: pictures per row, two at most on phones.
   Colours (album or gallery setting, GalleryHelper::COLORS): --am-btn-bg, --am-btn-color, --am-stage, --am-frame,
   --am-frame-text, --am-caption-color. */
.am-theme {
  --am-gap: 12px;
  --am-radius: 6px;
  position: relative;
  margin: 1.5rem 0;
}
.am-theme__items { margin: 0; padding: 0; list-style: none; }
.am-theme__item { position: relative; margin: 0; overflow: hidden; border-radius: var(--am-radius); }
.am-theme__item a { display: block; }
.am-theme__item img { display: block; width: 100%; height: auto; }
.am-theme__item a:focus-visible { outline: 3px solid var(--oui-primary, #2563eb); outline-offset: -3px; }

/* Caption over the bottom of the picture, shown on hover / focus */
.am-theme__caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 1.5rem .75rem .5rem;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, .65));
  color: var(--am-caption-color, #fff); font-size: .875rem; font-weight: 600; line-height: 1.3;
  pointer-events: none; opacity: 0; transition: opacity .3s;
}
.am-theme__item:hover .am-theme__caption,
.am-theme__item:focus-within .am-theme__caption { opacity: 1; }

/* Previous / next buttons */
.am-theme__btn {
  position: absolute; top: 50%; z-index: 20;
  display: grid; place-items: center;
  width: 44px; height: 44px; margin-top: -22px; padding: 0;
  border: 0; border-radius: 50%;
  background: color-mix(in srgb, var(--am-btn-bg, #000) 55%, transparent); color: var(--am-btn-color, #fff); cursor: pointer;
}
.am-theme__btn:hover, .am-theme__btn:focus-visible { background: color-mix(in srgb, var(--am-btn-bg, #000) 85%, transparent); }
.am-theme__btn:focus-visible { outline: 3px solid var(--am-btn-color, #fff); outline-offset: 2px; }
.am-theme__prev { left: .5rem; }
.am-theme__next { right: .5rem; }

/* Slideshow and carousel: a track scrolling by snap points */
/* inline-size containment: the long track never widens the template's columns (a flex or grid item sized by its content) */
.am-theme--slider, .am-theme--carousel { contain: inline-size; }
.am-theme--slider .am-theme__items,
.am-theme--carousel .am-theme__items {
  display: flex; gap: var(--am-gap);
  overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
}
.am-theme--slider .am-theme__items::-webkit-scrollbar,
.am-theme--carousel .am-theme__items::-webkit-scrollbar { display: none; }
.am-theme--slider .am-theme__items:focus-visible,
.am-theme--carousel .am-theme__items:focus-visible { outline: 3px solid var(--oui-primary, #2563eb); outline-offset: 2px; }
.am-theme--slider .am-theme__items > li,
.am-theme--carousel .am-theme__items > li { scroll-snap-align: start; }

.am-theme--slider .am-theme__items { gap: 0; border-radius: var(--am-radius); }
.am-theme--slider .am-theme__items > li { flex: 0 0 100%; }
.am-theme--slider .am-theme__item { border-radius: 0; }
.am-theme--slider .am-theme__item img { aspect-ratio: 3 / 2; max-height: 75vh; object-fit: contain; background: var(--am-stage, #111); }

.am-theme--carousel .am-theme__items > li { flex: 0 0 calc((100% - (var(--am-cols) - 1) * var(--am-gap)) / var(--am-cols)); }
.am-theme--carousel .am-theme__item img { aspect-ratio: 4 / 3; object-fit: cover; }

/* Mosaic: square tiles, every sixth one twice as large */
.am-theme--mosaic .am-theme__items {
  display: grid; gap: var(--am-gap);
  grid-template-columns: repeat(var(--am-cols), minmax(0, 1fr));
  grid-auto-flow: dense;
}
.am-theme--mosaic .am-theme__items > li:nth-child(6n + 1) { grid-column: span 2; grid-row: span 2; }
.am-theme--mosaic .am-theme__items > li { aspect-ratio: 1; }
.am-theme--mosaic .am-theme__item,
.am-theme--mosaic .am-theme__item a { height: 100%; }
.am-theme--mosaic .am-theme__item img { height: 100%; object-fit: cover; }

/* Masonry: columns, each picture at its own ratio */
.am-theme--masonry .am-theme__items { columns: var(--am-cols); column-gap: var(--am-gap); }
.am-theme--masonry .am-theme__items > li { break-inside: avoid; margin-bottom: var(--am-gap); }

/* Polaroid: white framed prints, slightly tilted, straightened on hover */
.am-theme--polaroid .am-theme__items {
  display: grid; gap: calc(var(--am-gap) * 2);
  grid-template-columns: repeat(var(--am-cols), minmax(0, 1fr));
  padding: 1rem .5rem;
}
.am-theme--polaroid .am-theme__item,
.am-theme--heapshot .am-theme__item {
  padding: 10px 10px 0; border-radius: 2px;
  background: var(--am-frame, #fff); box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.am-theme--polaroid .am-theme__item { transform: rotate(var(--am-tilt)); transition: transform .3s, box-shadow .3s; }
.am-theme--polaroid .am-theme__item:hover,
.am-theme--polaroid .am-theme__item:focus-within { position: relative; z-index: 1; transform: rotate(0) scale(1.05); box-shadow: 0 10px 28px rgba(0, 0, 0, .35); }
.am-theme--polaroid .am-theme__item img,
.am-theme--heapshot .am-theme__item img { aspect-ratio: 1; object-fit: cover; }
.am-theme--polaroid .am-theme__caption,
.am-theme--heapshot .am-theme__caption {
  position: static; opacity: 1; background: none; color: var(--am-frame-text, #333);
  padding: .5rem 0 .75rem; font-weight: 400; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.am-theme--polaroid .am-theme__item:not(:has(.am-theme__caption)),
.am-theme--heapshot .am-theme__item:not(:has(.am-theme__caption)) { padding-bottom: 2.25rem; }

/* Heapshot: a pile of prints, a click sends the top one under the pile */
.am-theme--heapshot { width: min(100%, 26rem); margin-inline: auto; }
.am-theme--heapshot .am-theme__items { display: grid; margin: 1rem 0 2rem; }
.am-theme--heapshot .am-theme__next { right: -22px; }
.am-theme--heapshot .am-theme__items > li { grid-area: 1 / 1; transform: rotate(var(--am-tilt)); transition: transform .45s, opacity .45s; }
.am-theme--heapshot .am-theme__items > li:last-child { cursor: pointer; transform: rotate(0); }
.am-theme--heapshot .am-theme__items > li.is-leaving { transform: translateX(110%) rotate(12deg); opacity: 0; }

@media (max-width: 767.98px) {
  .am-theme { --am-cols: 2 !important; }
}
@media (prefers-reduced-motion: reduce) {
  .am-theme * { transition: none !important; }
}
