/* Sliding description panel over image */
.spaced-box-desc-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(0deg, #000000e0 0%, rgba(0, 0, 0, 0.678) 100%);
  color: #fff;
  padding: 1em 0.75em 0.75em 0.75em;
  font-size: clamp(0.8rem, 4.5cqw, 1.5rem);
  border-radius: 0 0 15px 15px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 0.35s cubic-bezier(.4,0,.2,1), transform 0.35s cubic-bezier(.4,0,.2,1);
  pointer-events: none;
  z-index: 10;
  text-align: center;
  word-break: break-word;
}

.spaced-box-hover-wrap:hover .spaced-box-desc-panel,
.spaced-box-hover-wrap:focus-within .spaced-box-desc-panel {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.spaced-box-hover-wrap .spaced-box-img {
  transition: transform 1s cubic-bezier(.4,0,.2,1), filter 0.2s;
}
.spaced-box-hover-wrap:hover .spaced-box-img,
.spaced-box-hover-wrap:focus-within .spaced-box-img {
  transform: scale(1.04);
}
/* Make the title white when the hover rectangle is visible */
.spaced-box-hover-wrap:hover .spaced-box-title,
.spaced-box-hover-wrap:focus-within .spaced-box-title,
.spaced-box-hover-wrap:hover .spaced-box-title-link,
.spaced-box-hover-wrap:focus-within .spaced-box-title-link {
  color: #fff;
}
/* Hover wrap for unified hover effect */
.spaced-box-hover-wrap {
  container-type: inline-size;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin-bottom: 0.5em;
  padding:3px;
  padding-bottom:10px;
}

.spaced-box-hover-wrap::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  width:100%;
  height: calc(100% - 0.25em); /* slightly less than full to avoid overflow */
  background: linear-gradient(120deg, #ff6655 0%, #e30613 100%);
  border-radius: 15px;
  opacity: 0;
  z-index: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  box-shadow: #31313167 2px 2px 3px;
}

.spaced-box-hover-wrap:hover::before,
.spaced-box-hover-wrap:focus-within::before {
  opacity: 1;
}

.spaced-box-hover-wrap > * {
  position: relative;
  z-index: 1;
}

.spaced-box-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  border-radius: 15px 15px 15px 15px;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.spaced-box-link {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 15px;
  position: relative;
  z-index: 2;
  overflow: hidden;
}

.spaced-box-img {
  /* Will be positioned absolutely to allow a hover image to layer above */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 15px;
  transition: opacity 0.35s ease, transform 0.6s cubic-bezier(.4,0,.2,1), filter 0.2s;
  transform-origin: center center;
  z-index: 1;
  opacity: 1;
}

.spaced-box-img-hover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 15px;
  transition: opacity 0.35s ease, transform 0.6s cubic-bezier(.4,0,.2,1), filter 0.2s;
  transform-origin: center center;
  z-index: 3;
  opacity: 0;
}

/* Red hover rectangle with gradient, behind image and title */
.spaced-box-img-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 15px;
  background: linear-gradient(160deg, #ff4d3a 0%, #e30613 100%);
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 1;
}

.spaced-box-img-wrap:hover::before,
.spaced-box-img-wrap:focus-within::before {
  opacity: 1;
}

/* Brighten and increase contrast of both images on hover */
.spaced-box-img-wrap:hover .spaced-box-img,
.spaced-box-img-wrap:focus-within .spaced-box-img,
.spaced-box-img-wrap:hover .spaced-box-img-hover,
.spaced-box-img-wrap:focus-within .spaced-box-img-hover {
  filter: brightness(1.02) contrast(1.02);
}

/* Crossfade to hover image */
.spaced-box-hover-wrap:hover .spaced-box-img-hover,
.spaced-box-hover-wrap:focus-within .spaced-box-img-hover,
.spaced-box-img-wrap:hover .spaced-box-img-hover,
.spaced-box-img-wrap:focus-within .spaced-box-img-hover {
  opacity: 1;
}

