/**
 * Stache Player Frontend Styles
 *
 * Mobile-first, native app-inspired music player interface
 * Built for easy customization and rapid design iteration
 *
 * @package StachePlayer
 * @since 1.0.0
 */

/* ==========================================================================
   CSS Custom Properties - Design System
   ========================================================================== */

:root {
    /* Core Colors - Edit these to change the entire theme */
    --stache-primary: var(--stache-primary-color, #1a1a1a);
    --stache-accent: var(--stache-accent-color, #ff6b35);
    --stache-text: var(--stache-text-color, #ffffff);
    --stache-background: #0a0a0a;
    --stache-surface: #1e1e1e;
    --stache-surface-elevated: #2a2a2a;
    
    /* Semantic Colors */
    --stache-border: rgba(255, 255, 255, 0.1);
    --stache-border-focus: var(--stache-accent);
    --stache-text-secondary: rgba(255, 255, 255, 0.7);
    --stache-text-disabled: rgba(255, 255, 255, 0.3);
    --stache-shadow: rgba(0, 0, 0, 0.4);
    --stache-overlay: rgba(0, 0, 0, 0.8);
    
    /* Interactive States */
    --stache-hover: rgba(255, 255, 255, 0.05);
    --stache-active: rgba(255, 255, 255, 0.1);
    --stache-focus: 0 0 0 2px var(--stache-accent);
    
    /* Spacing System - Mobile-first sizes */
    --stache-space-xs: 4px;
    --stache-space-sm: 8px;
    --stache-space-md: 16px;
    --stache-space-lg: 24px;
    --stache-space-xl: 32px;
    --stache-space-2xl: 48px;
    
    /* Typography Scale */
    --stache-text-xs: 12px;
    --stache-text-sm: 14px;
    --stache-text-base: 16px;
    --stache-text-lg: 18px;
    --stache-text-xl: 20px;
    --stache-text-2xl: 24px;
    --stache-text-3xl: 30px;
    
    /* Layout */
    --stache-radius: 12px;
    --stache-radius-sm: 8px;
    --stache-radius-lg: 16px;
    --stache-radius-full: 9999px;
    
    /* Transitions */
    --stache-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --stache-transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --stache-transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Native App Dimensions */
    --stache-touch-target: 44px; /* iOS recommended minimum */
    --stache-progress-height: 4px;
    --stache-volume-height: 3px;
}

/* ==========================================================================
   Base Player Container
   ========================================================================== */

.stache-player {
    /* Layout */
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: var(--stache-space-lg);
    
    /* Appearance */
    background: var(--stache-background);
    color: var(--stache-text);
    border-radius: var(--stache-radius-lg);
    box-shadow: 
        0 10px 25px var(--stache-shadow),
        0 4px 6px rgba(0, 0, 0, 0.1);
    
    /* Typography */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: var(--stache-text-base);
    line-height: 1.5;
    
    /* Behavior */
    overflow: hidden;
    position: relative;
    isolation: isolate;
}

/* Style Variants */
.stache-player--compact {
    padding: var(--stache-space-md);
    max-width: 400px;
}

.stache-player--full {
    max-width: 500px;
}

/* ==========================================================================
   Hidden Audio Element
   ========================================================================== */

.stache-player__audio {
    display: none;
}

/* ==========================================================================
   Main Player Section
   ========================================================================== */

.stache-player__main {
    display: flex;
    flex-direction: column;
    gap: var(--stache-space-md);
    margin-bottom: var(--stache-space-xl);
}

/* ==========================================================================
   Track Information
   ========================================================================== */

.stache-player__track-info {
    display: flex;
    align-items: center;
    gap: var(--stache-space-md);
    text-align: left;
}

.stache-player__artwork {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: var(--stache-radius);
    overflow: hidden;
    background: var(--stache-surface);
    position: relative;
}

.stache-player__artwork-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--stache-primary), var(--stache-accent));
}

.stache-player__music-icon {
    width: 32px;
    height: 32px;
    opacity: 0.7;
    color: var(--stache-text);
}

.stache-player__track-details {
    flex: 1;
    min-width: 0; /* Allow text truncation */
}

.stache-player__track-title {
    font-size: var(--stache-text-xl);
    font-weight: 600;
    color: var(--stache-text);
    margin: 0 0 var(--stache-space-xs) 0;
    
    /* Text truncation */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stache-player__track-artist {
    font-size: var(--stache-text-base);
    color: var(--stache-text-secondary);
    margin: 0;
    
    /* Text truncation */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================================================
   Player Controls
   ========================================================================== */

.stache-player__controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--stache-space-lg);
}

