.fel-library,
.fel-courses,
.fel-empty,
.fel-modal {
	--fel-navy: #12304a;
	--fel-teal: #087f8c;
	--fel-teal-light: #eaf6f7;
	--fel-gold: #f4b942;
	--fel-gold-dark: #dfa62c;
	--fel-surface: #ffffff;
	--fel-surface-2: #f5f7f9;
	--fel-border: #e3e8ec;
	--fel-ink: #1f2933;
	--fel-muted: #64748b;
	--fel-radius: 14px;
	--fel-font-heading: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	--fel-font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	--fel-shadow: 0 1px 2px rgba( 18, 48, 74, 0.06 ), 0 4px 14px rgba( 18, 48, 74, 0.07 );
	--fel-shadow-hover: 0 2px 4px rgba( 18, 48, 74, 0.06 ), 0 16px 32px rgba( 18, 48, 74, 0.14 );
	font-family: var( --fel-font-body );
}

.fel-library,
.fel-library * {
	box-sizing: border-box;
}

/* ---------- Library layout: filters left, results right ---------- */

.fel-library {
	container-type: inline-size;
	width: 100%;
	margin: 28px 0;
}

.fel-library-inner.has-filters {
	display: grid;
	grid-template-columns: 240px minmax( 0, 1fr );
	gap: 28px;
	align-items: start;
}

/* ---------- Filter sidebar ---------- */

.fel-filters {
	position: sticky;
	top: 24px;
	background: var( --fel-surface );
	border: 1px solid var( --fel-border );
	border-radius: var( --fel-radius );
	padding: 18px 12px 12px;
	box-shadow: var( --fel-shadow );
}

.fel-filters-title {
	margin: 0 8px 12px !important;
	font-family: var( --fel-font-body );
	font-size: 0.72em;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var( --fel-muted );
}

