:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --bg-light: #f8f9fa;
    --text-dark: #1a202c;
    --text-gray: #718096;
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

body {
    font-family: 'Inter', sans-serif;
}

/* --- Layout & Utility --- */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: 80vh;
}

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.4s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Header & Controls --- */
.app-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1.5rem;
}

.app-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
}

/* Sliding Segment Control */
.sort-controls {
    background: #e2e8f0;
    padding: 4px;
    border-radius: 50px;
    display: flex;
    position: relative;
    width: fit-content;
    min-width: 300px;
}

.sort-radio {
    display: none;
}

.sort-label {
    flex: 1;
    padding: 8px 16px;
    cursor: pointer;
    text-align: center;
    z-index: 2;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-gray);
    transition: color 0.3s ease;
    user-select: none;
    white-space: nowrap;
}

/* The Glider (Sliding Background) */
.glider {
    position: absolute;
    top: 4px;
    left: 4px;
    height: calc(100% - 8px);
    width: calc((100% - 8px) / 3); /* 3 options, so divide by 3 */
    background: white;
    border-radius: 50px;
    z-index: 1;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Glider Logic */
#sortSeries:checked ~ .glider { transform: translateX(0%); }
#sortSpeaker:checked ~ .glider { transform: translateX(100%); }
#sortDate:checked ~ .glider { transform: translateX(200%); }

/* Text Color Change on Selection */
#sortSeries:checked + .sort-label,
#sortSpeaker:checked + .sort-label,
#sortDate:checked + .sort-label {
    color: var(--accent);
}

/* --- View 1: The Library Grid --- */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
}

.bucket-card {
    background: white;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1px solid #edf2f7;
}

.bucket-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 20px rgba(0,0,0,0.1);
}

.bucket-image {
    height: 180px;
    background-color: var(--primary);
    background-size: cover;
    background-position: center;
    position: relative;
}

/* Overlay for text legibility on images */
.bucket-image::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 50%;
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
}

.bucket-content {
    padding: 1.25rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.bucket-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
}

.bucket-meta {
    font-size: 0.85rem;
    color: var(--text-gray);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.count-badge {
    background: #edf2f7;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-gray);
}

/* --- View 2: The Split Player --- */
.player-view {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 2rem;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    overflow: hidden;
    min-height: 600px;
}

/* Back Button Area */
.player-nav {
    grid-column: 1 / -1;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #edf2f7;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-back {
    background: transparent;
    border: 1px solid #cbd5e0;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-gray);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-back:hover {
    background: #edf2f7;
    color: var(--primary);
}

.current-bucket-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

/* Sidebar List */
.playlist-sidebar {
    background: #f8f9fa;
    border-right: 1px solid #edf2f7;
    overflow-y: auto;
    max-height: 80vh;
}

.playlist-item {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #edf2f7;
    cursor: pointer;
    transition: background 0.2s;
}

.playlist-item:hover {
    background: #fff;
}

.playlist-item.active {
    background: white;
    border-left: 4px solid var(--accent);
}

.playlist-item h4 {
    margin: 0 0 5px 0;
    font-size: 0.95rem;
    color: var(--text-dark);
}

.playlist-item .meta {
    font-size: 0.8rem;
    color: var(--text-gray);
}

/* Main Player Area */
.player-main {
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

.media-container-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

/* Flip Animation Container */
.media-flip-scene {
    perspective: 1000px;
    width: 100%;
    margin-bottom: 1.5rem;
}

.media-flip-card {
    width: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
}

/* Use this class to trigger the flip */
.media-flip-card.is-flipped {
    transform: rotateY(180deg);
}

/* Common Face Styles */
.media-face {
    width: 100%;
    backface-visibility: hidden;
    border-radius: var(--border-radius);
    overflow: hidden;
    background: black;
}

/* Front Face (Video) */
.media-face-front {
    z-index: 2;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Back Face (Audio) */
.media-face-back {
    transform: rotateY(180deg);
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a202c;
}

.media-face iframe, .media-face video {
    width: 100%;
    height: 100%;
    border: none;
}

.media-face audio {
    width: 90%;
}

.btn-swap-format {
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    background: transparent;
    border: 1px solid transparent;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
}

.btn-swap-format:hover {
    background: #f8f9fa;
    border-color: #e2e8f0;
}

.sermon-details h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.sermon-details .speaker {
    font-size: 1.1rem;
    color: var(--text-gray);
    margin-bottom: 1.5rem;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.btn-resource {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
    cursor: pointer;
    border: none;
}

/* PDF Viewer Container */
.pdf-viewer-container {
    margin-top: 2rem;
    border: 1px solid #edf2f7;
    border-radius: var(--border-radius);
    overflow: hidden;
    background: #fff;
}

.pdf-header {
    padding: 10px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #edf2f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pdf-title { font-weight: 600; color: var(--primary); font-size: 0.9rem; }

.btn-download-sm {
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.pdf-frame {
    width: 100%;
    height: 600px;
    border: none;
}

.btn-slides {
    background-color: #dff9fb;
    color: #2980b9;
}
.btn-slides:hover { background-color: #c7ecee; }

.btn-notes {
    background-color: #ffeaa7;
    color: #d35400;
}
.btn-notes:hover { background-color: #fdcb6e; }

.btn-bible {
    background-color: #e8f5e9;
    color: #2e7d32;
}
.btn-bible:hover { background-color: #c8e6c9; }

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .player-view {
        grid-template-columns: 1fr;
        display: flex;
        flex-direction: column;
    }

    .playlist-sidebar {
        order: 2;
        max-height: 400px;
        border-top: 1px solid #edf2f7;
    }

    .player-main {
        order: 1;
        padding: 1rem;
    }
    
    .sort-controls {
        min-width: 100%;
    }
    
    .pdf-frame {
        height: 400px;
    }
    
    .pdf-viewer-container {
        display: none !important;
    }
}

/* Loading Spinner */
.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 50px auto;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }