/* 전역 오디오 플레이어 CSS - 우선순위 충돌 방지 */

/* 기본 오디오 플레이어 스타일 */
/* z-index policy: 1000 backdrop < 1001 sidebar < 1002 player < 1100 navbar < 1200 dropdown/tooltip */
#global-audio-player {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: var(--player-h-desktop, 64px); /* 명시적 높이: 64px */
    background: var(--bg-audio-player, rgba(0, 0, 0, 0.95));
    padding: 6px 16px; /* 8px 20px → 6px 16px로 축소 */
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px)); /* iOS 안전영역 보정 (패딩 축소에 맞춰 조정) */
    border-top: 1px solid var(--border-primary);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    z-index: 1002; /* sidebar(1001) 위 */
    display: flex;
    align-items: center;
    gap: 15px;
    transform: translateY(0);
    transition: background-color var(--transition-normal), border-color var(--transition-normal), transform 0.3s ease;
    overflow: hidden; /* Prevent overflow on small screens */
    box-sizing: border-box;
}

/* 오디오 플레이어 숨김 처리 - 높은 우선순위 */
body.login-page #global-audio-player,
body.register-page #global-audio-player,
body.admin-main-page #global-audio-player,
body.create-admin-page #global-audio-player {
    display: none !important;
}

/* 곡 정보 영역 - 기본 레이아웃 */
#global-audio-player .current-song-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 100px;
    max-width: 250px; /* 기본: 250px */
    order: 0;
    margin-right: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
    flex-shrink: 1;
    overflow: hidden;
    box-sizing: border-box;
}

#global-audio-player .current-song-info:hover {
    opacity: 0.8;
}

#global-audio-player .song-title-display {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2; /* 세로 중앙 정렬을 위한 line-height 추가 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color var(--transition-normal);
}

/* 앨범 이미지 섬네일 */
#global-audio-player .desktop-player-thumb {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    display: none; /* 기본 숨김, JavaScript에서 제어 */
}

/* 텍스트 영역 컨테이너 */
#global-audio-player .desktop-song-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    gap: 2px;
}

/* 아티스트 정보 스타일 */
#global-audio-player .song-artist-display {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color var(--transition-normal);
}

/* 컨트롤 버튼 영역 */
#global-audio-player .custom-player-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    order: 1;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    box-sizing: border-box;
}

/* 스킵 버튼 - SoundCloud 스타일 */
#global-audio-player .skip-btn {
    background: transparent;
    color: transparent; /* 변경: 투명 (외곽선만 보이도록) */
    -webkit-text-stroke: 1.5px #fff; /* 외곽선만 흰색 (두께 증가) */
    text-stroke: 1.5px #fff; /* 표준 속성 (호환성) */
    border: none; /* 변경: 원형 테두리 제거 */
    border-radius: 0; /* 변경: 원형 제거 */
    width: 36px; /* 변경: 사이즈 키움 (28px → 36px) */
    height: 36px; /* 변경: 사이즈 키움 (28px → 36px) */
    min-width: 36px; /* 변경: 사이즈 키움 */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px; /* 변경: 폰트 사이즈 키움 (10px → 16px) */
    transition: all 0.3s ease;
    box-sizing: border-box;
    filter: grayscale(100%) brightness(0) invert(1); /* 추가: 푸른색 배경 제거, 외곽선만 표시 */
    -webkit-text-fill-color: transparent; /* 추가: 텍스트 채우기 투명 */
}

#global-audio-player .skip-btn:hover {
    background: transparent; /* 변경: 투명 유지 */
    color: transparent; /* 변경: 투명 유지 */
    -webkit-text-stroke: 1.5px #fff; /* 외곽선 유지 (두께 증가) */
    text-stroke: 1.5px #fff; /* 표준 속성 유지 */
    border: none; /* 변경: 테두리 없음 */
    transform: scale(1.1);
    opacity: 0.8; /* 추가: 호버 시 약간의 투명도 효과 */
    filter: grayscale(100%) brightness(0) invert(1); /* 추가: 푸른색 배경 제거 유지 */
}

/* 재생/일시정지 버튼 - SoundCloud 스타일 */
#global-audio-player .play-pause-btn {
    background: #000;
    color: #f1c40f;
    border: 2px solid #f1c40f;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    min-width: 30px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
}

#global-audio-player .play-pause-btn:hover {
    background: #f1c40f;
    color: #000;
    transform: scale(1.1);
}

