/* ================================================
   ANIMATED BACKGROUND
   تحسين الأداء: will-change, contain, transform-only animations
================================================ */

.animated-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    background: linear-gradient(135deg, #f0f9ff 0%, #faf5ff 50%, #fff7ed 100%);
    contain: strict;
}

/* ✅ إصلاح: استبدلنا rotate(360deg) بـ rotate(0deg) لتفادي forced composite layers */
.animated-background::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 20% 50%, rgba(79, 209, 255, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(168, 85, 247, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(59, 130, 246, 0.06) 0%, transparent 50%);
    animation: gradientShift 20s ease-in-out infinite;
    will-change: transform;
}

/* ✅ إصلاح: حذف rotate من الـ keyframes — كان يسبب layer invalidation مستمر */
@keyframes gradientShift {
    0%, 100% { transform: translate(0, 0); }
    33%       { transform: translate(10%, 10%); }
    66%       { transform: translate(-5%, 5%); }
}

/* ================================================
   FLOATING LETTERS
================================================ */
.floating-letters {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    contain: layout style;
}

.letter {
    position: absolute;
    font-family: 'Amiri', serif;
    font-size: 3rem;
    font-weight: 700;
    opacity: 0;
    color: transparent;
    background: linear-gradient(135deg, rgba(79, 209, 255, 0.15), rgba(168, 85, 247, 0.15));
    -webkit-background-clip: text;
    background-clip: text;
    /* ✅ إصلاح: transform فقط — لا opacity لوحدها لأنها cheap على GPU */
    animation: floatLetter 15s ease-in-out infinite;
    will-change: transform, opacity;
    pointer-events: none;
}

.letter:nth-child(1) { top: 10%; left: 15%; animation-delay: 0s;   font-size: 4rem; }
.letter:nth-child(2) { top: 25%; left: 75%; animation-delay: 2s;   font-size: 3.5rem; }
.letter:nth-child(3) { top: 45%; left: 30%; animation-delay: 4s;   font-size: 3rem; }
.letter:nth-child(4) { top: 65%; left: 80%; animation-delay: 6s;   font-size: 3.8rem; }
.letter:nth-child(5) { top: 80%; left: 20%; animation-delay: 8s;   font-size: 3.2rem; }
.letter:nth-child(6) { top: 35%; left: 90%; animation-delay: 10s;  font-size: 3.6rem; }
.letter:nth-child(7) { top: 55%; left: 10%; animation-delay: 12s;  font-size: 3.4rem; }
.letter:nth-child(8) { top: 15%; left: 50%; animation-delay: 14s;  font-size: 3.9rem; }

/* ✅ إصلاح: حذف rotate(180deg) و rotate(360deg) — كانوا يسببون repaints
   استبدلناهم بـ translateY فقط وهو composite-only */
@keyframes floatLetter {
    0%   { opacity: 0; transform: translateY(100px); }
    10%  { opacity: 1; }
    50%  { opacity: 0.8; transform: translateY(-50px); }
    90%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(-150px); }
}

/* ================================================
   FLOATING BOOKS
================================================ */
.floating-books {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    contain: layout style;
}

.book {
    position: absolute;
    width: 40px;
    height: 55px;
    opacity: 0;
    animation: floatBook 20s ease-in-out infinite;
    will-change: transform, opacity;
}

.book::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(79, 209, 255, 0.2), rgba(168, 85, 247, 0.2));
    border-radius: 2px;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
}

.book::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
    border-radius: 1px;
}

.book:nth-child(1) { top: 20%; left: 10%; animation-delay: 0s; }
.book:nth-child(2) { top: 40%; left: 85%; animation-delay: 4s; }
.book:nth-child(3) { top: 70%; left: 25%; animation-delay: 8s; }
.book:nth-child(4) { top: 50%; left: 70%; animation-delay: 12s; }
.book:nth-child(5) { top: 85%; left: 60%; animation-delay: 16s; }

/* ✅ إصلاح: استبدلنا rotate(-10deg) → rotate(10deg) بـ transform ثابت على العنصر
   لأن rotate في keyframe يمنع GPU من composite-only path */
