/* MAIN GRID */
.fb-grid {
  display: grid;
  gap: 4px;
  width: 100%;
  border-radius: 12px;
  overflow: hidden; /* Ensures rounded corners on children */
}

.img-box {
  position: relative;
  background: transparent;
  width: 100%;
  height: 100%;
}

/* FIX: Changed contain to cover */
.img-box img {
    width: 100%;
    height: 100%;
    /* 1. Use 'contain' for every image to ensure zero cropping */
    object-fit: contain; 
    
    /* 2. Choose a background color for the empty space (Letterboxing) */
    /* Black (#1a1a1a) or the FB Gray (#f0f2f5) work best */
    background-color: transparent; 
    
    display: block;
    cursor: pointer;
}

/* If you want ONLY the large/first image to show fully: */
.fb-grid .img-box:first-child img {
    object-fit: contain;
}

/* Maintain cover for small side-tiles so they stay aligned */
.fb-grid .img-box:not(:first-child) img {
    object-fit: contain;
}

.layout-portrait img {
  width: 50%;
}

/* ========== IMPROVED LAYOUTS ========== */

.grid-1 { height: 400px; grid-template-columns: 1fr; }

/* 2 Images: Side by side (Vertical Split) */
.grid-2 { 
  height: 400px; 
  grid-template-columns: 1fr 1fr; 
}

/* 3 Images: 1 Large Top, 2 Small Bottom */
.grid-3 {
  height: 400px;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 200px 200px;
}

.grid-3 .img-box:nth-child(1) { grid-column: span 2; }


/* 4 Images: 1 Large Left, 3 Small Right (Vertical Stack) */
.grid-4 {
  height: 400px;
  grid-template-columns: 3fr 1fr; /* Large featured image on left */
  grid-template-rows: repeat(3, 1fr);
}
.grid-4 .img-box:nth-child(1) { grid-row: span 3; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  color: white;
  font-size: 2rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* Allows clicking the image behind it */
}

/* If the main image is Portrait, split the grid vertically (Left/Right) */
.fb-grid.layout-portrait.grid-3,
.fb-grid.layout-portrait.grid-4 {
    grid-template-columns: 2fr 1fr; /* Featured image on the left */
    grid-template-rows: repeat(3, 1fr);
    height: 450px;
}

.fb-grid.layout-portrait.grid-3 .img-box:nth-child(1),
.fb-grid.layout-portrait.grid-4 .img-box:nth-child(1) {
    grid-row: span 3;
    grid-column: span 1;
}