#global-audio-player .play-pause-btn:active {
    transform: scale(0.95);
}

/* Phase 1: Buffering animation */
#global-audio-player .play-pause-btn.buffering {
    animation: spin 1s linear infinite;
    cursor: wait;
    opacity: 0.7;
}

#global-audio-player .play-pause-btn.buffering:hover {
    transform: scale(1);
    background: #000;
    color: #f1c40f;
}

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

/* 시간 표시 */
#global-audio-player .time-display {
    display: flex;
    gap: 3px;
    color: #fff !important; /* 변경: 라이트 모드에서도 흰색 유지 */
    font-size: 10px;
    line-height: 1.2; /* 세로 중앙 정렬을 위한 line-height 추가 */
    min-width: 60px;
    flex-shrink: 0;
    white-space: nowrap;
    box-sizing: border-box;
    transition: color var(--transition-normal);
}

/* 진행바 - SoundCloud 스타일 */
#global-audio-player .progress-bar {
    flex: 1;
    position: relative;
    height: 4px;
    min-width: 60px;
    margin-right: 30px; /* 추가: 오른쪽 간격 최소 30px 유지 */
    /* max-width 제거: 반응형으로 화면 크기에 따라 자동 조정 */
    background: var(--bg-tertiary);
    border-radius: 2px;
    cursor: pointer;
    transition: height 0.2s ease, background-color var(--transition-normal);
    box-sizing: border-box;
}

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

#global-audio-player .progress-fill {
    height: 100%;
    background: #f1c40f;
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s ease, background 0.2s ease;
}

#global-audio-player .progress-bar:hover .progress-fill {
    background: #f39c12;
}

#global-audio-player .progress-slider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    margin: 0;
    padding: 0;
}

/* 볼륨 컨트롤 - SoundCloud 스타일 (세로 팝업) */
#global-audio-player .volume-controls {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    order: 2;
    overflow: visible !important;
    flex-shrink: 0;
    min-width: 24px;
    margin-left: -8px; /* 왼쪽으로 이동 */
    margin-right: 50px; /* 추가: 오른쪽 여백 */
    box-sizing: border-box;
}

#global-audio-player .volume-icon {
    color: #f1c40f;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
    display: inline-block;
}

#global-audio-player .volume-icon:hover {
    transform: scale(1.1);
}

/* 세로 슬라이더 팝업 - body 직접 자식 */
.volume-slider-popup {
    position: fixed;
    /* left와 bottom은 JavaScript에서 동적으로 설정 */
    width: 40px;
    height: 120px;
    background: linear-gradient(135deg, rgba(30, 30, 30, 0.98), rgba(20, 20, 20, 0.98));
    padding: 7px 10px;
    border-radius: 10px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 10001;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

/* hover 효과 제거 - 클릭으로만 작동 */

/* 클릭으로 활성화된 상태 */
.volume-slider-popup.active {
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important;
}

/* 세로 슬라이더 - 표준 방법 */
.volume-slider {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 4px;
    height: 100px;
    padding: 0;
    margin: 0;
    background: transparent;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    touch-action: none; /* 모바일에서 터치 드래그 시 페이지 스크롤 방지 */
}

.volume-slider::-webkit-slider-runnable-track {
    width: 4px;
    height: 100px;
    background: linear-gradient(to top, #f1c40f 0%, #555 0%);
    border-radius: 2px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: -5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(241, 196, 15, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(241, 196, 15, 0.5), 0 0 0 3px rgba(241, 196, 15, 0.3);
}

.volume-slider::-webkit-slider-thumb:active {
    transform: scale(1.1);
}

.volume-slider::-moz-range-track {
    width: 4px;
    height: 100px;
    background: linear-gradient(to top, #f1c40f 0%, #555 0%);
    border-radius: 2px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(241, 196, 15, 0.2);
}

.volume-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(241, 196, 15, 0.5), 0 0 0 3px rgba(241, 196, 15, 0.3);
}

.volume-slider::-moz-range-thumb:active {
    transform: scale(1.1);
}

/* 버튼은 데스크톱에서 기본 숨기기 */
#global-audio-player .volume-up-btn,
#global-audio-player .volume-down-btn {
    display: none;
    background: #f1c40f;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    color: #333;
    font-size: 12px;
    font-weight: bold;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#global-audio-player .volume-up-btn:hover,
#global-audio-player .volume-down-btn:hover {
    background: #f39c12;
    transform: scale(1.1);
}

#global-audio-player .volume-display {
    color: #fff !important; /* 변경: 흰색 강제 적용 */
    font-size: 12px;
    min-width: 35px;
    text-align: right;
    transition: color var(--transition-normal);
}

/* 반응형 디자인 */
/* 큰 화면에서 곡 정보 영역 확장 */
@media (min-width: 1200px) {
    #global-audio-player .current-song-info {
        max-width: 300px;
    }

    /* 진행바: 큰 화면에서 더 넓게 */
    #global-audio-player .progress-bar {
        min-width: 100px;
    }
}

