/**
 * IPS Social Flip Button - frontend styles.
 *
 * NO !important anywhere in this file, deliberately. Elementor emits widget
 * control CSS as "{{WRAPPER}} .ips-sfb" (specificity 0,2,0) while the rules
 * here are mostly 0,1,0, so a single !important would outrank every control
 * and they would all silently stop working.
 *
 * Every control writes a CSS custom property onto .ips-sfb rather than a
 * competing declaration, so the controls and this file never fight: this file
 * only ever READS the variables, with a fallback for each.
 *
 * There is no JavaScript. The flip is a transform, the stagger is a
 * transition-delay multiplied by a per-item --ips-sfb-i index emitted at
 * render time, the tooltip is a hover state and the sweep is a keyframe.
 */

.ips-sfb {
	--ips-sfb-size: 40px;
	--ips-sfb-gap: 8px;
	--ips-sfb-radius: 8px;
	--ips-sfb-duration: 700ms;
	--ips-sfb-stagger: 80ms;
	--ips-sfb-front-bg: #f5f5f5;
	--ips-sfb-front-color: #262626;
	--ips-sfb-back-bg: #000000;
	--ips-sfb-back-color: #ffffff;
	--ips-sfb-icon-size: 18px;
	--ips-sfb-icon-nudge: 0px;
	--ips-sfb-line-color: rgba(0, 0, 0, 0.65);
	--ips-sfb-line-thickness: 2px;
	--ips-sfb-sweep-duration: 2.5s;
	--ips-sfb-tip-bg: #171717;
	--ips-sfb-tip-color: #ffffff;
	--ips-sfb-tip-offset: 10px;

	display: flex;
	align-items: center;
	justify-content: center;
}

.ips-sfb__group {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--ips-sfb-gap);
}

/* ---------------------------------------------------------------- */
/* Sweeping border lines                                             */
/* ---------------------------------------------------------------- */

.ips-sfb__lines {
	position: absolute;
	inset: -1px;
	overflow: hidden;
	border-radius: inherit;
	pointer-events: none;
}

/*
 * The gradient HOLDS its colour from 20% to 80% rather than peaking at a single
 * point. The original faded transparent -> colour -> transparent with the peak only
 * at the centre, which at 1px on a white page read as a smudge rather than a line
 * and was easy to miss entirely.
 */
.ips-sfb__line {
	position: absolute;
	left: 0;
	width: 100%;
	height: var(--ips-sfb-line-thickness);
	border-radius: var(--ips-sfb-line-thickness);
	background-image: linear-gradient(
		to right,
		transparent 0%,
		var(--ips-sfb-line-color) 20%,
		var(--ips-sfb-line-color) 80%,
		transparent 100%
	);
}

.ips-sfb__line--top {
	top: 0;
	animation: ips-sfb-sweep-right var(--ips-sfb-sweep-duration) linear infinite;
}

.ips-sfb__line--bottom {
	bottom: 0;
	animation: ips-sfb-sweep-left var(--ips-sfb-sweep-duration) linear infinite;
}

@keyframes ips-sfb-sweep-right {
	from { transform: translateX(-100%); }
	to   { transform: translateX(100%); }
}

@keyframes ips-sfb-sweep-left {
	from { transform: translateX(100%); }
	to   { transform: translateX(-100%); }
}

/* ---------------------------------------------------------------- */
/* The cards                                                         */
/* ---------------------------------------------------------------- */

.ips-sfb__item {
	position: relative;
	display: block;
	width: var(--ips-sfb-size);
	height: var(--ips-sfb-size);
	flex: 0 0 auto;
	perspective: 1000px;
	cursor: pointer;
	text-decoration: none;
}

.ips-sfb__card {
	position: relative;
	display: block;
	width: 100%;
	height: 100%;
	z-index: 1;
	transform-style: preserve-3d;
	transition: transform var(--ips-sfb-duration) cubic-bezier(0.22, 1, 0.36, 1);
	transition-delay: calc(var(--ips-sfb-i, 0) * var(--ips-sfb-stagger));
}

.ips-sfb__face {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	/*
	 * border-box so the Border controls added in 1.1.0 eat into the face rather
	 * than growing it. Not left to a theme reset: this widget ships onto whatever
	 * site installs it.
	 */
	box-sizing: border-box;
	border-radius: var(--ips-sfb-radius);
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
	line-height: 1;
}

.ips-sfb__face--front {
	background-color: var(--ips-sfb-front-bg);
	color: var(--ips-sfb-front-color);
	font-weight: 700;
}

