#gallery-container {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 60px;
  align-items: start;
  min-height: 70vh;
  width: 100%;
}

#gallery-container > h1 {
  grid-column: 1 / -1;
}

.gallery {
  grid-column: 1;
  min-width: 0;
  padding-top: 5px;
  padding-bottom: 50px;
  padding-right: 40px;
  padding-left: 20px;
}

.gallery-category { display: none; }

.gallery-category.active {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  padding-right: 20px;
}

.carousel {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 600px;
  margin: auto;
}

.carousel-track {
  display: flex;
  transition: transform 0.5s ease;
  align-items: center;
}

.carousel figure {
  min-width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.carousel img {
  width: 100%;
  height: auto;
  max-height: 500px;
  object-fit: contain;
}

.carousel button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(0,0,0,0.5);
  color: white;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  z-index: 1;
}

.carousel .prev { left: 10px; }
.carousel .next { right: 10px; }

.sidebar {
  grid-column: 2;
  position: sticky;
  top: 20px;
  width: 220px;
  min-height: 90vh;
  box-shadow: 2px -2px 8px rgba(0, 0, 0, 0.3);
  background: #F9F7E9;
  backdrop-filter: blur(4px);
  padding: 20px;
  border-left: 2px solid #ddd;
}

.sidebar h3 {
  margin-bottom: 25px;
  padding-top: 25px;
  color: #431C13;
}

.sidebar ul { list-style: none; padding: 0; margin: 0; }
.sidebar li { margin-bottom: 10px; }

.sidebar a {
  text-decoration: none;
  color: #431C13;
  font-weight: bold;
  display: block;
  padding: 8px;
  border-radius: 4px;
}

.sidebar a.active,
.sidebar a:hover {
  background: #d9b89c;
  color: white;
}

figcaption {
  font-style: italic;
  font-size: large;
  color: #431C13;
  padding-top: 20px;
}

figure {
  display: flex;
  flex-direction: column;
  align-items: center;
}

@media (max-width: 870px) {
  #gallery-container {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .gallery {
    padding-right: 0;
    padding-left: 0;
    padding-bottom: 10px;
  }

  .gallery-category.active {
    padding-right: 0;
  }

  .carousel {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
  }

  .sidebar {
    grid-column: 1;
    position: static;
    width: 100%;
    height: auto;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: none;
    padding: 0;
    background: #F9F7E9;
  }

  .sidebar h3 { display: none; }

  .sidebar ul {
    display: flex;
    gap: 10px;
    margin: 0;
    overflow-x: auto;
    white-space: nowrap;
  }

  .sidebar li { margin-bottom: 0; }

  .sidebar a {
    padding: 6px 10px;
    font-size: 0.9rem;
  }

  figcaption {
    font-size: small;
  }
}

@media (max-width: 400px) {
  html, body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .gallery-category.active {
    grid-template-columns: 1fr;
    padding-left: 5px;
    padding-right: 5px;
  }

  .gallery,
  .carousel {
    padding-left: 0;
    padding-right: 0;
    margin: 0;
    overflow: hidden;
  }

  .carousel img,
  img {
    max-width: 100%;
    height: auto;
    display: block;
  }

  footer {
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .sidebar ul {
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
  }
}
