.projects {
  max-width: 1200px;
  margin: 5em auto;
  padding: 0 2rem;
}

#projects-container {
  position: relative;
  min-height: 450px;
  transition: height 0.3s ease;
  width: 100%; /* Ensure container doesn't overflow */
  overflow-x: hidden; /* Prevent horizontal scroll */
}

#expandable-image-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2rem;
  width: 90%;
  overflow-y: auto;
  padding: 1rem;
  transition: opacity 0.4s ease, transform 0.4s ease;
  opacity: 1;
  transform: translateY(0);
}

#expandable-image-container::-webkit-scrollbar {
  width: 6px;
}

#expandable-image-container::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
}

#expandable-image-container.hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.img-container {
  position: relative;
  width: 100%;
  max-width: 180px;
  /* Changed to use aspect-ratio instead of fixed height */
  aspect-ratio: 1/1;
  height: auto;
  margin: 0 auto;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.img-container:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.15);
}

.project-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
  transition: transform 0.3s ease;
}

.img-container:hover .project-icon {
  transform: scale(1.05);
}

.close-button {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: background 0.2s ease, transform 0.2s ease;
}

.close-button:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(1.1);
}

.close-icon {
  width: 20px;
  height: 20px;
}

.expandable-image-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  display: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  background-color: white;
  border-radius: 20px;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.expandable-image-content-shown {
  display: flex;
  opacity: 1;
  z-index: 5;
  padding: 2.5rem;
  /* Ensure no overflow causing horizontal scrollbars */
  max-width: 100%;
  box-sizing: border-box;
}

/* Updated expanded view container */
.expandable-image-content-shown .img-container {
  flex-shrink: 0;
  background-color: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fixed dimensions for expanded view */
  width: 180px;
  height: 180px;
}

.expanded-image {
  width: 100%;
  height: 100%;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.expanded-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 2.5rem;
  /* Ensure content doesn't cause overflow */
  width: 100%;
  box-sizing: border-box;
}

/* Project title */
.project-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: #222;
  position: relative;
  padding-bottom: 0.8rem;
}

.project-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 60px;
  height: 3px;
  background-color: #333;
  border-radius: 2px;
}

.expanded-content-text {
  line-height: 1.7;
  color: #444;
  margin-bottom: 2rem;
  /* Ensure text wraps properly */
  word-wrap: break-word;
}

.get-app-button {
  align-self: flex-start;
  background-color: #333;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.get-app-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  background-color: #222;
}

.get-app-button a {
  display: block;
  padding: 0.8em 1.5em;
  text-decoration: none;
  color: white;
  font-weight: 600;
  font-size: 1rem;
}

@media (max-width: 992px) {
  .projects {
    max-width: 90%;
  }
  
  #expandable-image-container {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }
  
  .project-title {
    font-size: 1.6rem;
  }
}

@media (max-width: 768px) {
  .projects {
    max-width: 95%;
    margin-top: 3em;
    padding: 0 1rem; /* Reduced padding */
  }
  
  .showcase-title-text {
    font-size: 2rem;
  }
  
  #expandable-image-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.2rem;
  }
  
  .expandable-image-content-shown {
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    overflow-y: auto; /* Allow vertical scrolling if needed */
  }
  
  .expandable-image-content-shown .img-container {
    width: 120px;
    height: 120px;
    margin-bottom: 1.5rem;
  }
  
  .expanded-content {
    padding: 0;
    text-align: center;
    width: 100%;
  }
  
  .project-title {
    font-size: 1.5rem;
  }
  
  .project-title::after {
    left: 50%;
    transform: translateX(-50%);
  }
  
  .get-app-button {
    align-self: center;
    margin-top: 1rem;
  }
}

@media (max-width: 480px) {
  .projects {
    margin-top: 2em;
    padding: 0 0.8rem; /* Further reduced padding */
  }
  
  .showcase-title-text {
    font-size: 1.75rem;
  }
  
  #expandable-image-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
  
  .project-title {
    font-size: 1.4rem;
  }
  
  /* Ensure image containers maintain aspect ratio */
  .img-container {
    max-width: 100%;
  }
}