/* ============================================
   CUSTOM AUDIO PLAYER
   ============================================ */
.ahm-player {
    width: 100%;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 32px;
    backdrop-filter: blur(10px);
    user-select: none;
    position: relative;
    isolation: isolate;
}

/* ── Blurred artwork background ── */
.ahm-player__bg {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-lg);
    background-size: cover;
    background-position: center;
    filter: blur(40px) saturate(1.8);
    opacity: 0;
    transition: opacity 0.6s ease;
    z-index: -1;
    pointer-events: none;
}

.ahm-player.has-artwork .ahm-player__bg {
    opacity: 0.14;
}

.ahm-player.has-artwork.is-playing .ahm-player__bg {
    opacity: 0.22;
    transition: opacity 1s ease;
}

/* Now Playing Info */
.ahm-player__now-playing {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 28px;
}

.ahm-player__info {
    flex: 1;
    min-width: 0;
}

.ahm-player__title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-white);
    line-height: 1.3;
    transition: all 0.3s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ahm-player__playlist-name {
    font-size: 0.8125rem;
    color: var(--color-accent-text);
    font-weight: 500;
    margin-top: 4px;
    font-family: var(--font-mono);
    letter-spacing: 0.5px;
}

/* ── Artwork thumbnail ── */
.ahm-player__artwork {
    width: 140px;
    height: 140px;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--color-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    transition: box-shadow 0.4s ease, transform 0.4s ease;
}

.ahm-player__artwork img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.6s ease;
}

/* Glow + slight zoom when playing */
.ahm-player.is-playing .ahm-player__artwork {
    box-shadow:
        0 0 0 2px var(--color-accent),
        0 8px 35px var(--color-accent-glow),
        0 4px 20px rgba(0, 0, 0, 0.5);
    transform: translateY(-2px);
}

.ahm-player.is-playing .ahm-player__artwork img {
    transform: scale(1.04);
}

/* Placeholder (no artwork set) */
.ahm-player__artwork--empty {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ahm-player__artwork-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-accent);
    opacity: 0.35;
}

/* ── Progress Bar ── */
.ahm-player__progress-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.ahm-player__time {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    min-width: 40px;
}

.ahm-player__time--current {
    text-align: right;
}

.ahm-player__time--duration {
    text-align: left;
}

.ahm-player__progress-bar {
    flex: 1;
    height: 64px;
    display: flex;
    align-items: center;
    position: relative;
    cursor: pointer;
}

/* Thin fallback bar (hidden when waveform is active) */
.ahm-player__progress-bar::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    transition: height 0.15s ease;
}

.ahm-player__progress-bar.has-waveform::before {
    display: none;
}

.ahm-player__progress-bar:hover::before {
    height: 6px;
}

/* Waveform canvas */
.ahm-player__waveform {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none; /* clicks handled by progress bar */
}

.ahm-player__progress-bar.has-waveform .ahm-player__waveform {
    opacity: 1;
}

/* Fallback fill bar, hidden when waveform canvas is active. */
.ahm-progress-fallback {
    height: 4px;
    background: linear-gradient(90deg, var(--color-accent), var(--color-accent-secondary));
    border-radius: 4px;
    width: 0%;
    position: relative;
    z-index: 1;
    transition: width 0.1s linear;
}

.ahm-player__progress-bar.has-waveform .ahm-progress-fallback {
    display: none;
}

.ahm-player__progress-handle {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 12px;
    height: 12px;
    background: var(--color-white);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.15s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 2;
}

.ahm-player__progress-bar:hover .ahm-player__progress-handle,
.ahm-player.is-dragging .ahm-player__progress-handle {
    transform: translate(-50%, -50%) scale(1);
}

/* ── Controls ── */
.ahm-player__controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

/* Volume pushed to far right */
.ahm-player__volume {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.ahm-player__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.ahm-player__btn:hover {
    color: var(--color-white);
    background: rgba(255, 255, 255, 0.06);
}

.ahm-player__btn:focus-visible,
.ahm-player__progress-bar:focus-visible,
.ahm-player__volume-slider:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 3px;
}

.ahm-player__btn--play {
    width: 56px;
    height: 56px;
    background: var(--color-accent);
    color: var(--color-white);
    border-radius: 50%;
    box-shadow: 0 4px 20px var(--color-accent-glow);
}

.ahm-player__btn--play:hover {
    background: var(--color-accent-hover);
    color: var(--color-white);
    transform: scale(1.05);
    box-shadow: 0 6px 25px var(--color-accent-glow);
}

.ahm-player__btn--play:active {
    transform: scale(0.98);
}

/* ── Volume ── */

.ahm-player__volume-slider {
    width: 80px;
    height: 20px;
    display: flex;
    align-items: center;
    position: relative;
    cursor: pointer;
}

