/**
 * Main Ginko theme: base styles for the front end and the editor canvas.
 *
 * Loaded on the front end after WordPress' global styles (dependency `global-styles`, so the
 * mobile steps below win the tie with the theme.json element rules) and in the editor canvas
 * through add_editor_style(), where WordPress scopes every rule with
 * `:where(.editor-styles-wrapper)` (zero specificity). Values come from theme.json presets.
 * Reproduces the reset and base typography of the legacy main.4881bccd.css / main.a27b9fe4.css
 * (docs/research/inventory.md §1.5): same selectors, same specificity, so every block sees the
 * computed styles it saw on the original.
 */

/* ===== Reset: legacy normalize equivalents ===== */

/* Legacy `*, :after, :before { border: none; box-sizing; margin: 0; padding: 0 }`. The legacy
   `outline: none` is not carried over: the focus ring below replaces it (D5). */
*,
::before,
::after {
	box-sizing: border-box;
	padding: 0;
	margin: 0;
	border: none;
}

/* Legacy `* { font-family: Lexend, sans-serif }`: every element gets the family explicitly, so
   form controls and UA monospace elements match the original. */
* {
	font-family: var(--wp--preset--font-family--body);
}

/* Legacy body: kerning and ligatures off. It changes glyph advance, so pixels depend on it. */
body {
	text-rendering: optimizespeed;
}

img {
	max-width: 100%;
	display: block;
}

button,
input,
select,
textarea {
	font: inherit;
}

/* ===== Base typography (legacy element rules; headings are in theme.json) ===== */

/* The legacy line heights are percentages, not factors: `175%` computes to px on the element and
   children with another font size inherit that px value. A unitless 1.75 would differ there, so
   the percentage stays (stylelint's unit rule is switched off for these three declarations). */

/* stylelint-disable declaration-property-unit-allowed-list */

p {
	font-size: var(--wp--preset--font-size--m);
	font-weight: 400;
	line-height: 175%;
}

small {
	font-size: var(--wp--preset--font-size--xs);
	font-weight: 400;
	line-height: 175%;
}

p small {
	font-size: var(--wp--preset--font-size--s);
}

mark {
	background: none;
	font-weight: 600;
	color: var(--wp--preset--color--accent);
	letter-spacing: 0.02em;
}

b {
	font-weight: 600;
	letter-spacing: 0.01em;
}

ul {
	line-height: 175%;
}

li {
	margin-left: var(--wp--preset--spacing--m);
}

/* A phone number link never breaks inside ("+49 170 / 1143284" in the Kontakt text at 320-338,
   379-403 and 1134-1248 px, legacy too; D349, deviation #330): it moves to the next line as a
   whole. In every text, also numbers the client types later; the editor canvas loads this file too. */
a[href^="tel:"] {
	white-space: nowrap;
}

/* stylelint-enable declaration-property-unit-allowed-list */

/* Mobile type steps (D12): theme.json holds the desktop sizes, and root `elements.h1.@mobile`
   is not printed by WordPress 7.1. Same values as the legacy `max-width: 750px` block. Headings
   use `body h1` (0,0,2): it beats the theme.json `h1` rule (0,0,1) in any source order (the
   editor canvas prints global styles after this file) and still loses to every class rule, as
   the legacy bare `h1` did. The mobile h3 size (24px) has no preset: no other text uses it. */
@media (max-width: 750px) {

	body h1 {
		font-size: var(--wp--preset--font-size--xxxl);
	}

	body h2 {
		font-size: var(--wp--preset--font-size--xxl);
	}

	body h3 {
		font-size: 24px;
	}

	body h4 {
		font-size: var(--wp--preset--font-size--l);
	}

	body h5 {
		font-size: var(--wp--preset--font-size--m);
	}

	/* h6 has no legacy rule (D312 (3)): one step below h5, like the desktop sizes. */
	body h6 {
		font-size: var(--wp--preset--font-size--s);
	}

	p,
	p b {
		font-size: var(--wp--preset--font-size--s);
	}

	p small,
	p small b {
		font-size: var(--wp--preset--font-size--xs);
	}

	small,
	small b {
		font-size: var(--wp--preset--font-size--xxs);
	}
}

/* ===== Page offset and anchors (build-plan §2.5, D41, D54) ===== */

/* Legacy body padding-top 67px (≤750: 56px) plus the 24px line box of the broken <head> (Q1):
   content starts at y=91 (≤750: y=80) under the fixed header. */
