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

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

  --square-light: #f0d9b5;
  --square-dark: #b58863;
  --square-highlight: rgba(255, 215, 0, 0.35);
  --square-move: rgba(80, 180, 120, 0.35);
  --square-check: rgba(220, 70, 70, 0.45);
}

html {
  direction: rtl;
}

body {
  font-family: Tahoma, Arial, sans-serif;
  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));
  color: var(--text);
  min-height: 100vh;
}

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

button {
  font-family: inherit;
}

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

.game-shell {
  width: min(100%, 860px);
}

.game-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.85);
  box-shadow: var(--shadow-soft);
  font-weight: 700;
}

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

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

.wrapper {
  width: 100%;
  background: var(--card);
  border-radius: 32px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

/* شاشة اختيار النمط */
.mode-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 520px;
}

.mode-card {
  width: min(100%, 420px);
  text-align: center;
}

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

.mode-screen h1,
.game-screen .header h1 {
  font-size: clamp(30px, 5vw, 48px);
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--text);
}

.mode-subtitle {
  color: var(--muted);
  margin-bottom: 22px;
  line-height: 1.9;
  font-size: 15px;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 280px;
  margin: 0 auto;
}

.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid rgba(159, 125, 255, 0.18);
  border-radius: 16px;
  cursor: pointer;
  transition: 0.2s ease;
  box-shadow: var(--shadow-soft);
}

.mode-btn:hover {
  background: rgba(255, 120, 178, 0.08);
  border-color: var(--pink);
  transform: translateY(-2px);
}

.mode-icon {
  font-size: 1.45rem;
}

/* شاشة اللعبة */
.game-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.game-screen .header {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
}

.title-wrap {
  min-width: 0;
}

.game-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.turn-label {
  font-weight: 700;
  color: var(--text);
}

.mode-badge {
  font-size: 0.85rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
}

.btn {
  font-size: 0.92rem;
  font-weight: 700;
  padding: 0.62rem 1rem;
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s ease;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(120, 109, 138, 0.28);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.7);
}

.btn-large {
  padding: 0.8rem 1.4rem;
  font-size: 1rem;
  margin-top: 0.5rem;
}

/* الرقعة */
.game-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(90vw, 520px);
  height: min(90vw, 520px);
  max-width: 520px;
  max-height: 520px;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.18);
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, 5vw, 2.75rem);
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.square.light {
  background: var(--square-light);
  color: #333;
}

.square.dark {
  background: var(--square-dark);
  color: #1a1a1a;
}

.square.highlight {
  background: var(--square-highlight) !important;
}

.square.move-target {
  background: var(--square-move) !important;
}

.square.check {
  background: var(--square-check) !important;
}

.square.last-move {
  outline: 2px solid rgba(255, 200, 0, 0.8);
  outline-offset: -2px;
}

.square.dragging {
  opacity: 0.85;
}

/* ترقية الجندي */
.promotion-overlay {
  position: absolute;
  inset: 0;
  background: rgba(47, 36, 64, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  border-radius: 18px;
  z-index: 10;
}

.promotion-overlay p {
  font-size: 0.95rem;
  color: #fff;
}

.promotion-pieces {
  display: flex;
  gap: 0.5rem;
}

.promotion-piece-btn {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  transition: 0.2s ease;
}

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

/* نهاية اللعبة */
.game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(47, 36, 64, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 1rem;
}

.game-over-box {
  background: rgba(255, 255, 255, 0.96);
  padding: 2rem;
  border-radius: 22px;
  text-align: center;
  max-width: 360px;
  color: var(--text);
  box-shadow: var(--shadow);
}

.game-over-box h2 {
  font-size: 1.6rem;
  margin-bottom: 0.6rem;
}

.game-over-box p {
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.8;
}

.game-note {
  color: var(--muted);
  line-height: 1.9;
  font-size: 14px;
  text-align: center;
}

/* Responsive */
@media (max-width: 520px) {
  .wrapper {
    padding: 14px;
    border-radius: 24px;
  }

  .board {
    width: min(95vw, 360px);
    height: min(95vw, 360px);
    min-width: 280px;
    min-height: 280px;
    border-radius: 14px;
  }

  .square {
    font-size: clamp(1.25rem, 4.5vw, 2rem);
  }

  .turn-label {
    font-size: 0.9rem;
  }

  .btn,
  .btn-ghost {
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
  }

  .game-over-box {
    padding: 1.4rem;
  }

  .promotion-piece-btn {
    width: 44px;
    height: 44px;
    font-size: 1.75rem;
  }
}

@media (max-width: 380px) {
  .mode-screen h1,
  .game-screen .header h1 {
    font-size: 1.9rem;
  }

  .board {
    width: min(100vw - 1rem, 320px);
    height: min(100vw - 1rem, 320px);
    min-width: 256px;
    min-height: 256px;
  }

  .square {
    font-size: clamp(1rem, 3.5vw, 1.5rem);
  }
}

@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}