How to to set a padding around the page body, draw a frame/border around it, and then add some margin?

What if I want to set a padding around the page body (on all pages), draw a frame/border around it, and then add some margin?

The geometry package doesn't seem to have an option for this among its basic options because it doesn't separate padding and margin.

(I'm asking this question about the whole page body, rather than about a box explicitly coded in the sources.

I'm dealing with LaTeX.)

What I want to achieve -- each page is printed like this:

>outer margin< | >left<  >mpwidth< >text body< >right< | >outer margin<
|                     ......            |
|                    Text text          |
|         marginpar  Text text          |
|                    Text text          |
|                     ......            |


Then, I'd also like to change the color of the frame depending on the text (with a command from the text). The frame/border style could be fancier than just a plain rule/line. The piece inside the frame is like a complete customizable page layout: a custom left margin width, a custom right margin width, and a custom marginpar width. This doesn't cross the frame. The frame is at a fixed distance from the edge of the paper ("outer margin").

I think the package background in combination with tikzpagenodes is a good choise.

As a starting point you can use:

Add background colour to margin notes area

However there is one disclaimer. The package background can change the color of the frame only for the whole page.

Here an example where you can control the distance between the frame and the text by the new two dimensions \xinnersep and \yinnersep:

\documentclass{book}
\usepackage{tikzpagenodes}
\usepackage{background}
\usepackage{lipsum}
\newlength{\xinnersep}
\setlength{\xinnersep}{1.5cm}
\newlength{\yinnersep}
\setlength{\yinnersep}{0.5cm}
\backgroundsetup{
scale=1,
angle=0,
contents={%
\begin{tikzpicture}[remember picture,overlay]
\draw[blue,line width=2pt,] ([xshift=-\xinnersep,yshift=\yinnersep]current page text area.north west) --
([xshift=\xinnersep,yshift=\yinnersep]current page text area.north east) --
([xshift=\xinnersep,yshift=-\yinnersep]current page text area.south east) --
([xshift=-\xinnersep,yshift=-\yinnersep]current page text area.south west) -- cycle;
\end{tikzpicture}%
}}

\begin{document}
\lipsum[1-15]
\end{document}