/* Gallery surfaces use the same theme and typography as the rest of the site. */
.home-work,
.gallery-page,
.gallery-section {
  background: var(--section-bg, #111111);
  color: var(--section-text, #ffffff);
}

.home-work {
  padding: 80px 0 100px;
  border-top: 1px solid var(--border-section, rgba(140, 144, 150, .4));
}

.gallery-section {
  padding: 85px 0 100px;
}

.home-work > .shell > h2 {
  margin-bottom: 30px;
}

.gallery-page > .shell > h1,
.gallery-section > .shell > h1 {
  font-size: clamp(3.3rem, 6vw, 5.8rem);
}

.gallery-page > .shell > p,
.gallery-section > .shell > p {
  max-width: 720px;
  margin-top: 22px;
  font-size: 1.2rem;
  line-height: 1.55;
}

.home-work__grid,
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gallery-page > .shell > h1 + .gallery-grid,
.gallery-page > .shell > p + .gallery-grid,
.gallery-section > .shell > h1 + .gallery-grid,
.gallery-section > .shell > p + .gallery-grid,
.gallery-filters[hidden] + .gallery-grid {
  margin-top: 32px;
}

.home-work__grid ~ .button,
.home-work__grid + .button-row {
  margin-top: 32px;
}

.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 32px 0 24px;
}

.gallery-filters [data-gallery-filter] {
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid var(--section-muted, #8c9096);
  border-radius: 2px;
  background: transparent;
  color: var(--section-text, #ffffff);
  font-family: var(--head, "Barlow Condensed", sans-serif);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: .035em;
  text-transform: uppercase;
  cursor: pointer;
}

.gallery-filters [data-gallery-filter]:hover {
  border-color: var(--section-accent, #6cc417);
}

.gallery-filters [data-gallery-filter][aria-pressed="true"] {
  border-color: var(--button-green, #397410);
  background: var(--button-green, #397410);
  color: #ffffff;
}

/* Explicitly preserve the hidden attribute when component display is set. */
.home-work__grid[hidden],
.gallery-grid[hidden],
.gallery-filters[hidden],
.gallery-filters [hidden],
.gallery-item[hidden],
.gallery-lightbox[hidden],
.gallery-lightbox [hidden] {
  display: none !important;
}

.gallery-item {
  position: relative;
  display: block;
  min-width: 0;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--service-card-bg, #1e1e1e);
  color: #ffffff;
}

.gallery-item > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--gallery-object-position, center);
}

.gallery-item__play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: clamp(44px, 5vw, 60px);
  height: clamp(44px, 5vw, 60px);
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: rgba(17, 17, 17, .85);
  color: #ffffff;
  line-height: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

svg.gallery-item__play {
  padding: 13px;
  fill: currentColor;
}

.gallery-item__play svg {
  width: 42%;
  height: 42%;
  fill: currentColor;
}

.home-work .gallery-item:focus-visible,
.gallery-page .gallery-item:focus-visible,
.gallery-section .gallery-item:focus-visible,
.gallery-filters [data-gallery-filter]:focus-visible {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--section-accent, #6cc417);
  outline-offset: 2px;
}

/* The dialog is deliberately dark in either theme, with dedicated space for
   the controls, media and unmodified caption. */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  border: 0;
  background: rgba(0, 0, 0, .96);
  color: #ffffff;
  font-family: var(--body, "Barlow", Arial, sans-serif);
  overflow: auto;
}

.gallery-lightbox[open] {
  display: block;
}

.gallery-lightbox::backdrop {
  background: rgba(0, 0, 0, .9);
}

.gallery-lightbox__shell {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  grid-template-rows: 48px minmax(120px, 1fr) auto;
  gap: 12px;
  width: min(100%, 1500px);
  height: 100%;
  min-height: 100%;
  margin: 0 auto;
}

.gallery-lightbox__close,
.gallery-lightbox__previous,
.gallery-lightbox__next {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 10px;
  border: 1px solid #ffffff;
  border-radius: 2px;
  background: #111111;
  color: #ffffff;
  cursor: pointer;
}

.gallery-lightbox__close:hover,
.gallery-lightbox__previous:hover,
.gallery-lightbox__next:hover {
  background: #ffffff;
  color: #111111;
}

.gallery-lightbox__close:focus-visible,
.gallery-lightbox__previous:focus-visible,
.gallery-lightbox__next:focus-visible {
  outline: 3px solid var(--focus-on-dark, #8add42);
  outline-offset: 3px;
}

.gallery-lightbox__close svg,
.gallery-lightbox__previous svg,
.gallery-lightbox__next svg {
  display: block;
  width: 100%;
  height: 100%;
}

.gallery-lightbox__close {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
}

.gallery-lightbox__previous {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
}

.gallery-lightbox__next {
  grid-column: 3;
  grid-row: 2;
  align-self: center;
}

.gallery-lightbox__media {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
}

.gallery-lightbox__media img,
.gallery-lightbox__media video,
img.gallery-lightbox__media,
video.gallery-lightbox__media {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.gallery-lightbox__caption {
  grid-column: 2;
  grid-row: 3;
  justify-self: center;
  max-width: 78ch;
  margin: 0;
  color: #ffffff;
  font-size: 1rem;
  line-height: 1.5;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (width < 768px) {
  .home-work {
    padding: 65px 0 75px;
  }

  .gallery-section {
    padding: 65px 0 75px;
  }

  .home-work > .shell > h2 {
    margin-bottom: 24px;
  }

  .gallery-page > .shell > p,
  .gallery-section > .shell > p {
    font-size: 1.08rem;
  }

  .home-work__grid,
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gallery-lightbox__shell {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    grid-template-rows: 48px minmax(100px, 1fr) auto 48px;
    gap: 10px;
  }

  .gallery-lightbox__media {
    grid-column: 1 / -1;
  }

  .gallery-lightbox__caption {
    grid-column: 1 / -1;
  }

  .gallery-lightbox__previous {
    grid-column: 1;
    grid-row: 4;
  }

  .gallery-lightbox__next {
    grid-column: 3;
    grid-row: 4;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-work .gallery-item,
  .gallery-page .gallery-item,
  .gallery-section .gallery-item,
  .gallery-filters [data-gallery-filter],
  .gallery-lightbox,
  .gallery-lightbox__close,
  .gallery-lightbox__previous,
  .gallery-lightbox__next {
    animation: none;
    transition: none;
  }
}

@media (forced-colors: active) {
  .gallery-filters [data-gallery-filter][aria-pressed="true"] {
    border: 2px solid ButtonText;
    text-decoration: underline;
    text-underline-offset: 3px;
  }
}
