:root {
  --sidebar-width: 260px;
}

.gallery-wrapper {
  padding-top: var(--space-8);
}

.gallery-container {
  display: flex;
  gap: var(--space-6);
  align-items: flex-start;
  padding-left: var(--space-8);
}

.gallery-sidebar {
  position: sticky;
  top: 140px;
  align-self: start;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.sidebar__header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.sidebar__toggle {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--card-bg);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sidebar__icon,
.sidebar__icon::before,
.sidebar__icon::after {
  content: "";
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 999px;
}
.sidebar__icon::before,
.sidebar__icon::after {
  position: relative;
}
.sidebar__icon::before {
  top: -6px;
}
.sidebar__icon::after {
  top: 4px;
}

.sidebar__nav {
  display: grid;
  gap: var(--space-2);
}

.sidebar__link {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  display: block;
  color: var(--text-primary);
  transition: background var(--duration-fast) var(--easing-smooth), border-color var(--duration-fast) var(--easing-smooth), transform var(--duration-fast) var(--easing-smooth), color var(--duration-fast) var(--easing-smooth);
}

.sidebar__link:hover,
.sidebar__link.is-active {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  transform: translateX(2px);
}

.gallery-content {
  flex: 1;
  display: grid;
  gap: var(--space-10);
}

.gallery-section {
  scroll-margin-top: 120px;
  padding-top: 0;
  margin-bottom: var(--space-12);
}

.gallery-section__header {
  margin-bottom: var(--space-4);
}

.gallery-section__title {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: -0.01em;
}

.gallery-section__description {
  margin: 0;
  color: var(--text-secondary);
  max-width: 72ch;
}

.gallery-section + .gallery-section {
  padding-top: 0;
  border-top: none;
}

.gallery-card {
  margin-top: var(--space-4);
  padding: var(--space-6);
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--color-border);
}

.image-grid {
  column-count: 3;
  column-gap: var(--space-4);
  width: 100%;
  margin-top: var(--space-6);
}

.image-grid figure {
  break-inside: avoid;
  margin: 0 0 var(--space-4) 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.08);
  transition: transform var(--duration-fast) var(--easing-smooth), box-shadow var(--duration-fast) var(--easing-smooth);
}

.image-grid img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-lg);
  object-fit: cover;
  transition: transform var(--duration-base) var(--easing-smooth);
}

.image-grid figure:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.14);
}

.image-grid figure:hover img {
  transform: scale(1.02);
}

.image-grid::after {
  content: "";
  display: block;
  height: var(--space-4);
}

.lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-base) var(--easing-smooth);
  z-index: 50;
}

.lightbox.is-open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox__backdrop {
  position: absolute;
  inset: 0;
}

.lightbox__content {
  position: relative;
  max-width: min(90vw, 1200px);
  max-height: 80vh;
}

.lightbox__content img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.lightbox__close {
  position: absolute;
  top: -16px;
  right: -16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1200px) {
  .image-grid {
    column-count: 2;
  }
}

@media (max-width: 900px) {
  .gallery-container {
    flex-direction: column;
    padding-left: 0;
  }
  .gallery-sidebar {
    position: relative;
    top: auto;
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .sidebar__toggle {
    display: inline-flex;
  }
  .sidebar__nav {
    display: none;
    gap: var(--space-2);
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .sidebar__nav.is-open {
    display: flex;
  }
}

@media (max-width: 640px) {
  .image-grid {
    column-count: 1;
  }
  .gallery-section {
    padding-top: 24px;
  }
}

body[data-theme="dark"] .gallery-sidebar,
body[data-theme="dark"] .lightbox__close {
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.6);
}

body[data-theme="dark"] .sidebar__link:hover,
body[data-theme="dark"] .sidebar__link.is-active {
  background: rgba(34, 197, 94, 0.18);
}

/* FIX for sticky sidebar being trapped by .section overflow */
.gallery-wrapper.section {
  overflow: visible !important;
}
