/* ============================================================
   STALLMAN PROJECTS CAROUSEL - FLEXBOX LAYOUT
   Responsive carousel with GSAP animation
   Structure: [Chevron] --20px-- [Viewport] --20px-- [Chevron]
   ============================================================ */

/* ===== CAROUSEL SHELL ===== */

.ssck-projects-carousel-block {
  /* master wrapper, set padding left and right here */
}

.ssck-projects-carousel {
  width: 100%;
  position: relative;
}

/* Carousel content wrapper (contains chevrons and viewport) */
.ssck-projects-carousel-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between; /* Distribute chevrons to edges */
  height: 320px;
  position: relative;
  overflow: hidden;
  width: 100%;
}

/* ===== CHEVRONS ===== */

.ssck-projects-carousel-chevron {
  opacity: 0.4;
  user-select: none; /* Standard */
  -webkit-user-select: none; /* Safari */
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Structural column definition: Fixed width, never shrink */
  width: 30px;
  flex: 0 0 30px;
  z-index: 100; /* Ensure above slides if overlap occurs */
}

/* Increase opacity .ssck-projects-carousel-chevron on hover to .8 */
.ssck-projects-carousel-chevron:hover {
  opacity: 0.6;
}

.ssck-projects-carousel-chevron img {
  width: 100%;
  height: auto;
  display: block;
}

/* Hidden/disabled chevron states */
.ssck-projects-carousel-chevron[disabled],
.ssck-projects-carousel-chevron[aria-disabled="true"] {
  opacity: 0;
  cursor: default;
  pointer-events: none;
}

/* ===== VIEWPORT (scrollable area) ===== */

.ssck-projects-carousel-viewport {
  /* Structural column definition: Fill remaining space */
  flex: 1 1 auto;
  min-width: 0; /* CSS Flexbox fix: allow shrinking below content size */

  /* The 20px gap is handled here as margin, ensuring structural separation */
  margin: 0 20px;

  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: auto;
  will-change: scroll-position;

  /* CONTAINER QUERY: This allows children to size relative to THIS element's width 
     (which excludes the chevrons and margins automatically) */
  container-type: inline-size;
  container-name: carousel-viewport;

  /* Hide scrollbar */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ssck-projects-carousel-viewport::-webkit-scrollbar {
  display: none;
}

/* ===== GRID / FLEX LAYOUT ===== */

.ssck-projects-carousel-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 40px; /* The gap between slides */
  align-items: center;
  height: 100%;
  width: max-content; /* Grow as wide as needed for content */
}

/* ===== INDIVIDUAL SLIDES ===== */

.ssck-projects-carousel-item {
  height: 100%;

  /* FIXED SLOT LOGIC:
     We force the item to be exactly 1/3 of the available space (minus gaps).
     This prevents narrow images from shrinking the slot and pulling the 4th slide in.
  */

  /* Basis: (ViewportWidth - 80px Gaps) / 3 */
  flex: 0 0 calc((100cqw - 80px) / 3);
  width: calc((100cqw - 80px) / 3);
  max-width: none; /* Remove max-width constraint, we are enforcing width directly */

  /* Fallback (vw): 100vw - (60px(Chevrons) - 40px(Margins) - 80px(Gaps)) = 180px */
  @supports not (container-type: inline-size) {
    flex: 0 0 calc((100vw - 180px) / 3);
    width: calc((100vw - 180px) / 3);
  }

  box-sizing: border-box;

  display: flex;
  align-items: center;
  justify-content: center; /* Centers the image inside the fixed slot */

  position: relative;
  cursor: pointer;

  /* CRITICAL: Hide slides completely until images load to prevent broken image icon flash */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s 0.3s;
}

/* Remove theme card margins inside the carousel so height stays at 320px */
.ssck-projects-carousel .ssck-projects-carousel-item.project-slide {
  margin: 0;
}

/* Visible when primary image loads */
.ssck-projects-carousel-item.is-primary-loaded {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0s 0s;
}

/* ===== CARD INTERNAL STRUCTURE ===== */

.ssck-projects-carousel-item .card-inner {
  position: relative;
  height: auto; /* Let height be determined by the image, up to max 320px */
  max-height: 100%;
  width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ssck-projects-carousel-item .inside {
  position: relative;
  height: auto;
  width: auto;
  display: flex; /* Ensures anchor tag behaves as a flex item */
}

/* ===== PRIMARY IMAGE ===== */

.ssck-projects-carousel-item .inside a.primary-link {
  position: relative;
  display: block;
  line-height: 0; /* Remove any font-descender spacing */
  width: auto; /* Shrink-wrap the image width */
  height: auto; /* Shrink-wrap the image height */
}

.ssck-projects-carousel-item .inside a img.slide {
  display: block;

  /* SCALING LOGIC:
     1. Constrain height to container (320px).
     2. Constrain width to item max-width (33vw).
     3. Use auto to maintain aspect ratio within those bounds.
  */
  max-height: 320px;
  /* We use specific pixel value or 100% of the .ssck-projects-carousel container. 
     Since parents are flex/auto, inheritance can be tricky. 
     320px is the block setting. */
  max-height: 320px;

  max-width: 100%; /* Respect the item's max-width constraint */

  width: auto;
  height: auto;

  /* Ensure no distortion */
  object-fit: contain;
}

/* ===== REVEALED IMAGE (hidden by default, shown on hover/tap) ===== */

.ssck-projects-carousel-item .inside a img.slide-revealed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;

  /* Because the parent <a> now exactly matches the primary image dimensions (via shrink-wrap),
     object-fit: cover will cover exactly that space. */
  object-fit: cover;

  object-position: center;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
  pointer-events: none;
  z-index: 10;
}

/* ===== PLAY ICONS ===== */

