/* ==========================================================================
   HaniArt — Galerie
   --------------------------------------------------------------------------
   A justified (Flickr-shaped) photo grid, in pure CSS.

   THE LAYOUT, IN ONE PARAGRAPH
   Every figure carries `--ar`, its real aspect ratio, written server-side from
   the attachment metadata. Each figure gets `flex-grow: var(--ar)` and a
   flex-basis proportional to the same number. Inside one flex row the widths
   therefore land in proportion to each photo's ratio — and because each image
   also has `aspect-ratio: var(--ar)`, every image in that row resolves to the
   SAME height. No JavaScript, no measuring pass, no layout library, and no
   jump when the images arrive, because the ratio is known before they load.

   NOTHING IS CROPPED. That is the point: the library is 62% landscape and 38%
   portrait, and the old carousel squeezed all of it into one 310x200 landscape
   box.
   ========================================================================== */

.hani-gal {
	--gal-gap: clamp(4px, 0.5vw, 10px);
	/* Target row height. This is the density dial: at 20rem only 2-3 photos fit
	   a 1440px row and 55 images ran to 19 screens. 14rem lands 4-5 per row and
	   roughly quarters the page, while still showing each photograph big enough
	   to read. */
	--gal-row: 14rem;
	--gal-radius: 14px;
	/* The gallery sets its own width. It must NOT inherit the 760px reading
	   measure that suits body copy - photographs need the room, and at 760px a
	   justified row held barely two of them. */
	max-width: min(100%, 1680px);
	margin-inline: auto;
	/* NOTE: there is deliberately no max-height on a figure. Capping the height
	   leaves the flex item still growing WIDE while its image cannot grow TALL,
	   so the row ends in dead space - which looks far worse than one tall photo.
	   A lone leftover is instead prevented by keeping --gal-row small enough
	   that rows hold 4-6 photographs, and by the spacers on the final row. */
}

/* --------------------------------------------------------------------------
   2. The justified grid
   -------------------------------------------------------------------------- */

.hani-gal__grid {
	display: flex;
	flex-wrap: wrap;
	gap: var(--gal-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.hani-gal__item {
	position: relative;
	flex-grow: var(--ar, 1.5);
	flex-basis: calc(var(--ar, 1.5) * var(--gal-row));
	margin: 0;
	min-width: 0;
	border-radius: var(--gal-radius);
	overflow: hidden;
	background: var(--wp--custom--surface-sunken, #f4f6f9);   /* holds the space while loading */
}

.hani-gal__link {
	display: block;
	width: 100%;
	height: 100%;
	text-decoration: none;
	outline-offset: -3px;
}

.hani-gal__img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: var(--ar, 1.5);
	object-fit: cover;
	transition: transform .5s var(--wp--custom--ease, cubic-bezier(.16, 1, .3, 1)),
	            filter .35s ease;
}

/* A restrained hover: the photograph grows very slightly inside its own frame
   and the frame lifts. Photography galleries are ruined by loud hover effects —
   the picture is the content, the interaction is not. */
.hani-gal__item::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55);
	pointer-events: none;
}

@media (hover: hover) {
	.hani-gal__item:hover .hani-gal__img { transform: scale(1.035); }
	.hani-gal__item:hover { box-shadow: var(--wp--preset--shadow--card, 0 24px 60px -15px rgba(20, 32, 54, .18)); }
}

/* Absorb the leftover growth on the final row. Without these, two photos left
   over would stretch to the full width and dwarf every row above them. */
