:root {
    --color-border-light: rgba(167, 139, 250, 0.2);
    --color-text-darker: #8b8ba7;
    --color-primary: #7a51e2;
    --color-primary-dark: #6a41d2;
    --color-text-default: #e7e4fb;
    --color-text-light: #c6c6d8;
    --color-card-background: rgba(0, 0, 0, 0.25);
    --color-item-background: rgba(122, 81, 226, 0.1);
    --shadow-purple-medium: rgba(122, 81, 226, 0.35);
    --shadow-strong: rgba(0, 0, 0, 0.5);
}

/* ---- COMMENTS SECTION ---- */
.comments-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--color-border-light);
    clear: both;
    overflow: visible;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    pointer-events: auto;
}

.comments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.comments-count {
    font-size: 0.9rem;
    color: var(--color-text-darker);
    cursor: pointer;
    transition: color 0.2s;
}

.comments-count:hover {
    color: var(--color-primary);
}

.comment-form {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.comment-input-wrapper {
    flex: 1;
    position: relative;
}

.comment-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--color-card-background);
    border: 1px solid var(--color-border-light);
    border-radius: 20px;
    color: var(--color-text-default);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    transition: border-color 0.2s, background 0.2s;
}

.comment-input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-item-background);
}

.comment-actions {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.comment-btn {
    padding: 10px 20px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.comment-btn:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--shadow-purple-medium);
}

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

.ai-generate-btn {
    padding: 10px 16px;
    background: linear-gradient(135deg, #7a51e2 0%, #a48cf0 100%);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-generate-btn:hover {
    background: linear-gradient(135deg, #6a41d2 0%, #9480e0 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--shadow-purple-medium);
}

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

.ai-generate-btn i {
    font-size: 0.9rem;
}

.comments-list-wrapper {
    margin-top: 10px;
    max-height: none;
    overflow: visible;
    position: relative;
    width: 100%;
    height: auto;
}

.comments-list {
    max-height: 200px !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding-right: 8px;
    padding-bottom: 5px;
    position: relative;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    display: block !important;
    pointer-events: auto !important;
    touch-action: pan-y !important;
    /* Force scrollbar to appear */
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-light) transparent;
    /* Ensure it can scroll */
    will-change: scroll-position;
    isolation: isolate;
    z-index: 1;
}

/* Ensure feed-item and item-content don't interfere with scrolling */
.feed-item .comments-list-wrapper,
.item-content .comments-list-wrapper {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
}

.feed-item .comments-list,
.item-content .comments-list {
    max-height: 200px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    display: block !important;
    pointer-events: auto !important;
    touch-action: pan-y !important;
    height: auto !important;
}

.comments-list .comment-item {
    margin-bottom: 10px;
}

.comments-list .comment-item:last-child {
    margin-bottom: 0;
}

.comments-list::-webkit-scrollbar {
    width: 6px;
}

.comments-list::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}

.comments-list::-webkit-scrollbar-thumb {
    background: var(--color-border-light);
    border-radius: 3px;
}

.comments-list::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

.comment-item {
    display: flex;
    gap: 10px;
    padding: 8px;
    background: var(--color-card-background);
    border-radius: 10px;
    transition: background 0.2s;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.comment-item:hover {
    background: var(--color-item-background);
}

.comment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--color-border-light);
    background: var(--color-item-background);
    display: block;
}

.comment-content {
    flex: 1;
    min-width: 0;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    position: relative;
}

.comment-username {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-text-default);
}

.comment-artist-name {
    font-size: 0.8rem;
    color: var(--color-primary);
    font-weight: 500;
}

.comment-ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(122, 81, 226, 0.2);
    color: var(--color-primary);
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 500;
}

.comment-time {
    font-size: 0.75rem;
    color: var(--color-text-darker);
}

.comment-delete-btn {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--color-text-darker);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    opacity: 0.6;
    transition: all 0.2s;
    width: 24px;
    height: 24px;
}

.comment-delete-btn:hover {
    opacity: 1;
    background: rgba(255, 0, 0, 0.1);
    color: #ff4444;
}

.comment-delete-btn i {
    width: 14px;
    height: 14px;
}

