#filmsproject {
  width: 100vw;
  position: relative;
  z-index: 50; /* Higher z-index to prevent other sections showing through */
  background-color: #e0dfdc;
  overflow: hidden;
}

.scroll-container {
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(150, 150, 150, 0.5) transparent;
}

.scroll-container::-webkit-scrollbar {
  width: 8px;
}

.scroll-container::-webkit-scrollbar-track {
  background: transparent;
}

.scroll-container::-webkit-scrollbar-thumb {
  background-color: rgba(150, 150, 150, 0.5);
  border-radius: 10px;
}

.gridBlock {
  opacity: 0;
}

.grid-container {
  width: 100vw;
  height: 400vh;
  position: relative;
}

.grid {
  top: 0;
  left: 0;
  z-index: 1;
  width: 70vw;
  height: 60vw;
  margin: 0 calc(100vw / 20 * 3);
  position: absolute;
}

@media only screen and (max-width: 580px) {
  .grid {
    margin: 0;
    width: 100vw;
    height: 89.444vw;
  }
}

.gridBlock {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  /* background-color: darkgray; */
  transition: transform 0.3s ease-in-out, z-index 0s;
  cursor: pointer;
  position: absolute;
  border-radius: 4px;
  z-index: 1; /* Set a base z-index for all blocks */
  pointer-events: auto; /* Ensure hover works */
}

.gridBlock:not(.centerBlock):hover {
  transform: scale(1.2);
  z-index: 100; /* Higher z-index when hovered */
}

/* Disable hover effect during animation */
.grid.animating .gridBlock:hover {
  transform: none;
}

.gridLayer {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  position: absolute;
  will-change: transform;
  transform-origin: 44.951% 50%;
  z-index: 1; /* Changed from -1 to 1 to allow interactions */
  pointer-events: none; /* This makes the layer ignore mouse events */
}

/* Desktop grid positions */
.gridLayer:nth-child(1) .gridBlock {
  top: 2vw;
  left: 19vw;
  width: 12vw;
  height: 12vw;
}

.gridLayer:nth-child(2) .gridBlock {
  top: 2vw;
  left: 29.5vw;
  width: 12vw;
  height: 12vw;
}

.gridLayer:nth-child(3) .gridBlock {
  left: 0vw;
  top: 10vw;
  width: 20vw;
  height: 20vw;
}

.gridLayer:nth-child(4) .gridBlock {
  top: 15.5vw;
  left: 17.5vw;
  width: 30vw;
  height: 30vw;
}

.gridLayer:nth-child(5) .gridBlock {
  top: 17.5vw;
  left: 49.5vw;
  width: 8vw;
  height: 8vw;
}

