/*
Theme Name: Atelier Grid
Author: You
Description: Gapless mosaic portfolio on a gallery grey wall. Four tile sizes at every breakpoint, captions scaled per tile, fitted headline.
Requires at least: 6.4
Tested up to: 6.8
Requires PHP: 7.4
Version: 3.1
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: atelier-grid
Tags: portfolio, art, block-theme, full-site-editing, grid-layout
*/

.atelier-head {
	padding: 1.1rem 1.5rem;
	border-bottom: 1px solid var(--wp--preset--color--sand);
}

/* ---------- image protection ---------- */
img {
	-webkit-user-drag: none;
	-khtml-user-drag: none;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
}
figcaption { user-select: text; -webkit-user-select: text; }

/* ---------- grid shell ---------- */
.atelier-grid .wp-block-query {
	--gap: clamp(0.4rem, 1vw, 1.1rem);
	--cols: 4;
	--cell: calc((100vw - (var(--cols) + 1) * var(--gap)) / var(--cols));
	padding: var(--gap);
	max-width: 1560px;
	margin-inline: auto;
}

.atelier-grid .wp-block-post-template,
.wp-block-group.atelier-grid ul.wp-block-post-template {
	display: grid !important;
	grid-template-columns: repeat(var(--cols), minmax(0, 1fr)) !important;
	grid-auto-rows: var(--cell) !important;
	grid-auto-flow: dense;
	gap: var(--gap) !important;
	list-style: none !important;
	margin: 0 !important;
	padding: 0 !important;
}

.atelier-grid .wp-block-post-template > li {
	position: relative;
	margin: 0;
	min-width: 0;
	border-radius: 6px;
	overflow: hidden;
	background: var(--wp--preset--color--sand);
}

/* 4 columns: 8-tile cycle */
.atelier-grid .wp-block-post-template > li:nth-child(8n+1),
.atelier-grid .wp-block-post-template > li:nth-child(8n+2) {
	grid-column: span 2;
	grid-row: span 2;
}
.atelier-grid .wp-block-post-template > li:nth-child(8n+7),
.atelier-grid .wp-block-post-template > li:nth-child(8n+8) {
	grid-column: span 2;
	grid-row: span 1;
}

.atelier-grid .wp-block-post-featured-image {
	margin: 0; width: 100%; height: 100%; line-height: 0;
	border-radius: 6px; overflow: hidden;
}
.atelier-grid .wp-block-post-featured-image a { display: block; width: 100%; height: 100%; }
.atelier-grid .wp-block-post-featured-image img {
	display: block; width: 100%; height: 100%;
	object-fit: cover;
	transition: opacity .35s ease, transform .5s ease;
}
.atelier-grid .wp-block-post-template > li:hover .wp-block-post-featured-image img {
	opacity: .9; transform: scale(1.02);
}

.atelier-grid .wp-block-post-template > li::after {
	content: "";
	position: absolute;
	left: 0; right: 0; bottom: 0;
	height: 55%;
	background: linear-gradient(to top, rgba(0, 0, 0, .68), rgba(0, 0, 0, 0));
	pointer-events: none;
	z-index: 1;
}

