.flipcard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(150px, 250px);
  gap: 15px;
  width: 100%;
  padding: 0;
  box-sizing: border-box;
}

/* Layout 1 (Default) - Tall Left, Wide Top-Right */
.flipcard-grid:not([class*="layout-"]) .item-1,
.flipcard-grid.layout-1 .item-1 {
  grid-column: 1;
  grid-row: span 2;
}

.flipcard-grid:not([class*="layout-"]) .item-2,
.flipcard-grid.layout-1 .item-2 {
  grid-column: 2;
  grid-row: 1;
}

.flipcard-grid:not([class*="layout-"]) .item-3,
.flipcard-grid.layout-1 .item-3 {
  grid-column: 2;
  grid-row: 2;
}

.flipcard-grid:not([class*="layout-"]) .item-4,
.flipcard-grid.layout-1 .item-4 {
  grid-column: 3 / span 2;
  grid-row: 1;
}

.flipcard-grid:not([class*="layout-"]) .item-5,
.flipcard-grid.layout-1 .item-5 {
  grid-column: 3;
  grid-row: 2;
}

.flipcard-grid:not([class*="layout-"]) .item-6,
.flipcard-grid.layout-1 .item-6 {
  grid-column: 4;
  grid-row: 2;
}

/* Layout 2 - Wide Bottom-Left, Tall Right */
.flipcard-grid.layout-2 .item-1 {
  grid-column: 1;
  grid-row: 1;
}

.flipcard-grid.layout-2 .item-2 {
  grid-column: 2;
  grid-row: 1;
}

.flipcard-grid.layout-2 .item-3 {
  grid-column: 3;
  grid-row: 1;
}

.flipcard-grid.layout-2 .item-4 {
  grid-column: 1 / span 2;
  grid-row: 2;
}

.flipcard-grid.layout-2 .item-5 {
  grid-column: 3;
  grid-row: 2;
}

.flipcard-grid.layout-2 .item-6 {
  grid-column: 4;
  grid-row: span 2;
}

/* Layout 3 - Two Wide (Stacked Left) */
.flipcard-grid.layout-3 .item-1 {
  grid-column: 1 / span 2;
  grid-row: 1;
}

.flipcard-grid.layout-3 .item-2 {
  grid-column: 3;
  grid-row: 1;
}

.flipcard-grid.layout-3 .item-3 {
  grid-column: 4;
  grid-row: 1;
}

.flipcard-grid.layout-3 .item-4 {
  grid-column: 1 / span 2;
  grid-row: 2;
}

.flipcard-grid.layout-3 .item-5 {
  grid-column: 3;
  grid-row: 2;
}

.flipcard-grid.layout-3 .item-6 {
  grid-column: 4;
  grid-row: 2;
}

/* Layout 4 - Two Tall (Sides) */
.flipcard-grid.layout-4 .item-1 {
  grid-column: 1;
  grid-row: span 2;
}

.flipcard-grid.layout-4 .item-2 {
  grid-column: 2;
  grid-row: 1;
}

.flipcard-grid.layout-4 .item-3 {
  grid-column: 2;
  grid-row: 2;
}

.flipcard-grid.layout-4 .item-4 {
  grid-column: 3;
  grid-row: 1;
}

.flipcard-grid.layout-4 .item-5 {
  grid-column: 3;
  grid-row: 2;
}

.flipcard-grid.layout-4 .item-6 {
  grid-column: 4;
  grid-row: span 2;
}

.flipcard {
  perspective: 1000px;
  overflow: hidden;
  border-radius: 12px;
}

.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .8s;
  transform-style: preserve-3d;
}

.flipcard:hover .flip-inner {
  transform: rotateY(180deg);
}

.flip-front,
.flip-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.flip-front img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

.flip-back {
  transform: rotateY(180deg);
  background: #111;
  color: #fff;
  padding: 20px;
  flex-direction: column;
}

.btn {
  display: inline-block;
  padding: 10px 15px;
  background: #fff;
  color: #000;
  text-decoration: none;
  margin-top: 10px;
}

/* Layout 5 - Two Wide Top, Four Bottom */
.flipcard-grid.layout-5 .item-1 {
  grid-column: 1 / span 2;
  grid-row: 1;
}

.flipcard-grid.layout-5 .item-2 {
  grid-column: 3 / span 2;
  grid-row: 1;
}

.flipcard-grid.layout-5 .item-3 {
  grid-column: 1;
  grid-row: 2;
}

.flipcard-grid.layout-5 .item-4 {
  grid-column: 2;
  grid-row: 2;
}

.flipcard-grid.layout-5 .item-5 {
  grid-column: 3;
  grid-row: 2;
}

