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

:root {
    --primary: #1a4d2e;
    --primary-light: #2d6a4f;
    --accent: #d4af37;
    --accent-light: #f4e4b0;
    --bg-main: #faf8f3;
    --bg-card: #ffffff;
    --text-primary: #2c3e2f;
    --text-secondary: #5a6c5b;
    --border: #e8e3d6;
    --shadow: rgba(26, 77, 46, 0.08);
}

body {
    font-family: 'Crimson Pro', serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.7;
    overflow-x: hidden;
}

/* Decorative Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(212, 175, 55, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(26, 77, 46, 0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* Islamic Geometric Pattern Overlay */
.pattern-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 300px;
    background-image:
        repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(212, 175, 55, 0.02) 35px, rgba(212, 175, 55, 0.02) 70px),
        repeating-linear-gradient(-45deg, transparent, transparent 35px, rgba(26, 77, 46, 0.02) 35px, rgba(26, 77, 46, 0.02) 70px);
    pointer-events: none;
    z-index: -1;
    opacity: 0;
    animation: fadeIn 1s ease-out 0.3s forwards;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    position: relative;
}

/* Header */
header {
    padding: 3rem 0 2rem;
    text-align: center;
    position: relative;
    opacity: 0;
    animation: fadeInUp 0.8s ease-out forwards;
}

.site-title {
    font-family: 'Amiri', serif;
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
    position: relative;
    display: inline-block;
}

.site-title::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.site-subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-top: 1.5rem;
    font-weight: 300;
}

/* Navigation */
nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 3rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 0.2s forwards;
}

.nav-btn {
    padding: 0.75rem 2rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    color: var(--text-primary);
    font-family: 'Crimson Pro', serif;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    border-radius: 2px;
}

.nav-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.1), transparent);
    transition: left 0.5s ease;
}

.nav-btn:hover::before {
    left: 100%;
}

