:root {
  --bg: #fff8fc;
  --bg-2: #f7f1ff;
  --card: rgba(255, 255, 255, 0.96);
  --text: #2f2440;
  --muted: #7b6e8f;
  --pink: #ff78b2;
  --pink-dark: #e25595;
  --purple: #9b7bff;
  --maze-bg: #f6ede9;
  --wall-color: #4b3d58;
  --joystick-color: #5b3f73;
  --joystick-head-color: #ff7da9;
  --ball-color: #ff7da9;
  --end-color: #8b92d9;
  --shadow: 0 18px 46px rgba(86, 53, 116, 0.14);
  --shadow-soft: 0 10px 24px rgba(86, 53, 116, 0.1);
  --line: #eadff6;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  direction: rtl;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Cairo", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(255, 203, 227, 0.58), transparent 28%),
    radial-gradient(circle at bottom left, rgba(215, 223, 255, 0.75), transparent 34%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

.page {
  min-height: 100vh;
  padding: 20px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shell {
  width: min(100%, 1100px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.back-link,
.brand-badge {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-soft);
  font-weight: 700;
}

.back-link {
  color: var(--muted);
}

.brand-badge {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--purple));
}

.game-card {
  background: var(--card);
  border-radius: 30px;
  box-shadow: var(--shadow);
  padding: 24px 20px;
}

.title-wrap {
  text-align: center;
  margin-bottom: 18px;
}

.game-kicker {
  margin: 0 0 6px;
  color: var(--pink-dark);
  font-size: 14px;
  font-weight: 800;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.1;
}

.game-desc {
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.8;
  max-width: 760px;
}

.toolbar {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar-btn {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.toolbar-btn.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--pink), var(--purple));
}

#center {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: grid;
  grid-template-columns: minmax(300px, 350px) minmax(220px, 260px);
  gap: 24px;
  align-items: center;
  perspective: 700px;
}

#maze {
  position: relative;
  width: 350px;
  height: 315px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--maze-bg);
  border-radius: 24px;
  box-shadow: inset 0 0 0 1px rgba(75, 61, 88, 0.08), var(--shadow-soft);
  transition: transform 0.06s linear;
}

#end {
  width: 65px;
  height: 65px;
  border: 5px dashed var(--end-color);
  border-radius: 50%;
}

.side-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#joystick {
  position: relative;
  background-color: var(--joystick-color);
  border-radius: 50%;
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 6px;
}

#joystick-head {
  position: relative;
  background-color: var(--joystick-head-color);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: grab;
  animation: glow 0.7s ease-in-out infinite alternate 3s;
}

@keyframes glow {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.18);
  }
}

.joystick-arrow:nth-of-type(1),
.joystick-arrow:nth-of-type(2),
.joystick-arrow:nth-of-type(3),
.joystick-arrow:nth-of-type(4) {
  position: absolute;
  width: 0;
  height: 0;
}

.joystick-arrow:nth-of-type(1) {
  bottom: 66px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 10px solid var(--joystick-color);
}

.joystick-arrow:nth-of-type(2) {
  top: 66px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid var(--joystick-color);
}

.joystick-arrow:nth-of-type(3) {
  left: 66px;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 10px solid var(--joystick-color);
}

.joystick-arrow:nth-of-type(4) {
  right: 66px;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid var(--joystick-color);
}

#note {
  width: 100%;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text);
  background: linear-gradient(180deg, #fbf8ff, #f5f0ff);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  box-shadow: var(--shadow-soft);
  transition: opacity 0.5s ease;
  line-height: 1.7;
}

#note p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.ball {
  position: absolute;
  margin-top: -5px;
  margin-left: -5px;
  border-radius: 50%;
  background-color: var(--ball-color);
  width: 10px;
  height: 10px;
  box-shadow: 0 0 0 4px rgba(255, 125, 169, 0.12);
}

.wall {
  position: absolute;
  background-color: var(--wall-color);
  transform-origin: top center;
  margin-left: -5px;
  border-radius: 999px;
}

.wall::before,
.wall::after {
  display: block;
  content: "";
  width: 10px;
  height: 10px;
  background-color: inherit;
  border-radius: 50%;
  position: absolute;
}

.wall::before {
  top: -5px;
}

.wall::after {
  bottom: -5px;
}

.black-hole {
  position: absolute;
  margin-top: -9px;
  margin-left: -9px;
  border-radius: 50%;
  background-color: #111;
  width: 18px;
  height: 18px;
  box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.08);
}

.touch-controls {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.touch-mid {
  display: flex;
  gap: 8px;
}

.touch-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow-soft);
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
}

.touch-btn:active {
  transform: scale(0.95);
}

@media (max-width: 900px) {
  #game {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .side-panel {
    width: min(100%, 380px);
  }
}

@media (max-width: 420px) {
  .page {
    padding: 14px 10px;
    align-items: flex-start;
  }

  .game-card {
    padding: 18px 14px;
    border-radius: 24px;
  }

  #maze {
    width: 350px;
    max-width: 100%;
    transform-origin: center center;
  }

  #note {
    font-size: 0.88rem;
  }
}