/* Expolab Memory Game — v1.3.2 */

/* Alcuni temi assegnano display a p, span e img annullando l'attributo hidden. */
.emg [hidden] {
	display: none !important;
}

.emg {
	--emg-cols-easy: 4;
	--emg-cols-hard: 4;
	--emg-gap: 12px;
	--emg-radius: 10px;
	--emg-ratio: 3 / 4;
	--emg-fit: cover;
	--emg-back-color: #e8a13a;
	--emg-back-image: none;
	--emg-front-color: #fff;
	--emg-front-padding: 0px;
	--emg-match-color: #3fa34d;
	--emg-btn-color: #333;
	--emg-btn-bg: #ececec;
	--emg-btn-active-color: #fff;
	--emg-btn-active-bg: #333;
	--emg-btn-radius: 999px;
	--emg-win-bg: rgba(255, 255, 255, 0.94);
	--emg-focus: #1a73e8;
	--emg-flip: 0.45s;

	position: relative;
	width: 100%;
	max-width: 640px;
	margin-left: auto;
	margin-right: auto;
	box-sizing: border-box;
}

.emg[data-level="easy"] {
	--emg-cols: var(--emg-cols-easy);
}

.emg[data-level="hard"] {
	--emg-cols: var(--emg-cols-hard);
}

@media (max-width: 480px) {
	.emg {
		--emg-gap: 8px;
		--emg-radius: 8px;
	}
}

/* ---------- Barra superiore ---------- */

.emg__toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 10px 16px;
	margin-bottom: 16px;
}

.emg__levels {
	display: inline-flex;
	gap: 6px;
}

.emg__stats {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 4px 16px;
	font-variant-numeric: tabular-nums;
}