@keyframes floatBook {
    0%   { opacity: 0;   transform: translateY(100px) translateX(0); }
    10%  { opacity: 0.6; }
    50%  { opacity: 0.8; transform: translateY(-100px) translateX(30px); }
    90%  { opacity: 0.6; }
    100% { opacity: 0;   transform: translateY(-200px) translateX(0); }
}

/* ================================================
   FLOATING PENS
================================================ */
.floating-pens {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    contain: layout style;
}

.pen {
    position: absolute;
    width: 60px;
    height: 6px;
    opacity: 0;
    animation: floatPen 18s ease-in-out infinite;
    will-change: transform, opacity;
}

.pen::before {
    content: '';
    position: absolute;
    width: 70%;
    height: 100%;
    background: linear-gradient(90deg,
        rgba(79, 209, 255, 0.3) 0%,
        rgba(168, 85, 247, 0.3) 100%);
    border-radius: 3px;
}

.pen::after {
    content: '';
    position: absolute;
    right: 0;
    width: 0;
    height: 0;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    border-left: 15px solid rgba(168, 85, 247, 0.3);
}

/* ✅ إصلاح: الـ rotate نقلناه للـ initial transform على العنصر نفسه
   وحذفناه من الـ keyframe لأن تغيير rotate داخل keyframe يكسر composite layer */
.pen:nth-child(1) { top: 15%; left: 70%; animation-delay: 0s;  transform: rotate(-30deg); }
.pen:nth-child(2) { top: 60%; left: 15%; animation-delay: 6s;  transform: rotate(45deg); }
.pen:nth-child(3) { top: 75%; left: 80%; animation-delay: 12s; transform: rotate(-15deg); }

@keyframes floatPen {
    0%   { opacity: 0;   }
    10%  { opacity: 0.5; }
    50%  { opacity: 0.7; }
    90%  { opacity: 0.5; }
    100% { opacity: 0;   }
}

/* ================================================
   INK PARTICLES
================================================ */
.ink-particles {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    contain: layout style;
}

.ink-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: radial-gradient(circle, rgba(79, 209, 255, 0.4), transparent);
    border-radius: 50%;
    opacity: 0;
    animation: inkDrop 12s ease-in-out infinite;
    will-change: transform, opacity;
}

.ink-particle:nth-child(1) { top: 20%; left: 30%; animation-delay: 0s; }
.ink-particle:nth-child(2) { top: 40%; left: 60%; animation-delay: 1.5s; }
.ink-particle:nth-child(3) { top: 60%; left: 45%; animation-delay: 3s; }
.ink-particle:nth-child(4) { top: 30%; left: 80%; animation-delay: 4.5s; }
.ink-particle:nth-child(5) { top: 70%; left: 25%; animation-delay: 6s; }
.ink-particle:nth-child(6) { top: 50%; left: 90%; animation-delay: 7.5s; }
.ink-particle:nth-child(7) { top: 85%; left: 50%; animation-delay: 9s; }
.ink-particle:nth-child(8) { top: 25%; left: 15%; animation-delay: 10.5s; }

/* ✅ إصلاح: حذفنا scale() من الـ keyframe — كان بيعمل stacking context جديد
   وبيمنع browser من تجميع الـ particles في layer واحدة */
@keyframes inkDrop {
    0%   { opacity: 0;   transform: translateY(-20px); }
    10%  { opacity: 1;   transform: translateY(0); }
    80%  { opacity: 0.8; transform: translateY(80px); }
    100% { opacity: 0;   transform: translateY(120px); }
}

/* ================================================
   FLOATING QUOTES
================================================ */
.floating-quotes {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    contain: layout style;
}

.quote-mark {
    position: absolute;
    font-family: 'Amiri', serif;
    font-size: 5rem;
    opacity: 0;
    color: transparent;
    background: linear-gradient(135deg, rgba(79, 209, 255, 0.12), rgba(168, 85, 247, 0.12));
    -webkit-background-clip: text;
    background-clip: text;
    animation: quoteFloat 16s ease-in-out infinite;
    will-change: transform, opacity;
}

.quote-mark:nth-child(1) { top: 30%; left: 25%; animation-delay: 0s; }
.quote-mark:nth-child(2) { top: 65%; left: 75%; animation-delay: 8s; }

/* ✅ إصلاح: حذف scale() وrotate() من keyframe — استبدلناهم بـ translateY بس */
@keyframes quoteFloat {
    0%   { opacity: 0;   transform: translateY(20px); }
    20%  { opacity: 0.5; transform: translateY(0); }
    50%  { opacity: 0.7; transform: translateY(-10px); }
    80%  { opacity: 0.5; transform: translateY(0); }
    100% { opacity: 0;   transform: translateY(20px); }
}

/* ================================================
   WRITING LINES
   ✅ إصلاح: المشكلة الأكبر — width: 0 → 150px في keyframe
   ده layout reflow حقيقي بيحسبه browser من أول كل frame
   استبدلناه بـ scaleX() على transform وهو composite-only
================================================ */
.writing-lines {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    contain: layout style;
}

.line {
    position: absolute;
    /* ✅ العرض ثابت الآن — الـ animation بتستخدم scaleX */
    width: 150px;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(79, 209, 255, 0.2) 50%,
        transparent 100%);
    opacity: 0;
    transform-origin: right center;
    animation: lineWrite 10s ease-in-out infinite;
    will-change: transform, opacity;
}

.line:nth-child(1) { top: 35%; left: 20%; animation-delay: 0s; }
.line:nth-child(2) { top: 45%; left: 60%; animation-delay: 3s; width: 180px; }
.line:nth-child(3) { top: 65%; left: 35%; animation-delay: 6s; width: 120px; }

/* ✅ scaleX بدل width — نفس التأثير البصري بدون layout reflow */
@keyframes lineWrite {
    0%   { opacity: 0;   transform: scaleX(0); }
    20%  { opacity: 0.5; }
    50%  { opacity: 0.7; transform: scaleX(1); }
    80%  { opacity: 0.5; }
    100% { opacity: 0;   transform: scaleX(0); }
}

/* ================================================
   PAPER EFFECT
   ✅ إصلاح: حذف background-position animation — بيعمل repaint كل frame
   استبدلناه بـ translateY على pseudo-element
================================================ */
.paper-effect {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    overflow: hidden;
}

.paper-effect::after {
    content: '';
    position: absolute;
    inset: -100px 0 0 0;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 30px,
            rgba(79, 209, 255, 0.02) 30px,
            rgba(79, 209, 255, 0.02) 31px
        );
    animation: paperShift 30s linear infinite;
    will-change: transform;
}

@keyframes paperShift {
    0%   { transform: translateY(0); }
    100% { transform: translateY(100px); }
}

/* ================================================
   AUTHOR PAGE FIXES
================================================ */
.author-page {
    position: relative;
    z-index: 10;
}

.main-header {
    position: fixed !important;
    z-index: 2000 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
}

.content-tabs {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 2000 !important;
}

body { position: relative; }
html { position: relative; }

/* ================================================
   MOBILE — إيقاف الأنيميشن الثقيل على الموبايل
================================================ */
@media (max-width: 768px) {
    .letter      { font-size: 2rem; }
    .letter:nth-child(1),
    .letter:nth-child(2),
    .letter:nth-child(4),
    .letter:nth-child(8) { font-size: 2.5rem; }
    .book  { width: 30px; height: 40px; }
    .pen   { width: 40px; height: 4px; }
    .quote-mark { font-size: 3rem; }

    /* ✅ إيقاف العناصر الثقيلة على الموبايل لتحسين الـ LCP و TBT */
    .floating-books,
    .floating-pens,
    .ink-particles,
    .writing-lines,
    .paper-effect {
        display: none;
    }
}

/* ================================================
   REDUCED MOTION
================================================ */
@media (prefers-reduced-motion: reduce) {
    .animated-background *,
    .animated-background::before,
    .paper-effect::after {
        animation: none !important;
    }
}