/*
 * The Library (/blog/) and the archives in its style, per
 * docs/design/pages/library.dc.html. Books are sized in cqh (% of the shelf
 * opening's height), so they scale with the painted room.
 */

body.fe-library {
	background: var(--fe-warm-dark) linear-gradient(180deg, var(--fe-ink) 0, #150a16 340px, var(--fe-warm-dark) 600px) no-repeat;
	color: #f4ead5;
}

.library a {
	color: #e9d3a1;
}

.library :focus-visible {
	outline-color: #e9d3a1;
}

/* ---------- Title ---------- */

.library-heading {
	text-align: center;
	padding: 40px var(--fe-gutter) 8px;
}

.library-heading__title {
	margin: 0 0 16px;
	font-size: clamp(3.25rem, 2rem + 5vw, 5.25rem);
	line-height: 1;
	color: #f6e7cc;
	text-shadow: 0 0 40px rgba(255, 200, 120, 0.2);
}

.library-heading__lead {
	margin: 0;
	font-family: var(--fe-font-reading);
	font-style: italic;
	font-size: clamp(1.25rem, 1rem + 1vw, 1.5625rem);
	line-height: 1.5;
	color: #d9c7ae;
}

/* ---------- The room ---------- */

.library-room {
	position: relative;
}

.library-room__skip {
	position: absolute;
	z-index: 60;
	left: 50%;
	top: 0;
	transform: translateX(-50%);
	padding: 0.5rem 1rem;
	border-radius: var(--fe-pill);
	background: var(--fe-warm-dark);
	font-size: var(--fe-size-small);
	white-space: nowrap;
}

/* Hidden until it has keyboard focus. */
.library-room__skip:not(:focus) {
	width: 1px;
	height: 1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
}

.scene {
	position: relative;
	max-width: 1600px;
	margin: 0 auto;
	aspect-ratio: 1672 / 941;
}

.scene-img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
	-webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 8%, #000 86%, transparent 100%), linear-gradient(to right, transparent 0, #000 7%, #000 93%, transparent 100%);
	-webkit-mask-composite: source-in;
	mask-image: linear-gradient(to bottom, transparent 0, #000 8%, #000 86%, transparent 100%), linear-gradient(to right, transparent 0, #000 7%, #000 93%, transparent 100%);
	mask-composite: intersect;
}

.shelf {
	position: absolute;
	left: var(--l);
	top: var(--t);
	width: var(--w);
	height: var(--h);
	scroll-margin-top: 2rem;
}

.shelf-name {
	display: none;
}

.shelf-box {
	position: absolute;
	inset: 0;
	container-type: size;
}

.row {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: flex-end;
	gap: 0.6cqh;
	padding: 0 1cqh;
}

/* Candlelight on each shelf: dark under the shelf above, warm in the middle. */
.shade {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 3;
	mix-blend-mode: multiply;
	background:
		linear-gradient(to bottom, rgba(40, 20, 12, 0.55) 0, rgba(255, 255, 255, 0) 22%),
		radial-gradient(ellipse 70% 120% at 50% 100%, #fff4e6 0%, #e7c9a8 55%, #8a6048 100%);
}

/* Overflow: the rest of a shelf on painted strips below the room, like a second bookcase. */
.shelf-extra {
	position: relative;
	width: min(50%, 800px);
	margin: 0 auto 24px;
	aspect-ratio: 2172 / 724;
	background: url("../images/library-shelf-strip.jpg") center / 100% 100% no-repeat;
	background-image: image-set(url("../images/library-shelf-strip.webp") type("image/webp"), url("../images/library-shelf-strip.jpg") type("image/jpeg"));
}

.shelf-extra .shelf-box {
	inset: auto;
	left: 7.5%;
	top: 10%;
	width: 85%;
	height: 52%;
}

/* ---------- Books ---------- */

.bk {
	position: relative;
	flex: 0 0 auto;
	display: block;
	width: var(--bw);
	height: var(--bh);
	background-size: 100% 100%;
	border-radius: 0.8cqh 0.8cqh 0.4cqh 0.4cqh;
	text-decoration: none;
	box-shadow: inset -0.6cqh 0 1cqh rgba(0, 0, 0, 0.45), inset 0.4cqh 0 0.6cqh rgba(255, 230, 190, 0.12), 0.8cqh 0 1.2cqh rgba(0, 0, 0, 0.55);
	transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1), filter 0.35s;
	z-index: 1;
}

.bk:hover,
.bk:focus-visible {
	transform: translateY(-9cqh);
	filter: brightness(1.18);
	z-index: 30;
	outline: none;
}

.bk:focus-visible {
	box-shadow: 0 0 0 2px #e9d3a1;
}

/* On desktop this book stands on an overflow strip instead. */
.bk--overflow {
	display: none;
}

.bk-label {
	position: absolute;
	left: 9%;
	right: 9%;
	top: 15%;
	bottom: 17%;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	background: radial-gradient(ellipse at 50% 50%, rgba(10, 4, 8, 0.62), rgba(10, 4, 8, 0.38) 70%, rgba(10, 4, 8, 0) 100%);
	border-radius: 1cqh;
}

.bk-title {
	writing-mode: vertical-rl;
	font-family: var(--fe-font-serif);
	font-size: max(8.5px, 6.4cqh);
	line-height: 1.08;
	letter-spacing: 0.03em;
	color: #edd39a;
	text-align: center;
	max-height: 100%;
	overflow: hidden;
	text-shadow: 0 0 3px rgba(0, 0, 0, 0.95), 0 1px 0 rgba(0, 0, 0, 0.9);
}

/* The brass plate at the start of each row. */
.plq {
	position: relative;
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 92cqh;
	height: 37cqh;
	margin-right: 3cqh;
	background: url("../images/library-plaque.png") center / 100% 100% no-repeat;
	background-image: image-set(url("../images/library-plaque.webp") type("image/webp"), url("../images/library-plaque.png") type("image/png"));
	filter: drop-shadow(0.6cqh 0.8cqh 0.8cqh rgba(0, 0, 0, 0.6));
	transform: rotate(-2deg);
	transform-origin: bottom left;
	z-index: 2;
}

.plq span {
	font-family: var(--fe-font-serif);
	font-size: max(10px, 9.5cqh);
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: #24160a;
	text-shadow: 0 1px 0 rgba(255, 240, 200, 0.7), 0 -1px 0 rgba(0, 0, 0, 0.35);
	white-space: nowrap;
}

/* The parchment slip under a lifted book. */
.slip {
	position: absolute;
	top: calc(100% + 10px);
	left: 50%;
	width: 250px;
	min-height: 250px;
	transform: translate(-50%, 8px);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	padding: 34px 30px 30px;
	display: flex;
	flex-direction: column;
	gap: 9px;
	text-align: left;
	background: url("../images/library-parchment.png") center / 100% 100% no-repeat;
	background-image: image-set(url("../images/library-parchment.webp") type("image/webp"), url("../images/library-parchment.png") type("image/png"));
	filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.65));
	transition: opacity 0.25s, transform 0.25s, visibility 0.25s;
	z-index: 40;
	writing-mode: horizontal-tb;
}