.emg .emg__btn,
.emg .emg__btn:hover,
.emg .emg__btn:focus,
.emg .emg__btn:active {
	-webkit-appearance: none;
	appearance: none;
	margin: 0;
	padding: 0.55em 1.15em;
	border: 0;
	border-radius: var(--emg-btn-radius);
	background: var(--emg-btn-bg);
	color: var(--emg-btn-color);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	text-transform: none;
	box-shadow: none;
	cursor: pointer;
	transition: filter 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.emg .emg__btn:hover {
	filter: brightness(0.94);
}

.emg__actions {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

/* Pulsante audio: solo icona, rotondo */
.emg .emg__btn.emg__mute,
.emg .emg__btn.emg__mute:hover,
.emg .emg__btn.emg__mute:focus,
.emg .emg__btn.emg__mute:active {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.55em;
}

.emg__mute svg {
	display: block;
	width: 1.2em;
	height: 1.2em;
	fill: currentColor;
}

.emg__mute .emg__mute-off,
.emg__mute.is-muted .emg__mute-on {
	display: none;
}

.emg__mute.is-muted .emg__mute-off {
	display: inline;
}

.emg__mute.is-muted {
	opacity: 0.7;
}

.emg .emg__btn.is-active,
.emg .emg__btn.is-active:hover,
.emg .emg__btn.is-active:focus,
.emg .emg__again,
.emg .emg__again:hover,
.emg .emg__again:focus {
	background: var(--emg-btn-active-bg);
	color: var(--emg-btn-active-color);
}

.emg .emg__btn:focus,
.emg .emg__card:focus {
	outline: none;
}

.emg .emg__btn:focus-visible,
.emg .emg__card:focus-visible {
	outline: 3px solid var(--emg-focus);
	outline-offset: 2px;
}

/* ---------- Tabellone ---------- */

.emg__board {
	display: grid;
}

.emg__grid,
.emg__win {
	grid-area: 1 / 1;
	min-width: 0;
}

.emg__grid {
	display: grid;
	grid-template-columns: repeat(var(--emg-cols, 4), minmax(0, 1fr));
	gap: var(--emg-gap);
	align-content: start;
}

/*
 * Adatta all'altezza dello schermo: limita la larghezza della griglia in modo che
 * tutte le righe restino visibili senza scorrere (--emg-rows è impostata dal JS).
 */
.emg--fit .emg__grid {
	--emg-avail: calc(100vh - var(--emg-fit-offset, 140px));
	width: 100%;
	max-width: max(
		240px,
		calc(
			(var(--emg-avail) - (var(--emg-rows, 2) - 1) * var(--emg-gap)) / var(--emg-rows, 2)
			* (var(--emg-ratio)) * var(--emg-cols, 4)
			+ (var(--emg-cols, 4) - 1) * var(--emg-gap)
		)
	);
	margin-left: auto;
	margin-right: auto;
}

@supports (height: 100dvh) {
	.emg--fit .emg__grid {
		--emg-avail: calc(100dvh - var(--emg-fit-offset, 140px));
	}
}

/* ---------- Carta ---------- */

.emg .emg__card,
.emg .emg__card:hover,
.emg .emg__card:focus,
.emg .emg__card:active {
	-webkit-appearance: none;
	appearance: none;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--emg-radius);
	background: transparent;
	color: inherit;
	box-shadow: none;
}

.emg .emg__card {
	display: block;
	position: relative;
	width: 100%;
	min-width: 0;
	aspect-ratio: var(--emg-ratio);
	perspective: 900px;
	cursor: pointer;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
	transition: transform 0.15s ease;
}

.emg .emg__card.is-matched {
	cursor: default;
}

@media (hover: hover) {
	.emg .emg__card:not(.is-flipped):not(.is-matched):hover {
		transform: translateY(-3px);
	}
}

.emg__inner {
	display: block;
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	transform-style: preserve-3d;
	transition: transform var(--emg-flip) cubic-bezier(0.4, 0.2, 0.2, 1);
}

.emg__card.is-flipped .emg__inner,
.emg__card.is-matched .emg__inner {
	transform: rotateY(180deg);
}

.emg__face {
	display: block;
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	box-sizing: border-box;
	border-radius: var(--emg-radius);
	overflow: hidden;
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.emg__face--back {
	background-color: var(--emg-back-color);
}

/* Immagine del retro su un livello interno: si può adattare e ingrandire
   (lo zoom nasconde un eventuale margine trasparente del PNG). */
.emg__back-img {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background-image: var(--emg-back-image);
	background-position: center;
	background-size: var(--emg-back-size, cover);
	background-repeat: no-repeat;
	transform: scale(var(--emg-back-zoom, 1));
	pointer-events: none;
}

/* Cornice decorativa quando non c'è un'immagine per il retro */
.emg--plain-back .emg__face--back::after {
	content: "";
	position: absolute;
	top: 8%;
	right: 8%;
	bottom: 8%;
	left: 8%;
	border: 2px solid rgba(255, 255, 255, 0.6);
	border-radius: calc(var(--emg-radius) * 0.6);
}

.emg__face--front {
	padding: var(--emg-front-padding);
	background: var(--emg-front-color);
	transform: rotateY(180deg);
}

.emg .emg__face--front img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	object-fit: var(--emg-fit);
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
}

.emg__card.is-matched .emg__face--front {
	outline: 3px solid var(--emg-match-color);
	outline-offset: -3px;
}

.emg__card.is-matched {
	animation: emg-pop 0.4s ease var(--emg-flip) both;
}

.emg__card.is-wrong {
	animation: emg-shake 0.35s ease var(--emg-flip) both;
}

@keyframes emg-pop {
	0% { transform: scale(1); }
	50% { transform: scale(1.06); }
	100% { transform: scale(1); }
}

@keyframes emg-shake {
	0%, 100% { transform: translateX(0); }
	25% { transform: translateX(-4px); }
	75% { transform: translateX(4px); }
}

/* Cornice PNG sopra le carte (es. semi negli angoli) */
.emg--overlay .emg__face--front::after,
.emg--overlay-back .emg__face--back::before {
	content: "";
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 1;
	background-image: var(--emg-overlay-image);
	background-position: center;
	background-size: var(--emg-overlay-size, 100% 100%);
	background-repeat: no-repeat;
	opacity: var(--emg-overlay-opacity, 1);
	pointer-events: none;
}

/* ---------- Messaggio finale ---------- */

.emg__win {
	z-index: 2;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 24px 16px;
	border-radius: var(--emg-radius);
	background: var(--emg-win-bg);
	text-align: center;
	animation: emg-fade 0.35s ease both;
}

.emg__win[hidden],
.emg__win-record[hidden] {
	display: none;
}

.emg .emg__win p {
	margin: 0;
}

.emg__win-title {
	font-size: clamp(1.5rem, 5vw, 2.25rem);
	font-weight: 700;
	line-height: 1.15;
}

.emg__win-record {
	font-weight: 700;
	color: var(--emg-match-color);
}

.emg .emg__again {
	margin-top: 6px;
}

@keyframes emg-fade {
	from { opacity: 0; transform: scale(0.97); }
	to { opacity: 1; transform: scale(1); }
}

/* ---------- Accessibilità ---------- */

.emg .emg__status {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

@media (prefers-reduced-motion: reduce) {
	.emg__inner,
	.emg .emg__card {
		transition: none;
	}

	.emg__card.is-matched,
	.emg__card.is-wrong,
	.emg__win {
		animation: none;
	}
}

/* ---------- Avviso nell'editor ---------- */

.emg-notice {
	padding: 16px;
	border: 1px dashed #c3c4c7;
	border-radius: 6px;
	background: #f6f7f7;
	color: #50575e;
	font-size: 14px;
	text-align: center;
}
