/*
 * CTI Linkhub: structure only. Colours and fonts come from the theme through the variables below.
 */
.ctilh {
	--ctilh-bg: var(--wp--preset--color--base, Canvas);
	--ctilh-fg: var(--wp--preset--color--contrast, CanvasText);
	/* Fallback is the text colour, not currentColor: currentColor would resolve to each element's own colour
	   (white on white for labels and buttons). */
	--ctilh-accent: var(--wp--preset--color--primary, var(--ctilh-fg));
	--ctilh-font: inherit;
	--ctilh-radius: 0;
	--ctilh-gap: .375rem;
	/* Tile shape, width / height. 3 / 4 is the Instagram grid; use 4 / 5 to show 1080x1350 images uncropped, 1 for squares. */
	--ctilh-ratio: 3 / 4;

	font-family: var(--ctilh-font);
	color: var(--ctilh-fg);
}

.ctilh *,
.ctilh *::before,
.ctilh *::after {
	box-sizing: border-box;
}

/* Visually hidden, still read by screen readers. */
.ctilh__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.ctilh a:focus-visible,
.ctilh button:focus-visible,
.ctilh input:focus-visible {
	outline: 3px solid var(--ctilh-accent);
	outline-offset: 2px;
}

/* Number search */
.ctilh__search {
	display: flex;
	gap: var(--ctilh-gap);
	margin: 0 0 var(--ctilh-gap);
}

.ctilh__input {
	flex: 1 1 auto;
	min-width: 0;
	font: inherit;
	padding: .6em .8em;
	border: 1px solid currentColor;
	border-radius: var(--ctilh-radius);
	background: var(--ctilh-bg);
	color: var(--ctilh-fg);
}

.ctilh__status {
	min-height: 1.5em;
	margin: 0 0 var(--ctilh-gap);
}

/* Category chips */
.ctilh__filters {
	display: flex;
	flex-wrap: wrap;
	gap: var(--ctilh-gap);
	margin: 0 0 var(--ctilh-gap);
}

