/* 커스텀 비디오 플레이어 스타일 */
.custom-video-container {
    position: relative;
    width: 100%;
    max-width: 670px;
    aspect-ratio: 16 / 9;
    margin: 0 auto;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

.custom-video-container video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

/* ═══════════════════════════════════════
   자막 표시 영역
═══════════════════════════════════════ */
.subtitle-display {
    position: absolute;
    bottom: 60px;           /* 컨트롤 바 위 */
    left: 50%;
    transform: translateX(-50%);
    max-width: 90%;
    text-align: center;
    color: #fff;
    font-size: 18px;
    font-weight: 500;
    line-height: 1.5;
    text-shadow:
        1px  1px 2px #000,
       -1px  1px 2px #000,
        1px -1px 2px #000,
       -1px -1px 2px #000;
    background: rgba(0, 0, 0, 0.55);
    padding: 4px 14px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 9;
    word-break: keep-all;
    display: none;  /* renderSubtitle()에서 제어 */
    transition: bottom 0.3s ease;
}

/* 컨트롤 표시 중엔 자막을 더 위로 올림 */
.custom-video-container.show-controls .subtitle-display {
    bottom: 72px;
}

/* 자막 크기 variants */
.subtitle-display[data-size="small"]  { font-size: 13px; }
.subtitle-display[data-size="medium"] { font-size: 18px; }
.subtitle-display[data-size="large"]  { font-size: 24px; }
.subtitle-display[data-size="xlarge"] { font-size: 30px; }

/* 모바일 자막 기본 크기 */
@media screen and (max-width: 768px) {
    .subtitle-display { font-size: 14px; bottom: 55px; }
    .custom-video-container.show-controls .subtitle-display { bottom: 65px; }
    .subtitle-display[data-size="small"]  { font-size: 11px; }
    .subtitle-display[data-size="medium"] { font-size: 14px; }
    .subtitle-display[data-size="large"]  { font-size: 18px; }
    .subtitle-display[data-size="xlarge"] { font-size: 22px; }
}

@media (max-width: 480px) {
    .subtitle-display { font-size: 12px; }
}

/* ═══════════════════════════════════════
   자막 버튼 스타일 - 3가지 상태
═══════════════════════════════════════ */

/* 상태1: 자막 없음 - disabled, 회색 아이콘 */
.subtitle-toggle-btn:disabled {
    cursor: not-allowed;
    pointer-events: none;
}
#subtitleNoIcon path {
    fill: #666;
}

/* 상태2: 자막 있음 + 꺼짐 - 흰색 아이콘 */
#subtitleOffIcon path {
    fill: white;
}

/* 상태3: 자막 있음 + 켜짐 - 흰색으로 채워진 배경 + 투명 글자 */
#subtitleOnIcon path {
    fill: white;  /* evenodd로 글자 부분은 자동으로 투명(구멍) 처리됨 */
}

/* ═══════════════════════════════════════
   자막 크기 서브메뉴
═══════════════════════════════════════ */
.subtitle-size-submenu {
    position: fixed;
    background: rgba(28, 28, 28, 0.95);
    border-radius: 6px;
    padding: 8px 0;
    min-width: 140px;
    display: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
    z-index: 100;
}
.subtitle-size-submenu::-webkit-scrollbar { width: 4px; }
.subtitle-size-submenu::-webkit-scrollbar-track { background: transparent; }
.subtitle-size-submenu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }

.subtitle-size-submenu.active {
    display: block;
}

.subtitle-size-option {
    padding: 10px 16px;
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    position: relative;
}

.subtitle-size-option:hover {
    background: rgba(255,255,255,0.1);
}

.subtitle-size-option.active {
    color: #4fc3f7;
}

.subtitle-size-option.active::before {
    content: '✓';
    position: absolute;
    left: 6px;
}

/* ═══════════════════════════════════════
   기존 스타일 (원본 유지)
═══════════════════════════════════════ */

/* 영상 제목 오버레이 */
.video-title-overlay {
    position: absolute;
    top: 0; left: 0; right: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    padding: 15px 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
    pointer-events: none;
}
.custom-video-container.show-controls .video-title-overlay { opacity: 1; }
.video-title-text {
    color: white;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
}

/* 전체화면 */
.custom-video-container:-webkit-full-screen,
.custom-video-container:-moz-full-screen,
.custom-video-container:fullscreen {
    position: relative; overflow: hidden;
    width: 100vw !important; height: 100vh !important; max-width: 100vw !important;
    border-radius: 0;
    display: flex !important; align-items: center !important; justify-content: center !important;
    background: #000 !important;
}
.custom-video-container:-webkit-full-screen video,
.custom-video-container:-moz-full-screen video,
.custom-video-container:fullscreen video {
    max-width: 100% !important; max-height: 100% !important;
    width: auto !important; height: auto !important;
    object-fit: contain !important; margin: auto !important;
}

