/* ==========================================================================
   Books that turn over: new books on the home page (Sergio, 27 Nov 2026;
   before, 25 Nov: books whose lid opened to the side)
   Markup: template-parts/buch-klappbuch.php, behaviour: assets/js/klappbuch.js.
   Loaded only on the home page, after main.css (inc/assets.php).

   With a mouse the book turns over while the mouse is over it (Sergio,
   27 Nov 2026), on tablets and phones by a tap on the cover; it turns in
   place, around its vertical axis; the back has the same size as the cover, so the book never
   moves and its neighbours never shift. Open state: class ist-offen on
   .klappbuch (set by the script, only one book at a time).
   ========================================================================== */

.klappbuch {
	position: relative;
}

/* The turned book lies above its neighbours (its shadow, the 3D turn). */
.klappbuch.ist-offen {
	z-index: 2;
}

.klappbuch-buch {
	position: relative;
	margin-bottom: 1rem;
	perspective: 1600px;
}

/* The card that turns: front in the flow (its height = the cover), back on
   top of it, turned by 180 degrees. */
.klappbuch-karte {
	position: relative;
	transform-style: preserve-3d;
	transition: transform 0.7s cubic-bezier(0.4, 0.1, 0.2, 1);
}

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

/* Front = cover button. Placeholder, softcover shading and format come
   from .book-card-cover (main.css); the lift of main.css is on the wrapper
   here, so the card keeps a clean 3D transform. */
.klappbuch .book-card-cover,
.klappbuch:hover .book-card-cover {
	margin-bottom: 0;
	transform: none;
}

.klappbuch-vorne {
	display: block;
	width: 100%;
	padding: 0;
	font: inherit;
	color: inherit;
	text-align: inherit;
	border: 0;
	cursor: pointer;
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
}

.klappbuch-vorne:focus-visible {
	outline: 2px solid var(--ring);
	outline-offset: 3px;
}

/* Back. */
.klappbuch-hinten {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	padding: 1rem 0.875rem 0.875rem;
	overflow: hidden;
	color: var(--body-text);
	background-color: var(--card);
	border: 1px solid var(--border);
	border-radius: var(--radius-cover);
	box-shadow: var(--shadow-lg);
	transform: rotateY(180deg);
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
	cursor: pointer;
}

.klappbuch-zu {
	position: absolute;
	top: 0.25rem;
	right: 0.25rem;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	padding: 0;
	font-size: 1.375rem;
	line-height: 1;
	color: var(--primary);
	background: transparent;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.klappbuch-zu:hover {
	background-color: var(--muted);
}

.klappbuch-zu:focus-visible {
	outline: 2px solid var(--ring);
	outline-offset: 1px;
}

.klappbuch-gattung {
	flex-shrink: 0;
	margin-right: 1.75rem;
	margin-bottom: 0.375rem;
	overflow: hidden;
	font-size: 0.6875rem;
	font-weight: 600;
	line-height: 1.4;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	white-space: nowrap;
	text-overflow: ellipsis;
	color: var(--accent);
}

.klappbuch-titel {
	display: -webkit-box;
	flex-shrink: 0;
	margin-right: 1.5rem;
	overflow: hidden;
	font-family: var(--font-heading);
	font-size: 1.0625rem;
	font-weight: 600;
	line-height: 1.25;
	letter-spacing: -0.025em;
	color: var(--foreground);
	hyphens: manual;
	overflow-wrap: break-word;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
}

/* Without a Gattung the title starts at the top, next to the ×. */
.klappbuch-namen {
	flex-shrink: 0;
	margin-top: 0.25rem;
	overflow: hidden;
	font-size: 0.8125rem;
	line-height: 1.35;
	white-space: nowrap;
	text-overflow: ellipsis;
	color: var(--muted-foreground);
}

/* The frame fills the free height; the script sets the number of lines of
   the text in it to what fits (fallback: 6 lines, cut by the frame). */
.klappbuch-text-rahmen {
	flex: 1 1 0;
	min-height: 0;
	margin-top: 0.625rem;
	overflow: hidden;
}

.klappbuch-text {
	display: -webkit-box;
	overflow: hidden;
	font-size: 0.84375rem;
	line-height: 1.55;
	color: var(--body-text);
	overflow-wrap: break-word;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 6;
	line-clamp: 6;
}

.klappbuch-fuss {
	display: flex;
	flex-shrink: 0;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding-top: 0.75rem;
}

.klappbuch-preis {
	font-family: var(--font-heading);
	font-size: 1rem;
	font-weight: 700;
	color: var(--accent);
}

.klappbuch-knopf {
	gap: 0.375rem;
	padding: 0.5rem 0.875rem;
	font-size: 0.8125rem;
	white-space: nowrap;
	cursor: pointer;
}

/* Phones (2 small columns): tighter back. */
@media (max-width: 639px) {
	.klappbuch-hinten {
		padding: 0.625rem 0.5rem 0.5rem;
	}

	.klappbuch-zu {
		top: 0;
		right: 0;
		width: 1.75rem;
		height: 1.75rem;
		font-size: 1.25rem;
	}

	.klappbuch-gattung {
		margin-right: 1.25rem;
		margin-bottom: 0.25rem;
		font-size: 0.625rem;
		letter-spacing: 0.06em;
	}

	.klappbuch-titel {
		margin-right: 1rem;
		font-size: 0.875rem;
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}

	.klappbuch-namen {
		font-size: 0.6875rem;
	}

	.klappbuch-text-rahmen {
		margin-top: 0.375rem;
	}

	.klappbuch-text {
		font-size: 0.75rem;
		line-height: 1.45;
	}

	.klappbuch-fuss {
		gap: 0.25rem;
		padding-top: 0.375rem;
	}

	.klappbuch-preis {
		font-size: 0.875rem;
	}

	.klappbuch-knopf {
		justify-content: center;
		width: 100%;
		padding: 0.375rem 0.5rem;
		font-size: 0.75rem;
	}
}

/* Less motion: nothing turns, the back simply fades in over the cover. */
@media (prefers-reduced-motion: reduce) {
	.klappbuch .klappbuch-karte {
		transform: none;
		transition: none;
	}

	.klappbuch-hinten {
		opacity: 0;
		visibility: hidden;
		transform: none;
		transition: opacity 0.25s ease, visibility 0s linear 0.25s;
	}

	.klappbuch.ist-offen .klappbuch-hinten {
		opacity: 1;
		visibility: visible;
		transition: opacity 0.25s ease, visibility 0s;
	}
}