.hani-gal__spacer {
	flex-grow: 1000;
	flex-basis: 0;
	height: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

/* --------------------------------------------------------------------------
   3. Lightbox — native <dialog>
   -------------------------------------------------------------------------- */

.hani-lb {
	width: min(96vw, 1500px);
	max-width: none;
	max-height: 94vh;
	padding: 0;
	border: 0;
	background: transparent;
	overflow: visible;
}

.hani-lb::backdrop {
	background: rgba(14, 18, 24, .93);
	backdrop-filter: blur(5px);
}

.hani-lb__stage {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: .75rem;
	margin: 0;
}

.hani-lb__img {
	display: block;
	max-width: 100%;
	max-height: 84vh;
	width: auto;
	height: auto;
	border-radius: 8px;
	background: #0e1218;
}

.hani-lb__cap {
	color: rgba(255, 255, 255, .82);
	font-size: .85rem;
	text-align: center;
	max-width: 60ch;
}

.hani-lb__close,
.hani-lb__nav {
	position: fixed;
	z-index: 2;
	display: grid;
	place-items: center;
	min-width: 48px;
	min-height: 48px;
	border: 0;
	border-radius: 9999px;
	background: rgba(255, 255, 255, .12);
	color: #fff;
	font-size: 1.8rem;
	line-height: 1;
	cursor: pointer;
	transition: background-color .18s ease;
}

.hani-lb__close:hover,
.hani-lb__nav:hover { background: rgba(255, 255, 255, .24); }

/*
 * The one focus ring in this theme that is deliberately NOT ink.
 *
 * main.css draws an ink ring because it is painted on the page - canvas or
 * white - where ink measures 15.6:1 and 17.8:1. These two buttons sit on the
 * lightbox backdrop, rgba(14, 18, 24, .93), where the same ink ring measures
 * 1.06:1 and simply is not there. Teal on that backdrop is 11.4:1.
 */
.hani-lb__close:focus-visible,
.hani-lb__nav:focus-visible {
	outline: 3px solid var(--wp--preset--color--accent-teal, #24515e);
	outline-offset: 2px;
}

.hani-lb__close { top: 1.1rem; right: 1.1rem; font-size: 2rem; }
.hani-lb__prev  { left: 1.1rem;  top: 50%; transform: translateY(-50%); }
.hani-lb__next  { right: 1.1rem; top: 50%; transform: translateY(-50%); }

/* Without JavaScript the dialog is never opened, so it must not occupy space
   or be reachable. */
.hani-lb:not([open]) { display: none; }

/* --------------------------------------------------------------------------
   4. Empty state
   -------------------------------------------------------------------------- */

.hani-gal__empty {
	padding: clamp(2rem, 6vw, 4rem);
	text-align: center;
	border: 1px dashed var(--wp--custom--border-subtle, rgba(226, 232, 240, .85));
	border-radius: var(--wp--custom--radius-card, 28px);
	background: var(--wp--preset--color--surface-white, #fff);
	color: var(--wp--preset--color--ink-secondary, #586171);
}

.hani-gal__hint {
	margin-block-start: .75rem;
	font-size: .88rem;
	color: var(--wp--preset--color--ink-muted, #656d7c);
}

/* --------------------------------------------------------------------------
   5. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1100px) { .hani-gal { --gal-row: 12rem; } }
@media (max-width: 780px)  { .hani-gal { --gal-row: 9rem; } }

/* Below this a justified row holds one, maybe two photos and the arithmetic
   stops helping — a single column shows the work far better on a phone. */
@media (max-width: 520px) {
	.hani-gal__grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
	.hani-gal__item { flex: none; }
	.hani-gal__spacer { display: none; }
	.hani-lb__prev { left: .5rem; }
	.hani-lb__next { right: .5rem; }
}

/* --------------------------------------------------------------------------
   6. Motion and print
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.hani-gal__img,
	.hani-gal__pill,
	.hani-lb__close,
	.hani-lb__nav { transition: none; }

	.hani-gal__item:hover .hani-gal__img { transform: none; }
}

@media print {
	.hani-gal__filters,
	.hani-lb { display: none !important; }

	.hani-gal__grid { display: block; }

	.hani-gal__item {
		break-inside: avoid;
		max-width: 48%;
		display: inline-block;
		margin: 0 1% 1% 0;
	}
}

/* ==========================================================================
   COVER OVERVIEW + MUSEON-STYLE HOVER
   --------------------------------------------------------------------------
   The gallery now opens on one cover card per category instead of a single
   filtered wall of every photograph.

   The hover is modelled on the Museon reference: the image scales slightly AND
   tilts a couple of degrees inside a clipped, rounded frame, over ~0.6s
   ease-out. Every third card tilts the other way, which is what stops a grid of
   them looking mechanical. The frame clips, so the tilt never pushes a corner
   outside the card.
   ========================================================================== */

.hani-gal {
	--gal-radius-card: 20px;       /* Museon uses 20px */
	--gal-tilt: 2deg;
	--gal-zoom: 1.06;
	--gal-ease: cubic-bezier(.16, 1, .3, 1);
}

/* --------------------------------------------------------------------------
   Level 1 — category covers (masonry, shaped by each cover photograph)
   --------------------------------------------------------------------------
   The first version of this was a uniform grid, every tile cropped to the same
   1:0.745 rectangle. On a photographer's site that is the one thing it must not
   do: a standing portrait and a wide studio shot are different pictures, and
   cropping both to the same box throws the difference away.

   So each tile takes the aspect ratio of its own cover photograph, handed to
   CSS by the renderer as --gal-cover-ratio, and the tiles pack into columns.

   WHY CSS COLUMNS AND NOT GRID
   Grid cannot do masonry without either `grid-template-rows: masonry`, which is
   not shipped widely enough to rely on, or computing a row span per tile - and
   a span in grid rows only works if you know the column width in advance, which
   a fluid layout does not. Columns give real masonry with no arithmetic and no
   JavaScript.

   The cost is reading order: columns flow top-to-bottom, so tile 2 sits below
   tile 1 rather than beside it. For a set of independent category tiles with no
   narrative order that is acceptable, and the DOM order - which keyboard and
   screen readers follow - is unchanged.
   -------------------------------------------------------------------------- */

.hani-gal__covers {
	columns: 3;
	column-gap: clamp(.9rem, 1.6vw, 1.6rem);
}

@media (max-width: 1100px) {
	.hani-gal__covers { columns: 2; }
}

@media (max-width: 700px) {
	.hani-gal__covers { columns: 1; }
}

.hani-gal__cover {
	/* A tile split across a column break is a broken photograph. */
	break-inside: avoid;
	-webkit-column-break-inside: avoid;
	page-break-inside: avoid;

	margin: 0 0 clamp(.9rem, 1.6vw, 1.6rem);
}

.hani-gal__cover-link {
	position: relative;
	display: block;
	text-decoration: none;
	color: inherit;
	border-radius: var(--gal-radius-card);
	outline-offset: 4px;
}

/* The clipping frame. Without overflow:hidden the tilt shows its corners. */
.hani-gal__cover-frame {
	position: relative;
	display: block;
	overflow: hidden;
	border-radius: var(--gal-radius-card);
	background: var(--wp--custom--surface-sunken, #f4f6f9);

	/* Set per tile by haniart_gallery_covers_html() from the cover photograph's
	 * real dimensions, clamped there to between 0.62 and 1.5. The fallback is
	 * the Museon card proportion the design was drawn with, used when a cover
	 * has no stored width and height. */
	aspect-ratio: var(--gal-cover-ratio, 1 / 0.745);
}

.hani-gal__cover-img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform .6s ease-out;
}

/* The gradient that makes white caption text legible over any photograph. */
.hani-gal__cover-frame::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(180deg, rgba(10, 14, 20, 0) 45%, rgba(10, 14, 20, .78) 100%);
	pointer-events: none;
	transition: opacity .4s ease;
}

.hani-gal__cover-meta {
	position: absolute;
	inset-inline: 0;
	inset-block-end: 0;
	z-index: 1;
	display: flex;
	flex-direction: column;
	gap: .15rem;
	padding: 1.15rem 1.35rem;
	color: #fff;
	pointer-events: none;
}

.hani-gal__cover-name {
	font-size: clamp(1rem, 1.5vw, 1.2rem);
	font-weight: 700;
	line-height: 1.2;
	letter-spacing: -.01em;
	text-wrap: balance;
}

.hani-gal__cover-count {
	font-size: .78rem;
	font-weight: 600;
	color: rgba(255, 255, 255, .78);
	font-variant-numeric: tabular-nums;
}

/* The little arrow badge, hidden until hover - straight from the reference. */
.hani-gal__cover-go {
	position: absolute;
	top: 1rem;
	right: 1rem;
	z-index: 2;
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	border-radius: 9999px;
	background: var(--wp--preset--color--accent-teal, #24515e);
	color: #fff;   /* 8.70:1 on the accent; the dark arrow was 1.95:1 */
	transform: scale(0);
	transition: transform .4s var(--gal-ease);
}

@media (hover: hover) {
	.hani-gal__cover-link:hover .hani-gal__cover-img,
	.hani-gal__cover-link:focus-visible .hani-gal__cover-img {
		transform: scale(var(--gal-zoom)) rotate(var(--gal-tilt));
	}

	/* Alternate the tilt so a wall of cards does not look stamped out. */
	.hani-gal__cover:nth-child(3n + 2) .hani-gal__cover-link:hover .hani-gal__cover-img {
		transform: scale(var(--gal-zoom)) rotate(calc(var(--gal-tilt) * -1));
	}

	.hani-gal__cover-link:hover .hani-gal__cover-go,
	.hani-gal__cover-link:focus-visible .hani-gal__cover-go { transform: scale(1); }
}

/* Keyboard users get the badge too - it is the affordance, not decoration. */
.hani-gal__cover-link:focus-visible .hani-gal__cover-go { transform: scale(1); }

/* --------------------------------------------------------------------------
   Level 2 — heading and back link
   -------------------------------------------------------------------------- */

.hani-gal__head { margin-block-end: clamp(1.2rem, 2.5vw, 2rem); }

.hani-gal__back {
	display: inline-flex;
	align-items: center;
	gap: .4rem;
	min-height: 44px;
	padding: .45rem .95rem .45rem .7rem;
	border: 1px solid var(--wp--custom--border-subtle, rgba(226, 232, 240, .85));
	border-radius: 9999px;
	background: var(--wp--preset--color--surface-white, #fff);
	color: var(--wp--preset--color--ink-secondary, #586171);
	font-size: .82rem;
	font-weight: 600;
	text-decoration: none;
	transition: background-color .18s ease, color .18s ease;
}

.hani-gal__back:hover {
	background: var(--wp--preset--color--pill-dark, #181d24);
	color: #fff;
	border-color: transparent;
}

.hani-gal__head-title {
	margin: .85rem 0 .1rem;
	font-size: clamp(1.6rem, 3.2vw, 2.4rem);
	line-height: 1.12;
	letter-spacing: -.02em;
}

.hani-gal__head-count {
	margin: 0;
	font-size: .85rem;
	font-weight: 600;
	color: var(--wp--preset--color--ink-muted, #656d7c);
}

.hani-gal__head-desc {
	margin: .6rem 0 0;
	max-width: 62ch;
	color: var(--wp--preset--color--ink-secondary, #586171);
}

/* --------------------------------------------------------------------------
   The same hover on the photographs inside a category
   -------------------------------------------------------------------------- */

.hani-gal__item { border-radius: var(--gal-radius-card); }
.hani-gal__img { transition: transform .6s ease-out; }

@media (hover: hover) {
	.hani-gal__item:hover .hani-gal__img {
		transform: scale(var(--gal-zoom)) rotate(var(--gal-tilt));
	}

	.hani-gal__item:nth-child(3n + 2):hover .hani-gal__img {
		transform: scale(var(--gal-zoom)) rotate(calc(var(--gal-tilt) * -1));
	}
}

@media (prefers-reduced-motion: reduce) {
	.hani-gal__cover-img,
	.hani-gal__cover-go,
	.hani-gal__img { transition: none; }

	.hani-gal__cover-link:hover .hani-gal__cover-img,
	.hani-gal__cover:nth-child(3n + 2) .hani-gal__cover-link:hover .hani-gal__cover-img,
	.hani-gal__item:hover .hani-gal__img,
	.hani-gal__item:nth-child(3n + 2):hover .hani-gal__img { transform: none; }

	.hani-gal__cover-link:hover .hani-gal__cover-go { transform: scale(1); }
}

@media (max-width: 560px) {
	.hani-gal__covers { columns: 1; }
}

@media print {
	.hani-gal__cover-go,
	.hani-gal__back { display: none !important; }
}
