/* ================= مغامرة الدومينو: أصدقاء العدد ================= */
:root{
  --cream:#FFF6E5;
  --ivory:#FFF9EE;
  --ink:#2E2A3B;
  --ink-2:#6A6480;
  --sun:#FFD166;
  --coral:#FF8A7A;
  --sky:#6EC3F5;
  --lilac:#B79CED;
  --mint:#7FD8BE;
  --orange:#FFB067;
  --pink:#FFA8C5;
  --wood:#E8C9A0;
  --stage:#7FD8BE;
  --pop:cubic-bezier(.34,1.56,.64,1);
  --ease:cubic-bezier(.22,.9,.35,1);
}

*,*::before,*::after{box-sizing:border-box;}
html,body{height:100%;margin:0;padding:0;}
body{
  height:100dvh;
  font-family:'Cairo',system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
  color:var(--ink);
  background-color:var(--cream);
  background-image:radial-gradient(rgba(46,42,59,.055) 1.4px,transparent 1.5px);
  background-size:19px 19px;
  overflow:hidden;
  overscroll-behavior:none;
  -webkit-tap-highlight-color:transparent;
  -webkit-user-select:none;user-select:none;
  -webkit-font-smoothing:antialiased;
}
button{font-family:inherit;color:inherit;}
.hidden{display:none !important;}
.fx{position:fixed;inset:0;pointer-events:none;z-index:80;}

