/* Sửa lỗi rò rỉ viền trắng do lệch sub-pixel rendering giữa phần tử bao ngoài và player */
.video.col-span-2 > div.rounded-md {
    border-radius: 12px !important;
    background-color: transparent !important;
    -webkit-transform: translateZ(0) !important;
    transform: translateZ(0) !important;
    margin-top: 25px !important; /* Tạo khoảng cách với phần tiêu đề bên trên */
    margin-bottom: 20px !important; /* Dịch chuyển margin ra ngoài wrapper */
}

.custom-yt-player-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background-color: #000;
    border-radius: 12px;
    overflow: hidden;
    /* Force WebKit browser clipping for rounded corners on GPU-accelerated frames */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    margin-bottom: 0; /* Loại bỏ margin ở container bên trong */
    user-select: none;
    -webkit-user-select: none;
}

.custom-yt-player-container iframe,
body .custom-yt-player-container iframe {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border: 0 !important;
    border-radius: 12px !important; /* Đồng bộ góc bo trực tiếp trên iframe */
    background: #000000 !important; /* Force black background to prevent white load flicker */
    pointer-events: none !important; /* Ngăn tương tác trực tiếp với iframe */
    z-index: 1 !important;
    transform: none !important;
}

/* Lớp phủ chặn click chuột ngoài */
.yt-click-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    cursor: pointer;
}

/* Lớp phủ ảnh Thumbnail khi tạm dừng hoặc chưa phát */
.yt-thumb-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    border-radius: 12px; /* Đồng bộ góc bo trực tiếp trên lớp Thumbnail */
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1), visibility 0.4s;
    opacity: 1;
    visibility: visible;
}

.yt-thumb-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.yt-thumb-img,
body .custom-yt-player-container .yt-thumb-overlay img.yt-thumb-img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: cover !important;
    object-position: center !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    pointer-events: none !important;
}

.yt-thumb-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.35); /* Làm tối nhẹ ảnh nền để nút phát nổi bật */
    z-index: 1;
}

/* Nút Play lớn ở giữa màn hình */
.custom-yt-player-container .yt-big-play-btn {
    position: relative;
    z-index: 3;
    width: 80px !important;
    height: 80px !important;
    background: linear-gradient(135deg, #ea6e43 0%, #f43f5e 100%) !important;
    border: none !important;
    border-radius: 50% !important;
    color: #ffffff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 8px 25px rgba(234, 110, 67, 0.45) !important;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s, background 0.3s;
    animation: yt-pulse 2.5s infinite;
    outline: none !important; /* Loại bỏ viền vuông focus khi click */
    padding: 0 !important;
    margin: 0 !important;
}

.custom-yt-player-container .yt-big-play-btn:hover {
    transform: scale(1.1) rotate(10deg) !important; /* Xoay nhẹ khi hover */
    background: linear-gradient(135deg, #f43f5e 0%, #ea6e43 100%) !important; /* Đổi màu gradient */
    box-shadow: 0 12px 30px rgba(234, 110, 67, 0.6) !important;
}

.custom-yt-player-container .yt-big-play-btn svg {
    width: 32px;
    height: 32px;
    fill: currentColor;
}

.custom-yt-player-container .yt-big-play-btn .yt-icon-play-triangle {
    margin-left: 2px !important; /* Căn chỉnh tâm tam giác phát chuẩn xác */
    display: block;
}

/* Ẩn tam giác phát và hiện spinner xoay tròn khi loading */
.custom-yt-player-container.loading .yt-big-play-btn .yt-icon-play-triangle {
    display: none !important;
}

.custom-yt-player-container.loading .yt-big-play-btn .yt-icon-play-spinner {
    display: block !important;
    animation: yt-spin-loader 1s linear infinite !important;
}

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

@keyframes yt-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(234, 110, 67, 0.6);
    }
    70% {
        box-shadow: 0 0 0 18px rgba(234, 110, 67, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(234, 110, 67, 0);
    }
}

/* Thanh điều khiển dưới đáy */
.yt-control-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 52px;
    background: rgba(15, 23, 42, 0.35) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 15px;
    box-sizing: border-box;
    transform: translateY(8px);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Hiển thị thanh công cụ khi video đang tạm dừng hoặc khi người dùng tương tác hoạt động */
.custom-yt-player-container.paused .yt-control-bar,
.custom-yt-player-container.controls-active .yt-control-bar {
    transform: translateY(0);
    opacity: 1;
}

/* Các nút điều khiển */
.yt-control-btn {
    background-color: rgba(156, 163, 175, 0.2) !important;
    border: none !important;
    color: #ffffff !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s, transform 0.1s;
    padding: 0;
}

.yt-control-btn:hover {
    background-color: rgba(156, 163, 175, 0.4) !important;
    color: #ea6e43 !important;
}

.yt-control-btn:active {
    transform: scale(0.95);
}

.yt-control-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Nhãn thời gian */
.yt-time-display {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, monospace;
    font-size: 13px;
    color: #ffffff;
    white-space: nowrap;
    letter-spacing: 0.5px;
}

/* Thanh tua Video (Seek Slider) */
.yt-seek-container {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
    height: 20px;
    cursor: pointer;
}

.yt-seek-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    transition: height 0.1s ease;
    margin: 0;
}

