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

body {
  background: #030a06;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Orbitron', monospace;
  overflow: hidden;
}

.back-link {
  position: fixed;
  top: 16px;
  left: 16px;
  color: rgba(120, 220, 160, 0.6);
  font-size: 0.7rem;
  text-decoration: none;
  letter-spacing: 0.05em;
  z-index: 100;
  transition: color 0.2s;
}

.back-link:hover {
  color: #4ade80;
}

#game-container {
  position: relative;
  width: min(100vw, 420px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#hud {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0 4px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-label {
  font-size: 0.5rem;
  letter-spacing: 0.15em;
  color: rgba(120, 200, 150, 0.5);
}

#score, #best, #length {
  font-size: 1rem;
  font-weight: 700;
  color: #bbf7d0;
  text-shadow: 0 0 10px rgba(74, 222, 128, 0.7);
}

#game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  background: #061208;
  border: 1px solid rgba(74, 222, 128, 0.2);
  box-shadow:
    0 0 40px rgba(34, 197, 94, 0.15),
    inset 0 0 60px rgba(0, 0, 0, 0.4);
}

#dpad {
  display: none;
  position: relative;
  width: 140px;
  height: 100px;
  margin-top: 4px;
}

@media (hover: none) and (pointer: coarse) {
  #dpad {
    display: block;
  }
}

.dpad-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  font-size: 0.9rem;
  padding: 0;
  background: rgba(20, 60, 35, 0.8);
  border: 1px solid rgba(74, 222, 128, 0.3);
  border-radius: 8px;
  color: #4ade80;
  box-shadow: 0 0 12px rgba(74, 222, 128, 0.15);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
  background: rgba(74, 222, 128, 0.25);
  transform: scale(0.92);
}

.dpad-btn.up    { top: 0;    left: 50%; transform: translateX(-50%); }
.dpad-btn.down  { bottom: 0; left: 50%; transform: translateX(-50%); }
.dpad-btn.left  { bottom: 0; left: 0; }
.dpad-btn.right { bottom: 0; right: 0; }

.dpad-btn.up:active    { transform: translateX(-50%) scale(0.92); }
.dpad-btn.down:active  { transform: translateX(-50%) scale(0.92); }

#overlay, #gameover {
  position: absolute;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(3, 12, 6, 0.88);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  z-index: 20;
  text-align: center;
  padding: 24px;
  transition: opacity 0.4s ease;
}

#overlay.hidden, #gameover.hidden {
  opacity: 0;
  pointer-events: none;
}

#overlay.visible {
  opacity: 1;
}

h1 {
  font-size: clamp(1.3rem, 5vw, 1.8rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, #4ade80, #22d3ee, #a3e635);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

h2 {
  font-size: 1.5rem;
  color: #f87171;
  text-shadow: 0 0 20px rgba(248, 113, 113, 0.6);
  margin-bottom: 12px;
  letter-spacing: 0.1em;
}

.subtitle {
  color: rgba(150, 220, 170, 0.65);
  font-size: 0.7rem;
  margin-bottom: 20px;
  letter-spacing: 0.04em;
  line-height: 1.5;
}

.controls-hint {
  color: rgba(120, 180, 140, 0.55);
  font-size: 0.6rem;
  line-height: 2;
  margin-bottom: 24px;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  background: rgba(40, 100, 60, 0.25);
  border: 1px solid rgba(74, 222, 128, 0.25);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.55rem;
}

button#start-btn,
button#restart-btn {
  font-family: 'Orbitron', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  padding: 14px 40px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: linear-gradient(135deg, #16a34a, #059669);
  color: white;
  box-shadow: 0 0 30px rgba(34, 197, 94, 0.45);
  transition: transform 0.15s, box-shadow 0.15s;
}

button#start-btn:hover,
button#restart-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 40px rgba(34, 197, 94, 0.6);
}

button#start-btn:active,
button#restart-btn:active {
  transform: scale(0.97);
}

#gameover p {
  color: rgba(180, 230, 200, 0.75);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

#final-score {
  color: #4ade80;
  font-weight: 700;
}
