:root {
    --color-primary: #1a1a1a;
    --color-secondary: #ffffff;
    --color-accent: #0066cc;
    --color-border: #e0e0e0;
    --color-error: #d32f2f;
    --color-text: #333333;
    --color-text-light: #666666;
    --color-control-bg: rgba(0, 0, 0, 0.7);
    --color-control-hover: rgba(255, 255, 255, 0.1);
    --color-progress: #0066cc;
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    --font-family-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.5rem;
    --font-size-xxl: 2rem;
    --line-height-tight: 1.2;
    --line-height-normal: 1.5;
    --transition-fast: 150ms ease-in-out;
    --transition-normal: 300ms ease-in-out;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--color-text);
    background-color: var(--color-secondary);
}

/* Accessibility - remove outline only when not needed */
*:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    line-height: var(--line-height-tight);
    font-weight: 600;
    margin-top: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

h1 {
    font-size: var(--font-size-xxl);
}

h2 {
    font-size: var(--font-size-xl);
}

p {
    margin-bottom: var(--spacing-sm);
}

/* Main container */
.lecture-container {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header styles */
.lecture-header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--color-border);
}

.lecture-label {
    font-size: var(--font-size-sm);
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--color-text-light);
    text-transform: uppercase;
    margin-bottom: var(--spacing-sm);
}

.lecture-title {
    font-size: var(--font-size-xxl);
    margin-bottom: var(--spacing-lg);
    color: var(--color-primary);
}

.lecture-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-lg);
    font-size: var(--font-size-sm);
}

.meta-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.meta-label {
    font-weight: 600;
    color: var(--color-text-light);
    margin-bottom: var(--spacing-xs);
}

.meta-value {
    color: var(--color-text);
}

/* Video section */
.video-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: var(--spacing-xl);
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: var(--color-primary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    /* No scaling, filtering, or image rendering that could reduce quality */
}

/* Loading state */
.loading-state {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-primary);
    color: var(--color-secondary);
    text-align: center;
    z-index: 10;
}

.loading-state p {
    font-size: var(--font-size-lg);
    margin: 0;
}

/* Error state */
.error-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--color-primary);
    color: var(--color-secondary);
    text-align: center;
    padding: var(--spacing-lg);
    z-index: 10;
}

.error-state p {
    font-size: var(--font-size-lg);
    margin-bottom: var(--spacing-lg);
    max-width: 400px;
}

/* Retry button */
.retry-button {
    padding: var(--spacing-sm) var(--spacing-md);
    background-color: var(--color-accent);
    color: var(--color-secondary);
    border: none;
    border-radius: 4px;
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.retry-button:hover {
    background-color: #0052a3;
}

.retry-button:active {
    transform: scale(0.98);
}

/* Player wrapper - NO SCALING, FILTERS, or TRANSFORMS */
#player-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    /* No transform, filter, or opacity - these degrade video quality */
}

.youtube-player-container {
    position: relative;
    width: 100%;
    height: 100%;
    /* Native rendering - no CSS effects */
}

#youtube-player {
    width: 100%;
    height: 100%;
    /* Container fills parent, iframe fills this */
}

#youtube-player iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    /* Ensure no scaling filters or transforms are applied */
}

/* Top Interaction Shield & Visual Mask over native YouTube title/channel area */
.youtube-top-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.8) 50%, rgba(0, 0, 0, 0.3) 100%);
    z-index: 15;
    pointer-events: none;
}

/* Click Shield - intercepts all pointer events on the top area */
.youtube-top-click-shield {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    z-index: 18;
    pointer-events: auto;
    cursor: default;
    background: transparent;
}

/* Prevent any interaction with the shield area */
.youtube-top-click-shield,
.youtube-top-click-shield * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Custom Controls Overlay */
.player-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    padding: var(--spacing-xl) var(--spacing-md) var(--spacing-md);
    z-index: 20;
    transition: opacity var(--transition-normal);
}

/* Progress Bar Container */
.progress-bar-container {
    width: 100%;
    margin-bottom: var(--spacing-md);
}

.progress-bar {
    position: relative;
    width: 100%;
    height: 4px;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    cursor: pointer;
    transition: height var(--transition-fast);
}

.progress-bar:hover {
    height: 6px;
}

.progress-bar:hover .progress-handle {
    opacity: 1;
    transform: scale(1);
}

.progress-fill {
    height: 100%;
    background-color: var(--color-progress);
    border-radius: 2px;
    transition: width 0.05s linear;
}

