* {
    margin: 0;
    padding: 0;
    /* This is great for layout consistency */
    box-sizing: border-box;
}

body {
    /* A more modern, lighter, and playful gradient */
    background: linear-gradient(135deg, #be80fa 0%, #50a4f8 100%);
    min-height: 100vh;
    color: #333;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    user-select: none;
}

a {
    text-decoration: none;
    color: inherit;
}

.header {
    padding-left: 20px;
    padding-right: 20px;
    padding-top: 25px;
    padding-bottom: 0px;
    text-align: center;
    /* For positioning the logout link */
    position: relative;
}

.header h1 {
    color: #fff;
    font-size: 2.5em;
    font-weight: 700;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.header h1 a {
    color: #fff;
}

.header p {
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 15px;
}

.header h2 a {
    color: #fff;
    font-weight: 500;
}

.header-nav {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.logout-link,
.about-link,
.profile-link {
    position: absolute;
    top: 25px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
    transition: color 0.2s;
}

.logout-link {
    right: 100px;
}

.about-link {
    right: 25px;
}

.profile-link {
    right: 180px;
}

.logout-link:hover,
.about-link:hover {
    color: #fff;
}

.login-link {
    position: absolute;
    top: 25px;
    left: 25px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
    transition: color 0.2s;
    max-width: 100px;
}

.login-link:hover {
    color: #fff;
}

.panel {
    background: rgba(255, 255, 255, 0.6);
    margin: 20px;
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    /* Frosted glass effect */
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.panel h2 {
    color: #555;
    margin-bottom: 20px;
}

.channel-form {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.channel-form input,
.channel-form select {
    flex: 1;
    padding: 14px;
    border: 2px solid #ddd;
    border-radius: 12px;
    font-size: 16px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.channel-form input {
    min-width: 200px;
}

.channel-form select {
    max-width: 140px;
    min-width: 140px;
}

.channel-form input:focus,
.channel-form select:focus {
    outline: none;
    border-color: #8ec5fc;
    box-shadow: 0 0 0 3px rgba(142, 197, 252, 0.4);
}

.channel-form button {
    padding: 12px 24px;
    background-image: linear-gradient(to right, #ff758c 0%, #ff7eb3 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s ease;
    /* Prevent buttons from shrinking on smaller screens */
    flex-shrink: 0;
}

.channel-form button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 126, 179, 0.4);
}

.approved-channels {
    margin-bottom: 30px;
}

.channel-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

/* Keep playlist cards a bit larger */
#playlistList.channel-list {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.channel-card {
    background: white;
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.channel-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.playlist-channel-title {
    font-size: 13px;
    color: #888;
    margin-bottom: 10px;
}

.channel-card h3 {
    color: #333;
    margin-bottom: 10px;
}

.channel-card .description {
    color: #666;
    font-size: 14px;
    margin-bottom: 15px;
}

#playlistList .description {
    margin-top: 5px;
}

.channel-card .stats {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #999;
}

.channel-btn {
    background: #eee;
    color: #555;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}

.channel-btn.remove-btn {
    background-color: #ffebee;
    color: #d32f2f;
}

.channel-btn:hover {
    background: #ddd;
}

.channel-btn.remove-btn:hover {
    background-color: #ffcdd2;
    color: white;
}

.videos-section {
    margin-top: 30px;
}

.videos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.video-card {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.video-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.video-thumbnail {
    position: relative;
}

.watched-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s ease;
    /* Don't interfere with clicks */
    pointer-events: none;
}

.video-card.watched .watched-indicator {
    opacity: 1;
}

.video-card.watched .video-thumbnail img {
    opacity: 0.7;
}

.video-info {
    padding: 15px;
}

.video-info h4 {
    color: #333;
    margin-bottom: 8px;
    font-size: 16px;
}

.video-info .row {
    display: flow-root;
}

.video-info .channel-name {
    color: #888;
    font-size: 14px;
    margin-bottom: 8px;
    float: left;
}

.video-info .duration {
    color: #999;
    font-size: 12px;
    float: right;
}

.video-info .publish-date {
    color: #999;
    font-size: 12px;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #666;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 30px;
    color: #fff;
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.pagination button {
    padding: 10px 20px;
    background-color: rgba(255, 255, 255, 0.8);
    color: #555;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.pagination button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.12);
    background-color: #fff;
}

.pagination button:disabled {
    background-color: rgba(255, 255, 255, 0.4);
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 2em;
    }

    .channel-form {
        flex-direction: column;
    }

    .channel-form input {
        min-width: auto;
    }
}

/* Modal Styles */
.modal {
    /* Hidden by default */
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    /* Darker background */
    background-color: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
}

.active-player-container {
    /* This class is added to #playerContainer to center it when active */
    position: relative;
    width: 100vw;
    background-color: #000;
    /* For pillar/letterboxing on non-16:9 screens */
    display: flex;
    justify-content: center;
    align-items: center;
}

#player {
    width: 100%;
    /* Ensure it doesn't get wider than the screen is tall */
    max-width: calc(100vh * 16 / 9);
    aspect-ratio: 16 / 9;
}

/* New Overlay and Big Close Button Styles */
#playerOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Invisible overlay */
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1100;
}

#bigCloseButton,
#playPauseButton,
#fullscreenButton {
    position: absolute;
    font-size: 40px;
    color: white;
    background-color: rgba(0, 0, 0, 0.6);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    /* Hidden by default */
    opacity: 0;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    /* Not clickable when hidden */
    pointer-events: none;
    user-select: none;
    backdrop-filter: blur(5px);
}

#playPauseButton {
    /* Position it to the left of the close button */
    transform: translateX(-60px);
}

#fullscreenButton {
    right: 40px;
    top: 40px;
    transform: none;
}

