*,
*::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;
  --x-color: #ff5f95;
  --o-color: #6d7cff;
  --win-bg: #dff8e7;
}

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,
select {
  font-family: inherit;
}

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

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

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

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

.game-panel {
  max-width: 560px;
  margin: 0 auto;
}

.setup-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.select-group {
  background: linear-gradient(180deg, #fbf8ff, #f5f0ff);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  box-shadow: var(--shadow-soft);
}

.select-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
  color: var(--text);
}

.select-group select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  outline: none;
}

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

.turn-badge,
.mode-note {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow-soft);
  display: inline-flex;
  align-items: center;
  font-weight: 800;
}

.turn-badge {
  color: var(--text);
}

.mode-note {
  color: var(--muted);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: linear-gradient(180deg, #fbf8ff, #f5f0ff);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 12px;
  box-shadow: var(--shadow-soft);
}

.cell {
  aspect-ratio: 1 / 1;
  min-height: 90px;
  border: none;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-size: clamp(42px, 7vw, 64px);
  font-weight: 800;
  transition: transform 0.12s ease, background 0.2s ease;
}

.cell:hover {
  transform: translateY(-2px);
  background: #fffafd;
}

.cell:active {
  transform: scale(0.97);
}

.cell.x {
  color: var(--x-color);
}

.cell.o {
  color: var(--o-color);
}

.cell.win {
  background: var(--win-bg);
  animation: winPulse 0.9s ease-in-out infinite alternate;
}

@keyframes winPulse {
  from {
    transform: scale(1);
    box-shadow: 0 8px 20px rgba(74, 222, 128, 0.14);
  }
  to {
    transform: scale(1.03);
    box-shadow: 0 10px 24px rgba(74, 222, 128, 0.24);
  }
}

.status {
  margin-top: 16px;
  min-height: 56px;
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px 16px;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.status.success {
  color: #1f8f4d;
}

.status.draw {
  color: #d14f6f;
}

.actions {
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

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

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

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

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

  .setup-panel {
    grid-template-columns: 1fr;
  }

  .status-bar {
    justify-content: center;
  }

  .cell {
    min-height: 84px;
    border-radius: 16px;
  }

  .status {
    font-size: 16px;
  }
}