/* ==========================================================================
   AcademyOS — قالب الصفحة الرئيسية «حيّ متحرّك»
   يُحمَّل فقط حين يختار المركز هذا القالب (appearance.home_template = motion).

   المبادئ:
   1) لا لون ثابت إلا آليةً مقصودة: كل لون رمزٌ من الثيم، عدا «الحجاب» الداكن
      فوق الترويسة وهو ليس اختيار لون بل ضمانُ تباين (انظر .hm-hero__scrim).
   2) خصائص منطقية حصراً — لا left/right.
   3) الحركة تُلغى تماماً مع prefers-reduced-motion، لا تُبطّأ.
   4) لا تزحزح تراكمي: نحرّك opacity وtransform فقط، والأرقام تُحجز مساحتها
      قبل أي عدّ (في home-motion.js).
   ========================================================================== */


/* ==========================================================================
   1) الترويسة — طبقات عمق: غلاف ← هالتان ← حجاب ← نصّ
   ========================================================================== */

.hm-hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    border-radius: var(--radius-lg);
    min-height: 62vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-7) var(--sp-5);
    text-align: center;
    background: linear-gradient(135deg, var(--brand-secondary), var(--brand-primary));
    box-shadow: var(--shadow);
}

/* svh لا vh حيث يُدعَم: على الجوال يقفز vh مع ظهور شريط المتصفّح واختفائه،
   فترتفع الترويسة وتنزل أثناء التمرير. */
@supports (min-height: 62svh) {
    .hm-hero { min-height: 62svh; }
}

.hm-hero__cover {
    position: absolute;
    inset: 0;
    z-index: -3;
    background-size: cover;
    background-position: center;
}

.hm-hero__glow {
    position: absolute;
    z-index: -2;
    border-radius: var(--radius-pill);
    filter: blur(70px);
    pointer-events: none;
}
.hm-hero__glow.a {
    width: 46%;
    aspect-ratio: 1;
    inset-block-start: -14%;
    inset-inline-end: -8%;
    background: var(--brand-primary);
    opacity: .75;
    animation: hmFloat 11s cubic-bezier(.45, 0, .55, 1) infinite;
}
.hm-hero__glow.b {
    width: 38%;
    aspect-ratio: 1;
    inset-block-end: -16%;
    inset-inline-start: -6%;
    background: var(--brand-secondary);
    opacity: .8;
    animation: hmFloat 14s cubic-bezier(.45, 0, .55, 1) infinite reverse;
}

/* الحجاب: هو ما يجعل النصّ الأبيض مقروءاً مهما كان لون العلامة أو الغلاف.
   القياس لا التقدير — أسوأ حالة ممكنة هي علامة بيضاء نقية (#ffffff):
   0.45 × 255 + 0.55 × 2 ≈ 116 ⇒ #747474 ⇒ تباين الأبيض عليه 4.67:1.
   فأي لون علامة يختاره أي مركز يبقى فوق العتبة 4.5:1. ولهذا كل ما يعلو
   الحجاب من أسطح (الوسم، صفّ الأرقام) شفافٌ داكن لا شفافٌ فاتح — الفاتح
   يرفع الإضاءة تحت النصّ ويكسر هذا الضمان. */
.hm-hero__scrim {
    position: absolute;
    inset: 0;
    z-index: -1;
    background: rgba(2, 6, 23, .55);
}

.hm-hero__inner {
    position: relative;
    width: 100%;
    max-width: 760px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
}

.hm-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 8px 18px;
    border-radius: var(--radius-pill);
    background: rgba(2, 6, 23, .38);
    border: var(--border-w) solid rgba(255, 255, 255, .22);
    color: #ffffff;
    font-size: var(--fs-sm);
    font-weight: 600;
    letter-spacing: 0;
}

.hm-title {
    font-family: var(--font-display);
    font-size: clamp(1.9rem, 5.2vw, 3.4rem);
    line-height: 1.35;
    font-weight: var(--heading-weight, 700);
    color: #ffffff;
    margin: 0;
    letter-spacing: 0;
}

.hm-lede {
    /* أبيض كامل لا شفّاف: خفض الشفافية إلى 0.96 يهبط بالتباين تحت 4.5 في أسوأ
       حالة الحجاب. التراتب يُبنى بالحجم والوزن لا بإضعاف اللون. */
    color: #ffffff;
    font-size: var(--fs-lg);
    line-height: var(--lh-body);
    max-width: 60ch;
    margin: 0;
}

.hm-hero__actions { margin-block-start: var(--sp-3); }

