/**
 * radio-pwa.css
 *
 * Native-app shell styles for the Radio Stations page when launched from
 * the iOS/Android home screen (display-mode: standalone).
 *
 * All rules are scoped inside @media (display-mode: standalone) so they
 * have zero effect in a normal browser tab. No existing CSS is altered.
 *
 * Deploy to:
 *   wp-content/themes/canard-child/css/radio-pwa.css
 *
 * @package Canard Child
 * @since   3.1.1
 */

/* ─────────────────────────────────────────────────────────────────────────────
   Design tokens — PWA shell (supplement :root tokens already in style.css)
   ───────────────────────────────────────────────────────────────────────────── */

:root {
	--pwa-safe-top: env(safe-area-inset-top, 0px);
	--pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
	--pwa-safe-left: env(safe-area-inset-left, 0px);
	--pwa-safe-right: env(safe-area-inset-right, 0px);
	--pwa-header-height: 52px;
	--pwa-minibar-height: 64px;
	--pwa-header-total: calc(var(--pwa-header-height) + var(--pwa-safe-top));
	--pwa-minibar-total: calc(var(--pwa-minibar-height) + var(--pwa-safe-bottom));
	--pwa-poster-size: 220px;
	--pwa-tap-min: 44px;
	--pwa-thumb-size: 96px;
	--pwa-press-scale: 0.94;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Standalone shell — only active when launched from home screen
   ───────────────────────────────────────────────────────────────────────────── */

@media (display-mode: standalone) {
	/* ── 1. HIDE WORDPRESS CHROME ─────────────────────────────────────────── */

	.site-header,
	#masthead {
		display: none !important;
	}
	.entry-hero,
	.post-thumbnail,
	.entry-header {
		display: none !important;
	}
	/* .author-info is listed separately because the parent theme's single.js
	   moves it out of the sidebar to just below .entry-content on viewports
	   959px wide or narrower, where the #secondary rule no longer reaches it.
	   .sidebar-toggle is the parent theme's three-dot button that opens
	   #secondary; it sits outside that element and has nothing to open here. */
	#secondary,
	.widget-area,
	.author-info,
	.sidebar-toggle {
		display: none !important;
	}
	.site-footer,
	#colophon {
		display: none !important;
	}
	.entry-footer,
	.entry-meta,
	.edit-link,
	#comments {
		display: none !important;
	}

	/* Intro copy paragraphs and "Radio Player" heading above the player */
	.site-main > h2:first-of-type,
	.site-main > p:first-of-type,
	.site-main > p:nth-of-type(2),
	.site-main > h2:nth-of-type(2) {
		display: none !important;
	}

	/* Strip WordPress layout wrappers */
	.site-content-inner {
		display: block !important;
		padding: 0 !important;
		margin: 0 !important;
		max-width: none !important;
		width: 100% !important;
	}

	#primary.content-area {
		float: none !important;
		width: 100% !important;
		padding: 0 !important;
		margin: 0 !important;
	}

	.site-main {
		padding: 0 !important;
		margin: 0 !important;
	}

	body {
		background: var(--color-primary-dark) !important;
		overflow-x: hidden;
	}

	/* ── 2. APP HEADER BAR ────────────────────────────────────────────────── */

	/* Injected by radio-pwa.js as the first child of <body> */
	#pwa-header {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: var(--z-fixed);
		padding-top: var(--pwa-safe-top);
		padding-left: max(var(--pwa-safe-left), var(--space-4));
		padding-right: max(var(--pwa-safe-right), var(--space-4));
		padding-bottom: 0;
		height: var(--pwa-header-total);
		background: var(--color-primary);
		box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
		display: flex;
		align-items: flex-end;
		justify-content: center;
	}

	#pwa-header-inner {
		display: flex;
		align-items: center;
		justify-content: center;
		height: var(--pwa-header-height);
		width: 100%;
	}

	#pwa-header-title {
		font-family: var(--font-primary);
		font-size: var(--text-base);
		font-weight: var(--weight-semibold);
		letter-spacing: var(--tracking-wide);
		color: var(--text-inverse);
		text-align: center;
		margin: 0;
		padding: 0;
		background-image: none;
		text-decoration: none;
	}

	/* ── 3. BODY PADDING — clears fixed header and mini bar ──────────────── */

	body.pwa-ready {
		padding-top: var(--pwa-header-total) !important;
		padding-bottom: var(--pwa-minibar-total) !important;
		background: var(--neutral-50) !important;
	}

	/* ── 4. COMPACT PLAYER SECTION ───────────────────────────────────────── */

	.radio-player-container {
		background: var(--color-primary-dark);
		padding: var(--space-6) var(--space-4) var(--space-4);
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	#radioContainer {
		margin: 0;
		padding: 0;
		width: 100%;
		max-width: 360px;
	}

	#radioPoster {
		width: var(--pwa-poster-size) !important;
		height: var(--pwa-poster-size) !important;
		max-height: var(--pwa-poster-size) !important;
		min-height: unset !important;
		max-width: var(--pwa-poster-size) !important;
		object-fit: cover;
		border-radius: var(--radius-xl) !important;
		box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55) !important;
		display: block;
		margin: 0 auto;
	}

	#playPauseButton {
		width: 72px !important;
		height: 72px !important;
	}

	#playIcon,
	#pauseIcon {
		width: 30px !important;
		height: 30px !important;
	}

	#playIcon svg,
	#pauseIcon svg {
		width: 30px !important;
		height: 30px !important;
	}

	#radioContainer figcaption {
		margin-top: var(--space-3);
		font-size: var(--text-base);
		color: var(--text-inverse);
	}

	#stationCaption a {
		color: var(--text-inverse) !important;
	}

	#stationCaption a:hover {
		color: rgba(255, 255, 255, 0.75) !important;
	}

	#metadataContainer {
		background: rgba(255, 255, 255, 0.08) !important;
		border: 1px solid rgba(255, 255, 255, 0.12);
		color: rgba(255, 255, 255, 0.8) !important;
	}

	/* ── 5. STATION GRID ─────────────────────────────────────────────────── */

	.pwa-stations-wrapper {
		background: var(--neutral-50);
		padding-bottom: var(--space-8);
	}

	h2.country-heading,
	.entry-content h2.country-heading {
		font-size: var(--text-base) !important;
		font-weight: var(--weight-semibold) !important;
		letter-spacing: var(--tracking-wider) !important;
		text-transform: uppercase;
		color: var(--text-secondary) !important;
		margin-top: var(--space-6) !important;
		margin-bottom: var(--space-2) !important;
		padding: 0 var(--space-4) !important;
		border: none !important;
	}

	h2.country-heading:first-of-type {
		margin-top: var(--space-4) !important;
	}

	.radiostations-grid {
		grid-template-columns: repeat(
				auto-fill,
				minmax(var(--pwa-thumb-size), 1fr)
			);
		gap: var(--space-4);
		margin: 0 !important;
		padding: 0 var(--space-4) !important;
	}

	.station-card {
		min-height: var(--pwa-tap-min);
		cursor: pointer;
		-webkit-tap-highlight-color: transparent;
		touch-action: manipulation;
	}

	/* Haptic-feel press */
	.station-card:not(.station-unavailable):active {
		transform: scale(var(--pwa-press-scale)) !important;
		transition: transform 80ms ease !important;
	}

	/* No desktop hover-lift on touch */
	.station-card:hover:not(.station-unavailable) {
		transform: none;
	}

	.station-thumbnail {
		width: var(--pwa-thumb-size) !important;
		height: var(--pwa-thumb-size) !important;
		border-radius: var(--radius-xl) !important;
	}

	.station-name {
		font-size: var(--text-xs) !important;
	}

	.station-card a.station-link,
	.station-card a.station-link:visited,
	.station-card a.station-link:hover,
	.station-card a.station-link:active {
		color: inherit !important;
		background-image: none !important;
		background-size: auto !important;
		-webkit-tap-highlight-color: transparent;
		touch-action: manipulation;
	}

	/* ── 6. NOW-PLAYING MINI BAR ─────────────────────────────────────────── */

	#pwa-minibar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: var(--z-sticky);
		padding-bottom: var(--pwa-safe-bottom);
		padding-left: max(var(--pwa-safe-left), var(--space-4));
		padding-right: max(var(--pwa-safe-right), var(--space-4));
		height: var(--pwa-minibar-total);
		background: var(--color-primary);
		border-top: 1px solid rgba(255, 255, 255, 0.1);
		box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.35);
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		transform: translateY(0);
		opacity: 1;
		transition:
			transform var(--transition-base),
			opacity var(--transition-base);
	}

	#pwa-minibar.pwa-minibar--hidden {
		transform: translateY(100%);
		opacity: 0;
		pointer-events: none;
	}

	#pwa-minibar-inner {
		display: flex;
		align-items: center;
		width: 100%;
		height: var(--pwa-minibar-height);
		gap: var(--space-3);
		cursor: pointer;
	}

	#pwa-minibar-thumb {
		width: 44px;
		height: 44px;
		border-radius: var(--radius-lg);
		object-fit: cover;
		flex-shrink: 0;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
	}

	#pwa-minibar-info {
		flex: 1;
		min-width: 0;
		display: flex;
		flex-direction: column;
		gap: 2px;
	}

	#pwa-minibar-name {
		font-size: var(--text-sm);
		font-weight: var(--weight-semibold);
		color: var(--text-inverse);
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	#pwa-minibar-status {
		font-size: var(--text-xs);
		color: rgba(255, 255, 255, 0.55);
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	#pwa-minibar-playpause {
		width: var(--pwa-tap-min);
		height: var(--pwa-tap-min);
		flex-shrink: 0;
		background: rgba(255, 255, 255, 0.15);
		border: none;
		border-radius: var(--radius-full);
		color: var(--text-inverse);
		display: flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
		-webkit-tap-highlight-color: transparent;
		touch-action: manipulation;
		transition:
			background var(--transition-fast),
			transform 80ms ease;
	}

	#pwa-minibar-playpause:active {
		background: rgba(255, 255, 255, 0.3);
		transform: scale(0.9);
	}

	#pwa-minibar-playpause svg {
		width: 22px;
		height: 22px;
		fill: var(--text-inverse);
		display: block;
	}

	#pwa-minibar-playpause.playing {
		background: var(--color-interactive);
	}

	/* ── 7. RESPONSIVE — portrait breakpoints ────────────────────────────── */

	@media (max-width: 390px) {
		:root {
			--pwa-poster-size: 190px;
			--pwa-thumb-size: 84px;
		}
		#pwa-minibar-name {
			font-size: var(--text-xs);
		}
	}

	@media (min-width: 768px) and (orientation: portrait) {
		:root {
			--pwa-poster-size: 280px;
			--pwa-thumb-size: 110px;
		}
		.radiostations-grid {
			padding: 0 var(--space-8) !important;
		}
		h2.country-heading,
		.entry-content h2.country-heading {
			padding: 0 var(--space-8) !important;
		}
	}

	/* ── 8. LANDSCAPE MODE ───────────────────────────────────────────────── */
	/*
     * Same stacked layout as portrait (player on top, stations below), but:
     *   – ALL WordPress wrappers are forced to 100% so nothing constrains width.
     *   – The player section stays the same size and remains centred.
     *   – The station grid uses more columns to fill the extra horizontal space.
     */

	@media (orientation: landscape) {
		/* Slightly shorter chrome to reclaim vertical space */
		:root {
			--pwa-header-height: 44px;
			--pwa-minibar-height: 56px;
		}

		/*
         * Force every possible WordPress layout wrapper to span the full
         * viewport. The theme's max-width on .site-content, .entry-content,
         * article, and .hentry is what created the ~60% dead zone on the right.
         */
		.site-content,
		.site-content-inner,
		#primary.content-area,
		.site-main,
		article.page,
		article.post,
		.hentry,
		.entry-content,
		.entry-content > *,
		.page-content,
		.page-content > * {
			max-width: 100% !important;
			width: 100% !important;
			margin-left: 0 !important;
			margin-right: 0 !important;
			padding-left: 0 !important;
			padding-right: 0 !important;
			box-sizing: border-box !important;
			float: none !important;
		}

		/* Player: full width, centred content, reduced vertical padding */
		.radio-player-container {
			width: 100% !important;
			padding: var(--space-4) var(--space-6) !important;
			align-items: center !important;
			box-sizing: border-box !important;
		}

		/* Keep poster the same size as portrait */
		#radioPoster {
			width: var(--pwa-poster-size) !important;
			height: var(--pwa-poster-size) !important;
			max-height: var(--pwa-poster-size) !important;
			max-width: var(--pwa-poster-size) !important;
		}

		/* Station wrapper: full width */
		.pwa-stations-wrapper {
			width: 100% !important;
			box-sizing: border-box !important;
		}

		.radiostations-grid {
			padding: 0 var(--space-6) !important;
		}

		h2.country-heading,
		.entry-content h2.country-heading {
			padding: 0 var(--space-6) !important;
		}

		/* iPad landscape (>= 900 px): bump thumb size for even more columns */
		@media (min-width: 900px) {
			:root {
				--pwa-thumb-size: 110px;
			}

			.radiostations-grid {
				padding: 0 var(--space-8) !important;
				gap: var(--space-5) !important;
			}

			h2.country-heading,
			.entry-content h2.country-heading {
				padding: 0 var(--space-8) !important;
			}
		}
	}

	/* ── 9. REDUCED MOTION ───────────────────────────────────────────────── */

	@media (prefers-reduced-motion: reduce) {
		#pwa-minibar {
			transition: none !important;
		}
		.station-card:not(.station-unavailable):active {
			transform: none !important;
			transition: none !important;
		}
		#pwa-minibar-playpause:active {
			transform: none !important;
		}
	}
} /* end @media (display-mode: standalone) */

