/**
 * RG Library Grid
 *
 * Every selector is scoped under #rg-lib and every class is prefixed rg-lib-,
 * so your existing page CSS for .caln / .rg-ic / .rg-tip / .featured_image /
 * .acf-book-author / .one-fourths cannot reach these cards. That old CSS was
 * overriding the grid with !important, which is what pushed the access badge
 * onto the cover corner and broke the tooltips.
 *
 * Turn on "Also emit legacy class names" in the settings if you need the old
 * names back for a third-party script.
 */

/* --------------------------------------------------------------------------
 * Tokens
 * ----------------------------------------------------------------------- */
#rg-lib {
	--rg-link: #1c6b8c;
	--rg-link-hover: #785897;
	--rg-active-bg: #1d6a9c;
	--rg-active-fg: #ffffff;
	--rg-sub-bg: #e9edee;
	--rg-text: #3a3a3a;
	--rg-muted: #6b7280;
	--rg-border: #e2e6e8;

	/* Icon palette, matching the live dashboard CSS.
	   --rg-icon-active is the same custom property the old stylesheet read,
	   so setting it anywhere on the page still recolours these icons. */
	--rg-icon-active: #745697;
	--rg-icon-ok: #166534;
	--rg-icon-off: #999999;

	--rg-icon-size: 14px;
	--rg-badge-icon-size: 24px;

	--rg-gap: 26px;

	/* The column count the shortcode asked for. --rg-cols derives from it so
	   the responsive rules below can override without losing a specificity
	   fight: the .rg-lib--cols-N classes are ID+class (110) and a media query
	   adds no specificity, so they must not set --rg-cols directly. */
	--rg-cols-desktop: 4;
	--rg-cols: var(--rg-cols-desktop);

	/* Covers are capped by WIDTH and letterboxed into a fixed-height box, so
	   every row lines up whatever aspect ratio the individual cover has.
	   The box height is derived from the standard 212x300 cover ratio
	   (1 / 0.707), which keeps a portrait cover exactly --rg-cover-w wide.
	   --rg-cover-w is written inline by the Cover width setting. */
	--rg-cover-w: 150px;
	--rg-cover-h: calc(var(--rg-cover-w) * 1.415);

	color: var(--rg-text);
	box-sizing: border-box;
}

#rg-lib *,
#rg-lib *::before,
#rg-lib *::after {
	box-sizing: border-box;
}

#rg-lib.rg-lib--cols-2 { --rg-cols-desktop: 2; }
#rg-lib.rg-lib--cols-3 { --rg-cols-desktop: 3; }
#rg-lib.rg-lib--cols-4 { --rg-cols-desktop: 4; }
#rg-lib.rg-lib--cols-5 { --rg-cols-desktop: 5; }
#rg-lib.rg-lib--cols-6 { --rg-cols-desktop: 6; }

/* --------------------------------------------------------------------------
 * Category nav
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-nav {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 14px;
	margin: 0 0 28px;
	padding: 0;
}

#rg-lib .rg-lib-navgroup {
	position: relative;
	display: inline-flex;
	align-items: center;
}

#rg-lib .rg-lib-pill,
#rg-lib .rg-lib-subpill,
#rg-lib .rg-lib-caret {
	appearance: none;
	-webkit-appearance: none;
	background: transparent;
	border: 0;
	margin: 0;
	font: inherit;
	line-height: 1.3;
	color: var(--rg-link);
	cursor: pointer;
	border-radius: 4px;
	box-shadow: none;
	text-transform: none;
	letter-spacing: normal;
	transition: color .15s ease, background-color .15s ease;
}

#rg-lib .rg-lib-pill,
#rg-lib .rg-lib-subpill {
	padding: 6px 4px;
	font-size: 15px;
}

#rg-lib .rg-lib-pill:hover,
#rg-lib .rg-lib-subpill:hover,
#rg-lib .rg-lib-navgroup.is-open .rg-lib-pill,
#rg-lib .rg-lib-navgroup.is-open .rg-lib-caret,
#rg-lib .rg-lib-navgroup.has-active-child .rg-lib-pill {
	color: var(--rg-link-hover);
	background: transparent;
}

#rg-lib .rg-lib-pill:focus-visible,
#rg-lib .rg-lib-subpill:focus-visible,
#rg-lib .rg-lib-caret:focus-visible {
	outline: 2px solid var(--rg-active-bg);
	outline-offset: 2px;
}

#rg-lib .rg-lib-count {
	font-variant-numeric: tabular-nums;
}

#rg-lib .rg-lib-pill.is-active,
#rg-lib .rg-lib-pill.is-active:hover {
	background: var(--rg-active-bg);
	color: var(--rg-active-fg);
	padding: 6px 12px;
}

#rg-lib .rg-lib-caret {
	padding: 6px 4px 6px 2px;
	line-height: 0;
}

#rg-lib .rg-lib-caret svg {
	transition: transform .18s ease;
}

#rg-lib .rg-lib-navgroup.is-open .rg-lib-caret svg {
	transform: rotate(180deg);
}

/* Submenu */
#rg-lib .rg-lib-submenu {
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	z-index: 30;
	min-width: 260px;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 2px;
	padding: 14px 18px;
	background: var(--rg-sub-bg);
	border-radius: 4px;
	box-shadow: 0 6px 20px rgba(0, 0, 0, .08);
}

