/* === CSS Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-card: #1a1a2e;
    --accent: #f5a623;
    --accent-hover: #e6951a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --danger: #ef4444;
    --success: #22c55e;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    direction: rtl;
    touch-action: manipulation; /* Improve touch response */
}

.hidden {
    display: none !important;
}

/* === Loading Screen === */
.loading-screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 100;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* === Error Screen === */
.error-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 90;
    padding: 20px;
}

.error-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 30px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow);
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.error-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.error-message {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 24px;
}

.error-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* === Buttons === */
.btn {
    padding: 12px 24px; /* Larger touch area */
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    min-height: 44px; /* Minimum Apple touch target size */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: var(--accent);
    color: #000;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* === VLC / External Player Fallback === */
.vlc-url-row {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    align-items: stretch;
}

.vlc-url-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 12px;
    font-family: 'Consolas', monospace;
    outline: none;
}

.vlc-url-input:focus {
    border-color: var(--accent);
}

.vlc-url-row .btn {
    padding: 10px 16px;
    white-space: nowrap;
}

.vlc-hint {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.6;
}

/* === Player Container === */
.player-container {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
}

/* === Title Bar === */
.title-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.9) 0%, rgba(0,0,0,0.6) 60%, transparent 100%);
    padding: 16px 24px;
    opacity: 1;
    transition: opacity 0.4s ease;
    pointer-events: auto;
}

.title-bar.hidden-controls {
    opacity: 0;
    pointer-events: none;
}

.title-bar-content {
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.bee-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.video-title {
    flex: 1;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    direction: ltr; /* Ensure scrolling/truncation works well for mixed text */
    text-align: right;
}

.back-btn {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
    transition: var(--transition);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

/* === Video Wrapper === */
.video-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    cursor: pointer;
    overflow: hidden;
}

#video-player {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

/* === Controls === */
.controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.6) 60%, transparent 100%);
    padding: 80px 24px 20px; /* More top padding for gradient fade */
    opacity: 1;
    transition: opacity 0.4s ease;
    pointer-events: auto;
}

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

.controls-inner {
    max-width: 1000px;
    margin: 0 auto;
}

.controls-top {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.controls-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.controls-left, .controls-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* === Control Buttons === */
.control-btn {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    min-width: 44px;
    min-height: 44px; /* Better touch target */
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

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

.skip-label {
    position: absolute;
    font-size: 10px;
    font-weight: 700;
    color: white;
    bottom: 10px; /* Adjusted for larger button */
    right: 50%;
    transform: translateX(50%);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* === Progress Bar === */
.progress-container {
    width: 100%;
    position: relative;
    padding: 5px 0; /* Increase touch hit area vertically */
    cursor: pointer;
}

.progress-bar {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px; /* Thinner inactive track */
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    cursor: pointer;
    transition: height 0.15s ease, background 0.2s;
    position: relative;
    z-index: 2;
}

.progress-container:hover .progress-bar,
.progress-bar:focus {
    height: 6px;
    background: rgba(255, 255, 255, 0.4);
}

.progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; /* Default small thumb */
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(245, 166, 35, 0.6);
    transition: transform 0.1s;
    margin-top: -4px; /* Center on track */
}

.progress-bar::-webkit-slider-runnable-track {
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.progress-container:hover .progress-bar::-webkit-slider-thumb {
    transform: scale(1.2);
}

.time-display {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 500;
    color: #e0e0e0;
    margin-top: 4px;
    direction: ltr;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* === Volume === */
.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    transition: width 0.3s ease;
}

.volume-bar {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    cursor: pointer;
}

.volume-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* === Mobile / Responsive Styles === */

/* Tablets & Mobile Landscape */
@media (max-width: 768px) {
    .controls {
        padding: 60px 16px 16px;
    }
    
    .video-title {
        font-size: 14px;
    }
    
    .control-btn {
        padding: 8px;
    }
}

/* Mobile Portrait */
@media (max-width: 600px) {
    .title-bar {
        padding: 12px 16px;
    }

    .bee-logo {
        display: none; /* Hide logo to save space */
    }

    .video-title {
        text-align: right;
        font-size: 14px;
    }

    .controls-left, .controls-right {
        gap: 6px; /* Tighter spacing */
    }

    .volume-bar {
        display: none; /* Hide volume slider on mobile, play/mute is enough */
    }
    
    .volume-container {
        gap: 0;
    }

    /* Make buttons slightly more compact but keep touch target */
    .control-btn {
        padding: 6px;
        min-width: 40px;
        min-height: 40px;
    }

    .skip-label {
        font-size: 9px;
        bottom: 8px;
    }
}

/* Landscape Mode on Mobile - Very constrained vertical space */
@media (max-height: 500px) and (orientation: landscape) {
    .title-bar {
        padding: 8px 16px;
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
    }
    
    .controls {
        padding: 40px 16px 10px;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    }
    
    .control-btn {
        min-height: 36px;
        min-width: 36px;
        padding: 4px;
    }
    
    .controls-top {
        margin-bottom: 4px;
    }
    
    /* Move progress bar to the very bottom edge ? Or keep standard?
       Let's keep standard but compact */
    
    .bee-logo {
        display: none;
    }
    
    .volume-bar {
        width: 60px;
    }
}
