@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05070b;
  font-family: "Vazirmatn", sans-serif;
  color: #f8fafc;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  display: block;
  background: #070a12;
  touch-action: none;
}

.hidden { display: none !important; }

#minimapCanvas {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 6;
  width: 140px;
  height: 140px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(7,9,14,0.55);
  pointer-events: none;
}

/* ===== HUD ===== */

#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  padding: 18px;
}

#topBar {
  display: flex;
  gap: 12px;
  width: fit-content;
}

#scoreBox, #playerCountBox, #coinBox {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  background: rgba(7, 9, 14, 0.75);
  backdrop-filter: blur(12px);
  font-size: 0.85rem;
  font-weight: 700;
  color: #cbd5e1;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
}

.hud-icon { font-size: 1rem; }

#scoreBox small, #playerCountBox small {
  color: #64748b;
  font-weight: 600;
  font-size: 0.66rem;
}

#scoreValue { color: #38bdf8; font-weight: 800; font-size: 1.05rem; transition: transform 0.15s ease; }
#scoreValue.pulse { animation: scorePulse 0.35s ease; }
@keyframes scorePulse {
  0% { transform: scale(1); color: #38bdf8; }
  50% { transform: scale(1.35); color: #4ade80; }
  100% { transform: scale(1); color: #38bdf8; }
}

#playerCountValue { color: #4ade80; font-weight: 800; }
#coinValue { color: #facc15; font-weight: 800; }

.hud-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
  animation: dotPulse 1.6s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#boostMeterWrap {
  position: absolute;
  top: 66px;
  left: 18px;
  width: 160px;
  height: 8px;
  border-radius: 999px;
  background: rgba(7,9,14,0.6);
  border: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
}

#boostMeterFill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #4ade80);
  box-shadow: 0 0 10px rgba(56,189,248,0.6);
  transition: width 0.15s linear;
}

#shortcutHint {
  position: absolute;
  bottom: 14px;
  left: 18px;
  display: flex;
  gap: 14px;
  font-size: 0.66rem;
  color: #64748b;
}

#shortcutHint b {
  display: inline-block;
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 5px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  color: #94a3b8;
  font-weight: 700;
}

#leaderboard {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 210px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  background: rgba(7, 9, 14, 0.75);
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
}

#leaderboard h4 {
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  color: #38bdf8;
  margin-bottom: 10px;
}

#leaderboardList {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.78rem;
}

#leaderboardList li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 7px;
  color: #cbd5e1;
  transition: background 0.15s ease;
}

#leaderboardList li b { color: #f8fafc; }
#leaderboardList li.me { color: #4ade80; background: rgba(74,222,128,0.1); }
#leaderboardList li span.rank { color: #64748b; width: 22px; flex-shrink: 0; font-weight: 700; text-align: center; }

#brandTag, #brandTagOver {
  position: absolute;
  bottom: 14px;
  right: 18px;
  font-size: 0.68rem;
  color: #64748b;
  letter-spacing: 0.3px;
}

#brandTagOver {
  position: static;
  margin-top: 18px;
  text-align: center;
}

#brandTag b, #brandTagOver b {
  color: #38bdf8;
  font-weight: 800;
}

#boostHint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border: none;
  border-radius: 999px;
  background: rgba(56,189,248,0.14);
  color: #38bdf8;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  pointer-events: none;
}

/* ===== Virtual joystick + boost button ===== */

#joystickZone {
  position: fixed;
  bottom: 26px;
  left: 26px;
  z-index: 15;
  width: 120px;
  height: 120px;
  touch-action: none;
}

#joystickBase {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(6px);
}

#joystickStick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.9), rgba(56,189,248,0.7));
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  transition: transform 0.05s linear;
}

#boostBtn {
  position: fixed;
  bottom: 34px;
  right: 34px;
  z-index: 15;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 2px solid rgba(56,189,248,0.4);
  background: rgba(56,189,248,0.16);
  color: #38bdf8;
  font-size: 1.6rem;
  backdrop-filter: blur(6px);
  touch-action: none;
  cursor: pointer;
}

#boostBtn:active {
  background: rgba(56,189,248,0.32);
  transform: scale(0.94);
}

/* ===== Overlays ===== */

#menuOverlay, #gameOverOverlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(56,189,248,0.16), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(139,92,246,0.12), transparent 45%),
    radial-gradient(circle at 0% 100%, rgba(74,222,128,0.08), transparent 40%),
    rgba(5,7,11,0.72);
  backdrop-filter: blur(2px);
}

