/* ============================================================
   CUSTOM-SONG.SHOP — UNIFIED AUDIO PLAYER
   Єдиний плеєр для всього сайту.
   Використовує фірмові змінні зі style.css (--primary-color тощо).
   ============================================================ */

/* ------------------------------------------------------------
   1. ФІКС СТАРИХ ПРОГРЕС-БАРІВ
   У style.css прогрес прив'язаний до scroll(root) — через це
   смужка відображала прокрутку сторінки, а не програвання.
   Тут вимикаємо це і віддаємо керування JS через --progress.
   ------------------------------------------------------------ */
.song-card.playing .progress-bar::after,
.mini-player.playing .mini-progress-bar::after {
    animation: none !important;
    animation-timeline: auto !important;
}

.progress-bar::after,
.mini-progress-bar::after {
    width: var(--progress, 0%) !important;
    transition: width 0.12s linear;
}

/* Прогрес-бари стають клікабельними для перемотки */
.audio-progress,
.mini-progress-container {
    cursor: pointer;
    touch-action: none;
}

.audio-progress .progress-bar,
.mini-progress-container .mini-progress-bar {
    transition: height 0.15s ease;
}

.audio-progress:hover .progress-bar {
    height: 6px;
}

.mini-progress-container:hover .mini-progress-bar {
    height: 5px;
}

/* Стан "буферизується" для кнопок карток */
.audio-play-btn.is-loading,
.mini-play-btn.is-loading {
    pointer-events: none;
}

.audio-play-btn.is-loading i,
.mini-play-btn.is-loading i {
    animation: csp-spin 0.8s linear infinite;
}

@keyframes csp-spin {
    to { transform: rotate(360deg); }
}

/* Активна картка — м'яке підсвічування у фірмових кольорах */
.song-card.current-playing {
    box-shadow: 0 0 0 2px var(--primary-color), var(--shadow-lg, 0 10px 40px rgba(0,0,0,.2));
}

.mini-player.current-playing {
    border-color: var(--primary-color) !important;
}

/* ------------------------------------------------------------
   2. ГЛОБАЛЬНИЙ ПЛЕЄР
   ------------------------------------------------------------ */
.csp-player {
    --csp-bg: rgba(20, 20, 28, 0.78);
    --csp-fg: #ffffff;
    --csp-muted: rgba(255, 255, 255, 0.62);
    --csp-line: rgba(255, 255, 255, 0.14);
    --csp-grad: linear-gradient(135deg, #48B699 0%, #595FCA 100%);

    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 9997;
    width: min(760px, calc(100vw - 32px));
    transform: translate(-50%, 160%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.35s ease,
                visibility 0s linear 0.5s;
    font-family: 'Nunito', system-ui, -apple-system, sans-serif;
    color: var(--csp-fg);
    -webkit-font-smoothing: antialiased;
}

.csp-player.is-visible {
    transform: translate(-50%, 0);
    opacity: 1;
    visibility: visible;
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.35s ease,
                visibility 0s linear 0s;
}

.csp-shell {
    position: relative;
    background: var(--csp-bg);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    border: 1px solid var(--csp-line);
    border-radius: 20px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45),
                0 2px 8px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    padding: 12px 14px 10px;
}

/* Тонка фірмова смужка зверху */
.csp-shell::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: var(--csp-grad);
    opacity: 0.9;
}

/* М'яке світіння у фірмових кольорах під час гри */
.csp-player.is-playing .csp-shell {
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45),
                0 0 0 1px rgba(72, 182, 153, 0.28),
                0 0 40px rgba(72, 182, 153, 0.15);
}

/* ---------- Верхній ряд: обкладинка + інфо + контроли ---------- */
.csp-top {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* Обкладинка */
.csp-art {
    position: relative;
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 12px;
    overflow: hidden;
    background: var(--csp-grad);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.csp-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.6s ease, filter 0.3s ease;
}

.csp-player.is-playing .csp-art img {
    transform: scale(1.06);
    filter: brightness(0.62);
}

/* Еквалайзер поверх обкладинки під час програвання */
.csp-eq {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.csp-player.is-playing .csp-eq {
    opacity: 1;
}

.csp-eq span {
    display: block;
    width: 3px;
    height: 8px;
    border-radius: 2px;
    background: #fff;
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
    animation: csp-bounce 1s ease-in-out infinite;
}

.csp-eq span:nth-child(1) { animation-delay: -0.9s; }
.csp-eq span:nth-child(2) { animation-delay: -0.6s; }
.csp-eq span:nth-child(3) { animation-delay: -0.3s; }
.csp-eq span:nth-child(4) { animation-delay: -0.15s; }

@keyframes csp-bounce {
    0%, 100% { height: 7px; }
    50%      { height: 22px; }
}

/* Інфо про трек */
.csp-info {
    flex: 1;
    min-width: 0;
}

.csp-title {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 2px;
    color: var(--csp-fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.csp-desc {
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.3;
    margin: 0;
    color: var(--csp-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.csp-counter {
    font-size: 0.7rem;
    color: var(--csp-muted);
    margin-left: 6px;
    font-variant-numeric: tabular-nums;
    opacity: 0.8;
}

/* ---------- Кнопки ---------- */
.csp-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.csp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--csp-fg);
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease, opacity 0.2s ease;
    padding: 0;
    font-size: 0.95rem;
    line-height: 1;
}

.csp-btn:focus-visible {
    outline: 2px solid var(--primary-color, #48B699);
    outline-offset: 2px;
}

.csp-skip {
    width: 36px;
    height: 36px;
    color: var(--csp-muted);
}

.csp-skip:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--csp-fg);
    transform: scale(1.08);
}

.csp-play {
    width: 46px;
    height: 46px;
    background: var(--csp-grad);
    font-size: 1.05rem;
    box-shadow: 0 4px 16px rgba(72, 182, 153, 0.4);
}

.csp-play:hover {
    transform: scale(1.07);
    box-shadow: 0 6px 22px rgba(72, 182, 153, 0.55);
}

.csp-play:active {
    transform: scale(0.97);
}

.csp-play.is-loading i {
    animation: csp-spin 0.8s linear infinite;
}

/* Гучність */
.csp-volume {
    position: relative;
    display: flex;
    align-items: center;
}

.csp-volume-panel {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    background: rgba(20, 20, 28, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--csp-line);
    border-radius: 12px;
    padding: 14px 10px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.csp-volume.is-open .csp-volume-panel {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0s;
}

.csp-volume-range {
    -webkit-appearance: none;
    appearance: none;
    writing-mode: vertical-lr;
    direction: rtl;
    width: 6px;
    height: 90px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.18);
    cursor: pointer;
    outline: none;
}

.csp-volume-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    cursor: pointer;
}

.csp-volume-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: none;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    cursor: pointer;
}

/* Закриття */
.csp-close {
    width: 30px;
    height: 30px;
    color: var(--csp-muted);
    font-size: 0.82rem;
}

.csp-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    transform: rotate(90deg);
}

