/* طبقة الحركة المشتركة لغطاوي (قرار المالك 2026-10-26: الأدوات السبع في كل الموقع).
   المصدر الوحيد هنا في site/fx، ونسخها في app/fx وkids/fx وtop10/fx تُزامن بـ tools/sync_fx.py.
   - المقياس: رموز ترانزشنز دوت ديف للمدد والمنحنيات والمسافات.
   - الحركات: نافذة، اهتزاز خطأ، علامة نجاح، تنبيه منبثق، تلميح.
   - المكونات: من رياكت بتس منقولة لجافاسكربت عادي: حدّ نجمة، بطاقة كشّاف،
     شرار الضغط، عدّاد دوّار، زر ضغط مطوّل.
   كلها تحترم سياسة تقليل الحركة الموجودة (motion-policy) وطلب النظام. */
:root {
  --duration-stagger: 40ms;
  --duration-micro: 80ms;
  --duration-quick: 150ms;
  --duration-fast: 250ms;
  --duration-medium: 350ms;
  --duration-slow: 400ms;
  --duration-very-slow: 500ms;
  --ease-smooth-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: ease-in-out;
  --ease-linear: linear;
  --distance-micro: 4px;
  --distance-small: 6px;
  --distance-base: 8px;
  --distance-medium: 12px;
  --scale-large: 0.96;
  --scale-medium: 0.97;
  --blur-small: 2px;
  --blur-medium: 3px;
  --fx-gold: #fbac28;
  --fx-gold-soft: #ffe8b0;
  --fx-good: #1fae6b;
  --fx-bad: #e0533d;
}

/* نافذة: تكبر بنعومة وتختفي أسرع (ترانزشنز: modal) — تُطبَّق على كل <dialog class="fx-modal"> */
dialog.fx-modal { transform: scale(var(--scale-large)); opacity: 0;
  transition: transform var(--duration-fast) var(--ease-smooth-out), opacity var(--duration-fast) var(--ease-smooth-out); }
dialog.fx-modal::backdrop { opacity: 0; transition: opacity var(--duration-fast) var(--ease-smooth-out); }
dialog.fx-modal.fx-open { transform: none; opacity: 1; }
dialog.fx-modal.fx-open::backdrop { opacity: 1; }
dialog.fx-modal.fx-closing { transform: scale(var(--scale-large)); opacity: 0; transition-duration: var(--duration-quick); }
dialog.fx-modal.fx-closing::backdrop { opacity: 0; transition-duration: var(--duration-quick); }

/* اهتزاز الخطأ: أربعة مقاطع بمنحنى لكل مقطع (ترانزشنز: error-state-shake) */
.fx-shake { animation: fx-shake 280ms linear; }
@keyframes fx-shake {
  0% { transform: translateX(0); animation-timing-function: var(--ease-smooth-out); }
  28.57% { transform: translateX(var(--distance-small)); animation-timing-function: var(--ease-smooth-out); }
  57.14% { transform: translateX(calc(var(--distance-small) * -1)); animation-timing-function: var(--ease-smooth-out); }
  78.57% { transform: translateX(var(--distance-micro)); animation-timing-function: var(--ease-smooth-out); }
  100% { transform: translateX(0); }
}
.fx-err-flash { box-shadow: 0 0 0 3px var(--fx-bad) !important; transition: box-shadow var(--duration-quick) ease-out; }

/* علامة النجاح: ظهور ودوران وارتداد ثم رسم الخط (ترانزشنز: success-check) */
.fx-check { display: inline-block; width: 1.6em; height: 1.6em; vertical-align: middle; opacity: 0; }
.fx-check svg { display: block; width: 100%; height: 100%; overflow: visible; }
.fx-check path { stroke-dasharray: 40; stroke-dashoffset: 40; }
.fx-check.fx-in { animation: fx-c-fade 500ms var(--ease-smooth-out) forwards, fx-c-rot 500ms var(--ease-smooth-out) forwards,
  fx-c-blur 500ms var(--ease-smooth-out) forwards, fx-c-bob 500ms cubic-bezier(0.22, 1, 0.36, 1) forwards; }
.fx-check.fx-in path { animation: fx-c-draw 500ms var(--ease-smooth-out) 80ms forwards; }
@keyframes fx-c-fade { to { opacity: 1; } }
@keyframes fx-c-rot { from { transform: rotate(80deg); } to { transform: none; } }
@keyframes fx-c-blur { from { filter: blur(8px); } to { filter: none; } }
@keyframes fx-c-bob { from { translate: 0 24px; } to { translate: 0 0; } }
@keyframes fx-c-draw { to { stroke-dashoffset: 0; } }

/* ظهور ناعم لعنصر يتبدّل نصه أو يظهر (ترانزشنز: text-swap / texts-reveal) */
.fx-rise { animation: fx-rise var(--duration-fast) var(--ease-smooth-out) both; }
@keyframes fx-rise { from { opacity: 0; transform: translateY(var(--distance-base)); filter: blur(var(--blur-small)); } }
.fx-stagger > * { animation: fx-rise var(--duration-slow) var(--ease-smooth-out) both; animation-delay: calc(var(--i, 0) * var(--duration-stagger)); }

