body { 
    font-family: Arial, sans-serif; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding: 20px; 
    margin: 0;
}

.video-container {
    position: relative; /* Essential for overlay positioning */
    display: inline-block; /* Fit container to video size */
    overflow: hidden; /* Clip the scaled player */
}

/* Default player styling - will be overridden by JavaScript for fixed dimensions */
#player {
    display: block;
    /* Scale trick to force higher quality from YouTube */
    width: 200% !important;
    height: 200% !important;
    transform: scale(0.5);
    transform-origin: left top;
}

/* Responsive player styling - applied when width=responsive */
.video-container.responsive {
    width: 100vw;
    height: calc(100vw * 9 / 16); /* Set explicit height to match visible player size */
}

.video-container.responsive #player {
    /* Keep the 200% scaling trick for responsive too */
    width: 200vw !important;
    height: calc(200vw * 9 / 16) !important;
    transform: scale(0.5);
    transform-origin: left top;
}

/* Fixed width player styling - applied when width is a specific number */
.video-container.fixed-width {
    /* Container will size to fit the player */
}

.video-container.fixed-width #player {
    /* Dimensions will be set by JavaScript - no CSS overrides */
}

/* Overlay positioned on top of video at 50% down */
.video-overlay {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    z-index: 100;
    text-align: center;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px;
    transition: opacity 0.3s ease;
}

.video-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Default overlay styling for responsive videos */
.video-container.responsive .overlay-title {
    font-size: 2.5vw;
    font-weight: bold;
    margin-bottom: 20px;
    line-height: 1.2;
    word-wrap: break-word;
    hyphens: auto;
}

.video-container.responsive .overlay-buttons {
    display: flex;
    flex-direction: row;
    gap: 1.5vw;
    justify-content: center;
    align-items: center;
}

.video-container.responsive .overlay-button {
    padding: 0.8vw 1.5vw;
    background-color: #1D764C;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.5vw;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease;
    min-width: 10vw;
    white-space: nowrap;
    flex: 0 0 auto;
}

/* Fixed-width video overlay styling - uses CSS custom properties set by JavaScript */
.video-container.fixed-width .overlay-title {
    font-size: var(--title-size, 24px) !important;
    font-weight: bold;
    margin-bottom: 15px !important;
    line-height: 1.2;
    word-wrap: break-word;
    hyphens: auto;
}

.video-container.fixed-width .overlay-buttons {
    display: flex;
    flex-direction: row;
    gap: var(--button-gap, 15px) !important;
    justify-content: center;
    align-items: center;
}

.video-container.fixed-width .overlay-button {
    padding: var(--button-padding, 8px 16px) !important;
    background-color: #1D764C;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: var(--button-size, 16px) !important;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease;
    min-width: var(--button-min-width, 140px) !important;
    white-space: nowrap;
    flex: 0 0 auto;
}

/* Fallback for containers without specific class */
.overlay-title {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 15px;
    line-height: 1.2;
    word-wrap: break-word;
    hyphens: auto;
}

.overlay-buttons {
    display: flex;
    flex-direction: row;
    gap: 15px;
    justify-content: center;
    align-items: center;
}

.overlay-button {
    padding: 8px 16px;
    background-color: #1D764C;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease;
    min-width: 120px;
    white-space: nowrap;
    flex: 0 0 auto;
}

.overlay-button:hover {
    background-color: #155a39;
    transform: translateY(-2px);
}

.overlay-button:active {
    transform: translateY(0);
}

/* Responsive font sizing for different window sizes */
@media (max-width: 1200px) {
    .overlay-title {
        font-size: 28px;
    }
    
    .overlay-button {
        font-size: 16px;
        min-width: 140px;
        padding: 10px 20px;
    }
    
    .overlay-buttons {
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .overlay-title {
        font-size: 24px;
    }
    
    .overlay-button {
        font-size: 14px;
        min-width: 120px;
        padding: 8px 16px;
    }
    
    .overlay-buttons {
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .overlay-title {
        font-size: 20px;
    }
    
    .overlay-button {
        font-size: 12px;
        min-width: 100px;
        padding: 6px 12px;
    }
    
    .overlay-buttons {
        gap: 10px;
    }
}

/* For very large windows, cap the font sizes */
@media (min-width: 1920px) {
    .overlay-title {
        font-size: 58px; /* 3vw at 1920px */
    }
    
    .overlay-button {
        font-size: 38px; /* 2vw at 1920px */
        min-width: 230px; /* 12vw at 1920px */
        padding: 19px 38px; /* 1vw 2vw at 1920px */
    }
    
    .overlay-buttons {
        gap: 38px; /* 2vw at 1920px */
    }
}

/* Chapter menu styling */
.chapter-menu {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    width: fit-content;
    max-width: min(calc(100% - 160px), 90%); /* 160px min space for small screens, up to 90% for larger */
}

.chapter-menu.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Responsive chapter menu items - responsive below 800px, capped above */
.video-container.responsive .chapter-menu-item {
    font-size: min(1.5vw, 12px); /* Cap at 12px (size at 800px: 800 * 0.015 = 12px) */
    padding: min(0.4vw, 4.8px) min(0.8vw, 9.6px); /* Cap proportionally */
}

/* Fixed-width chapter menu items */
.video-container.fixed-width .chapter-menu-item {
    font-size: var(--button-size, 16px);
    padding: calc(var(--button-size, 16px) * 0.375) calc(var(--button-size, 16px) * 0.75);
}

/* Default chapter menu items */
.chapter-menu-item {
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s ease;
    flex-shrink: 1;
    min-width: fit-content;
}

.chapter-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.chapter-menu-item:active {
    transform: translateY(0);
}

.chapter-menu-item.active {
    background-color: rgba(29, 118, 76, 0.9);
    border-color: rgba(29, 118, 76, 1);
    font-weight: 600;
}

/* Responsive chapter menu sizing */
@media (max-width: 768px) {
    .chapter-menu {
        padding: 8px 12px;
        gap: 6px;
    }
}

@media (max-width: 480px) {
    .chapter-menu {
        padding: 6px 8px;
        gap: 4px;
    }
}
