/*
 * Radio Directory WP - "Radio Directory Loop" block: base styles.
 * Stable, prefixed classes (.rdw-loop*) that themes can override.
 * Loaded only where the block is rendered (and in the editor preview).
 * The Play buttons are driven by the plugin's existing player.js / station.css.
 */

.rdw-loop {
	container: rdw-loop / inline-size;
	margin-block: 1.5em;
}

.rdw-loop .rdw-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.rdw-loop__items,
.rdw-loop__children {
	margin: 0;
	padding: 0;
	list-style: none;
}

.rdw-loop__item {
	min-width: 0;
	margin: 0;
}

.rdw-loop__empty {
	padding: 1em;
	border: 1px dashed rgba(127, 127, 127, 0.5);
	border-radius: 8px;
	text-align: center;
}

/* ---------------------------------------------------------------- */
/* Grid columns: desktop value, reduced by the block's own width     */
/* ---------------------------------------------------------------- */

.rdw-loop--grid > .rdw-loop__items {
	display: grid;
	grid-template-columns: repeat(var(--rdw-loop-cols, 4), minmax(0, 1fr));
	gap: 28px 20px;
}

.rdw-loop--cols-1 > .rdw-loop__items {
	--rdw-loop-cols: 1;
}

.rdw-loop--cols-2 > .rdw-loop__items {
	--rdw-loop-cols: 2;
}

.rdw-loop--cols-3 > .rdw-loop__items {
	--rdw-loop-cols: 3;
}

.rdw-loop--cols-4 > .rdw-loop__items {
	--rdw-loop-cols: 4;
}

.rdw-loop--cols-5 > .rdw-loop__items {
	--rdw-loop-cols: 5;
}

.rdw-loop--cols-6 > .rdw-loop__items {
	--rdw-loop-cols: 6;
}

@container rdw-loop (max-width: 1000px) {
	.rdw-loop--cols-5 > .rdw-loop__items,
	.rdw-loop--cols-6 > .rdw-loop__items {
		--rdw-loop-cols: 4;
	}
}

/* Term cards hold a name (plus an optional icon and count): six of them need a little more room than station images. */
@container rdw-loop (min-width: 1001px) and (max-width: 1100px) {
	.rdw-loop--taxonomies.rdw-loop--cols-6 > .rdw-loop__items {
		--rdw-loop-cols: 5;
	}
}

@container rdw-loop (max-width: 760px) {
	.rdw-loop--cols-4 > .rdw-loop__items,
	.rdw-loop--cols-5 > .rdw-loop__items,
	.rdw-loop--cols-6 > .rdw-loop__items {
		--rdw-loop-cols: 3;
	}
}

@container rdw-loop (max-width: 520px) {
	.rdw-loop--cols-3 > .rdw-loop__items,
	.rdw-loop--cols-4 > .rdw-loop__items,
	.rdw-loop--cols-5 > .rdw-loop__items,
	.rdw-loop--cols-6 > .rdw-loop__items {
		--rdw-loop-cols: 2;
	}
}

/* ---------------------------------------------------------------- */
/* Stations                                                          */
/* ---------------------------------------------------------------- */

.rdw-loop-station {
	min-width: 0;
}

.rdw-loop-station__media {
	position: relative;
	flex: 0 0 auto;
}

.rdw-loop-station__image {
	display: block;
	overflow: hidden;
	aspect-ratio: 1 / 1;
	background: rgba(127, 127, 127, 0.12);
	border-radius: 10px;
}

.rdw-loop-station__image img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.rdw-loop-station__placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	opacity: 0.45;
}

.rdw-loop-station__placeholder .rdw-loop-icon {
	width: 40%;
	height: 40%;
}

.rdw-loop-station__body {
	min-width: 0;
}

.rdw-loop .rdw-loop-station__title {
	margin: 10px 0 0;
	font-size: 1rem;
	line-height: 1.3;
	overflow-wrap: anywhere;
}

.rdw-loop-station__title a {
	color: inherit;
	text-decoration: none;
}

.rdw-loop-station__title a:hover {
	text-decoration: underline;
}

.rdw-loop .rdw-loop-station__meta {
	margin: 2px 0 0;
	font-size: 0.85em;
	opacity: 0.75;
}

/* Player wrapper: keep the player contract, drop the plugin card box styles. */
.rdw-loop .rdw-player.rdw-loop-player {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 0;
	color: inherit;
	background: transparent;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	container-type: normal;
	font-size: inherit;
	pointer-events: none;
}

.rdw-loop-player [hidden] {
	display: none !important;
}

.rdw-loop-icon {
	display: block;
	width: 24px;
	height: 24px;
	fill: currentColor;
}

.rdw-loop .rdw-loop-play {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	margin: 0;
	padding: 0;
	color: #ffffff;
	background: rgba(17, 24, 39, 0.72);
	border: 2px solid rgba(255, 255, 255, 0.85);
	border-radius: 50%;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
	cursor: pointer;
	pointer-events: auto;
}

