/* Snake-specific UI (console-ish, independent from other games) */
.game-shell{ padding-top: 18px; }
.snake-wrap{
  /* Keep the play area from feeling "too wide" on desktop */
  max-width: 640px;
  margin: 0 auto;
  display:flex;
  flex-direction:column;
  gap:12px;
}
.hud{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding: 12px 14px;
  border:1px solid rgba(31,42,58,.9);
  border-radius: 18px;
  background: rgba(17,24,38,.55);
}
.hud-left{display:flex; flex-direction:column; gap:2px;}
.hud-title{ font-weight:800; font-size:18px; letter-spacing:.2px; }
.hud-hint{ color: var(--muted); font-size:13px; margin-top:4px; }
.hud-right{ text-align:right; font-size:14px; color: var(--muted); }
.hud-right span{ color: var(--text); }

#c{
  width:100%;
  height:auto;
  display:block;
  background:
    radial-gradient(900px 600px at 50% 0%, rgba(94,234,212,.10), transparent 60%),
    rgba(3,6,10,.75);
}
.overlay{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  pointer-events:none;
  opacity:0;
  transition: 160ms ease;
}
.overlay.on,
.overlay.is-visible{ opacity:1; pointer-events:auto; }
.overlay-box{
  pointer-events:auto;
  padding: 14px 16px;
  border-radius: 18px;
  border:1px solid rgba(31,42,58,.9);
  background: rgba(11,15,20,.78);
  backdrop-filter: blur(10px);
  text-align:center;
  min-width: 260px;
}
.overlay-title{ font-weight:800; font-size:18px; }
.overlay-sub{ margin-top:6px; color: var(--muted); font-size:13px; }

.controls{
  color: var(--muted);
  font-size: 13px;
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:6px;
  justify-content:center;
}
.controls .sep{ margin:0 6px; }

.stage{
  position: relative;
  max-width: 448px;
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  border:2px solid rgba(55,65,81,.95);
  background: rgba(9,12,18,.65);
}
.stage canvas{
  display:block;
  width: 100%;
  height: auto;
  touch-action: none; /* important for swipe control */
}

.controls{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:center;
  color: var(--muted);
  font-size: 13px;
}
.kbd{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 28px;
  height: 26px;
  padding: 0 8px;
  border-radius: 10px;
  border:1px solid rgba(31,42,58,.9);
  background: rgba(17,24,38,.55);
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
}
.sep{ opacity:.7; padding: 0 2px; }


/* Mobile: keep the page fixed while playing (no vertical scroll / rubber-band) */
html, body{ height: 100%; }
@media (pointer: coarse){
  body{
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none; /* avoid browser gestures while in game page */
  }
  .game-shell{ min-height: 100dvh; }
  .snake-wrap{ gap: 10px; }
}

.touch{
  display:none;
  margin-top: 6px;
  padding: 12px 14px;
  border:1px solid rgba(31,42,58,.9);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(17,24,38,.55), rgba(9,12,18,.55));
}
.touch-hint{
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}
.touch-row{
  display:flex;
  gap:8px;
  align-items:center;
  justify-content:center;
}
.dpad{
  width: clamp(170px, 58vw, 220px);
  aspect-ratio: 1 / 1;
  height: auto;
  display:grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 10px;
  padding: 12px;
  box-sizing: border-box;
  border-radius: 22px;
  border:1px solid rgba(31,42,58,.95);
  background: radial-gradient(120px 120px at 50% 35%, rgba(34,197,94,.10), rgba(9,12,18,.75));
  position:relative;
}
.dpad::after{
  content:"";
  position:absolute;
  left:50%;
  top:50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%,-50%);
  border-radius: 12px;
  border:1px solid rgba(31,42,58,.95);
  background: rgba(9,12,18,.85);
  box-shadow: 0 0 0 2px rgba(255,255,255,.03) inset;
}
.dpad-btn{
  width: 100%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 0;
  line-height: 1;
  border-radius: 18px;
  border:1px solid rgba(31,42,58,.95);
  background: rgba(9,12,18,.85);
  color: rgba(226,232,240,.92);
  font-size: 26px;
  font-weight: 900;
  cursor:pointer;
  user-select:none;
  box-shadow: 0 10px 22px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.04) inset;
  transition: transform .06s ease, box-shadow .10s ease, background .12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* reduce double-tap zoom on some browsers */
}
.dpad-btn:active{ transform: translateY(1px) scale(.98); box-shadow: 0 0 0 1px rgba(34,197,94,.25) inset, 0 0 18px rgba(34,197,94,.18); }
.dpad-btn.up{ grid-column:2; grid-row:1; }
.dpad-btn.left{ grid-column:1; grid-row:2; }
.dpad-btn.right{ grid-column:3; grid-row:2; }
.dpad-btn.down{ grid-column:2; grid-row:3; }

