/* Custom Styles and Animations */

/* ================================
   CSS Custom Properties (Themes)
   ================================ */
:root {
    /* Default Theme: Green (Forest) */
    --color-primary: #2D6A4F;
    --color-secondary: #40916C;
    --color-accent: #95D5B2;
    --color-primary-rgb: 45, 106, 79;
    --color-secondary-rgb: 64, 145, 108;
    --color-accent-rgb: 149, 213, 178;
}

/* Theme: Blue (Ocean) */
[data-theme="blue"] {
    --color-primary: #1E3A5F;
    --color-secondary: #2563EB;
    --color-accent: #93C5FD;
    --color-primary-rgb: 30, 58, 95;
    --color-secondary-rgb: 37, 99, 235;
    --color-accent-rgb: 147, 197, 253;
}

/* Theme: Purple (Royal) */
[data-theme="purple"] {
    --color-primary: #581C87;
    --color-secondary: #7C3AED;
    --color-accent: #C4B5FD;
    --color-primary-rgb: 88, 28, 135;
    --color-secondary-rgb: 124, 58, 237;
    --color-accent-rgb: 196, 181, 253;
}

/* Theme: Brown (Earth) */
[data-theme="brown"] {
    --color-primary: #78350F;
    --color-secondary: #B45309;
    --color-accent: #FCD34D;
    --color-primary-rgb: 120, 53, 15;
    --color-secondary-rgb: 180, 83, 9;
    --color-accent-rgb: 252, 211, 77;
}

/* Theme: Teal (Serenity) */
[data-theme="teal"] {
    --color-primary: #134E4A;
    --color-secondary: #14B8A6;
    --color-accent: #99F6E4;
    --color-primary-rgb: 19, 78, 74;
    --color-secondary-rgb: 20, 184, 166;
    --color-accent-rgb: 153, 246, 228;
}

/* Theme: Rose (Blossom) */
[data-theme="rose"] {
    --color-primary: #9F1239;
    --color-secondary: #E11D48;
    --color-accent: #FDA4AF;
    --color-primary-rgb: 159, 18, 57;
    --color-secondary-rgb: 225, 29, 72;
    --color-accent-rgb: 253, 164, 175;
}

* {
    scroll-behavior: smooth;
}

body {
    overflow-x: hidden;
}

/* Navigation Links */
.nav-link {
    position: relative;
    padding: 0.5rem 1rem;
    color: var(--color-primary);
    font-weight: 600;
    transition: color 0.3s ease;
}

.dark .nav-link {
    color: var(--color-accent);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background-color: var(--color-secondary);
    transition: width 0.3s ease;
}

.dark .nav-link::after {
    background-color: var(--color-accent);
}

.nav-link:hover::after {
    width: 100%;
}

.nav-link:hover {
    color: var(--color-secondary);
}

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

/* Buttons */
.btn-primary {
    display: inline-block;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: white;
    font-weight: 600;
    border-radius: 0.75rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(var(--color-primary-rgb), 0.3);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(var(--color-primary-rgb), 0.4);
}

.btn-secondary {
    display: inline-block;
    padding: 1rem 2rem;
    background: transparent;
    color: var(--color-primary);
    font-weight: 600;
    border: 2px solid var(--color-primary);
    border-radius: 0.75rem;
    transition: all 0.3s ease;
}

.dark .btn-secondary {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

.btn-secondary:hover {
    background: var(--color-primary);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(var(--color-primary-rgb), 0.3);
}

.dark .btn-secondary:hover {
    background: var(--color-accent);
    color: #1B263B;
}

/* Buy Buttons */
.btn-buy {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: white;
    font-weight: 600;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    text-decoration: none;
    margin-top: 1rem;
    box-shadow: 0 4px 15px rgba(var(--color-primary-rgb), 0.3);
}

.btn-buy:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(var(--color-primary-rgb), 0.4);
}

