/**
 * AIContestList — Prompt gallery components (design-system §51–§54, §69).
 * Shared by the Prompt Library and the prompt detail page (related prompts):
 * Copy Prompt control, justified gallery, Prompt Card, "Prompt copied" toast, and the
 * color-palette swatch every Prompt surface uses.
 *
 * Gallery: justified rows. Each card is laid out at ratio × row height and rows grow
 * to the full width, so every image keeps its own aspect ratio (no cropping), reading
 * order stays row by row, and the geometry is known before any image loads (no CLS).
 * Card markup: template-parts/components/prompt-card.php; behaviour: assets/js/prompts.js.
 * Works on Immersive Dark and Editorial Light through semantic tokens.
 * Tokens only. Breakpoints: 600 · 1024 · 1440 · 1800.
 */

/* ---------------------------------------------------------------
   COPY PROMPT (tasks.md 2.13) — text and icon variants
--------------------------------------------------------------- */
.acl .acl-copy[hidden] { display: none; }

/* With JavaScript the control is laid out from the first paint (html.acl-js is set in
   <head>), so revealing it in prompts.js never shifts the layout. */
.acl-js .acl .acl-copy[hidden] { display: inline-flex; }

.acl .acl-copy {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	margin: 0;
	font: 600 .9375rem / 1 var(--font-sans);
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: background-color var(--motion-base) var(--ease-standard), border-color var(--motion-base) var(--ease-standard), color var(--motion-base) var(--ease-standard), opacity var(--motion-base) var(--ease-standard), transform var(--motion-base) var(--ease-standard);
}

.acl .acl-copy__done { display: none; }
.acl .acl-copy[data-state="copied"] .acl-copy__icon { display: none; }
.acl .acl-copy[data-state="copied"] .acl-copy__done { display: block; }

.acl .acl-copy--text {
	min-height: 44px;
	padding: 0 var(--space-4);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: transparent;
	color: var(--text-primary);
}

.acl .acl-copy--text:hover { background: var(--overlay-ink-05); border-color: var(--overlay-ink-20); }
.acl [data-theme="dark"] .acl-copy--text:hover { background: var(--overlay-white-06); border-color: var(--overlay-white-24); }

.acl .acl-copy--text[data-state="copied"] {
	border-color: var(--interactive-primary);
	color: var(--interactive-soft-text);
	background: var(--interactive-soft);
}

/* Icon variant: sits on the artwork, so it carries its own dark glass for contrast.
   44px hit area; the visible disc is 40px (transparent 2px ring). */
.acl .acl-copy--icon {
	width: 44px;
	height: 44px;
	padding: 0;
	border: 2px solid transparent;
	border-radius: 50%;
	background: rgba(8, 9, 11, .64) padding-box;
	-webkit-backdrop-filter: blur(10px);
	backdrop-filter: blur(10px);
	color: var(--acl-white);
	box-shadow: inset 0 0 0 1px var(--overlay-white-16);
}

.acl .acl-copy--icon:hover { background: rgba(8, 9, 11, .86) padding-box; }

.acl .acl-copy--icon[data-state="copied"] {
	background: var(--interactive-primary) padding-box;
	box-shadow: none;
}

.acl .acl-copy:focus-visible { outline: 2px solid var(--focus-outline); outline-offset: 2px; }

