/**
 * Browser TTS Styles
 * Theme-friendly styles using CSS variables
 */

:root {
	--wp-tts-primary-color: #6366f1;
	--wp-tts-primary-hover: #4f46e5;
	--wp-tts-primary-active: #4338ca;
	--wp-tts-secondary-color: #8b5cf6;
	--wp-tts-border-color: #e5e7eb;
	--wp-tts-border-radius: 12px;
	--wp-tts-spacing: 1.25em;
	--wp-tts-bg-color: #ffffff;
	--wp-tts-bg-hover: #f9fafb;
	--wp-tts-text-color: #1f2937;
	--wp-tts-text-secondary: #6b7280;
	--wp-tts-error-color: #ef4444;
	--wp-tts-success-color: #10b981;
	--wp-tts-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
	--wp-tts-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
	--wp-tts-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.wp-tts-container {
	margin: var(--wp-tts-spacing, 1.25em) 0;
	padding: 1.5em;
	background: var(--wp-tts-bg-color, #ffffff);
	border: 1px solid var(--wp-tts-border-color, #e5e7eb);
	border-radius: var(--wp-tts-border-radius, 12px);
	box-shadow: var(--wp-tts-shadow-md);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	position: relative;
	overflow: hidden;
	backdrop-filter: blur(10px);
}

.wp-tts-container:hover {
	box-shadow: var(--wp-tts-shadow-lg);
	border-color: rgba(99, 102, 241, 0.3);
	transform: translateY(-2px);
}

.wp-tts-container::before {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 3px;
	background: linear-gradient(90deg, var(--wp-tts-primary-color), var(--wp-tts-secondary-color));
	opacity: 0.8;
	transform: scaleX(0);
	transform-origin: left;
	transition: transform 0.5s ease;
}

.wp-tts-container:hover::before {
	transform: scaleX(1);
}

.wp-tts-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 1.25em;
	align-items: flex-end;
	margin-bottom: 0.75em;
}

.wp-tts-buttons {
	display: flex;
	gap: 0.75em;
	flex-wrap: wrap;
	align-items: center;
}

.wp-tts-btn {
	padding: 0.75em 1.5em;
	background: linear-gradient(135deg, var(--wp-tts-primary-color), var(--wp-tts-secondary-color));
	color: #ffffff;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	font-size: 0.9375em;
	font-weight: 600;
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	line-height: 1.5;
	box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
	position: relative;
	overflow: hidden;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	font-size: 0.8125em;
}

.wp-tts-btn::before {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 0;
	height: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	transform: translate(-50%, -50%);
	transition: width 0.6s, height 0.6s;
}

.wp-tts-btn:hover:not(:disabled)::before {
	width: 300px;
	height: 300px;
}

.wp-tts-btn:hover:not(:disabled) {
	background: linear-gradient(135deg, var(--wp-tts-primary-hover), var(--wp-tts-primary-color));
	box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
	transform: translateY(-2px);
}

.wp-tts-btn:active:not(:disabled) {
	transform: translateY(0);
	box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.wp-tts-btn:focus {
	outline: none;
	box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3), 0 4px 12px rgba(99, 102, 241, 0.4);
}

.wp-tts-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	background: #e5e7eb;
	color: #9ca3af;
	box-shadow: none;
	transform: none;
}

.wp-tts-options {
	display: flex;
	flex-direction: column;
	gap: 0.5em;
	min-width: 160px;
	flex: 1;
}

.wp-tts-label {
	font-size: 0.8125em;
	font-weight: 600;
	color: var(--wp-tts-text-color, #1f2937);
	display: flex;
	align-items: center;
	gap: 0.5em;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	margin-bottom: 0.25em;
}

.wp-tts-rate-value {
	font-weight: 700;
	color: var(--wp-tts-primary-color, #6366f1);
	font-size: 1.1em;
	background: linear-gradient(135deg, var(--wp-tts-primary-color), var(--wp-tts-secondary-color));
	-webkit-background-clip: text;
	-webkit-text-fill-color: transparent;
	background-clip: text;
}

.wp-tts-voice-select {
	padding: 0.75em 1em;
	border: 2px solid var(--wp-tts-border-color, #e5e7eb);
	border-radius: 8px;
	font-size: 0.9375em;
	background: var(--wp-tts-bg-color, #ffffff);
	color: var(--wp-tts-text-color, #1f2937);
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	cursor: pointer;
	font-weight: 500;
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236366f1' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.75em center;
	background-size: 1em;
	padding-right: 2.5em;
}

.wp-tts-voice-select:hover {
	border-color: var(--wp-tts-primary-color);
	background-color: var(--wp-tts-bg-hover, #f9fafb);
}

.wp-tts-voice-select:focus {
	outline: none;
	border-color: var(--wp-tts-primary-color);
	box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
	background-color: var(--wp-tts-bg-color, #ffffff);
}

.wp-tts-voice-select:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	background-color: #f3f4f6;
}

.wp-tts-rate {
	width: 100%;
	cursor: pointer;
	height: 6px;
	border-radius: 3px;
	background: var(--wp-tts-border-color, #e5e7eb);
	outline: none;
	-webkit-appearance: none;
	appearance: none;
	transition: background 0.3s ease;
	margin-top: 0.5em;
}

.wp-tts-rate:hover {
	background: #d1d5db;
}

.wp-tts-rate:focus {
	outline: none;
}

.wp-tts-rate:focus::-webkit-slider-thumb {
	box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.wp-tts-rate:focus::-moz-range-thumb {
	box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.wp-tts-rate::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--wp-tts-primary-color), var(--wp-tts-secondary-color));
	cursor: pointer;
	box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
	transition: all 0.3s ease;
	border: 2px solid #ffffff;
}

.wp-tts-rate::-webkit-slider-thumb:hover {
	transform: scale(1.15);
	box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
}

.wp-tts-rate::-moz-range-thumb {
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--wp-tts-primary-color), var(--wp-tts-secondary-color));
	cursor: pointer;
	box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
	transition: all 0.3s ease;
	border: 2px solid #ffffff;
}

.wp-tts-rate::-moz-range-thumb:hover {
	transform: scale(1.15);
	box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
}

.wp-tts-rate:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.wp-tts-message {
	margin-top: 1em;
	padding: 0.875em 1em;
	font-size: 0.875em;
	min-height: 1.5em;
	border-radius: 8px;
	font-weight: 500;
	transition: all 0.3s ease;
	display: flex;
	align-items: center;
	gap: 0.5em;
}

.wp-tts-message.wp-tts-error {
	color: #dc2626;
	background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.05));
	border: 1px solid rgba(239, 68, 68, 0.2);
	box-shadow: 0 2px 4px rgba(239, 68, 68, 0.1);
}

.wp-tts-message.wp-tts-error::before {
	content: '⚠';
	font-size: 1.2em;
}

.wp-tts-message.wp-tts-success {
	color: #059669;
	background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.05));
	border: 1px solid rgba(16, 185, 129, 0.2);
	box-shadow: 0 2px 4px rgba(16, 185, 129, 0.1);
}

.wp-tts-message.wp-tts-success::before {
	content: '✓';
	font-size: 1.2em;
	font-weight: bold;
}

/* Responsive adjustments */
@media (max-width: 768px) {
	.wp-tts-container {
		padding: 0.875rem;
		border-radius: 10px;
	}

	.wp-tts-controls {
		flex-direction: row;
		flex-wrap: wrap;
		gap: 0.5rem;
		align-items: center;
		justify-content: center;
	}

	.wp-tts-buttons {
		width: auto;
		flex: 0 0 auto;
		justify-content: center;
		flex-wrap: wrap;
		gap: 0.4rem;
	}

	.wp-tts-btn {
		flex: 0 0 auto;
		min-width: auto;
		padding: 0.5rem 0.875rem;
		font-size: 0.75rem;
		white-space: nowrap;
	}

	.wp-tts-options {
		width: auto;
		flex: 0 0 auto;
		flex-direction: row;
		flex-wrap: wrap;
		gap: 0.5rem;
		align-items: center;
	}

	.wp-tts-label {
		font-size: 0.75rem;
	}

	.wp-tts-voice-select {
		font-size: 0.875rem;
		padding: 0.5rem 0.75rem;
	}
}

@media (max-width: 480px) {
	.wp-tts-container {
		padding: 0.75rem;
		margin: 1rem 0;
	}

	.wp-tts-controls {
		gap: 0.4rem;
	}

	.wp-tts-buttons {
		gap: 0.35rem;
	}

	.wp-tts-btn {
		padding: 0.4rem 0.75rem;
		font-size: 0.6875rem;
		width: auto;
	}

	.wp-tts-options {
		gap: 0.4rem;
	}
}

/* High contrast mode support */
@media (prefers-contrast: high) {
	.wp-tts-container {
		border-width: 2px;
	}

	.wp-tts-btn {
		border: 2px solid currentColor;
	}
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
	.wp-tts-container,
	.wp-tts-btn,
	.wp-tts-voice-select,
	.wp-tts-rate,
	.wp-tts-message {
		transition: none;
	}
	
	.wp-tts-container:hover {
		transform: none;
	}
	
	.wp-tts-btn::before {
		transition: none;
	}
}

/* Text highlighting during TTS reading - Modern gradual green color transition */
/* All text that has been read gradually turns green in a smooth, modern style */
.wp-tts-highlight {
	color: #22c55e !important; /* Green color for read text */
	padding: 0;
	border-radius: 0;
	transition: color 0.6s cubic-bezier(0.4, 0, 0.2, 1) !important;
	display: inline;
	position: relative;
	z-index: 1;
	font-weight: 500;
	animation: textColorFlow 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
	text-shadow: 0 0 6px rgba(34, 197, 94, 0.15);
}

/* Smooth color flow animation for read text - modern flowing effect */
@keyframes textColorFlow {
	0% {
		color: rgba(34, 197, 94, 0.4);
		filter: brightness(0.85) saturate(0.8);
	}
	25% {
		color: rgba(34, 197, 94, 0.65);
		filter: brightness(0.95) saturate(0.9);
	}
	50% {
		color: rgba(34, 197, 94, 0.85);
		filter: brightness(1) saturate(1);
	}
	75% {
		color: rgba(34, 197, 94, 0.95);
		filter: brightness(1.05) saturate(1.1);
	}
	100% {
		color: #22c55e;
		filter: brightness(1.1) saturate(1.2);
	}
}

/* Currently reading text (bright green with smooth gradient) */
.wp-tts-highlight-word {
	background: linear-gradient(90deg, 
		rgba(34, 197, 94, 0.12) 0%, 
		rgba(34, 197, 94, 0.22) 50%,
		rgba(34, 197, 94, 0.12) 100%
	) !important;
	color: #16a34a !important; /* Darker green for current text */
	padding: 2px 4px !important;
	border-radius: 4px !important;
	box-shadow: 
		0 0 0 1px rgba(34, 197, 94, 0.25),
		0 2px 4px rgba(34, 197, 94, 0.12) !important;
	font-weight: 600 !important;
	transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
	display: inline;
	position: relative;
	z-index: 10;
	animation: currentTextFlow 1.2s ease-in-out infinite;
	text-shadow: 0 0 8px rgba(34, 197, 94, 0.2);
}

/* Smooth flowing animation for current reading text */
@keyframes currentTextFlow {
	0%, 100% {
		background: linear-gradient(90deg, 
			rgba(34, 197, 94, 0.12) 0%, 
			rgba(34, 197, 94, 0.22) 50%,
			rgba(34, 197, 94, 0.12) 100%
		);
		box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25), 0 2px 4px rgba(34, 197, 94, 0.12);
		transform: scale(1);
	}
	50% {
		background: linear-gradient(90deg, 
			rgba(34, 197, 94, 0.18) 0%, 
			rgba(34, 197, 94, 0.28) 50%,
			rgba(34, 197, 94, 0.18) 100%
		);
		box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35), 0 3px 6px rgba(34, 197, 94, 0.18);
		transform: scale(1.02);
	}
}