/* 컨트롤 바 */
.video-controls {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    padding: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}
.custom-video-container.show-controls .video-controls { opacity: 1; }

/* 프로그레스 바 */
.progress-container {
    width: 100%; height: 5px;
    background: rgba(255,255,255,0.3);
    cursor: pointer; margin-bottom: 8px; border-radius: 2px; position: relative;
}
.buffered-bar {
    position: absolute; height: 100%;
    background: rgba(255,255,255,0.5);
    width: 0%; border-radius: 2px; z-index: 1;
}
.progress-bar {
    height: 100%; background: #ff0000; width: 0%;
    border-radius: 2px; position: relative; z-index: 2;
}
.progress-bar::after {
    content: '';
    position: absolute; right: 0; top: 50%; transform: translateY(-50%);
    width: 12px; height: 12px; background: #ff0000; border-radius: 50%;
    opacity: 0; transition: opacity 0.2s;
}
.progress-container:hover .progress-bar::after,
.progress-container.dragging .progress-bar::after { opacity: 1; }

/* 타임 툴팁 */
.time-tooltip {
    position: absolute; bottom: 15px;
    background: rgba(0,0,0,0.9); color: white;
    padding: 4px 8px; border-radius: 4px;
    font-size: 12px; font-family: monospace;
    pointer-events: none; opacity: 0; transition: opacity 0.2s;
    transform: translateX(-50%); white-space: nowrap; z-index: 3;
}
.time-tooltip.show { opacity: 1; }

/* 컨트롤 레이아웃 */
.controls-wrapper { display: flex; justify-content: space-between; align-items: center; }
.controls-left, .controls-right { display: flex; align-items: center; gap: 10px; }

/* 버튼 */
.control-btn {
    background: none; border: none; color: white;
    cursor: pointer; padding: 5px;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s;
}
.control-btn:hover { transform: scale(1.1); }
.control-btn svg { width: 24px; height: 24px; fill: white; }

/* 볼륨 */
.volume-control { display: flex; align-items: center; gap: 5px; }
.volume-slider {
    width: 0; height: 4px;
    background: rgba(255,255,255,0.3);
    cursor: pointer; border-radius: 2px; position: relative; overflow: hidden;
    transition: width 0.3s ease;
}
.volume-control:hover .volume-slider { width: 60px; }
.volume-level { height: 100%; background: white; width: 100%; border-radius: 2px; }

/* 시간 표시 */
.time-display { color: white; font-size: 13px; font-family: monospace; user-select: none; }

