/* =========================================================
   المعمل التفاعلي

   الأنبوبة SVG مش صورة — بتتلوّن من بيانات التفاعل نفسها،
   فأي تفاعل جديد بيشتغل من غير ما نرسم حاجة.
   ========================================================= */

.lab {
  background: var(--card);
  border-radius: 18px;
  padding: 15px 16px 13px;
  margin: 14px 0;
}

.lab-head {
  font-size: 15px;
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 12px;
}

.lab-stage {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 480px) {
  .lab-stage {
    grid-template-columns: 92px 1fr;
    gap: 10px;
  }
}

.lab-tubewrap {
  position: relative;
}
.lab-tube {
  display: block;
  width: 100%;
  height: auto;
  color: var(--text-dim);
}
/* الوهج: تفاعل بيطلّع ضوء زي احتراق الماغنسيوم */
.lab-tube.is-glow {
  filter: drop-shadow(0 0 14px rgba(255, 240, 190, 0.95));
}

.lab-liquid,
.lab-solid {
  transition: fill 0.5s var(--ease-3, ease-out);
}

@keyframes lab-rise {
  from {
    transform: translateY(0);
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  to {
    transform: translateY(-96px);
    opacity: 0;
  }
}

/* أسماء اللي جوّه الأنبوبة */
.lab-inside {
  display: grid;
  gap: 4px;
  margin-top: 7px;
}
.lab-inside span {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  color: var(--text-soft);
  border-inline-start: 3px solid var(--c);
  padding-inline-start: 5px;
  line-height: 1.5;
}

.lab-shelf-t {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.lab-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* المادة على الرف — اللون بيساعد الولد يربط المادة بشكلها في الأنبوبة */
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 11px;
  padding: 7px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition:
    border-color 0.12s,
    opacity 0.12s;
}
.chip i {
  flex: none;
  width: 13px;
  height: 13px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.chip em {
  font-style: normal;
  font-size: 11px;
  color: var(--text-dim);
}
.chip:hover,
.chip:focus-visible {
  border-color: var(--brand);
  outline: none;
}
.chip.in {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}

.lab-tools {
  display: flex;
  gap: 7px;
  margin-top: 11px;
}
.lab-tools button {
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 11px;
  padding: 8px 13px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
  cursor: pointer;
}
.lab-tools button:hover,
.lab-tools button:focus-visible {
  border-color: var(--brand);
  outline: none;
}
.lab-heat.on {
  background: #fff3c4;
  border-color: #f5a623;
  color: #8a5a00;
}

/* ===== نتيجة التفاعل ===== */

.lab-out {
  margin-top: 13px;
  background: var(--ok-soft);
  border-inline-start: 4px solid var(--ok);
  border-radius: 12px;
  padding: 12px 15px;
  animation: chem-in 0.2s var(--ease-3, ease-out);
}
/* «مافيش تفاعل» نتيجة صحيحة مش فشل — لون محايد مش أحمر */
.lab-out.is-none {
  background: var(--bg-soft);
  border-inline-start-color: var(--text-dim);
}
.lab-out.is-none b {
  color: var(--text);
}
.lab-out.is-none span {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.8;
  color: var(--text-soft);
}

.lab-kind {
  display: inline-block;
  background: var(--ok);
  color: #fff;
  border-radius: 99px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 8px;
}
.lab-eq {
  margin: 4px 0 10px;
  overflow-x: auto;
}
.lab-note,
.lab-test,
.lab-warn {
  margin: 0 0 6px;
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.85;
  color: var(--text);
}
.lab-test {
  font-size: 13.5px;
  color: var(--text-soft);
}
.lab-test b {
  color: var(--brand);
}
.lab-warn {
  font-size: 13.5px;
  background: var(--danger-soft);
  border-radius: 10px;
  padding: 8px 11px;
}
.lab-warn b {
  color: var(--danger);
}

@media (prefers-reduced-motion: reduce) {
  .lab-out {
    animation: none;
  }
  .lab-bubbles circle {
    animation: none !important;
    opacity: 0.6;
  }
}

/* ===== الحركة: اللي بيخلّي التجربة تبان تجربة =====
   المادة بتنزل الأنبوبة، والفلز بيدوب لما يتفاعل مع الحمض، واللهب
   بيرعش. من غير الحركة دي الشاشة بتبان رسم توضيحي مش تجربة بتحصل. */

.lab-pieces .pc {
  animation: lab-drop 0.55s var(--ease-3, cubic-bezier(0.2, 0.8, 0.3, 1)) both;
  transition: opacity 0.9s ease-out;
}
@keyframes lab-drop {
  from {
    transform: translateY(-120px);
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  75% {
    transform: translateY(6px);
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* الفلز بيتآكل في الحمض — بيقلّ مع الوقت مش بيختفي فجأة */
.lab-pieces.is-melting .pc {
  animation:
    lab-drop 0.55s var(--ease-3, ease-out) both,
    lab-melt 2.4s 0.6s ease-in forwards;
}
@keyframes lab-melt {
  to {
    opacity: 0.18;
    transform: scale(0.72);
    transform-origin: 50% 100%;
  }
}

/* اللهب بيرعش زي لهب بنزن الحقيقي */
.lab-flame:not([hidden]) .lab-f1 {
  animation: lab-flicker 0.42s ease-in-out infinite alternate;
  transform-origin: 60px 214px;
}
.lab-flame:not([hidden]) .lab-f2 {
  animation: lab-flicker 0.31s ease-in-out infinite alternate-reverse;
  transform-origin: 60px 210px;
}
@keyframes lab-flicker {
  from {
    transform: scaleY(0.9) scaleX(1.05);
  }
  to {
    transform: scaleY(1.12) scaleX(0.94);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lab-pieces .pc,
  .lab-pieces.is-melting .pc,
  .lab-flame .lab-f1,
  .lab-flame .lab-f2 {
    animation: none !important;
  }
  .lab-pieces.is-melting .pc {
    opacity: 0.3;
  }
}

/* ===== واقعية المشهد =====
   طلب صاحب المشروع: «عاوز التجربة أكثر واقعية وألوان». الفرق بين
   رسم توضيحي وتجربة هو إن التغيير **بيحصل قدامك**: الراسب بينزل
   ويترسّب، والأزرق بيبهت بالتدريج، والجمرة بتتوهّج — مش لقطة نهائية. */

/* الراسب بيتجمّع في القاع — الطبقة بتكبر من تحت مش بتظهر فجأة */
.lab-solid.is-settle {
  transform-origin: 60px 196px;
  animation: lab-settle 2.8s var(--ease-3, ease-out) both;
}
@keyframes lab-settle {
  from {
    transform: scaleY(0.06);
  }
}

/* جسيمات الراسب وهي نازلة — بتختفي عند القاع لأن الطبقة بتاخد مكانها */
.lab-fx .fx-fall {
  animation: lab-fall 1.7s ease-in both infinite;
}
@keyframes lab-fall {
  0% {
    transform: translateY(0);
    opacity: 0;
  }
  18% {
    opacity: 0.95;
  }
  85% {
    opacity: 0.85;
  }
  100% {
    transform: translateY(66px);
    opacity: 0;
  }
}

/* البخار طالع من فم الأنبوبة — بيتوسّع ويخف زي بخار براد الشاي */
.lab-steam .fx-steam {
  animation: lab-steam 2.2s ease-out infinite both;
}
@keyframes lab-steam {
  0% {
    transform: translateY(0) scale(0.6);
    opacity: 0;
  }
  25% {
    opacity: 0.75;
  }
  100% {
    transform: translateY(-30px) scale(1.7);
    opacity: 0;
  }
}

/* طبقة السطح بتتكوّن بالتدريج بعد الرج — الدهون بتطفو والصبغة معاها */
.lab-fx .fx-surface {
  animation: lab-surface-in 1.2s ease-out 0.35s both;
}
@keyframes lab-surface-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 0.92;
    transform: translateY(0);
  }
}

/* قطرات التكاثف بتظهر واحدة ورا التانية على الجدار البارد */
.lab-fx .fx-drop {
  opacity: 0;
  animation: lab-drop-in 0.9s ease-out both;
}
@keyframes lab-drop-in {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ومضة الماغنسيوم: وميض أبيض يملا الأنبوبة لحظة الاشتعال وبيروح */
.lab-flashfx {
  pointer-events: none;
}
.lab-tube.is-flash .lab-flashfx {
  animation: lab-flash 1.15s ease-out both;
}
@keyframes lab-flash {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
  }
}

/* توهّج القطعة نفسها — جمرة الفحم: نبض إضاءة من غير لهب */
.lab-pieces.is-ember .pc {
  animation: lab-ember 1.3s ease-in-out infinite alternate;
}
@keyframes lab-ember {
  from {
    filter: drop-shadow(0 0 2px var(--ember)) brightness(1.15);
  }
  to {
    filter: drop-shadow(0 0 9px var(--ember)) brightness(1.75);
  }
}

/* الصوديوم بيجري على سطح المية — طالع لفوق وبيتنطط يمين وشمال */
.lab-pieces.is-darting .pc {
  animation:
    lab-drop 0.55s var(--ease-3, ease-out) both,
    lab-dart 1.5s 0.6s ease-in-out infinite alternate;
}
@keyframes lab-dart {
  0% {
    transform: translate(-13px, -84px);
  }
  50% {
    transform: translate(9px, -87px);
  }
  100% {
    transform: translate(-6px, -84px);
  }
}

/* القطع بتتلوّن بالتدريج (تغطية النحاس · الأحمر بيبقى فضي) */
.lab-pieces .pc * {
  transition:
    fill 2.6s ease,
    stroke 2.6s ease;
}

@media (prefers-reduced-motion: reduce) {
  .lab-solid.is-settle,
  .lab-fx .fx-fall,
  .lab-steam .fx-steam,
  .lab-fx .fx-surface,
  .lab-pieces.is-ember .pc,
  .lab-pieces.is-darting .pc {
    animation: none !important;
  }
  .lab-fx .fx-surface {
    opacity: 0.92;
  }
  .lab-fx .fx-fall {
    opacity: 0.5;
  }
  .lab-steam .fx-steam {
    opacity: 0.4;
  }
  .lab-tube.is-flash .lab-flashfx {
    animation: none;
    opacity: 0;
  }
}

/* ===== الرمز على المادة =====
   الولد بيشوف «خارصين» في المعمل و Zn في المعادلة — الرمز جنب
   الاسم بيخلّيه يربط الاتنين من غير ما حد يقوله. */

.chip {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  position: relative;
  padding-inline-start: 26px;
  /* 🔴 من غيرها السحب بالقلم بيحرّك الصفحة بدل ما يشيل المادة */
  touch-action: none;
}
.chip i {
  position: absolute;
  inset-inline-start: 9px;
  top: 50%;
  transform: translateY(-50%);
}
.chip-f {
  font-family: 'Times New Roman', Cambria, serif;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.1;
  direction: ltr;
  color: var(--brand);
}
.chip-f sub {
  font-size: 0.64em;
  vertical-align: -0.22em;
}
.chip span {
  font-size: 11.5px;
  line-height: 1.3;
}
.chip em {
  font-size: 10px;
}
.chip.in .chip-f {
  color: var(--brand);
}

/* ===== السحب بالقلم ===== */

.chip.dragging {
  opacity: 0.35;
}
/* الشبح بيمشي مع القلم — خفيف عشان مايحجبش الأنبوبة */
.lab-ghost {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: -22px 0 0 -34px;
  background: var(--card);
  border: 2px solid var(--brand);
  border-radius: 11px;
  padding: 7px 12px;
  font-family: 'Times New Roman', Cambria, serif;
  font-size: 15px;
  font-weight: 700;
  direction: ltr;
  color: var(--brand);
  box-shadow: var(--shadow-4, 0 8px 24px rgba(0, 0, 0, 0.18));
  pointer-events: none;
}
.lab-ghost i {
  width: 13px;
  height: 13px;
  border-radius: 4px;
}
.lab-ghost sub {
  font-size: 0.64em;
  vertical-align: -0.22em;
}

/* الأنبوبة بتقول «حطها هنا» */
.lab-tubewrap.is-target .lab-tube {
  color: var(--brand);
}
.lab-tubewrap.is-target::before {
  content: '';
  position: absolute;
  inset: -10px -6px 30px;
  border: 2px dashed var(--brand);
  border-radius: 16px;
  background: var(--brand-soft);
  opacity: 0.5;
}

/* ===== المعادلة بتتكتب وهي بتحصل ===== */

.lab-eq.is-live .chem > * {
  animation: lab-eq-in 0.34s var(--ease-3, ease-out) var(--d, 0ms) both;
}
@keyframes lab-eq-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.94);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lab-eq.is-live .chem > * {
    animation: none;
  }
}
