:root {
    --bg-primary: #f8fafc;
    --bg-surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent-color: #0284c7;
    --accent-hover: #0369a1;
    --border-color: #e2e8f0;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --warning-bg: #fef08a;
    --warning-text: #854d0e;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-arabic: 'Amiri', 'Traditional Arabic', serif;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

header.app-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 10;
}

header.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
}

header.app-header a {
    text-decoration: none;
    color: inherit;
}

/* Cards */
.book-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-color);
}

.card h2 {
    font-size: 1.25rem;
    color: var(--accent-color);
}

.card p.author {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* TOC */
.toc-container {
    background: var(--bg-surface);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow-sm);
    margin-top: 2rem;
}

.toc-list {
    list-style: none;
}

.toc-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.toc-item:last-child {
    border-bottom: none;
}

.toc-link {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    transition: color 0.2s;
    display: flex;
    align-items: center;
}

.toc-link:hover {
    color: var(--accent-color);
}

.toc-link::before {
    content: '•';
    color: var(--accent-color);
    margin-right: 0.75rem;
    font-size: 1.5rem;
    line-height: 1;
}

/* Reader Page */
.breadcrumbs {
    margin-bottom: 2rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.breadcrumbs ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.breadcrumbs li::after {
    content: '/';
    margin-left: 0.5rem;
    color: var(--border-color);
}

.breadcrumbs li:last-child::after {
    content: '';
}

.breadcrumbs a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.2s;
}

.breadcrumbs a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Reading Flow (Structural Wrapper) */
.reading-flow {
    display: flex;
    flex-direction: column;
    gap: 1.5rem; /* space between paragraphs */
    margin-bottom: 3rem; /* space before next heading */
}

/* Reading Unit (Base no-card) */
.reading-unit {
    display: flex;
    flex-direction: column;
}

/* Specific styling for paragraphs (Continuous Flow) */
.reading-unit.paragraph {
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
    margin-bottom: 0; 
}

/* Bilingual Side-by-Side Layout for Paragraphs */
@media (min-width: 768px) {
    .reading-unit.paragraph {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-areas: 
            "badges arabic"
            "translation arabic";
        gap: 0 2rem;
        align-items: start;
    }
}

/* Specific styling for headings */
.reading-unit.heading {
    background: transparent;
    border: none;
    padding: 2rem 0 1rem 0;
    box-shadow: none;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}


.text-arabic {
    font-family: var(--font-arabic);
    font-size: 1.75rem;
    line-height: 2.2;
    text-align: justify;
    direction: rtl;
    color: var(--text-primary);
    margin-bottom: 0;
}

/* On desktop, Arabic is on the right */
@media (min-width: 768px) {
    .reading-unit.paragraph .text-arabic {
        grid-area: arabic;
    }
}

.text-translation {
    font-size: 1.05rem;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-top: 0.5rem;
}

@media (min-width: 768px) {
    .reading-unit.paragraph .text-translation {
        grid-area: translation;
        margin-top: 0;
    }
}

.translation-missing {
    font-style: italic;
    color: var(--text-secondary);
    opacity: 0.5;
    font-size: 0.9rem;
    display: inline-block;
}

/* Badges */
.badges {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    justify-content: flex-end;
}

/* Ensure badges don't break Arabic flow in Grid */
@media (min-width: 768px) {
    .reading-unit.paragraph .badges {
        grid-area: badges;
        margin-bottom: 1rem;
        justify-content: flex-start; /* Align left with translation */
    }
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

/* Navigation Buttons */
.page-navigation {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    gap: 0.5rem;
}

.btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgb(2 132 199 / 0.2);
}

.btn.disabled {
    opacity: 0.5;
    pointer-events: none;
    background: var(--bg-primary);
}
