.rui-rui-launch {
	position: fixed;
	right: calc(22px + env(safe-area-inset-right));
	bottom: calc(16px + env(safe-area-inset-bottom));
	z-index: 9999;
	display: grid;
	justify-items: center;
	padding: 0;
	border: 0;
	border-radius: 22px;
	background: transparent;
	cursor: pointer;
	font: inherit;
	-webkit-tap-highlight-color: transparent;
}

.rui-rui-launch[hidden], .rui-rui-chat:not([open]) { display: none; }

/* Apply the shadow after masking the image so it can extend past its edges. */
.rui-rui-art {
	position: relative;
	filter: drop-shadow(0 3px 10px rgba(46, 32, 73, .24));
	transition: transform .2s ease-out;
}

.rui-rui-art img {
	display: block;
	width: 98px;
	height: auto;
	mask-image: linear-gradient(#000 86%, transparent 100%);
}

.rui-rui-launch:hover .rui-rui-art { transform: translateY(-3px); }

.rui-rui-art .rui-rui-paw {
	display: none;
	position: absolute;
	inset: 0;
	mask-image: none;
}

@media (prefers-reduced-motion: no-preference) {
	/* Both layers use the same portrait. Keep the cuff in front of the moving wrist. */
	.rui-rui-art.is-waving {
		transform-origin: 50% 90%;
		animation: rui-rui-greet 1.9s ease-in-out;
	}

	.rui-rui-art.is-waving img:first-child {
		position: relative;
		z-index: 1;
		clip-path: polygon(0 0, 100% 0, 100% 58.1%, 83% 58.1%, 81% 60.6%, 78.5% 62.8%,
			74.7% 64.7%, 76.4% 68.9%, 78.1% 71.8%, 79.5% 74%, 82.6% 76.2%,
			86% 77.6%, 89.6% 78.6%, 89.6% 74%, 90% 72.4%, 100% 72.4%, 100% 100%, 0 100%);
	}

	.rui-rui-art.is-waving .rui-rui-paw {
		display: block;
		clip-path: polygon(100% 58.1%, 83% 58.1%, 81% 60.6%, 78.5% 62.8%, 74.7% 64.7%,
			76.4% 68.9%, 77.1% 72.8%, 79.5% 76.2%, 83.4% 79.2%, 88% 81%,
			91% 81%, 91% 74%, 100% 73%);
		transform-origin: 84.2% 75%;
		animation: rui-rui-wave 1.9s ease-in-out;
	}
}

@keyframes rui-rui-greet {
	0%, 100% { transform: none; }
	23%, 57% { transform: translateY(-2px) rotate(-1deg); }
	40%, 73% { transform: translateY(-1px); }
}

@keyframes rui-rui-wave {
	0%, 100% { transform: none; }
	22%, 58% { transform: rotate(14deg); }
	40%, 74% { transform: rotate(-8deg); }
}

.rui-rui-label {
	position: relative;
	margin-top: -12px;
	padding: 6px 10px;
	border: 1px solid rgba(255, 255, 255, .65);
	border-radius: 20px;
	background: var(--c-primary-dark);
	color: #fff;
	font-size: 13px;
	font-weight: 700;
	line-height: 1.35;
	white-space: nowrap;
	box-shadow: 0 3px 12px rgba(46, 32, 73, .2);
}

.rui-rui-label small { margin-inline-start: 3px; color: #e7d9f7; font-size: 11px; }

body:has(.rui-rui-launch:not([hidden])) #fcp-root { bottom: calc(185px + env(safe-area-inset-bottom)); }

.rui-rui-chat {
	position: fixed;
	inset: 0;
	display: grid;
	grid-template-rows: auto minmax(0, 1fr);
	width: min(460px, calc(100vw - 32px));
	height: min(720px, calc(100dvh - 40px));
	margin: auto;
	padding: 0;
	border: 1px solid var(--c-border);
	border-radius: 20px;
	background: #fff;
	color: var(--c-primary-dark);
	box-shadow: 0 16px 55px rgba(46, 32, 73, .22);
	overflow: hidden;
}

.rui-rui-chat::backdrop { background: rgba(26, 18, 43, .32); }
.rui-rui-chat:modal[open] { animation: rui-rui-panel-in .2s ease-out both; }
html:has(.rui-rui-chat:modal) { overflow: hidden; }

@media (min-width: 900px) {
	.rui-rui-chat.is-docked {
		--rui-rui-panel-top: 0px;
		inset: var(--rui-rui-panel-top) 0 0 auto;
		z-index: 10000;
		width: min(440px, 100vw);
		height: calc(100dvh - var(--rui-rui-panel-top));
		max-height: none;
		margin: 0;
		border-width: 0 0 0 1px;
		border-radius: 0;
		box-shadow: -12px 0 36px rgba(46, 32, 73, .16);
	}
	.admin-bar .rui-rui-chat.is-docked { --rui-rui-panel-top: 32px; }
	.rui-rui-chat.is-docked[open] { animation: rui-rui-dock-in .28s ease-out both; }
	body:has(.rui-rui-chat.is-docked[open]) :is(.rui-rui-launch, #fcp-root) { visibility: hidden; }
}

@keyframes rui-rui-panel-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rui-rui-dock-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

.rui-rui-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--c-border);
	background: #fff;
}

.rui-rui-avatar { width: 42px; height: 42px; flex: none; border-radius: 50%; background: var(--c-accent-soft); object-fit: cover; object-position: 50% 70%; }
.rui-rui-identity { flex: 1; min-width: 0; }
.rui-rui-identity h2 { margin: 0; font: 750 17px/1.35 var(--font-sans); }
.rui-rui-identity span { color: var(--c-text-light); font-size: 12px; }
.rui-rui-header button {
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font: 30px/1 var(--font-sans);
	cursor: pointer;
}

.rui-rui-header button:hover { background: var(--c-accent-soft); }
.rui-rui-launch:focus-visible, .rui-rui-header :focus-visible { outline: 3px solid var(--c-accent); outline-offset: 2px; }
.rui-rui-chat iframe { display: block; width: 100%; height: 100%; border: 0; }

@media (max-width: 600px) {
	.rui-rui-launch { right: calc(14px + env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom)); }
	.rui-rui-art img { width: 80px; }
	body:has(.rui-rui-launch:not([hidden])) #fcp-root { bottom: calc(152px + env(safe-area-inset-bottom)); }
	.rui-rui-chat { inset: 0; width: 100%; height: 100dvh; max-width: none; max-height: none; border: 0; border-radius: 0; }
	.rui-rui-header { padding-top: max(12px, env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
	.rui-rui-art { transition: none; }
	.rui-rui-launch:hover .rui-rui-art { transform: none; }
	.rui-rui-chat:is(.is-docked, :modal)[open] { animation: none; }
}