/* Smooth scroll behavior for highlighted text */
html {
	scroll-behavior: smooth;
}

/* High contrast mode for highlights */
@media (prefers-contrast: high) {
	.wp-tts-highlight {
		color: #15803d !important; /* Darker green for high contrast */
		font-weight: 600;
	}
	
	.wp-tts-highlight-word {
		background: rgba(34, 197, 94, 0.4) !important;
		color: #15803d !important;
		border: 2px solid #16a34a !important;
		box-shadow: 0 0 0 1px #15803d !important;
	}
}

/* Ensure highlighted words are always visible above other content */
.wp-tts-highlight-word {
	position: relative;
	z-index: 999 !important;
}

/* Make sure highlighted text doesn't break layout */
article .wp-tts-highlight-word,
.entry-content .wp-tts-highlight-word,
.post-content .wp-tts-highlight-word,
.modern-entry-content .wp-tts-highlight-word {
	display: inline;
	vertical-align: baseline;
}

/* Ensure read text (green) flows naturally */
article .wp-tts-highlight,
.entry-content .wp-tts-highlight,
.post-content .wp-tts-highlight,
.modern-entry-content .wp-tts-highlight {
	display: inline;
	vertical-align: baseline;
}

/* Modern flowing effect - all read text gradually turns green */
.wp-tts-highlight {
	will-change: color, filter;
	backface-visibility: hidden;
	-webkit-font-smoothing: antialiased;
}