.yt-seek-container:hover .yt-seek-slider {
    height: 7px;
}

/* Thanh tiến trình đã chạy */
.yt-seek-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 100%;
    background: transparent;
}

/* Nút tròn di chuyển (Thumb) */
.yt-seek-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #ea6e43;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    margin-top: -4px; /* Cho Safari/Chrome */
    transform: scale(0);
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.yt-seek-container:hover .yt-seek-slider::-webkit-slider-thumb {
    transform: scale(1);
}

.yt-seek-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border: none;
    border-radius: 50%;
    background: #ea6e43;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transform: scale(0);
    transition: transform 0.15s ease;
}

.yt-seek-container:hover .yt-seek-slider::-moz-range-thumb {
    transform: scale(1);
}

/* Điều chỉnh âm lượng */
.yt-volume-container {
    display: flex;
    align-items: center;
    gap: 0;
    transition: gap 0.2s ease;
}

.yt-volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s;
    opacity: 0;
    margin: 0;
}

.yt-volume-container:hover .yt-volume-slider {
    width: 70px;
    opacity: 1;
    margin-left: 6px;
}

.yt-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    margin-top: -3px;
}

.yt-volume-slider::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border: none;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
}

/* Menu tốc độ phát */
.yt-speed-container {
    position: relative;
}

.yt-speed-btn {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 13px;
    color: #ffffff !important;
    background: rgba(156, 163, 175, 0.2) !important;
    border: 1px solid rgba(156, 163, 175, 0.3) !important;
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 48px;
    text-align: center;
}

.yt-speed-btn:hover {
    background: rgba(156, 163, 175, 0.4) !important;
    border-color: #ea6e43 !important;
    color: #ea6e43 !important;
}

