:root {
    --primary-color: #0056b3; /* Darker blue */
    --secondary-color: #6c757d;
    --background-color: #f8f9fa;
    --card-background: #ffffff;
    --text-color: #343a40;
    --sub-text-color: #6c757d;
    --border-color: #dee2e6;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --gold-color: #FFD700; /* Gold color for filled stars */
    --gray-star-color: #ccc;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans Bengali', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding-bottom: 50px;
}

.container {
    max-width: 960px;
    width: 100%;
    padding: 20px;
}

/* Header and Controls */
header {
    background-color: var(--card-background);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 5px 15px var(--shadow-color);
    margin-bottom: 25px;
    text-align: center;
}

h1 {
    font-size: 2.2rem;
    color: var(--primary-color);
    margin-bottom: 20px;
    font-weight: 700;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
}

.search-container,
.filter-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

#searchInput,
#ratingFilter {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    min-width: 180px;
    transition: all 0.3s ease-in-out;
}

#searchInput:focus,
#ratingFilter:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.2);
    outline: none;
}

/* Word List */
.word-list {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.word-item {
    background-color: var(--card-background);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 3px 10px var(--shadow-color);
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.word-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.word-title {
    font-size: 1.6rem;
    margin-bottom: 8px;
    color: var(--primary-color);
    font-weight: 700;
}

.part-of-speech {
    font-size: 1.1rem;
    font-weight: normal;
    color: var(--sub-text-color);
}

.word-meta {
    display: flex;
    gap: 20px;
    font-size: 1rem;
    color: var(--sub-text-color);
    margin-top: 10px;
}

.rating {
    font-size: 1.3rem;
    color: var(--gold-color);
}

.read-count {
    color: var(--secondary-color);
}

.no-words, .error-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 0;
    color: var(--sub-text-color);
    font-style: italic;
    font-size: 1.1rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    animation: fadeInBackground 0.3s;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--card-background);
    padding: 35px;
    border-radius: 16px;
    width: 90%;
    max-width: 850px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    animation: fadeInModal 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin: 4% auto;
    /* Added to fix scrolling issue */
    max-height: 90vh; /* Set a max height */
    overflow-y: auto; /* Enable internal scrolling */
}

.close-button {
    color: #999;
    position: sticky; /* Make the button sticky */
    top: 0; /* Stick to the top of the container */
    right: 0;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    background-color: var(--card-background);
    padding: 10px 15px;
    border-radius: 0 16px 0 16px;
    z-index: 1001; /* Ensure it stays on top of content */
    float: right; /* To position it correctly with padding */
}

.close-button:hover,
.close-button:focus {
    color: var(--primary-color);
}

.loading-message {
    text-align: center;
    padding: 60px;
    color: var(--sub-text-color);
}

/* Modal Details */
.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 12px;
    color: var(--primary-color);
    font-weight: 700;
    padding-top: 25px; /* Add padding to prevent text from going under button */
}

.modal-content h3 {
    margin-top: 25px;
    margin-bottom: 15px;
    font-size: 1.6rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
    color: var(--text-color);
}

.pronunciation {
    font-size: 1.2rem;
    color: var(--sub-text-color);
    margin-bottom: 20px;
}

.audio-icon {
    cursor: pointer;
    margin-left: 10px;
    font-size: 1.4rem;
    color: var(--primary-color);
    transition: transform 0.2s ease-in-out;
}
.audio-icon:hover {
    transform: scale(1.1);
}

.rating-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.stars {
    display: flex;
    gap: 5px;
}

.stars .star {
    cursor: pointer;
    font-size: 1.8rem;
    color: var(--gray-star-color);
    transition: color 0.2s;
}

.stars .star.filled {
    color: var(--gold-color);
}

/* Live rating hover effect */
.stars .star:hover,
.stars .star:hover ~ .star {
    color: var(--gold-color);
}

.mark-read-btn {
    padding: 12px 25px;
    background-color: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.4s ease;
    margin-top: 15px;
}

.mark-read-btn:hover {
    background-color: #004494;
}

.mark-read-btn.fadeOut {
    opacity: 0;
    pointer-events: none;
}

/* Tabs */
.tabs {
    display: flex;
    flex-wrap: nowrap;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab-button {
    padding: 14px 20px;
    cursor: pointer;
    background-color: transparent;
    border: none;
    border-radius: 10px 10px 0 0;
    font-size: 1.1rem;
    color: var(--sub-text-color);
    transition: all 0.3s;
    flex-shrink: 0;
}

.tab-button:hover {
    color: var(--primary-color);
}

.tab-button.active {
    background-color: var(--card-background);
    border-bottom: 3px solid var(--primary-color);
    color: var(--primary-color);
    font-weight: bold;
}

.tab-pane {
    display: none;
    padding: 10px;
}

.tab-pane.active {
    display: block;
}

.tab-pane ul {
    list-style-type: none;
    padding: 0;
    margin-left: 20px;
}

.tab-pane li {
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    padding: 18px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-size: 1rem;
    line-height: 1.8;
}

.tab-pane li strong {
    color: var(--primary-color);
    font-weight: 700;
}

/* Word Network Tree View */
.word-network h3 {
    margin-bottom: 0;
}
.word-network ul {
    margin-left: 0;
    list-style-type: none;
    position: relative;
    padding-left: 1.5em;
}

.word-network ul ul {
    margin-left: 20px;
}

.word-network ul li {
    background-color: transparent;
    border: none;
    padding: 5px 0 5px 25px;
    margin-bottom: 0;
    position: relative;
}

.word-network ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    border-left: 1px solid var(--border-color);
    height: 100%;
    width: 0;
}

.word-network ul li:last-child::before {
    height: 50%;
}

.word-network ul li::after {
    content: '';
    position: absolute;
    left: 0;
    top: 15px;
    border-top: 1px solid var(--border-color);
    width: 25px;
}

/* Keyframe Animations */
@keyframes fadeInBackground {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInModal {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    header {
        padding: 20px;
    }
    h1 {
        font-size: 1.8rem;
    }
    .controls {
        flex-direction: column;
        gap: 15px;
    }
    #searchInput, #ratingFilter {
        width: 100%;
    }
    .word-list {
        grid-template-columns: 1fr;
    }
    .modal-content {
        width: 95%;
        margin: 20px auto;
        padding: 20px;
    }
    .modal-content h2 {
        font-size: 2rem;
    }
    .modal-content h3 {
        font-size: 1.4rem;
    }
    .tabs {
        font-size: 0.9rem;
    }
    .tab-button {
        padding: 10px 14px;
        font-size: 1rem;
    }
    .close-button {
        padding: 8px 12px;
        font-size: 28px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }
    .modal-content h2 {
        font-size: 1.8rem;
    }
    .stars .star {
        font-size: 1.5rem;
    }
    .mark-read-btn {
        padding: 10px 20px;
        font-size: 1rem;
    }
}