.wp-site-blocks {
	padding-top: 80px;
}

/* Anchor targets land right below the fixed header, as the legacy SmoothScroll header offset did:
   the page's `scroll-padding-top` (below, D524) already keeps the header height and 1rem of air
   clear, so a jump target takes the 1rem back (D540; with its own header-high margin on top the
   targets landed 131px too low). */
[id] {
	scroll-margin-top: -1rem;
}

@media (min-width: 751px) {

	.wp-site-blocks {
		padding-top: 91px;
	}
}

/* Short pages (D306): the page column is at least as tall as the window and `<main>` takes the
   free height, so on a page shorter than the window (the 404 page, a short page the client adds)
   the footer part sits at the window's bottom edge instead of above a white strip. On pages taller
   than the window nothing moves (the header is fixed, the block gap is 0). The admin bar height is
   subtracted for logged-in users, so the page does not scroll by 32px. */
.wp-site-blocks {
	/* stylelint-disable-next-line custom-property-pattern -- core's admin bar height variable. */
	min-height: calc(100vh - var(--wp-admin--admin-bar--height, 0px));
	display: flex;
	flex-direction: column;
}

.wp-site-blocks > main {
	flex-grow: 1;
}

/* Editor canvas (pages open template-locked, D83; Site Editor): the header block sits in the flow
   there instead of over the page (main-ginko/site-header editor.scss, build-plan R9), so the
   content follows it directly without the page offset. The canvas root may carry `wp-site-blocks`
   itself; it stays a plain block list there (no window height, no flex column, D306). */
.editor-styles-wrapper .wp-site-blocks {
	min-height: 0;
	padding-top: 0;
	display: block;
}

@media (prefers-reduced-motion: no-preference) {

	html {
		scroll-behavior: smooth;
	}
}

/* Fixed header (audit F03, WCAG 2.4.11, D524): the browser keeps a focused element and a jump
   target clear of the header (80px, from 751px 88px since D545; plus the admin bar when logged in) and 1rem
   of air, also when tabbing backwards. */
html {
	/* stylelint-disable-next-line custom-property-pattern -- core's admin bar height (admin-bar.css). */
	scroll-padding-top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--wp--preset--dimension--header-mobile, 80px) + 1rem);
}

@media (min-width: 751px) {

	html {
		/* stylelint-disable-next-line custom-property-pattern -- core's admin bar height (admin-bar.css). */
		scroll-padding-top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--wp--preset--dimension--header, 88px) + 1rem);
	}
}

/* Text links are accent-strong (theme.json, audit F04, D523); on hover they turn ink with a thicker
   underline, so the hover shows in more than the colour. */
a:where(:not(.wp-element-button)):hover {
	text-decoration-thickness: 2px;
}

/* Core's "Zum Inhalt springen" link (block themes print it before the header) in the site's
   primary button look while it has focus (D544): green gradient pill, dark text, Lexend, with the
   site's focus ring. Hidden until focused, as core has it. (0,3,1) beats core's
   inline rule `.skip-link.screen-reader-text:focus` (grey box, 1em system font). */
