/*
 * Castos / SSP player, one component in two densities plus a playlist.
 * Brand it with --cp-accent. Surface: data-mode = light | dark | brand | auto.
 * Font comes from the host page (SSP) or the system stack (Castos embed).
 */

.cp,
.cp-playlist {
	--cp-accent: #6c25d0;
	--cp-on-accent: #fff;
	--cp-ink: var(--cp-accent); /* accent as a graphic, swapped by JS when it lacks contrast */
	--cp-ink-text: var(--cp-accent); /* accent as text, same idea at 4.5:1 */
	/* Light and Dark are tinted with the podcast's color, never flat white or black. */
	--cp-bg: color-mix(in srgb, var(--cp-accent) 9%, #fff);
	--cp-fg: color-mix(in srgb, var(--cp-accent) 20%, #0d0c10);
	--cp-muted: color-mix(in srgb, var(--cp-fg) 64%, var(--cp-bg));
	--cp-track: color-mix(in srgb, var(--cp-fg) 16%, var(--cp-bg));
	--cp-line: color-mix(in srgb, var(--cp-fg) 12%, var(--cp-bg));
	--cp-hover: color-mix(in srgb, var(--cp-fg) 6%, var(--cp-bg));
	--cp-play-bg: var(--cp-accent);
	--cp-play-fg: var(--cp-on-accent);
	--cp-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
	--cp-radius: 14px;
}

.cp[data-mode="dark"],
.cp-playlist[data-mode="dark"] {
	--cp-bg: color-mix(in srgb, var(--cp-accent) 16%, #0f0e12);
	--cp-fg: color-mix(in srgb, var(--cp-accent) 6%, #fff);
}

@media (prefers-color-scheme: dark) {
	.cp[data-mode="auto"],
	.cp-playlist[data-mode="auto"] {
		--cp-bg: color-mix(in srgb, var(--cp-accent) 16%, #0f0e12);
		--cp-fg: color-mix(in srgb, var(--cp-accent) 6%, #fff);
	}
}

/* Brand: the podcast's color is the player. Text and the play button flip to whatever reads on it. */
.cp[data-mode="brand"],
.cp-playlist[data-mode="brand"] {
	--cp-bg: var(--cp-accent);
	--cp-fg: var(--cp-on-accent);
	--cp-muted: color-mix(in srgb, var(--cp-fg) 78%, var(--cp-bg));
	--cp-track: color-mix(in srgb, var(--cp-fg) 30%, var(--cp-bg));
	--cp-line: color-mix(in srgb, var(--cp-fg) 22%, var(--cp-bg));
	--cp-hover: color-mix(in srgb, var(--cp-fg) 10%, var(--cp-bg));
	--cp-play-bg: var(--cp-fg);
	--cp-play-fg: var(--cp-bg);
	--cp-ink: var(--cp-fg) !important;
	--cp-ink-text: var(--cp-fg) !important;
}

.cp {
	container-type: inline-size;
	position: relative;
	box-sizing: border-box;
	background: var(--cp-bg);
	color: var(--cp-fg);
	border: 1px solid var(--cp-line);
	border-radius: var(--cp-radius);
	font-family: var(--cp-font, inherit);
	font-size: 15px;
	line-height: 1.35;
	overflow: hidden;
	-webkit-font-smoothing: antialiased;
}

.cp[data-mode="brand"] {
	border-color: transparent;
}

.cp *,
.cp *::before,
.cp *::after {
	box-sizing: inherit;
}

/* ---------- shared pieces ---------- */

.cp button {
	font: inherit;
	color: inherit;
	background: none;
	border: 0;
	margin: 0;
	padding: 0;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.cp :focus-visible {
	outline: 2px solid var(--cp-ink);
	outline-offset: 2px;
	border-radius: 6px;
}

.cp svg {
	display: block;
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.75;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.cp-art {
	display: block;
	flex: none;
	width: 148px;
	height: 148px;
	border-radius: 10px;
	object-fit: cover;
	background: var(--cp-track);
}

.cp--no-art .cp-art {
	display: none;
}

.cp-body {
	min-width: 0;
	flex: 1;
}

.cp-eyebrow {
	margin: 0;
	font-size: 11.5px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--cp-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.cp-eyebrow .cp-dot {
	margin: 0 0.4em;
}

.cp-title {
	margin: 4px 0 0;
	font-size: 22px;
	font-weight: 700;
	letter-spacing: -0.015em;
	line-height: 1.15;
	text-wrap: balance;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.cp-play {
	flex: none;
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	border-radius: 50% !important;
	background: var(--cp-play-bg) !important;
	color: var(--cp-play-fg) !important;
	transition: transform 0.12s;
}

.cp-play:active {
	transform: scale(0.94);
}

.cp .cp-play svg {
	width: 26px;
	height: 26px;
	fill: currentColor;
	stroke: none;
}

.cp-play .cp-i-pause,
.cp-play .cp-i-load,
.cp.is-playing .cp-play .cp-i-play,
.cp.is-loading .cp-play .cp-i-play,
.cp.is-loading .cp-play .cp-i-pause {
	display: none;
}

.cp.is-playing:not(.is-loading) .cp-play .cp-i-pause,
.cp.is-loading .cp-play .cp-i-load {
	display: block;
}

.cp .cp-play .cp-i-load {
	animation: cp-spin 0.8s linear infinite;
	fill: none;
	stroke: currentColor;
	stroke-width: 2.5;
	stroke-linecap: round;
}

.cp-load-track {
	opacity: 0.25;
}

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

/*
 * Seek: a native range input sits on top of the waveform, so arrows, Home/End
 * and screen readers work for free. With no peaks it falls back to a plain bar.
 */
.cp-seek {
	flex: 1;
	min-width: 0;
}

.cp-wave {
	position: relative;
	height: 44px;
}

.cp-bars,
.cp-bars-played {
	position: absolute;
	inset: 0;
	color: var(--cp-track);
	pointer-events: none;
}

.cp .cp-bars svg,
.cp .cp-bars-played svg {
	width: 100%;
	height: 100%;
	fill: currentColor;
	stroke: none;
}

.cp-bars-played {
	color: var(--cp-ink);
	clip-path: inset(0 calc(100% - var(--p, 0%)) 0 0);
}

/* No peaks: a plain 4px line through the middle. */
.cp-wave:not(.has-peaks) .cp-bars,
.cp-wave:not(.has-peaks) .cp-bars-played {
	top: calc(50% - 2px);
	bottom: auto;
	height: 4px;
	border-radius: 2px;
	background: currentColor;
}

.cp-range {
	-webkit-appearance: none;
	appearance: none;
	position: relative;
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	background: transparent;
	cursor: pointer;
}

.cp-range::-webkit-slider-runnable-track {
	height: 100%;
	background: transparent;
}

.cp-range::-moz-range-track {
	height: 100%;
	background: transparent;
}

/* The thumb is a thin playhead line, shown on hover, focus and while playing. */
.cp-range::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 2px;
	height: 100%;
	border: 0;
	border-radius: 1px;
	background: var(--cp-fg);
	opacity: 0;
	transition: opacity 0.12s;
}

.cp-range::-moz-range-thumb {
	width: 2px;
	height: 100%;
	border: 0;
	border-radius: 1px;
	background: var(--cp-fg);
	opacity: 0;
	transition: opacity 0.12s;
}

.cp-range:hover::-webkit-slider-thumb,
.cp-range:focus-visible::-webkit-slider-thumb,
.cp.is-playing .cp-range::-webkit-slider-thumb {
	opacity: 1;
}

.cp-range:hover::-moz-range-thumb,
.cp-range:focus-visible::-moz-range-thumb,
.cp.is-playing .cp-range::-moz-range-thumb {
	opacity: 1;
}

.cp-times {
	display: flex;
	justify-content: space-between;
	margin-top: 4px;
	font-family: var(--cp-mono);
	font-size: 12px;
	color: var(--cp-muted);
	font-variant-numeric: tabular-nums;
}

.cp-btn {
	display: grid;
	place-items: center;
	min-width: 38px;
	height: 38px;
	padding: 0 6px !important;
	border-radius: 8px;
	color: var(--cp-fg);
}

.cp-btn:hover {
	background: var(--cp-hover) !important;
}

.cp .cp-speed {
	min-width: 44px;
	height: 26px;
	margin: 0 4px;
	border: 1.5px solid currentColor;
	border-radius: 6px;
	font-family: var(--cp-mono);
	font-size: 12px;
	font-weight: 600;
}

.cp.is-muted .cp-i-vol,
.cp .cp-i-mute {
	display: none;
}

.cp.is-muted .cp-i-mute {
	display: block;
}

.cp .cp-link-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 36px;
	padding: 0 4px;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--cp-fg);
}

.cp-link-btn:hover {
	text-decoration: underline;
	text-underline-offset: 4px;
	text-decoration-thickness: 1.5px;
}

.cp .cp-link-btn svg {
	width: 16px;
	height: 16px;
	stroke-width: 2;
}

.cp-credit {
	display: block;
	flex: none;
	margin-top: 2px;
	color: var(--cp-muted);
}

.cp-credit:hover {
	color: var(--cp-fg);
}

.cp-credit-logo {
	display: block;
	width: 64px;
	height: 21px;
	background: currentColor;
	-webkit-mask: url("castos-logo.svg") no-repeat center / contain;
	mask: url("castos-logo.svg") no-repeat center / contain;
}

.cp--no-credit .cp-credit {
	display: none;
}

/* ---------- Full ---------- */

.cp--full {
	display: flex;
	gap: 22px;
	padding: 20px;
}

.cp--full .cp-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	margin-bottom: 12px;
}

.cp-head-text {
	min-width: 0;
}

.cp--full .cp-transport {
	display: flex;
	align-items: center;
	gap: 16px;
}

.cp--full .cp-transport .cp-seek {
	padding-top: 18px;
}

.cp--full .cp-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-top: 6px;
	margin-left: 70px;
}

.cp-controls,
.cp-actions {
	display: flex;
	align-items: center;
	gap: 2px;
}

.cp-actions {
	gap: 14px;
}

@container (max-width: 560px) {
	.cp--full {
		padding: 16px;
		gap: 14px;
	}

	.cp--full .cp-art {
		width: 84px;
		height: 84px;
	}

	.cp--full .cp-title {
		font-size: 19px;
	}

	.cp--full .cp-bar {
		margin-left: 0;
		flex-wrap: wrap;
	}

	.cp--full .cp-credit {
		display: none;
	}
}

@container (max-width: 420px) {
	.cp--full {
		flex-direction: column;
	}

	.cp--full .cp-art {
		position: absolute;
		top: 16px;
		left: 16px;
		width: 64px;
		height: 64px;
	}

	.cp--full:not(.cp--no-art) .cp-head {
		min-height: 64px;
		padding-left: 78px;
	}

	.cp--full .cp-title {
		font-size: 17px;
	}

	.cp--full .cp-play {
		width: 52px;
		height: 52px;
	}
}

/* ---------- Compact ---------- */

.cp--compact {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 14px 10px 10px;
}

.cp--compact .cp-art {
	width: 52px;
	height: 52px;
	border-radius: 8px;
}

.cp--compact .cp-play {
	width: 44px;
	height: 44px;
}

.cp--compact .cp-play svg {
	width: 20px;
	height: 20px;
}

.cp--compact .cp-title {
	margin: 0;
	font-size: 14.5px;
	letter-spacing: -0.005em;
	-webkit-line-clamp: 1;
}

.cp--compact .cp-seek {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: 2px;
}

.cp--compact .cp-wave {
	flex: 1;
	min-width: 0;
	height: 24px;
}

.cp--compact .cp-times {
	flex: none;
	margin: 0;
	gap: 4px;
}

.cp--compact .cp-controls {
	flex: none;
}

@container (max-width: 600px) {
	.cp--compact .cp-skip,
	.cp--compact .cp-mute {
		display: none;
	}
}

@container (max-width: 400px) {
	.cp--compact .cp-art,
	.cp--compact .cp-times .cp-total,
	.cp--compact .cp-times .cp-sep {
		display: none;
	}
}

.cp--full .cp-sep {
	display: none;
}

/* ---------- Subscribe sheet (Full only) ---------- */

.cp-sheet {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: flex;
	flex-direction: column;
	gap: 14px;
	padding: 18px 20px;
	background: var(--cp-bg);
	overflow-y: auto;
}

.cp-sheet[hidden] {
	display: none;
}

.cp-sheet-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 20px;
	font-weight: 700;
	letter-spacing: -0.015em;
}

.cp-apps {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.cp-apps a {
	display: inline-flex;
	align-items: center;
	height: 38px;
	padding: 0 16px;
	border: 1.5px solid var(--cp-line);
	border-radius: 999px;
	color: inherit;
	text-decoration: none;
	font-size: 14px;
	font-weight: 600;
}

.cp-apps a:hover {
	border-color: currentColor;
}

/* ---------- Playlist ---------- */

.cp-playlist {
	container-type: inline-size;
	border: 1px solid var(--cp-line);
	border-radius: var(--cp-radius);
	background: var(--cp-bg);
	color: var(--cp-fg);
	overflow: hidden;
	font-family: var(--cp-font, inherit);
}

.cp-playlist[data-mode="brand"] {
	border-color: transparent;
}

.cp-playlist > .cp {
	border: 0;
	border-radius: 0;
}

.cp-list-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin: 0;
	padding: 14px 20px 6px;
	border-top: 1px solid var(--cp-line);
	font-size: 11.5px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--cp-muted);
}

.cp-list {
	max-height: 300px;
	margin: 0;
	padding: 0 8px 8px;
	overflow-y: auto;
	list-style: none;
}

.cp-list button {
	display: grid;
	grid-template-columns: 52px 1fr auto;
	align-items: center;
	gap: 8px;
	width: 100%;
	min-height: 46px;
	padding: 6px 12px;
	border: 0;
	border-radius: 8px;
	background: none;
	color: inherit;
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.cp-list button:hover {
	background: var(--cp-hover);
}

.cp-list button:focus-visible {
	outline: 2px solid var(--cp-ink);
	outline-offset: -2px;
}

.cp-num,
.cp-eq {
	justify-self: center;
}

.cp-num,
.cp-len {
	font-family: var(--cp-mono);
	font-size: 12px;
	color: var(--cp-muted);
	font-variant-numeric: tabular-nums;
}

.cp-row-title {
	min-width: 0;
	font-size: 15px;
	font-weight: 500;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.cp-list [aria-current="true"] {
	background: var(--cp-hover);
}

.cp-list [aria-current="true"] .cp-row-title {
	color: var(--cp-ink-text);
	font-weight: 700;
}

/* The feed's <link>: the podcast's own website. */
.cp-site {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	color: var(--cp-fg);
	text-decoration: none;
	letter-spacing: 0.02em;
	text-transform: none;
	font-size: 13px;
	font-weight: 600;
	white-space: nowrap;
}

.cp-site:hover {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.cp-site svg {
	width: 14px;
	height: 14px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.cp-site:focus-visible {
	outline: 2px solid var(--cp-ink);
	outline-offset: 2px;
	border-radius: 4px;
}

/* Now-playing bars replace the episode number on the current row. */
.cp-eq {
	display: none;
	align-items: flex-end;
	gap: 2px;
	height: 14px;
}

.cp-eq i {
	width: 3px;
	height: 40%;
	border-radius: 1px;
	background: var(--cp-ink);
}

.cp-eq i:nth-child(2) { height: 80%; }
.cp-eq i:nth-child(3) { height: 55%; }

.cp-list [aria-current="true"] .cp-num {
	display: none;
}

.cp-list [aria-current="true"] .cp-eq {
	display: flex;
}

.cp-playlist.is-playing .cp-eq i {
	animation: cp-eq 0.9s ease-in-out infinite alternate;
}

.cp-eq i:nth-child(2) { animation-delay: -0.3s !important; }
.cp-eq i:nth-child(3) { animation-delay: -0.6s !important; }

@keyframes cp-eq {
	from { height: 25%; }
	to { height: 100%; }
}

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

	.cp .cp-play .cp-i-load {
		animation: cp-spin 2s linear infinite !important;
	}
}