.progress-handle {
    position: absolute;
    top: 50%;
    width: 12px;
    height: 12px;
    background-color: var(--color-secondary);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Controls Bottom Row */
.controls-bottom {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

/* Time Display */
.time-display {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    color: var(--color-secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    white-space: nowrap;
    min-width: 80px;
}

.time-separator {
    opacity: 0.7;
}

/* Main Controls Group */
.main-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex: 1;
    min-width: 0;
}

/* Control Button Styles */
.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    min-width: 40px;
    height: 40px;
    padding: 0 var(--spacing-sm);
    background-color: transparent;
    color: var(--color-secondary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.control-btn:hover {
    background-color: var(--color-control-hover);
}

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

.control-btn svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.control-label {
    display: none;
    white-space: nowrap;
}

/* Play/Pause Button - Larger */
.play-pause-btn {
    min-width: 48px;
    width: 48px;
    height: 48px;
    background-color: rgba(255, 255, 255, 0.15);
    border: 2px solid var(--color-secondary);
}

.play-pause-btn:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

.play-pause-btn svg {
    width: 28px;
    height: 28px;
}

/* Volume Control */
.volume-control {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex-shrink: 0;
}

.mute-btn {
    flex-shrink: 0;
}

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

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background-color: var(--color-secondary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background-color: var(--color-secondary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.volume-slider::-moz-range-track {
    background: transparent;
    border: none;
}

/* Speed Control */
.speed-control {
    flex-shrink: 0;
}

.speed-selector {
    padding: var(--spacing-xs) var(--spacing-sm);
    background-color: transparent;
    color: var(--color-secondary);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.speed-selector:hover {
    border-color: var(--color-secondary);
}

.speed-selector option {
    background-color: var(--color-primary);
    color: var(--color-secondary);
}

/* Captions Button */
.captions-btn {
    flex-shrink: 0;
}

.captions-btn.active {
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid var(--color-secondary);
}

/* Fullscreen Button */
.fullscreen-btn {
    flex-shrink: 0;
}

/* Footer */
.lecture-footer {
    text-align: center;
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--color-border);
    color: var(--color-text-light);
    font-size: var(--font-size-sm);
}

.lecture-footer p {
    margin: 0;
}

/* Fullscreen Styles */
#player-wrapper:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
}

#player-wrapper:-moz-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
}

#player-wrapper:fullscreen {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
}

/* Responsive Design - Tablet */
@media (max-width: 768px) {
    .lecture-container {
        padding: var(--spacing-md);
    }

    .lecture-header {
        margin-bottom: var(--spacing-lg);
        padding-bottom: var(--spacing-md);
    }

    .lecture-title {
        font-size: var(--font-size-xl);
    }

    .lecture-meta {
        flex-direction: column;
        gap: var(--spacing-md);
    }

    .meta-item {
        flex-direction: row;
        justify-content: center;
        gap: var(--spacing-xs);
    }

    .control-btn {
        min-width: 36px;
        height: 36px;
        padding: 0 var(--spacing-xs);
    }

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

    .play-pause-btn {
        min-width: 44px;
        width: 44px;
        height: 44px;
    }

    .play-pause-btn svg {
        width: 24px;
        height: 24px;
    }

    .volume-slider {
        width: 60px;
    }

    .controls-bottom {
        gap: var(--spacing-sm);
    }

    .player-controls {
        padding: var(--spacing-lg) var(--spacing-sm) var(--spacing-sm);
    }
}

/* Responsive Design - Mobile */
@media (max-width: 480px) {
    .lecture-container {
        padding: var(--spacing-sm);
    }

    .lecture-label {
        font-size: var(--font-size-sm);
    }

    .lecture-title {
        font-size: var(--font-size-lg);
        margin-bottom: var(--spacing-md);
    }

    .lecture-meta {
        gap: var(--spacing-sm);
    }

    .meta-item {
        flex-direction: column;
    }

    .video-container {
        aspect-ratio: 16 / 9;
    }

    /* Mobile controls - prioritize essential buttons */
    .main-controls {
        gap: var(--spacing-xs);
    }

    .control-btn {
        min-width: 40px;
        height: 40px;
        padding: 0;
    }

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

    .control-label {
        display: none;
    }

    .play-pause-btn {
        min-width: 44px;
        width: 44px;
        height: 44px;
        border-width: 2px;
    }

    .play-pause-btn svg {
        width: 24px;
        height: 24px;
    }

    /* Hide time display on very small screens if needed */
    @media (max-width: 360px) {
        .time-display {
            font-size: var(--font-size-sm);
            min-width: 70px;
        }
    }

    /* Stack controls differently on mobile */
    .controls-bottom {
        flex-direction: column;
        gap: var(--spacing-xs);
    }

    .time-display {
        width: 100%;
        justify-content: center;
        margin-bottom: var(--spacing-xs);
    }

    .main-controls {
        width: 100%;
        justify-content: center;
    }

    .volume-control {
        width: 100%;
        justify-content: center;
        gap: var(--spacing-xs);
    }

    .volume-slider {
        width: 100px;
    }

    .speed-control {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .speed-selector {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-sm);
    }

    .player-controls {
        padding: var(--spacing-md) var(--spacing-sm) var(--spacing-sm);
    }
}

/* Print styles */
@media print {
    .video-section {
        display: none;
    }

    .lecture-container {
        padding: 0;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --color-secondary: #1a1a1a;
        --color-primary: #ffffff;
        --color-border: #333333;
        --color-text: #e0e0e0;
        --color-text-light: #999999;
    }

    body {
        background-color: var(--color-secondary);
    }

    .speed-selector option {
        background-color: #2a2a2a;
    }
}

/* Hover states for better UX */
@media (hover: hover) and (pointer: fine) {
    .control-btn:hover {
        background-color: var(--color-control-hover);
    }

    .progress-bar:hover {
        height: 6px;
    }

    .progress-bar:hover .progress-handle {
        opacity: 1;
        transform: scale(1);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .control-btn {
        min-width: 44px;
        height: 44px;
    }

    .play-pause-btn {
        min-width: 48px;
        width: 48px;
        height: 48px;
    }

    .progress-handle {
        width: 16px;
        height: 16px;
    }
}