/* ---------------------------------------------------------------
   GALLERY — justified rows (see header)
--------------------------------------------------------------- */
.acl .acl-pl-gallery {
	/* Basis row height: rows are filled at this height, then grow to the full width
	   (typically ×1.1–1.3). Phones: portraits pair up, squares and landscapes take the
	   full width — large artwork, one decision per row. */
	--row-h: 180px;
	--gap: 10px;

	display: flex;
	flex-wrap: wrap;
	gap: var(--space-5) var(--gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* The last row keeps its natural size instead of stretching to the edge */
.acl .acl-pl-gallery::after {
	content: "";
	flex: 100000 1 0px;
}

/* Grow ∝ ratio (×10: a line whose factors sum below 1 would only take that fraction
   of its free space, leaving a lone card short of the edge). */
.acl .acl-pl-gallery__item {
	flex: calc(var(--r) * 10) 1 calc(var(--r) * var(--row-h));
	min-width: 0;
}

@media (min-width: 600px) {
	.acl .acl-pl-gallery { --row-h: 170px; --gap: 14px; }
	/* A card alone on its row never balloons: it stops at 1.7× and the row stays open */
	.acl .acl-pl-gallery__item { max-width: calc(var(--r) * var(--row-h) * 1.7); }
}

@media (min-width: 1024px) {
	.acl .acl-pl-gallery { --row-h: 205px; --gap: 20px; row-gap: var(--space-8); }
}

@media (min-width: 1440px) { .acl .acl-pl-gallery { --row-h: 230px; } }
@media (min-width: 1800px) { .acl .acl-pl-gallery { --row-h: 255px; } }

/* Slow reveal as each row enters (scroll-driven; no JS, no layout change). */
@supports (animation-timeline: view()) {
	@media (prefers-reduced-motion: no-preference) {
		/* The first rows are already on screen at load: they render at once (no half-faded
		   text in the first view, nothing delaying the largest paint). */
		.acl-js .acl .acl-pl-gallery__item:nth-child(n+9) {
			animation: acl-pl-in linear both;
			animation-timeline: view();
			animation-range: entry 0% entry 55%;
		}
	}
}

@keyframes acl-pl-in {
	from { opacity: 0; transform: translateY(28px); }
	to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------
   PROMPT CARD (design-system §52)
--------------------------------------------------------------- */
.acl .acl-pcard {
	--acl-title-size: .9375rem;

	position: relative;
	display: flex;
	flex-direction: column;
	height: 100%;
	container-type: inline-size;
}

.acl .acl-pcard__media {
	position: relative;
	overflow: hidden;
	aspect-ratio: var(--r);
	border-radius: var(--radius-md);
	background: var(--bg-surface); /* neutral while the image loads */
	transition: box-shadow var(--motion-slow) var(--ease-standard), transform var(--motion-slow) var(--ease-standard);
}

/* Hairline edge above the artwork; turns Iris on hover/focus */
.acl .acl-pcard__media::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	border-radius: inherit;
	box-shadow: inset 0 0 0 1px var(--overlay-ink-08);
	transition: box-shadow var(--motion-slow) var(--ease-standard);
	pointer-events: none;
}

.acl [data-theme="dark"] .acl-pcard__media::after { box-shadow: inset 0 0 0 1px var(--overlay-white-06); }

/* Lower neutral gradient that clarifies the "View prompt" label */
.acl .acl-pcard__media::before {
	content: "";
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 1;
	height: 48%;
	background: linear-gradient(to top, rgba(8, 9, 11, .62) 0%, rgba(8, 9, 11, 0) 100%);
	opacity: 0;
	transition: opacity var(--motion-slow) var(--ease-standard);
	pointer-events: none;
}

.acl .acl-pcard__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover; /* the box already has the image's ratio: nothing is cropped */
	transition: transform 300ms var(--ease-standard);
}

.acl .acl-pcard__view {
	position: absolute;
	left: var(--space-3);
	bottom: var(--space-3);
	z-index: 2;
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	font-size: var(--text-sm);
	font-weight: 600;
	color: var(--acl-white);
	opacity: 0;
	transform: translateY(8px);
	transition: opacity 280ms var(--ease-standard), transform 280ms var(--ease-enter);
	pointer-events: none;
}

.acl .acl-pcard__body {
	/* Two title lines + one meta line are always reserved, so every row's captions end
	   on the same line and the meta sits right under a one-line title. */
	min-width: 0;
	min-height: calc(var(--space-3) + 2 * 1.3 * var(--acl-title-size) + 2px + 1.5 * var(--text-xs));
	padding-top: var(--space-3);
}

.acl .acl-pcard__title {
	display: -webkit-box;
	margin: 0 0 2px;
	overflow: hidden;
	font-size: var(--acl-title-size);
	font-weight: 600;
	line-height: 1.3;
	letter-spacing: -.01em;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	text-wrap: pretty;
}

.acl .acl-pcard__link {
	color: var(--text-primary);
	text-decoration: underline;
	text-decoration-color: transparent;
	text-decoration-thickness: 1px;
	text-underline-offset: .2em;
	transition: text-decoration-color var(--motion-base) var(--ease-standard);
}

/* The whole card opens the prompt */
.acl .acl-pcard__link::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 2;
	border-radius: var(--radius-md);
}

.acl .acl-pcard__link:focus-visible { outline: none; }

.acl .acl-pcard__link:focus-visible::after {
	outline: 2px solid var(--focus-outline);
	outline-offset: 4px;
}

