/* ==========================================================
NOVA – mobile layout
Load after the stage CSS (the body.frontend / .container_main rules).

When: portrait screens (taller than wide) and low landscape screens
(phones turned sideways). Both are too small for the 16:9 stage.
The same query is in pm-modules.js ($.pmMobileQuery): keep them equal.

How:
- the stage stops scaling as a whole and becomes a normal scrolling column
- --u gets a mobile reference: the design is read as if the SHORT side of
the screen were 480 wide, capped at 1.5px so tablets don't get huge text
- blocks drop their float and stack, full column width, keeping their
design proportions (--bw / --bh from pm_css). Content that needs more
room makes the block taller instead of overflowing.
========================================================== */

@media (max-aspect-ratio: 1/1), (max-height: 500px) {

	body.frontend {
		--u: min(100vw / 480, 100vh / 480, 1.5px);
		overflow: auto;
	}

	/* if #layer1 is the desktop scroll container: let the page scroll instead */
	#layer1,
	#layer2 {
		position: static;
		height: auto;
		overflow: visible;
	}

	/* top bar: stays at the top while the page scrolls */
	#topbar {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		height: calc(var(--u) * 48);
		padding: calc(var(--u) * 12) calc(var(--u) * 16);
		background-color: #fff;
	}

	/* the stage becomes a centered column (all page types).
	"body.frontend #cm" so it outweighs the slide stage rule */
	body.frontend #cm {
		position: relative;
		left: auto;
		top: auto;
		translate: none;
		width: auto;
		max-width: calc(var(--u) * 480);
		height: auto;
		margin: 0 auto;
		padding: calc(var(--u) * 88) calc(var(--u) * 16) calc(var(--u) * 110);   /* top: room for the top bar, bottom: for the progress bar */
		box-sizing: border-box;
		overflow: visible;
	}

	/* blocks and groups: stacked, full width, design proportions */
	#cm .pblock,
	#cm .pgroup {
		float: none;
		width: auto;
		height: auto;
		min-height: auto;        /* lets content grow the block past its aspect-ratio */
		aspect-ratio: var(--bw) / var(--bh);
		margin: 0 0 calc(var(--u) * 16);   /* no desktop margins (positioning) on mobile */

		/* pm-layout sets overflow: hidden on .pblock. A box with overflow hidden
		can't grow past its aspect-ratio, so text gets cut off. clip still
		clips (animations, backgrounds) but lets the block grow. */
		overflow: clip;
	}

	/* desktop paddings are made for the 1920 composition (e.g. 250 to make
	room for an illustration); on a phone they eat the whole column */
	#cm .pblock {
		padding: calc(var(--u) * 24);
	}

	/* blocks inside a group: the group already has the outer spacing */
	#cm .pgroup .pblock:last-child {
		margin-bottom: 0;
	}

	/* images never wider than their block; height follows the width */
	#cm img:not(.pm-scene img) {
		max-width: 100%;
		height: auto !important;
	}


	/* stage layers on mobile: cover the screen, not part of the column.
	The front layer is hidden: shards over the text hurt readability. */
	body.frontend[data-p-type] #cm .block-cnt > .pblock.pm-layer {
		position: absolute;
		inset: 0;
		width: auto;
		height: auto;
		margin: 0;
		padding: 0;
		aspect-ratio: auto;
		overflow: visible;
	}
	body.frontend[data-p-type] #cm .block-cnt > .pblock.pm-layer-front {
		display: none;
	}

	/* quiz card on mobile: the band becomes a strip on top with the number */
	#cm .nv-card.pm-tabs {
		--band-w: 100%;
		padding-top: calc(var(--u) * 84);
	}
	#cm .nv-card.pm-tabs::before {
		bottom: auto;
		height: calc(var(--u) * 84);
	}
	#cm .nv-card.pm-tabs::after {
		left: 0;
		width: 100%;
		height: calc(var(--u) * 84);
		align-items: center;
		justify-content: flex-end;
		padding-right: calc(var(--u) * 20);
		border-bottom: 0;
		font-size: calc(var(--u) * 70);
		line-height: 1;
	}
	/* plain card: no strip on top either */
	#cm .nv-card.pm-tabs.nv-noband {
		padding-top: 0;
	}

	/* answers in one column */
	.vraag-cnt {
		grid-template-columns: 1fr;
	}
	.vraag-cnt > :not(._vraag) + ._vraag + ._vraag {
		margin-top: 0;
	}
	.vraag-cnt h2 {
		font-size: calc(var(--u) * 40);
	}

	/* phones: swiping replaces the arrows */
	.pm-nav-prev,
	.pm-nav-next {
		display: none;
	}
	#pm-title-slide ._title {
		font-size: calc(var(--u) * 54);
		padding: 0 calc(var(--u) * 24);
	}

	/* groups: no desktop padding either, the blocks inside have their own */
	#cm .pgroup {
		padding: 0;
	}

	/* popups (pm-modules.js 13): the whole phone screen, scrolling inside;
	room at the top for the close button */
	body.frontend #cm .pgroup.pm-popup {
		position: fixed;
		inset: 0;
		aspect-ratio: auto;
		margin: 0;
		padding: calc(var(--u) * 64) calc(var(--u) * 16) calc(var(--u) * 24);
		box-sizing: border-box;
		overflow-x: hidden;
		overflow-y: auto;
	}
	body.frontend #cm .pgroup.pm-popup .pblock {
		aspect-ratio: auto;
	}
	#cm .pgroup.pm-popup > a.bttn-close {
		position: fixed;
		top: calc(var(--u) * 18);
		right: calc(var(--u) * 16);
	}

	/* blocks inside a tab group: height follows the text, not the desktop shape */
	#cm .pgroup.pm-tabs .pblock {
		aspect-ratio: auto;
		margin-bottom: 0;
	}

	/* tabs: links in one row that scrolls sideways (no wrapping) */
	.pm-tabs-nav {
		flex-wrap: nowrap;
		overflow-x: auto;
		scrollbar-width: none;
		margin-right: calc(var(--u) * -16);    /* run to the screen edge */
		padding-right: calc(var(--u) * 16);
	}
	.pm-tabs-nav::-webkit-scrollbar {
		display: none;
	}


	/* ------------------------------------------------------
	SCREEN pages (slides): every screen is exactly one phone
	screen high, between the top bar and the progress bar.
	- blocks with class m-visual (illustrations) get a fixed share
	of the height (--m-visual-h) and their image scales to fit
	- the other blocks share the remaining height; text that
	doesn't fit scrolls inside its own block
	Regular pages keep the scrolling column above.
	------------------------------------------------------ */

	body.frontend[data-p-type="screen"] {
		overflow: hidden;
	}

	body.frontend[data-p-type="screen"] #cm {
		height: 100vh;
		height: 100dvh;              /* phones: without the address bar */
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	/* the blocks' wrapper fills the screen and stacks its blocks */
	/* the screen wrapper fills #cm and passes the column on */
	body.frontend[data-p-type="screen"] #cm > .pm-screen {
		flex: 1 1 auto;
		min-height: 0;
		display: flex;
		flex-direction: column;
	}

	body.frontend[data-p-type="screen"] #cm > .pm-screen > .block-cnt {
		flex: 1 1 auto;
		min-height: 0;
		display: flex;
		flex-direction: column;
	}

	/* clearing divs have no job in a flex column */
	body.frontend[data-p-type="screen"] #cm > .pm-screen > .clear,
	body.frontend[data-p-type="screen"] #cm > .pm-screen > .block-cnt > .clear {
		display: none;
	}

	/* text and other blocks: share what's left, scroll when full */
	body.frontend[data-p-type="screen"] #cm .block-cnt > .pblock,
	body.frontend[data-p-type="screen"] #cm .block-cnt > .pgroup {
		flex: 1 1 auto;
		min-height: 0;
		height: auto;
		aspect-ratio: auto;
		overflow-x: hidden;
		overflow-y: auto;
		overscroll-behavior: contain;   /* scrolling the text doesn't drag the page */
	}
	body.frontend[data-p-type="screen"] #cm .block-cnt > :last-child {
		margin-bottom: 0;
	}

	/* more text below: fade out the bottom edge (class set by pm-render.js).
	A mask stays in place while the text scrolls underneath it. */
	body.frontend[data-p-type="screen"] #cm .block-cnt > .__more {
		-webkit-mask-image: linear-gradient(#000 calc(100% - var(--u) * 70), transparent);
		mask-image: linear-gradient(#000 calc(100% - var(--u) * 70), transparent);
	}

	/* illustrations: fixed share of the height, image fits inside */
	body.frontend[data-p-type="screen"] #cm .block-cnt > .m-visual {
		flex: 0 0 var(--m-visual-h, 38%);
		padding: 0;
		overflow: clip;
		container-type: size;           /* lets the image measure this block */
		display: flex;
		align-items: center;
		justify-content: center;
	}
	body.frontend[data-p-type="screen"] #cm .m-visual img:not(.pm-scene img) {
		width: auto !important;
		height: auto !important;
		max-width: 100cqw;
		max-height: 100cqh;
		object-fit: contain;
	}

	/* intro (pm-render.js sets __intro on #cm or on the .pm-screen): the illustration first takes
	the whole screen, then shrinks to its share while the text comes in */
	body.frontend[data-p-type="screen"] #cm .block-cnt > .m-visual {
		transition: flex-basis .7s cubic-bezier(.4, 0, .2, 1);
	}
	body.frontend[data-p-type="screen"] #cm .block-cnt > :not(.m-visual) {
		transition: opacity .5s .35s;
	}
	body.frontend[data-p-type="screen"] #cm :is(.__intro) .block-cnt > .m-visual,
	body.frontend[data-p-type="screen"] #cm.__intro .block-cnt > .m-visual {
		flex-basis: 100%;
	}
	body.frontend[data-p-type="screen"] #cm :is(.__intro) .block-cnt > :not(.m-visual),
	body.frontend[data-p-type="screen"] #cm.__intro .block-cnt > :not(.m-visual) {
		opacity: 0;
		transition-delay: 0s;
	}

	/* community voices: Vorige / Volgende side by side, "Zelf mening plaatsen" full width below */
	.nv-voices-buttons {
		flex-wrap: wrap;
		margin-top: calc(var(--u) * 32);
	}
	.nv-voices-buttons > .nv-btn {
		order: 3;
		justify-content: center;
		width: 100%;
	}
	.nv-voice-text,
	.nv-voice-source,
	.nv-voices-empty,
	.nv-voices-empty-sub {
		font-size: calc(var(--u) * 18);
	}
	.nv-voice-meta {
		font-size: calc(var(--u) * 13);
	}
	.nv-voice-meta dt {
		padding-right: calc(var(--u) * 20);
	}
	.nv-voice-quote {
		width: calc(var(--u) * 52);
		height: calc(var(--u) * 42);
	}
}