/*
 * Fleisch Memory
 *
 * Farben lassen sich im Custom CSS der Seite ueberschreiben, z. B.:
 *   .fleisch-memory, .fm-buehne { --fm-akzent: #AE1F2C; }
 * Schrift: Das Spiel uebernimmt die Schrift der Umgebung.
 */

.fleisch-memory,
.fm-buehne {
	--fm-akzent: #AE1F2C;
	--fm-akzent-text: #fff;
	--fm-text: currentColor;
	--fm-linie: rgba(0, 0, 0, .18);
	--fm-rueckseite: #1d1d1b;
	--fm-ecken: 8px;
	--fm-schatten: 0 1px 3px rgba(0, 0, 0, .18), 0 4px 14px rgba(0, 0, 0, .10);
}

.fleisch-memory {
	position: relative;
	width: 100%;
	margin: 0 auto;
	font: inherit;
	color: inherit;
}

.fleisch-memory *,
.fm-buehne * { box-sizing: border-box; }

.fm-ansage {
	position: absolute !important;
	width: 1px; height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* ---------- Knoepfe ---------- */

/* Theme und Elementor gestalten Buttons global. Hier bewusst eng
   geschachtelt, damit unsere Regeln gewinnen. */
.fleisch-memory .fm-knopf {
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	margin: 0;
	padding: .55em 1.2em;
	border: 1.5px solid currentColor;
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 1rem;
	line-height: 1.2;
	letter-spacing: normal;
	text-transform: none;
	text-decoration: none;
	box-shadow: none;
	cursor: pointer;
	transition: background-color .15s, color .15s, border-color .15s;
}

.fleisch-memory .fm-knopf:hover,
.fleisch-memory .fm-knopf:focus-visible {
	background: rgba(0, 0, 0, .06);
	color: inherit;
	text-decoration: none;
}

.fleisch-memory .fm-knopf:focus-visible,
.fleisch-memory .fm-karte:focus-visible {
	outline: 2px solid var(--fm-akzent);
	outline-offset: 3px;
}

.fleisch-memory .fm-haupt,
.fleisch-memory .fm-wahl[aria-checked="true"] {
	background: var(--fm-akzent);
	border-color: var(--fm-akzent);
	color: var(--fm-akzent-text);
}

.fleisch-memory .fm-haupt:hover,
.fleisch-memory .fm-haupt:focus-visible,
.fleisch-memory .fm-wahl[aria-checked="true"]:hover {
	background: var(--fm-akzent);
	color: var(--fm-akzent-text);
	filter: brightness(1.1);
}

.fleisch-memory .fm-klein {
	min-height: 36px;
	padding: .35em 1em;
	font-size: .9rem;
}

/* ---------- Start ---------- */

.fm-start {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1.6rem;
	padding: 2rem 1rem;
	text-align: center;
}

.fm-auswahl-titel {
	margin-bottom: .6rem;
	font-weight: 700;
}

.fm-auswahl-reihe {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: .5rem;
}

.fleisch-memory .fm-wahl {
	min-width: 52px;
	padding-left: .9em;
	padding-right: .9em;
}

/* ---------- Kopfzeile ---------- */

.fm-kopf {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: .75rem;
	margin-bottom: 1rem;
}

.fm-spielerleiste {
	display: flex;
	flex-wrap: wrap;
	gap: .4rem;
}

.fm-spieler {
	display: inline-flex;
	align-items: center;
	gap: .5em;
	padding: .3em .85em;
	border: 1.5px solid var(--fm-linie);
	border-radius: 999px;
	font-size: .95rem;
	line-height: 1.3;
	transition: background-color .2s, color .2s, border-color .2s;
}

.fm-spieler.ist-dran {
	border-color: var(--fm-akzent);
	background: var(--fm-akzent);
	color: var(--fm-akzent-text);
}

.fm-spieler-punkte {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

/* ---------- Spielfeld ---------- */

.fm-feld {
	display: grid;
	justify-content: center;
	/* Spalten und Abstand setzt das Skript, passend zu Platz und Format. */
	grid-template-columns: repeat(4, 120px);
	gap: 10px;
}

.fleisch-memory .fm-karte {
	appearance: none;
	display: block;
	position: relative;
	width: 100%;
	height: auto;
	min-height: 0;
	aspect-ratio: var(--fm-verhaeltnis, 5 / 7);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--fm-ecken);
	background: none;
	box-shadow: none;
	line-height: 0;
	cursor: pointer;
	perspective: 900px;
	-webkit-tap-highlight-color: transparent;
}

.fleisch-memory .fm-karte:hover,
.fleisch-memory .fm-karte:focus { background: none; box-shadow: none; }

.fm-karte-innen {
	position: absolute;
	inset: 0;
	transform-style: preserve-3d;
	transition: transform .45s cubic-bezier(.4, .1, .25, 1);
}

.fm-karte.ist-offen .fm-karte-innen { transform: rotateY(180deg); }

.fm-karte:not(.ist-offen):hover .fm-karte-innen { transform: translateY(-2px); }

.fm-seite {
	position: absolute;
	inset: 0;
	overflow: hidden;
	border-radius: var(--fm-ecken);
	box-shadow: var(--fm-schatten);
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
	background: #fff;
}

.fm-seite img {
	display: block;
	width: 100% !important;
	height: 100% !important;
	max-width: none !important;
	margin: 0 !important;
	object-fit: cover;
	border-radius: 0 !important;
	pointer-events: none;
	user-select: none;
}

.fm-hinten { background: var(--fm-rueckseite); }

/* Ohne eigenes Rueckseitenbild: schlichtes Muster in der Akzentfarbe. */
.ohne-rueckseite .fm-hinten {
	background:
		repeating-linear-gradient(45deg, rgba(255, 255, 255, .08) 0 6px, transparent 6px 12px),
		var(--fm-akzent);
}

.fm-vorne { transform: rotateY(180deg); }

/* Gefunden: Der Platz bleibt, damit das Raster nicht nachrutscht. */
.fleisch-memory .fm-karte.ist-weg {
	visibility: hidden;
	pointer-events: none;
}

/* ---------- Ende ---------- */

.fm-ende {
	padding: 2.5rem 1rem;
	text-align: center;
}

.fm-ende-titel {
	font-size: clamp(1.5rem, 4vw, 2.2rem);
	font-weight: 700;
	line-height: 1.15;
}

.fm-ende-ergebnis {
	margin: .8rem 0 0;
	font-size: 1.15rem;
}

.fm-rangliste {
	max-width: 320px;
	margin: 1.2rem auto 0;
	padding: 0;
	list-style: none;
}

.fm-rangliste li {
	display: flex;
	justify-content: space-between;
	padding: .4rem 0;
	border-bottom: 1px solid var(--fm-linie);
}

.fm-rangliste li:first-child { font-weight: 700; }

.fm-ende-knoepfe {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: .6rem;
	margin-top: 1.8rem;
}

/* ---------- Buehne fuer die Treffer-Animation ---------- */

.fm-buehne {
	position: fixed;
	inset: 0;
	z-index: 100000;
	cursor: pointer;
	outline: none;
	-webkit-tap-highlight-color: transparent;
}

.fm-schleier {
	position: absolute;
	inset: 0;
	background: rgba(15, 15, 15, .72);
	-webkit-backdrop-filter: blur(3px);
	backdrop-filter: blur(3px);
	opacity: 0;
}

.fm-gross {
	position: fixed;
	perspective: 1600px;
	transform-origin: 50% 50%;
	will-change: transform;
}

.fm-gross-innen {
	position: absolute;
	inset: 0;
	transform-style: preserve-3d;
}

.fm-gross .fm-seite {
	border-radius: calc(var(--fm-ecken) * 1.6);
	box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}

.fm-gross-loesung { transform: rotateY(180deg); }

.fm-hinweis {
	position: absolute;
	left: 0;
	right: 0;
	bottom: max(16px, 4vh);
	color: #fff;
	text-align: center;
	font-size: .95rem;
	letter-spacing: .02em;
	opacity: 0;
	transition: opacity .4s;
	pointer-events: none;
}

.fm-buehne.ist-bereit .fm-hinweis { opacity: .85; }

@media (prefers-reduced-motion: reduce) {
	.fm-karte-innen { transition-duration: .01s; }
	.fm-schleier { opacity: 1; }
}
