:root {
    --primary: #0e7490;
    --primary-light: #cffafe;
    --primary-dark: #0c4a6e;
    --bg: #f8fafc;
    --card: #ffffff;
    --card-hover: #f0fdfa;
    --surface: #ffffff;
    --surface-dim: #f1f5f9;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow-sm: rgba(0,0,0,0.06);
    --shadow-md: rgba(0,0,0,0.1);
    --radius: 12px;
    --success: #059669;
    --success-light: #d1fae5;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --bookmark: #d97706;
    --bookmark-light: #fef3c7;
    --topic-bg: #f0fdfa;
    --topic-border: #99f6e4;
}

[data-theme="dark"] {
    --primary: #22d3ee;
    --primary-light: #164e63;
    --primary-dark: #67e8f9;
    --bg: #0f172a;
    --card: #1e293b;
    --card-hover: #1a3a4a;
    --surface: #1e293b;
    --surface-dim: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow-sm: rgba(0,0,0,0.2);
    --shadow-md: rgba(0,0,0,0.3);
    --success: #10b981;
    --success-light: #064e3b;
    --danger: #f87171;
    --danger-light: #450a0a;
    --bookmark: #fbbf24;
    --bookmark-light: #422006;
    --topic-bg: #164e63;
    --topic-border: #0e7490;
    color-scheme: dark;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
}

.header-stats {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Juz Grid */
.juz-grid {
    padding: 16px;
    max-width: 900px;
    margin: 0 auto;
}

.juz-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px var(--shadow-sm);
    transition: all 0.2s;
}

.juz-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.juz-header:hover {
    background: var(--card-hover);
}

.juz-title {
    font-weight: 600;
    font-size: 1rem;
}

.juz-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.juz-progress-bar {
    width: 60px;
    height: 4px;
    background: var(--surface-dim);
    border-radius: 2px;
    overflow: hidden;
}

.juz-progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 2px;
    transition: width 0.3s;
}

.juz-maqras {
    display: none;
    padding: 4px 12px 12px;
    gap: 8px;
    flex-wrap: wrap;
}

.juz-card.expanded .juz-maqras {
    display: flex;
}

.maqra-btn {
    flex: 1;
    min-width: calc(25% - 6px);
    padding: 10px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.8rem;
    text-align: center;
    transition: all 0.2s;
    position: relative;
}

.maqra-btn:hover {
    border-color: var(--primary);
    background: var(--card-hover);
}

.maqra-btn.completed {
    border-color: var(--success);
    background: var(--success-light);
}

.maqra-btn.completed::after {
    content: '✓';
    position: absolute;
    top: 2px;
    right: 6px;
    color: var(--success);
    font-size: 0.7rem;
    font-weight: 700;
}

.maqra-btn .maqra-label {
    font-weight: 500;
    display: block;
}

.maqra-btn .maqra-detail {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Reading View */
.reading-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.reading-title {
    flex: 1;
    min-width: 0;
}

.reading-title h2 {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reading-title .text-muted {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.reading-nav {
    display: flex;
    gap: 4px;
}

/* Buttons */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

.btn-primary:hover {
    opacity: 0.9;
}

.btn-primary.completed {
    background: var(--success);
    border-color: var(--success);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--card-hover);
}

.btn-danger {
    background: var(--danger-light);
    color: var(--danger);
    border-color: var(--danger);
}

/* Ayah List */
.ayah-list {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 16px 100px;
}

.surah-header {
    text-align: center;
    padding: 24px 0 16px;
    margin-bottom: 8px;
}

.surah-header h3 {
    font-family: 'Amiri', serif;
    font-size: 1.8rem;
    color: var(--primary);
    margin-bottom: 2px;
}

.surah-header .surah-name-en {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.bismillah {
    text-align: center;
    font-family: 'Amiri', serif;
    font-size: 1.5rem;
    color: var(--primary);
    padding: 8px 0 20px;
    direction: rtl;
}

.topic-header {
    margin: 24px 0 12px;
    padding: 12px 16px;
    background: var(--topic-bg);
    border-left: 3px solid var(--topic-border);
    border-radius: 0 8px 8px 0;
    animation: fadeIn 0.3s ease;
}

.topic-header h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 4px;
}

.topic-header p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

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

.ayah-item {
    padding: 16px;
    margin-bottom: 8px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
}

.ayah-item:hover {
    background: var(--surface-dim);
}

.ayah-item.bookmarked {
    border-color: var(--bookmark);
    background: var(--bookmark-light);
}

.ayah-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface-dim);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.ayah-arabic {
    font-family: 'Amiri', serif;
    font-size: 1.6rem;
    line-height: 2.2;
    direction: rtl;
    text-align: right;
    color: var(--text);
    margin-bottom: 10px;
}

.ayah-translation {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.7;
}

/* Reading Footer */
.reading-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px var(--shadow-sm);
    z-index: 10;
}

.reading-footer .btn {
    flex: 1;
}

.reading-footer .btn-primary {
    flex: 2;
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    z-index: 25;
    box-shadow: 0 2px 8px var(--shadow-sm);
    transition: all 0.2s;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

body.reading .theme-toggle {
    bottom: 80px;
}

/* AI Button */
.ai-btn {
    position: fixed;
    bottom: 16px;
    right: 64px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    z-index: 25;
    box-shadow: 0 2px 8px var(--shadow-sm);
    transition: all 0.2s;
    font-size: 0.8rem;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.ai-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

body.reading .ai-btn {
    bottom: 80px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 8px 32px var(--shadow-md);
}

.modal-content h3 {
    margin-bottom: 12px;
    font-size: 1rem;
}

.modal-content textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.875rem;
    resize: vertical;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Responsive */
@media (max-width: 640px) {
    .app-header h1 { font-size: 1.1rem; }
    .maqra-btn { min-width: calc(50% - 4px); }
    .ayah-arabic { font-size: 1.4rem; line-height: 2; }
    .reading-footer .btn { padding: 10px 12px; font-size: 0.8rem; }
    .reading-nav { display: none; }
}
