* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1db954, #191414);
    min-height: 100vh;
    color: white;
    overflow-x: hidden;
    position: relative;
    transition: all 0.8s ease;
}

body::before {
    content: '';
    position: fixed;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(40px) brightness(0.3);
    opacity: 0;
    z-index: -2;
    transition: opacity 0.6s ease;
}

body.fading-bg::before {
    opacity: 0 !important;
}

body.has-cover::before {
    opacity: 1;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(29, 185, 84, 0.4), rgba(25, 20, 20, 0.6));
    z-index: -1;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    overflow-x: hidden;
    /* Prevent horizontal overflow */
    width: 100%;
    /* Ensure proper width calculation */
    box-sizing: border-box;
    /* Include padding in width */
}

.section {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* New sidebar layout */
.main-layout {
    display: flex;
    gap: 30px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-height: 600px;
    overflow: hidden;
    /* Prevent layout overflow */
    width: 100%;
    /* Ensure it doesn't exceed container */
    box-sizing: border-box;
    /* Include padding in width calculation */
}

.sidebar {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.track-cover {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
}

.track-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.5s ease;
}

.track-cover.fading img {
    opacity: 0;
}

.track-info {
    text-align: center;
}

.track-info h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
    line-height: 1.3;
    transition: opacity 0.3s ease;
}

.track-info.paused h2 {
    opacity: 0.7;
    position: relative;
}

.track-info p {
    opacity: 0.8;
    margin-bottom: 4px;
}

.media-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 20px 0;
}

.media-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
}

.media-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #1db954;
    transform: scale(1.1);
}

.media-btn.play-pause {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    background: #1db954;
    border-color: #1db954;
}

.media-btn.play-pause:hover {
    background: #1ed760;
    transform: scale(1.15);
}

.media-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.platform-section {
    margin-top: auto;
}

.progress-section {
    margin: 20px 0;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
    cursor: pointer;
    transition: height 0.2s ease;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1db954, #1ed760);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

.progress-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    opacity: 0.8;
    font-weight: 500;
}

.sidebar-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.sidebar-controls button {
    flex: 1;
    min-width: 120px;
}

.auto-refresh-toggle {
    margin-top: 15px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 12px;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-label input:checked+.toggle-slider {
    background: #1db954;
}

.toggle-label input:checked+.toggle-slider::before {
    transform: translateX(20px);
}

.toggle-text {
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.9;
}

.toggle-label:hover .toggle-text {
    opacity: 1;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 30px;
    min-width: 0;
    /* Allows flex item to shrink below content size */
    overflow: hidden;
    /* Prevents overflow */
}

.youtube-videos-section h3 {
    margin-bottom: 20px;
    color: #ff0000;
}

.comments-section {
    flex: 1;
}

.comments-container {
    margin: 0 auto;
}



.hidden {
    display: none;
}

.btn-primary,
.btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.btn-primary {
    background: #1db954;
    color: white;
}

.btn-primary:hover {
    background: #1ed760;
    transform: translateY(-2px);
}

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

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



.track-card {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
}

#track-info {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

#track-image {
    width: 300px;
    height: 300px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
}

#track-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
}

#track-details h2 {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

#track-details p {
    opacity: 0.8;
    margin-bottom: 4px;
}

#external-links {
    margin: 20px 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

#external-links h4 {
    margin-bottom: 15px;
    color: #1db954;
    font-size: 1.1rem;
}

#platform-links {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.platform-link {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    text-decoration: none;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    justify-content: center;
}

.platform-link:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    border-color: #1db954;
}

#youtube-section {
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

#youtube-section h3 {
    color: #ff0000;
    margin-bottom: 15px;
}

#youtube-videos-container {
    margin-bottom: 20px;
    overflow: hidden;
    /* Prevent container overflow */
}

#youtube-videos {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    padding: 10px 0;
    scroll-behavior: smooth;
    width: 100%;
    /* Ensure it doesn't exceed container */
}

#youtube-videos::-webkit-scrollbar {
    height: 6px;
}

#youtube-videos::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

#youtube-videos::-webkit-scrollbar-thumb {
    background: #ff0000;
    border-radius: 3px;
}

.youtube-video-item {
    flex: 0 0 280px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    overflow: hidden;
    max-width: 280px;
    /* Prevent expansion */
}

.youtube-video-item:hover {
    transform: translateY(-2px);
    border-color: #ff0000;
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.2);
}

.youtube-video-item.selected {
    border-color: #ff0000;
    background: rgba(255, 0, 0, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.3);
}

.video-thumbnail-container {
    position: relative;
    width: 100%;
}

.video-thumbnail {
    width: 100%;
    height: 160px;
    object-fit: cover;
}

.comment-count-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.video-details {
    padding: 12px;
}

