/* =========================================================
   طبقة المغامرة — الاحتفالات والحركة والرسومات والخرائط.
   منفصلة عن app.css عشان الأساس يفضل نضيف والجديد يتطوّر لوحده.
   ========================================================= */

:root {
  /* ألوان العالم — بتتحدّد من JS حسب اختيار الولد (themes.js) */
  --w-sky: #dcfce7;
  --w-ground: #86efac;
  --w-path: #a3703c;
  --w-primary: #16a34a;
  --w-accent: #f59e0b;
  --w-deep: #14532d;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ------------------------------------------------- الرسومات */
.ka-art {
  display: block;
  overflow: visible;
}

.ka-companion {
  animation: ka-float 3.4s ease-in-out infinite;
}
@keyframes ka-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

.ka-station {
  transition:
    transform 0.25s var(--ease-bounce),
    filter 0.25s;
}
.ka-station.is-current {
  animation: ka-pulse 2.1s ease-in-out infinite;
}
.ka-station.is-locked {
  filter: grayscale(0.55) opacity(0.75);
}
@keyframes ka-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.07);
  }
}

.ka-badge-frame {
  position: relative;
  display: inline-grid;
  place-items: center;
  transition: transform 0.25s var(--ease-bounce);
}
.ka-badge-frame > svg {
  position: absolute;
  inset: 0;
}
.ka-badge-frame .ka-badge-icon {
  position: relative;
  font-size: 30px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28));
}
.ka-badge-frame.is-locked {
  filter: grayscale(1);
  opacity: 0.55;
}
.ka-badge-frame.is-earned:hover {
  transform: scale(1.09) rotate(-3deg);
}

/* ------------------------------------------------- خريطة الرحلة */
.ka-map {
  position: relative;
  border-radius: var(--r-lg, 20px);
  overflow: hidden;
  background: var(--w-sky);
  border: 1px solid var(--border);
  min-height: 320px;
}
.ka-map-scene {
  position: absolute;
  inset: 0;
}
.ka-map-scene svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ka-map-layer {
  position: relative;
  width: 100%;
}

.ka-map-node {
  position: absolute;
  transform: translate(50%, -50%);
  display: grid;
  justify-items: center;
  gap: 3px;
  cursor: pointer;
  transition: transform 0.2s var(--ease-bounce);
}
.ka-map-node:hover {
  transform: translate(50%, -50%) scale(1.09);
}
.ka-map-node[data-state='locked'] {
  cursor: not-allowed;
}
.ka-map-node .ka-map-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--w-deep);
  background: rgba(255, 255, 255, 0.86);
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[data-theme='dark'] .ka-map-node .ka-map-label {
  background: rgba(15, 23, 42, 0.82);
  color: #e8edf7;
}

/* ------------------------------------------------- الاحتفالات */
.ka-celebrate {
  position: fixed;
  inset: 0;
  z-index: 420;
  display: grid;
  place-items: center;
  background: rgba(8, 12, 24, 0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.24s var(--ease-out);
  padding: 20px;
  cursor: pointer;
}
.ka-celebrate.is-in {
  opacity: 1;
}
.ka-celebrate.is-out {
  opacity: 0;
}

.ka-celebrate-card {
  background: var(--card);
  border-radius: 26px;
  padding: 30px 34px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
  transform: scale(0.82) translateY(18px);
  transition: transform 0.36s var(--ease-bounce);
  max-width: 340px;
  border: 3px solid var(--w-accent);
}
.ka-celebrate.is-in .ka-celebrate-card {
  transform: scale(1) translateY(0);
}

.ka-celebrate-art {
  display: grid;
  place-items: center;
  margin-bottom: 6px;
}
.ka-celebrate-badge {
  font-size: 66px;
  line-height: 1;
  animation: ka-badge-in 0.7s var(--ease-bounce);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.25));
}
@keyframes ka-badge-in {
  0% {
    transform: scale(0) rotate(-140deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

.ka-celebrate-kicker {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--w-accent);
  margin-top: 10px;
}
.ka-celebrate-big {
  font-size: 62px;
  font-weight: 900;
  line-height: 1.05;
  color: var(--w-primary);
  margin: 2px 0;
}
.ka-celebrate-title {
  font-size: 22px;
  font-weight: 800;
  margin: 4px 0;
}
.ka-celebrate-sub {
  font-size: 14.5px;
  color: var(--text-soft);
  line-height: 1.7;
}
.ka-celebrate-points {
  display: inline-block;
  margin-top: 12px;
  background: var(--w-accent);
  color: #fff;
  font-weight: 800;
  padding: 5px 16px;
  border-radius: 999px;
}

/* رقاقة صغيرة بتطلع لفوق عند أي إنجاز خفيف */
.ka-pop-chip {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, 0);
  z-index: 410;
  background: var(--w-primary);
  color: #fff;
  padding: 9px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  display: flex;
  gap: 9px;
  align-items: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  animation: ka-pop-up 1.6s var(--ease-out) forwards;
  pointer-events: none;
  white-space: nowrap;
}
.ka-pop-chip span {
  background: rgba(255, 255, 255, 0.24);
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 13.5px;
}
@keyframes ka-pop-up {
  0% {
    opacity: 0;
    transform: translate(-50%, 14px) scale(0.85);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -6px) scale(1.05);
  }
  30% {
    transform: translate(-50%, 0) scale(1);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -44px) scale(0.95);
  }
}