.btn-buy-level {
    display: inline-block;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--color-secondary), var(--color-primary));
    color: white;
    font-weight: 600;
    border-radius: 0.75rem;
    transition: all 0.3s ease;
    margin-top: 1rem;
    box-shadow: 0 4px 15px rgba(var(--color-primary-rgb), 0.3);
    text-decoration: none;
}

.btn-buy-level:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(var(--color-primary-rgb), 0.4);
}

/* Section Titles */
.section-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-primary);
}

.dark .section-title {
    color: var(--color-accent);
}

@media (max-width: 768px) {
    .section-title {
        font-size: 2rem;
    }
}

/* Feature Cards */
.feature-card {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(30px);
}

.dark .feature-card {
    background: #1f2937;
}

.feature-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 12px 30px rgba(var(--color-primary-rgb), 0.15);
}

/* Scholar Cards */
.scholar-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    text-align: center;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(30px);
}

.dark .scholar-card {
    background: #1f2937;
}

.scholar-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(var(--color-primary-rgb), 0.15);
}

/* Level Cards */
.level-card {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    border: 2px solid transparent;
    opacity: 0;
    transform: translateY(30px);
}

.dark .level-card {
    background: #1f2937;
}

.level-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-10px);
    box-shadow: 0 12px 30px rgba(var(--color-primary-rgb), 0.2);
}

.dark .level-card:hover {
    border-color: var(--color-accent);
}

/* Book Cards */
.book-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(30px);
}

.dark .book-card {
    background: #1f2937;
}

.book-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 12px 30px rgba(var(--color-primary-rgb), 0.15);
}

.book-card-large {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(30px);
}

.dark .book-card-large {
    background: #1f2937;
}

.book-card-large:hover {
    box-shadow: 0 12px 35px rgba(var(--color-primary-rgb), 0.2);
}

.book-image {
    position: relative;
    overflow: hidden;
    border-radius: 0.5rem;
}

.book-image img {
    transition: transform 0.3s ease;
}

.book-card:hover .book-image img:last-child,
.book-card-large:hover .book-image img:last-child {
    transform: scale(1.05);
}

/* Approved Stage Cards */
.approved-stage-card {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    border-left: 5px solid var(--color-primary);
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateX(-30px);
}

.dark .approved-stage-card {
    background: #1f2937;
    border-left-color: var(--color-accent);
}

.approved-stage-card:hover {
    transform: translateX(5px);
    box-shadow: 0 8px 25px rgba(var(--color-primary-rgb), 0.15);
}

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

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

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

.slide-up {
    animation: slideUp 0.5s ease forwards;
}

.delay-100 {
    animation-delay: 0.05s;
}

.delay-200 {
    animation-delay: 0.1s;
}

.delay-300 {
    animation-delay: 0.15s;
}

.delay-400 {
    animation-delay: 0.2s;
}

.delay-500 {
    animation-delay: 0.25s;
}

.delay-1000 {
    animation-delay: 0.3s;
}

.animate-float {
    animation: float 3s ease-in-out infinite;
}

/* Scroll Animations */
.scroll-animate {
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease;
}

.scroll-animate.show {
    opacity: 1;
    transform: translateY(0);
}

/* Smooth Scroll Offset for Fixed Header */
section {
    scroll-margin-top: 100px;
}

/* Loading State */
.loading {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.loaded {
    opacity: 1;
}

/* Responsive Typography */
@media (max-width: 640px) {
    .section-title {
        font-size: 1.75rem;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.dark ::-webkit-scrollbar-track {
    background: #1f2937;
}

::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 5px;
}

.dark ::-webkit-scrollbar-thumb {
    background: var(--color-accent);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-secondary);
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: var(--color-accent);
}

/* Backdrop Blur Support */
@supports (backdrop-filter: blur(10px)) {
    header {
        backdrop-filter: blur(10px);
    }
}

/* Print Styles */
@media print {
    header {
        position: relative;
    }

    .btn-primary,
    .btn-secondary,
    #theme-toggle {
        display: none;
    }
}

