body {
    font-family: sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #1e1e1e;
    color: white;
    box-sizing: border-box;
    padding-bottom: 20px;
}

html {
    overflow-y: scroll;
}

*, *::before, *::after {
    box-sizing: inherit;
}

h1 {
    text-align: center;
    color: #e0e0e0;
}
#currentCategoryTitle {
    color: #ccc;
    margin-top: 10px;
    margin-bottom: 20px;
    text-align: center;
}

.back {
    margin: 10px 0 20px 10px;
    display: none;
    cursor: pointer;
    color: #ff6666;
    font-size: 1.1em;
    width: fit-content;
}
.back:hover {
    color: #ff8888;
}

.clip-grid {
    display: none;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    padding: 0 10px;
}

.category-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin: 0 auto 30px auto;
    padding: 0 10px;
    width: 100%;
}

.clip-card {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #2a2a2a;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transition: transform 0.2s ease-out, background-color 0.2s ease;
    flex-grow: 1;
    overflow: hidden;
}

.clip-card:hover {
    background-color: #3a3a3a;
    transform: translateY(-5px);
}

.clip-card .clip-thumbnail-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9; /* Replaces fixed height and enforces 16:9 */
    background-color: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden; /* Ensures content respects the wrapper's border radius */
    border-top-left-radius: 12px; /* Moved from child to wrapper */
    border-top-right-radius: 12px; /* Moved from child to wrapper */
}

.clip-card video,
.clip-card .clip-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Ensures the image covers the 16:9 area, cropping if necessary */
    display: block;
    /* border-top-left-radius and border-top-right-radius removed from here */
}

