/*!
 * JessJess Portfolio 2.0.0
 *
 * Five layouts share one shell: an optional vertical title beside the tiles, captions
 * and scroll parallax. Selectors keep the .mpg prefix from Metro Parallax Grid, which
 * this plugin replaces, so pages built with it keep their saved styles.
 *
 *   Gallery, Uniform: a CSS grid; each tile's shape comes from its image or the chosen ratio.
 *   Metro: a CSS grid of square cells sized from the grid's own width (container queries).
 *   Masonry, Pinterest: the script places every tile. The rules here are what shows
 *   until it does.
 *
 * Screens: phones are up to 680px wide (or held sideways with a short screen), tablets
 * are touch screens and anything up to 1024px wide, and everything else is desktop.
 */

/* ---------- Widget shell ---------- */
.mpg {
	--mpg-pad: 0px;         /* room for the parallax, set by the script */
	--mpg-ease: 2s;         /* parallax easing length */
	--mpg-caption-speed: 0.45s;
	--mpg-side: var(--mpg-rail-gap, clamp(12px, 1.8vw, 24px)); /* space between the title and the tiles */
	position: relative;
	display: grid;
	/* The script measures the vertical title and sets --mpg-rail-w, because Safari can
	   size an "auto" column around vertical text too narrow. */
	grid-template-columns: var(--mpg-rail-w, auto) minmax(0, 1fr);
	column-gap: var(--mpg-side);
	padding-block: var(--mpg-pad);
	box-sizing: border-box;
}
.mpg *,
.mpg *::before,
.mpg *::after { box-sizing: border-box; }
/* Centered tiles: the same space on the right as the title column takes on the left. */
.mpg[data-center="1"] { padding-inline-end: calc(var(--mpg-rail-w, 0px) + var(--mpg-side)); }
.mpg[data-title="off"] { grid-template-columns: minmax(0, 1fr); padding-inline-end: 0; }

/* ---------- Vertical title ---------- */
.mpg .mpg__rail {
	position: relative;
	z-index: 1; /* the title draws above the tiles, so it stays readable if they ever meet */
	min-width: var(--mpg-rail-w, 0px);
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	min-height: 0;
}
.mpg[data-align="middle"] .mpg__rail { justify-content: center; }
.mpg[data-align="bottom"] .mpg__rail { justify-content: flex-end; }