/* 중간 화면: 진행바 너비 조정 */
@media (min-width: 769px) and (max-width: 1199px) {
    #global-audio-player .progress-bar {
        min-width: 80px;
    }
}

@media (max-width: 768px) {
    #global-audio-player {
        padding: 6px 12px;
        gap: 8px;
    }

    /* 곡 정보 영역 조정 */
    #global-audio-player .current-song-info {
        min-width: 80px;
        max-width: 180px;
        margin-right: 6px;
    }

    #global-audio-player .song-title-display {
        font-size: 11px;
    }

    #global-audio-player .volume-controls {
        min-width: 20px;
        overflow: visible !important;
    }

    /* 진행바: 작은 화면에서 적절한 너비 유지 */
    #global-audio-player .progress-bar {
        min-width: 60px;
        max-width: none; /* flex: 1로 자동 조정 */
    }

    #global-audio-player .custom-player-controls {
        gap: 4px;
    }

    #global-audio-player .skip-btn {
        width: 24px;
        height: 24px;
        min-width: 24px;
        font-size: 9px;
    }

    #global-audio-player .play-pause-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        font-size: 11px;
    }

    #global-audio-player .time-display {
        font-size: 9px;
        min-width: 50px;
        gap: 2px;
    }

    /* 모바일에서는 슬라이더 팝업만 사용 */
    .volume-slider-popup:not(.active) {
        display: none !important;
    }

    /* +/- 버튼 숨기기 */
    #global-audio-player .volume-up-btn,
    #global-audio-player .volume-down-btn {
        display: none !important;
    }

    /* 모바일용 팝업 크기 조정 */
    .volume-slider-popup {
        width: 35px;
        height: 94px;
        padding: 7px 8px;
    }

    .volume-slider-popup .volume-slider {
        display: block !important;
        writing-mode: vertical-lr !important;
        direction: rtl !important;
        width: 4px !important;
        height: 80px !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        outline: none !important;
        cursor: pointer !important;
        -webkit-appearance: none !important;
        appearance: none !important;
    }

    .volume-slider-popup .volume-slider::-webkit-slider-runnable-track {
        width: 4px !important;
        height: 80px !important;
        background: linear-gradient(to top, #f1c40f 0%, #555 0%) !important;
        border-radius: 2px !important;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3) !important;
    }

    .volume-slider-popup .volume-slider::-webkit-slider-thumb {
        -webkit-appearance: none !important;
        appearance: none !important;
        width: 14px !important;
        height: 14px !important;
        background: linear-gradient(135deg, #f1c40f, #f39c12) !important;
        border-radius: 50% !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        margin-left: -5px !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(241, 196, 15, 0.2) !important;
        border: 2px solid rgba(255, 255, 255, 0.2) !important;
    }

    .volume-slider-popup .volume-slider::-moz-range-track {
        width: 4px !important;
        height: 80px !important;
        background: linear-gradient(to top, #f1c40f 0%, #555 0%) !important;
        border-radius: 2px !important;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3) !important;
    }

    .volume-slider-popup .volume-slider::-moz-range-thumb {
        width: 14px !important;
        height: 14px !important;
        background: linear-gradient(135deg, #f1c40f, #f39c12) !important;
        border-radius: 50% !important;
        cursor: pointer !important;
        border: 2px solid rgba(255, 255, 255, 0.2) !important;
        transition: all 0.2s ease !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(241, 196, 15, 0.2) !important;
    }
}

@media (max-width: 576px) {
    #global-audio-player .volume-controls {
        overflow: visible !important;
    }
}

@media (max-width: 260px) {
    #global-audio-player .volume-controls {
        overflow: visible !important;
    }

    #global-audio-player .volume-up-btn,
    #global-audio-player .volume-down-btn {
        width: 14px;
        height: 14px;
        font-size: 8px;
    }
}