.menu-card {
  width: min(460px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  padding: 44px 38px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 26px;
  background: rgba(13, 20, 30, 0.82);
  backdrop-filter: blur(20px);
  box-shadow: 0 40px 90px rgba(0,0,0,0.55), 0 0 0 1px rgba(56,189,248,0.06) inset;
  text-align: center;
  animation: cardIn 0.5s cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.menu-logo {
  font-size: 2.6rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
  text-shadow: 0 0 24px rgba(56,189,248,0.45);
  animation: logoGlow 3.2s ease-in-out infinite;
}

@keyframes logoGlow {
  0%, 100% { text-shadow: 0 0 22px rgba(56,189,248,0.4); }
  50% { text-shadow: 0 0 36px rgba(56,189,248,0.75), 0 0 60px rgba(139,92,246,0.35); }
}

.menu-tag {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 28px;
  direction: ltr;
}

.menu-tag b { color: #38bdf8; }

.menu-card-wide { width: min(640px, 100%); padding: 44px 40px; }

.menu-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 26px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 18px;
}

.menu-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 4px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
  color: #64748b;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.3;
}

.menu-tab .tab-emoji { font-size: 1.35rem; }

.menu-tab:hover { color: #94a3b8; background: rgba(255,255,255,0.05); transform: translateY(-2px); }

.menu-tab.active {
  color: #38bdf8;
  background: rgba(56,189,248,0.12);
  border-color: rgba(56,189,248,0.3);
  box-shadow: 0 6px 18px rgba(56,189,248,0.15);
}

.menu-panel { display: none; text-align: center; }
.menu-panel.active { display: block; animation: cardIn 0.35s ease both; }

.panel-desc {
  font-size: 0.88rem;
  color: #94a3b8;
  margin-bottom: 20px;
}

#coinDisplay {
  margin: -6px 0 20px;
  font-size: 1rem;
  font-weight: 700;
  color: #facc15;
}

.skins-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px;
}

.skin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 10px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  transition: all 0.2s ease;
}

.skin-card:hover { background: rgba(255,255,255,0.05); }

.skin-card.selected {
  border-color: #38bdf8;
  background: rgba(56,189,248,0.1);
  box-shadow: 0 0 0 1px rgba(56,189,248,0.4);
}

.skin-card canvas {
  border-radius: 8px;
  background: rgba(0,0,0,0.25);
}

.skin-card-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: #f8fafc;
}

.skin-card-price {
  font-size: 0.72rem;
  font-weight: 600;
  color: #facc15;
}

.skin-card-price.owned { color: #4ade80; }
.skin-card-price.selected-label { color: #38bdf8; }

.store-coming-soon {
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid rgba(250,204,21,0.3);
  border-radius: 10px;
  background: rgba(250,204,21,0.08);
  color: #facc15;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}

.store-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px;
}

.store-pack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 14px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  background: rgba(255,255,255,0.02);
  position: relative;
  transition: all 0.2s ease;
}

.store-pack:hover { background: rgba(255,255,255,0.05); transform: translateY(-2px); }

.store-pack-bonus {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(74,222,128,0.16);
  color: #4ade80;
  font-size: 0.6rem;
  font-weight: 800;
}

.store-pack-coins {
  font-size: 1rem;
  font-weight: 800;
  color: #facc15;
}

.store-pack-label {
  font-size: 0.72rem;
  color: #94a3b8;
}

.store-pack-price {
  font-size: 0.8rem;
  font-weight: 700;
  color: #f8fafc;
  direction: ltr;
}

.store-pack-buy {
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #0284c7);
  color: #fff;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.store-pack-buy:hover { filter: brightness(1.1); }

.store-pack-buy.disabled {
  background: rgba(255,255,255,0.06);
  color: #64748b;
  cursor: not-allowed;
}

.help-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 4px 4px 0;
  text-align: right;
}

.help-item {
  display: flex;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
}

.help-emoji { font-size: 1.5rem; flex-shrink: 0; line-height: 1; }
.help-item b { display: block; font-size: 0.86rem; margin-bottom: 4px; color: #f8fafc; }
.help-item p { font-size: 0.78rem; color: #94a3b8; line-height: 1.7; }

.key {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px 2px;
  border-radius: 6px;
  background: rgba(56,189,248,0.12);
  border: 1px solid rgba(56,189,248,0.3);
  color: #38bdf8;
  font-weight: 800;
  font-size: 0.72rem;
  direction: ltr;
}

.skins-grid, .store-grid, .help-list, .menu-card, #menuLeaderboardList {
  scrollbar-width: thin;
  scrollbar-color: rgba(56,189,248,0.5) rgba(255,255,255,0.04);
}

.skins-grid::-webkit-scrollbar,
.store-grid::-webkit-scrollbar,
.help-list::-webkit-scrollbar,
.menu-card::-webkit-scrollbar {
  width: 7px;
}

.skins-grid::-webkit-scrollbar-track,
.store-grid::-webkit-scrollbar-track,
.help-list::-webkit-scrollbar-track,
.menu-card::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.03);
  border-radius: 999px;
}

