/* ============================================================
   Quran Persistent Audio Controller
   Spotify-style fixed bottom player bar
   ============================================================
   Brand tokens:
     primary   #004aad   (deep blue)
     emerald   #0d5c3a   (Islamic green)
     gold      #c9a84c   (warm gold)
     magenta   #cb6ce6
   ============================================================ */


/* ============================================================
   1. FIXED BOTTOM PLAYER BAR
   ============================================================ */

.quran-player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: linear-gradient(135deg, #0d5c3a 0%, #0a4e32 60%, #083d28 100%);
    color: #fff;
    z-index: 9999;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.35),
                0 -1px 4px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 14px;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    border-top: 1px solid rgba(201, 168, 76, 0.15);
}

.quran-player-bar.visible {
    transform: translateY(0);
}

/* Body padding offset when player is active */
body.player-active {
    padding-bottom: 56px;
}


/* ============================================================
   2. PLAYER CONTROLS LAYOUT
   ============================================================ */

/* --- Transport buttons (prev / play-pause / next) --- */

.qp-controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.qp-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, 0.55);
    color: rgba(255, 255, 255, 0.85);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s ease,
                color 0.2s ease,
                background-color 0.2s ease;
    font-size: 0.85rem;
    padding: 0;
    line-height: 1;
    outline: none;
}

.qp-btn:hover {
    border-color: #c9a84c;
    color: #c9a84c;
}

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

.qp-btn:focus-visible {
    box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.5);
}

/* Play/pause is slightly larger and gets a gold accent when playing */
.qp-btn-play {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
    border-width: 2px;
    border-color: rgba(255, 255, 255, 0.7);
}

.qp-btn-play:hover {
    border-color: #c9a84c;
    background: rgba(201, 168, 76, 0.12);
}

.qp-btn-play.playing {
    background: #c9a84c;
    border-color: #c9a84c;
    color: #0d5c3a;
}

.qp-btn-play.playing:hover {
    background: #d4b35a;
    border-color: #d4b35a;
}


/* --- Now-playing label (sura:aya + speaker) --- */

.qp-label {
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
    overflow: hidden;
    max-width: 200px;
    flex-shrink: 1;
    min-width: 0;
    line-height: 1.25;
}

.qp-label-ref {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.02em;
}

.qp-label-speaker {
    font-size: 0.7rem;
    opacity: 0.65;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* --- Progress bar --- */

.qp-progress-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 6px 0;
    min-width: 0;
    -webkit-tap-highlight-color: transparent;
}

.qp-progress-track {
    position: relative;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 2px;
    overflow: visible;
}

.qp-progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #c9a84c;
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
    pointer-events: none;
}

.qp-progress-thumb {
    position: absolute;
    top: 50%;
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.18s ease;
    pointer-events: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.qp-progress-wrap:hover .qp-progress-thumb {
    opacity: 1;
}

.qp-progress-wrap:hover .qp-progress-track {
    height: 5px;
}

.qp-progress-wrap:hover .qp-progress-fill {
    background: #d4b35a;
}


/* --- Time display --- */

.qp-time {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    font-family: "SF Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
    min-width: 90px;
    text-align: center;
    flex-shrink: 0;
    letter-spacing: 0.04em;
    user-select: none;
}


/* --- Volume --- */

.qp-volume {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.qp-volume .qp-btn {
    width: 30px;
    height: 30px;
    border: none;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
}

.qp-volume .qp-btn:hover {
    color: #c9a84c;
}

.qp-volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.18);
    outline: none;
    cursor: pointer;
    accent-color: #c9a84c;
}

.qp-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #c9a84c;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.qp-volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #c9a84c;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.qp-volume-slider::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
}

.qp-volume-slider::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.18);
}


/* --- Close / dismiss button --- */

.qp-close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.45);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
    transition: color 0.2s ease, background-color 0.2s ease;
    flex-shrink: 0;
    padding: 0;
    outline: none;
}

.qp-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}


/* ============================================================
   3. AUDIO TRIGGER BUTTONS (replace native <audio>)
   ============================================================ */

.audio-trigger-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid rgba(0, 74, 173, 0.3);
    border-radius: 20px;
    padding: 4px 14px;
    color: #004aad;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease,
                border-color 0.2s ease,
                color 0.2s ease,
                box-shadow 0.2s ease;
    white-space: nowrap;
    outline: none;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.audio-trigger-btn:hover {
    background: rgba(0, 74, 173, 0.08);
    border-color: #004aad;
}