/* Sticky Music Player at Bottom */
.wp-tts-sticky-player {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: #ffffff;
	border-top: 1px solid #e0e0e0;
	box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
	z-index: 9999;
	padding: 0;
	transition: transform 0.3s ease, opacity 0.3s ease;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.wp-tts-sticky-player.hidden {
	transform: translateY(100%);
	opacity: 0;
	pointer-events: none;
	visibility: hidden;
}

.wp-tts-player-content {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 20px;
	gap: 20px;
	max-width: 1400px;
	margin: 0 auto;
}

.wp-tts-player-info {
	flex: 1;
	min-width: 0;
}

.wp-tts-player-title {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.wp-tts-player-track {
	font-size: 14px;
	font-weight: 600;
	color: #1a1a1a;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.wp-tts-player-status {
	font-size: 12px;
	color: #666;
	font-weight: 400;
}

.wp-tts-player-controls {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-shrink: 0;
}

.wp-tts-player-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	border: none;
	background: #2271b1;
	color: #ffffff;
	cursor: pointer;
	transition: all 0.2s ease;
	flex-shrink: 0;
	padding: 0;
}

.wp-tts-player-btn:hover:not(:disabled) {
	background: #135e96;
	transform: scale(1.05);
}

.wp-tts-player-btn:active:not(:disabled) {
	transform: scale(0.95);
}

.wp-tts-player-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.wp-tts-player-btn svg {
	width: 20px;
	height: 20px;
}

.wp-tts-player-options {
	display: flex;
	align-items: center;
	gap: 16px;
	flex-shrink: 0;
}

.wp-tts-player-voice {
	flex-shrink: 0;
}

.wp-tts-player-voice-select {
	padding: 8px 12px;
	border: 1px solid #ccc;
	border-radius: 6px;
	font-size: 13px;
	background: #ffffff;
	color: #333;
	cursor: pointer;
	min-width: 120px;
	transition: border-color 0.2s ease;
}

.wp-tts-player-voice-select:hover {
	border-color: #2271b1;
}

.wp-tts-player-voice-select:focus {
	outline: none;
	border-color: #2271b1;
	box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1);
}

