* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-image: url(img/snake.jpg);
  background-color: #272729;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-repeat: no-repeat;
  background-position: center;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #fff;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
}

header {
  text-align: center;
}

header h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  background: linear-gradient(90deg, #4ade80, #22d3ee);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stats {
  display: flex;
  gap: 2rem;
  justify-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: bold;
  color: #4ade80;
}

main {
  position: relative;
}

#game-canvas {
  display: block;
  border-radius: 12px;
  border: 3px solid rgba(74, 222, 128, 0.4);
  box-shadow: 0 0 40px rgba(74, 222, 128, 0.15),
              inset 0 0 60px rgba(0, 0, 0, 0.3);
  background: #1a1a2e;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 12px;
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  padding: 2rem;
}

.overlay-content h2 {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
  color: #4ade80;
}

.overlay-content p {
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 1.5rem;
}

.btn {
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  color: #0f0c29;
  background: linear-gradient(90deg, #4ade80, #22d3ee);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(74, 222, 128, 0.4);
}

.btn:active {
  transform: translateY(0);
}

footer {
  text-align: center;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: bold;
}

.controls-text {
  margin-left: 0.5rem;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
}

.hint {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.4);
}

.virtual-controls {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 400px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(74, 222, 128, 0.25);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.dpad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background 0.12s, transform 0.1s, box-shadow 0.12s;
  touch-action: manipulation;
}

.dpad-btn:not(.dpad-center):hover {
  background: rgba(74, 222, 128, 0.2);
}

.dpad-btn:not(.dpad-center):active,
.dpad-btn:not(.dpad-center).active {
  background: rgba(74, 222, 128, 0.45);
  transform: scale(0.94);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

.dpad-icon {
  font-size: 1.1rem;
  line-height: 1;
  pointer-events: none;
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
  border-radius: 10px 10px 4px 4px;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
  border-radius: 10px 4px 4px 10px;
}

.dpad-center {
  grid-column: 2;
  grid-row: 2;
  background: rgba(74, 222, 128, 0.15);
  border: 1px solid rgba(74, 222, 128, 0.3);
  border-radius: 8px;
  cursor: default;
  pointer-events: none;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
  border-radius: 4px 10px 10px 4px;
}

.dpad-down {
  grid-column: 2;
  grid-row: 3;
  border-radius: 4px 4px 10px 10px;
}

.virtual-pause-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  font-size: 1.25rem;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(34, 211, 238, 0.4);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  touch-action: manipulation;
}

.virtual-pause-btn:active {
  background: rgba(34, 211, 238, 0.35);
  transform: scale(0.94);
}

body.touch-device .virtual-controls {
  display: flex;
}

body.touch-device footer {
  display: none;
}

@media (max-width: 768px) {
  body.touch-device .container {
    padding: 1rem;
    gap: 1rem;
  }

  body.touch-device header h1 {
    font-size: 1.75rem;
  }

  body.touch-device #game-canvas {
    width: min(90vw, 400px);
    height: min(90vw, 400px);
  }
}