.hm-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: 52px;
    padding: 0 30px;
    background: #ffffff;
    color: var(--home-brand-on-light);
    border-radius: var(--radius-sm);
    font-size: var(--fs-lg);
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 10px 30px rgba(2, 6, 23, .3);
    transition:
        transform var(--dur) var(--ease),
        box-shadow var(--dur) var(--ease);
}
.hm-cta:hover { transform: translateY(-3px); box-shadow: 0 18px 42px rgba(2, 6, 23, .38); }
.hm-cta:active { transform: translateY(-1px); }
.hm-cta:focus-visible { outline: var(--ring) solid #ffffff; outline-offset: 3px; }

/* أيقونة اتجاهية: تُقلب مع اتجاه القراءة. رُسمت متّجهةً يميناً ثم تُعكس في RTL
   فتشير إلى جهة «التالي» الفعلية. */
.hm-cta__arrow { flex: none; transition: transform var(--dur) var(--ease); }
html[dir="rtl"] .hm-cta__arrow { transform: scaleX(-1); }
.hm-cta:hover .hm-cta__arrow { transform: translateX(4px); }
html[dir="rtl"] .hm-cta:hover .hm-cta__arrow { transform: scaleX(-1) translateX(4px); }


/* ==========================================================================
   2) الأرقام — داخل الترويسة نفسها، صفّ زجاجي لا بطاقات منفصلة
   ========================================================================== */

.hm-figures {
    width: 100%;
    margin-block-start: var(--sp-5);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-2);
    padding: var(--sp-4) var(--sp-3);
    border-radius: var(--radius);
    background: rgba(2, 6, 23, .34);
    border: var(--border-w) solid rgba(255, 255, 255, .18);
}
@supports (backdrop-filter: blur(10px)) {
    .hm-figures { backdrop-filter: blur(12px) saturate(140%); }
}

.hm-figure { text-align: center; }
.hm-figure + .hm-figure { border-inline-start: var(--border-w) solid rgba(255, 255, 255, .18); }

.hm-figure__n {
    font-family: var(--font-display);
    font-size: clamp(1.35rem, 3.4vw, 2rem);
    font-weight: 700;
    line-height: 1.25;
    color: #ffffff;
}
.hm-figure__l {
    margin-block-start: 4px;
    font-size: var(--fs-xs);
    color: #ffffff;
    /* الشفافية الوحيدة المسموح بها هنا، ومحسوبة: فوق الطبقتين (حجاب 0.55 ثم
       لوح 0.34) وبأسوأ لون علامة ممكن (أبيض نقي) يبقى التباين 6.93:1. */
    opacity: .88;
}


/* ==========================================================================
   3) الدورات — شبكة بطاقات
   ========================================================================== */

.hm-catalog { margin-block-start: var(--sp-6); }

.hm-catalog__head {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin-block-end: var(--sp-5);
}

.hm-kicker {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--home-accent);
}

.hm-catalog__head h2 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3.6vw, 2.1rem);
    line-height: var(--lh-tight);
    color: var(--heading);
    margin: 0;
}

.hm-catalog__lead {
    color: var(--text-muted);
    font-size: var(--fs-base);
    line-height: var(--lh-snug);
    max-width: 62ch;
    margin: 0;
}

.hm-search {
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
    margin-block-end: var(--sp-5);
}
.hm-search input[type=text] { flex: 1 1 220px; min-width: 0; width: auto; }
.hm-search select { flex: 0 1 160px; width: auto; }

.hm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--sp-4);
}

.hm-card {
    position: relative;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    background: var(--panel);
    border: var(--border-w) solid var(--panel-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--dur) var(--ease),
        box-shadow var(--dur) var(--ease),
        border-color var(--dur) var(--ease);
}
.hm-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
    border-color: var(--home-accent);
}
.hm-card:focus-visible { outline: var(--ring) solid var(--home-accent); outline-offset: 3px; }

.hm-card__thumb {
    display: block;
    aspect-ratio: 16 / 9;
    background-color: var(--surface-2);
    background-size: cover;
    background-position: center;
    transition: transform var(--dur-slow) var(--ease);
}
.hm-card:hover .hm-card__thumb { transform: scale(1.05); }

.hm-card__body {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    flex: 1;
    padding: var(--sp-4);
}
.hm-card__title {
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: var(--lh-snug);
    color: var(--heading);
}
.hm-card__by { font-size: var(--fs-xs); color: var(--text-muted); }

.hm-card__foot {
    margin-block-start: auto;
    padding-block-start: var(--sp-3);
    border-block-start: var(--border-w) solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    flex-wrap: wrap;
}
.hm-price { font-weight: 700; color: var(--home-accent); font-size: var(--fs-sm); }
.hm-price.is-free { color: var(--ok); }
.hm-card__more { font-size: var(--fs-xs); color: var(--text-muted); }