/* ─────────────────────────────────────────────────────────────────────────────
   Install tooltip — browser tab only (NOT standalone)
   Shown on iOS/iPadOS Safari; injected and animated by radio-pwa.js.
   ───────────────────────────────────────────────────────────────────────────── */

#pwa-install-tip {
	position: fixed;
	bottom: max(env(safe-area-inset-bottom, 0px), 16px);
	left: 50%;
	transform: translateX(-50%) translateY(0);
	z-index: 9999;

	display: flex;
	align-items: center;
	gap: 10px;

	background: var(--color-primary, #2c3e50);
	color: var(--text-inverse, #ffffff);
	border: 1px solid rgba(255, 255, 255, 0.15);
	border-radius: 12px;
	box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);

	padding: 10px 14px 10px 12px;
	max-width: min(360px, calc(100vw - 32px));
	width: max-content;

	font-family: var(--font-primary, system-ui, sans-serif);
	font-size: 13px;
	line-height: 1.4;
	font-weight: var(--weight-normal, 400);

	opacity: 1;
	transition:
		opacity 400ms ease,
		transform 400ms ease;

	/* Entrance animation */
	animation: pwa-tip-enter 350ms ease both;
}

#pwa-install-tip.pwa-tip--hidden {
	opacity: 0;
	transform: translateX(-50%) translateY(12px);
	pointer-events: none;
}

#pwa-install-tip-icon {
	flex-shrink: 0;
	width: 20px;
	height: 20px;
	opacity: 0.85;
}

#pwa-install-tip-text {
	flex: 1;
}

#pwa-install-tip-close {
	flex-shrink: 0;
	width: 24px;
	height: 24px;
	background: transparent;
	border: none;
	border-radius: var(--radius-full, 9999px);
	color: rgba(255, 255, 255, 0.6);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	margin-left: 4px;
	transition:
		color 150ms ease,
		background 150ms ease;
	-webkit-tap-highlight-color: transparent;
}

#pwa-install-tip-close:hover,
#pwa-install-tip-close:active {
	color: rgba(255, 255, 255, 1);
	background: rgba(255, 255, 255, 0.12);
}

#pwa-install-tip-close svg {
	width: 14px;
	height: 14px;
	fill: currentColor;
}

@keyframes pwa-tip-enter {
	from {
		opacity: 0;
		transform: translateX(-50%) translateY(16px);
	}
	to {
		opacity: 1;
		transform: translateX(-50%) translateY(0);
	}
}

@media (prefers-reduced-motion: reduce) {
	#pwa-install-tip {
		animation: none !important;
		transition: opacity 200ms ease !important;
	}
}
