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

:root {
  --pink: #ff78b2;
  --pink-dark: #e05597;
  --purple: #9f7dff;
  --text: #2f2440;
  --muted: #786d8a;
  --card-bg: rgba(255, 255, 255, 0.96);
  --shadow: 0 18px 46px rgba(86, 53, 116, 0.14);
  --shadow-soft: 0 10px 24px rgba(86, 53, 116, 0.1);
  --line: #eadff6;
  --dark-board: #171326;
  --dark-board-2: #221a38;
}

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.55), transparent 28%),
    radial-gradient(circle at bottom left, rgba(215, 223, 255, 0.72), transparent 34%),
    linear-gradient(135deg, #fff8fc, #f6f4ff);
}

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%, 1120px);
}

.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-bg);
  border-radius: 30px;
  box-shadow: var(--shadow);
  padding: 24px 20px;
}

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

.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, 48px);
  line-height: 1.1;
}

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

.tetris-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 18px;
  align-items: start;
}

.side-panel {
  display: grid;
  gap: 14px;
}

.panel-card {
  background: linear-gradient(180deg, #fbf8ff, #f5f0ff);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.panel-card h3 {
  margin: 0 0 10px;
  text-align: center;
  font-size: 16px;
}

.preview-panel canvas {
  display: block;
  margin: 0 auto;
  background: #120f20;
  border: 2px solid #2a2145;
  border-radius: 16px;
}

.stats-panel {
  display: grid;
  gap: 10px;
}

.stat-row {
  background: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow-soft);
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.actions-panel {
  display: grid;
  gap: 10px;
}

.btn {
  min-height: 48px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
  box-shadow: var(--shadow-soft);
}

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

.btn.secondary {
  color: #fff;
  background: linear-gradient(135deg, #8e7dff, #6e59ff);
}

.btn.ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.help-panel p {
  margin: 6px 0;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.board-shell {
  position: relative;
  width: fit-content;
}

#gameCanvas {
  display: block;
  background:
    linear-gradient(180deg, var(--dark-board), var(--dark-board-2));
  border: 4px solid #2c224a;
  border-radius: 20px;
  box-shadow: 0 20px 45px rgba(37, 24, 65, 0.24);
  max-width: 100%;
  height: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(23, 19, 38, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  padding: 20px;
}

.overlay.show {
  display: flex;
}

.overlay-box {
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  border-radius: 22px;
  padding: 24px 18px;
  text-align: center;
  max-width: 320px;
  box-shadow: var(--shadow);
}

.overlay-box h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

.overlay-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
  font-weight: 700;
}

.mobile-controls {
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: min(100%, 420px);
}

.mobile-controls button {
  min-height: 50px;
  border: none;
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
  box-shadow: var(--shadow-soft);
}

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

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

  .tetris-layout {
    grid-template-columns: 1fr;
  }

  .mobile-controls {
    display: grid;
  }
}