/*
 * Kacheln — a Group block style (inc/kacheln.php): the groups inside it as a
 * shelf of photo cards, each opening its group in a window. Built for the
 * Auslandseinsätze on Team; main.js builds the cards and the windows and marks
 * the group .is-enhanced.
 *
 * The cards are drawn after the book covers on Bildung (produktuebersicht.css):
 * upright, square-cornered, the same soft shadow down and to the right, a
 * centred row, and the same blurred white veil behind whatever opens.
 *
 * WordPress wraps a group's content in .wp-block-group__inner-container in
 * this theme (it has no theme.json), so the panel rules name both depths.
 */

/* --- Without the script: the groups stand one under another. ----------- */
.is-style-kacheln > .wp-block-group,
.is-style-kacheln > .wp-block-group__inner-container > .wp-block-group {
	margin: 0 0 clamp(36px, 4vw, 56px);
}

/* --- The shelf ----------------------------------------------------------
 * Seven countries in one row where there is room for it, which keeps the
 * section as short as a single row of covers; four and three below that, and
 * two on a phone. Centred, so a short last row sits in the middle like the
 * books do, rather than hanging off to the left. */
.kacheln {
	container-type: inline-size;
	--kacheln-n: 2;
	--kacheln-gap: clamp(14px, 1.8vw, 26px);
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--kacheln-gap);
	margin: 0;
	padding: 6px 0 clamp(20px, 2.4vw, 32px);
}

@container (min-width: 520px) {
	.kacheln > .kachel { --kacheln-n: 3; }
}

@container (min-width: 760px) {
	.kacheln > .kachel { --kacheln-n: 4; }
}

@container (min-width: 1100px) {
	.kacheln > .kachel { --kacheln-n: 7; }
}

.kachel {
	--kacheln-n: 2;
	container-type: inline-size;
	position: relative;
	display: block;
	flex: none;
	width: calc((100% - (var(--kacheln-n) - 1) * var(--kacheln-gap)) / var(--kacheln-n));
	max-width: 280px;
	aspect-ratio: 3 / 4;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border: 0;
	border-radius: 2px;
	background: var(--brand-cream);
	color: #fff;
	text-align: left;
	cursor: pointer;
	box-shadow:
		6px 6px 18px rgba(0, 0, 0, 0.35),
		1px 0 3px rgba(0, 0, 0, 0.15);
	transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.kachel img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.5s ease;
}

/* The shade the label stands on: clear over the top half of the photo, dark
   enough at the foot that white type passes 4.5:1 over the brightest photo
   in the set (Afghanistan's sky, Algerien's harbour). */
.kachel::after {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(to bottom,
		rgba(0, 0, 0, 0) 38%,
		rgba(0, 0, 0, 0.45) 64%,
		rgba(0, 0, 0, 0.82) 100%);
}

.kachel-text {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 1;
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 0 clamp(10px, 9cqw, 18px) clamp(12px, 10cqw, 20px);
}

.kachel-land {
	font-family: 'DIN Alternate Bold';
	font-size: clamp(15px, 11.5cqw, 24px);
	line-height: 1.1;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	/* A long name ("Aserbaidschan") breaks rather than running off the card. */
	overflow-wrap: anywhere;
	hyphens: auto;
	text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.kachel-jahre {
	font-family: 'Open Sans', sans-serif;
	font-size: clamp(12px, 7cqw, 15px);
	font-weight: 600;
	line-height: 1.3;
	font-variant-numeric: tabular-nums;
	opacity: 0.92;
}

/* "15 Fotos", in the corner — says there is more behind the cover, the job
   KLICKEN ZUM ÖFFNEN does on the books. */
.kachel-anzahl {
	position: absolute;
	top: clamp(8px, 6cqw, 12px);
	right: clamp(8px, 6cqw, 12px);
	z-index: 1;
	padding: 2px 9px;
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.55);
	font-family: 'Open Sans', sans-serif;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.5;
	letter-spacing: 0.02em;
}

.kachel:hover,
.kachel:focus-visible {
	transform: translateY(-4px);
	box-shadow:
		8px 12px 26px rgba(0, 0, 0, 0.38),
		1px 0 3px rgba(0, 0, 0, 0.15);
}

.kachel:hover img,
.kachel:focus-visible img {
	transform: scale(1.04);
}

.kachel:focus-visible {
	outline: 3px solid #1c1c1c;
	outline-offset: 4px;
}

/* --- The window ---------------------------------------------------------
 * A native <dialog>, opened modal: it takes focus, keeps it inside, and
 * closes on Esc without any code of ours. It is rendered in the top layer,
 * above the sticky bars and the nav circle, though it stays in the page's
 * DOM — which is what keeps the carousel's .p-bar-text rules applying. */
.kacheln-fenster {
	width: min(1240px, calc(100vw - 32px));
	max-width: none;
	max-height: calc(100dvh - 32px);
	margin: auto;
	padding: 0;
	overflow: auto;
	overscroll-behavior: contain;
	border: 0;
	border-radius: 6px;
	background: #fff;
	color: #1c1c1c;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.kacheln-fenster::backdrop {
	background: rgba(255, 255, 255, 0.4);
	backdrop-filter: blur(5px);
	-webkit-backdrop-filter: blur(5px);
}