.nav-btn:hover {
    border-color: var(--accent);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Filter Section */
.filter-section {
    background: rgba(26, 77, 46, 0.05);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    border: 1px solid var(--border);
}

.filter-title {
    font-family: 'Amiri', serif;
    font-size: 1.2rem;
    color: var(--primary);
    margin-bottom: 1rem;
    display: block;
}

.qari-picklist {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.qari-chip {
    padding: 0.5rem 1rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.qari-chip:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.qari-chip.selected {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Update Section: Remove the animation from the section itself */
.section {
    display: none;
    opacity: 1; /* Keep it at 1 so only the content card animates */
    visibility: hidden;
}

.section.active {
    display: block;
    visibility: visible;
    /* Removed the fadeIn animation from here to prevent mobile glitches */
}

/* Update Content Card: Add Hardware Acceleration */
.content-card {
    background: var(--bg-card);
    padding: 3rem;
    border-radius: 4px;
    box-shadow: 0 2px 20px var(--shadow);
    margin-bottom: 2rem;
    border-left: 4px solid var(--accent);
    position: relative;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s ease-out forwards;
    
    /* THE FIX: Tell the mobile GPU to handle this layer separately */
    will-change: transform, opacity;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Update Chapter Item: Ensure it doesn't overlap the hardware layer */
.chapter-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateZ(0); /* Force GPU rendering */
}

h2 {
    font-family: 'Amiri', serif;
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 1.5rem;
    position: relative;
}

h3 {
    font-family: 'Amiri', serif;
    font-size: 1.8rem;
    color: var(--primary-light);
    margin: 2rem 0 1rem;
}

p {
    font-size: 1.15rem;
    color: var(--text-secondary);
    margin-bottom: 1.2rem;
    line-height: 1.8;
}

/* Chapter Sections */


.chapter-item.visible {
    animation: fadeInUp 0.5s ease-out forwards;
}

.chapter-header {
    padding: 1.5rem 2rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(212, 175, 55, 0.02) 100%);
}

.chapter-order {
    background: var(--accent);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    margin-right: 1.5rem;
    flex-shrink: 0;
}

.chapter-title-wrapper {
    flex-grow: 1;
    margin-right: 1rem;
}

.expand-icon {
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.chapter-item.expanded .expand-icon {
    transform: rotate(180deg);
}

.chapter-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease;
}

.chapter-item.expanded .chapter-content {
    max-height: 10000px; /* Increased to accommodate content */
    padding: 2rem;
    border-top: 1px solid var(--border);
}

/* Rules Display */
.rule-section {
    background: white;
    border-radius: 4px;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary-light);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
    overflow: hidden;
    transition: all 0.2s ease;
}

.rule-section:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.chapter-description, 
.rule-description {
    white-space: pre-line;
    font-size: 1.1rem; /* Increased from default */
    line-height: 1.6;  /* Matched with notes/exceptions */
    color: var(--text-primary);
}


/* Rule Header (Clickable) */
.rule-header {
    padding: 1.5rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    transition: background-color 0.2s ease;
}

.rule-section.expanded .rule-header {
    background-color: rgba(26, 77, 46, 0.02);
    border-bottom: 1px solid var(--border);
}

.rule-title {
    font-family: 'Amiri', serif;
    font-size: 1.4rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    flex-grow: 1;
    margin-right: 1rem;
}

.rule-toggle-icon {
    color: var(--text-secondary);
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.rule-section.expanded .rule-toggle-icon {
    transform: rotate(180deg);
}

/* Rule Content (Collapsible) */
.rule-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
    opacity: 0;
}

.rule-section.expanded .rule-content {
    max-height: 2000px; /* Arbitrary large height */
    opacity: 1;
    transition: max-height 0.5s ease, opacity 0.3s ease 0.1s;
}

.rule-body-padding {
    padding: 1.5rem;
}

/* Shatibiyyah Reference Styling */
.reference-section {
    margin-bottom: 2rem;
    padding: 1rem;
    background: rgba(212, 175, 55, 0.05);
    border-radius: 4px;
    border: 1px dashed var(--accent);
}

.reference-meta {
    font-size: 1.1rem; /* Matched to exception-item */
    color: var(--text-primary);
}

.reference-note {
    margin-top: 0.5rem;
    font-style: italic;
    color: var(--text-secondary);
    border-top: 1px solid rgba(212, 175, 55, 0.2);
    padding-top: 0.5rem;
    font-size: 1.1rem; /* Matched to exception-item */
}

/* Note Box Styling */
.note-box {
    background: var(--accent-light);
    padding: 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    border-left: 3px solid var(--accent);
}

.note-text {
    margin-bottom: 0;
    font-style: italic;
    font-size: 1.1rem; /* Increased from 0.95rem to match exceptions */
    color: var(--text-primary);
    line-height: 1.6;
}

/* Exceptions Styling */
.exceptions-container {
    background: #fff5f5;
    padding: 1rem;
    border-radius: 4px;
    border-left: 3px solid #8b0000;
    margin-top: 1rem;
}

.exception-label {
    color: #8b0000 !important;
    font-weight: 600;
    font-size: 1rem;
}

.exceptions-list {
    list-style-type: none;
    padding-left: 0;
    margin-top: 0.5rem;
}

.exception-item {
    font-size: 1.1rem;
    color: #8b0000;
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.quraa-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0;
}

.qari-tag {
    background: var(--accent-light);
    color: var(--primary);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

.example-box {
    background: rgba(26, 77, 46, 0.03);
    padding: 1.5rem;
    border-radius: 4px;
    margin: 1rem 0;
}

.example-verse {
    font-family: 'Amiri', serif;
    font-size: 1.8rem;
    color: var(--primary);
    text-align: center;
    direction: rtl;
    line-height: 2.2;
}

.label {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 0.5rem;
    display: block;
}

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

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

/* --- MOBILE OPTIMIZATIONS --- */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    header {
        padding: 2rem 0 1rem;
    }

    .site-title { 
        font-size: 2.2rem;
        line-height: 1.2;
    }
    
    .site-subtitle {
        font-size: 1rem;
        margin-top: 0.5rem;
    }

    nav {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 1rem 0;
        margin-bottom: 2rem;
        gap: 0.5rem;
    }

    .nav-btn {
        flex: 1 1 45%;
        padding: 0.6rem 0.5rem;
        font-size: 1rem;
        text-align: center;
    }

    .content-card {
        padding: 1.25rem;
        border-left-width: 3px;
    }

    h2 {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }
    
    p {
        font-size: 1rem;
    }

    .chapter-header {
        padding: 1rem;
    }

    .chapter-order {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
        margin-right: 0.75rem;
    }

    .chapter-title {
        font-size: 1.05rem;
        line-height: 1.3;
    }

    .chapter-item.expanded .chapter-content {
        padding: 1rem;
    }

    /* Update Rule Header for Mobile */
    .rule-header {
        padding: 1rem;
    }

    .rule-body-padding {
        padding: 1rem;
    }

    .rule-title {
        font-size: 1.2rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.2rem;
    }

    .example-verse {
        font-size: 1.6rem;
        line-height: 2;
    }
    
    .filter-section {
        padding: 1rem;
    }
    
    .qari-chip {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
}