/**
 * Radio Sticky Player Pro v2.0 - Mobile Optimized CSS
 * 
 * Fixes for:
 * - iOS safe area (notch/home bar)
 * - Larger touch targets (48px minimum)
 * - backdrop-filter fallbacks
 * - GPU accelerated animations
 * - Better responsive design
 * 
 * @package RadioStickyPlayerPro
 * @version 2.0.0
 */

/* ============================================
   CSS Variables
   ============================================ */
:root {
    --rsp-primary: #6366f1;
    --rsp-accent: #22d3ee;
    --rsp-bg-dark: rgba(15, 15, 25, 0.97);
    --rsp-bg-light: rgba(255, 255, 255, 0.97);
    --rsp-glass: rgba(255, 255, 255, 0.1);
    --rsp-glass-border: rgba(255, 255, 255, 0.15);
    --rsp-text-dark: #f8fafc;
    --rsp-text-light: #1e293b;
    --rsp-text-muted: #64748b;
    --rsp-radius: 12px;
    --rsp-radius-lg: 16px;
    --rsp-glow: 0 0 20px rgba(34, 211, 238, 0.4);
    --rsp-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
    --rsp-transition: cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Touch target sizes */
    --rsp-touch-min: 48px;
    --rsp-touch-sm: 44px;
    
    /* Safe area insets (will be updated by env()) */
    --rsp-safe-bottom: env(safe-area-inset-bottom, 0px);
    --rsp-safe-left: env(safe-area-inset-left, 0px);
    --rsp-safe-right: env(safe-area-inset-right, 0px);
}

/* ============================================
   Reset & Base
   ============================================ */
.rsp-player,
.rsp-player *,
.rsp-player *::before,
.rsp-player *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ============================================
   Main Player Container
   ============================================ */
.rsp-player {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999999;
    
    /* Typography */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* Initial hidden state */
    opacity: 0;
    transform: translateY(100%);
    
    /* Performance: GPU acceleration */
    will-change: transform, opacity;
    transform: translateY(100%) translateZ(0);
    backface-visibility: hidden;
    
    /* Transition */
    transition: 
        opacity 0.35s var(--rsp-transition), 
        transform 0.35s var(--rsp-transition);
    
    /* Prevent text selection on mobile */
    -webkit-user-select: none;
    user-select: none;
    
    /* Prevent iOS scroll bounce affecting player */
    overscroll-behavior: contain;
    touch-action: pan-x;
}

.rsp-player.rsp-loaded {
    opacity: 1;
    transform: translateY(0) translateZ(0);
}

/* ============================================
   Player Inner Container
   ============================================ */
.rsp-player-inner {
    display: flex;
    align-items: center;
    gap: 14px;
    
    /* Padding with safe area support */
    padding: 14px 20px;
    padding-bottom: calc(14px + var(--rsp-safe-bottom));
    padding-left: calc(20px + var(--rsp-safe-left));
    padding-right: calc(20px + var(--rsp-safe-right));
    
    /* Background with fallback for no backdrop-filter */
    background: var(--rsp-bg-dark);
    
    /* Border */
    border-top: 1px solid var(--rsp-glass-border);
    
    /* Shadow */
    box-shadow: var(--rsp-shadow);
    
    /* Minimum height for touch */
    min-height: 72px;
}

/* Glassmorphism - only if supported */
@supports (backdrop-filter: blur(20px)) or (-webkit-backdrop-filter: blur(20px)) {
    .rsp-player-inner {
        background: rgba(15, 15, 25, 0.85);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        backdrop-filter: blur(20px) saturate(180%);
    }
}

/* ============================================
   Theme Variants
   ============================================ */

/* Dark Theme (default) */
.rsp-theme-dark .rsp-player-inner {
    background: var(--rsp-bg-dark);
    color: var(--rsp-text-dark);
}

@supports (backdrop-filter: blur(20px)) {
    .rsp-theme-dark .rsp-player-inner {
        background: rgba(15, 15, 25, 0.85);
    }
}

/* Light Theme */
.rsp-theme-light .rsp-player-inner {
    background: var(--rsp-bg-light);
    color: var(--rsp-text-light);
    border-top-color: rgba(0, 0, 0, 0.1);
}

@supports (backdrop-filter: blur(20px)) {
    .rsp-theme-light .rsp-player-inner {
        background: rgba(255, 255, 255, 0.85);
    }
}

.rsp-theme-light .rsp-btn {
    color: var(--rsp-text-light);
}

