/* Expolab Puzzle Game — v1.1.0 */

.epg {
	--epg-radius: 12px;
	--epg-table-color: #f4f1ea;
	--epg-board-color: #fff;
	--epg-board-line: #cdc6b8;
	--epg-guide-color: rgba(0, 0, 0, 0.16);
	--epg-tray-color: rgba(0, 0, 0, 0.05);
	--epg-piece-line: rgba(0, 0, 0, 0.45);
	--epg-piece-placed-line: rgba(0, 0, 0, 0.2);
	--epg-piece-line-width: 1.5px;
	--epg-thumb-size: 64px;
	--epg-thumb-gap: 8px;
	--epg-thumb-radius: 8px;
	--epg-thumb-active: #333;
	--epg-btn-color: #333;
	--epg-btn-bg: #ececec;
	--epg-btn-active-color: #fff;
	--epg-btn-active-bg: #333;
	--epg-btn-radius: 999px;
	--epg-win-bg: rgba(255, 255, 255, 0.94);
	--epg-match-color: #3fa34d;
	--epg-focus: #1a73e8;
	--epg-fit-offset: 200px;

	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 960px;
	margin-left: auto;
	margin-right: auto;
	box-sizing: border-box;
}

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

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

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

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

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

.epg .epg__btn,
.epg .epg__btn:hover,
.epg .epg__btn:focus,
.epg .epg__btn:active {
	-webkit-appearance: none;
	appearance: none;
	margin: 0;
	padding: 0.55em 1.15em;
	border: 0;
	border-radius: var(--epg-btn-radius);
	background: var(--epg-btn-bg);
	color: var(--epg-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;
}

.epg .epg__btn:hover {
	filter: brightness(0.94);
}

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

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

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

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

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

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

.epg .epg__btn.is-active,
.epg .epg__btn.is-active:hover,
.epg .epg__btn.is-active:focus,
.epg .epg__again,
.epg .epg__again:hover,
.epg .epg__again:focus {
	background: var(--epg-btn-active-bg);
	color: var(--epg-btn-active-color);
}

.epg .epg__btn:focus,
.epg .epg__thumb:focus,
.epg .epg__piece:focus {
	outline: none;
}

.epg .epg__btn:focus-visible,
.epg .epg__thumb:focus-visible {
	outline: 3px solid var(--epg-focus);
	outline-offset: 2px;
}

/* ---------- Miniature per scegliere l'immagine ---------- */

.epg__picker {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--epg-thumb-gap);
	margin-bottom: 14px;
}

.epg--picker-bottom .epg__picker {
	order: 3;
	margin-top: 14px;
	margin-bottom: 0;
}

.epg .epg__thumb,
.epg .epg__thumb:hover,
.epg .epg__thumb:focus,
.epg .epg__thumb:active {
	-webkit-appearance: none;
	appearance: none;
	display: block;
	flex: 0 0 auto;
	width: var(--epg-thumb-size);
	height: var(--epg-thumb-size);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--epg-thumb-radius);
	background: var(--epg-board-color);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
	overflow: hidden;
	cursor: pointer;
	opacity: 0.75;
	transition: opacity 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.epg .epg__thumb:hover {
	opacity: 1;
}

.epg .epg__thumb.is-active,
.epg .epg__thumb.is-active:hover,
.epg .epg__thumb.is-active:focus {
	opacity: 1;
	box-shadow: 0 0 0 3px var(--epg-thumb-active);
}

.epg .epg__thumb img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	object-fit: cover;
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
}

/* ---------- Tavolo ---------- */

.epg__table {
	position: relative;
	width: 100%;
	margin-left: auto;
	margin-right: auto;
	aspect-ratio: var(--epg-table-ratio, 2);
}

/*
 * Adatta all'altezza dello schermo: limita la larghezza del tavolo in modo che
 * resti tutto visibile senza scorrere (--epg-table-ratio è impostata dal JS).
 */
