/* ===== تنسيق عام ===== */
:root {
  --car: #ef4444;
  --car-dark: #b91c1c;
  --car-light: #f87171;
  --ink: #1e293b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Baloo Bhaijaan 2', 'Segoe UI', Tahoma, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button { font-family: inherit; cursor: pointer; border: 0; }

.icon-btn {
  width: 66px; height: 66px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 6px 0 rgba(0,0,0,.18);
  font-size: 32px;
  display: grid; place-items: center;
  text-decoration: none;
  transition: transform .1s;
}
.icon-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }

/* الشريط النصي */
#subtitle {
  position: fixed; top: 92px; left: 50%;
  transform: translate(-50%, -20px);
  background: rgba(255,255,255,.95);
  padding: 8px 22px; border-radius: 40px;
  font-size: clamp(18px, 2.6vw, 26px); font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  opacity: 0; transition: .3s; pointer-events: none;
  z-index: 50; max-width: 92vw; text-align: center;
}
#subtitle.show { opacity: 1; transform: translate(-50%, 0); }

/* سُحب متحركة */
.cloud {
  position: absolute; background: #fff; border-radius: 100px;
  width: 140px; height: 46px; opacity: .9; z-index: 0;
  animation: drift 40s linear infinite;
}
.cloud::before, .cloud::after {
  content: ''; position: absolute; background: #fff; border-radius: 50%;
}
.cloud::before { width: 70px; height: 70px; top: -34px; left: 22px; }
.cloud::after  { width: 52px; height: 52px; top: -22px; left: 72px; }
@keyframes drift { from { transform: translateX(-30vw); } to { transform: translateX(130vw); } }

