/* ============================================================
   خوارزميات — هيرو «نسيج المعرفة الحيّ»
   Live Knowledge Network Hero
   الأبعاد: 698px ديسكتوب (≥1200) / 880px دونها — عرض 100%
   ============================================================ */

.khw-hero {
    --khw-green: #2eb97e;
    --khw-green-soft: #7fe3b0;
    --khw-green-deep: #0a2e1f;
    --khw-navy: #1f4068;
    --khw-orange: #ff9f45;
    --khw-glow: 0.35;
    position: relative;
    width: 100%;
    height: 880px;
    overflow: hidden;
    direction: rtl;
    background-color: #04180f;
    isolation: isolate;
    z-index: 1;
}

@media (min-width: 1200px) {
    .khw-hero { height: 698px; }
}

/* ---------- الخلفية المتدرجة (تظهر فوراً قبل تحميل WebGL) ---------- */
.khw-hero__bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(ellipse 90% 75% at 68% 42%, rgba(15, 77, 51, 0.55) 0%, transparent 62%),
        radial-gradient(ellipse 70% 90% at 22% 60%, rgba(10, 55, 36, 0.65) 0%, transparent 70%),
        radial-gradient(ellipse 130% 110% at 50% 50%, #0a2e1f 0%, #04180f 100%);
}

/* فينييت سينمائي */
.khw-hero__bg::after {
    content: "";
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 180px 40px rgba(2, 12, 8, 0.55);
    pointer-events: none;
}

.khw-hero__canvas {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: block;
    opacity: 0;
    transition: opacity 0.45s ease;
}

.khw-hero__canvas.is-on { opacity: 1; }

/* ---------- درع حماية قراءة النص (WCAG) ---------- */
/* طبقتان: تعتيم مركّز خلف كتلة النص (يمين) + تدرّج أفقي عام يبتلع وهج الجسيمات */
.khw-hero__shield {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background:
        radial-gradient(ellipse 78% 105% at 80% 50%, rgba(2, 14, 9, 0.94) 0%, rgba(2, 14, 9, 0.78) 40%, rgba(2, 14, 9, 0.4) 64%, rgba(2, 14, 9, 0.12) 78%, transparent 88%),
        linear-gradient(270deg, rgba(3, 18, 11, 0.9) 0%, rgba(3, 18, 11, 0.72) 30%, rgba(3, 18, 11, 0.42) 50%, rgba(3, 18, 11, 0.12) 66%, transparent 76%);
}

/* تعتيم إضافي خفيف لكامل المشهد يخفض سطوع الجسيمات دون إطفائها */
.khw-hero__shield::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(3, 18, 11, 0.2);
}

@media (max-width: 991px) {
    .khw-hero__shield {
        background:
            radial-gradient(ellipse 120% 55% at 50% 88%, rgba(3, 17, 11, 0.9) 0%, rgba(3, 17, 11, 0.55) 45%, transparent 78%),
            linear-gradient(0deg, rgba(4, 22, 14, 0.88) 0%, rgba(4, 22, 14, 0.45) 42%, transparent 72%);
    }
}

/* ---------- طبقة المحتوى ---------- */
.khw-hero__inner {
    position: relative;
    z-index: 3;
    height: 100%;
    display: flex;
    align-items: center;
}

.khw-hero__content {
    max-width: 600px;
    padding: 24px 0;
    will-change: transform, opacity;
}

@media (max-width: 991px) {
    .khw-hero__inner { align-items: flex-end; }
    .khw-hero__content { padding-bottom: 96px; }
}