.acl .acl-pcard__meta {
	display: flex;
	min-width: 0;
	margin: 0;
	overflow: hidden;
	font-size: var(--text-xs);
	font-weight: 500;
	line-height: 1.5;
	color: var(--text-secondary);
	white-space: nowrap;
}

.acl .acl-pcard__fact { overflow: hidden; text-overflow: ellipsis; }
.acl .acl-pcard__fact + .acl-pcard__fact { flex: 1 1 auto; }
.acl .acl-pcard__fact + .acl-pcard__fact::before { content: "·"; margin: 0 .45em; color: var(--text-tertiary); }
.acl .acl-pcard__fact--model { flex: none; max-width: 70%; color: var(--interactive-soft-text); }

.acl .acl-pcard__copy {
	position: absolute;
	top: var(--space-2);
	right: var(--space-2);
	z-index: 3;
}

/* Text-only prompt: the words are the artifact, set like a type specimen */
.acl .acl-pcard__specimen {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	gap: clamp(10px, 5cqi, 20px);
	padding: clamp(14px, 9cqi, 28px);
	background:
		radial-gradient(120% 80% at 100% 0%, var(--iris-12) 0%, transparent 60%),
		linear-gradient(160deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
}

.acl .acl-pcard__specimen::after {
	content: "";
	position: absolute;
	left: clamp(14px, 9cqi, 28px);
	bottom: 0;
	width: 40%;
	height: 1px;
	background: var(--gradient-ai);
	opacity: .8;
}

.acl .acl-pcard__specimen-kicker {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: .12em;
	text-transform: uppercase;
	color: var(--interactive-soft-text);
}

.acl .acl-pcard__specimen-text {
	flex: 1 1 auto;
	min-height: 0;
	margin: 0;
	overflow: hidden;
	font-size: clamp(1rem, 7.5cqi, 1.375rem);
	font-style: italic;
	line-height: 1.25;
	letter-spacing: -.01em;
	color: var(--text-primary);
	-webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
	mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
}

/* Hover & keyboard focus: emphasis only (design-system §32, §52) */
@media (hover: hover) and (pointer: fine) {
	.acl .acl-pcard:hover .acl-pcard__img { transform: scale(1.025); }
	.acl .acl-pcard:hover .acl-pcard__media::before { opacity: 1; }
	.acl .acl-pcard:hover .acl-pcard__view { opacity: 1; transform: none; }
	.acl .acl-pcard:hover .acl-pcard__link { text-decoration-color: var(--acl-iris-dark-text); }

	.acl .acl-pcard:hover .acl-pcard__media {
		box-shadow: 0 18px 44px -18px var(--iris-36);
	}

	.acl .acl-pcard:hover .acl-pcard__media::after {
		box-shadow: inset 0 0 0 1px var(--iris-36);
	}

	/* The copy control appears with the card's emphasis; it stays while in use. */
	.acl .acl-pcard__copy {
		opacity: 0;
		transform: translateY(-4px);
	}

	.acl .acl-pcard:hover .acl-pcard__copy,
	.acl .acl-pcard:focus-within .acl-pcard__copy,
	.acl .acl-pcard__copy[data-state] {
		opacity: 1;
		transform: none;
	}
}

.acl .acl-pcard:focus-within .acl-pcard__media::before { opacity: 1; }
.acl .acl-pcard:focus-within .acl-pcard__view { opacity: 1; transform: none; }

/* Color palette: up to three small swatches at the end of the meta line */
.acl .acl-pcard__palette {
	display: inline-flex;
	flex: none;
	align-items: center;
	gap: 3px;
	margin-left: auto;
	padding-left: var(--space-2);
	align-self: center;
}

.acl .acl-pcard__palette .acl-swatch { width: 8px; height: 8px; }

/* Narrow cards: keep the essentials, drop what would crowd them */
@container (max-width: 159px) {
	.acl .acl-pcard__view { display: none; }
	.acl .acl-pcard__fact + .acl-pcard__fact { display: none; }
	.acl .acl-pcard__fact--model { max-width: 100%; }
}

@media (max-width: 599px) {
	.acl .acl-pcard { --acl-title-size: .875rem; }
	.acl .acl-pcard__body { padding-top: var(--space-2); min-height: calc(var(--space-2) + 2 * 1.3 * var(--acl-title-size) + 2px + 1.5 * var(--text-xs)); }
}

@media (prefers-reduced-motion: reduce) {
	.acl .acl-pcard:hover .acl-pcard__img { transform: none; }
}

/* ---------------------------------------------------------------
   TOAST — "Prompt copied" (design-system §69)
--------------------------------------------------------------- */
.acl .acl-toast {
	position: fixed;
	left: 50%;
	bottom: calc(var(--space-6) + 56px + env(safe-area-inset-bottom) + var(--acl-consent-space, 0px)); /* clears the Filters shortcut and the cookie card */
	z-index: 700;
	display: flex;
	align-items: center;
	gap: var(--space-2);
	max-width: calc(100vw - 32px);
	padding: var(--space-3) var(--space-5);
	border-radius: var(--radius-pill);
	background: var(--bg-inverse);
	color: var(--text-inverse);
	font-size: .9375rem;
	font-weight: 600;
	line-height: 1.35;
	box-shadow: var(--shadow-3);
	opacity: 0;
	visibility: hidden;
	transform: translate(-50%, 12px);
	transition: opacity var(--motion-base) var(--ease-standard), transform var(--motion-slow) var(--ease-enter), visibility 0s linear var(--motion-slow);
	pointer-events: none;
}

.acl .acl-toast::before {
	content: "";
	flex: none;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--acl-success);
}