.video-details h4 {
    margin-bottom: 8px;
    font-size: 0.9rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-bottom: 10px;
}

.video-actions {
    display: flex;
    gap: 8px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.75rem;
    border-radius: 15px;
    flex: 1;
    text-align: center;
}

.comments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.comments-header h4 {
    margin: 0;
}

#selected-video-title {
    font-size: 0.85rem;
    opacity: 0.8;
    max-width: 60%;
    text-align: right;
}

#youtube-comments {
    overflow-y: auto;
    padding-right: 10px;
}

#youtube-comments::-webkit-scrollbar {
    width: 6px;
}

#youtube-comments::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

#youtube-comments::-webkit-scrollbar-thumb {
    background: #ff0000;
    border-radius: 3px;
}

.youtube-comment {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    transition: background 0.2s ease;
}

.youtube-comment:hover {
    background: rgba(0, 0, 0, 0.3);
}

.youtube-comment .comment-author {
    font-weight: bold;
    color: #ffffff57;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.youtube-comment .comment-text {
    margin-bottom: 8px;
    line-height: 1.4;
    font-size: 0.9rem;
}

.youtube-comment .comment-meta {
    font-size: 0.75rem;
    opacity: 0.6;
    display: flex;
    align-items: center;
    gap: 8px;
}

.load-more-btn {
    width: 100%;
    margin-top: 20px;
    padding: 12px 24px;
    background: rgba(255, 0, 0, 0.1);
    border: 1px solid rgba(255, 0, 0, 0.3);
    color: #ff0000;
    font-weight: 600;
    transition: all 0.3s ease;
}

.load-more-btn:hover {
    background: rgba(255, 0, 0, 0.2);
    border-color: #ff0000;
    transform: translateY(-1px);
}

.load-more-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.quota-exceeded {
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
}

.quota-exceeded h4 {
    color: #ffc107;
    margin-bottom: 10px;
}

.quota-exceeded ul {
    text-align: left;
    margin: 10px 0;
    padding-left: 20px;
}

.quota-exceeded li {
    margin-bottom: 5px;
}

.platform-icon {
    margin-right: 8px;
    font-size: 1.1rem;
}

/* Phosphor Icons styling */
.ph {
    display: inline-block;
    vertical-align: middle;
}

#track-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

#social-section h3 {
    margin-bottom: 20px;
    color: #1db954;
}

#comments-container {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    min-height: 100px;
}



.placeholder {
    text-align: center;
    opacity: 0.6;
    font-style: italic;
}



.status {
    text-align: center;
    padding: 10px;
    border-radius: 8px;
    margin-top: 20px;
}

.status.success {
    background: rgba(29, 185, 84, 0.2);
    border: 1px solid #1db954;
}

.status.error {
    background: rgba(226, 33, 52, 0.2);
    border: 1px solid #e22134;
}

.more-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
}

.more-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}