.epg--fit .epg__table {
	--epg-avail: calc(100vh - var(--epg-fit-offset, 200px));
	max-width: max(300px, calc(var(--epg-avail) * var(--epg-table-ratio, 2)));
}

@supports (height: 100dvh) {
	.epg--fit .epg__table {
		--epg-avail: calc(100dvh - var(--epg-fit-offset, 200px));
	}
}

.epg .epg__svg {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border-radius: var(--epg-radius);
	overflow: hidden;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
}

.epg__table-bg {
	fill: var(--epg-table-color);
}

.epg__tray-bg {
	fill: var(--epg-tray-color);
}

.epg__board-bg {
	fill: var(--epg-board-color);
	stroke: var(--epg-board-line);
	stroke-width: 2px;
	vector-effect: non-scaling-stroke;
}

.epg__guide path {
	fill: none;
	stroke: var(--epg-guide-color);
	stroke-width: 1px;
	vector-effect: non-scaling-stroke;
}

/* ---------- Pezzi ---------- */

.epg__piece {
	cursor: grab;
	touch-action: none;
	transform-box: view-box;
	transform-origin: 0 0;
	transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.epg__piece.is-dragging {
	cursor: grabbing;
	transition: none;
}

.epg__piece.is-placed {
	cursor: default;
	pointer-events: none;
}

.epg__piece image {
	pointer-events: none;
}

.epg__piece-edge {
	fill: none;
	stroke: var(--epg-piece-line);
	stroke-width: var(--epg-piece-line-width);
	stroke-linejoin: round;
	vector-effect: non-scaling-stroke;
	pointer-events: all;
}

.epg__piece.is-placed .epg__piece-edge {
	stroke: var(--epg-piece-placed-line);
	pointer-events: none;
}

.epg__piece:focus-visible .epg__piece-edge,
.epg__piece.is-held .epg__piece-edge {
	stroke: var(--epg-focus);
	stroke-width: 3px;
}

.epg__piece-shadow {
	fill: rgba(0, 0, 0, 0.28);
	pointer-events: none;
	transform: translate(6px, 9px);
	transition: transform 0.15s ease, fill 0.15s ease;
}

.epg__piece.is-dragging .epg__piece-shadow,
.epg__piece.is-held .epg__piece-shadow {
	fill: rgba(0, 0, 0, 0.2);
	transform: translate(13px, 19px);
}

.epg__piece.is-placed .epg__piece-shadow,
.epg--no-shadow .epg__piece-shadow {
	display: none;
}

/* Immagine intera a puzzle completato */
.epg__full {
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.5s ease;
}

.epg.is-won .epg__full {
	opacity: 1;
}

.epg.is-loading .epg__svg {
	opacity: 0.6;
}

.epg .epg__message {
	position: absolute;
	top: 50%;
	left: 0;
	right: 0;
	margin: 0;
	padding: 0 16px;
	text-align: center;
	transform: translateY(-50%);
}

/* ---------- Messaggio finale (nella zona dei pezzi, ormai vuota) ---------- */

.epg__win {
	position: absolute;
	z-index: 2;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	box-sizing: border-box;
	padding: 12px;
	border-radius: var(--epg-radius);
	background: var(--epg-win-bg);
	text-align: center;
	overflow: auto;
	animation: epg-fade 0.35s ease both;
}

.epg .epg__win p {
	margin: 0;
}

.epg__win-title {
	font-size: clamp(1.25rem, 3.6vw, 2rem);
	font-weight: 700;
	line-height: 1.15;
}

.epg__win-record {
	font-weight: 700;
	color: var(--epg-match-color);
}

.epg .epg__again {
	margin-top: 4px;
}

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

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

.epg .epg__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) {
	.epg__piece,
	.epg__piece-shadow,
	.epg__full,
	.epg .epg__thumb {
		transition: none;
	}

	.epg__win {
		animation: none;
	}
}

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

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