.comment-text {
    font-size: 0.85rem;
    color: var(--color-text-light);
    line-height: 1.4;
    word-wrap: break-word;
    margin-top: 2px;
}

.comment-footer {
    margin-top: 6px;
}

.comment-reply-btn {
    background: transparent;
    border: none;
    color: #a78bfa;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}

.comment-reply-btn:hover {
    color: #c4b5fd;
}

.comment-thread {
    margin-bottom: 10px;
}

.comment-thread:last-child {
    margin-bottom: 0;
}

.comment-replies {
    margin: 8px 0 0 18px;
    padding-left: 12px;
    border-left: 2px solid rgba(167, 139, 250, 0.18);
}

.comment-item--reply .comment-avatar {
    width: 28px;
    height: 28px;
}

.comment-item--reply .comment-username,
.comment-item--reply .comment-text {
    font-size: 0.82rem;
}

.comment-reply-form {
    margin-top: 8px;
}

.comment-reply-compose {
    display: flex;
    align-items: center;
    gap: 8px;
}

.comment-reply-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 34px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--color-border-light);
    background: var(--color-card-background);
    color: var(--color-text-default);
    font-size: 0.84rem;
    font-family: inherit;
}

.comment-reply-input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-item-background);
}

.comment-reply-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.comment-reply-cancel,
.comment-reply-submit {
    height: 34px;
    padding: 0 12px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.comment-reply-cancel {
    background: transparent;
    border: 1px solid var(--color-border-light);
    color: var(--color-text-darker);
}

.comment-reply-cancel:hover {
    border-color: rgba(167, 139, 250, 0.35);
    color: var(--color-text-default);
}

.comment-reply-submit {
    background: var(--color-primary);
    border: 1px solid rgba(167, 139, 250, 0.4);
    color: #fff;
}

.comment-reply-submit:hover {
    background: var(--color-primary-dark);
}

.comment-reply-submit:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.comment-replies .comment-item {
    margin-bottom: 8px;
}

.comment-replies .comment-item:last-child {
    margin-bottom: 0;
}

.comment-replies .comment-reply-form {
    margin-left: 0;
    margin-bottom: 8px;
}

.feed-item .comment-reply-compose,
.item-content .comment-reply-compose {
    flex-wrap: wrap;
    align-items: stretch;
}

@media (min-width: 520px) {
    .feed-item .comment-reply-compose,
    .item-content .comment-reply-compose {
        flex-wrap: nowrap;
        align-items: center;
    }
}

@media (max-width: 519px) {
    .feed-item .comment-reply-actions,
    .item-content .comment-reply-actions {
        width: 100%;
        justify-content: stretch;
    }

    .feed-item .comment-reply-cancel,
    .feed-item .comment-reply-submit,
    .item-content .comment-reply-cancel,
    .item-content .comment-reply-submit {
        flex: 1 1 0;
    }
}

/* Comments Modal */
.comments-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s;
}

.comments-modal.show {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.comments-modal-content {
    background: var(--color-card-background);
    border-radius: 20px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px var(--shadow-strong);
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.comments-modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.comments-modal-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--color-text-default);
}

.comments-modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--color-text-darker);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.comments-modal-close:hover {
    background: var(--color-item-background);
    color: var(--color-text-default);
}

.comments-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.comments-modal-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.comments-modal-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--color-item-background);
    border-radius: 12px;
}

.comments-modal-item .comment-avatar {
    width: 40px;
    height: 40px;
}

.comments-loading {
    text-align: center;
    padding: 20px;
    color: var(--color-text-darker);
}

.comments-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--color-text-darker);
}

.comments-empty-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.load-more-comments {
    text-align: center;
    margin-top: 15px;
}

.load-more-comments-btn {
    padding: 10px 20px;
    background: var(--color-item-background);
    color: var(--color-text-default);
    border: 1px solid var(--color-border-light);
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.load-more-comments-btn:hover {
    background: var(--color-card-background);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

@media (max-width: 768px) {
    .comment-form {
        flex-direction: column;
    }
    
    .comment-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    .comments-modal-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}