.pull-refresh {
    position: fixed;
    top: 0;
    left: 50%;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-left: -18px;
    border-radius: 50%;
    background: rgba(34, 34, 34, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    color: rgba(255, 255, 255, 0.7);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.pull-refresh.visible {
    opacity: 1;
}

.pull-refresh.ready {
    color: #1db954;
}

.pull-refresh.spinning i {
    animation: pull-spin 0.8s linear infinite;
}

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

/* ---------------------------------------------------------------
   KEEP THIS BLOCK LAST. Media queries add no specificity, so any
   rule declared after it wins at equal specificity and silently
   overrides the mobile layout.

   Mobile: the player collapses to a sticky bar so the comments,
   which are the point of the app, start at the top of the page.
   One breakpoint on purpose - the old 1024/768/600 stack re-tuned
   the same elements three times and fought itself.
   --------------------------------------------------------------- */
@media (max-width: 900px) {
    .container {
        /* clear the floating bar, its bottom margin and the home indicator */
        padding: 0 0 calc(84px + env(safe-area-inset-bottom));
    }

    .main-layout {
        flex-direction: column;
        gap: 0;
        padding: 0;
        margin-bottom: 0;
        background: none;
        border: none;
        border-radius: 0;
        overflow: visible;
        /* blurring a full-page scrolling container costs real frames */
        backdrop-filter: none;
    }

    /* ---- sticky now-playing bar ---- */
    /* fixed, not sticky: the sidebar comes first in the DOM, so a
       sticky bottom offset would leave its footprint at the top.
       Floats clear of the edges so content stays visible around it. */
    .sidebar {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(8px + env(safe-area-inset-bottom));
        z-index: 20;
        flex: none;
        max-width: none;
        display: grid;
        grid-template-columns: 40px minmax(0, 1fr) auto auto;
        grid-template-areas: "art info controls more";
        align-items: center;
        gap: 10px;
        padding: 4px 10px 8px;
        background: rgba(34, 34, 34, 0.97);
        backdrop-filter: blur(12px);
        border: none;
        border-radius: 14px;
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    }

    /* :not(.hidden) so the JS toggle still wins - .hidden is declared
       after the media queries with no !important */
    /* inset along the bottom edge so it clears the rounded corners */
    .progress-section:not(.hidden) {
        position: absolute;
        top: auto;
        bottom: 4px;
        left: 12px;
        right: 12px;
        display: block;
    }

    .progress-bar {
        height: 3px;
        margin: 0;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.16);
        cursor: default;
    }

    /* the hairline carries the position; the timestamps cost a whole row */
    .progress-time {
        display: none;
    }

    .track-cover {
        grid-area: art;
        width: 40px;
        height: 40px;
        max-width: none;
        margin: 0;
    }

    #track-image {
        border-radius: 6px;
    }

    .track-info {
        grid-area: info;
        min-width: 0;
        text-align: left;
    }

    .track-info h2 {
        font-size: 0.85rem;
        line-height: 1.25;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #track-artist {
        font-size: 0.72rem;
        line-height: 1.25;
        margin: 0;
        opacity: 0.8;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #track-album {
        display: none;
    }

    .media-controls:not(.hidden) {
        grid-area: controls;
        display: flex;
        gap: 2px;
    }

    .media-btn {
        width: 34px;
        height: 34px;
        padding: 0;
        font-size: 1rem;
    }

    .media-btn.play-pause {
        width: 38px;
        height: 38px;
    }

    /* skip-back is the least used control and the bar is tight */
    #prev-btn {
        display: none;
    }

    .more-btn {
        grid-area: more;
        display: inline-flex;
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }

    /* ---- chrome, revealed by the more button ---- */
    .mobile-collapsible {
        display: none;
    }

    body.more-open .mobile-collapsible:not(.hidden) {
        display: block;
    }

    body.more-open .sidebar-controls.mobile-collapsible {
        display: flex;
        justify-content: center;
    }

    body.more-open .sidebar > .mobile-collapsible {
        grid-column: 1 / -1;
    }

    #platform-links {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .platform-link {
        padding: 8px;
        font-size: 0.75rem;
    }

    /* ---- comments become the page body, full bleed ---- */
    .main-content {
        gap: 12px;
        padding: 12px 0 0;
    }

    /* the nested cards stacked padding on padding; on a phone the content
       should run to the edges and let whitespace come from rhythm instead */
    #youtube-section {
        padding: 0;
        margin-bottom: 0;
        background: none;
        border-radius: 0;
    }

    /* the strip of thumbnails says "videos" on its own */
    .youtube-videos-section h3 {
        display: none;
    }

    #youtube-videos-container {
        margin-bottom: 12px;
    }

    .comments-header {
        padding: 0 14px;
    }

    .youtube-comment {
        background: none;
        border-radius: 0;
        margin-bottom: 0;
        padding: 12px 14px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .youtube-comment:hover {
        background: none;
    }

    /* ---- video picker: compact horizontal strip, always visible ---- */
    #youtube-videos {
        gap: 8px;
        padding: 2px 14px;
        scrollbar-width: none;
    }

    /* the strip is short enough that a chunky red scrollbar dominates it */
    #youtube-videos::-webkit-scrollbar {
        display: none;
    }

    .youtube-video-item {
        flex: 0 0 172px;
        max-width: 172px;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 6px;
        border-width: 1px;
    }

    .youtube-video-item.selected,
    .youtube-video-item:hover {
        transform: none;
        box-shadow: none;
    }

    .video-thumbnail-container {
        flex: 0 0 60px;
        width: 60px;
    }

    .video-thumbnail {
        height: 34px;
        border-radius: 4px;
    }

    .comment-count-badge {
        font-size: 0.6rem;
        padding: 1px 4px;
    }

    .video-details {
        padding: 0;
        min-width: 0;
    }

    .video-details h4 {
        font-size: 0.72rem;
        line-height: 1.25;
        margin: 0;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* tapping the card already loads its comments */
    .video-meta,
    .video-actions {
        display: none;
    }

    /* let the page scroll instead of trapping a scroller inside it */
    #youtube-comments {
        overflow: visible;
        padding-right: 0;
    }

    .comments-container {
        max-width: none;
    }

    .comments-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    #selected-video-title {
        max-width: 100%;
        text-align: left;
        font-size: 0.8rem;
    }


    /* black-translucent lets the page run under the status bar, so pad for it */
    .container {
        padding-top: env(safe-area-inset-top);
    }

    /* keep the pull gesture from fighting the rubber-band scroll */
    body {
        overscroll-behavior-y: contain;
    }
}
