* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: #0C0D14;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding-top: 16px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #e0e0e0;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 500px;
  padding: 0 8px;
}

/* ── Header ─────────────────────────────────────────────── */
#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 400px;
  padding: 8px 16px;
  background: #161822;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}

#level-info {
  color: #00ff88;
}

#move-counter {
  color: #b0b0c0;
}

/* ── Board ──────────────────────────────────────────────── */
#board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

#board {
  display: grid;
  gap: 1px;
  background: #0C0D14;
  border-radius: 4px;
  position: relative;
}

.cell {
  width: var(--cell-size, 44px);
  height: var(--cell-size, 44px);
  position: relative;
  transition: none;
}

/* Floor */
.cell-floor {
  background: #1a1a2e;
}

/* Wall */
.cell-wall {
  background: #2a2a3e;
  border-top: 2px solid #3a3a50;
  border-left: 2px solid #3a3a50;
  border-right: 2px solid #1a1a28;
  border-bottom: 2px solid #1a1a28;
}

/* Target */
.cell-target {
  background: #1a1a2e;
}

.cell-target::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 35%;
  height: 35%;
  background: #ff6b6b;
  animation: pulse-target 1.8s ease-in-out infinite;
  border-radius: 2px;
}

@keyframes pulse-target {
  0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) rotate(45deg) scale(0.8); }
  50% { opacity: 1; transform: translate(-50%, -50%) rotate(45deg) scale(1.1); }
}

/* Player */
.cell-player {
  background: #1a1a2e;
}

.cell-player::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 65%;
  height: 65%;
  background: #00ff88;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

/* Player on target */
.cell-player-on-target {
  background: #1a1a2e;
}

.cell-player-on-target::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 35%;
  height: 35%;
  background: #ff6b6b;
  opacity: 0.4;
  border-radius: 2px;
}

.cell-player-on-target::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 65%;
  height: 65%;
  background: #00ff88;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

/* Box */
.cell-box {
  background: #1a1a2e;
}

.cell-box::after {
  content: '';
  position: absolute;
  top: 12%;
  left: 12%;
  width: 76%;
  height: 76%;
  background: #c4883a;
  border-radius: 4px;
  border-top: 2px solid #daa050;
  border-left: 2px solid #daa050;
  border-right: 2px solid #8a5e20;
  border-bottom: 2px solid #8a5e20;
}

/* Box on target */
.cell-box-on-target {
  background: #1a1a2e;
}

.cell-box-on-target::after {
  content: '';
  position: absolute;
  top: 12%;
  left: 12%;
  width: 76%;
  height: 76%;
  background: #ffd700;
  border-radius: 4px;
  border-top: 2px solid #ffe44d;
  border-left: 2px solid #ffe44d;
  border-right: 2px solid #b89b00;
  border-bottom: 2px solid #b89b00;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.5);
}

/* Empty (outside walls) */
.cell-empty {
  background: #0C0D14;
}

/* Push animation on boxes */
.cell-push-anim::after {
  transition: transform 0.12s ease-out;
}

/* ── Controls ───────────────────────────────────────────── */
#controls {
  display: flex;
  gap: 8px;
}

#controls button {
  background: #1e1e30;
  color: #e0e0e0;
  border: 1px solid #333350;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

#controls button:hover {
  background: #2a2a40;
}

#controls button:active {
  background: #00ff88;
  color: #0C0D14;
}

/* ── D-Pad ──────────────────────────────────────────────── */
#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

#dpad-row-top, #dpad-row-bot {
  display: flex;
  justify-content: center;
}

#dpad-row-mid {
  display: flex;
  gap: 4px;
  align-items: center;
}

.dpad-spacer {
  width: 52px;
  height: 52px;
}

.dpad-btn {
  width: 52px;
  height: 52px;
  background: #1e1e30;
  color: #00ff88;
  border: 1px solid #333350;
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
  background: #00ff88;
  color: #0C0D14;
}

/* ── Overlays ───────────────────────────────────────────── */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(12, 13, 20, 0.92);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fade-in 0.2s ease;
}

.overlay.hidden {
  display: none;
}

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

.overlay-box {
  background: #161822;
  border: 1px solid #333350;
  border-radius: 12px;
  padding: 28px 32px;
  text-align: center;
  max-width: 380px;
  width: 90%;
}

.overlay-box h2 {
  color: #00ff88;
  margin-bottom: 16px;
  font-size: 22px;
}

.overlay-box p {
  color: #b0b0c0;
  margin-bottom: 20px;
  font-size: 15px;
  line-height: 1.5;
}

.overlay-btn {
  background: #00ff88;
  color: #0C0D14;
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}

.overlay-btn:hover {
  opacity: 0.85;
}

/* ── Level Grid ─────────────────────────────────────────── */
#level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.level-btn {
  width: 48px;
  height: 48px;
  background: #1e1e30;
  color: #e0e0e0;
  border: 1px solid #333350;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.level-btn:hover {
  background: #2a2a40;
}

.level-btn.current {
  border-color: #00ff88;
  color: #00ff88;
}

.level-btn.completed::after {
  content: '\2713';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 11px;
  color: #00ff88;
}

/* ── Celebration ────────────────────────────────────────── */
.celebration .stars {
  font-size: 36px;
  color: #ffd700;
  margin-bottom: 20px;
  animation: star-pulse 1.2s ease-in-out infinite;
}

@keyframes star-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 400px) {
  #header {
    font-size: 13px;
    padding: 6px 12px;
  }

  #controls button {
    padding: 6px 10px;
    font-size: 12px;
  }

  .dpad-btn {
    width: 46px;
    height: 46px;
    font-size: 18px;
  }

  .dpad-spacer {
    width: 46px;
    height: 46px;
  }
}

@media (min-width: 700px) {
  #dpad {
    display: none;
  }
}