.stache-player__btn {
    /* Reset button styles */
    appearance: none;
    border: none;
    background: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    
    /* Layout */
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--stache-touch-target);
    height: var(--stache-touch-target);
    
    /* Appearance */
    color: var(--stache-text);
    border-radius: var(--stache-radius-full);
    transition: var(--stache-transition);
    
    /* Interaction states */
    &:hover {
        background: var(--stache-hover);
        transform: scale(1.05);
    }
    
    &:active {
        background: var(--stache-active);
        transform: scale(0.95);
    }
    
    &:focus-visible {
        outline: none;
        box-shadow: var(--stache-focus);
    }
    
    &:disabled {
        opacity: 0.3;
        cursor: not-allowed;
        transform: none;
    }
}

/* Play Message (replaces main play button) */
.stache-player__play-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 64px;
    font-size: var(--stache-text-base);
    color: var(--stache-text-secondary);
    font-style: italic;
    text-align: center;
    opacity: 0.8;
}

/* ==========================================================================
   Progress Section
   ========================================================================== */

.stache-player__progress {
    display: flex;
    align-items: center;
    gap: var(--stache-space-md);
    margin: var(--stache-space-md) 0;
}

.stache-player__time {
    font-size: var(--stache-text-sm);
    color: var(--stache-text-secondary);
    font-variant-numeric: tabular-nums;
    min-width: 35px;
    text-align: center;
}

.stache-player__progress-bar {
    flex: 1;
    height: var(--stache-touch-target);
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: var(--stache-space-md) 0;
}

.stache-player__progress-track {
    position: relative;
    width: 100%;
    height: var(--stache-progress-height);
    background: var(--stache-border);
    border-radius: var(--stache-radius-full);
    overflow: hidden;
}

.stache-player__progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--stache-accent);
    border-radius: var(--stache-radius-full);
    width: 0%;
    transition: width 0.1s linear;
}

.stache-player__progress-handle {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 16px;
    height: 16px;
    background: var(--stache-accent);
    border-radius: var(--stache-radius-full);
    transform: translate(-50%, -50%);
    cursor: grab;
    opacity: 0;
    transition: var(--stache-transition);
    box-shadow: 0 2px 4px var(--stache-shadow);
    
    &:active {
        cursor: grabbing;
    }
    
    &:focus-visible {
        outline: none;
        box-shadow: var(--stache-focus);
        opacity: 1;
    }
}

.stache-player__progress-bar:hover .stache-player__progress-handle,
.stache-player__progress-handle:focus {
    opacity: 1;
}

/* ==========================================================================
   Volume Control
   ========================================================================== */

.stache-player__volume {
    display: flex;
    align-items: center;
    gap: var(--stache-space-sm);
    margin: var(--stache-space-md) 0;
}

.stache-player__btn--volume svg {
    width: 20px;
    height: 20px;
}

.stache-player__volume-bar {
    flex: 1;
    max-width: 100px;
    height: var(--stache-touch-target);
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: var(--stache-space-md) 0;
}

.stache-player__volume-track {
    position: relative;
    width: 100%;
    height: var(--stache-volume-height);
    background: var(--stache-border);
    border-radius: var(--stache-radius-full);
    overflow: hidden;
}

.stache-player__volume-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--stache-text);
    border-radius: var(--stache-radius-full);
    width: 100%;
    transition: width 0.1s linear;
}

.stache-player__volume-handle {
    position: absolute;
    top: 50%;
    left: 100%;
    width: 12px;
    height: 12px;
    background: var(--stache-text);
    border-radius: var(--stache-radius-full);
    transform: translate(-50%, -50%);
    cursor: grab;
    opacity: 0;
    transition: var(--stache-transition);
    box-shadow: 0 1px 2px var(--stache-shadow);
    
    &:active {
        cursor: grabbing;
    }
    
    &:focus-visible {
        outline: none;
        box-shadow: var(--stache-focus);
        opacity: 1;
    }
}

.stache-player__volume-bar:hover .stache-player__volume-handle,
.stache-player__volume-handle:focus {
    opacity: 1;
}

/* ==========================================================================
   Playlist Section
   ========================================================================== */

.stache-player__playlist {
    background: var(--stache-surface);
    border-radius: var(--stache-radius);
    margin-top: var(--stache-space-lg);
    overflow: hidden;
    transition: var(--stache-transition-slow);
}

.stache-player__playlist--collapsed .stache-player__playlist-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.stache-player__playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--stache-space-md) var(--stache-space-lg);
    border-bottom: 1px solid var(--stache-border);
    cursor: pointer;
    transition: var(--stache-transition);
    
    &:hover {
        background: var(--stache-hover);
    }
}

.stache-player__playlist-title {
    font-size: var(--stache-text-lg);
    font-weight: 600;
    margin: 0;
    color: var(--stache-text);
}

.stache-player__btn--playlist-toggle {
    width: 32px;
    height: 32px;
    transition: var(--stache-transition);
}

.stache-player__playlist--collapsed .stache-player__btn--playlist-toggle {
    transform: rotate(180deg);
}