.skins-grid::-webkit-scrollbar-thumb,
.store-grid::-webkit-scrollbar-thumb,
.help-list::-webkit-scrollbar-thumb,
.menu-card::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #38bdf8, #8b5cf6);
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.1);
}

.skins-grid::-webkit-scrollbar-thumb:hover,
.store-grid::-webkit-scrollbar-thumb:hover,
.help-list::-webkit-scrollbar-thumb:hover,
.menu-card::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #4ade80, #38bdf8);
}

.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 12px 22px;
  border-radius: 10px;
  background: rgba(15,23,34,0.95);
  border: 1px solid rgba(255,255,255,0.12);
  color: #f8fafc;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease both;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.control-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
  color: #f8fafc;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.control-card:hover { background: rgba(255,255,255,0.05); transform: translateY(-2px); }

.control-card.active {
  border-color: #38bdf8;
  background: rgba(56,189,248,0.1);
  box-shadow: 0 6px 18px rgba(56,189,248,0.15);
}

.control-icon { font-size: 1.9rem; }
.control-card b { font-size: 0.92rem; }
.control-card span { font-size: 0.76rem; color: #94a3b8; }

#nameInput {
  width: 100%;
  padding: 16px 18px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  color: #f8fafc;
  font-family: inherit;
  font-size: 1rem;
  text-align: center;
  margin-bottom: 20px;
  outline: none;
  transition: border-color 0.2s ease;
}

#nameInput:focus { border-color: #38bdf8; }

.color-picker {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 22px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: #fff; transform: scale(1.15); }

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
}

.btn {
  padding: 18px 22px;
  border-radius: 14px;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.25s ease;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0284c7);
  box-shadow: 0 10px 26px rgba(37,99,235,0.35);
}

.btn-primary:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(37,99,235,0.5); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  color: #f8fafc;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
}

.btn-ghost:hover { background: rgba(255,255,255,0.1); transform: translateY(-3px); }
.btn-ghost:active { transform: translateY(0); }

.link-btn {
  background: none;
  border: none;
  color: #64748b;
  font-family: inherit;
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
  margin-bottom: 10px;
}

.link-btn:hover { color: #94a3b8; }

.menu-hint {
  font-size: 0.7rem;
  color: #475569;
  margin-top: 6px;
}

#menuLeaderboard {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
}

.menu-lb-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.lb-tab {
  flex: 1;
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.lb-tab.active {
  color: #38bdf8;
  border-color: rgba(56,189,248,0.4);
  background: rgba(56,189,248,0.08);
}

#menuLeaderboardList {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  text-align: right;
  max-height: 340px;
  overflow-y: auto;
  padding: 2px 2px 2px 0;
}

#menuLeaderboardList li {
  display: flex;
  justify-content: space-between;
  color: #cbd5e1;
}

#menuLeaderboardList li b { color: #facc15; }

.final-score {
  font-size: 1.3rem;
  font-weight: 800;
  color: #38bdf8;
  margin-bottom: 6px;
}

.final-rank {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 20px;
}

.final-coins {
  font-size: 0.85rem;
  font-weight: 700;
  color: #facc15;
  margin-bottom: 20px;
}

@media (max-width: 600px) {
  .menu-card-wide { padding: 30px 18px; }
  .menu-tabs { grid-template-columns: repeat(3, 1fr); gap: 5px; padding-bottom: 14px; margin-bottom: 18px; }
  .menu-tab { font-size: 0.6rem; padding: 9px 2px; }
  .menu-tab .tab-emoji { font-size: 1.15rem; }
  .skins-grid, .store-grid { grid-template-columns: repeat(2, 1fr); max-height: 340px; gap: 10px; }
  .btn { padding: 15px 18px; font-size: 0.92rem; }
}

@media (max-width: 480px) {
  #leaderboard { width: 150px; padding: 10px; }
  #leaderboardList { font-size: 0.7rem; }
  .menu-card { padding: 28px 20px; }
  .menu-logo { font-size: 1.9rem; }
  #minimapCanvas { width: 100px; height: 100px; bottom: 12px; right: 12px; }
  #joystickZone { width: 100px; height: 100px; bottom: 18px; left: 18px; }
  #boostBtn { width: 64px; height: 64px; bottom: 24px; right: 24px; font-size: 1.3rem; }
}
