/* KulliQ — برمج الروبوت: a coding game for 9 to 12. A navy sky with stars, floating 3D tiles seen a little from the front,
   a robot from above, and the program as coloured blocks: قدّام (green), لف يمين (blue), لف يسار (purple), and «كرّر» (a
   yellow box that holds blocks). The first screen and «المزيد» follow «ذاكرة الصور» (games/memory/memory.css), kept
   here so each game stands on its own. */
:root {
  --ink: #1B2A4A; --soft: #4C5B7A; --panel: #FFFFFF; --chip: #F0F2FF; --chipLine: #DDE1F7; --navyInk: #2A2F7A;
  --sun: #FFD23F; --sunD: #E0A800; --sunInk: #3A2600; --coral: #FF6B6B; --coralD: #D94848; --mint: #3DDC97; --pink: #FF4D6D;
  --fwd: #22B573; --fwdD: #13824F; --rt: #2F8FE8; --rtD: #1C62AB; --lt: #8A5CF6; --ltD: #5E36C4; --rep: #F5B700; --repD: #C98F00;
  --display: "Baloo Bhaijaan 2", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --sprite: url(pics.webp?v=1);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --starsTile: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 220 220'%3E%3Cg fill='%23fff'%3E%3Ccircle cx='20' cy='30' r='1.4' opacity='.7'/%3E%3Ccircle cx='90' cy='12' r='1' opacity='.5'/%3E%3Ccircle cx='160' cy='40' r='1.6' opacity='.8'/%3E%3Ccircle cx='200' cy='110' r='1' opacity='.5'/%3E%3Ccircle cx='130' cy='95' r='1.2' opacity='.6'/%3E%3Ccircle cx='40' cy='120' r='1' opacity='.45'/%3E%3Ccircle cx='75' cy='180' r='1.5' opacity='.7'/%3E%3Ccircle cx='180' cy='190' r='1.1' opacity='.55'/%3E%3Cpath d='M110 150 Q110 157 117 157 Q110 157 110 164 Q110 157 103 157 Q110 157 110 150Z' opacity='.6'/%3E%3C/g%3E%3C/svg%3E");
  --space: radial-gradient(60% 38% at 88% 0%, rgba(124, 92, 255, .5), transparent 70%), radial-gradient(55% 35% at 0% 100%, rgba(46, 196, 182, .3), transparent 70%),
    var(--starsTile) 0 0 / 220px 220px, linear-gradient(180deg, #1F2468 0%, #15184C 55%, #0E1036 100%);
  --tickInk: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='%233A2600' stroke-width='3.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #15184C; color: #fff; font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif; }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pic { display: block; background: var(--sprite) var(--pp, 0 0) / var(--ps, 800% 100%) no-repeat; }

/* ---- the commands: a block each; «كرّر» holds blocks ---- */
.blk { position: relative; flex: none; width: var(--bw, 50px); height: var(--bh, 56px); padding: 0; border: 0; border-radius: 14px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; background: linear-gradient(180deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 55%), var(--c); color: #fff;
  font: 700 11px/1.1 "IBM Plex Sans Arabic", sans-serif; box-shadow: 0 4px 0 var(--d), inset 0 2px 0 rgba(255, 255, 255, .35); transition: transform .15s, opacity .2s; }
.blk svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.blk.f { --c: var(--fwd); --d: var(--fwdD); }
.blk.r { --c: var(--rt); --d: var(--rtD); }
.blk.l { --c: var(--lt); --d: var(--ltD); }
.blk.new { animation: pop .3s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: scale(.4); } to { transform: none; } }
.rep { position: relative; flex: none; display: flex; flex-direction: column; border-radius: 16px; background: #FFF6D2; box-shadow: 0 4px 0 var(--repD), inset 0 0 0 3px var(--rep); overflow: hidden;
  transition: opacity .2s; }
.repHead { display: flex; align-items: center; gap: 4px; padding: 3px 6px 3px 8px; background: var(--rep); color: var(--sunInk); font: 800 13px/1.3 var(--display); }
.repHead svg { width: 16px; height: 16px; fill: none; stroke: var(--sunInk); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.repHead b, .repN { margin-inline-start: 2px; padding: 0 8px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, .6); color: var(--sunInk); font: 800 14px/1.5 var(--display); }
.repN { min-width: 40px; min-height: 26px; }
.repX { width: 26px; height: 26px; margin-inline-start: auto; padding: 0; border: 0; border-radius: 8px; background: rgba(58, 38, 0, .12); color: var(--sunInk); font: 700 13px/1 sans-serif; }
.repBody { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; min-height: 58px; --bw: 40px; --bh: 46px; }
.repBody .blk svg { width: 20px; height: 20px; }
.repBody .blk { font-size: 10px; }
.slot { flex: none; width: var(--bw, 50px); height: var(--bh, 56px); border-radius: 14px; border: 2px dashed #CBD0EA; display: grid; place-items: center; color: #A3AACB; font: 700 20px/1 sans-serif; }
.slot.here { border-color: var(--sun); color: var(--sunD); background: rgba(255, 210, 63, .12); animation: here 1.4s ease-in-out infinite; }
@keyframes here { 50% { background: rgba(255, 210, 63, .28); } }
.rep.target { box-shadow: 0 4px 0 var(--repD), inset 0 0 0 3px var(--rep), 0 0 0 3px #fff, 0 0 0 6px rgba(255, 210, 63, .8); }
/* running: the block that runs lifts with a pointer, the ones done fade; a mistake is red */
.blk.now { transform: translateY(-4px); box-shadow: 0 4px 0 var(--d), 0 0 0 3px #fff, 0 0 0 7px rgba(255, 210, 63, .75); }
.blk.now::before { content: ""; position: absolute; top: -16px; left: 50%; margin-left: -7px; border: 7px solid transparent; border-top-color: var(--sun); border-bottom: 0; }
.done, .rep.done { opacity: .45; }
.rep.now { box-shadow: 0 4px 0 var(--repD), inset 0 0 0 3px var(--rep), 0 0 0 3px #fff, 0 0 0 6px rgba(255, 210, 63, .7); }
.blk.bad { --c: var(--coral); --d: var(--coralD); box-shadow: 0 4px 0 var(--d), 0 0 0 3px #fff, 0 0 0 7px rgba(255, 107, 107, .55); animation: shake .45s ease; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

/* ---- the board: floating tiles, the stars, the rocks, the rocket and the robot ---- */
.boardWrap { perspective: 900px; display: flex; justify-content: center; }
.board { position: relative; direction: ltr; transform: rotateX(16deg); transform-origin: 50% 100%; --cell: 56px; }
.tile { position: absolute; left: calc(var(--x) * var(--cell) + 3px); top: calc(var(--y) * var(--cell) + 3px); width: calc(var(--cell) - 6px); height: calc(var(--cell) - 6px);
  border-radius: 22%; background: linear-gradient(160deg, #6A7CF0 0%, #4C5BD3 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .38), inset 0 -3px 0 rgba(20, 24, 90, .25), 0 6px 0 #2A3289, 0 12px 16px rgba(5, 6, 30, .5); }
.tile.begin { background: linear-gradient(160deg, #5FE7B0 0%, #2EC48A 100%); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .45), 0 6px 0 #178A5E, 0 12px 16px rgba(5, 6, 30, .5); }
.tile.goal { background: radial-gradient(circle at 50% 45%, #FFF3B0 0 22%, #FFD23F 55%, #F5B700 100%); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .6), 0 6px 0 #B98500, 0 0 26px rgba(255, 210, 63, .55); }
.thing { position: absolute; left: calc(var(--x) * var(--cell)); top: calc(var(--y) * var(--cell)); width: var(--cell); height: var(--cell); pointer-events: none; }
.thing > * { position: absolute; }
.thing.star > svg { inset: 19%; width: 62%; height: 62%; filter: drop-shadow(0 0 8px rgba(255, 220, 90, .8)); animation: float 2.6s ease-in-out infinite; }
/* what is gone stays gone without its animation too (a reduced-motion phone) */
.thing.star.got > svg { opacity: 0; animation: pick .5s ease; }
@keyframes float { 50% { transform: translateY(-6%); } }
@keyframes pick { from { transform: none; opacity: 1; } to { transform: scale(1.7); opacity: 0; } }
.thing.rock > i { inset: 14%; filter: drop-shadow(0 5px 4px rgba(0, 0, 0, .35)); }
.thing.rocket > i { inset: 7% 7% 21% 7%; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .35)); }
.thing.rocket.fly > i { opacity: 0; animation: fly 1.5s cubic-bezier(.5, 0, .9, .5); }
.thing.rocket .flame { display: none; left: 34%; top: 66%; width: 32%; height: 90%; border-radius: 50% 50% 40% 40%; background: linear-gradient(180deg, #FFF3B0, #FF9A3C 45%, rgba(255, 107, 107, 0));
  filter: blur(2px); }
.thing.rocket.fly .flame { display: block; opacity: 0; animation: fly 1.5s cubic-bezier(.5, 0, .9, .5); }
@keyframes fly { 0% { transform: none; opacity: 1; } 15% { transform: translateY(5%); opacity: 1; } 100% { transform: translateY(-1100%) scale(.7); opacity: .2; } }
.robot, .ghost { position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); z-index: 3; pointer-events: none;
  transform: translate(calc(var(--x) * var(--cell)), calc(var(--y) * var(--cell))); transition: transform .38s ease-in-out, opacity .25s; }
.robot svg, .ghost svg { position: absolute; inset: 10%; width: 80%; height: 80%; overflow: visible; transform: rotate(var(--a, 0deg)); transition: transform .32s ease-in-out;
  filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .4)); }
.robot.still, .robot.still svg, .ghost.still, .ghost.still svg { transition: none; }
/* the path ahead (robot.js paintPath): a band of light over the tiles the program steps on with a dot on each, a red ✕
   where it would bump into a rock or step into space, and the robot's ghost where the program leaves it, glowing like its
   eyes; the ghost and the ✕ step aside while the robot runs */
.trail { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.trail .band { fill: none; stroke: rgba(92, 242, 214, .4); stroke-width: .44; stroke-linecap: round; stroke-linejoin: round; transition: stroke-dashoffset .38s ease-in-out; }
.trail .dots circle { fill: #E4FFF9; }
.trail .dots .new { transform-box: fill-box; transform-origin: center; animation: dotIn .3s cubic-bezier(.3, 1.6, .5, 1) backwards; }
@keyframes dotIn { from { transform: scale(0); } }
.trail .miss { display: none; transition: opacity .2s; }
.trail .miss.on { display: inline; }
.trail .miss line { stroke: #FF8A8A; stroke-width: .07; stroke-dasharray: .09 .07; stroke-linecap: round; }
.trail .miss circle { fill: var(--coral); stroke: #fff; stroke-width: .045; }
.trail .miss path { fill: none; stroke: #fff; stroke-width: .055; stroke-linecap: round; }
.trail .miss.pop .x { transform-box: fill-box; transform-origin: center; animation: dotIn .35s cubic-bezier(.3, 1.6, .5, 1) .3s backwards; }
.ghost { z-index: 4; }
.ghost svg { opacity: .5; filter: drop-shadow(0 0 5px rgba(92, 242, 214, .95)); }
.ghost.off, .board.going .ghost, .board.going .trail .miss { opacity: 0; }
/* on the robot's own tile one of them is enough: the robot when it looks the same way, the ghost when it would turn */
.ghost.same, .robot.hid { opacity: 0; }
.robot.fall svg { opacity: 0; animation: fall .7s ease-in; }
@keyframes fall { from { transform: rotate(var(--a, 0deg)); opacity: 1; } to { transform: rotate(calc(var(--a, 0deg) + 160deg)) scale(.1); opacity: 0; } }
.robot.bump svg { animation: bump .5s ease; }
@keyframes bump { 0%, 100% { transform: rotate(var(--a)); } 35% { transform: rotate(var(--a)) translateY(-18%); } 65% { transform: rotate(var(--a)) translateY(3%); } }
.robot.in svg { opacity: 0; animation: board .45s ease; }
@keyframes board { from { transform: rotate(var(--a)); opacity: 1; } to { transform: rotate(var(--a)) scale(.2); opacity: 0; } }
.spk { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; fill: #FFF4A8; filter: drop-shadow(0 0 4px rgba(255, 230, 120, .9)); animation: spark .8s ease-out forwards; }
@keyframes spark { from { transform: translate(0, 0) scale(.4); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(1.1); opacity: 0; } }

/* ---- the first screen ---- */
.setup { position: relative; min-height: 100vh; min-height: 100dvh; background: var(--space); background-attachment: fixed; overflow: hidden; }
.first { position: relative; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: calc(var(--sat) + 72px) 16px calc(var(--sab) + 24px); max-width: 560px; margin: 0 auto; }
.setup.open .first { min-height: 0; padding-bottom: 16px; }
.goBack { position: absolute; top: calc(var(--sat) + 16px); inset-inline-start: 16px; z-index: 2; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 999px; background: rgba(255, 255, 255, .14); color: #fff; text-decoration: none; font-weight: 600; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .24); }
.goBack:hover { background: rgba(255, 255, 255, .22); }
.planet { position: absolute; left: -34px; top: 22%; width: 110px; aspect-ratio: 1; transform: rotate(-14deg); filter: drop-shadow(0 10px 20px rgba(0, 0, 0, .35)); }
.comet { position: absolute; right: -6px; bottom: 18%; width: 64px; aspect-ratio: 1; opacity: .7; }
.hero { position: relative; width: 340px; height: 200px; flex: none; }
.hero .boardWrap { position: absolute; left: 30px; top: 44px; }
.hero > .blk { position: absolute; }
.hero .h1 { right: 2px; top: 0; transform: rotate(10deg); }
.hero .h2 { left: 6px; top: -4px; transform: rotate(-12deg); }
.hero .h3 { position: absolute; right: -4px; top: 112px; transform: rotate(8deg) scale(.82); }
.ttlWrap { margin: -4px 0 0; line-height: 0; }
.ttl { width: min(320px, 84vw); aspect-ratio: 760 / 210; overflow: visible; }
.sub { margin: -8px 0 0; font-size: 16px; font-weight: 600; opacity: .9; text-align: center; }
.steps { display: flex; gap: 8px; width: 100%; margin: 0; padding: 0; list-style: none; }
.steps li { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border-radius: 18px; background: rgba(255, 255, 255, .1);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .18); font-size: 13px; font-weight: 700; text-align: center; }
.steps i { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font: 800 17px/1 var(--display); font-style: normal; color: var(--sunInk); background: var(--sun); }
.start { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; border: 0; border-radius: 22px; padding: 15px 0 12px; background: var(--sun); color: var(--sunInk);
  box-shadow: 0 7px 0 var(--sunD), 0 14px 28px rgba(5, 6, 30, .45); font: 800 30px/1.2 var(--display); }
.start:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--sunD); }
.first .start { animation: nudge 3s ease-in-out 1.5s infinite; }
.first .start:active { animation: none; }
@keyframes nudge { 0%, 76%, 100% { transform: scale(1); } 84% { transform: scale(1.045); } 92% { transform: scale(.99); } }
.lvl { margin: 0; display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; opacity: .9; text-align: center; }
.lvl svg { flex: none; }
.moreBtn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 20px; border: 0; border-radius: 999px; background: rgba(255, 255, 255, .14); color: #fff;
  font-size: 16px; font-weight: 700; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .22); }
.moreBtn:hover { background: rgba(255, 255, 255, .22); }
.moreBtn svg { transition: transform .2s; }
.moreBtn[aria-expanded="true"] svg { transform: rotate(180deg); }
.start:focus-visible, .moreBtn:focus-visible, .goBack:focus-visible, .round:focus-visible, .lv:focus-visible, .switch:focus-visible, .plBtn:focus-visible, .again:focus-visible,
.pal:focus-visible, .run:focus-visible, .reset:focus-visible, .blk:focus-visible, .repN:focus-visible, .repX:focus-visible, .clear:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }

/* «المزيد»: white cards on the sky */
.more { position: relative; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 0 16px calc(var(--sab) + 44px); }
.sCard { width: min(700px, 100%); background: var(--panel); color: var(--ink); border-radius: 26px; padding: 22px clamp(16px, 4vw, 28px); display: flex; flex-direction: column; gap: 18px;
  box-shadow: 0 10px 0 rgba(9, 10, 40, .45), 0 16px 30px rgba(5, 6, 30, .35); }
.sCard h2 { margin: 0; font: 800 24px/1.3 var(--display); color: var(--navyInk); }
.levels { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.lv { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 2px 9px; border-radius: 16px; border: 2px solid var(--chipLine); background: var(--chip);
  color: var(--navyInk); font: 800 24px/1 var(--display); }
.lv:hover:not(:disabled) { border-color: #BCC3F2; }
.lv[aria-current="true"] { border-color: var(--rt); background: #E3EEFF; box-shadow: 0 4px 0 #B9D2F7; }
.lv:disabled { cursor: default; color: #A9AECF; background: #F7F8FD; }
.lv .st { display: flex; gap: 1px; height: 15px; align-items: center; }
.lv .st svg { width: 15px; height: 15px; }
.lv .lk { width: 16px; height: 16px; color: #B5BAD9; }
.hintLine { margin: -6px 0 0; color: var(--soft); font-size: 14px; line-height: 1.7; }
.soundRow { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.soundRow > div { display: flex; flex-direction: column; gap: 2px; }
.soundRow b { font-size: 17px; font-weight: 700; }
.soundRow span { color: var(--soft); font-size: 14px; }
.switch { flex: 0 0 64px; height: 36px; border-radius: 18px; border: 0; padding: 4px; background: #C8D3E6; display: flex; justify-content: flex-start; }
.switch span { width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch[aria-checked="true"] { background: var(--mint); justify-content: flex-end; }
.plBtn { min-height: 48px; border: 0; border-radius: 14px; background: var(--chip); color: var(--navyInk); font-size: 16px; font-weight: 700; box-shadow: inset 0 0 0 2px var(--chipLine); }
.notes { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; color: var(--soft); font-size: 15px; line-height: 1.7; }
.notes li { display: flex; align-items: flex-start; gap: 10px; }
.notes svg { flex: 0 0 20px; margin-top: 3px; }
@media (pointer: coarse) { .kbOnly { display: none !important; } }
.also { width: min(700px, 100%); display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.also a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border-radius: 999px; background: rgba(255, 255, 255, .14); color: #fff; text-decoration: none;
  font-size: 15px; font-weight: 600; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .22); }
.also a:hover { background: rgba(255, 255, 255, .24); }
.credits { margin: 0; font-size: 13px; opacity: .78; text-align: center; }
.credits a { color: #fff; }

/* ---- a level ---- */
.play { position: fixed; inset: 0; overflow: hidden; background: var(--space); user-select: none; -webkit-user-select: none; --top: calc(var(--sat) + 10px); }
.bar { position: absolute; top: var(--top); left: 14px; right: 14px; height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 10px; z-index: 6; }
.round { width: 52px; height: 52px; flex: none; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .14); color: #fff; display: grid; place-items: center;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .25); }
.round:hover { background: rgba(255, 255, 255, .22); }
.lvlPill { display: flex; flex-direction: column; align-items: center; line-height: 1.15; text-align: center; min-width: 0; }
.lvlPill b { font: 800 25px/1.2 var(--display); }
.lvlPill span { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; opacity: .88; white-space: nowrap; }
.hint { position: absolute; top: calc(var(--top) + 60px); inset-inline-start: 14px; z-index: 9; padding: 8px 14px; border-radius: 14px; background: #fff; color: var(--navyInk);
  font-size: 14px; font-weight: 700; box-shadow: 0 6px 18px rgba(5, 6, 30, .35); }
/* the board fills what the program leaves (robot.js sets the stage's edges and the cell's size) */
.stage { position: absolute; left: 14px; right: 14px; top: calc(var(--top) + 62px); bottom: 360px; display: flex; align-items: center; justify-content: center; }
/* the robot's words: over the bar held upright (the board keeps every row in sight), over the board held sideways */
.bubble { position: absolute; z-index: 7; top: calc(var(--top) + 2px); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; width: max-content;
  max-width: calc(100% - 132px); min-height: 50px; padding: 6px 12px 6px 8px; border-radius: 18px; background: #fff; color: var(--navyInk); font: 700 14px/1.45 "IBM Plex Sans Arabic", sans-serif;
  box-shadow: 0 6px 0 rgba(9, 10, 40, .35), 0 12px 24px rgba(5, 6, 30, .35); animation: rise .35s cubic-bezier(.3, 1.5, .5, 1); pointer-events: none; }
.bubble .me { width: 28px; height: 28px; flex: none; }
.play.wide .bubble { top: calc(var(--top) + 64px); max-width: min(56vw, 440px); font-size: 15px; padding: 8px 16px 8px 12px; }
.bubble.bad { color: #B42F3B; }
@keyframes rise { from { transform: translateX(-50%) translateY(10px) scale(.92); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* the program, the commands and «شغّل»: at the bottom held upright, at the side held sideways */
.panel { position: absolute; left: 14px; right: 14px; bottom: calc(var(--sab) + 12px); z-index: 5; display: flex; flex-direction: column; gap: 10px; }
.prog { background: #fff; color: var(--ink); border-radius: 22px; padding: 10px 12px 12px; box-shadow: 0 8px 0 rgba(9, 10, 40, .45), 0 16px 30px rgba(5, 6, 30, .4); }
.progHead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.progHead b { font: 800 20px/1.2 var(--display); color: var(--navyInk); }
.count { font-size: 13px; font-weight: 700; color: var(--soft); background: #EEF0FF; border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.count.full { color: #B42F3B; background: #FFE9EB; }
.clear { margin-inline-start: auto; width: 38px; height: 38px; flex: none; border: 0; border-radius: 12px; background: #F2F3FA; color: #6E7698; display: grid; place-items: center; }
.clear:disabled { opacity: .45; cursor: default; }
.code { display: flex; flex-wrap: wrap; align-items: flex-end; align-content: flex-start; gap: 12px 8px; min-height: 132px; max-height: 32vh; overflow-y: auto; padding: 14px 2px 4px; }
/* an empty program: the robot's hint for the level */
.code .empty { align-self: center; display: flex; align-items: center; gap: 8px; color: #59608A; font-size: 14px; font-weight: 700; line-height: 1.5; }
.code .empty svg { width: 30px; height: 30px; flex: none; }
.palette { display: grid; grid-template-columns: repeat(var(--tools, 4), 1fr); gap: 8px; }
.pal { position: relative; height: 72px; border: 0; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 55%), var(--c); color: #fff; font: 700 14px/1.1 "IBM Plex Sans Arabic", sans-serif;
  box-shadow: 0 5px 0 var(--d), inset 0 2px 0 rgba(255, 255, 255, .35); touch-action: manipulation; }
.pal:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--d), inset 0 2px 0 rgba(255, 255, 255, .35); }
.pal:disabled { opacity: .45; cursor: default; }
.pal svg { width: 28px; height: 28px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.pal.f { --c: var(--fwd); --d: var(--fwdD); }
.pal.r { --c: var(--rt); --d: var(--rtD); }
.pal.l { --c: var(--lt); --d: var(--ltD); }
.pal.p { --c: var(--rep); --d: var(--repD); color: var(--sunInk); }
.pal.p svg { stroke: var(--sunInk); }
.pal.no { animation: shake .4s ease; }
.runRow { display: flex; gap: 10px; }
.run { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; height: 58px; border: 0; border-radius: 20px; background: var(--sun); color: var(--sunInk);
  box-shadow: 0 6px 0 var(--sunD), 0 12px 24px rgba(5, 6, 30, .4); font: 800 27px/1 var(--display); touch-action: manipulation; }
.run:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--sunD); }
.run.stop { background: var(--coral); color: #fff; box-shadow: 0 6px 0 var(--coralD), 0 12px 24px rgba(5, 6, 30, .4); }
.reset { width: 58px; height: 58px; flex: none; border: 0; border-radius: 20px; background: rgba(255, 255, 255, .16); color: #fff; display: grid; place-items: center; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .25); }
.reset:disabled { opacity: .45; cursor: default; }
.play.wide .panel { left: auto; inset-inline-start: 22px; inset-inline-end: auto; top: calc(var(--top) + 70px); bottom: calc(var(--sab) + 18px); width: clamp(330px, 34vw, 440px); }
.play.wide .prog { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.play.wide .code { flex: 1; min-height: 0; max-height: none; --bw: 58px; --bh: 64px; }
.play.wide .code .blk svg { width: 28px; height: 28px; }
.play.wide .code .blk { font-size: 12px; }
.play.wide .code .repBody { --bw: 46px; --bh: 52px; }
.play.wide .bubble { left: calc((100% - var(--pw, 0px)) / 2); }
@media (orientation: portrait) and (max-height: 720px) {
  .code { min-height: 76px; max-height: 26vh; padding-top: 12px; --bw: 44px; --bh: 50px; }
  .code .repBody { --bw: 36px; --bh: 42px; min-height: 50px; padding: 6px; }
  .code .blk svg { width: 20px; height: 20px; }
  .code .blk { font-size: 10px; }
  .pal { height: 60px; font-size: 13px; }
  .pal svg { width: 24px; height: 24px; }
  .run, .reset { height: 52px; }
  .run { font-size: 24px; }
  .panel { gap: 8px; }
}
@media (orientation: landscape) and (max-height: 560px) {
  .play.wide .panel { top: calc(var(--top) + 60px); gap: 8px; }
  .play.wide .pal { height: 54px; font-size: 12px; }
  .play.wide .pal svg { width: 22px; height: 22px; }
  .play.wide .run, .play.wide .reset { height: 48px; }
  .play.wide .run { font-size: 22px; }
  .play.wide .code { --bw: 46px; --bh: 52px; padding-top: 12px; }
  .play.wide .code .repBody { --bw: 38px; --bh: 44px; }
}

.fx { position: absolute; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.conf { position: absolute; top: -24px; width: 10px; height: 16px; border-radius: 3px; animation: fall2 var(--d, 3s) linear forwards; }
@keyframes fall2 { to { transform: translate(var(--dx, 0), 112vh) rotate(var(--rot, 360deg)); } }

/* ---- the end of a level ---- */
.doneWrap { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: calc(var(--sat) + 96px) 16px calc(var(--sab) + 20px);
  overflow-y: auto; background: rgba(8, 9, 35, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.donePanel { position: relative; width: min(390px, 100%); margin: auto; padding: 74px 20px 22px; border-radius: 34px; background: #fff; color: var(--ink); text-align: center;
  box-shadow: 0 10px 0 #C7CBEF, 0 26px 50px rgba(5, 6, 30, .55); display: flex; flex-direction: column; align-items: center; gap: 12px; animation: up .45s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes up { from { transform: translateY(16px) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.buddy { position: absolute; top: -80px; left: 50%; width: 144px; height: 144px; margin-left: -72px; filter: drop-shadow(0 10px 12px rgba(5, 6, 30, .4)); overflow: visible;
  animation: cheer 1.6s ease-in-out infinite; }
@keyframes cheer { 0%, 100% { transform: rotate(-6deg) translateY(0); } 50% { transform: rotate(6deg) translateY(-6px); } }
.wow { width: min(250px, 70vw); height: 92px; overflow: visible; }
.stars3 { display: flex; align-items: flex-end; gap: 4px; margin-top: -4px; }
.stars3 svg { width: 64px; height: 64px; overflow: visible; }
.stars3 .mid { width: 86px; height: 86px; margin-bottom: 12px; }
.stars3 svg.on { animation: starIn .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.stars3 svg:nth-child(2).on { animation-delay: .2s; }
.stars3 svg:nth-child(3).on { animation-delay: .4s; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } to { transform: none; } }
.donePanel p { margin: 0; font-size: 17px; font-weight: 600; color: var(--soft); line-height: 1.6; }
.donePanel p b { color: var(--navyInk); }
.miniCode { display: flex; gap: 6px; align-items: flex-end; justify-content: center; flex-wrap: wrap; --bw: 38px; --bh: 42px; }
.miniCode .blk svg { width: 18px; height: 18px; }
.miniCode .blk { font-size: 0; }
.miniCode .repBody { --bw: 32px; --bh: 36px; padding: 5px; min-height: 0; }
.miniCode .repBody .blk svg { width: 15px; height: 15px; }
.donePanel .start { margin-top: 4px; font-size: 26px; }
.again { width: 100%; min-height: 52px; border-radius: 18px; border: 0; background: #EEF0FF; color: var(--navyInk); font-size: 18px; font-weight: 700; box-shadow: 0 4px 0 #D3D7F2; }
.again:active { transform: translateY(3px); box-shadow: 0 1px 0 #D3D7F2; }

@media (max-width: 520px) { .levels { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 380px) {
  .first { gap: 12px; }
  .hero { transform: scale(.9); margin: -10px 0; }
  .start { font-size: 27px; }
}
@media (max-height: 700px) {
  .first { gap: 10px; padding-top: calc(var(--sat) + 64px); }
  .hero { transform: scale(.82); margin: -18px 0; }
}
@media (prefers-reduced-motion: reduce) {
  .robot, .robot svg, .ghost, .ghost svg, .blk, .trail .band { transition: none; }
  .first .start, .buddy, .bubble, .donePanel, .stars3 svg.on, .thing.star > svg, .slot.here, .blk.new, .trail .miss.pop .x { animation: none; }
}