.sun {
  position: absolute; top: 18px; right: 6vw; width: 90px; height: 90px;
  background: radial-gradient(circle, #fde047 55%, #facc15 56%, #facc1500 72%);
  border-radius: 50%; z-index: 0;
}

/* قصاصات الاحتفال */
.confetti {
  position: fixed; top: -20px; width: 12px; height: 18px; border-radius: 3px;
  z-index: 100; pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall { to { top: 110vh; transform: rotate(720deg) translateX(40px); } }

/* ===== الصفحة الرئيسية ===== */
body.home {
  min-height: 100%;
  background: linear-gradient(#7dd3fc, #e0f2fe 70%, #bbf7d0 70%, #86efac);
  background-attachment: fixed;
  overflow-x: hidden;
}
.home header {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center; gap: 18px;
  padding: 28px 16px 10px;
}
.home h1 {
  margin: 0; font-size: clamp(34px, 6vw, 60px); color: #fff;
  text-shadow: 0 4px 0 #0284c7, 0 8px 18px rgba(0,0,0,.2);
}
.games {
  position: relative; z-index: 1;
  display: grid; gap: 28px;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  max-width: 1050px; margin: 20px auto 40px; padding: 0 20px;
}
.game-card {
  position: relative; display: block;
  background: #fff; border-radius: 30px; padding: 14px 14px 10px;
  text-align: center; text-decoration: none; color: var(--ink);
  box-shadow: 0 10px 0 rgba(0,0,0,.12), 0 16px 30px rgba(0,0,0,.12);
  transition: transform .15s;
}
.game-card:hover { transform: translateY(-6px) rotate(-1deg); }
.game-card:active { transform: scale(.97); }
.game-card img { width: 100%; aspect-ratio: 4/3; display: block; border-radius: 20px; }
.game-card .name { font-size: 28px; font-weight: 800; margin-top: 6px; }
.game-card .play {
  position: absolute; top: 24px; left: 24px;
  width: 64px; height: 64px; border-radius: 50%;
  background: #22c55e; color: #fff; font-size: 30px;
  display: grid; place-items: center;
  box-shadow: 0 5px 0 #15803d;
  animation: pulse 1.4s ease-in-out infinite;
}
.game-card.soon img { filter: grayscale(.75) brightness(1.05); }
.game-card.soon .play { background: #94a3b8; box-shadow: 0 5px 0 #64748b; animation: none; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* ===== صفحة اللعبة ===== */
body.game {
  height: 100vh; height: 100dvh; overflow: hidden; touch-action: none;
  background: linear-gradient(#7dd3fc, #e0f2fe);
  position: relative;
}
.topbar {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
}
.progress { display: flex; gap: 8px; background: rgba(255,255,255,.6); padding: 10px 14px; border-radius: 40px; }
.progress .dot {
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 3px solid #cbd5e1; transition: .3s;
}
.progress .dot.done { background: #facc15; border-color: #eab308; transform: scale(1.15); }

.stage {
  position: absolute; top: 90px; bottom: 32vh; left: 0; right: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
}
#car { width: min(96vw, 1050px); height: 100%; overflow: visible; }

#tray {
  position: absolute; bottom: 2vh; left: 0; right: 0; height: 28vh; z-index: 5;
  display: flex; align-items: center; justify-content: center;
}
.tray-box {
  height: 100%; min-width: 40vw; max-width: 92vw;
  background: rgba(255,255,255,.8); border: 5px dashed #fff; border-radius: 36px;
  display: flex; align-items: center; justify-content: center; padding: 12px 24px;
  box-shadow: 0 10px 25px rgba(0,0,0,.12);
}
#piece { cursor: grab; touch-action: none; animation: bob 1.6s ease-in-out infinite; overflow: visible; }
#piece.hidden { visibility: hidden; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-3deg); } }

.floating { position: fixed; z-index: 60; pointer-events: none; overflow: visible;
  filter: drop-shadow(0 12px 10px rgba(0,0,0,.3)); }
.floating.returning, .floating.snapping { transition: left .3s ease, top .3s ease, width .3s, height .3s; }

/* أجزاء السيارة */
.tire  { fill: #1f2937; }
.rim   { fill: #cbd5e1; stroke: #94a3b8; stroke-width: 4; }
.spoke { fill: #94a3b8; }
.hub   { fill: #64748b; }
.c-body  { fill: var(--car); stroke: var(--car-dark); stroke-width: 4; stroke-linejoin: round; }
.c-dark  { fill: var(--car-dark); }
.c-door  { fill: var(--car-light); stroke: var(--car-dark); stroke-width: 4; stroke-linejoin: round; }
.glass   { fill: #bae6fd; stroke: #0369a1; stroke-width: 4; stroke-linejoin: round; }
.shine   { stroke: #fff; stroke-width: 6; stroke-linecap: round; opacity: .8; }
.handle  { fill: #475569; }
.head    { fill: #fde047; stroke: #a16207; stroke-width: 4; }
.tail    { fill: #f97316; stroke: #7c2d12; stroke-width: 4; }
.bumper  { fill: #94a3b8; stroke: #64748b; stroke-width: 3; }

.part { opacity: 0; }
.part.placed { opacity: 1; animation: placePop .5s ease; transform-box: fill-box; transform-origin: center; }
@keyframes placePop { 0% { transform: scale(1.3); } 60% { transform: scale(.92); } 100% { transform: scale(1); } }

.ghost { opacity: 0; pointer-events: none; }
.ghost * { fill: rgba(255,255,255,.55) !important; stroke: #fff !important; stroke-width: 4 !important; stroke-dasharray: 10 7; }
.ghost .detail { display: none; }
.ghost.show { animation: glow 0.9s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: .35; } to { opacity: 1; } }

.spin { transform-box: fill-box; transform-origin: center; }
.driving .spin { animation: spin .35s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }
#carGroup { transition: none; }
#carGroup.drive { animation: drive 3.2s ease-in-out forwards; }
@keyframes drive {
  0%   { transform: translateX(0); }
  10%  { transform: translateX(25px); }
  48%  { transform: translateX(-1500px); }
  49%  { transform: translateX(1500px); }
  100% { transform: translateX(0); }
}
.lights-on .head { fill: #fffbeb; filter: drop-shadow(0 0 12px #fde047); }

/* يد التلميح */
.hint-hand { position: fixed; font-size: 64px; z-index: 70; pointer-events: none; }

/* الشاشات المنبثقة */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(14, 116, 144, .55); backdrop-filter: blur(3px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px;
}
.overlay.hidden { display: none; }
.big-btn {
  width: 160px; height: 160px; border-radius: 50%;
  font-size: 76px; color: #fff; display: grid; place-items: center;
  text-decoration: none;
}
.big-btn.green { background: #22c55e; box-shadow: 0 10px 0 #15803d; animation: pulse 1.3s ease-in-out infinite; }
.big-btn.blue  { background: #3b82f6; box-shadow: 0 10px 0 #1d4ed8; }
.big-btn:active { transform: translateY(8px); box-shadow: none; }
.overlay .row { display: flex; gap: 40px; }
.overlay .stars { font-size: 72px; animation: pulse 1s infinite; }

@media (max-height: 500px) {
  .icon-btn { width: 52px; height: 52px; font-size: 26px; }
  .stage { top: 70px; }
  #subtitle { top: 70px; }
  .big-btn { width: 120px; height: 120px; font-size: 56px; }
}
