/* ===============================
   YouTube 플레이어 컨테이너 (부모 배경색)
================================= */
#youtube-player-container {
    margin: 20px 0;
    padding: 25px 0;
    background: #f4f9f9;
    border-radius: 20px;
    box-sizing: border-box;
    /* 내부의 미세 오차가 밖으로 보이지 않게 차단 */
    overflow: hidden; 
}

/* ✅ wrapper: padding-top 방식으로 16:9 비율 유지 (가장 안정적) */
#youtube-player-wrapper {
    position: relative;
    width: 100%;
    height: 0;
    padding-top: 56.25%; /* 16:9 비율 (9/16 = 0.5625) */
    background-color: #000;
    overflow: hidden;
}

/* youtube-player (iframe으로 교체됨) - 절대 위치로 wrapper에 꽉 채움 */
#youtube-player-wrapper > * {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    /* ✅ 0.3% 확대 - 다양한 페이지 너비에 대응 */
    width: 100.3% !important;
    height: 100.3% !important;
    transform: translate(-50%, -50%) !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
}

/* ===============================
   플레이리스트
================================= */
#youtube-playlist,
#yt-playlist-list,
.yt-playlist-container {
    background: #fcfefe;
    border-radius: 0;
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box;
    overflow: hidden;
}

/* 플레이리스트 헤더 */
.yt-playlist-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 0;
    border-bottom: 1px solid #e0e0e0;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.yt-playlist-header h4 {
    margin: 0;
    font-size: 1.2em;
    white-space: nowrap;
    color: #333;
}

.yt-playlist-header h4 i {
    color: #ff0000;
    margin-right: 8px;
}

.yt-count {
    font-size: 0.9em;
    white-space: nowrap;
    margin-left: 8px;
    color: #666;
}

/* 플레이리스트 아이템 목록 */
.yt-playlist-items {
    list-style: none;
    margin: 0 !important;
    padding: 0 !important;
    max-height: 400px;
    overflow-y: auto !important;
    overflow-x: hidden;
    position: relative;
    border-bottom: none !important;
    -webkit-overflow-scrolling: touch;
}

.yt-playlist-items .yt-playlist-item:last-child {
    border-bottom: none !important;
}

/* ===============================
   선택 전체 행
================================= */
.yt-select-all-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 10px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.yt-select-all-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.yt-select-all-row label {
    cursor: pointer;
    font-size: 14px;
    color: #666;
    user-select: none;
}

.yt-drag-info {
    margin-left: auto;
    font-size: 13px;
    color: #999;
    font-style: italic;
}

/* ===============================
   플레이리스트 아이템
================================= */
.yt-playlist-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-bottom: 1px solid #f0f0f0;
    background: #ffffff;
    overflow: visible;
    box-sizing: border-box;
    z-index: 1;
}

.yt-playlist-item:hover {
    background: #f8f9fa;
}

/* ✅ 1. 재생 중 왼쪽 빨간 바 (기존 유지) */
.yt-playlist-item.playing::after {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background-color: #ff0000;
    z-index: 25 !important;
}

/* ✅ 2. 드래그 가이드 라인 (::before) */
.yt-playlist-item.drag-over-top::before,
.yt-playlist-item.drag-over-bottom::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background-color: #ff0000;
    z-index: 20; /* 선이 보더보다 위에 오도록 */
    pointer-events: none;
}

/* 🔴 핵심 보정: 1px 보더 두께를 고려하여 선을 겹치게 배치 */
/* 위쪽 아이템의 바닥선과 아래쪽 아이템의 천장선이 같은 위치가 되도록 함 */
.yt-playlist-item.drag-over-top::before {
    top: -1px; /* 1px 위로 밀어올림 */
}

.yt-playlist-item.drag-over-bottom::before {
    bottom: -1px; /* 1px 아래로 밀어내림 */
}

/* ✅ 3. 최상단/최하단 잘림 방지 (안쪽 배치) */
.yt-playlist-items .yt-playlist-item:first-child.drag-over-top::before {
    top: 0 !important;
}
.yt-playlist-items .yt-playlist-item:last-child.drag-over-bottom::before {
    bottom: 0 !important;
}

