* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #000;
  font-family: -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#game-wrap { position: fixed; inset: 0; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }

#hud {
  position: absolute; top: env(safe-area-inset-top, 8px); left: 0; right: 0;
  display: flex; justify-content: space-between; padding: 10px 16px;
  pointer-events: none; z-index: 5;
}
#hud > div {
  background: rgba(0,0,0,.45); color: #fff; font-weight: 800;
  padding: 6px 14px; border-radius: 20px; font-size: 17px;
  text-shadow: 2px 2px 0 #000; letter-spacing: .5px;
}

#inv {
  position: absolute; top: calc(env(safe-area-inset-top, 8px) + 52px);
  left: 0; right: 0; z-index: 5; display: none;
  justify-content: center; gap: 12px; pointer-events: none;
}
#inv.show { display: flex; }
#inv span {
  background: rgba(0,0,0,.5); color: #fff; font-weight: 800; font-size: 18px;
  padding: 5px 16px; border-radius: 18px; border: 2px solid rgba(255,255,255,.35);
}
#inv #invMoney { border-color: #46b163; }

/* On-screen controls, bottom-left, clear of the central character */
#controls {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 14px) + 12px);
  left: 14px; z-index: 6; display: none;
  align-items: flex-end; gap: 12px; direction: ltr;
}
#controls.show { display: flex; }
.arrows { display: flex; flex-direction: column; gap: 10px; }
.ctrl {
  width: 60px; height: 60px; border-radius: 50%;
  border: 4px solid #fff; font-size: 28px; font-weight: 900; color: #fff;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20,30,50,.55); box-shadow: 0 4px 0 rgba(0,0,0,.4), 0 6px 12px rgba(0,0,0,.35);
  transition: transform .05s; line-height: 1; padding: 0;
}
.ctrl:active { transform: scale(.9) translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.4); }
.ctrl.garlic {
  width: 70px; height: 70px; font-size: 34px;
  background: radial-gradient(circle at 35% 30%, #fff8e1, #e8c87a);
  box-shadow: 0 4px 0 #8a6d1f, 0 6px 12px rgba(0,0,0,.4);
}
.ctrl.garlic:active { box-shadow: 0 1px 0 #8a6d1f; }

.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px;
  background: linear-gradient(180deg, rgba(92,148,252,.92), rgba(40,70,150,.95));
  color: #fff; text-align: center;
}
.overlay.hidden { display: none; }
.overlay h1 { font-size: clamp(30px, 9vw, 48px); text-shadow: 3px 3px 0 #000; }
.overlay .sub { font-size: 17px; opacity: .95; max-width: 340px; line-height: 1.5; }
.howto {
  display: flex; flex-direction: column; gap: 6px; font-size: 15px;
  background: rgba(0,0,0,.25); padding: 14px 18px; border-radius: 14px;
}
.howto b { color: #ffe35c; }
.rankmsg { font-size: 16px; color: #ffe35c; font-weight: 700; min-height: 22px; }

#nameInput {
  width: min(80%, 320px); padding: 14px; border-radius: 12px; border: 3px solid #fff;
  font-size: 18px; text-align: center; outline: none; background: #fff; color: #222;
}
.bigbtn {
  background: #e63946; color: #fff; border: 4px solid #fff; border-radius: 14px;
  padding: 16px 34px; font-size: 20px; font-weight: 800; cursor: pointer;
  box-shadow: 0 5px 0 #9d1f29; transition: transform .05s;
}
.bigbtn:active { transform: translateY(4px); box-shadow: 0 1px 0 #9d1f29; }
.bigbtn.wa { background: #25D366; box-shadow: 0 5px 0 #128C3E; }
.bigbtn.wa:active { box-shadow: 0 1px 0 #128C3E; }
.linkbtn {
  background: rgba(255,255,255,.18); color: #fff; border: 2px solid rgba(255,255,255,.6);
  border-radius: 12px; padding: 10px 22px; font-size: 16px; cursor: pointer;
}
.linkbtn:active { background: rgba(255,255,255,.32); }

#lbList { list-style: none; width: min(90%, 360px); max-height: 60vh; overflow-y: auto; }
#lbList li {
  display: flex; justify-content: space-between; gap: 10px;
  background: rgba(0,0,0,.28); margin: 6px 0; padding: 12px 16px; border-radius: 10px;
  font-size: 17px; font-weight: 700;
}
#lbList li .rank { color: #ffe35c; min-width: 34px; text-align: center; }
#lbList li .nm { flex: 1; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lbList li.me { outline: 2px solid #ffe35c; }