#rg-lib .rg-lib-submenu[hidden] {
	display: none;
}

#rg-lib .rg-lib-subpill {
	width: 100%;
	text-align: left;
	padding: 7px 0;
}

#rg-lib .rg-lib-subpill.is-active {
	color: var(--rg-link-hover);
	font-weight: 600;
}

/* --------------------------------------------------------------------------
 * Grid
 *
 * The clearfix pseudo-elements that themes attach to .row become grid items
 * and leave phantom empty cells, so they are switched off here. The grid no
 * longer carries .row at all, this is belt and braces.
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-grid {
	display: grid;
	grid-template-columns: repeat(var(--rg-cols), minmax(0, 1fr));
	gap: var(--rg-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

#rg-lib .rg-lib-grid::before,
#rg-lib .rg-lib-grid::after {
	display: none !important;
	content: none !important;
}

#rg-lib .rg-lib-item {
	float: none;
	width: auto;
	max-width: none;
	padding: 0;
	margin: 0;
	position: relative;
	display: flex;
	flex-direction: column;
	min-width: 0;
}

/* Phones and tablets in portrait: two columns.
   1023px catches every phone, every iPad in portrait up to the 11 inch, and
   a narrow desktop window. */
@media (max-width: 1023px) {
	#rg-lib {
		--rg-cols: 2;
		--rg-gap: 20px;
	}
}

/* The 12.9 inch iPad is 1024px wide in portrait, the same width as a regular
   iPad in landscape, so width alone cannot tell them apart. Orientation can.
   Capped at 1366px so a genuinely large portrait display is left alone. */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: portrait) {
	#rg-lib {
		--rg-cols: 2;
		--rg-gap: 22px;
	}
}

@media (max-width: 690px) {
	#rg-lib { --rg-gap: 16px; }
	#rg-lib .rg-lib-submenu { min-width: min(80vw, 300px); }
	#rg-lib .rg-lib-nav { gap: 4px 12px; }
}

@media (max-width: 420px) {
	#rg-lib { --rg-gap: 12px; }
	#rg-lib .rg-lib-pill,
	#rg-lib .rg-lib-subpill { font-size: 14px; }
}

/* --------------------------------------------------------------------------
 * Card
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-card {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	flex: 1 1 auto;
	width: 100%;
}

#rg-lib .rg-lib-cardlink {
	display: block;
	width: 100%;
	text-decoration: none;
	color: inherit;
	border: 0;
}

#rg-lib .rg-lib-cardlink:hover,
#rg-lib .rg-lib-cardlink:focus {
	text-decoration: none;
	color: inherit;
}

/* Fixed-height cover box, images sit on a shared baseline. */
#rg-lib .rg-lib-thumb {
	position: relative;
	display: flex;
	justify-content: center;
	align-items: flex-end;
	height: var(--rg-cover-h);
}

#rg-lib .rg-lib-thumb img {
	display: block;
	width: auto;
	height: auto;
	max-width: min(var(--rg-cover-w), 100%);
	max-height: 100%;
	border-radius: 10px;
	box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
	transition: transform .18s ease, box-shadow .18s ease;
}

#rg-lib .rg-lib-cardlink:hover .rg-lib-thumb img {
	transform: translateY(-3px);
	box-shadow: 0 10px 26px rgba(0, 0, 0, .2);
}

/* Two lines reserved, so the icon rows align across a row of cards even when
   one book has three authors and its neighbour has none. */
#rg-lib .rg-lib-author {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	min-height: 2.7em;
	margin: 12px 0 0;
	font-size: 14px;
	line-height: 1.35;
	text-align: center;
	color: grey;
}

/* --------------------------------------------------------------------------
 * Access badge, centred above the cover
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-tagwrap {
	position: static;
	display: flex;
	justify-content: center;
	align-items: flex-end;
	min-height: 32px;
	margin: 0 0 6px;
}

#rg-lib .rg-lib-badgewrap {
	position: static;
	display: flex;
	justify-content: center;
}

#rg-lib .rg-lib-badge {
	text-align: center;
}

/* --------------------------------------------------------------------------
 * Icon rows and tooltips
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-icons {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	margin: 10px 0;
	padding: 0;
}

#rg-lib .rg-lib-tagwrap .rg-lib-icons {
	margin: 0;
}

#rg-lib .rg-lib-ic {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: default;
	outline: none;
}

#rg-lib .rg-lib-ic svg {
	display: block;
	width: var(--rg-icon-size);
	height: var(--rg-icon-size);
	overflow: visible;
	transition: opacity .15s ease, color .15s ease;
}

/* The access badge above the cover runs larger than the content row. */
#rg-lib .rg-lib-tagwrap .rg-lib-ic svg {
	width: var(--rg-badge-icon-size);
	height: var(--rg-badge-icon-size);
}