/* ------------------------------------------------- الحركة العامة */
.ka-reveal {
  animation: ka-reveal 0.42s var(--ease-out) both;
}
@keyframes ka-reveal {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
/* تأخير متدرّج للعناصر المتتابعة */
.ka-stagger > * {
  animation: ka-reveal 0.42s var(--ease-out) both;
}
.ka-stagger > *:nth-child(1) {
  animation-delay: 0.02s;
}
.ka-stagger > *:nth-child(2) {
  animation-delay: 0.06s;
}
.ka-stagger > *:nth-child(3) {
  animation-delay: 0.1s;
}
.ka-stagger > *:nth-child(4) {
  animation-delay: 0.14s;
}
.ka-stagger > *:nth-child(5) {
  animation-delay: 0.18s;
}
.ka-stagger > *:nth-child(6) {
  animation-delay: 0.22s;
}
.ka-stagger > *:nth-child(n + 7) {
  animation-delay: 0.26s;
}

/* شريط تقدّم بحركة */
.ka-bar {
  height: 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--w-deep) 12%, transparent);
  overflow: hidden;
  position: relative;
}
.ka-bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--w-primary), var(--w-accent));
  transition: width 0.7s var(--ease-out);
  position: relative;
}
.ka-bar > i::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  animation: ka-shine 2.2s linear infinite;
}
@keyframes ka-shine {
  to {
    transform: translateX(200%);
  }
}

/* بطاقة عالم للاختيار */
.ka-world-card {
  border: 3px solid transparent;
  border-radius: 18px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  background: var(--card);
  transition:
    transform 0.2s var(--ease-bounce),
    border-color 0.2s;
  text-align: center;
}
.ka-world-card:hover {
  transform: translateY(-4px);
}
.ka-world-card.is-active {
  border-color: var(--w-accent);
}
.ka-world-card .ka-world-preview {
  height: 84px;
  position: relative;
}
.ka-world-card .ka-world-preview svg {
  width: 100%;
  height: 100%;
}
.ka-world-card .ka-world-body {
  padding: 10px 12px 14px;
}
.ka-world-card strong {
  display: block;
  font-size: 15px;
}
.ka-world-card small {
  color: var(--text-dim);
  font-size: 12px;
}

/* ------------------------------------------------- احترام تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
  .ka-companion,
  .ka-station.is-current,
  .ka-bar > i::after {
    animation: none;
  }
  .ka-celebrate-card,
  .ka-celebrate-badge,
  .ka-reveal,
  .ka-stagger > * {
    animation: none;
    transition: none;
    transform: none;
  }
}

/* =========================================================
   رسمة سريعة فوق الشاشة (Lottie)
   مقصود إنها صغيرة وفي النص — مش شاشة كاملة تقطع على الولد شغله.
   ========================================================= */
.ka-lottie-flash {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 320;
  pointer-events: none;
  animation: ka-lottie-in 0.25s var(--ease-3, ease-out);
}

/* خانة الرسمة جوّه كارت الاحتفال — الرسمة هنا مش كوميض فوق الشاشة،
   لأن الكوميض طبقته تحت حجاب الكارت فمكانش بيتشاف أصلاً. */
.ka-lottie-slot {
  width: 132px;
  height: 132px;
  margin: 0 auto 6px;
  position: relative;
}

/* ⚠️ الرسوم الجاهزة دي كلها مرسومة لخلفية غامقة: على الثيم الفاتح
   بين ٤٥٪ و١٠٠٪ من بيكسلاتها بيبقى تباينها أقل من ١٫٥ — يعني بتختفي.
   الخلفية دي بتضمن إنها تتقرا على أي ثيم.

   جوّه الكارت: مربع مدوّر بيغطي الرسمة كلها بأطرافها، وشكله مقصود
   زي أي صورة في كارت. الكوميض الطايف: تدرّج ناعم عشان مايبقاش
   مستطيل غامق طالع فجأة فوق الصفحة. */
.ka-lottie-slot::before {
  content: '';
  position: absolute;
  inset: -9%;
  border-radius: 24%;
  background: rgb(15 23 42 / 0.92);
}
.ka-lottie-flash::before {
  content: '';
  position: absolute;
  inset: -16%;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(15 23 42 / 0.88) 72%, rgb(15 23 42 / 0) 93%);
}
html[data-theme='dark'] .ka-lottie-slot::before,
html[data-theme='dark'] .ka-lottie-flash::before {
  display: none;
}

/* أيقونة الشارة بتفضل — دي هوية الشارة نفسها مش زينة — بس بتصغّر
   عشان الرسمة تبقى هي البطل في الكارت */
.ka-lottie-slot + .ka-celebrate-badge {
  font-size: 34px;
}
.ka-lottie-flash.is-out {
  animation: ka-lottie-out 0.35s var(--ease-3, ease-in) forwards;
}
@keyframes ka-lottie-in {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.85);
  }
}
@keyframes ka-lottie-out {
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
  }
}
@media (prefers-reduced-motion: reduce) {
  .ka-lottie-flash {
    animation: none;
  }
}