.yt-speed-menu {
    position: absolute;
    bottom: 45px;
    right: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 6px 0;
    min-width: 90px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    z-index: 5;
    animation: yt-slide-up 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.yt-speed-menu.show {
    display: flex;
}

@keyframes yt-slide-up {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.yt-speed-item {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: #d1d5db;
    padding: 8px 12px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.yt-speed-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.yt-speed-item.active {
    color: #ea6e43;
    font-weight: 700;
    background-color: rgba(234, 110, 67, 0.1);
}

/* Hỗ trợ chế độ Toàn màn hình (Fullscreen) */
.custom-yt-player-container:fullscreen,
.custom-yt-player-container:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    aspect-ratio: auto !important;
}

.custom-yt-player-container:fullscreen iframe,
.custom-yt-player-container:-webkit-full-screen iframe {
    border-radius: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
}

.custom-yt-player-container:fullscreen .yt-control-bar,
.custom-yt-player-container:-webkit-full-screen .yt-control-bar {
    bottom: 15px !important;
    width: calc(100% - 30px) !important;
    left: 15px !important;
    border-radius: 10px !important;
    background: rgba(15, 23, 42, 0.35) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    height: 60px !important;
}

@media (max-width: 768px) {
    /* Cho video sát sang 2 bên màn hình di động và bỏ bo 4 góc */
    .video.col-span-2 > div.rounded-md {
        margin-left: -20px !important;
        margin-right: -20px !important;
        width: calc(100% + 40px) !important;
        max-width: calc(100% + 40px) !important;
        border-radius: 0px !important;
    }
    
    .custom-yt-player-container {
        border-radius: 0px !important;
    }
    
    .custom-yt-player-container iframe,
    body .custom-yt-player-container iframe {
        border-radius: 0px !important;
    }
    
    .yt-thumb-overlay {
        border-radius: 0px !important;
    }
    
    .yt-control-bar {
        border-bottom-left-radius: 0px !important;
        border-bottom-right-radius: 0px !important;
    }

    .custom-yt-player-container .yt-big-play-btn {
        width: 50px !important;
        height: 50px !important;
        box-shadow: 0 6px 18px rgba(234, 110, 67, 0.4) !important;
    }
    
    .custom-yt-player-container .yt-big-play-btn svg {
        width: 24px !important;
        height: 24px !important;
    }
    
    .custom-yt-player-container .yt-big-play-btn .yt-icon-play-triangle {
        margin-left: 1px !important;
    }

    /* Tối ưu hóa thanh điều khiển trên Mobile để thanh tua (seek) dài ra */
    .yt-control-bar {
        gap: 6px !important;
        padding: 0 8px !important;
        height: 48px !important;
    }

    /* Ẩn nút âm lượng trên Mobile vì người dùng sử dụng phím cứng của điện thoại */
    .custom-yt-player-container .yt-volume-container {
        display: none !important;
    }

    /* Ẩn nút Play/Pause ở góc trái bên dưới trên Mobile (người dùng chạm màn hình để phát/dừng) */
    .custom-yt-player-container .yt-play-pause-btn {
        display: none !important;
    }

    /* Thu nhỏ chữ hiển thị thời gian */
    .yt-time-display {
        font-size: 11px !important;
        letter-spacing: 0px !important;
    }

    /* Thu nhỏ nhẹ nút chọn tốc độ phát */
    .yt-speed-btn {
        padding: 3px 6px !important;
        min-width: 38px !important;
        font-size: 11px !important;
    }

    /* Hiển thị rõ và phóng to nút tròn kéo tua để dễ chạm vuốt (Touch Friendly) */
    .yt-seek-slider {
        height: 6px !important;
    }

    .yt-seek-slider::-webkit-slider-thumb {
        transform: scale(1.3) !important;
        margin-top: -3px !important;
    }

    .yt-seek-slider::-moz-range-thumb {
        transform: scale(1.3) !important;
    }
}

/* Giả lập toàn màn hình bằng CSS cho iOS Safari / iPhone */
.custom-yt-player-container.fullscreen-active {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999 !important;
    border-radius: 0 !important;
    margin: 0 !important;
    aspect-ratio: auto !important;
}

.custom-yt-player-container.fullscreen-active iframe {
    border-radius: 0 !important;
}

.custom-yt-player-container.fullscreen-active .yt-control-bar {
    bottom: 15px !important;
    width: calc(100% - 30px) !important;
    left: 15px !important;
    border-radius: 10px !important;
    background: rgba(15, 23, 42, 0.85) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    height: 60px !important;
}

/* Cho phép hiển thị player fullscreen đè lên các thẻ cha trong Elementor */
body.yt-parent-fullscreen-active .video.col-span-2 > div.rounded-md,
body.yt-parent-fullscreen-active .video.col-span-2,
body.yt-parent-fullscreen-active .grid,
body.yt-parent-fullscreen-active .kp3-courses,
body.yt-parent-fullscreen-active .kp3-topic,
body.yt-parent-fullscreen-active .elementor-widget-container,
body.yt-parent-fullscreen-active .elementor-widget,
body.yt-parent-fullscreen-active .elementor-column-wrap,
body.yt-parent-fullscreen-active .elementor-column,
body.yt-parent-fullscreen-active .elementor-row,
body.yt-parent-fullscreen-active .elementor-container,
body.yt-parent-fullscreen-active .elementor-section {
    transform: none !important;
    -webkit-transform: none !important;
    perspective: none !important;
    filter: none !important;
    will-change: auto !important;
    overflow: visible !important;
}

/* Nút thoát toàn màn hình nổi bật ở góc phải trên */
.yt-fullscreen-exit-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    background: rgba(15, 23, 42, 0.7) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 50% !important;
    color: #ffffff !important;
    cursor: pointer !important;
    display: none !important; /* Mặc định ẩn */
    align-items: center !important;
    justify-content: center !important;
    z-index: 999999999 !important;
    transition: background 0.2s, transform 0.2s !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
}

.yt-fullscreen-exit-btn:hover {
    background: rgba(234, 110, 67, 0.95) !important;
    transform: scale(1.05) !important;
}

.yt-fullscreen-exit-btn svg {
    width: 24px !important;
    height: 24px !important;
    fill: currentColor !important;
}

/* Chỉ hiển thị nút thoát khi ở chế độ fullscreen */
.custom-yt-player-container:fullscreen .yt-fullscreen-exit-btn,
.custom-yt-player-container:-webkit-full-screen .yt-fullscreen-exit-btn,
.custom-yt-player-container.fullscreen-active .yt-fullscreen-exit-btn {
    display: flex !important;
}

/* Lớp nền đen che toàn bộ trang web phía sau ở chế độ giả lập Fullscreen */
.custom-yt-player-container.fullscreen-active::before {
    content: '';
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    width: 300vw !important;
    height: 300vh !important;
    transform: translate(-50%, -50%) !important;
    -webkit-transform: translate(-50%, -50%) !important;
    background: #000000 !important;
    z-index: -1 !important;
    pointer-events: none !important;
}

/* Xoay ngang trình phát video khi phóng to trên thiết bị di động ở chế độ màn hình dọc (portrait) */
@media (max-width: 768px) and (orientation: portrait) {
    .custom-yt-player-container:fullscreen,
    .custom-yt-player-container:-webkit-full-screen,
    .custom-yt-player-container.fullscreen-active {
        width: min(100vh, 177.78vw) !important; /* Chiều ngang tối đa của video xoay ngang theo tỷ lệ 16:9 */
        height: min(56.25vh, 100vw) !important; /* Chiều dọc tối đa tương ứng để không bị tràn màn hình cắt 2 bên */
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) rotate(90deg) !important;
        -webkit-transform: translate(-50%, -50%) rotate(90deg) !important;
        z-index: 99999999 !important;
        border-radius: 0 !important;
        margin: 0 !important;
        aspect-ratio: auto !important;
    }

    .custom-yt-player-container:fullscreen iframe,
    .custom-yt-player-container:-webkit-full-screen iframe,
    .custom-yt-player-container.fullscreen-active iframe {
        width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
    }

    /* Đảm bảo thanh điều khiển hiển thị xoay theo container */
    .custom-yt-player-container:fullscreen .yt-control-bar,
    .custom-yt-player-container:-webkit-full-screen .yt-control-bar,
    .custom-yt-player-container.fullscreen-active .yt-control-bar {
        bottom: 15px !important;
        width: calc(100% - 30px) !important;
        left: 15px !important;
        border-radius: 10px !important;
        height: 52px !important;
        padding: 0 10px !important;
    }
}

