/**
 * Fast Gallery — canonical grid (sync with Astro src/styles/gallery.css .fg-gallery)
 */

.entry-content .fg-gallery,
.post-entry .fg-gallery,
.single-post .fg-gallery {
  width: 100%;
  max-width: 100%;
  margin: 25px 0;
  clear: both;
  box-sizing: border-box;
}

.fg-gallery-inner {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.fg-gallery-item {
  position: relative;
  display: block;
  box-sizing: border-box;
  border-radius: 6px;
  overflow: hidden;
  line-height: 0;
  text-decoration: none;
  transition: transform 0.3s ease;
}

.fg-gallery-item:hover {
  transform: translateY(-3px);
}

.fg-gallery-frame {
  display: block;
  width: 100%;
  line-height: 0;
}

.fg-gallery-item img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
  border-radius: 6px;
  margin: 0;
  transition: transform 0.3s ease;
}

.fg-layout-portrait .fg-gallery-item img {
  aspect-ratio: 585 / 831;
}

.fg-layout-square .fg-gallery-item img {
  aspect-ratio: 1 / 1;
}

.fg-gallery-item:hover img {
  transform: scale(1.03);
}

/* Column widths (gap 12px) */
.fg-gallery-cols-1 .fg-gallery-item {
  flex: 0 0 100%;
  max-width: 100%;
}

.fg-gallery-cols-2 .fg-gallery-item {
  flex: 0 0 calc((100% - 12px) / 2);
  max-width: calc((100% - 12px) / 2);
}

.fg-gallery-cols-3 .fg-gallery-item {
  flex: 0 0 calc((100% - 24px) / 3);
  max-width: calc((100% - 24px) / 3);
}

.fg-gallery-cols-4 .fg-gallery-item {
  flex: 0 0 calc((100% - 36px) / 4);
  max-width: calc((100% - 36px) / 4);
}

.fg-gallery-cols-5 .fg-gallery-item {
  flex: 0 0 calc((100% - 48px) / 5);
  max-width: calc((100% - 48px) / 5);
}

/* Wiki footer: 8-col square strip */
.fg-gallery.fg-gallery-square.fg-gallery-cols-8 .fg-gallery-inner {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
}

.fg-gallery.fg-gallery-square.fg-gallery-cols-8 .fg-gallery-item {
  flex: none;
  max-width: none;
  aspect-ratio: 1 / 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.fg-gallery-item[data-cap]:not([data-cap=""])::after {
  content: attr(data-cap);
  position: absolute;
  inset: auto 0 0 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.4) 60%, rgba(0, 0, 0, 0) 100%);
  color: #fff;
  font-size: 11px;
  font-style: italic;
  text-align: center;
  padding: 24px 6px 8px;
  line-height: 1.3;
  pointer-events: none;
  z-index: 2;
}

/* Legacy MGL inline output (until all posts re-render) */
.mgl-gallery-images {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
  margin: 25px 0;
}

.mgl-gallery-images > a {
  flex: 0 0 calc((100% - 24px) / 3);
  max-width: calc((100% - 24px) / 3);
  display: block;
  border-radius: 6px;
  overflow: hidden;
  line-height: 0;
}

.mgl-gallery-images > a img {
  width: 100%;
  height: auto;
  aspect-ratio: 585 / 831;
  object-fit: cover;
  display: block;
}

.mgl-gallery-images:has(> a:nth-child(2):last-child) > a,
.mgl-gallery-images:has(> a:nth-child(4):last-child) > a {
  flex: 0 0 calc((100% - 12px) / 2);
  max-width: calc((100% - 12px) / 2);
}

.mgl-gallery-images:has(> a:nth-child(8):last-child) > a {
  flex: 0 0 calc((100% - 36px) / 4);
  max-width: calc((100% - 36px) / 4);
}

@media (max-width: 767px) {
  .fg-gallery-inner {
    gap: 6px;
  }

  .fg-gallery-cols-4 .fg-gallery-item,
  .fg-gallery-cols-5 .fg-gallery-item {
    flex: 0 0 calc((100% - 6px) / 2);
    max-width: calc((100% - 6px) / 2);
  }

  .fg-gallery.fg-gallery-square.fg-gallery-cols-8 .fg-gallery-inner {
    grid-template-columns: repeat(4, 1fr);
  }

  .mgl-gallery-images > a {
    flex: 0 0 calc((100% - 12px) / 3);
    max-width: calc((100% - 12px) / 3);
  }
}

@media (max-width: 640px) {
  .fg-gallery.fg-gallery-square.fg-gallery-cols-8 .fg-gallery-inner {
    grid-template-columns: repeat(3, 1fr);
  }
}