/* ============================================
   모바일 미니 플레이어 & BottomSheet (≤480px)
   ============================================ */

/* 미니 플레이어 (≤480px) */
@media (max-width: 576px) {
    /* 기존 플레이어 숨기기 */
    #global-audio-player {
        display: none !important;
    }

    /* 미니 플레이어 - 데스크톱에서는 숨김 */
    .player-bar {
        display: none;
    }

    .player-bar:not([hidden]) {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 6px 10px; /* 10px 12px → 6px 10px으로 축소 */
        padding-bottom: max(6px, env(safe-area-inset-bottom, 0px)); /* iOS 안전영역 보정 (패딩 축소에 맞춰 조정) */
        height: var(--player-h-mobile, 52px); /* 명시적 높이: 52px */
        background: var(--bg-audio-player, rgba(24, 24, 24, 0.95));
        /* 플레이어 배경이 항상 어두우므로 텍스트는 항상 흰색으로 고정 */
        color: #fff !important;
        border-top: 1px solid var(--border-primary, #444);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
        z-index: 1002; /* sidebar(1001) 위 */
        box-sizing: border-box;
    }

    .player-bar .thumb {
        width: 40px;
        height: 40px;
        border-radius: 6px;
        object-fit: cover;
        flex-shrink: 0;
        cursor: pointer;
    }

    .player-bar .meta {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        cursor: pointer;
    }

    .player-bar .meta:focus-visible,
    .player-bar .thumb:focus-visible {
        outline: 2px solid var(--accent-primary, #f1c40f);
        outline-offset: 2px;
    }

    .player-bar .title {
        font-weight: 600;
        font-size: 14px;
        line-height: 1.2; /* 세로 중앙 정렬을 위한 line-height 추가 */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        /* 플레이어 배경이 항상 어두우므로 텍스트는 항상 흰색으로 고정 */
        color: #fff !important;
    }

    .player-bar .artist {
        font-size: 12px;
        line-height: 1.2; /* 세로 중앙 정렬을 위한 line-height 추가 */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        /* 플레이어 배경이 항상 어두우므로 텍스트는 반투명 흰색으로 고정 */
        color: rgba(255, 255, 255, 0.7) !important;
    }

    .player-bar .controls {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .player-bar button {
        min-width: 48px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        /* 플레이어 배경이 항상 어두우므로 아이콘은 항상 흰색으로 고정 */
        color: #fff !important;
        cursor: pointer;
        border-radius: 4px;
        transition: background-color 0.2s ease;
        font-size: 18px;
        padding: 0;
    }

    .player-bar button:active {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .player-bar button[aria-label="play"],
    .player-bar button[aria-label="pause"] {
        font-size: 20px;
    }

    /* 모바일 버퍼링 표시 */
    .player-bar.buffering {
        opacity: 0.8;
    }

    .player-bar.buffering button[aria-label="play"],
    .player-bar.buffering button[aria-label="pause"] {
        opacity: 0.6;
        cursor: wait;
    }
}

/* BottomSheet */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.sheet-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.player-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 70dvh;
    max-height: 70dvh;
    /* BottomSheet도 어두운 배경 사용 (플레이어와 일관성 유지) */
    background: var(--bg-audio-player, rgba(24, 24, 24, 0.95));
    /* 플레이어 배경이 항상 어두우므로 텍스트는 항상 흰색으로 고정 */
    color: #fff !important;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.player-sheet.is-open {
    transform: translateY(0);
}

.player-sheet .grabber {
    width: 48px;
    height: 4px;
    border-radius: 999px;
    background: var(--border-primary, #444);
    margin: 8px auto;
    flex-shrink: 0;
}

.player-sheet .sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

/* BottomSheet 내부 텍스트도 항상 흰색으로 고정 */
.player-sheet .sheet-body,
.player-sheet .sheet-body * {
    color: #fff !important;
}

/* BottomSheet 내부 특정 요소 스타일 조정 */
.player-sheet .sheet-body h3 {
    color: #fff !important;
}

.player-sheet .sheet-body p {
    color: rgba(255, 255, 255, 0.7) !important;
}

.player-sheet .sheet-body span {
    color: rgba(255, 255, 255, 0.9) !important;
}

.player-sheet .sheet-body button {
    color: #fff !important;
}

.player-sheet .sheet-body input[type="range"] {
    accent-color: #fff;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .sheet-backdrop,
  .player-sheet,
  .main-v2-top-nav {
    transition: none !important;
  }
}