/* Tone, not state: green for granted access, purple for the content types
   and the credit coin, grey for anything unavailable. */
#rg-lib .rg-lib-ic.is-accent { color: var(--rg-icon-active); }
#rg-lib .rg-lib-ic.is-ok { color: var(--rg-icon-ok); }
#rg-lib .rg-lib-ic.is-off { color: var(--rg-icon-off); }

/* --------------------------------------------------------------------------
 * Tooltip. White card below the icon, matching the live dashboard.
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-tip {
	position: absolute;
	top: calc(100% + 8px);
	left: 50%;
	z-index: 9999;
	display: block;
	width: max-content;
	max-width: 220px;
	padding: 8px 10px;
	background: #fff;
	border: 1px solid rgba(0, 0, 0, .12);
	border-radius: 10px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
	color: var(--rg-text);
	font-size: 12px;
	font-weight: 400;
	line-height: 1.2;
	text-align: center;
	white-space: normal;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateX(-50%);
	transition: opacity .12s ease, transform .12s ease, visibility .12s ease;
}

#rg-lib .rg-lib-tip::before {
	content: "";
	position: absolute;
	top: -6px;
	left: 50%;
	width: 10px;
	height: 10px;
	background: #fff;
	border-left: 1px solid rgba(0, 0, 0, .12);
	border-top: 1px solid rgba(0, 0, 0, .12);
	transform: translateX(-50%) rotate(45deg);
}

#rg-lib .rg-lib-ic:hover .rg-lib-tip,
#rg-lib .rg-lib-ic:focus .rg-lib-tip,
#rg-lib .rg-lib-ic:focus-within .rg-lib-tip {
	opacity: 1;
	visibility: visible;
	transform: translateX(-50%) translateY(2px);
}

#rg-lib .rg-lib-tip strong {
	display: block;
	margin-bottom: 2px;
	font-weight: 600;
	color: var(--rg-text);
}

#rg-lib .rg-lib-tip .rg-lib-yes { color: #22c55e; font-weight: 600; }
#rg-lib .rg-lib-tip .rg-lib-no { color: var(--rg-icon-off); font-weight: 600; }

/* --------------------------------------------------------------------------
 * Gift flag
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-gift {
	position: absolute;
	left: 50%;
	top: -10px;
	z-index: 5;
	transform: translateX(-50%);
}

#rg-lib .rg-lib-gift span {
	display: inline-block;
	color: #fff;
	background: var(--rg-link-hover);
	padding: 2px 8px;
	border-radius: 4px;
	font-size: 12px;
	line-height: 1.5;
	white-space: nowrap;
}

/* --------------------------------------------------------------------------
 * Shelves widget, pinned to the bottom of the card
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-shelves {
	width: 100%;
	margin-top: auto;
	padding-top: 5px;
	text-align: center;
}

#rg-lib .rg-lib-shelves:empty {
	padding-top: 0;
}

/* --------------------------------------------------------------------------
 * Load More, status, empty
 * ----------------------------------------------------------------------- */
#rg-lib .rg-lib-more {
	display: flex;
	justify-content: center;
	margin: 40px 0 0;
}

#rg-lib .rg-lib-loadmore {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 13px 34px;
	border: 1.5px solid var(--rg-active-bg);
	border-radius: 50px;
	background: #fff;
	color: var(--rg-active-bg);
	font: inherit;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color .15s ease, color .15s ease;
}

#rg-lib .rg-lib-loadmore:hover:not(:disabled) {
	background: var(--rg-active-bg);
	color: #fff;
}

#rg-lib .rg-lib-loadmore:disabled {
	opacity: .65;
	cursor: default;
}

#rg-lib .rg-lib-loadmore[hidden] { display: none; }

#rg-lib .rg-lib-spinner {
	display: none;
	width: 14px;
	height: 14px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: rg-lib-spin .7s linear infinite;
}

#rg-lib .rg-lib-loadmore.is-loading .rg-lib-spinner { display: inline-block; }

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

@media (prefers-reduced-motion: reduce) {
	#rg-lib .rg-lib-spinner { animation-duration: 2s; }
	#rg-lib .rg-lib-thumb img,
	#rg-lib .rg-lib-tip { transition: none; }
}

#rg-lib .rg-lib-empty,
#rg-lib .rg-lib-status {
	margin: 28px 0 0;
	text-align: center;
	color: var(--rg-muted);
	font-size: 15px;
}

#rg-lib .rg-lib-empty[hidden] { display: none; }

.rg-lib-error {
	padding: 20px;
	border: 1px solid #e2e6e8;
	border-radius: 6px;
	text-align: center;
	color: #6b7280;
}
