/**
 * Valhalla Pro — GIF Picker (front end).
 *
 * Colors come from the Vikinger custom properties (--color-*) with fallbacks for other themes,
 * sizes from the theme's font formula; breakpoints follow the theme (680 / 480).
 * Sections: 1 buttons in the theme forms · 2 inline GIFs in posts and comments · 3 picker ·
 * 4 small screens · 5 reduced motion.
 */

/* 1. Buttons in the theme forms --------------------------------------------------------------- */

.quick-post .quick-post-footer .vhl-gif-trigger-post {
	display: flex;
	align-items: center;
	border-radius: 6px;
	outline: none;
}

.quick-post .quick-post-footer .vhl-gif-trigger-post .quick-post-footer-action-icon {
	width: 20px;
	height: 20px;
	fill: var(--color-icon, #adafca);
}

.quick-post .quick-post-footer .vhl-gif-trigger-post:hover .quick-post-footer-action-icon,
.quick-post .quick-post-footer .vhl-gif-trigger-post:focus-visible .quick-post-footer-action-icon {
	fill: var(--color-icon-highlighted, #615dfa);
}

.quick-post .quick-post-footer .vhl-gif-trigger-post:focus-visible {
	box-shadow: 0 0 0 2px var(--color-box-background, #fff), 0 0 0 4px var(--color-secondary, #615dfa);
}

.vhl-gif-trigger-text {
	display: none;
	padding: 0 6px;
	border: 1px solid currentColor;
	border-radius: 5px;
	color: var(--color-icon, #adafca);
	font-size: calc((11 / var(--vikinger-font-size-base, 16)) * 1rem);
	font-weight: 700;
	line-height: 16px;
	letter-spacing: .04em;
}

.vhl-gif-trigger.no-sprite .vhl-gif-trigger-text {
	display: inline-block;
}

.vhl-gif-trigger.no-sprite .vhl-gif-trigger-icon {
	display: none;
}

.vhl-gif-trigger.no-sprite:hover .vhl-gif-trigger-text {
	color: var(--color-icon-highlighted, #615dfa);
}

.vhl-gif-trigger.is-disabled {
	opacity: .4;
	cursor: default;
	pointer-events: none;
}

/* Comment forms: a small pill at the start of the textarea footer, left of the counter. */
.form-textarea-footer > .vhl-gif-trigger-comment {
	display: inline-flex;
	align-items: center;
	flex: 0 0 auto;
	width: auto;
	height: 20px;
	min-height: 0;
	margin: 2px auto 0 14px;
	padding: 0;
	border: 0;
	border-radius: 6px;
	background: transparent;
	box-shadow: none;
	/* Body text color: the theme's lighter grey would leave this small label below 4.5:1. */
	color: var(--color-text, #3e3f5e);
	font-family: var(--vikinger-font-family-primary, inherit);
	cursor: pointer;
	outline: none;
}

.vhl-gif-pill {
	display: inline-block;
	padding: 0 6px;
	border: 1px solid var(--color-border, #dedeea);
	border-radius: 5px;
	font-size: calc((10 / var(--vikinger-font-size-base, 16)) * 1rem);
	font-weight: 700;
	line-height: 16px;
	letter-spacing: .05em;
	transition: color .2s ease-in-out, border-color .2s ease-in-out;
}

.form-textarea-footer > .vhl-gif-trigger-comment:hover,
.form-textarea-footer > .vhl-gif-trigger-comment:focus-visible {
	color: var(--color-secondary, #615dfa);
}

.form-textarea-footer > .vhl-gif-trigger-comment:hover .vhl-gif-pill,
.form-textarea-footer > .vhl-gif-trigger-comment:focus-visible .vhl-gif-pill {
	border-color: var(--color-secondary, #615dfa);
}

.form-textarea-footer > .vhl-gif-trigger-comment:focus-visible .vhl-gif-pill {
	box-shadow: 0 0 0 2px var(--color-box-background, #fff), 0 0 0 4px var(--color-secondary, #615dfa);
}

/* 2. Inline GIFs in posts and comments -------------------------------------------------------- */

.vhl-gif-embed {
	display: block;
	max-width: 100%;
	margin: 12px 0;
	line-height: 0;
}

br.vhl-gif-gap {
	display: none;
}

.vhl-gif-embed:first-child {
	margin-top: 4px;
}

.vhl-gif-embed:last-child {
	margin-bottom: 4px;
}

.vhl-gif-link {
	display: inline-block;
	max-width: 100%;
	border-radius: 12px;
	overflow: hidden;
	background-color: var(--color-box-background-alt, #f8f8fb);
	vertical-align: top;
}

.vhl-gif-link:focus-visible {
	outline: 3px solid var(--color-secondary, #615dfa);
	outline-offset: 2px;
}

.vhl-gif-media {
	display: block;
	width: auto;
	max-width: 100%;
	height: auto;
	max-height: 360px;
}

.vhl-gif-video {
	border-radius: 12px;
	background-color: var(--color-box-background-alt, #f8f8fb);
}

.vhl-gif-embed.is-image:not(.is-loaded) .vhl-gif-link {
	min-width: 160px;
	min-height: 120px;
	background-image: linear-gradient(90deg, transparent 0%, var(--color-box-highlight-background, #f7f7fb) 50%, transparent 100%);
	background-repeat: no-repeat;
	background-size: 60% 100%;
	animation: vhl-gif-shimmer 1.4s ease-in-out infinite;
}

.post-comment-text-content .vhl-gif-media {
	max-height: 220px;
}

.post-comment-text-content .vhl-gif-embed {
	margin: 8px 0;
}

.vhl-gif-play {
	display: inline-flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 10px;
	width: auto;
	max-width: 100%;
	min-height: 48px;
	padding: 10px 16px;
	border: 1px dashed var(--color-border, #dedeea);
	border-radius: 12px;
	background-color: var(--color-box-background-alt, #f8f8fb);
	color: var(--color-text, #3e3f5e);
	font-family: var(--vikinger-font-family-primary, inherit);
	font-size: calc((14 / var(--vikinger-font-size-base, 16)) * 1rem);
	font-weight: 700;
	line-height: 1.3;
	text-align: left;
	cursor: pointer;
	transition: border-color .2s ease-in-out;
}

.vhl-gif-play:hover,
.vhl-gif-play:focus-visible {
	border-color: var(--color-secondary, #615dfa);
	outline: none;
}

.vhl-gif-play-badge {
	padding: 2px 6px;
	border-radius: 5px;
	background-color: var(--color-secondary, #615dfa);
	color: #fff;
	font-size: calc((11 / var(--vikinger-font-size-base, 16)) * 1rem);
	letter-spacing: .04em;
}

.vhl-gif-play-note {
	color: var(--color-text-alt, #8f91ac);
	font-size: calc((12 / var(--vikinger-font-size-base, 16)) * 1rem);
	font-weight: 500;
}

@keyframes vhl-gif-shimmer {
	0% { background-position: -150% 0; }
	100% { background-position: 250% 0; }
}

/* 3. Picker --------------------------------------------------------------------------------- */

.vhl-gif-modal .vhl-modal-box {
	padding-bottom: 22px;
}

.vhl-gif-modal .vhl-modal-title + .vhl-modal-body {
	margin-top: 22px;
}

.vhl-gif-picker {
	display: flex;
	flex-direction: column;
	gap: 14px;
	min-width: 0;
}

.vhl-gif-picker > * + * {
	margin-top: 0 !important;
}

.vhl-gif-search {
	margin: 0;
}

.vhl-gif-search-field {
	position: relative;
}

.vhl-gif-search-field .vhl-gif-search-input {
	width: 100%;
	height: 48px;
	padding: 0 52px 0 18px;
	font-size: calc((14 / var(--vikinger-font-size-base, 16)) * 1rem);
	-webkit-appearance: none;
	appearance: none;
}

.vhl-gif-search-input::-webkit-search-cancel-button,
.vhl-gif-search-input::-webkit-search-decoration {
	-webkit-appearance: none;
	display: none;
}

.vhl-gif-search-input::placeholder {
	color: var(--color-text-alt-2, #adafca);
	font-weight: 500;
}

.vhl-gif-search-field .interactive-input-icon-wrap {
	width: 52px;
}

.vhl-gif-search-field .interactive-input-icon {
	width: 20px;
	height: 20px;
}

.vhl-gif-search-field.has-value .interactive-input-icon-wrap {
	display: none;
}

.vhl-gif-clear {
	display: flex;
	justify-content: center;
	align-items: center;
	width: 52px;
	height: 100%;
	padding: 0;
	border: 0;
	border-radius: 0 12px 12px 0;
	position: absolute;
	top: 0;
	right: 0;
	background: transparent;
	color: var(--color-icon, #adafca);
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
}

.vhl-gif-clear[hidden] {
	display: none;
}

.vhl-gif-clear-icon {
	width: 12px;
	height: 12px;
	fill: var(--color-icon, #adafca);
	transition: fill .2s ease-in-out;
}

.vhl-gif-clear:hover .vhl-gif-clear-icon,
.vhl-gif-clear:focus-visible .vhl-gif-clear-icon {
	fill: var(--color-text, #3e3f5e);
}

.vhl-gif-clear:focus-visible {
	outline: 2px solid var(--color-secondary, #615dfa);
	outline-offset: -4px;
}

.vhl-gif-clear-fallback,
.vhl-gif-fav-fallback {
	display: none;
}

.vhl-gif-picker.no-sprite .vhl-gif-clear-fallback,
.vhl-gif-picker.no-sprite .vhl-gif-fav-fallback {
	display: inline;
}

.vhl-gif-picker.no-sprite .vhl-gif-clear-icon,
.vhl-gif-picker.no-sprite .vhl-gif-fav-icon,
.vhl-gif-picker.no-sprite .vhl-gif-chip-icon {
	display: none;
}

.vhl-gif-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0 -4px;
	padding: 2px 4px 4px;
	overflow-x: auto;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.vhl-gif-bar::-webkit-scrollbar {
	display: none;
}

.vhl-gif-bar.has-overflow:not(.is-end) {
	-webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
	mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
}

[dir="rtl"] .vhl-gif-bar.has-overflow:not(.is-end) {
	-webkit-mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent);
	mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent);
}

.vhl-gif-chips {
	display: flex;
	flex: 0 0 auto;
	gap: 8px;
}

.vhl-gif-terms {
	padding-left: 10px;
	border-left: 1px solid var(--color-divider, #eaeaf5);
}

.vhl-gif-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	width: auto;
	height: 32px;
	margin: 0;
	padding: 0 14px;
	border: 1px solid var(--color-border, #dedeea);
	border-radius: 200px;
	background-color: var(--color-box-background, #fff);
	box-shadow: none;
	color: var(--color-text-alt, #8f91ac);
	font-family: var(--vikinger-font-family-primary, inherit);
	font-size: calc((12 / var(--vikinger-font-size-base, 16)) * 1rem);
	font-weight: 700;
	line-height: 1;
	white-space: nowrap;
	cursor: pointer;
	transition: color .2s ease-in-out, border-color .2s ease-in-out, background-color .2s ease-in-out;
}

.vhl-gif-chip:hover {
	border-color: var(--color-secondary, #615dfa);
	color: var(--color-text, #3e3f5e);
}

.vhl-gif-chip:focus-visible {
	outline: 2px solid var(--color-secondary, #615dfa);
	outline-offset: 2px;
}

.vhl-gif-chip.is-active {
	border-color: var(--color-secondary, #615dfa);
	background-color: var(--color-secondary, #615dfa);
	color: #fff;
}

.vhl-gif-chip-icon {
	width: 10px;
	height: 10px;
	fill: currentColor;
}

.vhl-gif-scroll {
	position: relative;
	height: min(56vh, 460px);
	margin: 0 -4px;
	padding: 4px;
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: var(--color-divider, #eaeaf5) transparent;
}

.vhl-gif-grid {
	display: flex;
	align-items: flex-start;
	gap: 8px;
}

.vhl-gif-col {
	display: flex;
	flex: 1 1 0;
	flex-direction: column;
	gap: 8px;
	min-width: 0;
}

.vhl-gif-cell {
	position: relative;
	border-radius: 10px;
}

.vhl-gif-item {
	display: block;
	position: relative;
	width: 100%;
	height: 0;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 10px;
	background-color: var(--color-box-background-alt, #f8f8fb);
	box-shadow: none;
	overflow: hidden;
	cursor: pointer;
	outline: none;
}

.vhl-gif-thumb {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 0;
	transition: opacity .25s ease-in-out, transform .3s ease-out;
}

.vhl-gif-cell.is-loaded .vhl-gif-thumb {
	opacity: 1;
}

.vhl-gif-cell.is-broken .vhl-gif-thumb {
	display: none;
}

.vhl-gif-item:hover .vhl-gif-thumb {
	transform: scale(1.04);
}

.vhl-gif-item::after {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: inherit;
	box-shadow: inset 0 0 0 3px transparent;
	transition: box-shadow .15s ease-in-out;
	pointer-events: none;
}

.vhl-gif-item:focus-visible::after {
	box-shadow: inset 0 0 0 3px var(--color-secondary, #615dfa), inset 0 0 0 5px var(--color-box-background, #fff);
}

.vhl-gif-fav {
	display: flex;
	justify-content: center;
	align-items: center;
	width: 28px;
	height: 28px;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	position: absolute;
	top: 6px;
	right: 6px;
	z-index: 1;
	background-color: rgba(21, 21, 31, .55);
	box-shadow: none;
	color: #fff;
	font-size: 14px;
	line-height: 1;
	opacity: 0;
	cursor: pointer;
	transition: opacity .2s ease-in-out, background-color .2s ease-in-out, transform .15s ease-out;
}

.vhl-gif-cell:hover .vhl-gif-fav,
.vhl-gif-cell:focus-within .vhl-gif-fav,
.vhl-gif-fav.is-active {
	opacity: 1;
}

.vhl-gif-fav:hover {
	background-color: rgba(21, 21, 31, .75);
}

.vhl-gif-fav:active {
	transform: scale(.92);
}

.vhl-gif-fav-icon {
	width: 13px;
	height: 12px;
	fill: #fff;
}

.vhl-gif-fav.is-active .vhl-gif-fav-icon {
	fill: var(--color-primary, #23d2e2);
}

.vhl-gif-fav.is-active .vhl-gif-fav-fallback {
	color: var(--color-primary, #23d2e2);
}

@media (hover: none) {
	.vhl-gif-fav {
		opacity: .9;
	}
}

.vhl-gif-skel {
	border-radius: 10px;
	background-color: var(--color-box-background-alt, #f8f8fb);
	background-image: linear-gradient(90deg, transparent 0%, var(--color-box-highlight-background, #f0f0f7) 50%, transparent 100%);
	background-repeat: no-repeat;
	background-size: 60% 100%;
	animation: vhl-gif-shimmer 1.4s ease-in-out infinite;
}

.vhl-gif-status {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 14px;
	padding: 18px 12px 6px;
	color: var(--color-text, #3e3f5e);
	font-size: calc((14 / var(--vikinger-font-size-base, 16)) * 1rem);
	font-weight: 500;
	line-height: 1.5;
	text-align: center;
}

.vhl-gif-status:empty {
	display: none;
}

.vhl-gif-status.is-error .vhl-gif-status-text {
	font-weight: 700;
}

.vhl-gif-retry.button {
	width: auto;
	min-width: 120px;
	padding: 0 20px;
	cursor: pointer;
}

.vhl-gif-sentinel {
	height: 1px;
}

.vhl-gif-footer {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 8px 16px;
	padding-top: 12px;
	border-top: 1px solid var(--color-divider, #eaeaf5);
	color: var(--color-text-alt, #8f91ac);
	font-size: calc((12 / var(--vikinger-font-size-base, 16)) * 1rem);
	font-weight: 500;
	line-height: 1.4;
}

.vhl-gif-attribution {
	margin-left: auto;
	color: var(--color-text, #3e3f5e);
	font-weight: 700;
	letter-spacing: .02em;
	text-decoration: none;
}

a.vhl-gif-attribution:hover,
a.vhl-gif-attribution:focus-visible {
	color: var(--color-primary, #23d2e2);
}

/* 4. Small screens (the modal becomes a bottom sheet at 680px) ---------------------------------- */

@media screen and (max-width: 680px) {
	.vhl-gif-scroll {
		height: 52vh;
	}

	.vhl-gif-help {
		display: none;
	}

	.vhl-gif-attribution {
		margin: 0 auto;
	}
}

@media screen and (max-width: 480px) {
	.vhl-gif-media {
		max-height: 300px;
	}

	.vhl-gif-chip {
		height: 30px;
		padding: 0 12px;
	}
}

@media (hover: none) and (pointer: coarse) {
	.vhl-gif-help {
		display: none;
	}
}

/* 5. Reduced motion ---------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.vhl-gif-skel,
	.vhl-gif-embed.is-image:not(.is-loaded) .vhl-gif-link {
		animation: none;
	}

	.vhl-gif-thumb,
	.vhl-gif-fav,
	.vhl-gif-chip {
		transition-duration: .01ms;
	}

	.vhl-gif-item:hover .vhl-gif-thumb {
		transform: none;
	}
}