body .screen-reader-text[href="#wp--skip-link--target"]:focus {
	padding: 17px 24px;
	top: calc(var(--wp-admin--admin-bar--height, 0px) + 12px); /* stylelint-disable-line custom-property-pattern -- core's admin bar height. */
	left: 16px;
	background: var(--wp--preset--gradient--accent, linear-gradient(170.33deg, #9bd46a -0.19%, #6ba368 99.74%));
	border-radius: var(--wp--preset--border-radius--pill, 50px);
	outline: var(--wp--custom--focus--width, 3px) solid var(--wp--preset--color--focus, #296f00);
	box-shadow: 0 8px 24px rgb(0 0 0 / 15%);
	font-family: var(--wp--preset--font-family--body, Lexend, sans-serif);
	font-size: var(--wp--preset--font-size--s, 14px);
	font-weight: 600;
	line-height: 1;
	color: var(--wp--preset--color--text, #212423);
	text-decoration: none;
	letter-spacing: 0.02em;
	outline-offset: var(--wp--custom--focus--offset, 3px);
}

/* ===== Legal pages (build-plan §3 U15, D58, D308) ===== */

/* Named prose container: `core/group` `mg-legal-page` (`<article>`) with the groups
   `mg-legal-page__header` (h1) and `mg-legal-page__content` (the text). Every element inside is a
   plain core block (heading, paragraph, list) that takes the base typography above and the
   theme.json element rules, so text the client adds looks like the seeded text. Values of the
   legacy `article` + `.styles_Impressum__article` / `__section` rules: article max 1280px,
   flex column centred, gap 48px at every width plus 1em (16px) margin on every child after the
   first (`article > * + *`); padding 48/24/72 (≤750px), 72/48/144 (≤1112px), 72/72/144;
   children full width; the two sections are flex columns with a 24px gap. Mobile first. */
.mg-legal-page {
	width: 100%;
	max-width: var(--wp--style--global--content-size);
	padding: var(--wp--preset--spacing--xl) var(--wp--preset--spacing--m) var(--wp--preset--spacing--xxl);
	margin-inline: auto;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--wp--preset--spacing--xl);
}

.mg-legal-page > :where(:not(a)) {
	width: 100%;
}

/* `:root` + one class (0,2,0): beats core's flow-layout margin reset `:root :where(.is-layout-flow) > *`
   (0,1,0), which comes later in the editor canvas; so the text sits as low there as on the page. */
:root .mg-legal-page > * + * {
	margin-top: var(--wp--preset--spacing--s);
}

/* A group the client emptied (e.g. "Seitentitel" after "Löschen" on its h1, or a "Text" left with
   only an empty "Buttons" row) leaves no extra gap on the page: the text then starts where it
   starts with the group removed (D310 (3), D317 (2)). `:not(:has(…))` instead of `:empty`: the
   saved group holds white space between its tags, which `:empty` does not ignore. `:root` + two
   classes + `:has()` (0,5,0) beat the flex column of the groups in a legal text (0,4,0, below). In
   the editor the group keeps core's appender, so it is not empty there. */
:root .mg-legal-page > .wp-block-group:not(:has(> :not(.mg-error__actions:empty))) {
	display: none;
}

.mg-legal-page > .wp-block-group:not(:has(> :not(.mg-error__actions:empty))):first-child + * {
	margin-top: 0;
}

/* Text blocks directly in the frame (D313 (2)): "Gruppierung aufheben" on "Text" moves its
   headings, paragraphs and lists into the article, where gap 48 + margin 16 would set them 64px
   apart. Two neighbours that are neither "Seitentitel" nor "Text" keep the text rhythm of 24px
   (48 − 24 = 24); "Seitentitel" → next block and a block ↔ a "Text" group stay 64px, as the two
   seeded sections. (0,4,0) beats the 16px rule above. */
:root .mg-legal-page > :not(.mg-legal-page__header, .mg-legal-page__content) + :not(.mg-legal-page__header, .mg-legal-page__content) {
	margin-top: calc(var(--wp--preset--spacing--m) - var(--wp--preset--spacing--xl));
}

/* The two parts carry their own layout (D313 (1)), also without the frame ("Gruppierung aufheben"
   on "Rechtstext" puts them into the page content, see "Free text blocks at the page's top
   level" below). */
.mg-legal-page__header,
.mg-legal-page__content {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--m);
}

/* A "Rechtstext" inside a legal text (inserted into "Text" or pasted, D313 (4)): no second frame
   padding or width; the editor normally unwraps it to its text (app/filters/freeDocumentPatterns.ts). */
.mg-legal-page .mg-legal-page {
	max-width: none;
	padding: 0;
}

:root .mg-legal-page .mg-legal-page > :not(:first-child) {
	margin-top: 0;
}

/* Groups the client makes inside the legal text ("Gruppieren", a Stapel/Zeile/Raster from the
   inserter) keep the text rhythm (D312 (2)): 24px between their children, like the "Text" group.
   A plain group is a flex column like "Text"; row and grid groups keep their layout and only get
   the gap. The "Block-Abstände" control is off on these groups (plugin
   app/filters/legalDesignSettings.ts), so this gap is never added to. `:root` + two classes beat
   core's `:root :where(.is-layout-*)` gap and margin rules in the editor canvas too. */
:root :is(.mg-legal-page, .mg-legal-page__content) .wp-block-group {
	gap: var(--wp--preset--spacing--m);
}

:root :is(.mg-legal-page, .mg-legal-page__content) .wp-block-group:is(.is-layout-flow, .is-layout-constrained) {
	display: flex;
	flex-direction: column;
}

/* "Gruppieren" makes a constrained group: core centres its children with `margin-inline: auto`,
   which in a flex column shrinks them to their text and centres them. Full width keeps them on the
   text's left edge, as in a flow group. "Text" itself is such a group. An Aktionsbutton is not
   stretched (D316 (1)): it keeps its own `width: fit-content` (full width only with its own
   "Volle Breite" option), see "Action buttons in a legal text" below. */
:is(.mg-legal-page, .mg-legal-page__content) .wp-block-group:is(.is-layout-flow, .is-layout-constrained) > :where(:not(.alignleft, .alignright, a)) {
	width: 100%;
}

/* Action buttons in a legal text (D316 (1)): an Aktionsbutton placed directly in "Text" ("+" of
   "Text", "Gruppierung aufheben" on "Buttons") or in the frame ("Gruppierung aufheben" on "Text")
   sits on the text's left edge with its own width, like the seeded button in its "Buttons" row.
   The frame centres its children (`align-items: center`), so the button is pulled to the start.
   The button is matched as a link element (`a`) that is a direct child of a group: the
   Aktionsbutton is the only block whose root is a link (text links sit inside a paragraph), and
   the theme names no class of a plugin block (stylelint `selector-disallowed-list`, architecture
   check A8). Its "Volle Breite" option still fills the text (the button's own `width: 100%`). */
:root :is(.mg-legal-page, .mg-legal-page__content) > a {
	align-self: flex-start;
}

/* A "Raster" in a legal text or the 404 page has 1–3 columns or "Automatisch" (the "Spalten"
   panel, plugin app/filters/footerGridColumns.tsx, D316 (4)); up to 750px every grid is one column,
   as in the footer, so three cards do not squeeze to 98px each on a phone. (0,3,0) beats core's
   generated `.wp-container-core-group-is-layout-…` column rule. */
@media (max-width: 750px) {

	:root :is(.mg-legal-page, .mg-legal-page__content, .mg-error) .is-layout-grid {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* Reflow (D37, WCAG 1.4.10, D308 (4), D327; deviations #317): the legacy privacy h1
   "Datenschutzerklärung" (36px, right edge 438.6px) runs off the page below 439px and into the
   side padding up to 462px. A title word longer than its line is hyphenated at every width
   (German dictionary, `lang="de"`; the editor canvas gets the lang too), keeping at least 8
   letters after the break, so the compound breaks at its joint ("Datenschutz-erklärung"), never as
   "Datenschutzer-klärung" or "Datenschutzerklä-rung"; `overflow-wrap` is the last resort for a
   word without a hyphenation point. A title that fits its line is unchanged. */
.mg-legal-page__title {
	overflow-wrap: break-word;
	hyphens: auto;
	hyphenate-limit-chars: auto auto 8;
}

/* Headings in the text (D308 (4), D327, D332): no dictionary hyphenation (it would re-wrap legacy
   lines that fit); the seeded long words carry soft hyphens at their compound joints
   ("Datenschutz&shy;erklärung", "Personen&shy;bezogene", "Sicherheits&shy;maßnahmen"). Up to 394px
   a soft hyphen is a break point: below 394px the widest of them, "Datenschutzerklärung" in h2 IV
   (345.5px), no longer fits its column (the legacy ran these words up to 23.5px past the text
   column), and 394px keeps 1px of margin. From 395px every seeded word fits whole, so soft hyphens
   are off and a word that does not fit the rest of a line moves to the next line whole, as in the
   legacy ("IV. Änderungen an dieser / Datenschutzerklärung"); with soft hyphens on, the line
   breaker split it there ("…dieser Datenschutz- / erklärung" at 393–444, 661–759 and 832–998px).
   `overflow-wrap` is the last resort for a word the client types without one.
   `text-wrap: pretty` (D335) moves one more word down where the last line would hold a single
   word: of the seeded headings only "V. Kontaktieren Sie / uns" (privacy, 345–408px) changes, to
   "V. Kontaktieren / Sie uns" (measured 320–1920px in 1px steps); long last words such as
   "Pausenregelung" or "Datenschutzerklärung" stay as in the legacy. */
:is(.mg-legal-page, .mg-legal-page__content) :is(h2, h3, h4, h5, h6) {
	overflow-wrap: break-word;
	hyphens: none;
	text-wrap: pretty;
}

@media (max-width: 394.98px) {

	:is(.mg-legal-page, .mg-legal-page__content) :is(h2, h3, h4, h5, h6) {
		hyphens: manual;
	}
}

/* E-mail links in a legal text never break inside (D210, deviations #37): the line breaker split
   "info@main- / ginko.de" at the hyphen, which reads like a hyphenated word. The contact form and
   the footer do the same (#330). A plain-text address carries the text format "Nicht umbrechen"
   (a span styled by the plugin, app/style.scss). */
.mg-legal-page a[href^="mailto:"] {
	white-space: nowrap;
}

/* A plain-text web address in a legal text breaks only after its last slash (D211, deviations
   #40): the browser never breaks after "/", so "https://bgsd.de/de/verband/berufs-und-
   ehrenordnung.html" broke at a hyphen of its own, which reads like a hyphenated word (legacy too,
   320-458px). The span around the part after the last slash (AGB §6, a span the editor keeps) is
   one box that never breaks inside, and the line may break before it. A box, not <wbr>: the editor
   drops <wbr> when the paragraph is edited, and then the unbreakable part would run off the screen. */
.mg-legal-page__url-part {
	display: inline-block;
	white-space: nowrap;
}

/* Numbered clauses of a legal text (audit R14, D532): an ordered list shows the legacy "(1)" in
   front of each clause, inside the line like the plain-text numbers it replaces (AGB). */
.mg-legal-page ol.wp-block-list {
	padding-left: 0;
	line-height: 1.75;
	list-style-position: inside;
}

.mg-legal-page ol.wp-block-list > li {
	margin-left: 0;
}

/* Same type as the paragraphs they replace (14px up to 750px). */
@media (max-width: 750px) {

	.mg-legal-page ol.wp-block-list {
		font-size: var(--wp--preset--font-size--s);
	}
}

.mg-legal-page ol.wp-block-list > li::marker {
	content: "(" counter(list-item) ") ";
}

/* AGB line breaks (D326, deviations #316): the legacy text breaks after every line of its PDF
   export, set for a column of at least 785px (viewport 881px). In a narrower column each such
   line wrapped once more and left a short fragment before the break. Those breaks carry
   `mg-legal-page__wide-break` (with a space before them in the text) and are hidden up to 880px,
   so the sentence runs on; from 881px they break as in the legacy. 735–750px is the exception
   (D338): there the legacy's 14px text fits every export line, so the breaks show as in the legacy.
   A paragraph the client edits keeps its `<br>` but loses the class (rich text drops attributes on
   line breaks), so there the break then shows at every width, as in the legacy. */
@media (max-width: 734.98px), (min-width: 751px) and (max-width: 880.98px) {

	.mg-legal-page br.mg-legal-page__wide-break {
		display: none;
	}
}

@media (min-width: 751px) {

	.mg-legal-page {
		padding: var(--wp--preset--spacing--xxl) var(--wp--preset--spacing--xl) var(--wp--preset--spacing--xxxl);
	}
}

@media (min-width: 1113px) {

	.mg-legal-page {
		padding: var(--wp--preset--spacing--xxl) var(--wp--preset--spacing--xxl) var(--wp--preset--spacing--xxxl);
	}
}

/* ===== 404 page (build-plan §3 U16, D39, D314) ===== */

/* `templates/404.html`: `<main class="mg-error">` holds a legal prose container ("Seite nicht
   gefunden" = `mg-legal-page` with "Seitentitel" and "Text"), so the title, text and spacing are
   the legal page's and every guard rail above applies when the client edits the template. Only
   the button row is its own: a core flex group ("Buttons", Aktionsbuttons only) that sits 48px
   below the text (gap 24 + 24), so the call to action reads as its own step. Without text above
   it (the client removed the paragraphs) it follows the title like any text block. The call to
   action keeps that 48px step in every structure the client makes with one click
   (D316 (1)): a lone Aktionsbutton in "Text" (after "Gruppierung aufheben" on "Buttons" or from the
   "+" of "Text") and the row or button directly in the frame (after "Gruppierung aufheben" on
   "Text": frame gap 48, no 24px text rhythm). A button or row right after a button or row is part
   of the same call to action and keeps the 24px text rhythm. */
:root .mg-legal-page__content > :not(a, .mg-error__actions) + :is(.mg-error__actions, a) {
	margin-top: var(--wp--preset--spacing--m);
}

:root .mg-legal-page > :not(.mg-legal-page__header, .mg-legal-page__content, .mg-error__actions, a) + :is(.mg-error__actions, a) {
	margin-top: 0;
}

/* A row whose last button the client removed leaves no gap on the page (the editor keeps the
   row with its "+" while it is empty). A "Text" left with nothing but such a row is hidden too
   (D316 (3)), so a title-only message ends where a title-only legal page ends; `:root` + two
   classes + `:has()` (0,5,0) beat the flex column of the groups in a legal text (0,4,0). */
.mg-error__actions:empty {
	display: none;
}

:root .wp-block-group.mg-legal-page__content:not(:has(> :not(.mg-error__actions:empty))) {
	display: none;
}

/* ===== Free text blocks at the page's top level (D312 (1)) ===== */

/* A plain core block placed directly in the page content (the top bar "+" with nothing selected,
   "Davor/Danach hinzufügen" on the "Rechtstext" frame) has no section around it. It gets the text
   column of the legal pages, so it does not start at the window edge: content size 1280px minus a
   side gutter of 24px (≥751px: 48px, ≥1113px: 72px), centred, and 24px above and below (48px
   under the header, 72px above the footer). Only plain core text blocks and groups without a theme
   class; the home sections are theme blocks (`mg-…`) and are not touched. A card, frame, area card,
   tile or member that lands there all the same (a paste; the inserter and the structure guard keep
   them out, D203 (1)) gets the column too instead of running from window edge to window edge. `:root` + two classes
   (0,3,0) beat core's flow-layout margin resets `:root :where(.is-layout-flow) > :first-child` and
   `> :last-child` (0,2,0), which come later in the editor canvas. The 404 template's `<main>`
   (`mg-error`, D314) is such a root too: there the blocks sit in the template, not in a page. */
:is(.wp-block-post-content, .mg-error) {
	--mg-root-gutter: var(--wp--preset--spacing--m);
	--mg-root-legal-top: var(--wp--preset--spacing--xl);
	--mg-root-legal-bottom: var(--wp--preset--spacing--xxl);
}

:root :is(.wp-block-post-content, .mg-error).is-layout-flow > :where(p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote, figure, hr, table, .wp-block-image, .wp-block-table, .wp-block-quote, .wp-block-separator, .wp-block-columns, .wp-block-buttons, .wp-block-media-text, .wp-block-gallery, .wp-block-embed, .wp-block-details, .wp-block-spacer, .wp-block-group:not([class*="mg-"]), .wp-block-group:is(.is-style-mg-card, .is-style-mg-frame-accent, .is-style-mg-frame-dashed, .is-style-mg-area-card, .is-style-mg-area-placeholder, .is-style-mg-team-member), .mg-legal-page__header, .mg-legal-page__content, .mg-error__actions) {
	width: calc(100% - 2 * var(--mg-root-gutter));
	max-width: calc(var(--wp--style--global--content-size) - 2 * var(--mg-root-gutter));
	margin: var(--mg-root-margin-top, var(--wp--preset--spacing--m)) auto var(--mg-root-margin-bottom, var(--wp--preset--spacing--m));
}

:is(.wp-block-post-content, .mg-error) > :first-child {
	--mg-root-margin-top: var(--wp--preset--spacing--xl);
}

:is(.wp-block-post-content, .mg-error) > :last-child {
	--mg-root-margin-bottom: var(--wp--preset--spacing--xxl);
}

/* "Seitentitel" and "Text" without their "Rechtstext" frame (D313 (1)): "Gruppierung aufheben" on
   the frame, or pasted markup. They take the frame's vertical rhythm: frame top padding above the
   first one (48px, ≥751px 72px), 64px (gap 48 + 16) after "Seitentitel", frame bottom padding
   below the last one (72px, ≥751px 144px). Same text column as above, so the page looks as before.
   A first "Text" (the client removed "Seitentitel") starts there too, as in the frame (D317 (2)). */
:is(.wp-block-post-content, .mg-error) > :is(.mg-legal-page__header, .mg-legal-page__content):first-child {
	--mg-root-margin-top: var(--mg-root-legal-top);
}

:is(.wp-block-post-content, .mg-error) > .mg-legal-page__header + * {
	--mg-root-margin-top: calc(var(--wp--preset--spacing--xl) + var(--wp--preset--spacing--s));
}

:is(.wp-block-post-content, .mg-error) > :is(.mg-legal-page__header, .mg-legal-page__content):last-child {
	--mg-root-margin-bottom: var(--mg-root-legal-bottom);
}

/* An emptied "Seitentitel" or other group without the frame (D317 (2)): hidden like in the frame;
   a block after an emptied first "Seitentitel" takes the frame top padding instead of the 64px
   step after the title. */
:root :is(.wp-block-post-content, .mg-error) > .wp-block-group:not(:has(> :not(.mg-error__actions:empty))) {
	display: none;
}

:is(.wp-block-post-content, .mg-error) > .mg-legal-page__header:first-child:not(:has(> :not(.mg-error__actions:empty))) + * {
	--mg-root-margin-top: var(--mg-root-legal-top);
}

/* Call to action at the top level (D316 (1)): the "Buttons" row or an Aktionsbutton directly in
   the page content or the 404 `<main>` ("+" of "Inhalt der Fehlerseite", or "Gruppierung aufheben"
   on the frame and then on "Text") sits 48px below the text before it, on the text column's left
   edge. A button keeps its own width (`fit-content`; "Volle Breite" = the text column). The 24px
   bottom margin of the block above collapses into the 48px (flow layout). After "Seitentitel" the
   64px of the title stay. */
:is(.wp-block-post-content, .mg-error) > :not(.mg-legal-page__header, .mg-error__actions, a) + :is(.mg-error__actions, a) {
	--mg-root-margin-top: var(--wp--preset--spacing--xl);
}

:root :is(.wp-block-post-content, .mg-error).is-layout-flow > a {
	max-width: min(calc(var(--wp--style--global--content-size) - 2 * var(--mg-root-gutter)), calc(100% - 2 * var(--mg-root-gutter)));
	margin: var(--mg-root-margin-top, var(--wp--preset--spacing--m)) 0 var(--mg-root-margin-bottom, var(--wp--preset--spacing--m)) max(var(--mg-root-gutter), calc((100% - var(--wp--style--global--content-size)) / 2 + var(--mg-root-gutter)));
}

@media (min-width: 751px) {

	:is(.wp-block-post-content, .mg-error) {
		--mg-root-gutter: var(--wp--preset--spacing--xl);
		--mg-root-legal-top: var(--wp--preset--spacing--xxl);
		--mg-root-legal-bottom: var(--wp--preset--spacing--xxxl);
	}
}

@media (min-width: 1113px) {

	:is(.wp-block-post-content, .mg-error) {
		--mg-root-gutter: var(--wp--preset--spacing--xxl);
	}
}

/* ===== Quotes (D312 (4)) ===== */

/* `core/quote` ("Zitat") in any text: the theme.json block style draws the green rule on the left
   and the 24px indent; here the rhythm of its paragraphs and the source line. */
:root .wp-block-quote > * + * {
	margin-top: var(--wp--preset--spacing--s);
}

/* Core's block style "Einfach" drops the rule and the indent. */
.wp-block-quote.is-style-plain {
	padding-left: 0;
	border-left-width: 0;
}

.wp-block-quote cite {
	display: block;
	font-size: var(--wp--preset--font-size--s);
	font-style: normal;
	color: var(--wp--preset--color--text-muted);
}

/* ===== Accessibility ===== */

/* One focus ring for the whole site (D5; the legacy had none). Dark bands switch the colour to
   `focus-on-dark` in their own block stylesheet (plugin mixin d.focus-ring-on-dark). Block
   wrappers in the editor canvas carry tabindex and have their own focus UI, so they are left out. */
:where(a, button, input, select, textarea, summary, [tabindex]:not(.block-editor-block-list__block)):focus-visible {
	outline: var(--wp--custom--focus--width) solid var(--wp--preset--color--focus);
	outline-offset: var(--wp--custom--focus--offset);
}

/* Text for screen readers only (D45); the parity harness strips it from NEW innerText. */
.mg-visually-hidden {
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	position: absolute;
	border: 0;
	white-space: nowrap;
	overflow: hidden;
	clip-path: inset(50%);
}

/* Reduced-motion kill switch, as in the legacy CSS. `!important` is the point here: it must beat
   every component transition and animation, whatever its specificity. */
@media (prefers-reduced-motion: reduce) {

	*,
	::before,
	::after {
		/* stylelint-disable declaration-no-important */
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		/* stylelint-enable declaration-no-important */
	}
}
