.gallery-modal {
  box-sizing: border-box;
  width: min(1120px, calc(100vw - 32px));
  height: min(900px, calc(100vh - 32px));
  height: min(900px, calc(100dvh - 32px));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  border: 1px solid #bec8ba;
  border-radius: 12px;
  background: #f7f5ee;
  color: #1f3431;
  box-shadow: 0 24px 90px #12252166;
  overflow: hidden;
  overscroll-behavior: contain;
}

.gallery-modal[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.gallery-modal::backdrop {
  background: #1f3431d9;
}

.gallery-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid #dcded3;
}

.gallery-modal-title {
  margin: 0;
  color: inherit;
  font-size: clamp(16px, 2vw, 21px);
  line-height: 1.4;
}

.gallery-modal-button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid #bec8ba;
  border-radius: 4px;
  background: transparent;
  color: #1f3431;
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
}

.gallery-modal-button:hover:not(:disabled) {
  background: #e6ebe1;
  border-color: #1f3431;
}

.gallery-modal-button:focus-visible {
  outline: 2px solid #1f3431;
  outline-offset: 3px;
}

.gallery-modal-button:disabled {
  opacity: .4;
  cursor: default;
}

.gallery-modal-close > [aria-hidden] {
  font-size: 24px;
  line-height: 1;
}

.gallery-modal-stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 16px;
  overflow: hidden;
}

.gallery-modal-image {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.gallery-modal-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-top: 1px solid #dcded3;
}

.gallery-modal-previous {
  justify-self: start;
}

.gallery-modal-next {
  justify-self: end;
}

.gallery-modal-count {
  margin: 0;
  color: #47534c;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
  .gallery-modal {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    height: calc(100dvh - 16px);
    border-radius: 8px;
  }

  .gallery-modal-header,
  .gallery-modal-footer {
    gap: 8px;
    padding: 10px 12px;
  }

  .gallery-modal-stage {
    padding: 10px;
  }

  .gallery-modal-button {
    gap: 5px;
    padding-inline: 10px;
    font-size: 12px;
  }

  .gallery-modal-count {
    max-width: 92px;
    font-size: 12px;
  }
}