/* السطر التمهيدي */
.khw-hero__kicker {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: "Tajawal", sans-serif;
    font-size: 15px;
    font-weight: 700;
    color: #a8ecc9;
    margin: 0 0 18px;
    text-shadow: 0 1px 8px rgba(3, 17, 11, 0.9), 0 0 18px rgba(3, 17, 11, 0.7);
    transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

/* الإخفاء الابتدائي مشروط بتسليح السكربت — لو فشل تحميله يبقى المحتوى ظاهراً */
.khw-hero.is-armed .khw-hero__kicker {
    opacity: 0;
    transform: translateY(18px);
}

.khw-hero__kicker::before {
    content: "";
    width: 34px;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(270deg, var(--khw-green), transparent);
}

/* اسم الموقع */
.khw-hero__title {
    font-family: "Tajawal", sans-serif;
    font-size: clamp(52px, 6.4vw, 92px);
    font-weight: 800;
    line-height: 1.08;
    color: #ffffff;
    margin: 0 0 14px;
    text-shadow:
        0 2px 20px rgba(3, 17, 11, 0.75),
        0 0 40px rgba(3, 17, 11, 0.5),
        0 0 24px rgba(46, 185, 126, calc(var(--khw-glow) * 0.9));
    transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.khw-hero.is-armed .khw-hero__title {
    opacity: 0;
    transform: translateY(26px);
}

.khw-hero.is-typo .khw-hero__kicker,
.khw-hero.is-typo .khw-hero__title {
    opacity: 1;
    transform: translateY(0);
}

/* الشعار */
.khw-hero__tagline {
    font-family: "Tajawal", sans-serif;
    font-size: clamp(17px, 2vw, 23px);
    font-weight: 500;
    line-height: 1.75;
    color: #e4f4ec;
    margin: 0 0 34px;
    max-width: 480px;
    text-shadow: 0 2px 14px rgba(3, 17, 11, 0.92), 0 0 26px rgba(3, 17, 11, 0.6);
    transition: clip-path 1s cubic-bezier(0.4, 0, 0.2, 1) 0.15s;
}

.khw-hero.is-armed .khw-hero__tagline { clip-path: inset(0 0 0 100%); }

.khw-hero.is-typo .khw-hero__tagline { clip-path: inset(0 0 0 0%); }

.khw-hero__tagline .khw-accent {
    color: var(--khw-orange);
    font-weight: 700;
    position: relative;
    white-space: nowrap;
}

.khw-hero__tagline .khw-accent svg {
    position: absolute;
    right: 0;
    bottom: -7px;
    width: 100%;
    height: 8px;
    overflow: visible;
}

.khw-hero__tagline .khw-accent svg path {
    fill: none;
    stroke: var(--khw-orange);
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-dasharray: 120;
    stroke-dashoffset: 120;
    opacity: 0.85;
}

/* ---------- شريط البحث (منقول من الهيدر) ---------- */
.khw-hero__search {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 460px;
    margin: 0 0 26px;
    padding: 7px 7px 7px 18px;
    border-radius: 999px;
    background: rgba(6, 35, 26, 0.55);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(127, 227, 176, 0.28);
    box-shadow: 0 10px 30px -14px rgba(2, 12, 8, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: border-color 0.3s ease, box-shadow 0.3s ease,
        opacity 0.7s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

@supports not ((backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px))) {
    .khw-hero__search { background: rgba(8, 38, 26, 0.9); }
}

.khw-hero.is-armed .khw-hero__search {
    opacity: 0;
    transform: translateY(18px);
}

.khw-hero.is-typo .khw-hero__search {
    opacity: 1;
    transform: translateY(0);
    transition: border-color 0.3s ease, box-shadow 0.3s ease,
        opacity 0.7s ease 0.28s, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.28s;
}

.khw-hero__search:focus-within {
    border-color: var(--khw-green-soft);
    box-shadow: 0 12px 34px -12px rgba(2, 12, 8, 0.7), 0 0 0 4px rgba(46, 185, 126, 0.16);
}

.khw-hero__search-icon {
    color: var(--khw-green-soft);
    font-size: 16px;
    flex: 0 0 auto;
}

.khw-hero__search input {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    font-family: "Tajawal", sans-serif;
    font-size: 16px;
    font-weight: 500;
    color: #f2fbf6;
    padding: 8px 4px;
}

.khw-hero__search input::placeholder {
    color: rgba(159, 212, 184, 0.8);
    font-weight: 400;
}

.khw-hero__search-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: "Tajawal", sans-serif;
    font-size: 15.5px;
    font-weight: 700;
    color: #06231a;
    background: linear-gradient(135deg, var(--khw-green-soft) 0%, var(--khw-green) 55%);
    border: none;
    border-radius: 999px;
    padding: 11px 22px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(46, 185, 126, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.3s ease;
}

.khw-hero__search-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(46, 185, 126, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.khw-hero__search-btn i { display: none; }

.khw-hero__search-btn:focus-visible {
    outline: 2px solid var(--khw-green-soft);
    outline-offset: 3px;
}

@media (max-width: 575px) {
    .khw-hero__search { padding: 6px 6px 6px 14px; margin-bottom: 20px; }
    .khw-hero__search input { font-size: 15px; }
    .khw-hero__search-btn span { display: none; }
    .khw-hero__search-btn i { display: inline-block; }
    .khw-hero__search-btn { padding: 11px 14px; }
}

.khw-hero.is-underline .khw-accent svg path {
    animation: khwDrawLine 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes khwDrawLine {
    to { stroke-dashoffset: 0; }
}

/* زر CTA */
.khw-hero__cta {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-family: "Tajawal", sans-serif;
    font-size: 17px;
    font-weight: 700;
    color: #06231a;
    background: linear-gradient(135deg, var(--khw-green-soft) 0%, var(--khw-green) 55%);
    border-radius: 999px;
    padding: 15px 34px;
    text-decoration: none;
    box-shadow: 0 8px 28px rgba(46, 185, 126, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease;
}

.khw-hero.is-armed .khw-hero__cta {
    opacity: 0;
    transform: translateY(20px);
}

.khw-hero.is-typo .khw-hero__cta {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.7s ease 0.35s, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.35s, box-shadow 0.35s ease;
}

.khw-hero__cta:hover {
    color: #06231a;
    transform: translateY(-3px);
    box-shadow: 0 14px 36px rgba(46, 185, 126, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.khw-hero__cta i { transition: transform 0.3s ease; }
.khw-hero__cta:hover i { transform: translateX(-5px); }

/* ---------- كبسولة عدّاد الزوار ---------- */
.khw-hero__counter {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    margin-top: 38px;
    padding: 13px 22px;
    border-radius: 16px;
    background: rgba(10, 46, 31, 0.55);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(127, 227, 176, calc(0.18 + var(--khw-glow) * 0.3));
    transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.6s ease;
}

.khw-hero.is-armed .khw-hero__counter {
    opacity: 0;
    transform: translateY(16px);
}

@supports not ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
    .khw-hero__counter { background: rgba(8, 38, 26, 0.88); }
}

.khw-hero.is-counter .khw-hero__counter {
    opacity: 1;
    transform: translateY(0);
}

.khw-hero__counter-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--khw-green-soft);
    box-shadow: 0 0 10px 2px rgba(127, 227, 176, 0.65);
    animation: khwDotPulse 2.6s ease-in-out infinite;
}

@keyframes khwDotPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.72); opacity: 0.6; }
}

.khw-hero__count {
    font-family: "Tajawal", sans-serif;
    font-variant-numeric: tabular-nums;
    font-size: 26px;
    font-weight: 800;
    color: #f2fbf6;
    line-height: 1;
}

.khw-hero__count::after {
    content: "+";
    color: var(--khw-orange);
    margin-right: 2px;
}

.khw-hero__counter-label {
    font-family: "Tajawal", sans-serif;
    font-size: 13.5px;
    font-weight: 400;
    color: #9fd4b8;
}

/* ---------- كرات البوكيه الأمامية (عمق DOM) ---------- */
.khw-hero__bokeh {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    will-change: transform;
}

.khw-hero__bokeh span {
    position: absolute;
    border-radius: 50%;
    filter: blur(7px);
    opacity: 0.5;
    animation: khwBokehFloat 12s ease-in-out infinite;
}

.khw-hero__bokeh span:nth-child(1) {
    width: 34px; height: 34px; top: 22%; left: 14%;
    background: radial-gradient(circle, rgba(127, 227, 176, 0.75) 0%, transparent 70%);
    animation-duration: 13s;
}

.khw-hero__bokeh span:nth-child(2) {
    width: 18px; height: 18px; top: 64%; left: 32%;
    background: radial-gradient(circle, rgba(255, 159, 69, 0.65) 0%, transparent 70%);
    animation-duration: 10s; animation-delay: -4s;
}

.khw-hero__bokeh span:nth-child(3) {
    width: 26px; height: 26px; top: 38%; left: 56%;
    background: radial-gradient(circle, rgba(46, 185, 126, 0.6) 0%, transparent 70%);
    animation-duration: 15s; animation-delay: -7s;
}

.khw-hero__bokeh span:nth-child(4) {
    width: 14px; height: 14px; top: 76%; left: 70%;
    background: radial-gradient(circle, rgba(31, 64, 104, 0.9) 0%, transparent 70%);
    animation-duration: 11s; animation-delay: -2s;
}

@keyframes khwBokehFloat {
    0%, 100% { transform: translate3d(0, 0, 0); }
    33% { transform: translate3d(9px, -14px, 0); }
    66% { transform: translate3d(-7px, 8px, 0); }
}

/* ---------- مؤشر التمرير ---------- */
.khw-hero__scrollcue {
    position: absolute;
    bottom: 26px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    width: 24px;
    height: 38px;
    border: 2px solid rgba(207, 233, 219, 0.35);
    border-radius: 14px;
    opacity: 0;
    transition: opacity 1s ease;
    pointer-events: none;
}

.khw-hero.is-idle .khw-hero__scrollcue { opacity: 0.7; }

.khw-hero__scrollcue::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    width: 4px;
    height: 8px;
    margin-left: -2px;
    border-radius: 3px;
    background: var(--khw-green-soft);
    animation: khwScrollCue 2s ease-in-out infinite;
}

@keyframes khwScrollCue {
    0% { transform: translateY(0); opacity: 1; }
    70% { transform: translateY(11px); opacity: 0; }
    100% { transform: translateY(0); opacity: 0; }
}

/* ---------- زر إيقاف الحركة (وصولية) ---------- */
.khw-hero__pause {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 6;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(207, 233, 219, 0.6);
    background: rgba(6, 35, 26, 0.45);
    color: rgba(207, 233, 219, 0.95);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.75;
    transition: opacity 0.3s ease, background 0.3s ease;
    padding: 0;
}

.khw-hero__pause:hover,
.khw-hero__pause:focus-visible { opacity: 1; background: rgba(6, 35, 26, 0.75); }

.khw-hero__pause:focus-visible,
.khw-hero__cta:focus-visible {
    outline: 2px solid var(--khw-green-soft);
    outline-offset: 3px;
}
.khw-hero__pause svg { width: 14px; height: 14px; fill: currentColor; }
.khw-hero__pause .khw-ic-play { display: none; }
.khw-hero.is-paused .khw-hero__pause .khw-ic-play { display: block; }
.khw-hero.is-paused .khw-hero__pause .khw-ic-pause { display: none; }

/* ---------- fallback (بلا WebGL / reduced motion) ---------- */
.khw-hero__fallback {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: none;
    pointer-events: none;
}

.khw-hero__fallback span {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(127, 227, 176, 0.8) 0%, transparent 70%);
    animation: khwDotPulse 4s ease-in-out infinite;
}

