@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&display=swap');

div.gallery {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

div.gallery-item {
  margin: 5px;
  width: min(24%, 350px);
  max-width: 350px;
  height: auto;
  perspective: 1000px;
  flex: 1 1 280px;
}

/* The card container that actually spins */
div.gallery-item .card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

/* When Javascript toggles the class, spin it 180 degrees */
div.gallery-item.flipped .card-inner {
  transform: rotateY(180deg);
}

/* Front and Back Face settings */
div.card-front, div.card-back {
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 1px solid var(--card-border);
  cursor: pointer;
  transition: border 0.3s; 
  box-sizing: border-box; 
}

/* --- THE HOVER & FLIP LOGIC --- */

/* 1. Standard hover: Apply dark border to the front face */
div.gallery-item:hover div.card-front {
  border: 1px solid black;
}

div.gallery-item:hover div.card-back {
  border: 1px solid black;
}

/* 2. When FLIPPED: Disable pointer events on the front face so the hover un-sticks */
div.gallery-item.flipped {
  pointer-events: none; 
}

/* 3. Re-enable pointer events ONLY for the back face if you need to click it again to flip back */
div.card-back {
  position: absolute;
  display: flex;
  top: 0;
  left: 0;
  background-color: var(--card-bg);
  color: var(--text);
  justify-content: center;
  align-items: center;
  transform: rotateY(180deg);
  pointer-events: auto; /* Allows the back to still be clickable */
}

/* Kept your exact image and description styles */
div.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

div.gallery-item div.desc {
  padding: 15px;
  text-align: center;
  font-family: "Instrument Serif", serif;
}