.stache-player__playlist-content {
    max-height: 300px;
    overflow-y: auto;
    transition: var(--stache-transition-slow);
    padding: var(--stache-space-sm) 0;
}

/* ==========================================================================
   Track List
   ========================================================================== */

.stache-player__track-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.stache-player__track-item {
    position: relative;
    transition: var(--stache-transition);
    
    &:hover {
        background: var(--stache-hover);
    }
    
    &:focus-within {
        background: var(--stache-hover);
    }
}

.stache-player__track-item--active {
    background: rgba(var(--stache-accent-rgb, 255, 107, 53), 0.1);
    
    &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 3px;
        background: var(--stache-accent);
    }
}

.stache-player__track-button {
    /* Reset button styles */
    appearance: none;
    border: none;
    background: none;
    padding: var(--stache-space-md) var(--stache-space-lg);
    margin: 0;
    cursor: pointer;
    
    /* Layout */
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--stache-space-md);
    text-align: left;
    
    /* Typography */
    color: inherit;
    font-size: var(--stache-text-base);
    
    &:focus-visible {
        outline: none;
        box-shadow: inset var(--stache-focus);
    }
}

.stache-player__track-number {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--stache-text-sm);
    color: var(--stache-text-secondary);
    position: relative;
}

.stache-player__track-index {
    font-variant-numeric: tabular-nums;
}

.stache-player__track-playing-icon,
.stache-player__track-paused-icon {
    width: 16px;
    height: 16px;
    color: var(--stache-accent);
}

.stache-player__track-info-playlist {
    flex: 1;
    min-width: 0;
}

.stache-player__track-title-playlist {
    font-weight: 500;
    color: var(--stache-text);
    margin-bottom: 2px;
    
    /* Text truncation */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stache-player__track-artist-playlist {
    font-size: var(--stache-text-sm);
    color: var(--stache-text-secondary);
    
    /* Text truncation */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stache-player__track-duration {
    flex-shrink: 0;
    font-size: var(--stache-text-sm);
    color: var(--stache-text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Loading and Error States
   ========================================================================== */

.stache-player__loading,
.stache-player__error {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    padding: var(--stache-space-lg);
    background: var(--stache-overlay);
    color: var(--stache-text);
    border-radius: var(--stache-radius);
    backdrop-filter: blur(8px);
    z-index: 10;
}

.stache-player__loading-text,
.stache-player__error-text {
    font-size: var(--stache-text-sm);
    margin: 0;
}

/* ==========================================================================
   Error Message Styling
   ========================================================================== */

.stache-player-error {
    padding: var(--stache-space-lg);
    text-align: center;
    background: var(--stache-surface);
    border: 1px solid var(--stache-border);
    border-radius: var(--stache-radius);
    color: var(--stache-text-secondary);
}

.stache-player-error p {
    margin: 0;
    font-size: var(--stache-text-base);
}

/* ==========================================================================
   Responsive Design - Tablet and Desktop
   ========================================================================== */

@media (min-width: 768px) {
    .stache-player {
        padding: var(--stache-space-xl);
    }
    
    .stache-player__track-info {
        gap: var(--stache-space-lg);
    }
    
    .stache-player__artwork {
        width: 120px;
        height: 120px;
    }
    
    .stache-player__music-icon {
        width: 48px;
        height: 48px;
    }
    
    .stache-player__track-title {
        font-size: var(--stache-text-2xl);
    }
    
    .stache-player__track-artist {
        font-size: var(--stache-text-lg);
    }
    
    .stache-player__controls {
        gap: var(--stache-space-xl);
    }
    
    .stache-player__btn--play {
        width: 80px;
        height: 80px;
    }
    
    .stache-player__btn--play svg {
        width: 40px;
        height: 40px;
    }
    
    .stache-player__volume-bar {
        max-width: 150px;
    }
}

@media (min-width: 1024px) {
    .stache-player--full {
        max-width: 600px;
    }
    
    .stache-player__playlist-content {
        max-height: 400px;
    }
}

/* ==========================================================================
   Accessibility Enhancements
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .stache-player,
    .stache-player *,
    .stache-player *::before,
    .stache-player *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .stache-player {
        border: 2px solid var(--stache-text);
    }
    
    .stache-player__btn {
        border: 1px solid var(--stache-border);
    }
    
    .stache-player__btn--play {
        border: 2px solid var(--stache-text);
    }
}

/* Focus visible improvements for keyboard users */
.stache-player *:focus:not(:focus-visible) {
    outline: none;
}

.stache-player *:focus-visible {
    outline: 2px solid var(--stache-accent);
    outline-offset: 2px;
}

/* ==========================================================================
   Print Styles (Hide player in print)
   ========================================================================== */

@media print {
    .stache-player {
        display: none;
    }
}