.touch-actions{
  display:flex;
  flex-direction:column;
  gap:10px;
}
.action-btn{
  min-width: 140px;
  padding: 12px 14px;
  border-radius: 14px;
  border:1px solid rgba(31,42,58,.9);
  background: rgba(9,12,18,.55);
  color: var(--text);
  font-weight: 800;
  cursor:pointer;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
.action-btn:active{ transform: translateY(1px); }

@media (pointer: coarse){
  .controls{ display:none; }
  .touch{ display:block; }
}

@media (pointer: coarse){
  /* Mobile: prioritize play area + D-pad */
  /* Hide HUD on mobile to free vertical space */
  .hud{ display:none; }

  /* Slightly smaller play area so D-pad fits on short screens */
  /* Slightly smaller play area so a larger D-pad fits comfortably */
  .stage{ max-width: min(300px, 84vw); }
  .touch{ padding: 8px 10px; }
  .touch-hint{ display:none; }
}

@media (max-width: 420px){
  .touch-row{ flex-direction:column; align-items:stretch; }
  .dpad{ margin: 0 auto; }
  .touch-actions{ flex-direction:row; justify-content:center; }
  .action-btn{ min-width: 0; flex:1; }
  /* Keep D-pad readable on very small screens */
  .dpad{ width: clamp(165px, 68vw, 220px); aspect-ratio: 1 / 1; height: auto; gap: 7px; padding: 9px; }
  .dpad-btn{ font-size: 24px; }
}


/* Score celebration */
#score.flash-bonus{
  color:#fbbf24;
  text-shadow: 0 0 14px rgba(251,191,36,.55);
  animation: bonusPop .28s ease-out;
}
@keyframes bonusPop{ from{ transform:scale(1.0); } 50%{ transform:scale(1.22);} to{ transform:scale(1.0);} }
@media (pointer: coarse){
  .touch-row{
    position: sticky;
    bottom: 8px;
    padding: 0;
    border: 0;
    background: transparent;
  }
}


/* Bonus score celebration */
#score.score-bonus{color:#f5c842; text-shadow:0 0 16px rgba(245,200,66,.55); transform:scale(1.08);}
#score{transition:transform .15s ease, color .15s ease, text-shadow .15s ease;}

/* Make it obvious when BONUS is eaten */
.hud-score.bonus-flash{ color:#f5c842; text-shadow:0 0 16px rgba(245,200,66,.35); }
.hud-score{ transition: color .15s ease, text-shadow .15s ease; }

/* Make it obvious you ate a bonus */
.hud-score.bonus-flash{
  color:#f5c842;
  text-shadow: 0 0 14px rgba(245,200,66,.45);
}



/* Mobile HUD compact */
@media (max-width: 480px){
  .hud{ padding: 8px 10px; border-radius: 14px; }
  .hud-title{ font-size: 16px; }
  .hud-right{ font-size: 13px; }
  .hud-best{ display:none; }
}
