/*
 * SPORTONOM ground photos - final presentation layer (loads after polish.css).
 *
 * Owners upload photos in any shape: portrait phone shots, wide panoramas,
 * squares, tiny files. Two rules keep every one of them looking professional:
 *
 *   1. Ground CARDS use one uniform frame. A normal landscape photo fills it.
 *      A photo whose shape is too far from the frame (very tall / very wide)
 *      is marked `.is-fit` by assets/js/ground-photos.js and shown whole on a
 *      soft blurred copy of itself instead of being cut to a thin strip.
 *   2. The ground DETAIL page uses a single gallery stage with a fixed shape.
 *      The photo is always shown complete (never cropped); thumbnails, arrows,
 *      swipe and a full-screen viewer let people look at every photo.
 *
 * The `!important` flags on the card rules are intentional: earlier layers in
 * polish.css (v6/v8/v9) forced fixed heights with !important.
 */

/* ---------------------------------------------------------------------------
 * 1) Ground cards (home, Explore, owner grounds list)
 * ------------------------------------------------------------------------- */
.ground-card .ground-image.has-photo,
.owner-ground-cover.has-photo {
  position: relative;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: hidden;
  isolation: isolate;
  background: #dfe9ee;
}

.ground-card .ground-image.has-photo { aspect-ratio: 3 / 2; }
.owner-ground-cover.has-photo { aspect-ratio: 16 / 10; }

.ground-card .ground-image.has-photo .ground-image-photo,
.owner-ground-cover.has-photo .owner-ground-cover-photo {
  position: absolute !important;
  inset: 0 !important;
  z-index: 1;
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: cover !important;
  object-position: center 40% !important;
}

/* Soft shade at the bottom only, so the photo itself is not darkened. */
.ground-image.has-photo::after,
.owner-ground-cover.has-photo::after {
  z-index: 2;
  background: linear-gradient(180deg, transparent 70%, rgba(7, 17, 31, .26) 100%);
  pointer-events: none;
}

.ground-image.has-photo .ground-badge,
.owner-ground-cover.has-photo .status-badge {
  z-index: 3;
}

/* Very tall / very wide photos: show the whole picture over a blurred copy. */
.ground-card .ground-image.has-photo.is-fit::before,
.owner-ground-cover.has-photo.is-fit::before {
  content: "" !important;
  display: block !important;
  position: absolute;
  inset: -24px;
  z-index: 0;
  background: var(--photo) center / cover no-repeat;
  filter: blur(18px) saturate(1.15);
  opacity: .95;
}

.ground-card .ground-image.has-photo.is-fit .ground-image-photo,
.owner-ground-cover.has-photo.is-fit .owner-ground-cover-photo {
  object-fit: contain !important;
  object-position: center !important;
}

/* ---------------------------------------------------------------------------
 * 2) Ground detail gallery
 * ------------------------------------------------------------------------- */
.photo-gallery {
  display: grid;
  gap: .75rem;
  min-width: 0;
}

.gallery-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: min(72vh, 600px);
  overflow: hidden;
  isolation: isolate;
  border-radius: 20px;
  background: #0e1b27;
  touch-action: pan-y;
}

.gallery-slide {
  position: absolute;
  inset: 0;
  display: none;
  margin: 0;
}

.gallery-slide.is-active { display: block; }

/* Blurred copy of the photo fills any space the whole picture leaves free. */
.gallery-slide::before {
  content: "";
  position: absolute;
  inset: -30px;
  background: var(--photo) center / cover no-repeat;
  filter: blur(26px) saturate(1.1) brightness(.88);
}

.gallery-slide img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: contain;
  cursor: zoom-in;
}

.gallery-nav,
.gallery-zoom {
  position: absolute;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  color: #0b1d2e;
  font-size: 1.05rem;
  box-shadow: 0 6px 18px rgba(7, 17, 31, .28);
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}

.gallery-nav:hover,
.gallery-zoom:hover { background: #fff; transform: scale(1.06); }
.gallery-nav:focus-visible,
.gallery-zoom:focus-visible,
.gallery-thumb:focus-visible { outline: 3px solid rgba(26, 135, 255, .65); outline-offset: 2px; }

.gallery-nav { top: 50%; margin-top: -21px; }
.gallery-nav-prev { left: 12px; }
.gallery-nav-next { right: 12px; }
.gallery-zoom { top: 12px; right: 12px; width: 38px; height: 38px; font-size: .95rem; }

.gallery-counter {
  position: absolute;
  z-index: 3;
  left: 12px;
  bottom: 12px;
  padding: .28rem .7rem;
  border-radius: 999px;
  background: rgba(7, 17, 31, .72);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .02em;
  pointer-events: none;
}

.gallery-thumbs {
  position: relative; /* offsetParent for the thumbnail auto-scroll */
  display: flex;
  gap: .5rem;
  padding: 3px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.gallery-thumb {
  flex: 0 0 auto;
  width: 92px;
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 12px;
  background: #dfe9ee;
  opacity: .72;
  cursor: pointer;
  transition: opacity .15s ease, border-color .15s ease;
}

.gallery-thumb:hover { opacity: 1; }
.gallery-thumb[aria-current="true"] { border-color: #1a87ff; opacity: 1; }

.gallery-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
}

@media (max-width: 767.98px) {
  .gallery-stage { aspect-ratio: 4 / 3; border-radius: 16px; }
  .gallery-nav { width: 38px; height: 38px; margin-top: -19px; }
  .gallery-thumb { width: 72px; border-radius: 10px; }
}

/* ---------------------------------------------------------------------------
 * 3) Full-screen viewer (built by assets/js/ground-photos.js)
 * ------------------------------------------------------------------------- */
html.gl-lock { overflow: hidden; }

.gl-lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 1rem;
  background: rgba(5, 10, 18, .98);
  touch-action: pan-y;
}

.gl-lightbox img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 6px;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.gl-lightbox button {
  position: absolute;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 1.15rem;
  cursor: pointer;
  transition: background .15s ease;
}

.gl-lightbox button:hover { background: rgba(255, 255, 255, .28); }
.gl-lightbox button:focus-visible { outline: 3px solid rgba(26, 135, 255, .8); outline-offset: 2px; }
.gl-close { top: 12px; right: 12px; }
.gl-prev { left: 12px; top: 50%; margin-top: -22px; }
.gl-next { right: 12px; top: 50%; margin-top: -22px; }

.gl-count {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .03em;
}

@media (max-width: 575.98px) {
  .gl-lightbox { padding: 3.5rem 0; }
  .gl-lightbox img { border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-nav, .gallery-zoom, .gallery-thumb, .gl-lightbox button { transition: none; }
}