.bk:hover .slip,
.bk:focus-visible .slip {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, 0);
}

.slip-k {
	font-family: var(--fe-font-sans);
	font-size: 10.5px;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	font-weight: 700;
	color: #4a3018; /* about 5:1 on the parchment (the design's #6e4a22 is 3.2:1) */
}

.slip-t {
	font-family: var(--fe-font-serif);
	font-size: 19px;
	line-height: 1.25;
	color: #2a1408;
}

.slip-l {
	font-family: var(--fe-font-reading);
	font-style: italic;
	font-size: 16px;
	line-height: 1.42;
	color: #4a3018;
}

.slip-m {
	font-family: var(--fe-font-sans);
	font-size: 12px;
	color: #4a3018;
}

/*
 * ---------- Phone: the shelves only ----------
 * No room painting on phones (D56): under the heading, one continuous
 * bookcase, the three shelves stacked with no gaps or headings, each
 * starting with its brass plate as on desktop. Its top edge fades softly
 * into the dark page. Each shelf scrolls sideways; a soft fade at its right
 * edge hints that it does.
 */

@media (max-width: 760px) {
	/* About 32px from the heading's last line to the top of the bookcase. */
	.scene {
		aspect-ratio: auto;
		padding-top: 24px;
	}

	/* The painting is not shown, and room.php gives phones a blank source so it is not downloaded either. */
	.scene > picture {
		display: none;
	}

	.shelf {
		position: static;
		width: auto;
		height: auto;
		margin: 0;
		scroll-margin-top: 1rem;
	}

	.shelf-name {
		display: none;
	}

	/*
	 * The strip, drawn 280px tall: top plank 0 to 7.5%, back panel to 61.5%,
	 * the front of the shelf to 73.5%. Each shelf shows one panel and its
	 * shelf; the second and third leave out the top plank, so the three
	 * stack into one bookcase. Books stand on the shelf at 172px.
	 */
	.shelf .shelf-box {
		position: relative;
		inset: auto;
		height: 206px;
		padding-top: 32px;
		background: url("../images/library-shelf-strip.jpg") center 0 / auto 280px repeat-x;
		background-image: image-set(url("../images/library-shelf-strip.webp") type("image/webp"), url("../images/library-shelf-strip.jpg") type("image/jpeg"));
		background-size: auto 280px;
		background-position: center 0;
		container-type: normal;
	}

	/* The bookcase's top plank fades in from the dark page over its first 24px. */
	.shelf:not(.shelf + .shelf) .shelf-box {
		-webkit-mask-image: linear-gradient(to bottom, transparent, #000 24px);
		mask-image: linear-gradient(to bottom, transparent, #000 24px);
	}

	.shelf + .shelf .shelf-box {
		height: 185px;
		padding-top: 11px;
		background-position: center -21px;
	}

	.shelf .row {
		position: static;
		container-type: size;
		height: 140px;
		width: 100%;
		padding: 0;
		align-items: flex-end;
		overflow-x: auto;
		overflow-y: hidden;
		scrollbar-width: none;
		overscroll-behavior-x: contain;
		-webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 56px), transparent);
		mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 56px), transparent);
	}

	.shelf .row::-webkit-scrollbar {
		display: none;
	}

	/* Room before the plate, and enough after the last book to scroll it clear of the fade. */
	.shelf .row::before {
		content: "";
		flex: 0 0 16px;
	}

	.shelf .row::after {
		content: "";
		flex: 0 0 64px;
	}

	.shelf .plq {
		margin-bottom: 4cqh;
	}

	.shelf .plq span {
		font-size: 11.5px;
		letter-spacing: 0.07em;
	}

	.shelf .shade,
	.shelf-extra {
		display: none;
	}

	.bk--overflow {
		display: block;
	}

	/* A little wider than on desktop, so two lines of the spine title fit. */
	.shelf .bk {
		width: calc(var(--bw) * 1.15);
	}

	.shelf .bk-title {
		font-size: max(11px, 7.8cqh);
		line-height: 1.12;
	}

	.shelf .bk:hover,
	.shelf .bk:focus-visible {
		transform: none;
	}

	.shelf .bk:focus-visible {
		outline: 2px solid #e9d3a1;
		outline-offset: -2px;
	}

	.shelf .slip {
		display: none;
	}
}

