/* Spindle Dynamic Glossary: inline terms, tooltips, info box, modal.
   Colours come from --sdg-bg / --sdg-text / --sdg-title (set from the settings). */

.sdg-term-wrap {
	position: relative;
	display: inline;
}

/* Highlighted term */
.sdg-inline-term {
	color: inherit;
	font-weight: 500;
	text-decoration: underline dotted;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
	cursor: pointer;
}
.sdg-inline-term:hover {
	text-decoration-style: solid;
}
.sdg-inline-term:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 2px;
}

/* Tooltip */
/* Hidden tooltips use display:none so they never widen the page (horizontal scroll on phones). */
.sdg-inline-tooltip {
	display: none;
	position: absolute;
	z-index: 9999;
	width: 260px;
	max-width: calc(100vw - 16px);
	box-sizing: border-box;
	background-color: var(--sdg-bg, #1f2937);
	color: var(--sdg-text, #ffffff);
	padding: 12px 15px;
	border-radius: 6px;
	font-size: 14px;
	font-weight: 400;
	font-style: normal;
	line-height: 1.5;
	text-align: left;
	text-transform: none;
	letter-spacing: normal;
	white-space: normal;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
	font-family: var(--sdg-font, inherit);
	animation: sdg-fade-in 0.15s ease;
}
@keyframes sdg-fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}
.sdg-tt-title {
	display: block;
	margin-bottom: 6px;
	color: var(--sdg-title, #fcd34d);
	font-size: 15px;
}
.sdg-tt-text {
	display: block;
}

@media (min-width: 769px) {
	/* Visible while the term or the tooltip is hovered, or the link has keyboard focus
	   (not after a mouse click, so it never lingers over the text). */
	.sdg-term-wrap[data-desktop="default"]:hover .sdg-inline-tooltip,
	.sdg-term-wrap[data-desktop="default"] .sdg-inline-term:focus-visible + .sdg-inline-tooltip {
		display: block;
	}
	.sdg-term-wrap.sdg-tt-dismissed .sdg-inline-tooltip {
		display: none !important;
	}

	/* An invisible bridge so the pointer can move from the term onto the tooltip. */
	.sdg-inline-tooltip::before {
		content: "";
		position: absolute;
	}

	.sdg-term-wrap[data-pos="bottom"] .sdg-inline-tooltip {
		top: calc(100% + 8px);
		left: 50%;
		transform: translateX(calc(-50% + var(--sdg-tt-shift, 0px)));
	}
	.sdg-term-wrap[data-pos="bottom"] .sdg-inline-tooltip::before {
		left: 0;
		right: 0;
		bottom: 100%;
		height: 10px;
	}
	.sdg-term-wrap[data-pos="bottom"].sdg-tt-above .sdg-inline-tooltip {
		top: auto;
		bottom: calc(100% + 8px);
	}
	.sdg-term-wrap[data-pos="bottom"].sdg-tt-above .sdg-inline-tooltip::before {
		bottom: auto;
		top: 100%;
	}

	.sdg-term-wrap[data-pos="right"] .sdg-inline-tooltip {
		top: 50%;
		left: calc(100% + 10px);
		transform: translateY(-50%);
	}
	.sdg-term-wrap[data-pos="right"] .sdg-inline-tooltip::before {
		top: 0;
		bottom: 0;
		right: 100%;
		width: 12px;
	}

	.sdg-term-wrap[data-pos="left"] .sdg-inline-tooltip {
		top: 50%;
		right: calc(100% + 10px);
		transform: translateY(-50%);
	}
	.sdg-term-wrap[data-pos="left"] .sdg-inline-tooltip::before {
		top: 0;
		bottom: 0;
		left: 100%;
		width: 12px;
	}
}

/* Box method (desktop and mobile): a fixed info box in the corner. */
.sdg-term-wrap.sdg-box-active .sdg-inline-tooltip {
	display: block;
	position: fixed;
	top: auto;
	left: auto;
	bottom: 20px;
	right: 20px;
	width: 300px;
	max-width: calc(100vw - 40px);
	transform: none;
}
.sdg-term-wrap.sdg-box-active .sdg-inline-tooltip::before {
	content: none;
}

@media (prefers-reduced-motion: reduce) {
	.sdg-inline-tooltip,
	.sdg-modal-container {
		transition: none;
		animation: none;
	}
}

/* Modal (shared by inline terms and the glossary grid) */
html.sdg-modal-open,
html.sdg-modal-open body {
	overflow: hidden;
}
.sdg-modal-viewport {
	display: none;
	position: fixed;
	z-index: 999999;
	inset: 0;
	overflow: auto;
	padding: 16px;
	box-sizing: border-box;
	background-color: rgba(17, 24, 39, 0.6);
	backdrop-filter: blur(4px);
}
.sdg-modal-viewport.sdg-active {
	display: flex;
	align-items: center;
	justify-content: center;
}
.sdg-modal-container {
	position: relative;
	box-sizing: border-box;
	width: 100%;
	max-width: 650px;
	max-height: calc(100vh - 32px);
	overflow: auto;
	padding: 32px;
	border-radius: 12px;
	background-color: #ffffff;
	color: #1f2937;
	box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
	text-align: left;
	text-transform: none;
	font-family: var(--sdg-font, inherit);
	animation: sdg-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.sdg-modal-container:focus {
	outline: none;
}
.sdg-modal-title {
	margin: 0 40px 0 0;
	color: #111827;
}
.sdg-modal-body > :last-child {
	margin-bottom: 0;
}
.sdg-modal-more {
	margin: 20px 0 0;
	font-size: 14px;
}
.sdg-modal-more a {
	color: #1d4ed8;
}
.sdg-modal-dismiss-btn {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 40px;
	height: 40px;
	padding: 0;
	border: none;
	border-radius: 6px;
	background: none;
	color: #4b5563;
	font-size: 28px;
	line-height: 1;
	cursor: pointer;
}
.sdg-modal-dismiss-btn:hover {
	color: #111827;
	background: #f3f4f6;
}
.sdg-modal-dismiss-btn:focus-visible {
	outline: 2px solid #1d4ed8;
	outline-offset: 2px;
}
@keyframes sdg-slide-up {
	from {
		transform: translateY(15px);
		opacity: 0;
	}
	to {
		transform: translateY(0);
		opacity: 1;
	}
}