.clip-card video {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.clip-title-container {
    padding: 12px 10px;
    width: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 58px; /* Give a consistent height */
}

.clip-title-group {
    text-align: center;
}

.clip-title {
    color: #e0e0e0;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px; /* Adjust as needed */
    display: block;
    margin: 0 auto;
}

.clip-date {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    color: #ccc;
    white-space: nowrap;
}

.clip-codec-badge {
    display: inline-block;
    margin-top: 4px;
    background-color: #007bff; /* Default blue for H.264 */
    color: white;
    padding: 2px 6px;
    font-size: 0.7em;
    border-radius: 4px;
}

.clip-codec-badge.hevc {
    background-color: #28a745; /* Green */
}

.clip-codec-badge.av1 {
    background-color: #dc3545; /* Red */
}

.clip-codec-badge.unknown {
    background-color: #6c757d;
}

.clip-overlay {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100vw;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.clip-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.overlay-background {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}

.clip-expanded {
    position: relative;
    background: #111;
    z-index: 9999;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.clip-expanded video {
    display: block;
    width: 100%;
    height: auto;
    max-width: calc(95vw - 30px);
    max-height: calc(95vh - 60px);
    border-radius: 8px;
}

.overlay-close {
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 28px;
    color: white;
    background-color: rgba(0,0,0,0.7);
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000;
    transition: background-color 0.2s ease;
}
.overlay-close:hover {
    background-color: #ff6666;
}

.video-status-badge {
    margin-top: 10px;
    padding: 5px 10px;
    background-color: rgba(0,0,0,0.5);
    color: #ddd;
    font-size: 0.8em;
    border-radius: 5px;
    text-align: center;
}

.category-card {
    background-color: #2a2a2a;
    color: white;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    min-height: 120px;
    overflow: hidden;
}

.category-card:hover {
    background-color: #3a3a3a;
    transform: translateY(-5px);
}

.category-icon {
    font-size: 3em;
    margin-bottom: 15px;
    color: #ffcc66;
}
.category-label {
    font-size: 1.1em;
    font-weight: bold;
    color: #e0e0e0;
}

.clip-tags {
    font-size: 0.85em;
    color: #ccc;
    margin-top: 4px;
}

.tag-badge-container {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-badge {
    background-color: #444;
    color: white;
    padding: 4px 10px;
    font-size: 0.8em;
    border-radius: 12px;
    border: 1px solid #666;
    white-space: nowrap;
}

.top-nav-container {
    display: none;
    align-items: center;
    gap: 15px;
    margin: 10px 0 20px 10px;
}

.nav-button {
    background-color: #333;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease;
    display: inline-block;
    text-align: center;
}

.nav-button:hover {
    background-color: #444;
    color: white;
}

.back.nav-button {
    margin: 0;
    font-size: 0.9em;
    width: auto;
    color: #e0e0e0;
}
.back.nav-button:hover {
    color: white;
}

.clip-rating-container {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 5px;
}

.clip-rating-label {
    font-size: 0.8em;
    color: #a0a0a0;
}

.clip-rating-bar-wrapper {
    width: 12px;
    height: 28px;
    background-color: #444;
    border-radius: 2px;
    overflow: hidden;
    display: flex;
    flex-direction: column-reverse;
}

.clip-rating-bar {
    width: 100%;
    transition: height 0.3s ease, background-color 0.3s ease;
}

.sort-controls {
    display: flex;
}

/* Base styles for category cards, adjusted for small screens */
@media (max-width: 699px) {
    .category-card {
        flex-basis: 100%;
        max-width: 450px;
        margin-left: auto;
        margin-right: auto;
        flex-grow: 0;
        min-width: auto;
    }
    .category-grid {
        padding: 0 5px;
    }
}

/* Styles for clip cards on small screens */
@media (max-width: 699px) {
    .clip-card {
        flex-basis: 100%;
        max-width: 400px;
        margin-left: auto;
        margin-right: auto;
    }
    .clip-grid {
        padding: 0 5px;
    }
}

/* Media query for category cards: 700px to 999px */
@media (min-width: 700px) and (max-width: 999px) {
    .category-card {
        flex-basis: calc( (100% - 20px - 2px) / 2 ); /* 20px gap, 2px for potential border/outline */
        max-width: none;
        flex-grow: 1;
    }
}

/* Media query for clip cards: 700px to 999px */
@media (min-width: 700px) and (max-width: 999px) {
    .clip-card {
        flex-basis: calc(50% - 8px); /* Account for gap */
        max-width: calc(50% - 8px);
    }
}

/* Media query for category cards: 1000px to 1219px */
@media (min-width: 1000px) and (max-width: 1219px) {
    .category-card {
        flex-basis: calc( (100% - 40px - 3px) / 3 ); /* 20px gap between each, 3 cards, total 40px gap + 3px for borders */
        max-width: none;
        flex-grow: 0;
    }
    .category-grid {
        padding: 0 10px;
    }
}

/* Media query for clip cards: 1000px to 1199px */
@media (min-width: 1000px) and (max-width: 1199px) {
    .clip-card {
        flex-basis: calc(33.333% - 10.67px); /* Account for gap */
        max-width: calc(33.333% - 10.67px);
    }
}

/* Media query for category cards: 1220px and up */
@media (min-width: 1220px) {
    body {
        overflow-y: auto;
        padding-bottom: 20px;
    }
    html {
        overflow-y: auto;
    }
    .category-grid {
        flex-wrap: nowrap;
        overflow-x: hidden; /* To prevent horizontal scroll if not needed */
        justify-content: flex-start;
        padding-left: 20px;
        padding-right: 20px;
    }
    .category-card {
        flex-grow: 1;
        flex-basis: 0;
        width: auto;
        max-width: none;
    }
}

/* Media query for clip cards: 1200px and up */
@media (min-width: 1200px) {
    .clip-card {
        flex-basis: calc(25% - 12px); /* Account for gap */
        max-width: calc(25% - 12px);
    }
}

/* Added a more specific media query for smaller screens based on old CSS */
@media (max-width: 380px) {
    body {
        padding: 10px;
    }
    .category-grid {
        padding: 0 5px;
    }
}