/* ===== MUSIC PLAYER ===== */

/* --- Desktop header controls --- */
.mp-hdr {
    display: none;
    align-items: center;
    gap: 2px;
    margin: 0 14px;
    flex-shrink: 1;
    min-width: 0;
}
.mp-hdr-btn {
    background: none; border: none; color: #5B3826; cursor: pointer;
    padding: 4px 5px; border-radius: 50%; font-size: 0.95rem; line-height: 1;
    transition: background 0.15s, color 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.mp-hdr-btn:hover { background: rgba(91,56,38,0.1); }
.mp-hdr-btn-play { font-size: 1.15rem; }
.mp-hdr-sep { color: #ccc; font-size: 0.75rem; margin: 0 2px; user-select: none; }
.mp-hdr-track {
    font-size: 0.73rem; color: #888;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 180px; margin-left: 4px;
}
.mp-hdr-btn.active, .mp-hdr-shuffle.active { color: #d4956b; }

/* Header volume slider */
.mp-hdr-vol-icon { font-size: 0.9rem; margin-left: 2px; }
.mp-hdr-vol-range {
    width: 70px;
    margin: 0 2px;
}

/* ===== UNIVERSAL RANGE INPUT STYLING (volume sliders) ===== */
.mp-vol-range {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    border: none;
    padding: 0;
}
/* Track — WebKit */
.mp-vol-range::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: rgba(180,160,150,0.3);
}
/* Track — Firefox */
.mp-vol-range::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: rgba(180,160,150,0.3);
    border: none;
}
/* Thumb — WebKit */
.mp-vol-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #5B3826;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    margin-top: -5px;
    cursor: grab;
}
.mp-vol-range::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.15); }
/* Thumb — Firefox */
.mp-vol-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #5B3826;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: grab;
}
.mp-vol-range::-moz-range-thumb:active { cursor: grabbing; }