/* Hiển thị đầy đủ nút Play/Pause và Volume ở dạng Fullscreen trên Mobile */
.custom-yt-player-container:fullscreen .yt-play-pause-btn,
.custom-yt-player-container:-webkit-full-screen .yt-play-pause-btn,
.custom-yt-player-container.fullscreen-active .yt-play-pause-btn {
    display: flex !important;
}

.custom-yt-player-container:fullscreen .yt-volume-container,
.custom-yt-player-container:-webkit-full-screen .yt-volume-container,
.custom-yt-player-container.fullscreen-active .yt-volume-container {
    display: flex !important;
}

.custom-yt-player-container:fullscreen .yt-seek-container,
.custom-yt-player-container:-webkit-full-screen .yt-seek-container,
.custom-yt-player-container.fullscreen-active .yt-seek-container {
    flex: 1 !important;
}

/* Tự động mở rộng thanh kéo âm lượng trên mobile khi fullscreen để dễ chạm vuốt (Touch-friendly) */
@media (max-width: 768px) {
    .custom-yt-player-container:fullscreen .yt-volume-slider,
    .custom-yt-player-container:-webkit-full-screen .yt-volume-slider,
    .custom-yt-player-container.fullscreen-active .yt-volume-slider {
        width: 60px !important;
        opacity: 1 !important;
        margin-left: 6px !important;
    }
}

/* Ẩn tiến trình bài học và nút hoàn thành/điều hướng mặc định của LearnDash */
.ld-infobar,
.ld-content-actions,
.learndash_topic_dots,
.learndash-topic-parent-link,
.ld-lesson-navigation,
.ld-topic-navigation,
#learndash_next_prev_link,
#learndash_back_to_lesson,
.learndash_mark_complete_button {
    display: none !important;
}