.hm-empty { grid-column: 1 / -1; }


/* ==========================================================================
   4) عن المركز — عمودان، عنوان يرافق النصّ
   ========================================================================== */

.hm-about {
    margin-block-start: var(--sp-6);
    display: grid;
    grid-template-columns: minmax(200px, 1fr) 2fr;
    gap: var(--sp-5);
    padding: var(--sp-6) var(--sp-5);
    background: var(--panel);
    border: var(--border-w) solid var(--panel-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.hm-about__aside { position: sticky; top: 84px; align-self: start; }
.hm-about__aside h2 {
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    line-height: var(--lh-tight);
    color: var(--heading);
    margin-block-start: var(--sp-2);
}
.hm-about__body p {
    color: var(--text);
    line-height: var(--lh-body);
    white-space: pre-line;
    margin: 0;
}


/* ==========================================================================
   5) الدعوة الختامية
   ========================================================================== */

.hm-final {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    margin-block-start: var(--sp-6);
    padding: var(--sp-7) var(--sp-5);
    border-radius: var(--radius-lg);
    text-align: center;
    background: linear-gradient(120deg, var(--brand-primary), var(--brand-secondary));
    box-shadow: var(--shadow);
}
.hm-final__glow {
    position: absolute;
    z-index: -2;
    width: 55%;
    aspect-ratio: 1;
    inset-block-start: -30%;
    inset-inline-start: 10%;
    border-radius: var(--radius-pill);
    background: var(--brand-primary);
    filter: blur(80px);
    opacity: .8;
    animation: hmFloat 13s cubic-bezier(.45, 0, .55, 1) infinite;
}
/* نفس ضمان التباين المشروح أعلاه، بالقيمة نفسها. */
.hm-final__scrim { position: absolute; inset: 0; z-index: -1; background: rgba(2, 6, 23, .55); }

.hm-final__inner {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
}
.hm-final__inner h2 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 4vw, 2.3rem);
    line-height: var(--lh-tight);
    color: #ffffff;
    margin: 0;
    max-width: 22ch;
}
.hm-final__inner .hm-cta { margin-block-start: var(--sp-2); }


/* ==========================================================================
   6) الحركة — كشف بالتمرير بتتابع
   الكشف نفسه من academyos.css (.reveal + .in)؛ هنا التأخير المتدرّج فقط.
   ========================================================================== */

.js-reveal .hm-card.reveal { transition-delay: calc(var(--i, 0) * 70ms); }

@keyframes hmFloat {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(0, -26px, 0) scale(1.06); }
}


/* ==========================================================================
   7) القياسات الصغيرة — 768 / 480 / 320
   ========================================================================== */

@media (max-width: 860px) {
    .hm-about { grid-template-columns: 1fr; }
    .hm-about__aside { position: static; }
}

@media (max-width: 620px) {
    .hm-hero { min-height: 0; padding: var(--sp-6) var(--sp-4); }
    /* الأرقام تبقى صفّاً من ثلاثة حتى 320: تكديسها عمودياً قِيس فأضاف ~230px
       إلى ارتفاع الترويسة ودفع الدورات خارج أول شاشة. تُضغط ولا تُكدَّس. */
    .hm-figures { gap: 0; padding: var(--sp-3) var(--sp-2); }
    .hm-figure { padding-inline: 2px; }
    .hm-figure__l { font-size: 11px; line-height: 1.55; }
    .hm-grid { grid-template-columns: 1fr; }
    .hm-about, .hm-final { padding: var(--sp-5) var(--sp-4); }
    .hm-search input[type=text],
    .hm-search select,
    .hm-search .btn { flex: 1 1 100%; width: 100%; }
}

@media (max-width: 360px) {
    .hm-cta { padding: 0 20px; font-size: var(--fs-base); }
}


/* ==========================================================================
   8) تقليل الحركة — إيقاف لا إبطاء
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .hm-hero__glow,
    .hm-final__glow { animation: none; }
    .hm-card,
    .hm-card__thumb,
    .hm-cta,
    .hm-cta__arrow { transition: none; }
    .hm-card:hover { transform: none; }
    .hm-card:hover .hm-card__thumb { transform: none; }
    .hm-cta:hover { transform: none; }
    .hm-cta:hover .hm-cta__arrow { transform: none; }
    html[dir="rtl"] .hm-cta:hover .hm-cta__arrow { transform: scaleX(-1); }
    .js-reveal .hm-card.reveal { transition-delay: 0s; }
}
