/* ---------- لعبة الثعبان — Snake theme ----------
   Uses the shared Games Hub palette (teal snake + red food). */

:root {
  --bg: #fdf3e3;
  --ink: #2b2d42;
  --muted-ink: #5a5d73;
  --card: #ffffff;
  --blue: #4aa8ff;
  --yellow: #ffd93d;
  --amber: #f5a201;
  --red: #ff6b6b;
  --teal: #4ecdc4;
  --teal-dark: #19a89f;
  --shadow: 0 12px 28px rgba(43, 45, 66, 0.14);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

body {
  font-family: "Baloo Bhaijaan 2", system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 255, 255, 0.4), transparent 34%),
    radial-gradient(circle at 88% 90%, rgba(255, 107, 107, 0.22), transparent 38%),
    linear-gradient(160deg, #4ecdc4 0%, #a9e2ff 52%, #fdf3e3 100%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-x: hidden;
}

/* ---------- Background scene (decorations only) ---------- */

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.shape {
  position: absolute;
  border-radius: 50%;
  opacity: 0.5;
  animation: float-drift 11s ease-in-out infinite;
}

.shape-1 {
  width: 110px;
  height: 110px;
  top: 16%;
  inset-inline-start: -40px;
  background: rgba(78, 205, 196, 0.25);
}

.shape-2 {
  width: 70px;
  height: 70px;
  bottom: 14%;
  inset-inline-end: 6%;
  background: rgba(255, 107, 107, 0.3);
  animation-delay: -4s;
}

.shape-3 {
  width: 46px;
  height: 46px;
  top: 32%;
  inset-inline-end: 16%;
  background: rgba(255, 217, 61, 0.4);
  animation-delay: -7s;
}

.float-emoji {
  position: absolute;
  font-size: 1.7rem;
  opacity: 0.8;
  animation: float-drift 12s ease-in-out infinite;
}

.float-1 { top: 24%; inset-inline-start: 10%; }
.float-2 { bottom: 18%; inset-inline-end: 10%; animation-delay: -5s; }
.float-3 { top: 52%; inset-inline-end: 30%; animation-delay: -9s; }

/* ---------- Game card ---------- */

.game-container {
  position: relative;
  z-index: 1;
  background: var(--card);
  border: 4px solid #ffffff;
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 26px 26px 30px;
  width: 100%;
  max-width: 520px;
  animation: card-enter 0.5s ease-out;
}

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

h1 {
  font-size: 1.9rem;
  font-weight: 800;
  background: linear-gradient(90deg, #19a89f, var(--amber));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.pause-btn {
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  background: #ffffff;
  border: 2px solid #dcefec;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s var(--spring), border-color 0.2s ease, box-shadow 0.2s ease;
}

.pause-btn:hover,
.pause-btn:focus-visible {
  transform: translateY(-2px);
  border-color: var(--teal);
  box-shadow: 0 4px 12px rgba(43, 45, 66, 0.12);
}

.pause-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

/* ---------- Score row ---------- */

.score-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  font-size: 1rem;
  font-weight: 700;
  color: #0e8a81;
  background: #eaf7f6;
  border: 2px solid #bfece8;
  border-radius: 16px;
}

.pill.best {
  color: #b45309;
  background: #fff7e6;
  border-color: #ffd9a0;
}

.pill b {
  font-size: 1.35rem;
}

/* ---------- Board ---------- */

.canvas-wrap {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  border: 3px solid var(--teal);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.55);
  background: #fffdf6;
  margin-bottom: 12px;
}

#board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.canvas-wrap::after {
  content: "⏸️ متوقفة مؤقتًا";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: #ffffff;
  background: rgba(43, 45, 66, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease;
}

body.paused .canvas-wrap::after {
  opacity: 1;
  visibility: visible;
}

/* ---------- Status ---------- */

.status {
  min-height: 1.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--muted-ink);
  margin-bottom: 16px;
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  border-radius: 999px;
  font-weight: 800;
  transition: transform 0.2s var(--spring), filter 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary {
  padding: 14px 22px;
  font-size: 1.15rem;
  color: #ffffff;
  background: linear-gradient(180deg, #4cd08a, #22b573);
  box-shadow: 0 6px 0 #128a4f, 0 8px 16px rgba(18, 138, 79, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #128a4f;
}

/* ---------- D-pad ---------- */

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-areas:
    ". up ."
    "right down left";
  gap: 8px;
  justify-content: center;
}

.dpad-btn {
  width: 64px;
  height: 54px;
  font-size: 1.3rem;
  color: var(--ink);
  background: #eaf7f6;
  border: 2px solid #bfece8;
  border-radius: 16px;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
  transform: scale(0.92);
  background: #d4efec;
}

.dpad-up    { grid-area: up; }
.dpad-left  { grid-area: left; }
.dpad-down  { grid-area: down; }
.dpad-right { grid-area: right; }

/* ---------- Game-over overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(43, 45, 66, 0.42);
  backdrop-filter: blur(2px);
  animation: fade-in 0.3s ease;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 28px 26px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  animation: card-enter 0.35s ease-out;
}

.overlay-card h2 {
  font-size: 1.6rem;
  margin-bottom: 6px;
}

.overlay-card .sub {
  color: var(--muted-ink);
  font-weight: 600;
  margin-bottom: 16px;
}

.overlay-stats {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

/* ---------- Keyframes ---------- */

@keyframes card-enter {
  from { transform: translateY(20px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes float-drift {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-20px) rotate(4deg); }
}

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
  .game-container {
    padding: 20px 14px 24px;
    border-radius: 22px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .game-header {
    flex-direction: column;
    gap: 10px;
  }

  .dpad {
    grid-template-columns: repeat(3, 56px);
  }

  .dpad-btn {
    width: 56px;
    height: 48px;
  }

  .pill {
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .pill b {
    font-size: 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Back to hub link ---------- */

.back-hub {
  position: fixed;
  top: 14px;
  inset-inline-start: 14px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.35em 0.9em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(43, 45, 66, 0.22);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.back-hub:hover,
.back-hub:focus-visible {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 7px 18px rgba(43, 45, 66, 0.3);
}