/**
 * Novelty Gene — photos at the top of an article (1 to 4).
 *
 * Markup:  <div class="ng-photos ng-photos-N ng-layout-{row|mosaic|flip}">
 *             <figure class="ng-photo is-{rounded|square|circle}"><img></figure> ...
 *
 * Layouts
 *   row     photos side by side, equal width (1 = full width, 2 = halves, ...)
 *   mosaic  1: full · 2: wide + narrow · 3: big + two stacked · 4: two tall + two stacked
 *   flip    the same mosaic mirrored (stacked photos on the left)
 *   stack   every photo full width, one under another
 *   custom  Sam chooses each photo's width (full, 2/3, 1/2, 1/3) and ratio (wide, landscape, square, portrait)
 *
 * Per article: height (.ng-h-short / .ng-h-tall) and spacing (.ng-g-tight / .ng-g-roomy) scale the layouts above.
 *
 * Shared by the site and by the live preview in the post editor.
 * Mobile first: phones get a simple 2-column grid; wider screens get the layouts above.
 */

.ng-photos{
	--ng-ph:190px; --ng-gap:22px; --ng-r:26px;
	display:grid; gap:calc(var(--ng-gap) * var(--ng-gm, 1)); margin:0 0 60px;
	grid-template-columns:repeat(2,minmax(0,1fr));
}
.ng-photo{ position:relative; margin:0; min-width:0; overflow:hidden; aspect-ratio:1/1; background:#e4e4e4; box-shadow:var(--ng-shadow, 12px 14px 18px rgba(0,0,0,.30)); }
.ng-photo img{ position:absolute; inset:0; width:100%; height:100%; object-fit:cover; display:block; }
.ng-photo.is-rounded{ border-radius:var(--ng-r); }
.ng-photo.is-square{ border-radius:0; }
.ng-photo.is-circle{ border-radius:50%; }

/* ---------- phones (default): 2 columns; first photo full width when the count is odd ---------- */
.ng-photos{ --ng-gap:12px; --ng-r:18px; margin-bottom:34px; }
.ng-photos-1 .ng-photo,
.ng-photos-3 .ng-photo:first-child{ grid-column:1 / -1; aspect-ratio:4/3; }
.ng-photos-1 .ng-photo.is-circle,
.ng-photos-3 .ng-photo.is-circle:first-child{ aspect-ratio:1/1; width:72%; justify-self:center; }

/* ---------- tablet and up ---------- */
@media (min-width:700px){
	.ng-photos{ --ng-ph:150px; --ng-gap:16px; --ng-r:22px; margin-bottom:50px; grid-auto-rows:calc(var(--ng-ph) * var(--ng-hm, 1)); }
	.ng-photo{ --ch:calc(var(--ng-ph) * var(--ng-hm, 1) * 2 + var(--ng-gap) * var(--ng-gm, 1)); aspect-ratio:auto; grid-column:auto; grid-row:span 2; }
	/* a circle must stay a circle: as wide as it is tall, centered in its cell */
	.ng-photo.is-circle,
	.ng-photos-1 .ng-photo.is-circle,
	.ng-photos-3 .ng-photo.is-circle:first-child{ aspect-ratio:1/1; width:min(100%,var(--ch)); align-self:center; justify-self:center; }
	.ng-photos-1 .ng-photo,.ng-photos-3 .ng-photo:first-child{ aspect-ratio:auto; }

	/* row: equal columns */
	.ng-layout-row.ng-photos-1{ grid-template-columns:minmax(0,1fr); }
	.ng-layout-row.ng-photos-2{ grid-template-columns:repeat(2,minmax(0,1fr)); }
	.ng-layout-row.ng-photos-3{ grid-template-columns:repeat(3,minmax(0,1fr)); }
	.ng-layout-row.ng-photos-4{ grid-template-columns:repeat(4,minmax(0,1fr)); }

	/* mosaic and flip */
	.ng-layout-mosaic.ng-photos-1,.ng-layout-flip.ng-photos-1{ grid-template-columns:minmax(0,1fr); }
	.ng-layout-mosaic.ng-photos-2{ grid-template-columns:minmax(0,2fr) minmax(0,1fr); }
	.ng-layout-flip.ng-photos-2{ grid-template-columns:minmax(0,1fr) minmax(0,2fr); }
	.ng-layout-flip.ng-photos-2 .ng-photo:nth-child(1){ grid-column:2; grid-row:1 / span 2; }
	.ng-layout-flip.ng-photos-2 .ng-photo:nth-child(2){ grid-column:1; grid-row:1 / span 2; }

	.ng-layout-mosaic.ng-photos-3{ grid-template-columns:minmax(0,1.5fr) minmax(0,1fr); }
	.ng-layout-flip.ng-photos-3{ grid-template-columns:minmax(0,1fr) minmax(0,1.5fr); }
	.ng-layout-mosaic.ng-photos-3 .ng-photo:nth-child(1){ grid-column:1; grid-row:1 / span 2; }
	.ng-layout-flip.ng-photos-3 .ng-photo:nth-child(1){ grid-column:2; grid-row:1 / span 2; }
	.ng-layout-mosaic.ng-photos-3 .ng-photo:nth-child(2),.ng-layout-mosaic.ng-photos-3 .ng-photo:nth-child(3){ grid-column:2; }
	.ng-layout-flip.ng-photos-3 .ng-photo:nth-child(2),.ng-layout-flip.ng-photos-3 .ng-photo:nth-child(3){ grid-column:1; }

	.ng-layout-mosaic.ng-photos-4,.ng-layout-flip.ng-photos-4{ grid-template-columns:repeat(3,minmax(0,1fr)); }
	.ng-layout-mosaic.ng-photos-4 .ng-photo:nth-child(1){ grid-column:1; grid-row:1 / span 2; }
	.ng-layout-mosaic.ng-photos-4 .ng-photo:nth-child(2){ grid-column:2; grid-row:1 / span 2; }
	.ng-layout-mosaic.ng-photos-4 .ng-photo:nth-child(3),.ng-layout-mosaic.ng-photos-4 .ng-photo:nth-child(4){ grid-column:3; }
	.ng-layout-flip.ng-photos-4 .ng-photo:nth-child(1){ grid-column:2; grid-row:1 / span 2; }
	.ng-layout-flip.ng-photos-4 .ng-photo:nth-child(2){ grid-column:3; grid-row:1 / span 2; }
	.ng-layout-flip.ng-photos-4 .ng-photo:nth-child(3),.ng-layout-flip.ng-photos-4 .ng-photo:nth-child(4){ grid-column:1; }

	/* the two stacked photos are half as tall */
	.ng-layout-mosaic.ng-photos-3 .ng-photo:nth-child(n+2),
	.ng-layout-flip.ng-photos-3 .ng-photo:nth-child(n+2),
	.ng-layout-mosaic.ng-photos-4 .ng-photo:nth-child(n+3),
	.ng-layout-flip.ng-photos-4 .ng-photo:nth-child(n+3){ --ch:calc(var(--ng-ph) * var(--ng-hm, 1)); grid-row:span 1; }
	.ng-layout-mosaic.ng-photos-3 .ng-photo:nth-child(2),.ng-layout-flip.ng-photos-3 .ng-photo:nth-child(2),
	.ng-layout-mosaic.ng-photos-4 .ng-photo:nth-child(3),.ng-layout-flip.ng-photos-4 .ng-photo:nth-child(3){ grid-row:1; }
	.ng-layout-mosaic.ng-photos-3 .ng-photo:nth-child(3),.ng-layout-flip.ng-photos-3 .ng-photo:nth-child(3),
	.ng-layout-mosaic.ng-photos-4 .ng-photo:nth-child(4),.ng-layout-flip.ng-photos-4 .ng-photo:nth-child(4){ grid-row:2; }
}
@media (min-width:981px){
	.ng-photos{ --ng-ph:190px; --ng-gap:22px; --ng-r:26px; margin-bottom:60px; }
}

/* ---------- per-article height and spacing ---------- */
.ng-h-short{ --ng-hm:.72; } .ng-h-tall{ --ng-hm:1.35; }
.ng-g-tight{ --ng-gm:.4; } .ng-g-roomy{ --ng-gm:1.7; }

/* ---------- stack + custom: each photo has its own ratio, and (custom) its own width ---------- */
.ng-photos.ng-layout-stack .ng-photo,
.ng-photos.ng-layout-custom .ng-photo{ aspect-ratio:3/2; grid-column:span 2; grid-row:auto; align-self:start; }
.ng-photos.ng-layout-custom.ng-photos-2 .ng-pw-auto,
.ng-photos.ng-layout-custom.ng-photos-4 .ng-pw-auto,
.ng-photos.ng-layout-custom .ng-pw-12,
.ng-photos.ng-layout-custom .ng-pw-13{ grid-column:span 1; }
.ng-photos.ng-layout-custom .ng-pw-full,
.ng-photos.ng-layout-custom .ng-pw-23{ grid-column:span 2; }
.ng-photos.ng-layout-custom.ng-photos-3 .ng-pw-auto:not(:first-child){ grid-column:span 1; }
.ng-photos .ng-pr-wide{ aspect-ratio:16/9 !important; }
.ng-photos .ng-pr-landscape{ aspect-ratio:3/2 !important; }
.ng-photos .ng-pr-square{ aspect-ratio:1/1 !important; }
.ng-photos .ng-pr-portrait{ aspect-ratio:4/5 !important; }
.ng-photos.ng-layout-stack .ng-photo.is-circle,
.ng-photos.ng-layout-custom .ng-photo.is-circle{ aspect-ratio:1/1 !important; width:min(100%,520px); justify-self:center; }
@media (min-width:700px){
	.ng-photos.ng-layout-stack,.ng-photos.ng-layout-custom{ grid-template-columns:repeat(6,minmax(0,1fr)); grid-auto-rows:auto; }
	.ng-photos.ng-layout-stack .ng-photo,
	.ng-photos.ng-layout-custom .ng-photo{ grid-column:span 6; grid-row:auto; }
	.ng-photos.ng-layout-custom .ng-pw-full{ grid-column:span 6; }
	.ng-photos.ng-layout-custom .ng-pw-23{ grid-column:span 4; }
	.ng-photos.ng-layout-custom .ng-pw-12{ grid-column:span 3; }
	.ng-photos.ng-layout-custom .ng-pw-13{ grid-column:span 2; }
	.ng-photos.ng-layout-custom.ng-photos-1 .ng-pw-auto{ grid-column:span 6; }
	.ng-photos.ng-layout-custom.ng-photos-2 .ng-pw-auto,
	.ng-photos.ng-layout-custom.ng-photos-4 .ng-pw-auto{ grid-column:span 3; }
	.ng-photos.ng-layout-custom.ng-photos-3 .ng-pw-auto,
	.ng-photos.ng-layout-custom.ng-photos-3 .ng-pw-auto:not(:first-child){ grid-column:span 2; }
}
/* the small preview in the post editor */
.ng-photos--preview{ --ng-ph:64px; --ng-gap:8px; --ng-r:10px; max-width:520px; margin:12px 0 4px !important; }
.ng-photos--preview .ng-photo{ box-shadow:0 1px 4px rgba(0,0,0,.25); }
@media (max-width:699px){ .ng-photo{ box-shadow:var(--ng-shadow-sm, 6px 7px 10px rgba(0,0,0,.30)); } }

/* ============================================================
   FREE CANVAS (2.8): each photo has its own position, size, shape and crop.
   Units are % of the canvas width, so the picture keeps its proportions at every screen width.
   Markup: <div class="ng-canvas" style="--ngc-h:56"><figure class="ng-cv-item is-rounded" style="--l:..;--t:..;--w:..;--h:..;--z:..;--ar:..;--fx:..;--fy:..;--zm:.."><img></figure>…
   Phones: the canvas becomes a simple 1 / 2 column grid in reading order (not for the editor: .ng-canvas--edit).
   ============================================================ */
.ng-canvas{ position:relative; width:100%; height:0; padding-bottom:calc(var(--ngc-h) * 1%); margin:0 0 60px; container-type:inline-size; }
.ng-cv-item{ position:absolute; left:var(--l); top:var(--t); width:var(--w); height:var(--h); z-index:var(--z); margin:0; overflow:hidden; background:#e4e4e4; border-radius:20px; border-radius:2.3cqw; box-shadow:var(--ng-shadow, 12px 14px 18px rgba(0,0,0,.30)); }
.ng-cv-item img{ position:absolute; inset:0; width:100%; height:100%; max-width:none; object-fit:cover; display:block; object-position:var(--fx,50%) var(--fy,50%); transform:scale(var(--zm,1)); transform-origin:var(--fx,50%) var(--fy,50%); -webkit-user-drag:none; user-select:none; }
.ng-cv-item.is-square{ border-radius:0; }
.ng-cv-item.is-circle{ border-radius:50%; }
@media (max-width:699px){
	.ng-canvas:not(.ng-canvas--edit){ height:auto; padding-bottom:0; margin-bottom:34px; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; container-type:normal; }
	.ng-canvas:not(.ng-canvas--edit) .ng-cv-item{ position:relative; left:auto; top:auto; width:auto; height:auto; z-index:auto; aspect-ratio:var(--ar); border-radius:18px; box-shadow:var(--ng-shadow-sm, 6px 7px 10px rgba(0,0,0,.30)); }
	.ng-canvas:not(.ng-canvas--edit) .ng-cv-item.is-square{ border-radius:0; }
	.ng-canvas:not(.ng-canvas--edit) .ng-cv-item.is-circle{ border-radius:50%; }
	.ng-canvas:not(.ng-canvas--edit) .ng-cv-item.is-wide{ grid-column:1 / -1; }
	.ng-canvas:not(.ng-canvas--edit) .ng-cv-item.is-circle.is-wide{ width:72%; justify-self:center; }
}
@media (min-width:700px) and (max-width:980px){ .ng-canvas{ margin-bottom:50px; } }