/* In the bottom bar — lighter track + white thumb */
.mp-bar-vol-range::-webkit-slider-runnable-track { background: rgba(255,255,255,0.2); }
.mp-bar-vol-range::-moz-range-track { background: rgba(255,255,255,0.2); }
.mp-bar-vol-range::-webkit-slider-thumb { background: #e8a87c; border-color: rgba(255,255,255,0.9); }
.mp-bar-vol-range::-moz-range-thumb { background: #e8a87c; border-color: rgba(255,255,255,0.9); }

/* --- Floating button (MOBILE ONLY) --- */
#music-toggle-btn {
    position: fixed; bottom: 10px; right: 10px; z-index: 1090;
    width: 40px; height: 40px; border-radius: 50%; border: none;
    background: linear-gradient(145deg,#5B3826,#4c2011);
    color: #fff; font-size: 1.1rem; cursor: pointer;
    box-shadow: 0 3px 12px rgba(76,32,17,0.35);
    display: none; align-items: center; justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}
#music-toggle-btn:hover { transform: scale(1.08); box-shadow: 0 5px 18px rgba(76,32,17,0.5); }
#music-toggle-btn.playing { animation: mp-pulse 2s infinite; }
#music-toggle-btn.has-music { display: flex; }
@keyframes mp-pulse {
    0%,100% { box-shadow: 0 3px 12px rgba(76,32,17,0.35); }
    50% { box-shadow: 0 3px 20px rgba(76,32,17,0.6), 0 0 0 6px rgba(76,32,17,0.08); }
}
@media (min-width: 768px) { #music-toggle-btn { display: none !important; } }
body.mp-active #music-toggle-btn { bottom: 62px; }

/* --- Bottom player bar --- */
#music-player-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1085;
    height: 56px; background: rgba(91,56,38,0.97);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    color: #fff; display: flex; align-items: center;
    padding: 0 14px; gap: 10px;
    box-shadow: 0 -2px 20px rgba(0,0,0,0.15);
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
}
#music-player-bar.visible { transform: translateY(0); }

.mp-controls { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.mp-btn {
    background: none; border: none; color: rgba(255,255,255,0.85); cursor: pointer;
    padding: 5px; border-radius: 50%; font-size: 1rem;
    transition: color 0.15s, background 0.15s;
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
}
.mp-btn:hover { color: #fff; background: rgba(255,255,255,0.12); }
.mp-btn-play { font-size: 1.3rem; width: 36px; height: 36px; color: #fff; }
.mp-btn-shuffle.active, [data-mp="shuffle"].active { color: #e8a87c; }

.mp-info { display: flex; flex-direction: column; min-width: 0; flex-shrink: 1; max-width: 160px; }
.mp-track-title { font-size: 0.78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.mp-track-artist { font-size: 0.68rem; color: rgba(255,255,255,0.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }

.mp-progress-section { display: flex; align-items: center; flex: 1; gap: 6px; min-width: 0; }
.mp-time { font-size: 0.66rem; color: rgba(255,255,255,0.55); white-space: nowrap; flex-shrink: 0; min-width: 28px; text-align: center; }
.mp-progress-wrap { flex: 1; height: 5px; background: rgba(255,255,255,0.15); border-radius: 3px; cursor: pointer; position: relative; min-width: 40px; }
.mp-progress-fill { height: 100%; background: linear-gradient(90deg,#e8a87c,#d4956b); border-radius: 3px; width: 0%; transition: width 0.1s linear; }

.mp-volume-section { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.mp-bar-vol-range { width: 70px; }
.mp-right-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

/* --- Playlist panel --- */
#music-playlist-panel {
    position: fixed; bottom: 0; right: 16px; z-index: 1088;
    width: 340px; max-height: 450px;
    background: #fff; border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 30px rgba(0,0,0,0.2);
    overflow: hidden; display: none; flex-direction: column;
}
#music-playlist-panel.open { display: flex; }
body.mp-active #music-playlist-panel { bottom: 56px; }

.mp-panel-header { padding:14px 16px; background:linear-gradient(145deg,#5B3826,#4c2011); color:#fff; font-weight:600; font-size:0.95rem; display:flex; justify-content:space-between; align-items:center; flex-shrink:0; }
.mp-panel-close { background:none; border:none; color:rgba(255,255,255,0.7); cursor:pointer; font-size:1.4rem; padding:6px; }
.mp-panel-close:hover { color:#fff; }
.mp-panel-body { overflow-y:auto; flex:1; padding:0; }

.mp-playlist-item { display:flex; align-items:center; padding:12px 16px; cursor:pointer; transition:background .15s; gap:12px; border-bottom:1px solid #f0f0f0; }
.mp-playlist-item:hover { background:#f8f5f3; }
.mp-playlist-item.active { background:#f3ece7; }
.mp-playlist-cover { width:42px; height:42px; border-radius:6px; background:linear-gradient(145deg,#e8a87c,#d4956b); display:flex; align-items:center; justify-content:center; color:#fff; font-size:1.1rem; flex-shrink:0; }
.mp-playlist-cover img { width:100%; height:100%; border-radius:6px; object-fit:cover; }
.mp-playlist-info { flex:1; min-width:0; }
.mp-playlist-name { font-weight:600; font-size:1.02rem; color:#333; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.mp-playlist-playing-icon { color:#5B3826; font-size:1rem; margin-right:4px; }
.mp-playlist-play-btn { background:none; border:none; color:#5B3826; font-size:1.5rem; cursor:pointer; padding:4px 6px; flex-shrink:0; transition:color .15s, transform .15s; line-height:1; display:flex; align-items:center; order:-1; }
.mp-playlist-play-btn:hover { color:#d4956b; transform:scale(1.18); }
.mp-playlist-item.active .mp-playlist-play-btn { color:#d4956b; }

.mp-tracks-header { display:flex; align-items:center; padding:10px 16px; background:#f8f5f3; border-bottom:1px solid #eee; gap:10px; }
.mp-tracks-back { background:none; border:none; cursor:pointer; color:#5B3826; font-size:1.1rem; padding:4px; }
.mp-tracks-title { font-weight:600; font-size:0.9rem; color:#333; }
.mp-track-item { display:flex; align-items:center; padding:10px 16px; cursor:pointer; transition:background .15s; gap:10px; border-bottom:1px solid #f5f5f5; }
.mp-track-item:hover { background:#f8f5f3; }
.mp-track-item.active { background:#f3ece7; }
.mp-track-num { font-size:0.73rem; color:#aaa; width:22px; text-align:center; flex-shrink:0; }
.mp-track-item.active .mp-track-num { color:#5B3826; }
.mp-track-item-info { flex:1; min-width:0; }
.mp-track-item-title { font-size:0.83rem; font-weight:500; color:#333; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.mp-track-item.active .mp-track-item-title { color:#5B3826; font-weight:600; }
.mp-track-item-artist { font-size:0.7rem; color:#999; }
.mp-track-eq { display:none; gap:2px; align-items:flex-end; height:16px; }
.mp-track-item.active.playing .mp-track-eq { display:flex; }
.mp-track-eq-bar { width:3px; background:#5B3826; border-radius:1px; animation:mp-eq .8s ease-in-out infinite alternate; }
.mp-track-eq-bar:nth-child(1) { height:60%; animation-delay:0s; }
.mp-track-eq-bar:nth-child(2) { height:100%; animation-delay:.2s; }
.mp-track-eq-bar:nth-child(3) { height:40%; animation-delay:.4s; }
@keyframes mp-eq { 0%{height:20%} 100%{height:100%} }

/* --- AJAX loading bar --- */
#mp-loading { position:fixed; top:0; left:0; right:0; height:3px; z-index:9999; background:linear-gradient(90deg,#e8a87c,#d4956b,#e8a87c); background-size:200% 100%; opacity:0; pointer-events:none; transition:opacity .2s; }
#mp-loading.active { opacity:1; animation:mp-ld 1.2s linear infinite; }
@keyframes mp-ld { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* --- MOBILE --- */
@media (max-width: 767.98px) {
    #music-toggle-btn.has-music { display: flex; }
    #music-player-bar {
        height: auto;
        padding: 6px 8px 4px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .mp-info { max-width: 90px; flex: 1; max-width: none; }
    .mp-volume-section { display: flex; }
    .mp-bar-vol-range { width: 120px; }
    .mp-progress-section {
        display: flex !important;
        width: 100%;
        flex-basis: 100%;
        margin-top: 2px;
    }
    .mp-right-actions {
        margin-left: auto;
    }
    /* Hide close button on mobile — not needed, saves space */
    [data-mp="close"] { display: none !important; }
    #music-playlist-panel { width:calc(100vw - 16px); right:8px; left:8px; max-height:55vh; }
    body.mp-active #music-playlist-panel { bottom: 70px; }
    body.mp-active #music-toggle-btn { bottom: 78px; }
    /* Bigger thumb on mobile for easier touch */
    .mp-vol-range::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -7px; }
    .mp-vol-range::-moz-range-thumb { width: 20px; height: 20px; }
}
@media (max-width: 400px) {
    .mp-bar-vol-range { width: 120px; }
    .mp-btn { width: 28px; height: 28px; font-size: 0.9rem; }
    .mp-btn-play { width: 32px; height: 32px; font-size: 1.1rem; }
}

body.mp-active { padding-bottom: 56px; }
@media (max-width: 767.98px) { body.mp-active { padding-bottom: 70px; } }
