/* ============================================
   DESIGN SYSTEM — RANDOM PODCAST PLAYER
   iPhone-optimized, dark mode, glassmorphism
   ============================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0f;
    --bg-card: rgba(18, 18, 28, 0.85);
    --glass: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f0f0f5;
    --text-secondary: rgba(240, 240, 245, 0.55);
    --text-tertiary: rgba(240, 240, 245, 0.3);
    --accent: #8b5cf6;
    --accent-glow: rgba(139, 92, 246, 0.35);
    --accent-secondary: #c084fc;
    --accent-warm: #f472b6;
    --progress-bg: rgba(255, 255, 255, 0.08);
    --progress-buffered: rgba(255, 255, 255, 0.15);
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --radius-full: 50%;
    --safe-top: env(safe-area-inset-top, 20px);
    --safe-bottom: env(safe-area-inset-bottom, 20px);
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-med: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
    -webkit-user-select: none;
}

/* ---------- App Shell ---------- */
.app {
    position: relative;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Ambient Background ---------- */
.ambient-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.4;
    animation: blobDrift 20s ease-in-out infinite alternate;
}

.blob-1 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
    top: -80px;
    right: -60px;
    animation-delay: 0s;
}

.blob-2 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, var(--accent-warm) 0%, transparent 70%);
    bottom: -60px;
    left: -80px;
    animation-delay: -7s;
    animation-duration: 25s;
}

.blob-3 {
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, var(--accent-secondary) 0%, transparent 70%);
    top: 40%;
    left: 50%;
    transform: translateX(-50%);
    animation-delay: -14s;
    animation-duration: 30s;
    opacity: 0.2;
}

@keyframes blobDrift {
    0% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -20px) scale(1.1); }
    66% { transform: translate(-20px, 30px) scale(0.9); }
    100% { transform: translate(10px, -10px) scale(1.05); }
}

/* ---------- Player Container ---------- */
.player-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    padding: calc(var(--safe-top) + 16px) 24px calc(var(--safe-bottom) + 16px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    height: 100dvh;
    justify-content: center;
}

/* ---------- Header ---------- */
.podcast-header {
    width: 100%;
    text-align: center;
}

.podcast-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.podcast-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--accent-secondary);
    background: rgba(139, 92, 246, 0.12);
    padding: 4px 12px;
    border-radius: 100px;
    border: 1px solid rgba(139, 92, 246, 0.15);
}

.episode-counter {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-tertiary);
}

/* ---------- Artwork ---------- */
.artwork-wrapper {
    position: relative;
    width: 72vw;
    max-width: 300px;
    aspect-ratio: 1;
    flex-shrink: 0;
}

.artwork-glow {
    position: absolute;
    inset: -20%;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 60%);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 1s ease;
    pointer-events: none;
}

.artwork-glow.active {
    opacity: 1;
    animation: pulseGlow 4s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 0.9; transform: scale(1.05); }
}

.artwork {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: transform var(--transition-spring);
    cursor: pointer;
}

.artwork:active {
    transform: scale(0.96);
}

.artwork img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.artwork-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-med);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.artwork:active .artwork-overlay {
    opacity: 1;
}

.shuffle-icon {
    width: 48px;
    height: 48px;
    color: white;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
}

/* Spinning animation for loading */
.artwork.loading {
    animation: artworkPulse 1.5s ease-in-out infinite;
}

@keyframes artworkPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ---------- Episode Info ---------- */
.episode-info {
    text-align: center;
    width: 100%;
    padding: 0 8px;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.episode-title {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-primary);
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: opacity var(--transition-med);
}

.episode-title.fade {
    opacity: 0;
}

.episode-date {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
    transition: opacity var(--transition-med);
}

.episode-date.fade {
    opacity: 0;
}

/* ---------- Progress ---------- */
.progress-container {
    width: 100%;
    padding: 0 4px;
}

.progress-bar {
    position: relative;
    height: 4px;
    background: var(--progress-bg);
    border-radius: 100px;
    overflow: visible;
    cursor: pointer;
    touch-action: none;
}

.progress-bar::before {
    content: '';
    position: absolute;
    inset: -12px -4px;
    /* Larger touch target */
}

.progress-buffered {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: var(--progress-buffered);
    border-radius: 100px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-played {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-secondary));
    border-radius: 100px;
    width: 0%;
    z-index: 1;
}

.progress-thumb {
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 12px;
    height: 12px;
    background: white;
    border-radius: var(--radius-full);
    box-shadow: 0 0 8px var(--accent-glow), 0 2px 4px rgba(0,0,0,0.3);
    transition: transform var(--transition-fast);
}