/* Accessibility */
.focus-visible:focus {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

.dark .focus-visible:focus {
    outline-color: var(--color-accent);
}

/* Reduce Motion for Accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark Mode Transitions */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* RTL Support */
[dir="rtl"] .nav-link::after {
    left: auto;
    right: 0;
}

[dir="rtl"] .approved-stage-card {
    border-left: none;
    border-right: 5px solid var(--color-primary);
}

[dir="rtl"] .dark .approved-stage-card {
    border-right-color: var(--color-accent);
}

[dir="rtl"] .approved-stage-card {
    transform: translateX(30px);
}

[dir="rtl"] .approved-stage-card:hover {
    transform: translateX(-5px);
}

/* 7-Part Book Posters Grid */
.book-parts-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    height: 20rem;
}

.book-parts-grid .part-poster {
    position: relative;
    overflow: hidden;
    border-radius: 0.375rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.book-parts-grid .part-poster:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.book-parts-grid .part-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Center the last 3 items on the second row */
.book-parts-grid .part-poster:nth-child(5) {
    grid-column: 2;
}

@media (max-width: 768px) {
    .book-parts-grid {
        grid-template-columns: repeat(3, 1fr);
        height: auto;
    }

    .book-parts-grid .part-poster:nth-child(5) {
        grid-column: auto;
    }

    .book-parts-grid .part-poster:nth-child(7) {
        grid-column: 2;
    }
}

/* ================================
   Color Theme Picker Component
   ================================ */

.theme-picker {
    position: fixed;
    top: 80px;
    left: 24px;
    z-index: 40;
    font-family: 'Cairo', sans-serif;
}

/* Toggle Button */
.theme-picker-toggle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(var(--color-primary-rgb), 0.4);
    transition: all 0.3s ease;
}

.theme-picker-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(var(--color-primary-rgb), 0.5);
}

.theme-picker-toggle:focus {
    outline: 3px solid var(--color-accent);
    outline-offset: 3px;
}

.theme-picker-toggle svg {
    width: 22px;
    height: 22px;
}

/* Panel */
.theme-picker-panel {
    position: absolute;
    top: 58px;
    left: 0;
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 280px;
}

.dark .theme-picker-panel {
    background: #1f2937;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.theme-picker.open .theme-picker-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Title */
.theme-picker-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 16px;
    text-align: center;
}

.dark .theme-picker-title {
    color: var(--color-accent);
}

/* Options Grid */
.theme-picker-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

/* Theme Option Button */
.theme-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 8px;
    border: 2px solid transparent;
    border-radius: 12px;
    background: #f3f4f6;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.dark .theme-option {
    background: #374151;
}

.theme-option:hover {
    border-color: var(--color-secondary);
    transform: translateY(-2px);
}

.theme-option:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.2);
}

.theme-option[aria-selected="true"] {
    border-color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.1);
}

.dark .theme-option[aria-selected="true"] {
    background: rgba(var(--color-primary-rgb), 0.2);
}

/* Color Preview Circle */
.theme-option-color {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Option Name */
.theme-option-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: #4b5563;
}

.dark .theme-option-name {
    color: #d1d5db;
}

/* Checkmark */
.theme-option-check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    background: var(--color-primary);
    color: white;
    border-radius: 50%;
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
}

.theme-option[aria-selected="true"] .theme-option-check {
    display: flex;
}

/* Responsive */
@media (max-width: 640px) {
    .theme-picker {
        top: 70px;
        left: 16px;
    }

    .theme-picker-toggle {
        width: 42px;
        height: 42px;
    }

    .theme-picker-panel {
        min-width: 240px;
        padding: 16px;
    }

    .theme-picker-options {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Animation for toggle rotation */
.theme-picker-toggle.rotating svg {
    animation: spin 0.5s ease;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .theme-picker-panel {
        transition: opacity 0.1s ease;
        transform: none !important;
    }

    .theme-picker-toggle:hover {
        transform: none;
    }

    .theme-picker-toggle.rotating svg {
        animation: none;
    }
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