.gridLayer:nth-child(5) a {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gridLayer:nth-child(5) svg {
  width: 1.75vw;
}

.gridLayer:nth-child(6) .gridBlock {
  left: 47vw;
  top: 26.5vw;
  width: 20vw;
  height: 20vw;
}

.gridLayer:nth-child(7) .gridBlock {
  left: 3vw;
  top: 33vw;
  width: 15vw;
  height: 15vw;
}

.gridLayer:nth-child(8) .gridBlock {
  top: 8vw;
  left: 41.5vw;
  width: 6vw;
  height: 6vw;
}

.gridLayer:nth-child(9) .gridBlock {
  top: 50vw;
  left: 42vw;
  width: 13vw;
  height: 13vw;
}

.gridLayer:nth-child(10) .gridBlock {
  top: 2vw;
  left: 47.5vw;
  width: 13vw;
  height: 13vw;
}

.gridLayer:nth-child(11) .gridBlock {
  top: 5vw;
  left: 58vw;
  width: 20vw;
  height: 20vw;
}

.gridLayer:nth-child(12) .gridBlock {
  top: 4vw;
  right: 67vw;
  width: 10vw;
  height: 10vw;
}

.gridLayer:nth-child(13) .gridBlock {
  top: 16vw;
  right: 65vw;
  width: 17vw;
  height: 17vw;
}

.gridLayer:nth-child(14) .gridBlock {
  top: 26.5vw;
  left: 65vw;
  width: 15vw;
  height: 15vw;
}

.gridLayer:nth-child(15) .gridBlock {
  top: 43vw;
  left: 66vw;
  width: 9vw;
  height: 9vw;
}

.gridLayer:nth-child(16) .gridBlock {
  top: 50vw;
  left: 25vw;
  width: 22vw;
  height: 22vw;
}

.gridLayer:nth-child(17) .gridBlock {
  top: 48vw;
  left: 52vw;
  width: 15vw;
  height: 15vw;
}

.gridLayer:nth-child(18) .gridBlock {
  top: 35vw;
  right: 65vw;
  width: 19vw;
  height: 19vw;
}

.gridLayer:nth-child(19) .gridBlock {
  top: 50vw;
  left: 18.5vw;
  width: 10vw;
  height: 10vw;
}

.gridLayer:nth-child(20) .gridBlock {
  top: 50vw;
  right: 60vw;
  width: 7vw;
  height: 7vw;
}

.gridLayer:nth-child(21) .gridBlock {
  top: 50vw;
  left: 8.5vw;
  width: 12vw;
  height: 12vw;
}

.gridBlock {
  display: block;
  position: absolute;
}

/* Grid label styles */
.grid-label {
  opacity: 0.9;
  transition: opacity 0.3s ease;
}

.gridBlock:hover .grid-label {
  opacity: 1;
}

.canvas-top-text {
  font-size: clamp(1.2rem, 4vw, 2.5rem); /* Responsive font size using clamp */
  font-weight: bold;
  color: #121516;
  opacity: 1;
  position: relative;
  top: 30%;
}

.canvas-bot-text {
  font-size: clamp(1rem, 3vw, 2rem); /* Responsive font size using clamp */
  font-weight: bold;
  color: #121516;
  opacity: 1;
  position: relative;
  bottom: 20%;
}

/* ============= MEDIA QUERIES ============= */

/* Max width 768px */
@media (max-width: 768px) {
  #filmsproject {
    height: auto;
    min-height: 100vh;
  }

  .grid-container {
    height: 300vh; /* Adjust height for mobile */
  }

  /* Adjust grid scaling */
  .gridBlock {
    transform-origin: center center;
  }

  /* Disable animations that might cause performance issues on mobile */
  .gridBlock:not(.centerBlock):hover {
    transform: scale(1.1); /* Smaller scale increase on mobile */
  }

  /* Ensure mobile touch interactions work smoothly */
  .gridLayer {
    pointer-events: auto;
  }

  .gridLayer .gridBlock {
    pointer-events: auto;
  }

  /* Improve mobile scrolling */
  .scroll-container {
    -webkit-overflow-scrolling: touch;
  }

  .canvas-top-text {
    font-size: 0.8rem;
    top: 20%;
    left: 0;
  }

  .canvas-bot-text {
    font-size: 0.7rem;
    bottom: 5%;
    left: 0;
  }
}

/* Max width 580px - Main mobile grid layout */
@media only screen and (max-width: 580px) {
  .grid {
    margin: 0;
    width: 100vw;
    height: 89.444vw;
  }

  .gridLayer:nth-child(1) .gridBlock {
    top: 11.111vw;
    left: 23.889vw;
    width: 15vw;
    height: 15vw;
  }

  .gridLayer:nth-child(2) .gridBlock {
    top: 0;
    left: 43.333vw;
    width: 26.389vw;
    height: 26.389vw;
  }

  .gridLayer:nth-child(3) .gridBlock {
    top: 30.278vw;
    left: 0;
    width: 26.389vw;
    height: 26.389vw;
  }

  .gridLayer:nth-child(4) .gridBlock {
    top: 30.278vw;
    left: 30.278vw;
    width: 39.444vw;
    height: 39.444vw;
  }

  .gridLayer:nth-child(5) .gridBlock {
    top: 23.889vw;
    left: 73.889vw;
    width: 15.278vw;
    height: 15.278vw;
  }

  .gridLayer:nth-child(5) svg {
    width: 4.722vw;
  }

  .gridLayer:nth-child(6) .gridBlock {
    top: 43.889vw;
    left: 73.889vw;
    width: 26.389vw;
    height: 26.389vw;
  }

  .gridLayer:nth-child(7) .gridBlock,
  .gridLayer:nth-child(8) .gridBlock {
    display: none;
  }

  .gridLayer:nth-child(9) .gridBlock {
    top: 73.889vw;
    left: 58.889vw;
    width: 15.278vw;
    height: 15.278vw;
  }

  .gridLayer:nth-child(10) .gridBlock {
    top: 73.889vw;
    left: 0;
    width: 20vw;
    height: 20vw;
  }

  .gridLayer:nth-child(11) .gridBlock {
    top: 73.889vw;
    left: 25vw;
    width: 20vw;
    height: 20vw;
  }

  .gridLayer:nth-child(12) .gridBlock {
    top: 73.889vw;
    left: 78vw;
    width: 15vw;
    height: 15vw;
  }

  .gridLayer:nth-child(13) .gridBlock {
    top: 89vw;
    left: 10vw;
    width: 20vw;
    height: 20vw;
  }

  .gridLayer:nth-child(14) .gridBlock {
    top: 89vw;
    left: 40vw;
    width: 20vw;
    height: 20vw;
  }

  .gridLayer:nth-child(15) .gridBlock {
    top: 89vw;
    left: 70vw;
    width: 20vw;
    height: 20vw;
  }

  /* Changing from display:none to random positions */
  .gridLayer:nth-child(16) .gridBlock {
    top: 105vw;
    left: 5vw;
    width: 22vw;
    height: 22vw;
  }

  .gridLayer:nth-child(17) .gridBlock {
    top: 105vw;
    left: 32vw;
    width: 18vw;
    height: 18vw;
  }

  .gridLayer:nth-child(18) .gridBlock {
    top: 105vw;
    left: 55vw;
    width: 19vw;
    height: 19vw;
  }

  .gridLayer:nth-child(19) .gridBlock {
    top: 105vw;
    left: 78vw;
    width: 17vw;
    height: 17vw;
  }

  .gridLayer:nth-child(20) .gridBlock {
    top: 130vw;
    left: 20vw;
    width: 25vw;
    height: 25vw;
  }

  .gridLayer:nth-child(21) .gridBlock {
    top: 130vw;
    left: 50vw;
    width: 25vw;
    height: 25vw;
  }
}