.acl .acl-toast[data-tone="error"]::before { background: var(--acl-danger); }

.acl .acl-toast.is-visible {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, 0);
	transition: opacity var(--motion-base) var(--ease-standard), transform var(--motion-slow) var(--ease-enter), visibility 0s;
}

@media (min-width: 1024px) {
	.acl .acl-toast { bottom: calc(var(--space-8) + env(safe-area-inset-bottom)); }
}

/* ---------------------------------------------------------------
   PAGE TRANSITION (design-system §33) — progressive enhancement
   Library ⇄ prompt page: the card's artwork grows into the page's artwork
   (same view-transition-name on both); everything else cross-fades.
   Browsers without cross-document view transitions simply navigate.
--------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
	@view-transition { navigation: auto; }

	::view-transition-group(*) {
		animation-duration: 420ms;
		animation-timing-function: var(--ease-enter);
	}

	::view-transition-old(root),
	::view-transition-new(root) { animation-duration: 220ms; }
}

/* ---------------------------------------------------------------
   COLOR PALETTE SWATCH — the seven colour families a result is filed under
   (Prompt Studio → /prompts/color/{slug}/). Library filter, hub index, color hub
   hero, prompt cards and the generation record all draw the same disc.

   Flat discs in a slightly muted, editorial palette with a hairline edge: no gloss,
   no gradients beyond Neutral's split. These are data colours, not interface colours —
   they appear only inside a swatch, never as text, fills or borders of controls, so the
   artwork keeps the colour and the UI stays quiet (design-system §116: scoped here, not
   added to the token layer).
--------------------------------------------------------------- */
.acl [data-hue="red"] { --hue: #D4524A; --hue-paint: initial; }
.acl [data-hue="orange"] { --hue: #DD7B3A; --hue-paint: initial; }
.acl [data-hue="yellow"] { --hue: #DDB64C; --hue-paint: initial; }
.acl [data-hue="green"] { --hue: #4E9A70; --hue-paint: initial; }
.acl [data-hue="blue"] { --hue: #4A78D4; --hue-paint: initial; }
.acl [data-hue="purple"] { --hue: #8B63C8; --hue-paint: initial; }

/* Neutral: bone and graphite meet on the diagonal */
.acl [data-hue="neutral"] {
	--hue: #8B8D96;
	--hue-paint: linear-gradient(135deg, #ECEAE6 0 50%, #2E3035 50% 100%);
}

.acl .acl-swatch {
	position: relative;
	display: inline-block;
	flex: none;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--hue-paint, var(--hue, var(--text-tertiary)));
	box-shadow: inset 0 0 0 1px var(--overlay-ink-12);
	vertical-align: middle;
}

.acl [data-theme="dark"] .acl-swatch { box-shadow: inset 0 0 0 1px var(--overlay-white-10); }

/* "No colour constraint": an empty hairline ring */
.acl .acl-swatch--none,
.acl [data-theme="dark"] .acl-swatch--none {
	background: transparent;
	box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* Removable filter chip (an inline-flex with its own gap): the swatch leads the name */
.acl .acl-chip .acl-swatch { width: 11px; height: 11px; }
