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

body {
  font-family: 'Nunito', sans-serif;
  background: #1a1a2e;
  background-image: radial-gradient(circle at 30% 70%, #16213e 0%, #1a1a2e 60%);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: #fff;
  user-select: none;
  touch-action: none;
}

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-back {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.15);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-back:hover { background: rgba(255,255,255,0.3); }

.game-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 0.8rem;
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.9;
  white-space: nowrap;
}

/* ===== GAME CONTAINER ===== */
.game-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0.5rem;
  min-height: 0;
}

/* ===== BOARD ===== */
#board {
  display: grid;
  gap: 1px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  border: 2px solid rgba(255,255,255,0.1);
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  line-height: 1;
  transition: background 0.1s;
}

/* Cell types */
.cell-wall {
  background: #2c2c54;
}

.cell-floor {
  background: #0f3460;
}

.cell-target {
  background: #0f3460;
  position: relative;
}
.cell-target::after {
  content: '';
  width: 35%;
  height: 35%;
  border-radius: 50%;
  background: rgba(233, 69, 96, 0.5);
  position: absolute;
}

.cell-player {
  background: #0f3460;
}

.cell-box {
  background: #0f3460;
}

.cell-box-on-target {
  background: rgba(83, 215, 105, 0.15);
}

.cell-player-on-target {
  background: #0f3460;
  position: relative;
}

.cell-void {
  background: #1a1a2e;
}

/* ===== OVERLAY ===== */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 10;
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }

.overlay-content {
  text-align: center;
  animation: popIn 0.3s ease;
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.overlay-icon { font-size: 3.5rem; margin-bottom: 0.5rem; }
.overlay-content h2 {
  font-size: 1.8rem;
  font-weight: 800;
  color: #e94560;
  margin-bottom: 0.3rem;
}
.overlay-content p {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 0.3rem;
}
.overlay-score {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 0.6rem 1.8rem;
  border: none;
  border-radius: 999px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  margin-top: 0.8rem;
}
.btn:active { transform: scale(0.96); }
.btn-orange { background: #e94560; color: #fff; }
.btn-orange:hover { opacity: 0.88; }

/* ===== CONTROLS BAR ===== */
.controls-bar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  flex-shrink: 0;
}

.ctrl-action {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-action:hover { background: rgba(255,255,255,0.25); }
.ctrl-action:active { transform: scale(0.96); }

/* ===== MOBILE CONTROLS ===== */
.mobile-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 0.2rem 0 0.6rem;
  gap: 0.2rem;
  flex-shrink: 0;
}

.ctrl-row {
  display: flex;
  gap: 0.3rem;
}

.ctrl-btn {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 14px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:active { background: rgba(255,255,255,0.3); }

/* Show mobile controls on touch devices */
@media (max-width: 768px) {
  .mobile-controls { display: flex; }
  .game-title { font-size: 0.95rem; }
  .cell { font-size: 1.1rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .mobile-controls { display: flex; flex-direction: row; padding: 0.2rem; gap: 0.5rem; }
  .ctrl-row { gap: 0.2rem; }
  .ctrl-btn { width: 44px; height: 44px; font-size: 1rem; border-radius: 10px; }
  .topbar { padding: 0.25rem 0.5rem; }
  .game-title { display: none; }
  .controls-bar { padding: 0.2rem; }
  .cell { font-size: 0.9rem; }
}

@media (max-width: 380px) {
  .ctrl-btn { width: 48px; height: 48px; font-size: 1.1rem; }
  .cell { font-size: 1rem; }
}

/* ===== SEO GAME INFO SECTION ===== */
body:has(.game-info) { overflow-y: auto; height: auto; min-height: 100dvh; }
.game-info {
  max-width: 780px;
  margin: 1rem auto;
  padding: 1rem 1.2rem;
  background: rgba(0,0,0,0.15);
  border-radius: 12px;
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
  line-height: 1.6;
}
.game-info h2 { font-size: 1.1rem; font-weight: 800; margin-bottom: 0.5rem; }
.game-info h3 { font-size: 0.95rem; font-weight: 700; margin: 0.8rem 0 0.3rem; }
.game-info ul { padding-left: 1.2rem; }
.game-info li { margin-bottom: 0.2rem; }
