/**
 * ImageSnippets Search.
 *
 * The layout rule that matters is .iss__frame: every result is a box of a fixed
 * ratio and the image covers it. A search results template that sizes each
 * result from the image's own dimensions is what turns a page of photographs
 * into a column of full-width images with a one-line caption under each. Here
 * the grid decides the size and the photograph fits it, so rows line up and
 * nothing reflows as images arrive.
 *
 * Colours and type are inherited on purpose. This has to sit inside whatever
 * theme a site runs — two so far, and more later — so it sets structure and
 * borrows appearance. currentColor and transparent backgrounds mean a dark
 * theme needs no dark stylesheet here.
 */

.iss {
	--iss-columns: 4;
	--iss-ratio: 1;
	--iss-gap: 1rem;
	--iss-radius: 4px;
}

/* ---- form ---- */

.iss__form {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	margin-block-end: 0.75rem;
}

.iss__input {
	flex: 1 1 auto;
	min-width: 0;
	padding: 0.5em 0.75em;
	font: inherit;
	color: inherit;
	background: transparent;
	border: 1px solid currentColor;
	border-radius: var( --iss-radius );
}

.iss__clear,
.iss__facet-more,
.iss__page {
	padding: 0.35em 0.7em;
	font: inherit;
	font-size: 0.875em;
	color: inherit;
	cursor: pointer;
	background: transparent;
	border: 1px solid currentColor;
	border-radius: var( --iss-radius );
}

.iss__page.is-current {
	font-weight: 700;
	/* Not a colour: the theme owns colour. Inverting the border weight is
	   legible against any palette. */
	border-width: 2px;
}

.iss__page[disabled] {
	cursor: default;
	opacity: 0.4;
}

.iss__status {
	margin: 0 0 0.75rem;
	font-size: 0.875em;
	opacity: 0.75;
}

.iss.is-loading .iss__results {
	opacity: 0.55;
	transition: opacity 120ms linear;
}

/* ---- layout ---- */

.iss__body {
	display: grid;
	grid-template-columns: minmax( 0, 1fr );
	gap: calc( var( --iss-gap ) * 1.5 );
}

@media ( min-width: 782px ) {
	.iss__body:has( .iss__facets ) {
		grid-template-columns: minmax( 11rem, 15rem ) minmax( 0, 1fr );
	}
}

/* ---- facets ---- */

.iss__facet {
	margin-block-end: 1.25rem;
}

.iss__facet-name {
	margin: 0 0 0.35rem;
	font-size: 0.8125em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	opacity: 0.7;
}

.iss__facet-coverage {
	margin: 0 0 0.3rem;
	font-size: 0.75em;
	font-style: italic;
	opacity: 0.55;
}

.iss__facet-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.iss__facet-row {
	margin: 0;
}

.iss__facet-label {
	display: flex;
	gap: 0.45rem;
	align-items: baseline;
	padding: 0.15rem 0;
	font-size: 0.9375em;
	cursor: pointer;
}

.iss__facet-box {
	flex: 0 0 auto;
}

.iss__facet-text {
	flex: 1 1 auto;
	min-width: 0;
}

.iss__facet-count {
	flex: 0 0 auto;
	font-size: 0.8125em;
	font-variant-numeric: tabular-nums;
	opacity: 0.6;
}

/* Marks a value reached through a class chain rather than asserted outright. */
.iss__facet-inferred {
	flex: 0 0 auto;
	font-size: 0.8125em;
	text-decoration: none;
	cursor: help;
	opacity: 0.5;
}

.iss__facet-more {
	margin-block-start: 0.35rem;
}

/* ---- results ---- */

.iss__grid {
	display: grid;
	grid-template-columns: repeat( var( --iss-columns ), minmax( 0, 1fr ) );
	gap: var( --iss-gap );
	margin: 0;
	padding: 0;
	list-style: none;
}

@media ( max-width: 960px ) {
	.iss__grid {
		grid-template-columns: repeat( min( var( --iss-columns ), 3 ), minmax( 0, 1fr ) );
	}
}

@media ( max-width: 640px ) {
	.iss__grid {
		grid-template-columns: repeat( 2, minmax( 0, 1fr ) );
	}
}

.iss__item {
	margin: 0;
}

.iss__link {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	color: inherit;
	text-decoration: none;
}

.iss__link:hover .iss__title,
.iss__link:focus-visible .iss__title {
	text-decoration: underline;
}

.iss__link:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

/*
 * The fix for the whole layout problem. The box has the ratio; the photograph
 * covers it whatever its own proportions are. aspect-ratio holds the space
 * before the image loads, so a grid of results does not reflow line by line as
 * remote thumbnails arrive.
 */
.iss__frame {
	position: relative;
	overflow: hidden;
	aspect-ratio: var( --iss-ratio );
	background: currentColor;
	border-radius: var( --iss-radius );
	/* The background is only a placeholder tint behind a loading image. */
	opacity: 0.999;
}

.iss__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	/* Cancels the placeholder tint inherited from the frame. */
	background: transparent;
}

.iss__caption {
	display: flex;
	flex-direction: column;
	gap: 0.1rem;
}

.iss__title {
	font-size: 0.9375em;
	line-height: 1.3;
	/* Two lines, then ellipsis: titles come from the graph and vary wildly in
	   length, and a single long one must not push its neighbours out of line. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.iss__meta {
	font-size: 0.8125em;
	opacity: 0.65;
}

/*
 * Which galleries an image is in. Sits below the tile rather than inside its
 * link, because these are links themselves. With one gallery it is a quiet
 * label; with several it is a row of choices, and they need to look chooseable
 * without competing with the photograph above them.
 */
.iss__in {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem;
	align-items: baseline;
	margin-top: 0.3rem;
	font-size: 0.75em;
}

.iss__in-one,
.iss__in-label {
	opacity: 0.6;
}

.iss__in-link {
	padding: 0.1em 0.45em;
	color: inherit;
	text-decoration: none;
	border: 1px solid color-mix( in srgb, currentColor 30%, transparent );
	border-radius: 999px;
	opacity: 0.85;
}

.iss__in-link:hover,
.iss__in-link:focus-visible {
	border-color: currentColor;
	opacity: 1;
}

.iss__in-link:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* ---- pager ---- */

.iss__pager {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem;
	align-items: center;
	justify-content: center;
	margin-block-start: 1.5rem;
}

.iss__gap {
	padding: 0 0.2rem;
	opacity: 0.5;
}

.iss__noscript {
	font-size: 0.9375em;
}

/* Editor preview: the block renders its shell but never runs the view script,
   so give it something with shape rather than an empty box. */
.iss__editor-note {
	padding: 1rem;
	font-size: 0.875em;
	text-align: center;
	border: 1px dashed currentColor;
	border-radius: var( --iss-radius );
	opacity: 0.6;
}