/* ---------- Прогрес ---------- */
.csp-progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 9px;
}

.csp-time {
    font-size: 0.72rem;
    color: var(--csp-muted);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 34px;
}

.csp-time.csp-time-total {
    text-align: right;
}

.csp-seek {
    position: relative;
    flex: 1;
    height: 18px;
    display: flex;
    align-items: center;
    cursor: pointer;
    touch-action: none;
}

.csp-seek-track {
    position: relative;
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.16);
    overflow: hidden;
    transition: height 0.15s ease;
}

.csp-seek:hover .csp-seek-track,
.csp-seek.is-scrubbing .csp-seek-track {
    height: 8px;
}

/* Завантажена частина */
.csp-seek-buffer {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background: rgba(255, 255, 255, 0.16);
    transition: width 0.3s ease;
}

/* Програна частина */
.csp-seek-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background: var(--csp-grad);
    border-radius: 3px;
}

/* Головка */
.csp-seek-thumb {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 13px;
    height: 13px;
    margin-left: -6.5px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    transform: translateY(-50%) scale(0);
    transition: transform 0.18s ease;
    pointer-events: none;
}

.csp-seek:hover .csp-seek-thumb,
.csp-seek.is-scrubbing .csp-seek-thumb {
    transform: translateY(-50%) scale(1);
}

/* Підказка з часом при наведенні */
.csp-seek-tip {
    position: absolute;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.88);
    color: #fff;
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
    padding: 3px 7px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    white-space: nowrap;
}

.csp-seek:hover .csp-seek-tip,
.csp-seek.is-scrubbing .csp-seek-tip {
    opacity: 1;
}

/* ---------- Адаптив ---------- */
@media (max-width: 640px) {
    .csp-player {
        width: calc(100vw - 20px);
        bottom: 10px;
    }

    .csp-shell {
        border-radius: 18px;
        padding: 10px 12px 8px;
    }

    .csp-top {
        gap: 10px;
    }

    .csp-art {
        width: 44px;
        height: 44px;
        border-radius: 10px;
    }

    .csp-title { font-size: 0.86rem; }
    .csp-desc  { font-size: 0.72rem; }

    /* На мобільному ховаємо гучність — там є апаратні кнопки */
    .csp-volume { display: none; }

    .csp-skip {
        width: 32px;
        height: 32px;
    }

    .csp-play {
        width: 42px;
        height: 42px;
    }

    .csp-close {
        width: 26px;
        height: 26px;
    }

    .csp-controls { gap: 2px; }
}

@media (max-width: 380px) {
    .csp-desc { display: none; }
    .csp-skip { display: none; }
}

/* Кнопка "нагору" не має перекривати плеєр */
body.csp-player-open .scroll-top-btn {
    bottom: 120px;
}

@media (max-width: 640px) {
    body.csp-player-open .scroll-top-btn {
        bottom: 108px;
    }
}

/* Повага до налаштувань доступності */
@media (prefers-reduced-motion: reduce) {
    .csp-player,
    .csp-art img,
    .csp-btn,
    .csp-seek-track,
    .csp-seek-thumb {
        transition-duration: 0.01ms !important;
    }

    .csp-eq span {
        animation: none;
        height: 14px;
    }
}

/* ------------------------------------------------------------
   3. ДРІБНІ УТИЛІТИ
   ------------------------------------------------------------ */

/* Текст лише для пошукових систем і скрінрідерів (не змінює верстку) */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Посилання «Як відрізнити підробку» у футері */
.footer-fraud-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.footer-fraud-link i {
    color: var(--primary-color, #48B699);
}

/* Постер відео у картці, поки саме відео ще не завантажилось */
.song-video {
    background-color: #1a1a1a;
    background-size: cover;
    background-position: center;
}
