*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #06142e 0%, #01010a 55%, #000 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: #f8f8ff;
}

.wrapper {
  width: 100%;
  max-width: 620px;
  padding: 16px;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: center;
  margin-bottom: 8px;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-size: 0.95rem;
}

.score-label,
.lives-label {
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.restart-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  background: #f5c33b;
  color: #1b1b1b;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3),
    0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease,
    background 0.15s ease;
}

.restart-btn:hover {
  background: #ffd54a;
}

.restart-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

canvas {
  border-radius: 8px;
  border: 2px solid #0ff;
  background: #000016;
  box-shadow: 0 0 18px rgba(0, 255, 255, 0.3);
  max-width: 100%;
}

.mobile-controls {
  display: none;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(2, 50px);
  gap: 7px;
  margin: 8px auto 2px;
  touch-action: manipulation;
}

.direction-btn {
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 255, 255, 0.58);
  border-radius: 12px;
  background: linear-gradient(145deg, #12325b, #07152f);
  color: #f7d14a;
  font: 800 1.45rem/1 system-ui, sans-serif;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 5px 12px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.direction-btn:active { transform: translateY(1px) scale(0.96); background: #174b7d; }
.direction-up { grid-column: 2; }
.direction-left { grid-column: 1; grid-row: 2; }
.direction-down { grid-column: 2; grid-row: 2; }
.direction-right { grid-column: 3; grid-row: 2; }

@media (max-width: 520px) {
  canvas {
    width: 100%;
    height: auto;
  }

  .mobile-controls { display: grid; }
}

@media (hover: none) and (pointer: coarse) {
  .mobile-controls { display: grid; }
}