/* Font, size and weight come from the theme's style for the chosen heading tag. */
.mpg .mpg__title {
	margin: 0 !important; /* the theme gives h1–h4 margins with !important */
	padding: 0;
	white-space: nowrap;
	will-change: transform;
	transition: transform var(--mpg-ease) cubic-bezier(0.2, 0.84, 0.5, 1);
}
.mpg .mpg__title-text { display: block; writing-mode: vertical-rl; white-space: nowrap; }
.mpg[data-dir="up"] .mpg__title-text { transform: rotate(180deg); }
.mpg[data-tstyle="muted"] .mpg__title { color: var(--mpg-title-muted, #dcdcd7) !important; }
.mpg[data-tstyle="outline"] .mpg__title {
	color: transparent !important;
	-webkit-text-stroke: 1.25px var(--mpg-title-color, #000);
}

/* ---------- Grid: every layout ---------- */
.mpg .mpg__wrap { container: mpg / inline-size; min-width: 0; }
.mpg .mpg__grid {
	--gap: var(--mpg-gap-md, 32px);
	display: grid;
	grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
	gap: var(--gap);
	margin: 0;
	padding: 0;
	list-style: none;
}
@container mpg (min-width: 1100px) { .mpg .mpg__grid { --gap: var(--mpg-gap-lg, 50px); } }

.mpg .mpg__item {
	container: tile / inline-size;
	position: relative;
	min-width: 0;
	margin: 0;
	padding: 0;
	list-style: none;
}
.mpg .mpg__item::before,
.mpg .mpg__item::after { content: none; display: none; }

/* ---------- Gallery and Uniform: columns and rows ---------- */
.mpg[data-layout="gallery"] .mpg__grid,
.mpg[data-layout="uniform"] .mpg__grid,
.mpg[data-layout="pinterest"] .mpg__grid { --cols: var(--mpg-cols-d, 3); }
.mpg[data-layout="gallery"] .mpg__grid,
.mpg[data-layout="uniform"] .mpg__grid { align-items: start; }
.mpg[data-layout="gallery"] .mpg__item { aspect-ratio: var(--ar, 1); }   /* the image's own shape, never cropped */
.mpg[data-layout="uniform"] .mpg__item { aspect-ratio: var(--mpg-ratio, 1); }

/* ---------- Metro: square cells; s = 1x1, w = 2x1, t = 1x2, b = 2x2 ---------- */
/* Two columns, or four once the grid is 720px wide. Upright tablets and phones are set below. */
.mpg[data-layout="metro"] .mpg__grid {
	--cols: 2;
	--cell: calc((100cqi - (var(--cols) - 1) * var(--gap)) / var(--cols));
	grid-auto-rows: calc((var(--cell) - var(--gap)) / 2); /* a row is half a cell */
	grid-auto-flow: row dense;
}
@container mpg (min-width: 720px) { .mpg[data-layout="metro"] .mpg__grid { --cols: 4; } }
.mpg[data-layout="metro"] .mpg__item { grid-column: span 1; grid-row: span 2; }
.mpg[data-layout="metro"] .mpg__item--w { grid-column: span 2; }
.mpg[data-layout="metro"] .mpg__item--t { grid-row: span 4; }
.mpg[data-layout="metro"] .mpg__item--b { grid-column: span 2; grid-row: span 4; }

/* ---------- Masonry: rows of one height (shown until the script places the tiles) ---------- */
.mpg[data-layout="masonry"] .mpg__grid { --row: var(--mpg-row-d, 320px); display: flex; flex-wrap: wrap; }
.mpg[data-layout="masonry"] .mpg__item { height: var(--row); flex: var(--ar, 1) 1 calc(var(--ar, 1) * var(--row)); }

/* ---------- Pinterest: columns of one width (shown until the script places the tiles) ---------- */
.mpg[data-layout="pinterest"] .mpg__grid { display: block; columns: var(--cols); column-gap: var(--gap); }
.mpg[data-layout="pinterest"] .mpg__item { display: block; aspect-ratio: var(--ar, 1); margin-bottom: var(--gap); break-inside: avoid; }

/* ---------- Masonry and Pinterest once placed by the script ---------- */
.mpg .mpg__grid.is-placed { display: block; position: relative; columns: auto; }
.mpg .mpg__grid.is-placed > .mpg__item { position: absolute; margin: 0; flex: none; aspect-ratio: auto; }

/* ---------- Tablets, and phones held sideways ---------- */
@media (max-width: 1024px) {
	.mpg[data-layout="gallery"] .mpg__grid,
	.mpg[data-layout="uniform"] .mpg__grid,
	.mpg[data-layout="pinterest"] .mpg__grid { --cols: var(--mpg-cols-t, 2); }
	.mpg[data-layout="masonry"] .mpg__grid { --row: var(--mpg-row-t, 260px); }
}
/* Metro on tablets held upright: two columns unless the widget asks for three or four. */
@media (min-width: 681px) and (max-width: 1024px) and (orientation: portrait) {
	.mpg[data-layout="metro"] .mpg__grid { --cols: 2; }
	.mpg[data-layout="metro"][data-tablet-cols="3"] .mpg__grid { --cols: 3; }
	.mpg[data-layout="metro"][data-tablet-cols="4"] .mpg__grid { --cols: 4; }
}

/* ---------- Phones held upright ---------- */
@media (max-width: 680px) and (orientation: portrait), (max-width: 680px) and (min-height: 541px) {
	.mpg .mpg__grid { --gap: var(--mpg-gap-sm, 24px); }
	.mpg[data-layout="gallery"] .mpg__grid,
	.mpg[data-layout="uniform"] .mpg__grid,
	.mpg[data-layout="pinterest"] .mpg__grid { --cols: var(--mpg-cols-p, 1); }
	.mpg[data-layout="masonry"] .mpg__grid { --row: var(--mpg-row-p, 140px); }

	/* Metro: one column (or two, if the widget asks for it). */
	.mpg[data-layout="metro"] .mpg__grid { --cols: 1; }
	.mpg[data-layout="metro"] .mpg__item--w { grid-column: span 1; grid-row: span 1; }
	.mpg[data-layout="metro"] .mpg__item--b { grid-column: span 1; grid-row: span 2; }
	.mpg[data-layout="metro"] .mpg__item--t { grid-row: span 3; }
	.mpg[data-layout="metro"][data-phone-cols="2"] .mpg__grid { --cols: 2; --gap: calc(var(--mpg-gap-sm, 24px) * 0.6); }
	.mpg[data-layout="metro"][data-phone-cols="2"] .mpg__item--w { grid-column: span 2; grid-row: span 2; }
	.mpg[data-layout="metro"][data-phone-cols="2"] .mpg__item--b { grid-column: span 2; grid-row: span 4; }
	.mpg[data-layout="metro"][data-phone-cols="2"] .mpg__item--t { grid-row: span 4; }
}
/* Phones held sideways: tablet columns and rows, and Metro uses four columns so a big
   tile fits on the short screen. */
@media (orientation: landscape) and (max-height: 540px) {
	.mpg .mpg__grid { --gap: var(--mpg-gap-sm, 24px); }
	.mpg[data-layout="metro"] .mpg__grid { --cols: 4; }
}

/* ---------- Tile ---------- */
/* The link is the moving layer, so the tap target moves with the picture. */
.mpg .mpg__link {
	position: absolute;
	inset: 0;
	display: block;
	overflow: hidden;
	background: var(--mpg-tile-bg, #f1f1ee);
	color: inherit;
	text-decoration: none;
	will-change: transform;
	-webkit-tap-highlight-color: transparent;
	transition: transform var(--mpg-ease) cubic-bezier(0.2, 0.84, 0.5, 1);
}
.mpg a.mpg__link:focus-visible { outline: 2px solid currentColor; outline-offset: 4px; }
/* The picture fills its tile and is cropped from the center when its shape differs. */
.mpg .mpg__img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	object-fit: cover;
	object-position: center;
}

/* ---------- Caption ---------- */
/* The text is part of the panel, so it arrives with it. */
.mpg .mpg__caption {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	padding: 18px 22px 16px;
	background: var(--mpg-caption-bg, #fff);
	color: var(--mpg-caption-color, #000);
	transform: translate3d(0, 101%, 0);
	transition: transform var(--mpg-caption-speed) cubic-bezier(0.22, 0.8, 0.24, 1);
}
.mpg .mpg__caption-inner {
	max-width: 34em;
	transform: translate3d(0, 10px, 0);
	transition: transform var(--mpg-caption-speed) cubic-bezier(0.22, 0.8, 0.24, 1);
}
.mpg .mpg__name {
	margin: 0 0 6px;
	padding: 0;
	font-family: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
	font-size: 16px;
	font-weight: 600;
	line-height: 20px;
	letter-spacing: normal;
	text-transform: none;
	color: inherit;
}
.mpg .mpg__desc {
	margin: 0;
	font-size: 14px;
	line-height: 20px;
	white-space: pre-line; /* keeps the line break after "My work on this project:" */
	color: inherit;
}
.mpg .mpg__desc p { margin: 0; }
.mpg .mpg__desc strong { font-weight: 600; }
.mpg .mpg__cta { display: none; margin-top: 10px; font-size: 13px; font-weight: 600; line-height: 1.3; }
@container tile (max-width: 250px) {
	.mpg .mpg__caption { padding: 12px 14px 11px; }
	.mpg .mpg__desc { display: none; }
	.mpg .mpg__name { margin-bottom: 0; font-size: 15px; }
}

/* Open: mouse hover, keyboard focus, or tapped (.is-open, set by the script) */
@media (hover: hover) {
	.mpg .mpg__item:hover .mpg__caption,
	.mpg .mpg__item:hover .mpg__caption-inner { transform: none; }
}
.mpg a.mpg__link:focus-visible .mpg__caption,
.mpg a.mpg__link:focus-visible .mpg__caption-inner,
.mpg .mpg__item.is-open .mpg__caption,
.mpg .mpg__item.is-open .mpg__caption-inner { transform: none; }
.mpg[data-tap="twice"] .mpg__item.is-open .mpg__cta { display: block; }

/* Touch option: captions always visible */
@media (hover: none) {
	.mpg[data-tap="always"] .mpg__caption,
	.mpg[data-tap="always"] .mpg__caption-inner { transform: none; }
}

/* Tablets and phones: no captions unless the widget turns them on. The script adds
   .mpg-touch to the page for iPads with a trackpad, which report a mouse-like pointer. */
@media (max-width: 1024px), (hover: none), (pointer: coarse), (orientation: landscape) and (max-height: 540px) {
	.mpg[data-touch-captions="0"] .mpg__caption { display: none; }
}
.mpg-touch .mpg[data-touch-captions="0"] .mpg__caption { display: none; }

/* ---------- Phones: portrait up to 680px, or sideways with a short screen ---------- */
/* The title becomes a regular heading above the grid. Tiles stay still unless the
   widget turns on parallax for phones. */
@media (max-width: 680px), (orientation: landscape) and (max-height: 540px) {
	.mpg,
	.mpg[data-center="1"] { grid-template-columns: minmax(0, 1fr); row-gap: 16px; padding-inline-end: 0; }
	.mpg .mpg__rail { display: block; }
	.mpg .mpg__title { white-space: normal; text-wrap: balance; transform: none !important; transition: none !important; }
	.mpg .mpg__title-text { writing-mode: horizontal-tb; white-space: normal; transform: none !important; }
	.mpg:not([data-phone="1"]) .mpg__link { transform: none !important; transition: none !important; }
}
.mpg[data-title="off"] .mpg__rail { display: none; }

@media (prefers-reduced-motion: reduce) {
	.mpg .mpg__caption,
	.mpg .mpg__caption-inner,
	.mpg .mpg__link,
	.mpg .mpg__title { transition: none !important; }
}

/* ---------- Editor-only notes ---------- */
.mpg-note {
	margin: 0 0 12px;
	padding: 10px 12px;
	border: 1px dashed rgba(0, 0, 0, 0.3);
	border-radius: 4px;
	background: #fffbe6;
	color: #333;
	font-size: 13px;
	line-height: 1.45;
}