.rsp-theme-light .rsp-volume-slider::-webkit-slider-runnable-track {
    background: rgba(0, 0, 0, 0.1);
}

.rsp-theme-light .rsp-now-playing {
    color: var(--rsp-primary);
}

/* Transparent Theme */
.rsp-theme-transparent .rsp-player-inner {
    background: rgba(0, 0, 0, 0.75);
}

@supports (backdrop-filter: blur(20px)) {
    .rsp-theme-transparent .rsp-player-inner {
        background: rgba(0, 0, 0, 0.5);
        -webkit-backdrop-filter: blur(30px);
        backdrop-filter: blur(30px);
    }
}

/* Auto Theme - follows system preference */
@media (prefers-color-scheme: light) {
    .rsp-theme-auto .rsp-player-inner {
        background: var(--rsp-bg-light);
        color: var(--rsp-text-light);
        border-top-color: rgba(0, 0, 0, 0.1);
    }
    
    .rsp-theme-auto .rsp-btn {
        color: var(--rsp-text-light);
    }
    
    .rsp-theme-auto .rsp-now-playing {
        color: var(--rsp-primary);
    }
}

/* ============================================
   Station Logo
   ============================================ */
.rsp-station-logo {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--rsp-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Subtle glow when playing */
    transition: box-shadow 0.3s ease;
}

.rsp-playing .rsp-station-logo {
    box-shadow: var(--rsp-glow);
}

.rsp-station-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rsp-logo-placeholder {
    font-size: 24px;
    color: var(--rsp-accent);
    opacity: 0.8;
}

/* ============================================
   Station Info
   ============================================ */
.rsp-station-info {
    flex: 1;
    min-width: 0;
    max-width: 300px;
}

.rsp-station-name {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 3px;
}

.rsp-name-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* LIVE Indicator */
.rsp-live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    opacity: 0.5;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.rsp-live-indicator.rsp-live-active,
.rsp-playing .rsp-live-indicator {
    opacity: 1;
    background: rgba(239, 68, 68, 0.2);
}

.rsp-live-dot {
    width: 6px;
    height: 6px;
    background: #ef4444;
    border-radius: 50%;
    animation: rsp-pulse 1.5s ease-in-out infinite;
}

.rsp-playing .rsp-live-dot {
    animation: rsp-pulse 1s ease-in-out infinite;
}

@keyframes rsp-pulse {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1); 
    }
    50% { 
        opacity: 0.4; 
        transform: scale(0.7); 
    }
}

/* Now Playing */
.rsp-now-playing {
    color: var(--rsp-accent);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 18px;
}

.rsp-now-playing-text {
    display: inline-block;
    transition: opacity 0.2s ease;
}

.rsp-now-playing-text.rsp-fade-out {
    opacity: 0;
}

/* ============================================
   Visualizer
   ============================================ */
.rsp-visualizer {
    flex-shrink: 0;
    width: 80px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.rsp-playing .rsp-visualizer {
    opacity: 1;
}

#rsp-visualizer-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ============================================
   Controls
   ============================================ */
.rsp-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Base Button Styles */
.rsp-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Minimum touch target size */
    min-width: var(--rsp-touch-min);
    min-height: var(--rsp-touch-min);
    width: var(--rsp-touch-min);
    height: var(--rsp-touch-min);
    
    padding: 0;
    border: none;
    background: transparent;
    color: var(--rsp-text-dark);
    cursor: pointer;
    border-radius: 50%;
    
    /* Transitions */
    transition: all 0.2s var(--rsp-transition);
    
    /* Performance */
    will-change: transform, background-color;
    
    /* Remove tap highlight on mobile */
    -webkit-tap-highlight-color: transparent;
    
    /* Improve touch response */
    touch-action: manipulation;
}

.rsp-btn:hover {
    background: var(--rsp-glass);
}

.rsp-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4);
}

.rsp-btn:focus:not(:focus-visible) {
    box-shadow: none;
}

.rsp-btn:active {
    transform: scale(0.92);
}

.rsp-btn svg {
    display: block;
    pointer-events: none;
    width: 22px;
    height: 22px;
}