.audio-trigger-btn:active {
    transform: scale(0.97);
}

.audio-trigger-btn:focus-visible {
    box-shadow: 0 0 0 2px rgba(0, 74, 173, 0.3);
}

/* Currently playing state */
.audio-trigger-btn.audio-active {
    background: #004aad;
    color: #fff;
    border-color: #004aad;
    box-shadow: 0 2px 8px rgba(0, 74, 173, 0.25);
}

.audio-trigger-btn.audio-active:hover {
    background: #003a8a;
    border-color: #003a8a;
}

/* Icon sizing inside triggers */
.audio-trigger-btn .fa-play,
.audio-trigger-btn .fa-pause {
    font-size: 0.7rem;
}

.audio-trigger-btn .fa-pause {
    position: relative;
    top: 0.5px;
}

/* Loading spinner state */
.audio-trigger-btn.audio-loading {
    opacity: 0.7;
    pointer-events: none;
}

.audio-trigger-btn.audio-loading .fa-play::before {
    content: "\f110"; /* fa-spinner */
    animation: qp-spin 1s linear infinite;
}

@keyframes qp-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Chapter-level trigger (larger variant) */
.audio-trigger-chapter {
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    gap: 8px;
}

.audio-trigger-chapter .fa-play,
.audio-trigger-chapter .fa-pause {
    font-size: 0.8rem;
}


/* ============================================================
   4. HIDE NATIVE DOWNLOAD & OVERFLOW BUTTONS
   ============================================================ */

audio::-webkit-media-controls-download-button {
    display: none !important;
}

audio::-webkit-media-controls-overflow-button {
    display: none !important;
}


/* ============================================================
   5. RESPONSIVE BREAKPOINTS
   ============================================================ */

/* Tablet and below */
@media (max-width: 768px) {
    .qp-volume-slider {
        display: none;
    }

    .qp-label {
        display: none;
    }

    .qp-time {
        min-width: 70px;
        font-size: 0.7rem;
    }

    .qp-progress-wrap {
        flex: 1;
        min-width: 80px;
    }

    .quran-player-bar {
        padding: 0 10px;
        gap: 8px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .quran-player-bar {
        height: auto;
        flex-wrap: wrap;
        padding: 8px 10px;
        gap: 6px;
    }

    body.player-active {
        padding-bottom: 80px;
    }

    .qp-controls {
        order: 1;
        gap: 6px;
    }

    .qp-btn {
        width: 32px;
        height: 32px;
        font-size: 0.78rem;
    }

    .qp-btn-play {
        width: 36px;
        height: 36px;
    }

    .qp-time {
        order: 2;
        min-width: auto;
        font-size: 0.68rem;
    }

    .qp-volume {
        order: 3;
    }

    .qp-close {
        order: 4;
    }

    .qp-progress-wrap {
        order: 5;
        flex-basis: 100%;
        padding: 2px 0 4px;
    }
}


/* ============================================================
   6. INTEGRATION WITH EXISTING PLAYER COMPONENTS
   ============================================================ */

/* Verse-level inline player: updated for trigger buttons */
.verse-audio-player {
    border-left: 3px solid #004aad;
    border-radius: 8px;
    padding: 10px 14px;
    margin: 8px 0;
    background: rgba(0, 74, 173, 0.04);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.verse-audio-player .audio-trigger-btn {
    flex-shrink: 0;
}

.verse-audio-player .speaker-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(0, 74, 173, 0.08);
    white-space: nowrap;
}

/* Chapter-level card player: full-width trigger */
.chapter-audio-player .audio-trigger-btn {
    width: 100%;
    justify-content: center;
    padding: 8px 16px;
    font-size: 0.85rem;
    margin-top: 8px;
    border-radius: 8px;
}

.chapter-audio-player .audio-trigger-btn.audio-active {
    border-radius: 8px;
}

/* Character audio clips: compact trigger */
.char-audio-clip .audio-trigger-btn {
    width: 100%;
    justify-content: center;
    padding: 4px 10px;
    font-size: 0.75rem;
    margin-top: 4px;
}

/* Responsive: verse player stacks on small screens */
@media (max-width: 576px) {
    .verse-audio-player {
        flex-direction: column;
        align-items: stretch;
    }

    .verse-audio-player .audio-trigger-btn {
        width: 100%;
        justify-content: center;
    }
}