.app{
  position:relative;
  height:100%;
  max-width:1000px;
  margin-inline:auto;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

/* ألوان المستويات */
.app[data-level="3"]{--stage:#7FD8BE;}
.app[data-level="4"]{--stage:#6EC3F5;}
.app[data-level="5"]{--stage:#FF8A7A;}
.app[data-level="6"]{--stage:#FFD166;}
.app[data-level="7"]{--stage:#B79CED;}
.app[data-level="8"]{--stage:#FFB067;}
.app[data-level="9"]{--stage:#FFA8C5;}

.screen{position:relative;flex:1;min-height:0;display:flex;flex-direction:column;}

/* ================= أزرار عامة ================= */
.btn{
  appearance:none;-webkit-appearance:none;
  border:3px solid var(--ink);
  background:var(--ivory);
  color:var(--ink);
  border-radius:16px;
  padding:10px 14px;
  font-size:clamp(14px,3.8vw,17px);
  font-weight:900;
  min-height:52px;
  box-shadow:0 4px 0 var(--ink);
  cursor:pointer;
  transition:transform .12s var(--ease),box-shadow .12s var(--ease),background .15s;
  display:inline-flex;align-items:center;justify-content:center;
  line-height:1.2;
}
.btn:active{transform:translateY(4px);box-shadow:0 0 0 var(--ink);}
.btn:focus-visible{outline:3px solid var(--sky);outline-offset:3px;}
.btn-primary{background:var(--sun);}
.btn-primary.ready{animation:readyPulse .6s var(--pop);}
.btn-ghost{background:var(--ivory);}
.btn:disabled{
  opacity:.45;
  box-shadow:0 4px 0 rgba(46,42,59,.25);
  cursor:default;
  transform:none;
}
.btn.wide{width:100%;}
.btn-link{
  border:0;background:transparent;box-shadow:none;color:var(--ink-2);
  font-size:14px;font-weight:700;min-height:40px;text-decoration:underline;
}
.btn-link:active{transform:none;box-shadow:none;}

.icon-btn{
  width:46px;height:46px;flex:0 0 auto;
  display:grid;place-items:center;
  border:3px solid var(--ink);
  border-radius:14px;
  background:var(--ivory);
  box-shadow:0 4px 0 var(--ink);
  cursor:pointer;
  color:var(--ink);
  transition:transform .1s var(--ease),box-shadow .1s var(--ease);
}
.icon-btn:active{transform:translateY(3px);box-shadow:0 1px 0 var(--ink);}
.icon-btn:focus-visible{outline:3px solid var(--sky);outline-offset:3px;}

/* ================= خريطة المستويات ================= */
.map{
  z-index:1;
  padding:18px 16px 20px;
  gap:clamp(10px,2.4vh,18px);
  align-items:center;
  justify-content:center;
  overflow-y:auto;
}
.map-sky{position:absolute;inset:0;overflow:hidden;pointer-events:none;z-index:0;}
.sun{
  position:absolute;top:-40px;inset-inline-start:-40px;
  width:150px;height:150px;border-radius:50%;
  background:var(--sun);opacity:.42;
}
.cloud{
  position:absolute;background:#fff;opacity:.85;border-radius:999px;
  box-shadow:0 6px 0 rgba(46,42,59,.05);
}
.cloud::before,.cloud::after{
  content:'';position:absolute;background:inherit;border-radius:50%;
}
.cl-a{width:86px;height:30px;top:22px;inset-inline-end:12%;}
.cl-a::before{width:38px;height:38px;top:-16px;inset-inline-start:14px;}
.cl-a::after{width:26px;height:26px;top:-10px;inset-inline-start:48px;}
.cl-b{width:64px;height:24px;top:96px;inset-inline-start:8%;opacity:.7;}
.cl-b::before{width:30px;height:30px;top:-14px;inset-inline-start:10px;}
.cl-b::after{width:20px;height:20px;top:-8px;inset-inline-start:34px;}
.cl-c{width:74px;height:26px;top:150px;inset-inline-end:6%;opacity:.55;}
.cl-c::before{width:32px;height:32px;top:-15px;inset-inline-start:12px;}
.cl-c::after{width:22px;height:22px;top:-9px;inset-inline-start:40px;}
.bg-star{
  position:absolute;width:14px;height:14px;background:var(--sun);
  clip-path:polygon(50% 0%,61% 35%,98% 35%,68% 57%,79% 91%,50% 70%,21% 91%,32% 57%,2% 35%,39% 35%);
  opacity:.6;
}
.bs-1{top:60px;inset-inline-start:26%;transform:rotate(-12deg) scale(1.2);}
.bs-2{top:200px;inset-inline-end:16%;transform:rotate(18deg);opacity:.45;}
.bs-3{top:270px;inset-inline-start:12%;transform:rotate(8deg) scale(.8);opacity:.5;}
.bs-4{top:340px;inset-inline-end:30%;transform:rotate(-20deg) scale(.9);opacity:.35;}

.map-head{position:relative;z-index:2;text-align:center;}
.map-head h1{
  position:relative;
  display:inline-block;
  margin:0;
  padding:0 12px;
  font-size:clamp(25px,7.2vw,44px);
  font-weight:900;
  line-height:1.25;
  color:var(--ink);
}
.map-head h1::before{
  content:'';position:absolute;
  inset-inline:-4px;
  top:42%;height:42%;
  background:var(--sun);opacity:.6;
  border-radius:10px;
  transform:rotate(-1.2deg);
  z-index:-1;
}
.map-head .sub{
  margin:6px 0 0;
  font-size:clamp(14px,4vw,19px);
  font-weight:700;
  color:var(--ink-2);
  display:flex;align-items:center;justify-content:center;gap:8px;
}
.map-head .dot{width:7px;height:7px;border-radius:50%;background:var(--coral);display:inline-block;}

.map-guide{
  position:relative;z-index:2;
  display:flex;align-items:center;gap:10px;
  width:100%;max-width:430px;
}
.owl-slot{width:clamp(58px,16vw,84px);flex:0 0 auto;}
.owl-slot svg{width:100%;height:auto;display:block;filter:drop-shadow(0 4px 0 rgba(46,42,59,.18));}
.owl-slot.big{width:clamp(78px,22vw,110px);}
.bubble{
  position:relative;flex:1;margin:0;
  background:var(--ivory);
  border:3px solid var(--ink);
  border-radius:16px;
  padding:9px 14px;
  font-size:clamp(12px,3.4vw,15px);
  font-weight:700;
  line-height:1.55;
  box-shadow:0 4px 0 var(--ink);
}
.bubble::after{
  content:'';position:absolute;top:16px;right:-10px;
  width:14px;height:14px;background:var(--ivory);
  border-top:3px solid var(--ink);border-right:3px solid var(--ink);
  transform:rotate(45deg);border-radius:3px;
}

.levels{
  position:relative;z-index:2;
  display:grid;grid-template-columns:repeat(4,1fr);
  gap:clamp(8px,2.4vw,14px);
  width:100%;max-width:470px;
}
.level-tile{
  appearance:none;-webkit-appearance:none;
  aspect-ratio:1/1;
  border:3px solid var(--ink);
  border-radius:20px;
  background:var(--c,var(--mint));
  box-shadow:0 5px 0 var(--ink);
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:3px;padding:4px;cursor:pointer;
  transition:transform .12s var(--ease),box-shadow .12s var(--ease);
  color:var(--ink);
}
.level-tile:active{transform:translateY(4px);box-shadow:0 1px 0 var(--ink);}
.level-tile:focus-visible{outline:3px solid var(--sky);outline-offset:3px;}
.level-num{font-size:clamp(22px,6.6vw,34px);font-weight:900;line-height:1;display:block;}
.level-stars{display:flex;gap:1px;justify-content:center;}
.level-stars .star-svg{width:9px;height:9px;display:block;}

.map-foot{
  position:relative;z-index:2;
  display:flex;align-items:center;gap:12px;
  width:100%;max-width:430px;justify-content:space-between;
}
.total-stars{
  display:flex;align-items:center;gap:7px;
  background:var(--ivory);
  border:3px solid var(--ink);
  border-radius:999px;
  padding:5px 14px;
  font-size:clamp(12px,3.4vw,15px);
  font-weight:700;
  box-shadow:0 4px 0 var(--ink);
}
.total-stars b{font-weight:900;font-size:1.12em;}
.mini-star{width:18px;height:18px;display:inline-block;}
.mini-star svg{width:100%;height:100%;display:block;}

/* ================= شاشة اللعب ================= */
.play{z-index:1;}
.floor{
  position:absolute;inset-inline:0;bottom:0;height:42%;
  background:var(--stage);opacity:.3;
  border-radius:60% 60% 0 0 / 26px 26px 0 0;
  pointer-events:none;z-index:0;
}
.play > *:not(.floor){position:relative;z-index:1;}

.hud{display:flex;align-items:center;gap:8px;padding:8px 10px 0;}
.hud-mid{flex:1;display:flex;align-items:center;justify-content:center;gap:8px;min-width:0;}
.chip{
  background:var(--stage);
  border:3px solid var(--ink);
  border-radius:999px;
  padding:3px 12px;
  font-weight:900;
  font-size:clamp(11px,3.2vw,14px);
  white-space:nowrap;
  box-shadow:0 3px 0 var(--ink);
}
.star-strip{display:flex;gap:3px;flex:0 0 auto;}
.star-strip .star{width:clamp(16px,4.6vw,21px);height:clamp(16px,4.6vw,21px);display:block;}
.star-strip .star svg{width:100%;height:100%;display:block;}
.star-strip .star.pop svg{animation:starPop .55s var(--pop) both;}

.goal-row{
  display:flex;align-items:flex-end;gap:6px;
  padding:16px 12px 0;
}
.goal-board{
  position:relative;flex:1;
  background:var(--ivory);
  border:4px solid var(--ink);
  border-radius:18px;
  box-shadow:0 5px 0 var(--ink);
  padding:7px 10px 9px;
  display:flex;flex-direction:column;align-items:center;gap:1px;
  cursor:pointer;
}
.goal-board::before,.goal-board::after{
  content:'';position:absolute;top:-16px;width:3px;height:16px;
  background:var(--ink);border-radius:3px;
}
.goal-board::before{right:28px;}
.goal-board::after{left:28px;}
.goal-label{font-size:clamp(11px,3.2vw,14px);font-weight:700;color:var(--ink-2);line-height:1.3;}
.goal-num{
  display:grid;place-items:center;
  width:clamp(48px,13.5vw,68px);height:clamp(48px,13.5vw,68px);
  border-radius:50%;
  background:var(--stage);
  border:3px solid var(--ink);
  font-size:clamp(28px,8.4vw,42px);
  font-weight:900;line-height:1;
  animation:popIn .35s var(--pop) both;
}
.goal-sub{font-size:clamp(9px,2.6vw,11px);font-weight:700;color:var(--ink-2);line-height:1.2;}

.dodo{
  width:clamp(54px,15vw,80px);flex:0 0 auto;
  transform-origin:bottom center;
  animation:breathe 2.6s ease-in-out infinite;
}
.dodo svg{width:100%;height:auto;display:block;}
.dodo.happy{animation:jump .85s var(--pop);}
.dodo.think{animation:think .8s ease-in-out;}

/* الطاولة وأحجار الاختيار */
.table-area{
  flex:1;min-height:0;
  display:flex;
  padding:8px 12px;
  position:relative;
}
.table-surface{
  flex:1;min-height:0;width:100%;
  display:flex;align-items:center;justify-content:center;
  padding:8px;
  border:3px solid var(--ink);
  border-radius:26px;
  background:
    repeating-linear-gradient(90deg,rgba(46,42,59,.05) 0 2px,transparent 2px 9px),
    repeating-linear-gradient(0deg,rgba(255,255,255,.25) 0 3px,transparent 3px 14px),
    var(--wood);
  box-shadow:inset 0 -6px 0 rgba(46,42,59,.13),0 5px 0 var(--ink);
}
.options{
  display:grid;
  grid-template-columns:1fr 1fr;
  grid-auto-rows:minmax(0,1fr);
  gap:clamp(6px,2vw,12px);
  width:100%;height:100%;
  max-width:480px;max-height:360px;
  margin:auto;
}
.stone{
  appearance:none;-webkit-appearance:none;
  border:0;padding:0;margin:0;background:transparent;
  width:100%;height:100%;
  display:block;
  cursor:grab;
  touch-action:none;
  transition:transform .14s var(--ease);
  will-change:transform;
  border-radius:14px;
}
.stone.returning{transition:transform .34s var(--pop);}
.stone.dragging{z-index:60;cursor:grabbing;transition:none;}
.stone .domino-svg{
  width:100%;height:100%;display:block;
  filter:drop-shadow(0 4px 0 rgba(46,42,59,.75));
  transition:filter .16s ease;
}
.stone .domino-svg rect{transition:stroke .16s ease;}
.stone.picked .domino-svg{filter:drop-shadow(0 0 12px rgba(110,195,245,.95)) drop-shadow(0 4px 0 rgba(46,42,59,.75));}
.stone.picked .domino-svg rect{stroke:var(--sky);}
.stone.dragging .domino-svg{filter:drop-shadow(0 14px 12px rgba(46,42,59,.32));}
.stone.wrong .domino-svg rect{stroke:var(--coral);}
.stone.used{opacity:.34;pointer-events:none;filter:grayscale(.55);}
.stone.shake{animation:shake .5s ease;}
.stone:focus-visible{outline:3px solid var(--sky);outline-offset:2px;}

.pip{fill:#1C1A26;transition:fill .18s ease,transform .18s ease;transform-box:fill-box;transform-origin:center;}
.pip.lit{fill:var(--coral);transform:scale(1.4);}

/* رسالة التوست */
.toast{
  position:absolute;top:6px;left:50%;
  transform:translate(-50%,-10px) scale(.9);
  opacity:0;
  max-width:94%;
  padding:8px 16px;
  border:3px solid var(--ink);
  border-radius:16px;
  background:var(--ivory);
  font-size:clamp(12px,3.6vw,15px);
  font-weight:900;
  line-height:1.4;
  text-align:center;
  box-shadow:0 4px 0 var(--ink);
  pointer-events:none;
  transition:opacity .2s var(--ease),transform .25s var(--pop);
  z-index:30;
}
.toast.show{opacity:1;transform:translate(-50%,0) scale(1);}
.toast.ok{background:#D9F7EA;}
.toast.err{background:#FFE3DF;}

/* منطقة الإجابة */
.answer-area{padding:8px 12px 0;}
.tray{
  min-height:clamp(78px,13vh,104px);
  border:3px dashed rgba(46,42,59,.45);
  border-radius:18px;
  background:rgba(255,249,238,.9);
  display:flex;align-items:center;justify-content:center;gap:12px;
  padding:8px 10px;
  transition:border-color .18s ease,background .18s ease,box-shadow .18s ease,transform .18s ease;
}
.tray.hot{
  border-color:var(--coral);
  background:rgba(255,209,102,.42);
  transform:scale(1.015);
}
.tray.solved{
  border-style:solid;
  border-color:var(--sun);
  background:#FFFDF6;
  box-shadow:0 0 0 4px rgba(255,209,102,.5),0 4px 0 var(--ink);
}
.tray-hint{
  font-size:clamp(12px,3.5vw,15px);
  font-weight:700;
  color:rgba(46,42,59,.45);
  text-align:center;
  line-height:1.5;
}
.placed{
  width:min(152px,42%);
  flex:0 0 auto;
  animation:popIn .34s var(--pop) both;
}
.placed .domino-svg{
  width:100%;height:auto;display:block;
  filter:drop-shadow(0 3px 0 rgba(46,42,59,.55));
}
.eq{
  display:flex;align-items:center;gap:7px;
  font-size:clamp(19px,5.6vw,28px);
  font-weight:900;
  line-height:1;
  flex-wrap:nowrap;
}
.eq-part{display:inline-block;animation:eqIn .3s var(--pop) both;}
.eq-part.total{color:#E4572E;}
.eq-part.op{color:var(--ink-2);}

/* الشريط السفلي */
.bar{
  display:grid;
  grid-template-columns:1fr 1fr 1.25fr;
  gap:8px;
  padding:10px 12px 12px;
}

/* ================= النوافذ المنبثقة ================= */
.overlay{
  position:absolute;inset:0;z-index:50;
  display:flex;align-items:center;justify-content:center;
  padding:18px;
  background:rgba(46,42,59,.45);
  -webkit-backdrop-filter:blur(3px);
  backdrop-filter:blur(3px);
}
.panel{
  width:100%;max-width:400px;
  max-height:100%;
  overflow-y:auto;
  background:var(--ivory);
  border:4px solid var(--ink);
  border-radius:26px;
  box-shadow:0 8px 0 rgba(46,42,59,.85);
  padding:18px 18px 20px;
  display:flex;flex-direction:column;align-items:center;gap:10px;
  text-align:center;
  animation:panelIn .34s var(--pop) both;
}
.panel-title{margin:0;font-size:clamp(20px,5.8vw,28px);font-weight:900;line-height:1.3;}
.panel-text{margin:0;font-size:clamp(13px,3.8vw,16px);font-weight:700;line-height:1.6;color:var(--ink);}
.panel-hint{margin:0;font-size:clamp(11px,3.2vw,13px);font-weight:700;color:var(--ink-2);}
.panel-row{display:flex;gap:8px;width:100%;}
.panel-row .btn{flex:1;}
.big-stars{display:flex;gap:6px;justify-content:center;padding:4px 0;}
.big-star{width:clamp(28px,8vw,38px);height:clamp(28px,8vw,38px);display:block;animation:starPop .5s var(--pop) both;}
.big-star svg{width:100%;height:100%;display:block;}

/* شرارات النجاح */
.spark{
  position:fixed;width:22px;height:22px;
  margin:0;pointer-events:none;
  animation:sparkFly .95s ease-out forwards;
}
.spark svg{width:100%;height:100%;display:block;}

/* ================= الحركات ================= */
@keyframes popIn{0%{opacity:0;transform:scale(.6);}100%{opacity:1;transform:scale(1);}}
@keyframes eqIn{0%{opacity:0;transform:translateY(10px) scale(.6);}100%{opacity:1;transform:translateY(0) scale(1);}}
@keyframes shake{
  0%,100%{transform:translateX(0);}
  15%{transform:translateX(-9px) rotate(-2deg);}
  30%{transform:translateX(9px) rotate(2deg);}
  45%{transform:translateX(-7px) rotate(-1deg);}
  60%{transform:translateX(7px) rotate(1deg);}
  80%{transform:translateX(-3px);}
}
@keyframes starPop{
  0%{transform:scale(.2) rotate(-35deg);opacity:0;}
  60%{transform:scale(1.28) rotate(8deg);opacity:1;}
  100%{transform:scale(1) rotate(0);opacity:1;}
}
@keyframes breathe{
  0%,100%{transform:scale(1,1) translateY(0);}
  50%{transform:scale(1.035,.965) translateY(-2px);}
}
@keyframes jump{
  0%{transform:translateY(0) scale(1,1);}
  22%{transform:translateY(-26px) scale(.94,1.09);}
  48%{transform:translateY(0) scale(1.08,.92);}
  68%{transform:translateY(-12px) scale(.98,1.03);}
  86%{transform:translateY(0) scale(1.03,.97);}
  100%{transform:translateY(0) scale(1,1);}
}
@keyframes think{
  0%,100%{transform:rotate(0);}
  30%{transform:rotate(-8deg);}
  60%{transform:rotate(8deg);}
}
@keyframes sparkFly{
  0%{opacity:1;transform:translate(-50%,-50%) scale(.4) rotate(0deg);}
  100%{opacity:0;transform:translate(calc(-50% + var(--dx,0px)),calc(-50% + var(--dy,-60px))) scale(1.15) rotate(var(--rot,120deg));}
}
@keyframes panelIn{0%{opacity:0;transform:translateY(24px) scale(.94);}100%{opacity:1;transform:none;}}
@keyframes readyPulse{0%{transform:scale(1);}45%{transform:scale(1.07);}100%{transform:scale(1);}}

/* ================= الشاشات الصغيرة والقائمة ================= */
@media (max-width:359px){
  .levels{grid-template-columns:repeat(3,1fr);}
  .hud-mid{gap:5px;}
  .star-strip{gap:2px;}
}

@media (min-width:700px), (min-aspect-ratio:5/4){
  .options{grid-template-columns:repeat(4,1fr);max-width:820px;max-height:260px;}
  .table-surface{border-radius:80px;}
  .bar{max-width:620px;margin-inline:auto;width:100%;}
  .answer-area{max-width:620px;margin-inline:auto;width:100%;}
  .goal-row{max-width:620px;margin-inline:auto;width:100%;}
}

@media (max-height:620px){
  .hud{padding:5px 10px 0;}
  .icon-btn{width:42px;height:42px;}
  .goal-row{padding:14px 12px 0;}
  .goal-label{display:none;}
  .goal-sub{display:none;}
  .goal-num{width:44px;height:44px;font-size:26px;}
  .dodo{width:52px;}
  .tray{min-height:70px;}
  .bar{padding:6px 12px 8px;gap:6px;}
  .btn{min-height:46px;padding:8px 10px;}
  .table-area{padding:6px 12px;}
  .answer-area{padding:6px 12px 0;}
  .placed{width:min(120px,38%);}
  .map{padding:10px 14px 12px;gap:8px;}
  .map-head h1{font-size:clamp(22px,6vw,32px);}
}

@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:.001ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.001ms !important;
  }
}