@font-face {
    font-family: 'Kitab';
    src: url('fonts/Kitab-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Kitab';
    src: url('fonts/Kitab-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

:root {
    /* Default Dark Theme */
    --bg-color: #0f172a;
    --bg-surface: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --border: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(30, 41, 59, 0.85);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    --glass-border: rgba(255, 255, 255, 0.05);

    /* Font Sizes */
    --ar-font-size: 28px;
    --id-font-size: 16px;
}

[data-theme="light"] {
    --bg-color: #f8fafc;
    --bg-surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border: rgba(0, 0, 0, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0, 0, 0, 0.05);
}

[data-theme="sepia"] {
    --bg-color: #f4ecd8;
    --bg-surface: #fdf6e3;
    --text-primary: #4a3627;
    --text-secondary: #7a5f49;
    --accent: #b35900;
    --accent-hover: #804000;
    --border: rgba(92, 64, 51, 0.15);
    --glass-bg: rgba(253, 246, 227, 0.85);
    --glass-border: rgba(92, 64, 51, 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 16px; /* Default UI Font size - untethered from content zoom */
}

/* Typography */
h1, h2, h3, h4 {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
}

.ar {
    font-family: 'Kitab', 'Amiri', serif;
    font-size: var(--ar-font-size);
    line-height: 2.2;
    direction: rtl;
    text-align: right;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    transition: font-size 0.2s ease;
}

.id {
    font-family: 'Inter', sans-serif;
    font-size: var(--id-font-size);
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    direction: ltr;
    text-align: left;
    transition: font-size 0.2s ease;
}

/* Reading Modes */
[data-mode="ar-only"] .id {
    display: none !important;
}
[data-mode="id-only"] .ar {
    display: none !important;
}
[data-mode="ar-only"] .ar {
    margin-bottom: 1.5rem;
}

/* Header & Breadcrumb */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem;
    box-shadow: var(--glass-shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-inner {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.bc-item {
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.bc-item:hover {
    color: var(--accent);
}

.bc-active {
    color: var(--text-primary);
    cursor: default;
}

.bc-separator {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    color: var(--accent);
    background: rgba(128, 128, 128, 0.1);
}

/* Layout */
#app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: calc(100vh - 60px);
}

.view {
    display: none;
    animation: fadeIn 0.4s ease-out forwards;
}

.view.active {
    display: block;
}

/* Settings Full Page Modal */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-surface);
    z-index: 1000;
    display: none;
    flex-direction: column;
}

.settings-overlay.active {
    display: flex;
    animation: fadeIn 0.3s ease forwards;
}

.settings-modal-content {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.settings-header h3 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

/* Preview Box */
.preview-box {
    background: rgba(128, 128, 128, 0.05);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.preview-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    font-weight: 600;
}

.setting-group {
    margin-bottom: 2rem;
}

.setting-group-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.setting-options {
    display: flex;
    gap: 0.75rem;
}

.setting-btn {
    flex: 1;
    padding: 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.setting-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Font Size Controls specifically */
.font-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.font-controls span {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 1.1rem;
}

/* Hero Section */
.header-hero {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
    background: radial-gradient(circle at top, rgba(59,130,246,0.15) 0%, transparent 70%);
}

.header-hero h1 {
    font-family: 'Kitab', 'Amiri', serif;
    font-size: 3rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
}

/* Search Box */
.search-box {
    max-width: 400px;
    margin: 0 auto;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 1rem 1.5rem;
    border-radius: 99px;
    border: 1px solid var(--border);
    background: rgba(30, 41, 59, 0.1);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    background: var(--bg-surface);
}

/* Chapter List */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chapter-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.chapter-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border-color: rgba(96, 165, 250, 0.3);
}

.chapter-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    transform: scaleY(0);
    transition: transform 0.3s ease;
    transform-origin: center;
}

.chapter-card:hover::before {
    transform: scaleY(1);
}

.chapter-card-title {
    font-family: 'Kitab', 'Amiri', serif;
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.chapter-card-id {
    font-size: 0.85rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    direction: ltr;
    display: inline-block;
}

/* Detail View Content */
.chapter-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.chapter-header h1 {
    font-family: 'Kitab', 'Amiri', serif;
    font-size: calc(var(--ar-font-size) * 1.5);
    color: var(--accent-hover);
    transition: font-size 0.2s ease;
}

[data-theme="sepia"] .chapter-header h1, [data-theme="light"] .chapter-header h1 {
    color: var(--accent);
}

.section-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: all 0.3s ease;
}

.section-header {
    padding: 1rem 1.5rem;
    background: rgba(128, 128, 128, 0.05);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.section-header h2 {
    font-family: 'Kitab', 'Amiri', serif;
    font-size: calc(var(--ar-font-size) * 0.9);
    color: var(--text-primary);
    transition: font-size 0.2s ease;
}

.toggle-icon {
    transition: transform 0.3s ease;
    color: var(--text-secondary);
}

.section-container.collapsed .toggle-icon {
    transform: rotate(180deg);
}

.section-content {
    padding: 1.5rem;
    transition: max-height 0.4s ease-in-out, padding 0.4s ease, opacity 0.4s ease;
    overflow: hidden;
    opacity: 1;
}

.section-container.collapsed .section-content {
    max-height: 0 !important;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    border-top: none;
}

/* FAB */
.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

[data-theme="sepia"] .fab {
    box-shadow: 0 4px 12px rgba(179, 89, 0, 0.4);
}

.fab:hover {
    transform: scale(1.1) rotate(-5deg);
    background: var(--accent-hover);
}

.fab:active {
    transform: scale(0.95);
}

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

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