.ctilh__chip {
	font: inherit;
	padding: .35em .9em;
	border: 1px solid currentColor;
	border-radius: 999px;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.ctilh__chip[aria-pressed="true"] {
	background: var(--ctilh-fg);
	color: var(--ctilh-bg);
}

/* Grid: always two columns on phones, the chosen number from tablet width on. */
.ctilh .ctilh__grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--ctilh-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (min-width: 600px) {
	.ctilh .ctilh__grid {
		grid-template-columns: repeat(var(--ctilh-columns, 3), minmax(0, 1fr));
	}
}

.ctilh .ctilh__grid > .ctilh__cell {
	/* display:block removes the list marker even where a theme sets list-style on li. */
	display: block;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ctilh .ctilh__grid > .ctilh__cell::marker,
.ctilh .ctilh__grid > .ctilh__cell::before {
	content: none;
}

.ctilh-tile {
	position: relative;
	display: block;
	aspect-ratio: var(--ctilh-ratio, 3 / 4);
	overflow: hidden;
	border-radius: var(--ctilh-radius);
	background: color-mix(in srgb, var(--ctilh-fg) 12%, transparent);
	color: inherit;
	text-decoration: none;
}

.ctilh-tile img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.ctilh-tile__placeholder {
	display: block;
	width: 100%;
	height: 100%;
}

.ctilh-tile__nr {
	position: absolute;
	top: .375rem;
	left: .375rem;
	min-width: 2em;
	padding: .1em .55em;
	border-radius: var(--ctilh-radius);
	background: var(--ctilh-fg);
	color: var(--ctilh-bg);
	font-size: .9375rem;
	font-weight: 700;
	line-height: 1.5;
	text-align: center;
}

.ctilh-tile__new {
	position: absolute;
	right: .375rem;
	bottom: .375rem;
	padding: .1em .55em;
	border-radius: var(--ctilh-radius);
	background: var(--ctilh-accent);
	color: var(--ctilh-bg);
	font-size: .8125rem;
	font-weight: 700;
	line-height: 1.5;
}

/* Highlight of a search hit; static when the visitor asks for less motion. */
.ctilh-tile--hit {
	outline: 4px solid var(--ctilh-accent);
	outline-offset: 2px;
	animation: ctilh-hit 2.4s ease-out 1;
}

@keyframes ctilh-hit {
	0%,
	55% {
		outline-color: var(--ctilh-accent);
	}

	100% {
		outline-color: transparent;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ctilh-tile--hit {
		animation: none;
	}
}

/* Detail card for a found number (the JS sheet in a later step reuses these classes). */
.ctilh-result {
	display: grid;
	gap: var(--ctilh-gap);
	margin: 0 0 calc(var(--ctilh-gap) * 2);
	padding: 1rem;
	border: 1px solid currentColor;
	border-radius: var(--ctilh-radius);
	background: var(--ctilh-bg);
}

@media (min-width: 600px) {
	.ctilh-result {
		grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
		align-items: start;
	}
}

.ctilh-result__img {
	display: block;
	width: 100%;
	height: auto;
	border-radius: var(--ctilh-radius);
}

.ctilh-result__title {
	margin: 0 0 .5em;
}

.ctilh-result__nr {
	display: inline-block;
	margin-right: .4em;
	padding: .05em .5em;
	background: var(--ctilh-fg);
	color: var(--ctilh-bg);
	font-size: .8em;
	border-radius: var(--ctilh-radius);
}

.ctilh-result__text,
.ctilh-result__date {
	margin: 0 0 .75em;
}

.ctilh-result__date {
	font-size: .875em;
	opacity: .8;
}

.ctilh-label {
	margin: 0 0 .5em;
	font-size: .875em;
	font-weight: 700;
}

/* Buttons: padding, font and radius come from the theme (wp-element-button plus the extra class from
   the settings, zero-specificity fallback below). Background and text colour are set as a pair, because
   themes colour links with more specific rules than their own buttons (black text on a dark button).
   Override with --ctilh-button-bg and --ctilh-button-fg. */
.ctilh .ctilh-button,
.ctilh .ctilh__submit {
	display: inline-block;
	background: var(--ctilh-button-bg, var(--ctilh-accent));
	color: var(--ctilh-button-fg, var(--ctilh-bg));
	cursor: pointer;
	text-align: center;
	text-decoration: none;
}

.ctilh a.ctilh-button:hover,
.ctilh a.ctilh-button:focus,
.ctilh a.ctilh-button:active,
.ctilh a.ctilh-button:visited,
.ctilh .ctilh__submit:hover,
.ctilh .ctilh__submit:focus {
	color: var(--ctilh-button-fg, var(--ctilh-bg));
	text-decoration: none;
}

.ctilh .ctilh-button:hover,
.ctilh .ctilh__submit:hover {
	opacity: .88;
}

:where(.ctilh-button, .ctilh__submit) {
	padding: .6em 1.2em;
	border: 0;
	border-radius: var(--ctilh-radius);
	font: inherit;
	font-weight: 700;
}

.ctilh__more {
	margin: calc(var(--ctilh-gap) * 2) 0 0;
	text-align: center;
}

.ctilh__notice {
	margin: calc(var(--ctilh-gap) * 2) 0 0;
	font-size: .875em;
	opacity: .85;
}

.ctilh__legal {
	margin: var(--ctilh-gap) 0 0;
	font-size: .875em;
}

/* An inline card that the script has replaced by the sheet. */
.ctilh-result[hidden] {
	display: none;
}

/* Detail sheet (native <dialog>, built by linkhub.js). It has no padding of its own, so a click on
   the dialog element itself is a click on the backdrop. */
.ctilh-sheet {
	width: 100%;
	max-width: min(42rem, calc(100vw - 2rem));
	max-height: calc(100vh - 2rem);
	max-height: calc(100dvh - 2rem);
	margin: auto;
	padding: 0;
	overflow: auto;
	border: 0;
	border-radius: var(--ctilh-radius);
	background: var(--ctilh-bg);
	color: var(--ctilh-fg);
	box-shadow: 0 12px 48px rgba(0, 0, 0, .4);
}

.ctilh-sheet::backdrop {
	background: rgba(0, 0, 0, .6);
}

.ctilh-sheet[open] {
	animation: ctilh-sheet-in .16s ease-out;
}

@keyframes ctilh-sheet-in {
	from {
		opacity: 0;
		transform: translateY(.5rem);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ctilh-sheet[open] {
		animation: none;
	}
}

html:has(.ctilh-sheet[open]) {
	overflow: hidden;
}

.ctilh-sheet__inner {
	padding: 0 1rem 1rem;
}

.ctilh-sheet__bar {
	display: flex;
	justify-content: flex-end;
	padding: .5rem 0;
}

.ctilh-sheet__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	border: 1px solid currentColor;
	border-radius: var(--ctilh-radius);
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}

.ctilh-sheet .ctilh-result {
	margin: 0;
	padding: 0;
	border: 0;
}

.ctilh-sheet .ctilh-result__img {
	max-height: 60vh;
	object-fit: contain;
}