.khw-hero__fallback span:nth-child(1) { width: 10px; height: 10px; top: 30%; left: 18%; }
.khw-hero__fallback span:nth-child(2) { width: 7px; height: 7px; top: 52%; left: 30%; animation-delay: -1s; }
.khw-hero__fallback span:nth-child(3) { width: 12px; height: 12px; top: 24%; left: 46%; animation-delay: -2s; }
.khw-hero__fallback span:nth-child(4) { width: 8px; height: 8px; top: 66%; left: 55%; animation-delay: -0.5s; background: radial-gradient(circle, rgba(255, 159, 69, 0.7) 0%, transparent 70%); }
.khw-hero__fallback span:nth-child(5) { width: 9px; height: 9px; top: 44%; left: 68%; animation-delay: -3s; background: radial-gradient(circle, rgba(31, 64, 104, 1) 0%, transparent 70%); }
.khw-hero__fallback span:nth-child(6) { width: 6px; height: 6px; top: 58%; left: 12%; animation-delay: -2.5s; }

.khw-hero.is-fallback .khw-hero__fallback { display: block; }
.khw-hero.is-fallback .khw-hero__canvas { display: none; }
.khw-hero.is-fallback .khw-hero__pause,
.khw-hero.is-fallback .khw-hero__scrollcue { display: none; }

/* في وضع fallback أو reduced-motion: كل النصوص ظاهرة فوراً */
.khw-hero.is-static .khw-hero__kicker,
.khw-hero.is-static .khw-hero__title,
.khw-hero.is-static .khw-hero__search,
.khw-hero.is-static .khw-hero__cta {
    opacity: 1;
    transform: none;
    transition: none;
}

.khw-hero.is-static .khw-hero__tagline { clip-path: none; transition: none; }
.khw-hero.is-static .khw-hero__counter { opacity: 1; transform: none; transition: none; }
.khw-hero.is-static .khw-accent svg path { stroke-dashoffset: 0; animation: none; }

@media (prefers-reduced-motion: reduce) {
    .khw-hero__bokeh span,
    .khw-hero__fallback span,
    .khw-hero__counter-dot,
    .khw-hero__scrollcue::before { animation: none !important; }
}