#playPauseButton.visible,
#fullscreenButton.visible,
#lastVideoButton.visible {
    opacity: 1;
    pointer-events: auto;
    /* Clickable when visible */
}

#bigCloseButton.visible {
    opacity: 1;
    pointer-events: auto;
}

#bigCloseButton {
    transform: translateX(60px);
}

/* Video Info in Overlay */
#videoInfoOverlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 80px;
    color: white;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent);
    padding: 20px;
    padding-bottom: 40px;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

#videoInfoOverlay.visible {
    opacity: 1;
}

#videoChannelOverlay {
    color: #ddd;
}

/* "Last Video" Button */
#lastVideoButton {
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px;
    color: white;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease-in-out, background-color 0.3s;
    pointer-events: none;
    user-select: none;
    backdrop-filter: blur(5px);
}

#lastVideoButton.activated {
    color: gray;
}

/* Overlay to hide YouTube's suggestions on pause */
#pauseOverlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    /* Use percentage to cover recommendations on all screen sizes */
    height: 35%;
    background-color: #000;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    pointer-events: none;
}

#playerOverlay.paused #pauseOverlay {
    opacity: 1;
}

#videoTimeDisplay {
    position: absolute;
    bottom: 40px;
    right: 20px;
    font-size: 18px;
    color: white;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 5px 10px;
    border-radius: 5px;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
}

#videoTimeDisplay.visible {
    opacity: 1;
}

#progressBarContainer {
    position: absolute;
    bottom: 20px;
    left: 5%;
    right: 5%;
    height: 10px;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
}

#progressBarContainer.visible {
    opacity: 1;
    pointer-events: auto;
}

#progressBar {
    height: 100%;
    width: 0;
    background-color: #ff758c;
    border-radius: 10px;
}

.video-thumbnail-16-9 {
    position: relative;
    width: 100%;
    /* 16:9 Aspect Ratio (9 / 16 = 0.5625) */
    padding-top: 56.25%;
    /* Black background for letterboxing */
    background-color: #000;
    cursor: pointer;
}

.video-thumbnail-16-9 img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* New styles for channel card thumbnails */
.channel-thumbnail-1-1 {
    position: relative;
    width: 100%;
    /* 1:1 Aspect Ratio */
    padding-top: 100%;
    background-color: #eee;
    cursor: pointer;
    border-radius: 10px;
    /* Rounded corners for the image container */
    overflow: hidden;
    /* Ensures the img respects the border-radius */
}

.channel-thumbnail-1-1 img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Cover the area, cropping if necessary */
}

/* --- Login/Register Form Styles --- */
.login-panel {
    max-width: 400px;
    margin: 50px auto;
    text-align: center;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.auth-form input {
    padding: 14px;
    border: 2px solid #ddd;
    border-radius: 12px;
    font-size: 16px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.auth-form input:focus {
    outline: none;
    border-color: #8ec5fc;
    box-shadow: 0 0 0 3px rgba(142, 197, 252, 0.4);
}

.auth-form button {
    padding: 12px 24px;
    background-image: linear-gradient(to right, #ff758c 0%, #ff7eb3 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.auth-form button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 126, 179, 0.4);
}

.message {
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-weight: bold;
}

#errorMessage {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 90%;
    max-width: 500px;
}

.toast-message {
    padding: 15px 20px;
    border-radius: 12px;
    font-weight: 500;
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.message.error {
    background-color: #ffebee;
    color: #d32f2f;
    border: 1px solid #d32f2f;
}

.message.success {
    background-color: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #2e7d32;
}

.toast-message.error {
    background-color: #d32f2f;
}

.toast-message.success {
    background-color: #2e7d32;
}

.toast-message.visible {
    opacity: 1;
    transform: translateY(0);
}

.login-panel p {
    margin-top: 20px;
    color: #666;
}

.login-panel p a {
    color: #8ec5fc;
    font-weight: bold;
}

/* --- About Page Styles --- */
.about-panel {
    max-width: 800px;
    margin: 20px auto;
    line-height: 1.6;
}

.about-panel h2 {
    text-align: center;
    color: #333;
    margin-bottom: 25px;
}

.about-panel h3 {
    color: #444;
    margin-top: 30px;
    margin-bottom: 15px;
    border-bottom: 2px solid #eee;
    padding-bottom: 5px;
}

.about-panel ul {
    list-style-position: inside;
    padding-left: 10px;
    color: #555;
}

/* --- Profile Page Styles --- */
.profile-panel {
    max-width: 400px;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}

.profile-panel #updatePasswordForm {
    margin-top: 30px;
}

.profile-panel .delete-account-section {
    margin-top: 30px;
    border-top: 1px solid #ddd;
    padding-top: 20px;
}

.profile-panel .delete-account-section .remove-btn {
    background: #d32f2f;
    color: white;
}

.profile-panel .delete-account-section .remove-btn:hover {
    /* A darker red for hover */
    background: #b71c1c;
    color: white;
}