.progress-container:hover .progress-thumb,
.progress-container.dragging .progress-thumb {
    transform: translateY(-50%) scale(1);
}

.progress-container.dragging .progress-bar {
    height: 6px;
}

.time-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

/* ---------- Controls ---------- */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    width: 100%;
    padding: 8px 0;
}

.control-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    transform: scale(0.9);
    opacity: 0.7;
}

.control-btn svg {
    width: 28px;
    height: 28px;
}

.skip-label {
    position: absolute;
    font-size: 0.5rem;
    font-weight: 700;
    color: var(--text-primary);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin-top: 1px;
    pointer-events: none;
}

/* Play button */
.control-btn-play {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--accent), var(--accent-warm));
    border-radius: var(--radius-full);
    box-shadow: 
        0 4px 20px var(--accent-glow),
        inset 0 1px 0 rgba(255,255,255,0.2);
    transition: all var(--transition-med);
}

.control-btn-play:active {
    transform: scale(0.92);
}

.control-btn-play svg {
    width: 32px;
    height: 32px;
}

.control-btn-play .icon-play {
    margin-left: 3px; /* Visual centering for play triangle */
}

.play-ring {
    position: absolute;
    inset: -4px;
    border: 2px solid var(--accent);
    border-radius: var(--radius-full);
    opacity: 0;
    transition: all var(--transition-med);
}

.control-btn-play.playing .play-ring {
    opacity: 0.3;
    animation: playRing 2s ease-in-out infinite;
}

@keyframes playRing {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.15); opacity: 0; }
}

/* ---------- Bottom Actions ---------- */
.bottom-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 8px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 100px;
    padding: 8px 16px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.action-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.08);
}

.action-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.action-btn-shuffle {
    background: rgba(139, 92, 246, 0.12);
    border-color: rgba(139, 92, 246, 0.2);
    color: var(--accent-secondary);
}

.action-btn-shuffle:active {
    background: rgba(139, 92, 246, 0.25);
}

.action-btn.active {
    color: var(--accent-secondary);
    border-color: rgba(139, 92, 246, 0.3);
    background: rgba(139, 92, 246, 0.1);
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-med);
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    width: 100%;
    max-width: 420px;
    background: rgba(28, 28, 38, 0.95);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 24px 24px calc(var(--safe-bottom) + 24px);
    transform: translateY(100%);
    transition: transform var(--transition-slow);
    border-top: 1px solid var(--glass-border);
}

.modal-overlay.show .modal {
    transform: translateY(0);
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.modal-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.modal-option {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 14px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.modal-option:active {
    transform: scale(0.96);
    background: rgba(139, 92, 246, 0.15);
    border-color: var(--accent);
}

.modal-close {
    width: 100%;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 14px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.modal-close:active {
    transform: scale(0.98);
}

/* ---------- Shuffle Animation ---------- */
@keyframes shuffleSpin {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(90deg) scale(0.8); }
    50% { transform: rotate(180deg) scale(1.1); }
    75% { transform: rotate(270deg) scale(0.9); }
    100% { transform: rotate(360deg) scale(1); }
}

.artwork.shuffling {
    animation: shuffleSpin 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Episode transition ---------- */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.episode-info.reveal .episode-title,
.episode-info.reveal .episode-date {
    animation: slideInUp 0.4s ease-out both;
}

.episode-info.reveal .episode-date {
    animation-delay: 0.08s;
}

/* ---------- Responsive ---------- */
@media (max-height: 680px) {
    .artwork-wrapper {
        width: 55vw;
        max-width: 240px;
    }
    
    .player-container {
        gap: 14px;
    }
    
    .controls {
        gap: 24px;
    }
    
    .control-btn-play {
        width: 60px;
        height: 60px;
    }
}

@media (max-height: 580px) {
    .artwork-wrapper {
        width: 45vw;
        max-width: 200px;
    }

    .player-container {
        gap: 10px;
    }

    .podcast-header {
        display: none;
    }
}

/* iPhone SE height */
@media (max-height: 570px) {
    .artwork-wrapper {
        width: 40vw;
        max-width: 180px;
    }
}

/* Desktop / iPad */
@media (min-width: 768px) {
    .player-container {
        max-width: 440px;
    }
    
    .artwork-wrapper {
        max-width: 320px;
    }
}

/* ---------- Haptic feedback visual hint ---------- */
@keyframes tapFeedback {
    0% { box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { box-shadow: 0 0 0 12px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}