/* ✅ 4. 흔들림 방지 및 보더 투명화 */
.yt-playlist-item.drag-over-top,
.yt-playlist-item.drag-over-bottom {
    background-color: rgba(255, 68, 68, 0.05) !important;
    /* 보더를 없애면 흔들리므로, 색상만 투명하게 바꿉니다. */
    border-bottom-color: transparent !important;
}

/* 체크박스 */
.yt-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
}

/* 선택된 항목 */
.yt-playlist-item.selected {
    opacity: 1;
}

.yt-playlist-item:not(.selected) .yt-item-title {
    color: #999;
}

/* 번호 */
.yt-item-num {
    font-size: 14px;
    color: #999;
    min-width: 25px;
    text-align: center;
    font-weight: 500;
    flex-shrink: 0;
}

/* 제목 */
.yt-item-title {
    flex: 1;
    font-size: 14px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 컨트롤 버튼 영역 */
.yt-item-controls {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* 이동 버튼 */
.yt-btn-move {
    padding: 6px 10px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.yt-btn-move:hover:not(:disabled) {
    background: #e0e0e0;
}

.yt-btn-move:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.yt-btn-move i {
    font-size: 10px;
}

/* 재생 버튼 */
.yt-item-play {
    padding: 4px 12px 7px 12px;
    background: #ff0000;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.2s;
    width: 32px;
}

.yt-item-play:hover {
    background: #cc0000;
}

.yt-item-play:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.4;
}

.yt-item-play i {
    font-size: 13px;
}

/* ===============================
   컨트롤 버튼
================================= */
.yt-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.yt-btn-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.yt-ctrl-btn {
    padding: 9px 0;
    background: #d9dfe3;
    border: none;
    color: #535962;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 51px;
    text-align: center;
    border-radius: 4px;
}

.yt-ctrl-btn.play {
    background: #ff0000;
    color: white;
    border-color: #ff0000;
}

.yt-ctrl-btn.play:hover {
    background: #cc0000;
}

#yt-ctrl-play-pause {
    background: #ff4444;
    border: none;
    color: #eee;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 아이콘 래퍼 */
.icon-wrapper {
    display: inline-block;
    width: 20px;
    text-align: center;
    margin-right: 1px;
}

.play-icon i {
    margin-left: 0;
}

/* ===============================
   빈 플레이리스트
================================= */
.yt-empty {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.yt-empty i {
    font-size: 48px;
    color: #ddd;
    margin-bottom: 15px;
}

.yt-empty p {
    margin: 0;
    line-height: 1.6;
}

/* 빈 플레이어 안내 메시지 */
#youtube-now-playing[data-comment-srl="none"] {
    cursor: default !important;
    pointer-events: none;
}

#youtube-now-playing[data-comment-srl="none"]:hover {
    background: #17191a !important;
}

body.color_scheme_dark #youtube-now-playing[data-comment-srl="none"]:hover {
    background: #22262e !important;
}

/* 빈 상태일 때 플레이어 화면 클릭 비활성화 */
#youtube-player-wrapper.empty-state {
    pointer-events: none;
    cursor: default;
}

#youtube-player-wrapper.empty-state::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 10;
}

/* ===============================
   다크 모드
================================= */
body.color_scheme_dark #youtube-player-container {
    background: #1a1d23;
}

body.color_scheme_dark #youtube-playlist,
body.color_scheme_dark #yt-playlist-list,
body.color_scheme_dark .yt-playlist-container {
    background: #22262e;
}

body.color_scheme_dark .yt-playlist-header {
    border-bottom-color: #2d323c;
}

body.color_scheme_dark .yt-playlist-header h4 {
    color: #e4e6eb;
}

body.color_scheme_dark .yt-count {
    color: #9ca3af;
}

body.color_scheme_dark .yt-select-all-row {
    background: #1a1d23;
    border-bottom-color: #2d323c;
}

body.color_scheme_dark .yt-select-all-row label {
    color: #9ca3af;
}