.kacheln-fenster[open] {
	animation: kacheln-auf 0.25s ease-out;
}

@keyframes kacheln-auf {
	from { opacity: 0; transform: translateY(12px) scale(0.98); }
	to   { opacity: 1; transform: none; }
}

/* Nothing behind the window scrolls while it is open. */
html:has(.kacheln-fenster[open]) {
	overflow: hidden;
}

/* The content box, inside the dialog's zero padding: a click that lands on
   the dialog element itself can then only be a click on the veil around it,
   which is what closes it. The top padding is the close button's row. */
.kacheln-inhalt {
	container-type: inline-size;
	padding: 64px clamp(18px, 3vw, 40px) clamp(20px, 3vw, 36px);
}

/* Focused only as the place a mouse-opened window starts from (main.js). */
.kacheln-inhalt:focus {
	outline: none;
}

@media (max-width: 600px) {
	.kacheln-fenster {
		width: calc(100vw - 16px);
		max-height: calc(100dvh - 16px);
	}
}

.kacheln-zu {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 2;
	display: grid;
	place-items: center;
	width: var(--tap);
	height: var(--tap);
	margin: 0;
	padding: 0;
	border: 1.5px solid #c9d3d1;
	border-radius: 50%;
	background: #fff;
	color: #1c1c1c;
	font-size: 18px;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.kacheln-zu:hover,
.kacheln-zu:focus-visible {
	border-color: #057e65;
	background: #057e65;
	color: #fff;
}

.kacheln-zu:focus-visible {
	outline: 3px solid #1c1c1c;
	outline-offset: 2px;
}

/* --- One country ---------------------------------------------------------
 * A heading, a line naming the project, perhaps a sentence about it, and the
 * carousel. Where there is room the words stand in a column to the left of
 * the photos, so a photo can be large without the text pushing it out of the
 * window; narrower, they sit above it. The carousel is matched both as the
 * gallery and as the .karussell box main.js wraps it in. */
@container (min-width: 820px) {
	.kacheln-inhalt > .wp-block-group > .wp-block-group__inner-container,
	.kacheln-inhalt > .wp-block-group:not(:has(> .wp-block-group__inner-container)) {
		display: grid;
		grid-template-columns: minmax(200px, 1fr) minmax(0, 2.8fr);
		grid-auto-rows: min-content;
		column-gap: clamp(28px, 3.5cqw, 48px);
		align-items: start;
	}

	.kacheln-inhalt :is(.karussell, .wp-block-gallery) {
		grid-column: 2;
		grid-row: 1 / span 20;
	}

	.kacheln-inhalt .karussell > .wp-block-gallery {
		grid-row: auto;
	}

	.kacheln-inhalt > .wp-block-group > * > :not(.karussell, .wp-block-gallery),
	.kacheln-inhalt > .wp-block-group > :not(.karussell, .wp-block-gallery, .wp-block-group__inner-container) {
		grid-column: 1;
	}
}

/* Whatever level the panel headings are: h3 where the shelf is a section of
   its own, h4 where it sits under a heading of a person's chapter on Team.
   Weight and colour restated, because a page's own heading rules (team.css
   sets h3 as small capitals) would otherwise reach in. */
.is-style-kacheln .wp-block-group :is(h2, h3, h4),
.kacheln-inhalt :is(h2, h3, h4) {
	margin: 0 0 10px;
	font-family: 'DIN Alternate Bold';
	font-size: clamp(24px, 2vw, 30px);
	font-weight: normal;
	line-height: 1.2;
	letter-spacing: 0;
	text-transform: none;
	color: #1c1c1c;
	text-wrap: balance;
}

/* The years a heading ends in, split off by main.js. #555 is 7.5:1. */
.kacheln-inhalt :is(h2, h3, h4) .kacheln-jahre {
	display: block;
	margin-top: 4px;
	font-family: 'Open Sans', sans-serif;
	font-size: 16px;
	font-weight: 600;
	color: #555;
	font-variant-numeric: tabular-nums;
}

.is-style-kacheln .wp-block-group p,
.kacheln-inhalt p {
	margin: 0 0 10px;
	font-family: 'Open Sans', sans-serif;
	font-size: 17px;
	font-weight: 400;
	line-height: 1.55;
	color: #222;
}

.is-style-kacheln .wp-block-group p.ieo-einsatz-projekt,
.kacheln-inhalt p.ieo-einsatz-projekt {
	font-weight: 700;
}

/* A logo set into the project line, such as Mir's. */
.is-style-kacheln .wp-block-group p img,
.kacheln-inhalt p img {
	display: inline-block;
	height: auto;
	margin: -4px 10px 0 0;
	vertical-align: middle;
}

@media (prefers-reduced-motion: reduce) {
	.kachel,
	.kachel img,
	.kacheln-zu {
		transition: none;
	}

	.kachel:hover,
	.kachel:focus-visible {
		transform: none;
	}

	.kachel:hover img,
	.kachel:focus-visible img {
		transform: none;
	}

	.kacheln-fenster[open] {
		animation: none;
	}
}