.ahm-player__volume-slider::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}

.ahm-player__volume-fill {
    height: 4px;
    background: var(--color-accent);
    border-radius: 4px;
    width: 80%;
    transition: width 0.1s linear;
    position: relative;
    z-index: 1;
}

/* ── Filter chips ── */
.ahm-player__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.ahm-player__filter {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    padding: 7px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ahm-player__filter:hover {
    color: var(--color-white);
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
}

.ahm-player__filter.is-active {
    color: var(--color-accent-text);
    border-color: rgba(61, 125, 90, 0.5);
    background: rgba(61, 125, 90, 0.12);
}

.ahm-player__filter:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 3px;
}

/* ── Hover timestamp tooltip ── */
.ahm-player__hover-time {
    position: absolute;
    top: -6px;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--color-text-primary);
    background: rgba(10, 10, 10, 0.9);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 2px 7px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    white-space: nowrap;
    z-index: 3;
}

.ahm-player__hover-time.is-visible {
    opacity: 1;
}

/* ── Track List ── */
.ahm-player__tracklist {
    border-top: 1px solid var(--color-border);
    padding-top: 16px;
    max-height: 420px;               /* ~7-8 tracks visible */
    overflow-y: auto;
    overscroll-behavior: contain;    /* don't chain scroll to the page */
    scrollbar-width: thin;           /* Firefox */
    scrollbar-color: rgba(255,255,255,0.12) transparent;
}

/* Webkit scrollbar */
.ahm-player__tracklist::-webkit-scrollbar {
    width: 6px;
}
.ahm-player__tracklist::-webkit-scrollbar-track {
    background: transparent;
}
.ahm-player__tracklist::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 3px;
}
.ahm-player__tracklist::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

.ahm-player__track {
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    position: relative;
}

.ahm-player__track.is-filtered {
    display: none;
}

/* The whole row is one real <button>, so it is keyboard and screen-reader friendly. */
.ahm-player__track-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    text-align: left;
    color: inherit;
}

.ahm-player__track-btn:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: -2px;
}

.ahm-player__track-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.ahm-player__track-desc {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ahm-player__track:hover {
    background: rgba(255, 255, 255, 0.04);
}

.ahm-player__track.is-active {
    background: rgba(61, 125, 90, 0.08);
}

.ahm-player__track.is-active .ahm-player__track-title {
    color: var(--color-accent-text);
}

.ahm-player__track-num {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.ahm-player__track.is-active .ahm-player__track-num {
    display: none;
}

.ahm-player__track-play-icon {
    display: none;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
    color: var(--color-accent-text);
}

.ahm-player__track.is-active .ahm-player__track-play-icon {
    display: block;
}

/* EQ bars animation when playing */
.ahm-player__track.is-active.is-playing .ahm-player__track-play-icon svg {
    display: none;
}

.ahm-player__track.is-active.is-playing .ahm-player__track-play-icon::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    background: linear-gradient(
        90deg,
        var(--color-accent) 0%, var(--color-accent) 20%,
        transparent 20%, transparent 30%,
        var(--color-accent) 30%, var(--color-accent) 50%,
        transparent 50%, transparent 60%,
        var(--color-accent) 60%, var(--color-accent) 80%,
        transparent 80%
    );
    background-size: 14px 14px;
    animation: eqBars 0.8s steps(4) infinite;
}

@keyframes eqBars {
    0%   { background-position: 0 0; }
    100% { background-position: 0 -14px; }
}

.ahm-player__track-title {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    transition: color 0.2s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ahm-player__track:hover .ahm-player__track-title {
    color: var(--color-text-primary);
}

.ahm-player__track-duration {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .ahm-player {
        padding: 20px;
    }

    .ahm-player__now-playing {
        flex-direction: column;
        text-align: center;
        gap: 16px;
    }

    .ahm-player__artwork {
        width: 160px;
        height: 160px;
        border-radius: 10px;
        margin: 0 auto;
    }

    .ahm-player__info {
        width: 100%;
    }

    .ahm-player__title {
        white-space: normal;
        text-align: center;
    }

    .ahm-player__playlist-name {
        text-align: center;
    }

    .ahm-player__controls {
        justify-content: center;
    }

    .ahm-player__volume {
        display: none;   /* volume slider hidden on touch devices */
    }

    .ahm-player__track-btn {
        padding: 10px 12px;
    }

    .ahm-player__track-title {
        font-size: 0.875rem;
    }
}

@media (max-width: 480px) {
    .ahm-player {
        padding: 16px;
    }

    .ahm-player__artwork {
        width: 140px;
        height: 140px;
    }

    .ahm-player__btn--play {
        width: 48px;
        height: 48px;
    }

    .ahm-player__tracklist {
        max-height: 320px;
    }
}