body.color_scheme_dark .yt-drag-info {
    color: #6b7280;
}

body.color_scheme_dark .yt-playlist-item {
    background: #22262e;
    border-bottom-color: #2d323c;
}

body.color_scheme_dark .yt-playlist-item:hover {
    background: #2a2f3a;
}

body.color_scheme_dark .yt-item-title {
    color: #e4e6eb;
}

body.color_scheme_dark .yt-item-num {
    color: #6b7280;
}

body.color_scheme_dark .yt-ctrl-btn {
    background: #2a2f3a;
    border-color: #3a404c;
    color: #e4e6eb;
}

body.color_scheme_dark .yt-ctrl-btn:hover {
    background: #333842;
}

body.color_scheme_dark .yt-ctrl-btn.play {
    background: #ff0000;
    border-color: #ff0000;
    color: white;
}

body.color_scheme_dark .yt-ctrl-btn.play:hover {
    background: #cc0000;
}

body.color_scheme_dark .yt-btn-move {
    background: #2a2f3a;
    border-color: #3a404c;
    color: #e4e6eb;
}

body.color_scheme_dark .yt-btn-move:hover:not(:disabled) {
    background: #333842;
}

body.color_scheme_dark .yt-btn-move:disabled {
    opacity: 0.3;
}

body.color_scheme_dark .yt-empty {
    color: #6b7280;
}

body.color_scheme_dark .yt-empty i {
    color: #374151;
}

body.color_scheme_dark .yt-playlist-items .yt-playlist-item:last-child {
    border-bottom-color: transparent !important;
}

/* ===============================
   모바일 최적화
================================= */
@media (max-width: 768px) {
    #youtube-player-container {
        border-radius: 10px;
        padding: 15px 0;
    }
    
    body.color_scheme_dark #youtube-player-container {
        background: #1a1d23;
    }
    
    #youtube-now-playing {
        font-size: 13px;
        padding: 8px 12px;
        margin: -4px 0 10px 0;
        height: 36px;
        border-radius: 0;
    }
    
    #youtube-playlist,
    body.color_scheme_dark #youtube-playlist {
        border-radius: 0;
    }
    
    .yt-playlist-header {
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 8px;
        padding-left: 7px;
        padding-right: 7px;
    }
    
    .yt-playlist-header h4 {
        font-size: 14px;
    }
    
    .yt-count {
        font-size: 0.9em;
        margin-left: 8px;
    }
    
    .yt-select-all-row {
        padding: 10px 6px;
    }
    
    .yt-item-controls {
        gap: 2px;
    }
    
    .yt-ctrl-btn {
        font-size: 18px !important;
    }
    .yt-playlist-items {
        max-height: 310px;
        overflow-y: auto;
    }
    
    .yt-playlist-item {
        padding: 4px 6px;
        font-size: 13px;
        gap: 6px;
    }
    
    .yt-item-title {
        font-size: 13px;
    }
    
    .yt-item-num {
        min-width: 12px;
        font-size: 12px;
        flex: 0 0 auto;
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
    }
    
    .yt-item-play {
        padding: 0;
        width: 26px;
        height: 26px;
    }
    
    .yt-controls {
        gap: 8px;
    }
    
    .yt-ctrl-btn {
        width: 43px;
        font-size: 18px;
        text-align: center;
    }
    
    .yt-drag-info {
        font-size: 13px;
    }
    
    .yt-btn-move {
        padding: 5px 8px;
    }
}

/* 데스크톱에서만 호버 효과 적용 */
@media (hover: hover) and (pointer: fine) {
    .yt-ctrl-btn:hover {
        transform: scale(1.2);
    }
    
    #yt-ctrl-play-pause:hover {
        color: #fff;
        transform: scale(1.2);
    }
}

/* ===============================
   YouTube 제목 자동 색인 애드온용 CSS
   youtube_player.css 파일 끝에 추가하세요
================================= */

/* YouTube 제목 자동 색인 - 숨김 처리 */
.yt-hidden-title {
    display: none !important;
    visibility: hidden !important;
    position: absolute !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
}