.rdw-loop .rdw-loop-play:hover,
.rdw-loop-player[data-rdw-state="playing"] .rdw-loop-play,
.rdw-loop-player[data-rdw-state="connecting"] .rdw-loop-play {
	background: #4338ca;
}

.rdw-loop .rdw-loop-play:focus-visible,
.rdw-loop-term:focus-visible {
	outline: 3px solid #2563eb;
	outline-offset: 2px;
}

/* player.js toggles .is-active while playing/connecting. */
.rdw-loop-play .rdw-loop-icon--pause,
.rdw-loop-play.is-active .rdw-loop-icon--play {
	display: none;
}

.rdw-loop-play.is-active .rdw-loop-icon--pause {
	display: block;
}

/* List: one row per station. */
.rdw-loop--stations.rdw-loop--list > .rdw-loop__items {
	display: grid;
	gap: 14px;
}

.rdw-loop--stations.rdw-loop--list .rdw-loop-station {
	display: flex;
	align-items: center;
	gap: 16px;
	padding-bottom: 14px;
	border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.rdw-loop--stations.rdw-loop--list .rdw-loop-station__media {
	width: 88px;
}

.rdw-loop--stations.rdw-loop--list .rdw-loop-station__title {
	margin-top: 0;
}

/* Compact: small rows, several per line when there is room. */
.rdw-loop--stations.rdw-loop--compact > .rdw-loop__items {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
	gap: 12px 20px;
}

.rdw-loop--stations.rdw-loop--compact .rdw-loop-station {
	display: flex;
	align-items: center;
	gap: 12px;
}

.rdw-loop--stations.rdw-loop--compact .rdw-loop-station__media {
	width: 56px;
}

.rdw-loop--stations.rdw-loop--compact .rdw-loop-station__image {
	border-radius: 8px;
}

.rdw-loop--stations.rdw-loop--compact .rdw-loop-play,
.rdw-loop--stations.rdw-loop--list .rdw-loop-play {
	width: 34px;
	height: 34px;
	border-width: 1.5px;
}

.rdw-loop--stations.rdw-loop--compact .rdw-loop-play .rdw-loop-icon,
.rdw-loop--stations.rdw-loop--list .rdw-loop-play .rdw-loop-icon {
	width: 18px;
	height: 18px;
}

.rdw-loop--stations.rdw-loop--compact .rdw-loop-station__title {
	margin: 0;
	font-size: 0.95rem;
}

/* ---------------------------------------------------------------- */
/* Terms                                                             */
/* ---------------------------------------------------------------- */

.rdw-loop-term {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	color: inherit;
	text-decoration: none;
}

.rdw-loop-term:hover .rdw-loop-term__name {
	text-decoration: underline;
}

.rdw-loop-term__name {
	font-weight: 600;
	overflow-wrap: anywhere;
}

.rdw-loop-term__count {
	display: inline-block;
	min-width: 1.75em;
	padding: 0 0.5em;
	border: 1px solid rgba(127, 127, 127, 0.35);
	border-radius: 999px;
	font-size: 0.8em;
	line-height: 1.6;
	text-align: center;
}

/*
 * Optional term image/icon (rendered only when the term has one, so terms
 * without an image keep exactly the previous layout): small (22 px; 20 px for
 * child terms and Compact), contained (flags and icons keep their shape), at
 * the start of the name on the same line, 8 px before it (the link's gap).
 */
.rdw-loop-term__media {
	display: inline-flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: flex-start;
}

.rdw-loop .rdw-loop-term__image {
	display: block;
	width: var(--rdw-term-image-size, 22px);
	max-width: none;
	height: var(--rdw-term-image-size, 22px);
	object-fit: contain;
}

.rdw-loop__children .rdw-loop-term__media,
.rdw-loop--taxonomies.rdw-loop--compact .rdw-loop-term__media {
	--rdw-term-image-size: 20px;
}

/* Grid: one card per top-level term, children listed inside. */
.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items {
	gap: 16px;
}

.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item {
	border: 1px solid rgba(127, 127, 127, 0.3);
	border-radius: 10px;
}

/* The top-level link fills the card's header row: whole row clickable, count at the end. */
.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 4px 8px;
	padding: 14px 16px;
	border-radius: 9px;
}

/* Whole words stay together; the count moves below a name that needs the full width. */
.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term .rdw-loop-term__name {
	min-width: 0;
	font-size: 1.1rem;
	line-height: 1.35;
	overflow-wrap: break-word;
}

.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term .rdw-loop-term__count {
	flex: 0 0 auto;
}

.rdw-loop--taxonomies.rdw-loop--grid .rdw-loop__children {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 12px;
	padding: 0 16px 14px;
	font-size: 0.9em;
}

