/* ============================================================
   NEON SNAKE — retro arcade snake
   Vanilla CSS · dark neon theme · responsive · touch-ready
   ============================================================ */

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

:root {
  --bg1: #0a0e27;
  --accent: #00d4ff;
  --accent2: #667eea;
  --accent3: #764ba2;
  --snake: #5ee0a0;
  --food: #ffd166;
  --danger: #ff4d6d;
  --font: "Courier New", ui-monospace, Menlo, Consolas, monospace;
}

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% 20%, #141a3a 0%, var(--bg1) 60%, #05070f 100%);
  color: #e8ecff;
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
body { display: flex; align-items: center; justify-content: center; }

/* Square play area, centered, scales to viewport */
.game-wrap {
  position: relative;
  width: min(96vw, 96vh, 620px);
  aspect-ratio: 1 / 1;
  background: #05070f;
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(0, 212, 255, 0.15), inset 0 0 0 2px rgba(102, 126, 234, 0.25);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* HUD */
.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; z-index: 6;
  font-size: clamp(10px, 2.4vw, 15px);
  letter-spacing: 1px; pointer-events: none;
  text-shadow: 0 0 8px rgba(0, 212, 255, 0.6);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; }
.hud-item { color: #9fb0ff; }
.hud-item b { color: #fff; }
.icon-btn {
  pointer-events: auto;
  background: rgba(102, 126, 234, 0.15);
  border: 1px solid rgba(0, 212, 255, 0.4);
  color: #fff; border-radius: 8px;
  width: 34px; height: 30px; font-size: 14px; cursor: pointer;
  transition: background .2s, transform .1s;
}
.icon-btn:hover { background: rgba(0, 212, 255, 0.25); }
.icon-btn:active { transform: scale(0.92); }

/* Overlays */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 7, 15, 0.82); backdrop-filter: blur(3px); padding: 16px;
}
.overlay.hidden { display: none; }
.panel {
  text-align: center; padding: clamp(18px, 4vw, 38px);
  border: 2px solid rgba(0, 212, 255, 0.35); border-radius: 16px;
  background: linear-gradient(160deg, rgba(102,126,234,0.12), rgba(118,75,162,0.08));
  box-shadow: 0 0 40px rgba(0, 212, 255, 0.2); max-width: 420px; width: 100%;
}
.title {
  font-size: clamp(26px, 8vw, 48px); font-weight: 800; letter-spacing: 4px; color: #fff;
  text-shadow: 0 0 12px var(--accent), 0 0 28px var(--accent2);
  animation: flicker 3s infinite;
}
.title.small { font-size: clamp(20px, 6vw, 34px); }
@keyframes flicker { 0%,92%,100%{opacity:1} 93%{opacity:.6} 95%{opacity:1} 97%{opacity:.7} }
.tagline { margin: 10px 0 18px; color: #9fb0ff; font-size: clamp(11px, 2.6vw, 15px); }
.how {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px;
  margin: 8px 0 20px; font-size: clamp(10px, 2.4vw, 13px);
}
.how div { display: flex; justify-content: space-between; gap: 8px; background: rgba(255,255,255,0.05); padding: 7px 10px; border-radius: 8px; }
.how b { color: var(--accent); }
.how span { color: #cdd6ff; }
.btn {
  display: inline-block; margin: 6px 5px 0; padding: 12px 26px;
  font-family: var(--font); font-weight: 700; font-size: clamp(13px, 3vw, 16px); letter-spacing: 2px;
  color: #fff; background: rgba(255,255,255,0.06);
  border: 2px solid rgba(0, 212, 255, 0.5); border-radius: 10px; cursor: pointer;
  transition: transform .12s, box-shadow .2s, background .2s;
}
.btn:hover { background: rgba(0, 212, 255, 0.15); box-shadow: 0 0 18px rgba(0,212,255,.35); }
.btn:active { transform: scale(0.95); }
.btn.primary { background: linear-gradient(135deg, var(--accent2), var(--accent3)); border-color: transparent; box-shadow: 0 6px 20px rgba(102,126,234,.5); }
.hint { margin-top: 14px; font-size: 11px; color: #6f7bb5; }
.score-line { margin: 6px 0; font-size: clamp(13px, 3vw, 17px); color: #cdd6ff; }
.score-line b { color: var(--food); }
.new-high { color: var(--food); margin: 10px 0; letter-spacing: 2px; animation: flicker 1.2s infinite; }
.hidden { display: none !important; }

/* Touch controls */
.touch {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 7;
  display: none; justify-content: center; align-items: flex-end;
  padding: 14px 18px; pointer-events: none;
}
.touch .dpad { position: relative; width: 150px; height: 150px; pointer-events: none; }
.tbtn {
  pointer-events: auto; position: absolute;
  width: 50px; height: 50px; border-radius: 12px;
  background: rgba(102,126,234,0.28); border: 1px solid rgba(0,212,255,0.5);
  color: #fff; font-size: 18px; display: flex; align-items: center; justify-content: center;
  touch-action: none; transition: background .1s, transform .05s;
}
.tbtn:active, .tbtn.active { background: rgba(0,212,255,0.5); transform: scale(0.9); }
.dpad .up    { top: 0;   left: 50px; }
.dpad .left  { top: 50px; left: 0; }
.dpad .right { top: 50px; left: 100px; }
.dpad .down  { top: 100px; left: 50px; }

@media (hover: none) and (pointer: coarse) { .touch { display: none; } }
body.touch-mode .touch { display: none; }

.back-home {
  position: absolute; left: 10px; bottom: 8px; z-index: 6;
  font-size: 11px; color: #7f8bc7; text-decoration: none;
  background: rgba(0,0,0,.25); padding: 4px 8px; border-radius: 6px;
}
.back-home:hover { color: var(--accent); }
@media (hover: none) and (pointer: coarse) {
  .back-home { bottom: auto; top: 6px; left: 50%; transform: translateX(-50%); }
}