/* Zoom both images subtly on hover */
.spaced-box-hover-wrap:hover .spaced-box-img,
.spaced-box-hover-wrap:focus-within .spaced-box-img,
.spaced-box-hover-wrap:hover .spaced-box-img-hover,
.spaced-box-hover-wrap:focus-within .spaced-box-img-hover,
.spaced-box-img-wrap:hover .spaced-box-img,
.spaced-box-img-wrap:focus-within .spaced-box-img,
.spaced-box-img-wrap:hover .spaced-box-img-hover,
.spaced-box-img-wrap:focus-within .spaced-box-img-hover {
  transform: scale(1.06);
}

.spaced-box-title-wrap {
  width: 100%;
  text-align: center;
  margin-top: 0.25em;
}
/* Clean grid-based layout for spaced boxes */
.spaced-boxes {
  padding: 1em;
}

.spaced-boxes .columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1em;
  align-items: stretch;
  justify-items: center; /* center grid items horizontally */
  align-content: start;
  grid-auto-flow: row;
}

/* Ensure any inline width on .col (from the PHP template) does not interfere with grid sizing
   and make each .col a flex container so the anchor can stretch to fill the cell. */
.spaced-boxes .columns > .col {
  width: auto !important; /* override inline width attribute */
  min-width: 0;           /* allow items to shrink below their content widths */
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* Force the anchor to fill the column and be fully clickable across the whole cell */
.spaced-boxes .columns > .col > .spaced-box-link {
  display: flex; /* already flex in main rule, but ensure here for specificity */
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* .spaced-box-link is now a block-level anchor inside .spaced-box-img-wrap */

/* When an image is present we set it as the background (inline style/class from PHP). */
.spaced-box-link.has-bg {
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

/* Remove old .spaced-box-link hover/visited rules */

/* If there is no background image, keep the coloured gradient as visual fill */
.spaced-box-link:not(.has-bg) {
  background: linear-gradient(160deg, #ffffff 0%, #c7c7c7 100%);
}

/* Remove old .spaced-box-content rules */

.spaced-box-title {
  font-size: clamp(1.0rem, 1.1vw, 1.3rem);
  font-weight: 600;
  color: black;
  text-transform: uppercase;
  margin: 0.25em 0 0 0;
  text-align: center;
  display: inline-block;
  background: none;
  border-radius: 0;
  position: relative;
  z-index: 2;
}

.spaced-box-title-link {
  color: inherit;
  text-decoration: none;
  transition: text-decoration 0.2s;
}
.spaced-box-title-link:hover,
.spaced-box-title-link:focus {
  text-decoration: none;
}

/* Mobile: collapse to a single column. */
@media (max-width: 1023px) {
  .spaced-boxes .columns {
    grid-template-columns: 1fr;
    gap: 1.5em;
  }
  .spaced-box-link {
    min-height: 80px;
  }
  .spaced-box-title {
    font-size: 1.3em;
  }
  .spaced-box-desc-panel {
    font-size: 1.1rem;
  }
  .spaced-boxes .columns > .col {
    width: 100% !important;
    max-width: 100%;
    flex: 1 1 100%;
  }
}

/* Desktop and up: prefer a single-row distribution (except mobile where we collapse to 1 column).
   Use flexbox at desktop+ to force one row of equal-width items (no wrapping). */
@media (min-width: 1024px) {
  .spaced-boxes .columns {
    display: flex;
    flex-wrap: nowrap;
    gap: 0em;
    align-items: stretch;
    justify-content: center; /* center flex items horizontally */
  }

  .spaced-boxes .columns > .col {
    /* each column becomes an equal-flex item */
    flex: 1 1 0;
    min-width: 0; /* allow shrinking */
    max-width:40%;
  }

  /* ensure anchor fills the flex child */
  .spaced-boxes .columns > .col > .spaced-box-link {
    height: 100%;
  }
}