/* ---------- The card catalogue, and the archives ---------- */

.catalogue {
	padding: 72px var(--fe-gutter) 120px;
	scroll-margin-top: 1rem;
}

.catalogue__head {
	max-width: 1180px;
	margin: 0 auto 44px;
	text-align: center;
}

.catalogue__eyebrow {
	margin: 0 0 12px;
	font-size: 0.8125rem;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	font-weight: 700;
	color: #c9a45c;
}

.catalogue__title {
	margin: 0;
	font-size: clamp(2rem, 1.5rem + 2vw, 2.5rem);
	color: #f6e7cc;
}

.catalogue__columns {
	max-width: 1180px;
	margin: 0 auto;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
	gap: 48px;
}

.catalogue__column h3 {
	margin: 0 0 18px;
	padding-bottom: 12px;
	font-size: 1.625rem;
	color: #f4ead5;
	border-bottom: 1px solid rgba(233, 211, 161, 0.25);
}

.catalogue__list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.catalogue__list li {
	display: flex;
	justify-content: space-between;
	gap: 16px;
	margin: 0 -10px;
	padding: 9px 10px;
	border-radius: 8px;
	--fe-lift-bg-hover: rgba(233, 211, 161, 0.06);
	--fe-lift-shadow: 0 12px 24px -14px rgba(0, 0, 0, 0.75);
	border-bottom: 1px dotted rgba(233, 211, 161, 0.18);
	font-family: var(--fe-font-reading);
	font-size: 1.125rem;
	line-height: 1.35;
}

.library .catalogue__list li a {
	color: #e4d6c2;
	text-decoration: none;
}

.library .catalogue__list li a:hover {
	color: var(--fe-gold-pale);
	text-decoration: underline;
}

.catalogue__list li span {
	flex: 0 0 auto;
	font-family: var(--fe-font-sans);
	font-size: 0.8125rem;
	color: #a8957e;
	padding-top: 3px;
}

.catalogue__more {
	margin: 18px 0 0;
	font-family: var(--fe-font-reading);
	font-style: italic;
	font-size: 1.0625rem;
}

.library-archive__inner {
	max-width: calc(46rem + 2 * var(--fe-gutter));
	margin: 0 auto;
	padding: 56px var(--fe-gutter) 120px;
}

.library-archive__title {
	margin: 0 0 16px;
	font-size: clamp(2.5rem, 1.75rem + 3vw, 3.75rem);
	line-height: 1.05;
	color: #f6e7cc;
}

.library-archive__lead {
	margin: 0 0 32px;
	font-family: var(--fe-font-reading);
	font-style: italic;
	font-size: 1.25rem;
	color: #d9c7ae;
}

.library-archive .catalogue__list {
	margin-top: 32px;
}

.library-archive .pagination {
	margin-top: 32px;
}

.library .pagination__status,
.library .empty-state {
	color: #c9b9a2;
}

@media (prefers-reduced-motion: reduce) {
	.bk,
	.slip {
		transition: none;
	}
}
