/* Race page gallery grid and carousel shell.
   Preview strip styles live in preview-controls.css; arrow chrome lives in arrow-controls.css. */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (max-width: 900px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

.gallery-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.gallery-item:hover {
  border-color: var(--gold);
  transform: translateY(-4px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 16px var(--gold-glow);
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  object-position: top center;
  display: block;
  transition: transform 0.4s ease;
}

.gallery-item:hover img {
  transform: scale(1.04);
}

/* Gallery carousel for races with three or more images. */
.gallery-grid.gallery-grid--carousel {
  --gallery-carousel-width: min(880px, 100%);
  --gallery-carousel-stage-height: clamp(620px, 78vh, 940px);
  --gallery-carousel-portrait-stage-height: var(--gallery-carousel-stage-height);
  --gallery-carousel-arrow-size: 54px;
  --gallery-carousel-arrow-offset: 18px;
  --gallery-carousel-portrait-width: min(100%, clamp(560px, 70vh, 860px));
  display: block;
  margin-inline: auto;
  width: var(--gallery-carousel-width);
  max-width: var(--gallery-carousel-width);
}

.gallery-carousel {
  width: 100%;
}

.gallery-carousel__stage {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--gallery-carousel-stage-height);
  min-height: 0;
  isolation: isolate;
  position: relative;
  overflow: hidden;
}

.gallery-carousel__stage--portrait {
  height: var(--gallery-carousel-portrait-stage-height);
}

.gallery-carousel__media {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.gallery-carousel__media--portrait {
  width: var(--gallery-carousel-portrait-width);
  height: auto;
  max-height: 100%;
  aspect-ratio: 5 / 6;
}

.gallery-carousel__image {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  object-fit: contain;
  object-position: center center;
}

.gallery-carousel__arrow {
  width: var(--gallery-carousel-arrow-size);
  height: var(--gallery-carousel-arrow-size);
  color: var(--sftl-arrow-color);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
}

.gallery-carousel__arrow--prev {
  left: var(--gallery-carousel-arrow-offset);
  right: auto;
}

.gallery-carousel__arrow--next {
  right: var(--gallery-carousel-arrow-offset);
  left: auto;
}

@media (max-width: 760px) {
  .gallery-grid.gallery-grid--carousel {
    --gallery-carousel-stage-height: clamp(240px, 62vw, 420px);
    --gallery-carousel-portrait-stage-height: clamp(360px, calc((100vw - 48px) * 1.2), 680px);
    --gallery-carousel-portrait-width: min(100%, clamp(360px, 82vh, 680px));
    --gallery-carousel-arrow-offset: 10px;
  }
}

.gallery-carousel__main {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  cursor: zoom-in;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  background: transparent;
  overflow: hidden;
}

.gallery-carousel__main--portrait {
  width: 100%;
  height: 100%;
  max-height: 100%;
}

.gallery-carousel__image--portrait {
  object-fit: cover;
  object-position: var(--gallery-focus-x, center) var(--gallery-focus-y, 8%);
}
