/* ═══════════════════════════════════════════════════════════════
   KHUSHFLIX UNIVERSAL PLAYER — player.css
   Cross-compatible: Desktop / Mobile / Smart TV
   ═══════════════════════════════════════════════════════════════ */

/* ── Player Wrapper ── */
.kf-player-wrap {
    position: relative;
    width: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    /* Contain everything */
    isolation: isolate;
}

.kf-player-wrap video {
    width: 100%;
    display: block;
    max-height: 80vh;
    background: #000;
}

/* ── Controls Overlay ── */
.kf-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    background: linear-gradient(0deg, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.6) 60%, transparent 100%);
    padding: 60px 16px 14px;
    opacity: 1;
    transition: opacity 0.35s ease;
    pointer-events: auto;
}

.kf-player-wrap.kf-controls-hidden .kf-controls {
    opacity: 0;
    pointer-events: none;
}

/* ── Title Bar (top) ── */
.kf-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 11;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, transparent 100%);
    opacity: 1;
    transition: opacity 0.35s ease;
}

.kf-player-wrap.kf-controls-hidden .kf-topbar {
    opacity: 0;
    pointer-events: none;
}

.kf-topbar-title {
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.kf-topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ── Progress Bar ── */
.kf-progress-area {
    position: relative;
    width: 100%;
    padding: 6px 0 10px;
    cursor: pointer;
    touch-action: none;
}

.kf-progress-track {
    position: relative;
    width: 100%;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: visible;
    transition: height 0.15s ease;
}

.kf-progress-area:hover .kf-progress-track,
.kf-progress-area.kf-scrubbing .kf-progress-track {
    height: 7px;
}

.kf-progress-buffered {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: rgba(255,255,255,0.18);
    border-radius: 4px;
    pointer-events: none;
}

.kf-progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #e50914;
    border-radius: 4px;
    pointer-events: none;
    transition: width 0.1s linear;
}

.kf-progress-thumb {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    background: #e50914;
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    pointer-events: none;
    box-shadow: 0 0 6px rgba(0,0,0,0.5);
}

.kf-progress-area:hover .kf-progress-thumb,
.kf-progress-area.kf-scrubbing .kf-progress-thumb {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Hover time tooltip */
.kf-progress-tooltip {
    position: absolute;
    bottom: 100%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #fff;
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    margin-bottom: 8px;
    font-variant-numeric: tabular-nums;
    transition: opacity 0.12s ease;
}

.kf-progress-area:hover .kf-progress-tooltip {
    opacity: 1;
}

/* ── Button Row ── */
.kf-btn-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.kf-btn-row-left {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.kf-btn-row-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── Universal Button ── */
.kf-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    transition: background 0.15s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    min-width: 36px;
    min-height: 36px;
}

.kf-btn:hover {
    background: rgba(255,255,255,0.12);
}

.kf-btn:active {
    transform: scale(0.92);
}

.kf-btn:focus-visible {
    outline: 2px solid #e50914;
    outline-offset: 2px;
}

.kf-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ── Time Display ── */
.kf-time {
    color: rgba(255,255,255,0.85);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    padding: 0 6px;
    letter-spacing: 0.02em;
}

/* ── Volume Slider ── */
.kf-volume-wrap {
    display: flex;
    align-items: center;
    gap: 0;
}

.kf-volume-slider {
    width: 0;
    overflow: hidden;
    transition: width 0.2s ease, opacity 0.2s ease;
    opacity: 0;
}

.kf-volume-wrap:hover .kf-volume-slider,
.kf-volume-wrap.kf-vol-open .kf-volume-slider {
    width: 100px;
    opacity: 1;
}

.kf-volume-slider input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 90px;
    height: 4px;
    background: rgba(255,255,255,0.25);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    margin: 0 4px;
}

.kf-volume-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
}

.kf-volume-slider input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

/* Volume percentage label */
.kf-volume-pct {
    color: rgba(255,255,255,0.6);
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    min-width: 28px;
    text-align: center;
    opacity: 0;
    width: 0;
    overflow: hidden;
    transition: opacity 0.2s ease, width 0.2s ease;
}

.kf-volume-wrap:hover .kf-volume-pct,
.kf-volume-wrap.kf-vol-open .kf-volume-pct {
    opacity: 1;
    width: auto;
}

.kf-volume-pct.kf-vol-boosted {
    color: #e5730e;
    font-weight: 600;
}

/* ── Skip Indicators ── */
.kf-skip-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 50px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 12;
}

.kf-skip-indicator.kf-skip-back {
    left: 12%;
}

.kf-skip-indicator.kf-skip-fwd {
    right: 12%;
}

.kf-skip-indicator.kf-skip-visible {
    opacity: 1;
}

