:root {
  --bg-1: #fff8fc;
  --bg-2: #f6f4ff;
  --card-bg: rgba(255, 255, 255, 0.94);
  --text: #2f2440;
  --muted: #786d8a;
  --pink: #ff78b2;
  --pink-dark: #e05597;
  --purple: #9f7dff;
  --shadow: 0 18px 46px rgba(86, 53, 116, 0.14);
  --shadow-soft: 0 10px 24px rgba(86, 53, 116, 0.1);

  --board-bg: #1c1832;
  --tile-border: #3a2f63;
  --empty-bg: rgba(255, 255, 255, 0.08);
  --tile-gap: 6px;
  --tile-radius: 10px;
}

* {
  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.55), transparent 28%),
    radial-gradient(circle at bottom left, rgba(215, 223, 255, 0.72), transparent 34%),
    linear-gradient(135deg, var(--bg-1), 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%, 960px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  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));
}

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

.hidden {
  display: none !important;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4.8vw, 48px);
  line-height: 1.15;
  text-align: center;
}

.subtitle {
  margin: 10px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.level-screen {
  text-align: center;
}

.level-buttons {
  display: grid;
  gap: 14px;
  max-width: 380px;
  margin: 24px auto 0;
}

.level-btn {
  border: none;
  border-radius: 20px;
  padding: 18px;
  background: linear-gradient(180deg, #eef3ff, #dde7ff);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.12s ease;
}

.level-btn:hover {
  transform: translateY(-2px);
}

.level-name {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

.level-desc {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.game-header {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.game-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.badge {
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #eef3ff, #dde7ff);
  box-shadow: var(--shadow-soft);
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  border: none;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
  box-shadow: var(--shadow-soft);
}

.btn-ghost {
  background: #fff;
  color: var(--text);
}

.board-wrap {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  gap: var(--tile-gap);
  padding: 10px;
  background: var(--board-bg);
  border-radius: 18px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
  width: min(92vw, 720px);
  aspect-ratio: 1 / 1;
}

.board.size-3 {
  grid-template-columns: repeat(3, 1fr);
}

.board.size-4 {
  grid-template-columns: repeat(4, 1fr);
}

.board.size-5 {
  grid-template-columns: repeat(5, 1fr);
}

.tile {
  border-radius: var(--tile-radius);
  border: 2px solid var(--tile-border);
  background-color: #1e1a36;
  background-repeat: no-repeat;
  background-size: cover;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.tile:hover {
  transform: scale(1.02);
}

.tile.empty {
  background: var(--empty-bg);
  border-color: transparent;
  cursor: default;
}

.tile.empty:hover {
  transform: none;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(19, 15, 31, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}

.modal {
  width: min(100%, 430px);
  background: #fff;
  color: var(--text);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 24px;
}

.close-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: #f2f0fa;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}

.modal-body {
  padding: 0 18px 18px;
}

.modal-body p {
  margin: 0 0 10px;
  line-height: 1.9;
}

.modal-body ul {
  margin: 0;
  padding-right: 18px;
  line-height: 1.9;
}

.center {
  text-align: center;
  padding-top: 22px;
}

.win-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

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

  .panel {
    padding: 16px;
    border-radius: 22px;
  }

  .board {
    width: min(96vw, 420px);
  }

  .btn {
    width: 100%;
  }

  .header-actions {
    display: grid;
  }
}