/* ---------- captions: one shared left inset, sizes scale with the tile ---------- */
.atelier-grid .wp-block-post-title {
	--cap-base: clamp(.78rem, .92vw, .95rem);
	--cap: var(--cap-base);
	--cap-x: .65rem;          /* identical left/right inset for every tile */
	--cap-y: .55rem;
	position: absolute;
	left: 0; right: 0; bottom: 0;
	z-index: 2;
	margin: 0;
	padding: var(--cap-y) var(--cap-x);
	color: #fff;
	font-size: var(--cap);
	font-weight: 600;
	line-height: 1.25;
	letter-spacing: .07em;
	text-transform: uppercase;
	text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
/* large square tiles */
.atelier-grid .wp-block-post-template > li:nth-child(8n+1) .wp-block-post-title,
.atelier-grid .wp-block-post-template > li:nth-child(8n+2) .wp-block-post-title {
	--cap: calc(var(--cap-base) * 1.45);
	--cap-y: .7rem;
}
/* wide tiles */
.atelier-grid .wp-block-post-template > li:nth-child(8n+7) .wp-block-post-title,
.atelier-grid .wp-block-post-template > li:nth-child(8n+8) .wp-block-post-title {
	--cap: calc(var(--cap-base) * 1.15);
}
.atelier-grid .wp-block-post-title a {
	color: #fff; text-decoration: none;
	text-transform: inherit; letter-spacing: inherit;
}

.atelier-grid .wp-block-query-pagination { display: none !important; }
.atelier-sentinel { height: 1px; }

/* ---------- single artwork ---------- */
.atelier-single {
	--text-width: 34rem;
	text-align: center;
	padding: clamp(0.9rem, 2.2vw, 2rem);
	max-width: 1560px;
	margin-inline: auto;
}

.atelier-single .wp-block-post-featured-image {
	margin: 0 auto clamp(1.5rem, 3vw, 2.5rem);
	width: 100%;
	border-radius: 6px;
	overflow: hidden;
	line-height: 0;
	background: var(--wp--preset--color--sand);
}
.atelier-single .wp-block-post-featured-image img {
	display: block; width: 100%; height: auto; border-radius: 6px;
}

.atelier-single .wp-block-post-title {
	display: block;
	width: 100%;
	max-width: var(--text-width);
	margin: 0 auto 2.1rem;
	text-align: left;
	text-transform: uppercase;
	letter-spacing: .02em;
	font-size: clamp(1.2rem, 2.4vw, 1.7rem);
	font-weight: 700;
	line-height: 1.15;
	white-space: normal;
}

.atelier-single .wp-block-post-content {
	width: 100%;
	max-width: var(--text-width);
	margin-inline: auto;
}
.atelier-single .wp-block-post-content > p,
.atelier-single .wp-block-post-content > ul,
.atelier-single .wp-block-post-content > ol {
	text-align: justify;
	text-align-last: justify;
	hyphens: auto;
	max-width: 100%;
}
.atelier-single .wp-block-post-content > h2,
.atelier-single .wp-block-post-content > h3,
.atelier-single .wp-block-post-content > blockquote,
.atelier-single .wp-block-post-content > figure {
	text-align: center; max-width: 100%; margin-inline: auto;
}
.atelier-single .wp-block-post-content figure,
.atelier-single .wp-block-post-content img,
.atelier-single .wp-block-post-content table {
	max-width: 100%; margin-inline: auto; border-radius: 6px;
}
.atelier-single .wp-block-post-content blockquote { padding-inline: 0; border: 0; }

/* ---------- word mosaic ---------- */
.atelier-single .wp-block-post-content > p.has-fw { text-align: left; text-align-last: auto; }
.atelier-single .fw-line {
	display: flex; justify-content: space-between; align-items: baseline;
	flex-wrap: nowrap; white-space: nowrap; line-height: 1.45; margin: 0 0 .18em;
}
.atelier-single .fw-line.fw-last { justify-content: flex-start; gap: .26em; }
.atelier-single .fw-word { display: inline-block; white-space: nowrap; line-height: 1.15; }
.atelier-single .fw-word.fw-f1 { font-family: var(--wp--preset--font-family--text); }
.atelier-single .fw-word.fw-f2 { font-family: var(--wp--preset--font-family--text-alt); }
.atelier-single .fw-word.fw-f3 { font-family: var(--wp--preset--font-family--text-alt2); }

.atelier-nav {
	width: 100%; max-width: var(--text-width);
	margin: 3rem auto 0; padding-top: 1.5rem;
	border-top: 1px solid var(--wp--preset--color--sand);
	justify-content: center; gap: 2rem;
}

/* ---------- 3 columns ---------- */
@media (max-width: 1100px) {
	.atelier-grid .wp-block-query { --cols: 3; }
	.atelier-grid .wp-block-post-template > li:nth-child(8n+1),
	.atelier-grid .wp-block-post-template > li:nth-child(8n+2),
	.atelier-grid .wp-block-post-template > li:nth-child(8n+7),
	.atelier-grid .wp-block-post-template > li:nth-child(8n+8) {
		grid-column: span 1; grid-row: span 1;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+2),
	.atelier-grid .wp-block-post-template > li:nth-child(5n+4) {
		grid-column: span 2; grid-row: span 2;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+5) {
		grid-column: span 1; grid-row: span 2;
	}

	.atelier-grid .wp-block-post-title { --cap-base: clamp(.78rem, 1.1vw, .92rem); }
	.atelier-grid .wp-block-post-template > li:nth-child(5n+2) .wp-block-post-title,
	.atelier-grid .wp-block-post-template > li:nth-child(5n+4) .wp-block-post-title {
		--cap: calc(var(--cap-base) * 1.4);
		--cap-y: .65rem;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+5) .wp-block-post-title {
		--cap: calc(var(--cap-base) * .88);
	}
}

/* ---------- 2 columns: 5-tile cycle, four sizes ---------- */
@media (max-width: 760px) {
	.atelier-grid .wp-block-query { --cols: 2; }

	.atelier-grid .wp-block-post-template > li:nth-child(5n+2),
	.atelier-grid .wp-block-post-template > li:nth-child(5n+4),
	.atelier-grid .wp-block-post-template > li:nth-child(5n+5) {
		grid-column: span 1; grid-row: span 1;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+1) {
		grid-column: span 2; grid-row: span 1;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+2) {
		grid-column: span 1; grid-row: span 2;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+3) {
		grid-column: span 2; grid-row: span 2;
	}

	.atelier-grid .wp-block-post-title {
		--cap-base: clamp(.72rem, 1.9vw, .88rem);
		--cap-x: .55rem;
		--cap-y: .5rem;
	}
	/* clear the 3-column caption sizes first */
	.atelier-grid .wp-block-post-template > li:nth-child(5n+2) .wp-block-post-title,
	.atelier-grid .wp-block-post-template > li:nth-child(5n+4) .wp-block-post-title,
	.atelier-grid .wp-block-post-template > li:nth-child(5n+5) .wp-block-post-title {
		--cap: var(--cap-base);
		--cap-y: .5rem;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+3) .wp-block-post-title {
		--cap: calc(var(--cap-base) * 1.35);
		--cap-y: .6rem;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+1) .wp-block-post-title {
		--cap: calc(var(--cap-base) * 1.15);
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+2) .wp-block-post-title {
		--cap: calc(var(--cap-base) * .92);
	}
}

/* ---------- phones ---------- */
@media (max-width: 560px) {
	.atelier-grid .wp-block-query { --gap: .45rem; }
	.atelier-grid .wp-block-post-template > li,
	.atelier-grid .wp-block-post-featured-image,
	.atelier-grid .wp-block-post-featured-image img,
	.atelier-grid .wp-block-post-featured-image a,
	.atelier-grid .wp-block-post-template > li::after { border-radius: 4px; }

	.atelier-grid .wp-block-post-title {
		--cap-base: clamp(.62rem, 2.4vw, .76rem);
		--cap-x: .45rem;
		--cap-y: .38rem;
		line-height: 1.22;
		letter-spacing: .04em;
	}
	.atelier-grid .wp-block-post-template > li:nth-child(5n+3) .wp-block-post-title { --cap-y: .45rem; }
	.atelier-grid .wp-block-post-template > li::after { height: 62%; }
	.atelier-head { padding: .8rem 1rem; }
}

/* ---------- very small phones ---------- */
@media (max-width: 400px) {
	.atelier-grid .wp-block-query { --gap: .35rem; }
	.atelier-grid .wp-block-post-title {
		--cap-base: clamp(.58rem, 2.5vw, .7rem);
		--cap-x: .38rem;
		--cap-y: .32rem;
	}
	.atelier-single { --text-width: 100%; }
	.atelier-single .wp-block-post-content > p,
	.atelier-single .wp-block-post-content > ul,
	.atelier-single .wp-block-post-content > ol {
		text-align: left; text-align-last: left;
	}
}

@media (prefers-reduced-motion: reduce) {
	.atelier-grid .wp-block-post-featured-image img { transition: none; }
}