.rsp-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Play Button - Larger and prominent */
.rsp-btn-play {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    background: var(--rsp-primary);
    color: white;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.rsp-btn-play:hover {
    background: var(--rsp-primary);
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.rsp-btn-play:active {
    transform: scale(0.95);
}

.rsp-btn-play svg {
    width: 26px;
    height: 26px;
}

/* Play/Pause icon toggle */
.rsp-icon-play,
.rsp-icon-pause {
    display: flex;
    align-items: center;
    justify-content: center;
}

.rsp-btn-play .rsp-icon-pause {
    display: none;
}

.rsp-playing .rsp-btn-play .rsp-icon-play {
    display: none;
}

.rsp-playing .rsp-btn-play .rsp-icon-pause {
    display: flex;
}

/* Loading Spinner */
.rsp-btn-loader {
    display: none;
    position: absolute;
    width: 26px;
    height: 26px;
    border: 3px solid rgba(255,255,255,0.25);
    border-top-color: white;
    border-radius: 50%;
    animation: rsp-spin 0.8s linear infinite;
}

.rsp-loading .rsp-btn-play .rsp-icon-play,
.rsp-loading .rsp-btn-play .rsp-icon-pause {
    display: none;
}

.rsp-loading .rsp-btn-play .rsp-btn-loader {
    display: block;
}

@keyframes rsp-spin {
    to { transform: rotate(360deg); }
}

/* Volume Control */
.rsp-volume-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Volume Icon (static, non-interactive) */
.rsp-volume-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--rsp-touch-sm);
    height: var(--rsp-touch-sm);
    min-width: var(--rsp-touch-sm);
    min-height: var(--rsp-touch-sm);
    opacity: 0.7;
}

.rsp-volume-icon svg {
    width: 20px;
    height: 20px;
}

.rsp-muted .rsp-volume-icon {
    opacity: 0.4;
}

/* Volume Slider */
.rsp-volume-slider-wrap {
    position: relative;
    width: 90px;
    height: var(--rsp-touch-sm);
    display: flex;
    align-items: center;
    padding: 0 4px;
}

.rsp-volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--rsp-glass);
    border-radius: 3px;
    cursor: pointer;
    
    /* Improve touch on mobile */
    touch-action: none;
}

/* Webkit (Chrome, Safari, Edge) */
.rsp-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--rsp-accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rsp-volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.rsp-volume-slider::-webkit-slider-thumb:active {
    transform: scale(1.25);
}

/* Firefox */
.rsp-volume-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--rsp-accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rsp-volume-slider::-moz-range-track {
    background: var(--rsp-glass);
    height: 6px;
    border-radius: 3px;
}

/* Volume Fill (custom) */
.rsp-volume-fill {
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    background: var(--rsp-accent);
    border-radius: 3px;
    pointer-events: none;
    width: 80%;
    transition: width 0.1s ease;
}

/* Station Selector */
.rsp-station-selector {
    display: flex;
    gap: 2px;
}

.rsp-btn-prev,
.rsp-btn-next {
    width: var(--rsp-touch-sm);
    height: var(--rsp-touch-sm);
    min-width: var(--rsp-touch-sm);
    min-height: var(--rsp-touch-sm);
}

.rsp-btn-prev svg,
.rsp-btn-next svg {
    width: 20px;
    height: 20px;
}

/* Hide station buttons if only one station */
.rsp-single-station .rsp-station-selector {
    display: none;
}

/* Collapse Button */
.rsp-btn-collapse {
    width: var(--rsp-touch-sm);
    height: var(--rsp-touch-sm);
    min-width: var(--rsp-touch-sm);
    min-height: var(--rsp-touch-sm);
}

/* ============================================
   Mini Player (Collapsed State)
   ============================================ */
.rsp-mini-player {
    display: none;
    padding: 10px 16px;
    padding-bottom: calc(10px + var(--rsp-safe-bottom));
    background: var(--rsp-bg-dark);
    border-top: 1px solid var(--rsp-glass-border);
}

@supports (backdrop-filter: blur(20px)) {
    .rsp-mini-player {
        background: rgba(15, 15, 25, 0.85);
        -webkit-backdrop-filter: blur(20px);
        backdrop-filter: blur(20px);
    }
}

.rsp-collapsed .rsp-player-inner {
    display: none;
}

.rsp-collapsed .rsp-mini-player {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.rsp-btn-expand {
    width: auto;
    padding: 0 16px;
    gap: 8px;
    border-radius: var(--rsp-radius);
    height: var(--rsp-touch-min);
}

.rsp-mini-status {
    font-size: 14px;
    font-weight: 500;
}

/* ============================================
   Error Message (hidden - errors handled silently)
   ============================================ */
.rsp-error-message {
    display: none !important;
}

.rsp-btn-retry {
    display: none !important;
}

.rsp-tap-to-play .rsp-error-message {
    display: none !important;
}

/* ============================================
   Offline Indicator
   ============================================ */
.rsp-offline-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
}

