/* Global Styles & Variables */
:root {
    --primary-color: #0f5132;
    /* Deep Islamic Green */
    --secondary-color: #d4af37;
    /* Gold */
    --background-color: #f8f9fa;
    /* Cream/Off-white */
    --text-color: #212529;
    --light-text: #6c757d;
    --border-color: #dee2e6;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --font-main: 'Cairo', sans-serif;
}

/* Import Cairo Font */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&display=swap');

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

body {
    font-family: var(--font-main);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    direction: rtl;
    text-align: right;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.3s ease;
}

ul {
    list-style: none;
}

img {
    max-width: 100%;
    display: block;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: #fff;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    border: none;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.btn:hover {
    background-color: #0c4128;
    transform: translateY(-2px);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: #000;
}

.btn-secondary:hover {
    background-color: #c09b2e;
}

.btn-sm {
    padding: 5px 15px;
    font-size: 0.9rem;
}

/* Header & Navbar */
header {
    background-color: #fff;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 3px solid var(--secondary-color);
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
}

.logo a {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    color: var(--primary-color);
    font-weight: 700;
}

.logo svg {
    width: 40px;
    height: 40px;
    fill: var(--secondary-color);
}

.nav-links {
    display: flex;
    gap: 20px;
    align-items: center;
}

.nav-item {
    position: relative;
    font-size: 1.1rem;
    font-weight: 600;
}

.nav-item>a:hover {
    color: var(--secondary-color);
}

/* Dropdown */
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: #fff;
    box-shadow: var(--shadow);
    border-radius: 5px;
    min-width: 180px;
    display: none;
    flex-direction: column;
    padding: 10px 0;
    border-top: 3px solid var(--secondary-color);
    z-index: 1001;
}

.dropdown:hover .dropdown-menu {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.dropdown-menu li a {
    padding: 10px 20px;
    display: block;
    color: var(--text-color);
}

.dropdown-menu li a:hover {
    background-color: var(--background-color);
    color: var(--primary-color);
}

/* Hero Section */
.hero {
    background: linear-gradient(rgba(15, 81, 50, 0.9), rgba(15, 81, 50, 0.9));
    background-size: cover;
    background-position: center;
    color: #fff;
    text-align: center;
    padding: 100px 20px;
    margin-bottom: 40px;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 20px;
    color: var(--secondary-color);
    font-weight: 700;
}

.hero p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.search-container {
    position: relative;
    max-width: 500px;
    margin: 0 auto;
}

.search-input {
    width: 100%;
    padding: 15px 20px;
    padding-left: 50px;
    border-radius: 30px;
    border: none;
    font-size: 1.1rem;
    font-family: var(--font-main);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.search-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.5);
}

/* Categories Section */
.section-title {
    text-align: center;
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-bottom: 40px;
    position: relative;
    display: inline-block;
    width: 100%;
    font-weight: 700;
}

.section-title::after {
    content: '';
    display: block;
    width: 80px;
    height: 4px;
    background-color: var(--secondary-color);
    margin: 10px auto 0;
    border-radius: 2px;
}

/* Topic Page Header Layout */
.topic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 20px;
}



.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Right aligned in RTL */
    gap: 10px;
}

.topic-header .section-title {
    text-align: right;
    width: auto;
    margin-bottom: 0;
}

.topic-header .section-title::after {
    margin: 10px 0 0 0;
    /* Right aligned underline */
}

/* Override search container for topic header */
.topic-header .search-container {
    margin: 0;
    width: 100%;
    max-width: 400px;
}

/* Filter Buttons */
.subcategories-container {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

.btn-filter {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 8px 20px;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s ease;
}

.btn-filter:hover {
    background: rgba(15, 81, 50, 0.1);
}

.btn-filter.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px rgba(15, 81, 50, 0.3);
}

@media (max-width: 768px) {
    .topic-header {
        flex-direction: column;
        text-align: center;
    }

    .topic-header .section-title {
        text-align: center;
        width: 100%;
    }

    .topic-header .section-title::after {
        margin: 10px auto 0;
    }
}

/* Level Buttons */
.level-container {
    display: flex;
    justify-content: flex-start;
    /* Align right in RTL */
    gap: 10px;
    margin-bottom: 0;
}

.btn-level {
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    color: #fff;
    opacity: 0.6;
    transition: opacity 0.3s, transform 0.2s;
}

.btn-level:hover,
.btn-level.active {
    opacity: 1;
    transform: scale(1.05);
}

.btn-level.beginner {
    background-color: #28a745;
}

/* Green */
.btn-level.intermediate {
    background-color: #ffc107;
    color: #333;
}

/* Yellow */
.btn-level.advanced {
    background-color: #dc3545;
}

/* Red */

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    /* Adjusted for better mobile fit */
    gap: 20px;
    padding-bottom: 60px;
}

.category-card {
    background-color: #fff;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    border-color: var(--secondary-color);
}

.category-icon {
    font-size: 2.5rem;
    margin-bottom: 15px;
    display: block;
}

.category-card h3 {
    color: var(--primary-color);
    font-size: 1.3rem;
    font-weight: 600;
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 30px;
    padding-bottom: 60px;
}

.book-card {
    background-color: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-5px);
}

.book-image {
    width: 100%;
    height: 280px;
    /* Ensure aspect ratio consistency */
    object-fit: cover;
    background-position: center;
    background-color: #eee;
}

.book-info {
    padding: 15px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.book-title {
    color: var(--primary-color);
    font-size: 1.1rem;
    margin-bottom: 5px;
    font-weight: 700;
    line-height: 1.4;
}

.book-author {
    color: var(--light-text);
    font-size: 0.9rem;
    margin-bottom: 15px;
    flex-grow: 1;
}

/* Footer */
footer {
    background-color: var(--primary-color);
    color: #fff;
    padding: 40px 0 20px;
    text-align: center;
    margin-top: auto;
}

.footer-links a {
    color: #fff;
    margin: 0 10px;
    font-size: 1.1rem;
}

.footer-links a:hover {
    color: var(--secondary-color);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 15px;
    }

    .nav-links {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 15px;
    }

    .nav-item {
        font-size: 1rem;
    }

    .dropdown-menu {
        position: relative;
        /* Static position for mobile to flow naturally */
        width: 100%;
        box-shadow: none;
        border: 1px solid #eee;
        display: none;
        /* Hidden by default, toggled via JS if needed, or rely on hover (tricky on touch) */
        /* Better mobile interaction usually requires a click toggle script, 
           but for now keeping simple hover/focus logic or letting it be accessible via direct link */
    }

    /* Force display on hover/focus for mobile 'tap' sometimes works */
    .dropdown:hover .dropdown-menu,
    .dropdown:focus-within .dropdown-menu {
        display: flex;
        position: relative;
        top: 0;
        animation: none;
    }

    .hero {
        padding: 60px 20px;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .section-title {
        font-size: 2rem;
    }

    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }

    .book-image {
        height: 220px;
    }

    .book-title {
        font-size: 1rem;
    }
}