/**
 * QSM Fill in the Blanks — стили виджета на фронтенде.
 * Все селекторы ограничены префиксом .qsm-fb, чтобы не конфликтовать с темами.
 */

.qsm-fb {
	--qsm-fb-accent: #4f6df5;
	--qsm-fb-accent-soft: #eef1ff;
	--qsm-fb-accent-glow: rgba(79, 109, 245, 0.28);
	--qsm-fb-border: #d7dce8;
	--qsm-fb-text: #2c3247;
	--qsm-fb-muted: #7a819c;
	--qsm-fb-correct-bg: #e8f7ee;
	--qsm-fb-correct-fg: #1e7e34;
	--qsm-fb-wrong-bg: #fdecea;
	--qsm-fb-wrong-fg: #c0392b;

	margin: 10px 0 16px;
	font-size: 16px;
	line-height: 1.5;
	color: var(--qsm-fb-text);
}

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

.qsm-fb-hint {
	margin: 0 0 12px;
	color: var(--qsm-fb-muted);
	font-size: 0.9em;
}

.qsm-fb-error {
	margin: 8px 0;
	padding: 10px 12px;
	border: 1px solid #e0b4b4;
	background: #fdf3f3;
	color: #9f3a38;
	border-radius: 6px;
	font-size: 14px;
}

/* ---------- Банк слов ---------- */

.qsm-fb-pool-title {
	font-weight: 600;
	margin-bottom: 8px;
	font-size: 0.95em;
}

.qsm-fb-pool {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-content: flex-start;
	min-height: 58px;
	padding: 12px;
	background: #f4f6fb;
	border-radius: 12px;
	transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

/* ---------- Слова (чипы) ---------- */

.qsm-fb-word {
	display: inline-flex;
	align-items: center;
	padding: 7px 14px;
	background: #ffffff;
	border: 1px solid var(--qsm-fb-border);
	border-radius: 8px;
	box-shadow: 0 1px 2px rgba(20, 26, 51, 0.08);
	cursor: grab;
	user-select: none;
	-webkit-user-select: none;
	touch-action: none; /* перетаскивание пальцем без прокрутки страницы */
	transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

/* «Ручка» — три точки слева, как в H5P */
.qsm-fb-word::before {
	content: "";
	flex: 0 0 auto;
	width: 3px;
	height: 15px;
	margin-right: 8px;
	background-image: radial-gradient(circle, #c3c8d9 1.1px, transparent 1.4px);
	background-size: 3px 5px;
	background-repeat: repeat-y;
	background-position: center;
}

.qsm-fb-word:hover {
	box-shadow: 0 3px 8px rgba(20, 26, 51, 0.16);
	transform: translateY(-1px);
}

.qsm-fb-word:focus-visible {
	outline: 2px solid var(--qsm-fb-accent);
	outline-offset: 2px;
}

.qsm-fb-word.qsm-fb-selected {
	border-color: var(--qsm-fb-accent);
	background: var(--qsm-fb-accent-soft);
	box-shadow: 0 0 0 3px var(--qsm-fb-accent-glow);
}

.qsm-fb-word.qsm-fb-dragging {
	cursor: grabbing;
	opacity: 0.92;
	box-shadow: 0 10px 24px rgba(20, 26, 51, 0.28);
	pointer-events: none; /* чтобы elementFromPoint видел зону под словом */
}

/* ---------- Пропуски внутри текста ---------- */

.qsm-fb-passage {
	margin-top: 14px;
	line-height: 2.1;
}

.qsm-fb-blank {
	display: inline-block;
	vertical-align: middle;
	min-width: 110px;
	min-height: 40px;
	margin: 0 2px;
	padding: 2px 6px;
	background: #ffffff;
	border: 1.5px solid #d9dee9;
	border-radius: 10px;
	box-shadow: inset 0 1px 2px rgba(20, 26, 51, 0.05);
	text-align: center;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

/* Подсветка зоны под указателем при перетаскивании */
.qsm-fb-dropzone.qsm-fb-over {
	border-color: var(--qsm-fb-accent);
	background: var(--qsm-fb-accent-soft);
	box-shadow: 0 0 0 3px var(--qsm-fb-accent-glow);
}

.qsm-fb-pool.qsm-fb-over {
	box-shadow: 0 0 0 3px var(--qsm-fb-accent-glow);
}

/* Слово, вставленное в пропуск, прижимается без внешних отступов */
.qsm-fb-blank .qsm-fb-word {
	margin: 0;
}

/* ---------- Анимации перетаскивания ---------- */

@keyframes qsm-fb-drop-pop {
	0%   { transform: scale(1.12); opacity: 0.85; }
	60%  { transform: scale(0.96); }
	100% { transform: scale(1); opacity: 1; }
}

.qsm-fb-word.qsm-fb-landed {
	animation: qsm-fb-drop-pop 0.3s ease-out;
}

@keyframes qsm-fb-return {
	0%   { transform: scale(1.06); opacity: 0.9; }
	100% { transform: scale(1); opacity: 1; }
}

.qsm-fb-word.qsm-fb-returned {
	animation: qsm-fb-return 0.25s ease-out;
}

@keyframes qsm-fb-drop-flash {
	0%   { box-shadow: 0 0 0 6px var(--qsm-fb-accent-glow); }
	100% { box-shadow: 0 0 0 6px rgba(79, 109, 245, 0); }
}

.qsm-fb-blank.qsm-fb-flash {
	animation: qsm-fb-drop-flash 0.45s ease-out;
}

@media (prefers-reduced-motion: reduce) {
	.qsm-fb-word.qsm-fb-landed,
	.qsm-fb-word.qsm-fb-returned,
	.qsm-fb-blank.qsm-fb-flash {
		animation: none;
	}

	.qsm-fb-word {
		transition: none;
	}
}

/* ---------- Страница результатов ---------- */

.qsm-fb-results {
	margin: 6px 0 10px;
	font-size: 16px;
	line-height: 2.1;
	color: var(--qsm-fb-text);
}

.qsm-fb-results .qsm-fb-result-word {
	display: inline-block;
	vertical-align: middle;
	margin: 1px 3px;
	padding: 1px 10px;
	border-radius: 8px;
	font-weight: 600;
}

.qsm-fb-results .qsm-text-correct-option {
	background: var(--qsm-fb-correct-bg);
	color: var(--qsm-fb-correct-fg);
	box-shadow: inset 0 0 0 1px rgba(30, 126, 52, 0.25);
}

.qsm-fb-results .qsm-text-wrong-option {
	background: var(--qsm-fb-wrong-bg);
	color: var(--qsm-fb-wrong-fg);
	box-shadow: inset 0 0 0 1px rgba(192, 57, 43, 0.25);
}

.qsm-fb-results .qsm-fb-result-empty {
	min-width: 64px;
	text-align: center;
	border: 1.5px dashed rgba(192, 57, 43, 0.45);
	background: transparent;
}

/* ---------- Мобильная версия ---------- */

@media (max-width: 600px) {
	.qsm-fb-pool {
		padding: 10px;
		gap: 8px;
	}

	.qsm-fb-word {
		padding: 9px 16px;
		font-size: 1.05em; /* крупнее зона захвата на тач-экранах */
	}

	.qsm-fb-blank {
		min-width: 92px;
		min-height: 44px;
	}

	.qsm-fb-passage,
	.qsm-fb-results {
		line-height: 2.3;
	}
}