.wp-tts-player-rate {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-shrink: 0;
}

.wp-tts-player-rate-slider {
	width: 100px;
	height: 4px;
	border-radius: 2px;
	background: #e0e0e0;
	outline: none;
	-webkit-appearance: none;
	appearance: none;
	cursor: pointer;
}

.wp-tts-player-rate-slider::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: #2271b1;
	cursor: pointer;
	transition: all 0.2s ease;
}

.wp-tts-player-rate-slider::-webkit-slider-thumb:hover {
	background: #135e96;
	transform: scale(1.2);
}

.wp-tts-player-rate-slider::-moz-range-thumb {
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: #2271b1;
	cursor: pointer;
	border: none;
	transition: all 0.2s ease;
}

.wp-tts-player-rate-slider::-moz-range-thumb:hover {
	background: #135e96;
	transform: scale(1.2);
}

.wp-tts-player-rate-value {
	font-size: 13px;
	font-weight: 600;
	color: #2271b1;
	min-width: 35px;
	text-align: center;
}

/* Responsive Design */
@media (max-width: 768px) {
	.wp-tts-player-content {
		padding: 10px 16px;
		gap: 12px;
	}
	
	.wp-tts-player-btn {
		width: 40px;
		height: 40px;
	}
	
	.wp-tts-player-btn svg {
		width: 18px;
		height: 18px;
	}
	
	.wp-tts-player-track {
		font-size: 13px;
	}
	
	.wp-tts-player-status {
		font-size: 11px;
	}
	
	.wp-tts-player-options {
		gap: 12px;
	}
	
	.wp-tts-player-voice-select {
		min-width: 100px;
		font-size: 12px;
		padding: 6px 10px;
	}
	
	.wp-tts-player-rate-slider {
		width: 80px;
	}
	
	.wp-tts-player-rate-value {
		font-size: 12px;
		min-width: 30px;
	}
}

@media (max-width: 480px) {
	.wp-tts-player-content {
		flex-wrap: wrap;
		padding: 10px 12px;
	}
	
	.wp-tts-player-info {
		order: 1;
		width: 100%;
		margin-bottom: 8px;
	}
	
	.wp-tts-player-controls {
		order: 2;
		flex: 1;
		justify-content: center;
	}
	
	.wp-tts-player-options {
		order: 3;
		width: 100%;
		justify-content: space-between;
	}
	
	.wp-tts-player-rate {
		flex: 1;
	}
	
	.wp-tts-player-rate-slider {
		flex: 1;
		max-width: none;
	}
}