.kf-skip-indicator svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

/* ── Double-tap zones (mobile) ── */
.kf-tap-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 35%;
    z-index: 8;
}

.kf-tap-zone-left {
    left: 0;
}

.kf-tap-zone-right {
    right: 0;
}

/* ── Center play/pause overlay ── */
.kf-center-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 9;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.kf-center-play.kf-center-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.kf-center-play svg {
    width: 32px;
    height: 32px;
    fill: #fff;
}

/* ── Playback Speed Menu ── */
.kf-speed-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: rgba(20,20,20,0.95);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 6px 0;
    display: none;
    z-index: 20;
    min-width: 120px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.kf-speed-menu.kf-menu-open {
    display: block;
}

.kf-speed-option {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    text-align: left;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.kf-speed-option:hover,
.kf-speed-option:focus-visible {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.kf-speed-option.kf-speed-active {
    color: #e50914;
    font-weight: 700;
}

/* ── Loading Spinner ── */
.kf-loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 13;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.kf-loading-overlay.kf-loading-visible {
    opacity: 1;
}

.kf-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: #e50914;
    border-radius: 50%;
    animation: kf-spin 0.8s linear infinite;
}

@keyframes kf-spin {
    to { transform: rotate(360deg); }
}

/* ── Fullscreen ── */

/* Fake fullscreen (CSS-only fallback) */
.kf-player-wrap.kf-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    z-index: 999999 !important;
    background: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.kf-player-wrap.kf-fullscreen video {
    width: 100% !important;
    height: 100% !important;
    max-height: 100vh !important;
    object-fit: contain;
}

/* When fullscreen is via Fullscreen API (on the wrapper) */
.kf-player-wrap:fullscreen,
.kf-player-wrap:-webkit-full-screen,
.kf-player-wrap:-moz-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    background: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.kf-player-wrap:fullscreen video,
.kf-player-wrap:-webkit-full-screen video,
.kf-player-wrap:-moz-full-screen video {
    width: 100% !important;
    height: 100% !important;
    max-height: 100vh !important;
    object-fit: contain;
}

/* ── PiP indicator ── */
.kf-pip-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 16px 28px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    z-index: 15;
    display: none;
    pointer-events: none;
}

.kf-player-wrap.kf-pip-active .kf-pip-badge {
    display: block;
}

/* ═══════════ TV-SPECIFIC OVERRIDES ═══════════ */

/* Larger hit targets on TV */
.tv-mode .kf-btn {
    min-width: 48px;
    min-height: 48px;
    padding: 10px;
}

.tv-mode .kf-btn svg {
    width: 28px;
    height: 28px;
}

.tv-mode .kf-time {
    font-size: 1rem;
}

.tv-mode .kf-progress-track {
    height: 6px;
}

.tv-mode .kf-progress-area:hover .kf-progress-track {
    height: 10px;
}

.tv-mode .kf-progress-thumb {
    width: 18px;
    height: 18px;
}

.tv-mode .kf-topbar-title {
    font-size: 1.2rem;
}

/* TV focus ring on buttons */
.tv-mode .kf-btn:focus-visible,
.tv-mode .kf-btn.kf-tv-focused {
    outline: 3px solid #e50914;
    outline-offset: 3px;
    background: rgba(229,9,20,0.15);
}

/* ═══════════ MOBILE OVERRIDES ═══════════ */
@media (max-width: 600px) {
    .kf-controls {
        padding: 40px 10px 10px;
    }
    .kf-topbar {
        padding: 10px 10px;
    }
    .kf-topbar-title {
        font-size: 0.8rem;
        max-width: 55%;
    }
    .kf-btn {
        min-width: 32px;
        min-height: 32px;
        padding: 5px;
    }
    .kf-btn svg {
        width: 20px;
        height: 20px;
    }
    .kf-time {
        font-size: 0.7rem;
    }
    .kf-volume-wrap {
        display: none; /* Hide volume on mobile — use hardware buttons */
    }
    .kf-skip-indicator {
        font-size: 0.75rem;
        padding: 8px 14px;
    }
    .kf-skip-indicator svg {
        width: 18px;
        height: 18px;
    }
    .kf-speed-menu {
        min-width: 100px;
    }
}

@media (max-width: 380px) {
    .kf-btn-row-left .kf-btn:not(.kf-btn-play):not(.kf-btn-skip-fwd):not(.kf-btn-skip-back) {
        display: none;
    }
}

/* ═══════════ LANDSCAPE MOBILE (fullscreen-like) ═══════════ */
@media (max-height: 500px) and (orientation: landscape) {
    .kf-player-wrap video {
        max-height: 100vh;
    }
}