/* Max width 480px - Small mobile devices */
@media screen and (max-width: 480px) {
  .canvas-top-text {
    font-size: 0.6rem;
    top: 20%;
    left: -3vw;
  }

  .canvas-bot-text {
    font-size: 0.5rem;
    bottom: 5%;
    left: -3vw;
    text-align: center;
  }

  .grid-label {
    font-size: 7px !important;
    padding: 1px 3px !important;
    top: 2px !important;
    left: 2px !important;
  }
}

/* Max width 1200px - Small desktop/tablets */
@media screen and (max-width: 1200px) {
  .grid-label {
    font-size: 10px !important;
    padding: 2px 5px !important;
  }
}

/* Responsive Display Control */
.desktop-films {
  display: block;
}

.mobile-films {
  display: none;
}

@media only screen and (max-width: 768px) {
  .desktop-films {
    display: none;
  }

  .mobile-films {
    display: block;
  }
}

/* Mobile Films Carousel Styles */
.mobile-films {
  background: #e0dfdc;
  min-height: 100vh;
  padding: 2rem 0;
  position: relative;
}

.films-header {
  text-align: center;
  padding: 2rem 1rem;
  margin-bottom: 0rem;
}

.films-title {
  font-family: "Montserrat", sans-serif;
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.films-subtitle {
  font-family: "Roboto", sans-serif;
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: #7f8c8d;
  margin: 0;
  max-width: 600px;
  margin: 0 auto;
}

.gallery {
  position: relative;
  width: 100%;
  height: 70vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cards {
  position: relative;
  width: 18rem;
  height: 22rem;
  margin: 0;
  padding: 1rem;
  list-style: none;
  overflow: visible;
}

.card {
  position: absolute;
  top: 0;
  left: 1rem;
  width: 16rem;
  height: 22rem;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  align-items: flex-end;
  will-change: transform;
  touch-action: pan-y;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  -webkit-backface-visibility: hidden;
  border-radius: 1rem;
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 60%,
    rgba(0, 0, 0, 0.7) 100%
  );
  z-index: 1;
}

.card-content {
  position: relative;
  z-index: 2;
  padding: 1.5rem;
  width: 100%;
  color: white;
}

.card-content h3 {
  font-family: "Montserrat", sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  line-height: 1.3;
}

.card-content p {
  font-family: "Roboto", sans-serif;
  font-size: 0.9rem;
  margin: 0;
  opacity: 0.9;
  font-weight: 300;
}

.actions {
  position: absolute;
  bottom: 0rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1rem;
  z-index: 10;
}

.actions button {
  padding: 12px 24px;
  background: #121516;
  border: none;
  border-radius: 10px;
  color: white;
  font-family: "Montserrat", sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.actions button:hover {
  background: #405a74;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.actions button:active {
  transform: translateY(0);
}

/* Smaller mobile devices */
@media only screen and (max-width: 480px) {
  .cards {
    width: 16rem;
    height: 20rem;
  }

  .card {
    width: 14rem;
    height: 20rem;
    left: 1rem;
  }

  .films-header {
    padding: 1.5rem 1rem;
  }

  .actions button {
    padding: 10px 20px;
    font-size: 0.8rem;
  }

  .gallery {
    height: 60vh;
  }
}