.ips-sfb__face--back {
	background-color: var(--ips-sfb-back-bg);
	color: var(--ips-sfb-back-color);
	font-size: var(--ips-sfb-icon-size);
	transform: rotateY(180deg);
}

/*
 * Elementor's e_font_icon_svg experiment is active on these sites, so
 * Icons_Manager renders an inline <svg>, not an <i>. font-size alone would not
 * size an SVG, so pin it to 1em and let the font-size above drive both forms.
 *
 * The nudge is applied to the ICON, never to the face: the back face already
 * carries `transform: rotateY(180deg)` and overwriting that would un-flip it.
 * Default 0, so this changes nothing until someone asks for it.
 */
.ips-sfb__face--back svg {
	width: 1em;
	height: 1em;
	fill: currentColor;
	transform: translateY(var(--ips-sfb-icon-nudge));
}

.ips-sfb__face--back i {
	font-size: inherit;
	line-height: 1;
	transform: translateY(var(--ips-sfb-icon-nudge));
}

/* ---------------------------------------------------------------- */
/* Flip triggers                                                     */
/* ---------------------------------------------------------------- */

.ips-sfb--trigger-group .ips-sfb__group:hover .ips-sfb__card {
	transform: rotateY(180deg);
}

.ips-sfb--trigger-group .ips-sfb__group:focus-within .ips-sfb__card {
	transform: rotateY(180deg);
}

/* Per-item mode ignores the stagger: only the hovered card moves. */
.ips-sfb--trigger-item .ips-sfb__item:hover .ips-sfb__card,
.ips-sfb--trigger-item .ips-sfb__item:focus-within .ips-sfb__card {
	transform: rotateY(180deg);
	transition-delay: 0s;
}

/*
 * Autoplay when fully in view (1.3.0). The script only adds and removes this class;
 * the ripple out AND the ripple back come from the same transition-delay the hover
 * uses, which is why no keyframes are needed and why it automatically respects the
 * client's own duration and stagger settings.
 */
.ips-sfb.is-autoplaying .ips-sfb__card {
	transform: rotateY(180deg);
}

/*
 * Touch devices have no hover, so `.is-revealed` (added by the one script in this
 * plugin on the first tap) stands in for it. Scoped to (hover: none) so it can never
 * affect a desktop, where the :hover rules above are what run.
 */
@media (hover: none) {
	.ips-sfb--trigger-group.is-revealed .ips-sfb__card {
		transform: rotateY(180deg);
	}

	.ips-sfb--trigger-item .ips-sfb__item.is-revealed .ips-sfb__card {
		transform: rotateY(180deg);
		transition-delay: 0s;
	}
}

/* ---------------------------------------------------------------- */
/* Tooltip                                                           */
/* ---------------------------------------------------------------- */

/*
 * This is hidden until hover, which normally needs an Elementor editor
 * exception. It deliberately has none: .ips-sfb__tip is internal markup of this
 * widget, not an element the client can select on the canvas, and its text is
 * edited through the repeater's "Label" field in the panel. Revealing every
 * tooltip at once inside the editor would stack seven overlapping labels and
 * make the widget harder to edit, not easier.
 */
.ips-sfb__tip {
	position: absolute;
	left: 50%;
	bottom: calc(100% + var(--ips-sfb-tip-offset));
	z-index: 10;
	padding: 6px 10px;
	border-radius: 8px;
	background-color: var(--ips-sfb-tip-bg);
	color: var(--ips-sfb-tip-color);
	font-size: 12px;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transform: translateX(-50%) translateY(6px) scale(0.9);
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.ips-sfb__item:hover .ips-sfb__tip,
.ips-sfb__item:focus-visible .ips-sfb__tip {
	opacity: 1;
	visibility: visible;
	transform: translateX(-50%) translateY(0) scale(1);
}

.ips-sfb__tip-arrow {
	position: absolute;
	left: 50%;
	bottom: -3px;
	width: 8px;
	height: 8px;
	background-color: var(--ips-sfb-tip-bg);
	transform: translateX(-50%) rotate(45deg);
}

/* ---------------------------------------------------------------- */
/* Accessibility                                                     */
/* ---------------------------------------------------------------- */

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

@media (prefers-reduced-motion: reduce) {
	.ips-sfb__card {
		transition-duration: 1ms;
		transition-delay: 0s;
	}

	.ips-sfb__line {
		animation: none;
	}

	.ips-sfb__tip {
		transition: none;
	}
}
