* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1020;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #fff;
  touch-action: none;
}

canvas {
  display: block;
  position: fixed;
  inset: 0;
}

.hidden {
  display: none !important;
}

/* ---------- Login ---------- */
#login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1b2a55, #0b1020 70%);
}

.login-card {
  text-align: center;
  padding: 36px 40px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-width: 92vw;
}

.login-card h1 {
  font-size: 48px;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ffd86b, #ff7eb3, #7afcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  opacity: 0.7;
  margin-bottom: 22px;
}

#nameInput {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  outline: none;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
}

#nameInput::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

#playBtn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  color: #1b1130;
  background: linear-gradient(90deg, #ffd86b, #ff9f6b);
  transition: transform 0.1s ease;
}

#playBtn:active {
  transform: scale(0.97);
}

.hints {
  margin-top: 22px;
  font-size: 13px;
  line-height: 1.7;
  opacity: 0.75;
}

.hints small {
  display: block;
  margin-top: 8px;
  opacity: 0.7;
}

/* ---------- HUD ---------- */
#coinCounter {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 30px;
  font-size: 22px;
  font-weight: 800;
}

.coin-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #f1c40f 60%, #c79100);
  box-shadow: 0 0 6px rgba(241, 196, 15, 0.7);
  display: inline-block;
}

#shopBtn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 20;
  padding: 10px 22px;
  border: none;
  border-radius: 30px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: #1b1130;
  background: linear-gradient(90deg, #7afcff, #6bffb0);
}

#shopBtn:active {
  transform: scale(0.96);
}

/* ---------- Chat ---------- */
#chatBox {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 20;
  width: 340px;
  max-width: 70vw;
}

#chatLog {
  max-height: 26vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 6px;
  scrollbar-width: thin;
}

#chatLog .msg {
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 10px;
  border-radius: 10px;
  font-size: 14px;
  width: fit-content;
  max-width: 100%;
  word-break: break-word;
  line-height: 1.35;
}

#chatLog .msg .who {
  font-weight: 700;
  color: #7afcff;
}

#chatLog .msg.system {
  font-style: italic;
  opacity: 0.7;
}

#chatLog .msg.system .who {
  color: #ffd86b;
}

#chatInput {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 14px;
  outline: none;
}

#chatInput::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

/* ---------- Mobile controls ---------- */
#joystick {
  position: fixed;
  left: 30px;
  bottom: 30px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  z-index: 25;
  touch-action: none;
}

#joystickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#jumpBtn {
  position: fixed;
  right: 36px;
  bottom: 46px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(122, 252, 255, 0.25);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  z-index: 25;
  touch-action: none;
}

#jumpBtn:active {
  background: rgba(122, 252, 255, 0.5);
}

#descendBtn {
  position: fixed;
  right: 140px;
  bottom: 46px;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 179, 107, 0.3);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  z-index: 25;
  touch-action: none;
}

#descendBtn:active {
  background: rgba(255, 179, 107, 0.55);
}

/* ---------- Vehicle enter/exit ---------- */
#vehicleBtn {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 26;
  padding: 12px 26px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 30px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  color: #1b1130;
  background: linear-gradient(90deg, #ffe08a, #ffb36b);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

#vehicleBtn:active {
  transform: translateX(-50%) scale(0.96);
}

/* ---------- Shop ---------- */
#shop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.shop-card {
  width: 540px;
  max-width: 94vw;
  max-height: 88vh;
  background: #16203f;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.shop-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.shop-head h2 {
  flex: 1;
}

.shop-coins {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 18px;
}

#closeShop {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}

#shopItems {
  padding: 16px 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.shop-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}

.shop-item .swatch {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}

.shop-item .iname {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.shop-item .iprice {
  font-size: 13px;
  opacity: 0.85;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.shop-item button {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(90deg, #ffd86b, #ff9f6b);
  color: #1b1130;
}

.shop-item button:disabled {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.5);
  cursor: not-allowed;
}

.shop-item.owned button {
  background: rgba(122, 255, 176, 0.3);
  color: #aaffcc;
}

/* ---------- Misc ---------- */
#loadingMsg {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b1020;
  font-size: 18px;
  opacity: 0.9;
}

#toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  background: rgba(0, 0, 0, 0.75);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

#toast.show {
  opacity: 1;
}

@media (max-width: 720px) {
  .login-card h1 {
    font-size: 38px;
  }
  #chatBox {
    width: 240px;
  }
  #chatLog {
    max-height: 18vh;
  }
}
