:root {
  --grid-tile: 250px; /* фикс размер превью */
  --grid-gap: 2px;
}

/* Универсальная плитка: от 1 до 4 колонок по 250px, центр */
.grid-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, var(--grid-tile));
  gap: var(--grid-gap);
  justify-content: center; /* центрируем всю решётку */
}

/* ограничение до 4 колонок (по желанию) */
.grid-tiles--max4 {
  max-width: calc(4 * var(--grid-tile) + 3 * var(--grid-gap));
  margin: 0 auto;
}

/* Плитка поста: без скруглений, лёгкая рамка, дешёвый offscreen-скип */
.grid-tiles .post-tile {
  display: block;
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;

  /* экономим рендер вне экрана */
  content-visibility: auto;
  contain-intrinsic-size: var(--grid-tile) var(--grid-tile);
}

/* Медиа: строгий размер 250×250, cover, фон-плейсхолдер */
.grid-tiles .post-tile img,
.grid-tiles .post-tile video {
  width: var(--grid-tile);
  height: var(--grid-tile);
  object-fit: cover;
  display: block;
  background: var(--elev-2); /* фон пока грузится */
  border-radius: 0 !important;
}

/* Скелет-заливка до загрузки (дешёвая) */
.grid-tiles .post-tile img.is-loading {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.12) 20%,
    rgba(255, 255, 255, 0.06) 40%,
    rgba(255, 255, 255, 0.06) 100%
  );
  background-size: 400% 100%;
  animation: grid-shimmer 1.2s linear infinite;
}

@keyframes grid-shimmer {
  0% {
    background-position: 0% 0;
  }
  100% {
    background-position: 100% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grid-tiles .post-tile img.is-loading {
    animation: none;
  }
}

.post-tile .gallery-badge + .gallery-badge {
  right: 32px;
}

/* оверлей на весь тайл */
.post-tile {
  position: relative;
}

.post-tile .tile-overlay {
  position: absolute;
  inset: 0; /* занять весь блок */
  display: flex;
  align-items: center; /* метрики по центру по вертикали */
  justify-content: center; /* по центру по горизонтали */
  gap: 16px;
  padding: 12px;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none; /* клики проходят сквозь */
  transition: opacity 0.1s ease;
  background: #0009;
}

.post-tile:hover .tile-overlay,
.post-tile:focus-visible .tile-overlay {
  opacity: 1;
}

.post-tile .tile-overlay .metric {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  opacity: 0.95;
}

.post-tile .tile-overlay .icon {
  display: block;
}

/* бейджи поверх оверлея */
.post-tile .gallery-badge {
  z-index: 3;
}

.post-tile .tile-overlay {
  z-index: 2;
}

/* ——— Грид ——— */
.grid-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 250px));
  justify-content: center;
  gap: 2px;
}

.post-tile {
  position: relative;
  display: block;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 0;
  width: 250px;
  height: 250px;
}

.post-tile img {
  width: 250px;
  height: 250px;
  object-fit: cover;
  display: block;
  background: linear-gradient(90deg, #1d1d22 0%, #24242a 50%, #1d1d22 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.post-tile img:not(.is-loading) {
  background: none;
  animation: none;
}

@keyframes shimmer {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* бейджи */
.gallery-badge {
  position: absolute;
  right: 6px;
  top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: #fffffff5;
  color: #444;
  box-shadow: 0 6px 16px #0000002e;
  pointer-events: none;
  z-index: 2;
}

/* оверлей метрик на ховер */
.tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 8px;
  gap: 14px;
  opacity: 0;
  transition: opacity 0.1s ease;
  background: #0009;
}

.post-tile:hover .tile-overlay {
  opacity: 1;
}

.metric {
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.metric .icon {
  width: 14px;
  height: 14px;
  display: block;
}

/* видео-бейдж сдвигаем левее, если одновременно с галереей */
.badge-video.two {
  right: 32px;
}