/*
 * Grid card of a term with an image: the image stays at the start of the
 * name on the same line (never on a row of its own) and the name wraps next
 * to it; the count stays at the end of the row and moves under it only when
 * the card is too narrow for both (same as cards without an image).
 */
.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term--has-image {
	align-items: flex-start;
}

/* Centred on the first line of the name (its font-size × line-height). */
.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term--has-image > .rdw-loop-term__media {
	height: calc(1.1rem * 1.35);
}

/*
 * The name keeps its natural width, capped at the room next to the image
 * (22px image + 8px gap): the count wraps only when it does not fit, and the
 * name itself never wraps below the image.
 */
.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term--has-image > .rdw-loop-term__name {
	flex: 1 1 auto;
	max-width: calc(100% - 30px);
}

.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term--has-image > .rdw-loop-term__count {
	align-self: center;
}

/* Narrow cards (two or three columns): a slightly smaller name, so whole words fit next to the image. */
@container rdw-loop (max-width: 600px) {
	.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term--has-image > .rdw-loop-term__name {
		font-size: 1rem;
		hyphens: auto;
	}

	.rdw-loop--taxonomies.rdw-loop--grid > .rdw-loop__items > .rdw-loop__item > .rdw-loop-term--has-image > .rdw-loop-term__media {
		height: calc(1rem * 1.35);
	}
}

/* List: nested, indented. */
.rdw-loop--taxonomies.rdw-loop--list .rdw-loop__item {
	padding: 6px 0;
}

.rdw-loop--taxonomies.rdw-loop--list > .rdw-loop__items > .rdw-loop__item {
	border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.rdw-loop--taxonomies.rdw-loop--list .rdw-loop__children {
	margin-top: 4px;
	padding-left: 1.25em;
	border-left: 2px solid rgba(127, 127, 127, 0.25);
}

/* Compact: pills; children follow their parent inside the same item. */
.rdw-loop--taxonomies.rdw-loop--compact > .rdw-loop__items,
.rdw-loop--taxonomies.rdw-loop--compact .rdw-loop__children {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.rdw-loop--taxonomies.rdw-loop--compact > .rdw-loop__items > .rdw-loop__item {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.rdw-loop--taxonomies.rdw-loop--compact .rdw-loop-term {
	padding: 4px 12px;
	border: 1px solid rgba(127, 127, 127, 0.35);
	border-radius: 999px;
	font-size: 0.9em;
}

.rdw-loop--taxonomies.rdw-loop--compact .rdw-loop__children .rdw-loop-term {
	font-size: 0.8em;
	opacity: 0.85;
}

/* ---------------------------------------------------------------- */
/* Numbered station rows ("Numbered list", List / Compact layouts)    */
/* ---------------------------------------------------------------- */

/* Position, then the station row: small image, name, Play at the end. */
.rdw-loop--numbered > .rdw-loop__items > .rdw-loop__item {
	display: flex;
	align-items: center;
	gap: 12px;
}

.rdw-loop--stations.rdw-loop--list.rdw-loop--numbered > .rdw-loop__items {
	gap: 10px;
}

.rdw-loop--stations.rdw-loop--list.rdw-loop--numbered > .rdw-loop__items > .rdw-loop__item {
	padding-bottom: 10px;
	border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.rdw-loop__position {
	flex: 0 0 auto;
	min-width: 2ch;
	font-size: 1.05rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	text-align: end;
	opacity: 0.75;
}

.rdw-loop--stations.rdw-loop--numbered .rdw-loop-station {
	position: relative;
	flex: 1 1 auto;
	gap: 12px;
	min-width: 0;
	min-height: 48px;
	padding-bottom: 0;
	padding-inline-end: 52px;
	border-bottom: 0;
}

.rdw-loop--stations.rdw-loop--numbered .rdw-loop-station__media {
	position: static;
	width: 48px;
}

/* The existing player wrapper, moved from over the image to the end of the row. */
.rdw-loop.rdw-loop--numbered .rdw-player.rdw-loop-player {
	inset-block: 0;
	inset-inline: auto 0;
	width: 44px;
}

/* ---------------------------------------------------------------- */
/* Pagination                                                        */
/* ---------------------------------------------------------------- */

.rdw-loop__pagination ul.page-numbers {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 6px;
	margin: 32px 0 0;
	padding: 0;
	list-style: none;
}

.rdw-loop__pagination .page-numbers a,
.rdw-loop__pagination .page-numbers span {
	display: inline-block;
	min-width: 38px;
	padding: 6px 10px;
	color: inherit;
	border: 1px solid rgba(127, 127, 127, 0.35);
	border-radius: 8px;
	text-align: center;
	text-decoration: none;
}

.rdw-loop__pagination .page-numbers .current {
	color: #ffffff;
	background: #111827;
	border-color: #111827;
}

@media (prefers-reduced-motion: reduce) {
	.rdw-loop * {
		transition: none !important;
		animation: none !important;
	}
}