.rsp-offline .rsp-offline-indicator {
    display: inline-flex;
}

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 768px) {
    .rsp-player-inner {
        gap: 10px;
        padding: 12px 14px;
        padding-bottom: calc(12px + var(--rsp-safe-bottom));
        min-height: 68px;
    }

    .rsp-station-logo {
        width: 46px;
        height: 46px;
    }

    .rsp-station-info {
        max-width: 160px;
    }

    .rsp-station-name {
        font-size: 14px;
        gap: 8px;
    }

    .rsp-live-indicator {
        padding: 2px 8px;
        font-size: 9px;
    }

    .rsp-now-playing {
        font-size: 12px;
    }

    /* Hide visualizer on mobile by default */
    .rsp-visualizer {
        display: none;
    }
    
    /* Show if explicitly enabled */
    .rsp-mobile-visualizer .rsp-visualizer {
        display: flex;
        width: 50px;
    }

    /* Hide volume slider on mobile - use hardware buttons */
    .rsp-volume-slider-wrap {
        display: none;
    }

    .rsp-btn-play {
        width: 52px;
        height: 52px;
        min-width: 52px;
        min-height: 52px;
    }

    .rsp-btn {
        width: var(--rsp-touch-min);
        height: var(--rsp-touch-min);
    }

    /* Hide less important controls */
    .rsp-btn-collapse {
        display: none;
    }
}

/* Small phones */
@media (max-width: 380px) {
    .rsp-player-inner {
        gap: 8px;
        padding: 10px 12px;
        padding-bottom: calc(10px + var(--rsp-safe-bottom));
    }

    .rsp-station-logo {
        width: 42px;
        height: 42px;
    }

    .rsp-station-info {
        max-width: 120px;
    }

    .rsp-station-name {
        font-size: 13px;
    }

    .rsp-btn-play {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }

    /* Hide station navigation on very small screens */
    .rsp-station-selector {
        display: none;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .rsp-player-inner {
        min-height: 56px;
        padding: 8px 20px;
        padding-bottom: calc(8px + var(--rsp-safe-bottom));
    }

    .rsp-station-logo {
        width: 40px;
        height: 40px;
    }

    .rsp-btn-play {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
}

/* ============================================
   iOS Specific Fixes
   ============================================ */
.rsp-is-ios .rsp-player-inner {
    /* Extra bottom padding for home indicator */
    padding-bottom: calc(16px + var(--rsp-safe-bottom));
}

/* Fix for iOS Safari position: fixed issues */
.rsp-is-ios.rsp-keyboard-open .rsp-player {
    position: absolute;
}

/* ============================================
   State Classes
   ============================================ */

/* Switching station animation */
.rsp-switching .rsp-station-info {
    opacity: 0.5;
    transform: translateX(10px);
    transition: all 0.2s ease;
}

/* Autoplay blocked state */
.rsp-autoplay-blocked .rsp-btn-play {
    animation: rsp-attention 1s ease-in-out 3;
}

@keyframes rsp-attention {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* ============================================
   Accessibility
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .rsp-player,
    .rsp-player *,
    .rsp-btn,
    .rsp-btn-loader,
    .rsp-live-dot {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .rsp-player-inner {
        background: #000 !important;
        border-top: 2px solid #fff !important;
    }

    .rsp-btn {
        border: 2px solid currentColor;
    }

    .rsp-btn-play {
        background: #fff !important;
        color: #000 !important;
    }
}

/* Focus visible for keyboard navigation */
.rsp-btn:focus-visible {
    outline: 3px solid var(--rsp-accent);
    outline-offset: 2px;
}

/* ============================================
   Print (hide player)
   ============================================ */
@media print {
    .rsp-player {
        display: none !important;
    }
}

/* ============================================
   Loading State Skeleton
   ============================================ */
.rsp-skeleton {
    background: linear-gradient(
        90deg,
        var(--rsp-glass) 0%,
        rgba(255,255,255,0.15) 50%,
        var(--rsp-glass) 100%
    );
    background-size: 200% 100%;
    animation: rsp-skeleton 1.5s ease-in-out infinite;
}

@keyframes rsp-skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