.fel-filter-list {
	list-style: none;
	margin: 0 !important;
	padding: 0 !important;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.fel-filter-list li {
	margin: 0;
	padding: 0;
}

.fel-filter-list li::before,
.fel-filter-list li::marker {
	content: none;
}

.fel-filter {
	all: unset;
	box-sizing: border-box;
	position: relative;
	display: flex !important;
	align-items: center !important;
	justify-content: space-between !important;
	gap: 10px;
	width: 100% !important;
	max-width: none !important;
	margin: 0 !important;
	padding: 10px 12px !important;
	border-radius: 10px;
	text-align: left !important;
	background: transparent !important;
	border: none !important;
	box-shadow: none !important;
	color: var( --fel-ink ) !important;
	font-family: var( --fel-font-body );
	font-size: 0.92em;
	font-weight: 500;
	line-height: 1.3;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.fel-filter:hover {
	background: var( --fel-surface-2 ) !important;
}

.fel-filter:focus-visible {
	outline: 2px solid var( --fel-teal );
	outline-offset: 1px;
}

.fel-filter.is-active {
	background: var( --fel-teal-light ) !important;
	color: var( --fel-teal ) !important;
	font-weight: 600;
}

.fel-filter.is-active::before {
	content: "";
	position: absolute;
	left: 0;
	top: 8px;
	bottom: 8px;
	width: 3px;
	border-radius: 0 3px 3px 0;
	background: var( --fel-teal );
}

.fel-filter-name {
	flex: 1 1 auto;
	min-width: 0;
	text-align: left;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.fel-filter-count {
	flex: 0 0 auto;
	display: inline-block !important;
	margin-left: auto !important;
	min-width: 28px !important;
	padding: 2px 8px !important;
	border-radius: 999px !important;
	line-height: 1.5 !important;
	background: var( --fel-surface-2 );
	color: var( --fel-muted );
	font-size: 0.8em;
	font-weight: 600;
	text-align: center;
	font-variant-numeric: tabular-nums;
	transition: background 0.15s ease, color 0.15s ease;
}

.fel-filter.is-active .fel-filter-count {
	background: var( --fel-teal );
	color: #fff;
}

/* ---------- Results ---------- */

.fel-results {
	container-type: inline-size;
	min-width: 0;
}

.fel-results-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 24px;
	margin-bottom: 16px;
}

.fel-results-count {
	font-size: 0.9em;
	font-weight: 600;
	color: var( --fel-muted );
}

.fel-spinner.fel-results-spinner {
	width: 16px;
	height: 16px;
	border-width: 2px;
	opacity: 0;
	transition: opacity 0.15s ease;
}

.fel-results.is-loading .fel-results-spinner {
	opacity: 1;
}

.fel-results-body {
	transition: opacity 0.2s ease;
}

.fel-results.is-loading .fel-results-body {
	opacity: 0.45;
	pointer-events: none;
}

/* ---------- Grid ---------- */

.fel-grid {
	display: grid;
	grid-template-columns: repeat( var( --fel-columns, 3 ), minmax( 0, 1fr ) );
	gap: 24px;
}

@container ( max-width: 680px ) {
	.fel-grid {
		grid-template-columns: repeat( 2, minmax( 0, 1fr ) );
		gap: 16px;
	}
}

@container ( max-width: 420px ) {
	.fel-grid {
		grid-template-columns: 1fr;
	}
}

/* ---------- Card ---------- */

.fel-card {
	position: relative;
	display: flex;
	flex-direction: column;
	min-width: 0;
	background: var( --fel-surface );
	border: 1px solid var( --fel-border );
	border-radius: var( --fel-radius );
	overflow: hidden;
	box-shadow: var( --fel-shadow );
	cursor: pointer;
	transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.fel-card:hover,
.fel-card:focus-visible {
	transform: translateY( -4px );
	box-shadow: var( --fel-shadow-hover );
	border-color: #cfe3e6;
}

.fel-card:focus-visible {
	outline: 2px solid var( --fel-teal );
	outline-offset: 3px;
}

/* Cover: a real cover image sits on a soft backdrop like a physical book;
   books without one get a generated cover in one of four brand tones. */
.fel-card-cover {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 210px;
	padding: 20px 20px 18px;
	background: linear-gradient( 180deg, var( --fel-surface-2 ) 0%, #e9eef2 100% );
	border-bottom: 1px solid var( --fel-border );
	overflow: hidden;
}

.fel-card-cover .fel-card-cover-img {
	display: block;
	width: auto !important;
	height: auto !important;
	max-width: 100%;
	max-height: 100%;
	margin: 0;
	border-radius: 3px 6px 6px 3px;
	box-shadow: 0 2px 4px rgba( 18, 48, 74, 0.12 ), 0 10px 22px rgba( 18, 48, 74, 0.22 );
	transition: transform 0.25s ease;
}

.fel-card:hover .fel-card-cover-img,
.fel-card:focus-visible .fel-card-cover-img {
	transform: scale( 1.04 );
}

.fel-card-cover.is-placeholder {
	--fel-tone-a: var( --fel-navy );
	--fel-tone-b: var( --fel-teal );
	background: radial-gradient( circle at 85% 10%, rgba( 255, 255, 255, 0.16 ) 0, transparent 45% ),
		linear-gradient( 135deg, var( --fel-tone-a ) 0%, var( --fel-tone-b ) 100% );
	border-bottom: none;
}

.fel-card-cover.is-placeholder[data-tone="1"] {
	--fel-tone-a: #0b5f69;
	--fel-tone-b: #2aa198;
}

.fel-card-cover.is-placeholder[data-tone="2"] {
	--fel-tone-a: #1d3557;
	--fel-tone-b: #457b9d;
}

.fel-card-cover.is-placeholder[data-tone="3"] {
	--fel-tone-a: #213547;
	--fel-tone-b: #3d6b7d;
}

.fel-cover-book {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	max-width: 100%;
	color: #fff;
	text-align: center;
	transition: transform 0.25s ease;
}

.fel-card:hover .fel-cover-book,
.fel-card:focus-visible .fel-cover-book {
	transform: translateY( -2px );
}

.fel-cover-book svg {
	width: 38px;
	height: 38px;
	padding: 10px;
	box-sizing: content-box;
	border-radius: 14px;
	background: rgba( 255, 255, 255, 0.14 );
}

.fel-cover-title {
	font-family: var( --fel-font-heading );
	font-weight: 600;
	font-size: 0.95em;
	line-height: 1.35;
	color: rgba( 255, 255, 255, 0.92 );
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.fel-card-badge {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	background: rgba( 255, 255, 255, 0.95 );
	color: var( --fel-teal );
	font-family: var( --fel-font-body );
	font-size: 10.5px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	padding: 5px 10px;
	border-radius: 999px;
	box-shadow: 0 2px 6px rgba( 18, 48, 74, 0.14 );
}

.fel-card-badge.is-members {
	background: var( --fel-gold );
	color: var( --fel-navy );
}

.fel-card-badge svg {
	width: 11px;
	height: 11px;
}

.fel-card-body {
	display: flex;
	flex-direction: column;
	flex-grow: 1;
	padding: 18px 18px 16px;
}

.fel-card-category {
	align-self: flex-start;
	margin-bottom: 8px;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 0.72em;
	font-weight: 700;
	letter-spacing: 0.07em;
	text-transform: uppercase;
	color: var( --fel-teal );
}

.fel-card-title {
	margin: 0 0 8px !important;
	padding: 0;
	font-family: var( --fel-font-heading );
	font-weight: 600;
	font-size: 1.02em;
	line-height: 1.4;
	color: var( --fel-navy );
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.fel-card-excerpt {
	margin: 0 0 16px !important;
	color: var( --fel-muted );
	font-size: 0.88em;
	line-height: 1.6;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.fel-card-footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-top: auto;
	padding-top: 14px;
	border-top: 1px solid var( --fel-border );
}

.fel-card-format {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 0.78em;
	font-weight: 600;
	letter-spacing: 0.04em;
	color: var( --fel-muted );
}

.fel-card-format svg {
	width: 14px;
	height: 14px;
}

.fel-preview-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 14px;
	border-radius: 999px;
	background: var( --fel-gold );
	color: var( --fel-navy );
	font-family: var( --fel-font-body );
	font-size: 0.84em;
	font-weight: 600;
	line-height: 1;
	white-space: nowrap;
	transition: background 0.15s ease;
}

.fel-card:hover .fel-preview-btn,
.fel-card:focus-visible .fel-preview-btn {
	background: var( --fel-gold-dark );
}

.fel-preview-btn .fel-icon-eye {
	width: 15px;
	height: 15px;
	fill: currentColor;
	flex-shrink: 0;
}

/* ---------- Empty state ---------- */

.fel-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	padding: 56px 20px;
	color: var( --fel-muted );
	text-align: center;
	background: var( --fel-surface-2 );
	border: 1px dashed var( --fel-border );
	border-radius: var( --fel-radius );
}

.fel-empty svg {
	width: 40px;
	height: 40px;
	color: #c3ccd5;
}

.fel-empty p {
	margin: 0;
	font-size: 0.95em;
}

/* ---------- Narrow layouts: filters become a scrollable chip strip ---------- */

@container ( max-width: 760px ) {
	.fel-library-inner.has-filters {
		grid-template-columns: minmax( 0, 1fr );
		gap: 18px;
	}

	.fel-filters {
		position: static;
		padding: 0;
		background: transparent;
		border: none;
		box-shadow: none;
	}

	.fel-filters-title {
		display: none;
	}

	.fel-filter-list {
		flex-direction: row;
		gap: 8px;
		overflow-x: auto;
		padding: 2px 2px 8px !important;
		scrollbar-width: thin;
		-webkit-overflow-scrolling: touch;
	}

	.fel-filter {
		width: auto !important;
		padding: 8px 10px 8px 14px !important;
		border-radius: 999px;
		background: var( --fel-surface ) !important;
		border: 1px solid var( --fel-border ) !important;
		white-space: nowrap;
	}

	.fel-filter.is-active {
		background: var( --fel-teal ) !important;
		border-color: var( --fel-teal ) !important;
		color: #fff !important;
	}

	.fel-filter.is-active::before {
		display: none;
	}

	.fel-filter.is-active .fel-filter-count {
		background: rgba( 255, 255, 255, 0.22 );
	}

	.fel-filter-name {
		overflow: visible;
	}
}

@container ( max-width: 420px ) {
	.fel-card-cover {
		height: 190px;
	}
}

/* ---------- Modal ---------- */

.fel-modal,
.fel-modal * {
	box-sizing: border-box;
}

.fel-modal {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
}

body.fel-modal-open {
	overflow: hidden;
}

.fel-modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba( 18, 48, 74, 0.6 );
	backdrop-filter: blur( 2px );
}

.fel-modal-dialog {
	position: relative;
	background: var( --fel-surface );
	border-radius: 20px;
	width: min( 880px, 100% );
	max-height: 92vh;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	box-shadow: 0 16px 40px rgba( 18, 48, 74, 0.28 );
}

.fel-modal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 18px 22px;
	border-bottom: 1px solid var( --fel-border );
	background: var( --fel-surface );
}

.fel-modal-heading {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

.fel-icon-doc {
	width: 26px;
	height: 26px;
	flex-shrink: 0;
	color: var( --fel-navy );
}

.fel-modal-heading h2 {
	margin: 0;
	font-family: var( --fel-font-heading );
	font-size: 1.05em;
	font-weight: 700;
	color: var( --fel-navy );
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.fel-modal-subtitle {
	display: block;
	font-size: 0.78em;
	color: var( --fel-muted );
	margin-top: 2px;
}

.fel-modal-close {
	all: unset;
	box-sizing: border-box;
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 999px;
	background: transparent !important;
	border: none !important;
	box-shadow: none !important;
	color: var( --fel-muted );
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.fel-modal-close:hover,
.fel-modal-close:focus-visible {
	background: var( --fel-surface-2 ) !important;
	color: var( --fel-navy );
}

.fel-modal-close svg {
	width: 16px;
	height: 16px;
}

.fel-viewer {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	flex-grow: 1;
	background: var( --fel-teal-light );
	user-select: none;
	-webkit-user-select: none;
}

.fel-viewer-canvas-wrap {
	position: relative;
	overflow: auto;
	flex-grow: 1;
	display: flex;
	justify-content: center;
	align-items: flex-start;
	padding: 26px;
}

.fel-viewer-canvas {
	display: block;
	background: #fff;
	box-shadow: 0 2px 10px rgba( 18, 48, 74, 0.18 );
	border-radius: 4px;
	max-width: 100%;
	height: auto;
	flex-shrink: 0;
	pointer-events: none; /* Blocks the browser's built-in image "save/copy" context actions on the canvas. */
}

.fel-viewer-loading {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	background: var( --fel-teal-light );
}

.fel-spinner {
	width: 30px;
	height: 30px;
	border: 3px solid rgba( 18, 48, 74, 0.15 );
	border-top-color: var( --fel-navy );
	border-radius: 50%;
	animation: fel-spin 0.75s linear infinite;
}

@keyframes fel-spin {
	to {
		transform: rotate( 360deg );
	}
}

.fel-viewer-loading-text {
	font-size: 0.85em;
	font-weight: 600;
	color: var( --fel-navy );
}

.fel-viewer-status {
	text-align: center;
	color: var( --fel-navy );
	background: transparent;
	margin: 0;
	padding: 0 16px 14px;
	font-size: 0.85em;
}

.fel-viewer-toolbar {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 14px;
	padding: 12px;
	background: var( --fel-surface );
	border-top: 1px solid var( --fel-border );
}

.fel-viewer-toolbar button {
	all: unset;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	border-radius: 999px;
	background: var( --fel-surface-2 ) !important;
	border: none !important;
	box-shadow: none !important;
	color: var( --fel-navy );
	font-family: var( --fel-font-body );
	font-size: 0.88em;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.fel-viewer-toolbar button:hover:not( :disabled ) {
	background: var( --fel-teal-light ) !important;
	color: var( --fel-teal );
}

.fel-viewer-toolbar button:disabled {
	opacity: 0.4;
	cursor: default;
}

.fel-viewer-toolbar button svg {
	width: 15px;
	height: 15px;
}

.fel-viewer-page-info {
	font-size: 0.85em;
	font-weight: 600;
	color: var( --fel-muted );
	min-width: 90px;
	text-align: center;
}

@media ( max-width: 480px ) {
	.fel-modal {
		padding: 8px;
	}

	.fel-modal-dialog {
		border-radius: 16px;
		max-height: 96vh;
	}

	.fel-modal-header {
		padding: 14px 16px;
	}

	.fel-modal-subtitle {
		display: none;
	}

	.fel-viewer-canvas-wrap {
		padding: 14px;
	}

	.fel-viewer-toolbar {
		gap: 8px;
	}

	.fel-viewer-toolbar .fel-btn-label {
		display: none;
	}

	.fel-viewer-page-info {
		min-width: 0;
	}
}