.flipcard-grid.layout-5 .item-6 {
  grid-column: 4;
  grid-row: 2;
}

/* Layout 6 - Center Wide */
.flipcard-grid.layout-6 .item-1 {
  grid-column: 1;
  grid-row: 1;
}

.flipcard-grid.layout-6 .item-2 {
  grid-column: 2 / span 2;
  grid-row: 1;
}

.flipcard-grid.layout-6 .item-3 {
  grid-column: 4;
  grid-row: 1;
}

.flipcard-grid.layout-6 .item-4 {
  grid-column: 1;
  grid-row: 2;
}

.flipcard-grid.layout-6 .item-5 {
  grid-column: 2 / span 2;
  grid-row: 2;
}

.flipcard-grid.layout-6 .item-6 {
  grid-column: 4;
  grid-row: 2;
}

/* Tablet devices - 2 columns */
@media(max-width: 991px) {
  .flipcard-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 0 15px;
    grid-auto-rows: minmax(200px, 250px);
  }

  /* Reset to simple flow for tablet unless specified otherwise */
  .flipcard-grid .item-1,
  .flipcard-grid .item-2,
  .flipcard-grid .item-3,
  .flipcard-grid .item-4,
  .flipcard-grid .item-5,
  .flipcard-grid .item-6 {
    grid-column: auto;
    grid-row: auto;
  }
}

/* Small tablets and large phones - 1 column */
@media(max-width: 768px) {
  .flipcard-grid {
    grid-template-columns: 1fr;
    gap: 15px;
    padding: 0 10px;
    grid-auto-rows: minmax(200px, 250px);
  }

  .flipcard-grid .item-1,
  .flipcard-grid .item-2,
  .flipcard-grid .item-3,
  .flipcard-grid .item-4,
  .flipcard-grid .item-5,
  .flipcard-grid .item-6 {
    grid-column: 1;
    grid-row: auto;
  }
}

/* Mobile phones - Single Column Layout */
@media(max-width: 600px) {
  .flipcard-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 0 10px;
    grid-auto-rows: 250px;
  }

  /* Reset all items to flow naturally in single column with uniform size */
  .flipcard-grid .item-1,
  .flipcard-grid .item-2,
  .flipcard-grid .item-3,
  .flipcard-grid .item-4,
  .flipcard-grid .item-5,
  .flipcard-grid .item-6,
  .flipcard-grid.layout-1 .item-1,
  .flipcard-grid.layout-1 .item-2,
  .flipcard-grid.layout-1 .item-3,
  .flipcard-grid.layout-1 .item-4,
  .flipcard-grid.layout-1 .item-5,
  .flipcard-grid.layout-1 .item-6,
  .flipcard-grid.layout-2 .item-1,
  .flipcard-grid.layout-2 .item-2,
  .flipcard-grid.layout-2 .item-3,
  .flipcard-grid.layout-2 .item-4,
  .flipcard-grid.layout-2 .item-5,
  .flipcard-grid.layout-2 .item-6,
  .flipcard-grid.layout-3 .item-1,
  .flipcard-grid.layout-3 .item-2,
  .flipcard-grid.layout-3 .item-3,
  .flipcard-grid.layout-3 .item-4,
  .flipcard-grid.layout-3 .item-5,
  .flipcard-grid.layout-3 .item-6,
  .flipcard-grid.layout-4 .item-1,
  .flipcard-grid.layout-4 .item-2,
  .flipcard-grid.layout-4 .item-3,
  .flipcard-grid.layout-4 .item-4,
  .flipcard-grid.layout-4 .item-5,
  .flipcard-grid.layout-4 .item-6,
  .flipcard-grid.layout-5 .item-1,
  .flipcard-grid.layout-5 .item-2,
  .flipcard-grid.layout-5 .item-3,
  .flipcard-grid.layout-5 .item-4,
  .flipcard-grid.layout-5 .item-5,
  .flipcard-grid.layout-5 .item-6,
  .flipcard-grid.layout-6 .item-1,
  .flipcard-grid.layout-6 .item-2,
  .flipcard-grid.layout-6 .item-3,
  .flipcard-grid.layout-6 .item-4,
  .flipcard-grid.layout-6 .item-5,
  .flipcard-grid.layout-6 .item-6 {
    grid-column: 1;
    grid-row: auto;
  }

  .flip-back {
    padding: 15px;
    font-size: 14px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }
}

/* Extra small devices */
@media(max-width: 400px) {
  .flipcard-grid {
    grid-auto-rows: minmax(150px, 200px);
    gap: 10px;
  }

  .flip-back {
    padding: 12px;
    font-size: 13px;
  }
}