/* تنبيه منبثق (ترانزشنز: toast) */
.fx-toast { position: fixed; inset-inline: 16px; bottom: max(16px, env(safe-area-inset-bottom)); margin: 0 auto; max-width: 420px; z-index: 1000;
  background: #161e3d; color: #F5EEDC; border: 1px solid #2b3560; border-radius: 14px; padding: 12px 16px; font-weight: 700; text-align: center;
  box-shadow: 0 16px 36px rgba(0,0,0,.45); opacity: 0; transform: translateY(16px); filter: blur(var(--blur-small));
  transition: opacity var(--duration-slow) var(--ease-smooth-out), transform var(--duration-slow) var(--ease-smooth-out), filter var(--duration-slow) var(--ease-smooth-out); }
.fx-toast.fx-open { opacity: 1; transform: none; filter: none; }
.fx-toast.fx-closing { transition-duration: var(--duration-medium); opacity: 0; transform: translateY(8px); }

/* حدّ نجمة (رياكت بتس: StarBorder) — نجمة تلف حول حدّ الزر */
.fx-star { position: relative; isolation: isolate; overflow: hidden; }
.fx-star::before { content: ""; position: absolute; inset: -60%; z-index: -2; pointer-events: none;
  background: conic-gradient(from var(--fx-a, 0deg), transparent 0 78%, var(--fx-star, var(--fx-gold)) 88%, transparent 92%);
  animation: fx-orbit 4s linear infinite; }
.fx-star::after { content: ""; position: absolute; inset: 2px; z-index: -1; border-radius: inherit; background: var(--fx-star-bg, inherit); pointer-events: none; }
@property --fx-a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes fx-orbit { to { --fx-a: 360deg; } }

/* بطاقة كشّاف (رياكت بتس: SpotlightCard) — ضوء يتبع الإصبع؛ الإحداثيات من fx.js */
.fx-spot { position: relative; isolation: isolate; }
.fx-spot::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1;
  background: radial-gradient(240px circle at var(--fx-x, 50%) var(--fx-y, 50%), var(--fx-spot, rgba(251,172,40,.22)), transparent 70%);
  opacity: 0; transition: opacity var(--duration-fast) var(--ease-smooth-out); }
.fx-spot.fx-lit::after { opacity: 1; }

/* شرار الضغط (رياكت بتس: ClickSpark) — لوحة رسم واحدة فوق الصفحة */
.fx-spark-layer { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2000; }

/* عدّاد دوّار (رياكت بتس: Counter) — كل خانة شريط أرقام يتحرك عمودياً */
.fx-counter { display: inline-flex; direction: ltr; font-variant-numeric: tabular-nums; line-height: 1; overflow: hidden; vertical-align: bottom; }
.fx-counter .fx-d { display: inline-block; height: 1em; overflow: hidden; }
.fx-counter .fx-r { display: flex; flex-direction: column; transition: transform var(--duration-very-slow) var(--ease-smooth-out); }
.fx-counter .fx-r span { height: 1em; display: block; }
.fx-counter .fx-sep { display: inline-block; height: 1em; }
.fx-counter [data-c]::before { content: attr(data-c); }
.fx-counter .fx-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.fx-counter { position: relative; }

/* زر ضغط مطوّل (رياكت بتس: HoldButton) — يمتلئ أثناء الضغط ولا يُنفَّذ إلا بالإكمال */
.fx-hold { position: relative; overflow: hidden; isolation: isolate; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.fx-hold::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--fx-hold, var(--fx-bad)); transform: scaleX(var(--fx-p, 0));
  transform-origin: right; }
.fx-hold.fx-done::before { transform: scaleX(1); }

/* تقليل الحركة: نفس سياسة الموقع، والمكونات تبقى ظاهرة ثابتة */
[data-reduced-motion="true"] .fx-star::before { animation: none; display: none; }
[data-reduced-motion="true"] .fx-check { opacity: 1; }
[data-reduced-motion="true"] .fx-check path { stroke-dashoffset: 0; }
/* تقليل الحركة داخل الطبقة نفسها، لا اعتماداً على motion-policy (صفحة الدرس لا تحمّلها؛ كشفه qa_motion 2026-10-26) */
[data-reduced-motion="true"] :is(.fx-check, .fx-check path, .fx-rise, .fx-stagger > *, .fx-shake) { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  :is(.fx-check, .fx-check path, .fx-rise, .fx-stagger > *, .fx-shake) { animation: none !important; }
  .fx-star::before { display: none; }
  .fx-check { opacity: 1; } .fx-check path { stroke-dashoffset: 0; }
  dialog.fx-modal, dialog.fx-modal::backdrop, .fx-toast { transition: none; }
}
.fx-pre { opacity: 0; }
/* خانات العدّاد ترث خط العنصر ولونه، فلا تأخذها قواعد عامة مثل «.home .numbers span»؛ الصنف مكرر عمداً ليغلب أي قاعدة صفحة (درس الرئيسية 2026-10-26) */
.fx-counter.fx-counter.fx-counter span { font: inherit; color: inherit; letter-spacing: inherit; }