/* 설정 메뉴 - overflow 없음: absolute 서브메뉴가 바깥으로 나올 수 있어야 함 */
.settings-menu {
    position: absolute; bottom: 50px; right: 10px;
    background: rgba(28,28,28,0.95); border-radius: 6px;
    min-width: 200px;
    display: none; z-index: 20; box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.settings-menu.active { display: block; }

/* 스크롤은 이 래퍼에서만 처리. 서브메뉴는 이 래퍼 밖(.settings-menu 직계)에 배치 */
.settings-scroll-wrapper {
    max-height: calc(var(--player-height, 300px) - 70px);
    overflow-y: auto;
    overflow-x: visible;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}
.settings-scroll-wrapper::-webkit-scrollbar { width: 4px; }
.settings-scroll-wrapper::-webkit-scrollbar-track { background: transparent; }
.settings-scroll-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }
.settings-scroll-wrapper::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.5); }
.settings-item {
    padding: 10px 16px; color: white; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    transition: background 0.2s;
}
.settings-item:hover { background: rgba(255,255,255,0.1); }
.settings-item-label { font-size: 14px; }
.settings-item-value { font-size: 13px; color: #aaa; }

/* 재생 속도 서브메뉴 */
.speed-submenu {
    position: fixed; /* fixed로 변경: overflow 클리핑 완전히 탈출 */
    background: rgba(28,28,28,0.95); border-radius: 6px;
    padding: 8px 0; min-width: 150px; display: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
    z-index: 100;
}
.speed-submenu::-webkit-scrollbar { width: 4px; }
.speed-submenu::-webkit-scrollbar-track { background: transparent; }
.speed-submenu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }
.speed-submenu.active { display: block; }
.speed-option {
    padding: 10px 16px; color: white; cursor: pointer;
    font-size: 14px; transition: background 0.2s; position: relative;
}
.speed-option:hover { background: rgba(255,255,255,0.1); }
.speed-option.active { color: #ff0000; }
.speed-option.active::before { content: '✓'; position: absolute; left: 8px; }

/* 로딩 스피너 */
.loading-spinner {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    width: 50px; height: 50px;
    border: 4px solid rgba(255,255,255,0.3); border-top-color: white;
    border-radius: 50%; animation: spin 1s linear infinite;
    display: none; z-index: 5;
}
.loading-spinner.active { display: block; }
@keyframes spin { to { transform: translate(-50%,-50%) rotate(360deg); } }

/* 센터 재생 버튼 */
.center-play-btn {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    width: 80px; height: 80px;
    background: rgba(0,0,0,0.6); border-radius: 50%; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.3s; z-index: 5;
}
.center-play-btn:hover { background: rgba(0,0,0,0.8); transform: translate(-50%,-50%) scale(1.1); }
.center-play-btn svg { width: 40px; height: 40px; fill: white; margin-left: 5px; }
.center-play-btn.hidden { display: none; }

/* 모바일 센터 재생 표시 */
.mobile-center-play {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    width: 80px; height: 80px;
    background: rgba(0,0,0,0.6); border-radius: 50%; border: none;
    display: none; align-items: center; justify-content: center;
    z-index: 6; pointer-events: none; opacity: 0; transition: opacity 0.3s;
}
.mobile-center-play.show { opacity: 1; }
.mobile-center-play svg { width: 40px; height: 40px; fill: white; }
.mobile-center-play svg.play-icon { margin-left: 5px; }

/* 모바일 화면 중앙 재생/정지 버튼 */
.mobile-center-control-btn {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    width: 64px; height: 64px;
    background: rgba(0,0,0,0.6); border: 2px solid rgba(255,255,255,0.8);
    border-radius: 50%; cursor: pointer;
    display: none; align-items: center; justify-content: center;
    transition: all 0.3s ease; z-index: 8; opacity: 0;
}
.custom-video-container.show-controls .mobile-center-control-btn { opacity: 1; }
.mobile-center-control-btn:active { transform: translate(-50%,-50%) scale(0.95); background: rgba(0,0,0,0.8); }
.mobile-center-control-btn svg { width: 32px; height: 32px; fill: white; }
.mobile-center-control-btn svg:first-child { margin-left: 3px; }

/* 더블탭 피드백 */
.double-tap-feedback {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 100px; height: 100px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.7); border-radius: 50%;
    color: white; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 15;
}
.double-tap-feedback.left { left: 15%; }
.double-tap-feedback.right { right: 15%; }
.double-tap-feedback.show { opacity: 1; animation: scaleUp 0.3s ease; }
.double-tap-feedback svg { width: 48px; height: 48px; fill: white; margin-bottom: 4px; }
.double-tap-feedback span { font-size: 14px; font-weight: bold; }
@keyframes scaleUp {
    0%   { transform: translateY(-50%) scale(0.8); }
    50%  { transform: translateY(-50%) scale(1.1); }
    100% { transform: translateY(-50%) scale(1); }
}

/* ─── 반응형 ─── */
@media screen and (max-width: 768px) {
    .control-btn svg { width: 20px; height: 20px; }
    .time-display { font-size: 11px; }
    .controls-left, .controls-right { gap: 5px; }
    .volume-slider { display: none; }
    .mobile-center-play { display: flex; }
    .mobile-center-control-btn { display: flex; }
    .progress-container { padding: 4px 0; margin-bottom: 0; display: flex; align-items: center; }
    .buffered-bar, .progress-bar { position: absolute; top: 50%; transform: translateY(-50%); left: 0; }
    .time-tooltip { bottom: 35px; font-size: 13px; padding: 6px 10px; }
    .progress-bar::after { width: 14px; height: 14px; }
    .video-title-overlay { padding: 12px 15px; }
    .video-title-text { font-size: 14px; -webkit-line-clamp: 1; }
}

@media (max-width: 480px) {
    .double-tap-feedback { width: 80px; height: 80px; }
    .double-tap-feedback.left { left: 10%; }
    .double-tap-feedback.right { right: 10%; }
    .double-tap-feedback svg { width: 36px; height: 36px; }
    .double-tap-feedback span { font-size: 12px; }
    .center-play-btn { width: 70px; height: 70px; }
    .center-play-btn svg { width: 35px; height: 35px; }
    .mobile-center-play { width: 70px; height: 70px; }
    .mobile-center-play svg { width: 35px; height: 35px; }
    .mobile-center-control-btn { width: 56px; height: 56px; }
    .mobile-center-control-btn svg { width: 28px; height: 28px; }
    .video-title-overlay { padding: 10px 12px; }
    .video-title-text { font-size: 13px; }
}