.ssck-projects-carousel-item .inside a .play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(36px, 30%, 216px);
  height: clamp(36px, 30%, 216px);
  background: center / contain no-repeat url("../images/play-icon.png");
  opacity: 0.85;
  pointer-events: none;
  transition: opacity 0.5s ease-in-out;
}

.ssck-projects-carousel-item .inside a .play-icon-primary {
  z-index: 5;
}

.ssck-projects-carousel-item .inside a .play-icon-revealed {
  z-index: 20;
  opacity: 0;
}

/* ===== TITLE OVERLAY ===== */

.ssck-projects-carousel-item .inside a.title-link {
  position: absolute;
  inset: 0;
  display: block;
  z-index: 40;
}

.ssck-projects-carousel-item .inside a.title-link span.title {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  inset: 0;
  padding: 15px;
  font-size: 1em;
  line-height: 1.2;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
  pointer-events: none;
}

.ssck-projects-carousel-item .title span {
  color: #fff;
  background-color: rgba(0, 0, 0, 0.4);
  padding: 7px;
  border-radius: 3px;
}

/* Adjust title position for revealed video content */
.ssck-projects-carousel-item.has-revealed-video .inside a.title-link span.title {
  align-items: center;
  justify-content: center;
  padding: 0;
}

.ssck-projects-carousel-item.has-revealed-video .inside a.title-link span.title span {
  transform: translateY(calc(clamp(18px, 10%, 108px) + 15px));
}

/* ===== TOUCH DEVICES: reveal via .tap-active ===== */

.ssck-projects-carousel-item.tap-active .inside img.slide-revealed,
.ssck-projects-carousel-item.tap-active .inside .play-icon-revealed,
.ssck-projects-carousel-item.tap-active .inside a.title-link span.title {
  opacity: 1;
}

/* ===== HOVER-CAPABLE DEVICES: use :hover pseudo-class ===== */

@media (hover: hover) {
  .ssck-projects-carousel-item .inside:hover img.slide-revealed {
    opacity: 1;
  }

  .ssck-projects-carousel-item .inside:hover .play-icon-revealed {
    opacity: 0.85;
  }

  .ssck-projects-carousel-item .inside:hover a.title-link span.title {
    opacity: 1;
  }
}

/* ===== EMPTY STATE ===== */

.ssck-projects-carousel-empty {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

.ssck-projects-carousel-empty p {
  margin: 0;
  font-size: 14px;
}

/* ============================================================
   LAST SLIDE (optional text-only final slide)
   ============================================================ */

.ssck-projects-carousel-last-slide {
  /* Inherits sizing from .ssck-projects-carousel-item */
  /* Override visibility since we don't need image loading */
  opacity: 1;
  visibility: visible;
}

.ssck-projects-carousel-last-slide .card-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.ssck-projects-carousel-last-slide .inside {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ssck-projects-carousel-last-slide .last-slide-content {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  font-size: clamp(16px, 2.5vw, 20px);
  line-height: 1.5;
  color: #555;
}

.ssck-projects-carousel-last-slide .last-slide-content p {
  margin: 0;
}

.ssck-projects-carousel-last-slide .last-slide-content a {
  color: #0073aa;
  text-decoration: underline;
}

.ssck-projects-carousel-last-slide .last-slide-content a:hover {
  color: #005177;
}

/* ============================================================
   TOP HEADING AND BOTTOM TEXT
   ============================================================ */

.ssck-projects-carousel-top-heading {
  text-align: center;
}

.ssck-projects-carousel-top-heading h2 {
  margin: 0;
  line-height: 1.3;
}

.ssck-projects-carousel-bottom-text {
  text-align: center;
}

.ssck-projects-carousel-bottom-text p {
  margin: 0;
  font-size: 24px;
  /* font-size: clamp(14px, 2vw, 16px); */
  line-height: 1.6;
  color: #666;
}

.ssck-projects-carousel-bottom-text a {
  color: #0073aa;
  text-decoration: underline;
}

.ssck-projects-carousel-bottom-text a:hover {
  color: #005177;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Tablet ≤ 1024px: 2 slides across (1 gap of 30px) */
@media (max-width: 1024px) {
  .ssck-projects-carousel-item {
    /* Formula: (ViewportWidth - 1 Gap) / 2 */
    /* We must explicitly override flex and width to break the 3-across layout */
    flex: 0 0 calc((100cqw - 30px) / 2);
    width: calc((100cqw - 30px) / 2);

    /* Fallback: 100vw - 60px(chevrons) - 40px(margins) - 30px(gap) = 130px */
    @supports not (container-type: inline-size) {
      flex: 0 0 calc((100vw - 130px) / 2);
      width: calc((100vw - 130px) / 2);
    }
  }
}

/* Mobile ≤ 640px: 1 slide across */
@media (max-width: 640px) {
  .ssck-projects-carousel-top-heading {
    margin-bottom: 16px !important;
  }

  .ssck-projects-carousel-grid {
    gap: 0;
  }

  .ssck-projects-carousel-item {
    /* Formula: 1 slide fills the viewport */
    flex: 0 0 100cqw;
    width: 100cqw;
    padding: 0 5px; /* Minimal breathing room */

    /* Fallback for mobile */
    @supports not (container-type: inline-size) {
      /* 100vw - 60px(chevrons) - 40px(margins) = 100px */
      flex: 0 0 calc(100vw - 100px);
      width: calc(100vw - 100px);
    }
  }

  /* Explicit height and centering ensures flex layout works before image loads */
  .ssck-projects-carousel-item .card-inner,
  .ssck-projects-carousel-item .inside {
    height: 320px;
    align-items: center;
    justify-content: center;
  }

  .ssck-projects-carousel-item .inside a img.slide {
    max-height: 320px;
    width: auto;
    max-width: 100%;
  }
}
