@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700;900&display=swap');

:root {
  --bg: #050a05;
  --grid: #0d1f0d;
  --snake-head: #39ff14;
  --snake-body: #1aff1a;
  --snake-tail: #0a8a0a;
  --food: #ff3c3c;
  --food-glow: #ff000088;
  --accent: #39ff14;
  --dim: #1a3a1a;
  --text: #c8ffc8;
  --score-bg: #061206;
}

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

body {
  background: var(--bg);
  font-family: 'Share Tech Mono', monospace;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  user-select: none;
  padding-bottom: 100px;
  box-sizing: border-box;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(0deg,
      transparent,
      transparent 2px,
      rgba(0, 255, 0, 0.015) 2px,
      rgba(0, 255, 0, 0.015) 4px);
  pointer-events: none;
  z-index: 10;
}

.title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(2rem, 6vw, 3.5rem);
  color: var(--accent);
  letter-spacing: 0.3em;
  text-shadow:
    0 0 20px var(--accent),
    0 0 40px var(--accent),
    0 0 80px rgba(57, 255, 20, 0.3);
  margin-bottom: 1.5rem;
  animation: flicker 6s infinite;
}

@keyframes flicker {

  0%,
  96%,
  98%,
  100% {
    opacity: 1;
  }

  97% {
    opacity: 0.85;
  }

  99% {
    opacity: 0.92;
  }
}

.hud {
  display: flex;
  gap: 2rem;
  margin-bottom: 1rem;
  width: 100%;
  max-width: 480px;
  justify-content: space-between;
}

.stat-box {
  background: var(--score-bg);
  border: 1px solid var(--dim);
  padding: 0.5rem 1rem;
  flex: 1;
  text-align: center;
  position: relative;
  clip-path: polygon(4px 0%, 100% 0%, calc(100% - 4px) 100%, 0% 100%);
}

.stat-box::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--accent);
  opacity: 0.4;
}

.stat-label {
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  color: #4a8a4a;
  text-transform: uppercase;
  display: block;
  margin-bottom: 0.15rem;
}

.stat-value {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent);
  transition: transform 0.1s;
}

.stat-value.bump {
  transform: scale(1.3);
  color: #fff;
  text-shadow: 0 0 15px #fff;
}

.canvas-wrapper {
  position: relative;
  border: 2px solid var(--dim);
  box-shadow:
    0 0 0 1px #0a2a0a,
    0 0 30px rgba(57, 255, 20, 0.15),
    inset 0 0 30px rgba(0, 0, 0, 0.8);
}

canvas {
  display: block;
  background: var(--bg);
  image-rendering: pixelated;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(5, 10, 5, 0.88);
  gap: 1rem;
}

.overlay.hidden {
  display: none !important;
  /* Added priority tag to prevent style override issues */
}

.overlay-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent);
  letter-spacing: 0.2em;
}

.overlay-sub {
  font-size: 0.75rem;
  color: #4a8a4a;
  letter-spacing: 0.15em;
  text-align: center;
  line-height: 1.8;
}

.btn {
  font-family: 'Orbitron', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.6rem 2rem;
  cursor: pointer;
  transition: all 0.15s;
  clip-path: polygon(6px 0%, 100% 0%, calc(100% - 6px) 100%, 0% 100%);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: translateX(-100%);
  transition: transform 0.15s;
}

.btn:hover::before {
  transform: translateX(0);
}

.btn:hover {
  color: var(--bg);
  text-shadow: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn span {
  position: relative;
  z-index: 1;
}

.controls-hint {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.8rem;
  justify-content: center;
}

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.6rem;
  color: #3a6a3a;
  letter-spacing: 0.1em;
}

.key-symbol {
  border: 1px solid #1a4a1a;
  padding: 0.15rem 0.4rem;
  font-size: 0.65rem;
  color: #4a9a4a;
  background: #051005;
}

.game-over-score {
  font-family: 'Orbitron', sans-serif;
  font-size: 0.9rem;
  color: #4a9a4a;
  letter-spacing: 0.1em;
}

#scanline {
  position: absolute;
  top: -100%;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(transparent, rgba(57, 255, 20, 0.03), transparent);
  animation: scan 8s linear infinite;
  pointer-events: none;
}

@keyframes scan {
  to {
    top: 200%;
  }
}

/* ========== MOBILE TOUCH CONTROLS (T-Shape) ========== */
.mobile-controls {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  justify-content: center;
  align-items: center;
  padding: 10px;
  z-index: 100;
}

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

.dpad-row {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.top-row {
  margin-bottom: 0;
}

.bottom-row {
  gap: 12px;
}

.dpad-btn {
  width: 50px;
  height: 50px;
  font-size: 24px;
  font-weight: bold;
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid #00ff41;
  border-radius: 50%;
  color: #00ff41;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-shadow: 0 0 8px rgba(0, 255, 65, 0.3);
  font-family: monospace;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.dpad-btn:active {
  transform: scale(0.92);
  background: #00ff41;
  color: #000;
  box-shadow: 0 0 15px #00ff41;
}

/* ========== RESPONSIVE DESIGN ========== */

@media (max-width: 768px) {
  .mobile-controls {
    display: flex;
    bottom: 15px;
    padding: 8px;
  }

  .dpad-btn {
    width: 45px;
    height: 45px;
    font-size: 22px;
  }

  .dpad-row {
    gap: 10px;
  }

  .bottom-row {
    gap: 10px;
  }

  body {
    padding-bottom: 90px;
    overflow-y: auto;
  }

  .canvas-wrapper {
    margin-bottom: 80px;
  }
}

@media screen and (max-width: 500px) {
  .mobile-controls {
    bottom: 10px;
    padding: 6px;
  }

  .dpad-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
    border-width: 1.5px;
  }

  .dpad-row {
    gap: 8px;
  }

  .bottom-row {
    gap: 8px;
  }

  .dpad {
    gap: 6px;
  }

  body {
    padding-bottom: 80px;
  }

  .canvas-wrapper {
    margin-bottom: 70px;
  }
}

@media screen and (max-width: 480px) {
  .dpad-btn {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }

  body {
    padding-bottom: 75px;
  }
}