/* ---------- tokens ---------- */
:root {
  --bg: #0e0b24;
  --bg2: #150f36;
  --card: #1d1650;
  --card2: #271e66;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f6f3ff;
  --muted: #aca5dc;
  --orange: #ff8a3d;
  --pink: #ff4d8d;
  --cyan: #35e0ff;
  --lime: #a6ff4d;
  --yellow: #ffd23f;
  --violet: #8b5cff;
  --red: #ff5263;
  --green: #35dd87;
  --r: 22px;
  --display: 'Readex Pro', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
a { color: inherit; }
b { font-weight: 700; }
code { font-family: var(--mono); font-size: 0.88em; background: rgba(255, 255, 255, 0.09); padding: 0.1em 0.4em; border-radius: 6px; }
.t { color: var(--green); }
.f { color: var(--red); }
[hidden] { display: none !important; }

/* ---------- chunky buttons ---------- */
.btn {
  --c: var(--orange);
  --c-dark: color-mix(in srgb, var(--c) 62%, #000);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 26px;
  border-radius: 18px;
  background: var(--c);
  color: #1a1030;
  font-weight: 800; font-size: 18px; letter-spacing: 0.01em;
  box-shadow: 0 6px 0 var(--c-dark);
  transform: translateY(0);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.2s, opacity 0.2s;
  text-decoration: none;
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 var(--c-dark); }
.btn:disabled { --c: #3a3370; color: #8d86c0; box-shadow: 0 6px 0 #25204f; cursor: not-allowed; }
.btn-ghost { --c: #2a2270; color: var(--text); }
.btn-good { --c: var(--green); }
.btn-bad { --c: var(--red); color: #fff; }
.btn-cyan { --c: var(--cyan); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center; font-size: 20px;
  background: rgba(255, 255, 255, 0.06);
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- mascot animation ---------- */
.mascot { display: block; width: 100%; height: auto; overflow: visible; }
.mascot .m-crest { transform-origin: 108px 54px; animation: crest 2.6s ease-in-out infinite; }
.mascot .m-eye { transform-origin: 128px 72px; animation: blink 4s infinite; }
.mascot .m-tail { transform-origin: 62px 130px; animation: tail 1.8s ease-in-out infinite; }
.mascot .m-head { transform-origin: 110px 100px; animation: nod 3.2s ease-in-out infinite; }
.mascot.bounce .m-body { animation: bounce 1.1s ease-in-out infinite; transform-origin: 100px 180px; }
.mascot.dance .m-body { animation: dance 0.7s ease-in-out infinite; transform-origin: 100px 180px; }
@keyframes crest { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(8deg) scale(1.05); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes tail { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-8deg); } }
@keyframes nod { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-4deg); } }
@keyframes bounce { 0%, 100% { transform: translateY(0) scale(1, 1); } 45% { transform: translateY(-10px) scale(0.98, 1.03); } 90% { transform: translateY(0) scale(1.04, 0.96); } }
@keyframes dance { 0%, 100% { transform: rotate(-7deg) translateY(0); } 50% { transform: rotate(7deg) translateY(-12px); } }

/* ---------- code blocks ---------- */
.code {
  margin: 0;
  font-family: var(--mono); font-size: 16px; line-height: 1.7;
  background: #0a0820;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  white-space: pre-wrap;
  overflow-x: auto;
}
.code i, .demo-code i { font-style: normal; }
/* Code and world coordinates always read left-to-right, in either locale. */
.code, .demo-code, .console, .code-chip, .blank, .rule, .code-input,
code, .orb, .orb-tag, .tok, .var-lid, .gate, [dir="ltr"] {
  direction: ltr;
  unicode-bidi: isolate;
}
.code, .demo-code, .console, .code-chip, .code-input { text-align: left; }
.board, .prog, .palette, .vars { direction: ltr; }
html[lang="ar"] body { line-height: 1.6; }
html[lang="ar"] :is(h1, h2, h3, .brand, .btn, .kicker, .pill, .start-tag, .unit-card small, .marquee-track, .big-stats b) {
  letter-spacing: normal;
}
html[lang="ar"] :is(h1, h2, h3) { line-height: 1.3; }
.tk-k { color: var(--pink); font-weight: 700; }
.tk-s { color: var(--lime); }
.tk-n { color: var(--yellow); }
.tk-f { color: var(--cyan); }
.tk-c { color: #7d76b3; }
.ln { display: inline-block; width: 100%; border-radius: 6px; padding: 0 6px; margin: 0 -6px; transition: background 0.2s, box-shadow 0.2s; }
.ln.on { background: rgba(255, 210, 63, 0.16); box-shadow: inset 3px 0 0 var(--yellow); }

/* ---------- board (grid world) ---------- */
.board {
  --n: 5;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 20px;
  background: #1a3b2c;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.2), 0 10px 30px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.board .cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), 1fr); }
.board .cell { background: #2a6a47; }
.board .cell.alt { background: #317a52; }
.board .piece {
  position: absolute; left: 0; top: 0;
  width: calc(100% / var(--n)); height: calc(100% / var(--n));
  transform: translate(calc(var(--x, 0) * 100%), calc(var(--y, 0) * 100%));
  display: grid; place-items: center;
}
.board .rock i {
  width: 78%; height: 70%;
  background: radial-gradient(circle at 35% 30%, #a39ec4, #5f5a85 60%, #3e3a60);
  border-radius: 46% 54% 40% 60% / 60% 55% 45% 40%;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
}
.board .goal svg { width: 62%; filter: drop-shadow(0 0 10px rgba(53, 224, 255, 0.8)); animation: gem 1.6s ease-in-out infinite; }
.board .goal.got svg { animation: gem-got 0.7s forwards; }
@keyframes gem { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8%) rotate(4deg); } }
@keyframes gem-got { 0% { transform: scale(1); } 40% { transform: scale(1.6) rotate(20deg); } 100% { transform: scale(0) rotate(180deg); opacity: 0; } }
.board .bird { transition: transform 0.3s cubic-bezier(0.5, 0, 0.3, 1.3); z-index: 2; }
.board .bird.no-anim { transition: none; }
.board .bird-hop { width: 96%; }
.board .bird-face { transition: transform 0.2s; }
.board .bird.flip .bird-face { transform: scaleX(-1); }
.board .bird-hop.hop { animation: hop 0.3s ease-out; }
.board .bird-hop.bump { animation: bump 0.5s ease-out; }
.board .bird-hop.dance { animation: win-dance 0.5s ease-in-out 3; }
@keyframes hop { 50% { transform: translateY(-18%) scale(1.05); } }
@keyframes bump {
  30% { transform: translate(calc(var(--dx) * 30%), calc(var(--dy) * 30%)) rotate(-12deg); }
  55% { transform: translate(calc(var(--dx) * -8%), calc(var(--dy) * -8%)) rotate(8deg); }
  75% { transform: rotate(-4deg); }
}
@keyframes win-dance { 25% { transform: translateY(-20%) rotate(-10deg); } 75% { transform: translateY(-20%) rotate(10deg); } }

/* ---------- self-playing demo ---------- */
.demo { display: grid; grid-template-columns: 1fr 1.1fr; gap: 14px; align-items: center; }
.demo-code {
  margin: 0; font-family: var(--mono); font-size: 15px; line-height: 1.9;
  background: #0a0820; border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
  color: var(--cyan); white-space: pre; min-width: 0; overflow-x: auto;
}
.demo .board { border-radius: 16px; }

/* ---------- fx ---------- */
.confetti-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 999; }
.float-text {
  position: fixed; z-index: 998; pointer-events: none;
  font-weight: 800; font-size: 22px; transform: translate(-50%, 0);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  animation: float-up 1s ease-out forwards;
  max-width: calc(100vw - 24px); text-align: center; white-space: nowrap;
}
@keyframes float-up { to { transform: translate(-50%, -70px) scale(1.2); opacity: 0; } }
.toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); z-index: 997;
  transform: translateX(-50%);
  background: #fff; color: #1a1030; font-weight: 700;
  padding: 12px 20px; border-radius: 99px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.3s cubic-bezier(0.3, 1.4, 0.5, 1);
  width: max-content; max-width: calc(100vw - 24px); text-align: center;
}
.toast.out { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in { from { transform: translate(-50%, 20px) scale(0.9); opacity: 0; } }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

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