.gallery-item[type="button"] {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: inherit;
  cursor: pointer;
}

.gallery-item[type="button"]:focus-visible,
.lightbox-close:focus-visible,
.lightbox-nav:focus-visible,
.lightbox-actions a:focus-visible {
  outline: 2px solid var(--theme-ink);
  outline-offset: 3px;
}

.gallery-item img {
  transition: transform 0.32s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
}

dialog.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: max(4rem, env(safe-area-inset-top, 0px)) clamp(1rem, 3vw, 2.5rem) max(1.5rem, env(safe-area-inset-bottom, 0px));
  border: 0;
  color: var(--theme-ink);
  background: var(--theme-scrim);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  opacity: 0;
  transition: opacity 0.18s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
}

dialog.lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
}

@starting-style {
  dialog.lightbox[open] {
    opacity: 0;
  }
}

dialog.lightbox::backdrop {
  background: transparent;
}

.lightbox-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  max-width: min(92vw, 1320px);
  max-height: 100%;
  padding: clamp(0.75rem, 2vw, 1.5rem);
  border: 1px solid var(--theme-modal-hairline, var(--theme-hairline));
  background: var(--theme-modal-bg, var(--theme-bg));
  box-shadow: var(--theme-modal-shadow, none);
  transform: translate3d(0, 6px, 0) scale(0.99);
  transition: transform 0.22s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
}

dialog.lightbox[open] .lightbox-stage {
  transform: translate3d(0, 0, 0) scale(1);
}

@starting-style {
  dialog.lightbox[open] .lightbox-stage {
    transform: translate3d(0, 6px, 0) scale(0.99);
  }
}

.lightbox-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  gap: clamp(0.5rem, 1.5vw, 1.25rem);
}

.lightbox-media img {
  display: block;
  max-width: calc(100% - 6.5rem);
  max-height: calc(100dvh - 15rem);
  object-fit: contain;
}

.lightbox-media:has(.lightbox-nav[hidden]) img {
  max-width: 100%;
}

.lightbox-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--theme-hairline);
  border-radius: 999px;
  background: var(--theme-bg);
  color: var(--theme-ink);
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
}

.lightbox-nav[hidden] {
  display: none;
}

.lightbox-nav:hover {
  background: var(--theme-hover-soft);
  border-color: var(--theme-ink);
}

.lightbox-nav:active {
  transform: scale(0.96);
}

.lightbox-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 48rem;
}

.lightbox-heading {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  text-align: center;
}

#lightbox-title {
  margin: 0;
  font-size: var(--type-base, 1rem);
  font-weight: 500;
  letter-spacing: -0.015em;
}

.lightbox-counter {
  color: var(--site-text-muted, var(--theme-copy-muted));
  font-size: var(--type-xs, 0.75rem);
  font-variant-numeric: tabular-nums;
}

.lightbox-details {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.35rem 1rem;
  width: 100%;
  max-width: 36rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--theme-hairline);
  font-size: var(--type-xs, 0.75rem);
  color: var(--site-text-muted, var(--theme-copy-muted));
}

.lightbox-details[hidden],
.lightbox-actions[hidden],
.lightbox-counter[hidden] {
  display: none;
}

.lightbox-details strong {
  color: var(--theme-ink);
  font-weight: 600;
}

.lightbox-details code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  word-break: break-all;
}

.lightbox-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.lightbox-actions a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--theme-hairline);
  border-radius: var(--radius-control, 8px);
  color: var(--theme-ink);
  font-size: var(--type-xs, 0.75rem);
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.lightbox-actions a:hover {
  background: var(--theme-hover-soft);
  border-color: var(--theme-ink);
}

.lightbox-close {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top, 0px));
  right: clamp(1rem, 3vw, 2rem);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--theme-hairline);
  border-radius: var(--radius-control, 8px);
  color: var(--theme-ink);
  background: var(--theme-bg);
  font-size: var(--type-xs, 0.75rem);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.lightbox-close:hover {
  background: var(--theme-hover-soft);
  border-color: var(--theme-ink);
}

@media (max-width: 767px) {
  .lightbox-media img {
    max-width: 100%;
    max-height: calc(100dvh - 18rem);
  }

  .lightbox-nav {
    position: absolute;
    bottom: -3.25rem;
  }

  .lightbox-nav--prev {
    left: 0;
  }

  .lightbox-nav--next {
    right: 0;
  }

  .lightbox-footer {
    padding-top: 2.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-item img,
  dialog.lightbox,
  .lightbox-stage,
  .lightbox-nav,
  .lightbox-close {
    transition: none;
  }
}
