:root {
  --bg: var(--tg-bg, #000011);
  --bg2: var(--tg-bg2, #0a0a2a);
  --text: var(--tg-text, #e0e8ff);
  --hint: var(--tg-hint, #6678aa);
  --accent: var(--tg-accent, #00ccff);
  --accent-text: var(--tg-accent-text, #001133);
  --gold: #ffd700;
  --danger: #ff4444;
  --ok: #00ff88;
  --radius: 14px;
  --tg-top: 0px;
  --tg-bottom: 0px;
  --safe-top: calc(env(safe-area-inset-top, 0px) + var(--tg-top));
  --safe-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tg-bottom));
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: var(--bg);
  color: var(--text);
  font-family: 'Rajdhani', -apple-system, BlinkMacSystemFont, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

#game-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  z-index: 10;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#toasts {
  position: absolute;
  top: calc(var(--safe-top) + 60px);
  left: 0; right: 0;
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  pointer-events: none;
  z-index: 200;
}

.toast {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(10,10,40,0.92);
  border: 1px solid rgba(0,204,255,0.3);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: toastIn 0.3s ease;
  max-width: 88vw;
  text-align: center;
}
.toast-success { border-color: var(--ok); color: var(--ok); }
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-out { animation: toastOut 0.3s ease forwards; }

@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 5;
  padding: calc(var(--safe-top) + 12px) 14px 0;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.hud-score-wrap, .hud-lives-wrap {
  display: flex; flex-direction: column; gap: 2px;
}

.hud-label {
  font-size: 10px; font-weight: 700;
  color: var(--hint);
  letter-spacing: 1px;
  font-family: 'Orbitron', monospace;
}

.hud-value {
  font-family: 'Orbitron', monospace;
  font-size: 22px; font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(0,204,255,0.5);
}

.hud-combo {
  font-family: 'Orbitron', monospace;
  font-size: 18px; font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255,215,0,0.5);
  animation: comboPulse 0.5s ease infinite;
}

@keyframes comboPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.hud-lives {
  display: flex; gap: 4px;
}

.heart {
  font-size: 16px;
  opacity: 0.2;
  transition: opacity 0.2s, transform 0.2s;
}
.heart.active { opacity: 1; transform: scale(1.1); }

.hud-powerup {
  position: absolute;
  top: calc(var(--safe-top) + 80px);
  left: 50%; transform: translateX(-50%);
  font-family: 'Orbitron', monospace;
  font-size: 14px; font-weight: 900;
  color: var(--gold);
  background: rgba(0,0,0,0.6);
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  opacity: 0;
  transition: opacity 0.3s;
}
.hud-powerup.show { opacity: 1; }

.hud-boss {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 100px);
  left: 50%; transform: translateX(-50%);
  background: rgba(255,0,0,0.15);
  border: 1px solid rgba(255,0,0,0.4);
  padding: 8px 20px;
  border-radius: 999px;
  animation: bossPulse 1s ease infinite;
}

.boss-text {
  font-family: 'Orbitron', monospace;
  font-size: 12px; font-weight: 700;
  color: #ff4444;
  letter-spacing: 2px;
}

@keyframes bossPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,0,0,0.3); }
  50% { box-shadow: 0 0 0 8px rgba(255,0,0,0); }
}

.loading-content {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
}

.loading-icon {
  font-size: 64px;
  animation: float 2s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

.loading-title {
  font-family: 'Orbitron', monospace;
  font-size: 28px; font-weight: 900;
  background: linear-gradient(135deg, #00ccff, #00ff88);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 3px;
}

.loading-bar {
  width: 200px; height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.loading-fill {
  width: 30%; height: 100%;
  background: var(--accent);
  border-radius: 2px;
  animation: loadingSlide 1.5s ease-in-out infinite;
}

@keyframes loadingSlide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.loading-text {
  font-size: 14px; color: var(--hint);
}

.menu-content {
  flex: 1;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 12px);
}

.menu-header { margin-bottom: 12px; }

.user-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.06);
}

.user-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  object-fit: cover;
}

.user-info { flex: 1; min-width: 0; }

.user-name {
  font-weight: 700; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-stats {
  display: flex; align-items: center; gap: 8px;
  margin-top: 3px;
}

.user-level {
  font-family: 'Orbitron', monospace;
  font-size: 11px; font-weight: 700;
  color: var(--accent);
}

.user-xp-wrap {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--hint);
}

.xp-bar {
  width: 60px; height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.xp-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  border-radius: 2px;
  transition: width 0.5s ease;
}

.user-currency {
  display: flex; flex-direction: column; gap: 4px;
}

.currency-item {
  display: inline-flex; align-items: center; gap: 4px;
  direction: ltr;
  font-family: 'Orbitron', monospace;
  font-size: 13px; font-weight: 700;
  background: rgba(255,255,255,0.06);
  padding: 4px 10px;
  border-radius: 999px;
}

.currency-icon { font-size: 12px; }

.menu-center {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
}

.game-title {
  text-align: center;
  margin-bottom: 8px;
}

.title-accent {
  font-family: 'Orbitron', monospace;
  font-size: 14px; font-weight: 400;
  color: var(--accent);
  letter-spacing: 12px;
  margin-bottom: -4px;
}

.title-main {
  font-family: 'Orbitron', monospace;
  font-size: 42px; font-weight: 900;
  background: linear-gradient(180deg, #ffffff, #00ccff);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 20px rgba(0,204,255,0.3));
}

.menu-score {
  display: flex; align-items: baseline; gap: 8px;
  font-family: 'Orbitron', monospace;
}

.score-label {
  font-size: 11px; color: var(--hint);
  letter-spacing: 2px;
}

.score-value {
  font-size: 20px; font-weight: 900;
  color: var(--gold);
}

.btn-play {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; max-width: 300px;
  padding: 16px;
  font-family: 'Orbitron', monospace;
  font-size: 18px; font-weight: 900;
  color: var(--accent-text);
  background: linear-gradient(180deg, #00eeff, var(--accent));
  border: none; border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,204,255,0.35), inset 0 -3px 0 rgba(0,0,0,0.2);
  cursor: pointer;
  transition: transform 0.12s ease;
  letter-spacing: 2px;
}

.btn-play:active { transform: scale(0.96); }

.play-icon { font-size: 22px; }

.btn-daily {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 300px;
  padding: 12px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 15px; font-weight: 700;
  color: #06281a;
  background: linear-gradient(180deg, #7fe7ad, var(--ok));
  border: none; border-radius: var(--radius);
  cursor: pointer;
  animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,255,136,0.4); }
  50% { box-shadow: 0 0 0 10px rgba(0,255,136,0); }
}

.btn-ghost {
  width: 100%; max-width: 300px;
  padding: 14px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 15px; font-weight: 700;
  color: var(--text);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-ghost:active { transform: scale(0.97); }

.menu-bottom {
  display: flex; gap: 8px;
  margin-top: auto;
  padding-bottom: 8px;
}

.menu-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0;
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  color: var(--hint);
  font-family: 'Rajdhani', sans-serif;
  font-size: 11px; font-weight: 700;
  cursor: pointer;
}

.menu-btn .btn-icon { font-size: 20px; }

.btn-admin {
  margin-top: 8px;
  padding: 8px;
  background: none;
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: 8px;
  color: var(--hint);
  font-size: 11px;
  cursor: pointer;
}

.gameover-card {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(90vw, 360px);
  background: var(--bg2);
  border-radius: 24px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.08);
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn { from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

.go-header { margin-bottom: 16px; }

.go-record {
  display: inline-block;
  padding: 6px 16px;
  background: linear-gradient(90deg, var(--gold), #ff9f43);
  color: #1a1000;
  font-family: 'Orbitron', monospace;
  font-size: 12px; font-weight: 900;
  border-radius: 999px;
  margin-bottom: 8px;
  animation: pulseGlow 1.5s infinite;
}

.go-title {
  font-family: 'Orbitron', monospace;
  font-size: 20px; font-weight: 900;
  color: var(--text);
}

.go-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.go-stat {
  background: rgba(255,255,255,0.04);
  padding: 12px;
  border-radius: 12px;
}

.go-label {
  display: block;
  font-size: 10px; color: var(--hint);
  letter-spacing: 1px;
  font-family: 'Orbitron', monospace;
  margin-bottom: 4px;
}

.go-value {
  font-family: 'Orbitron', monospace;
  font-size: 20px; font-weight: 900;
  color: var(--accent);
}

.go-buttons {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 16px;
}

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.panel-header h2 {
  font-family: 'Orbitron', monospace;
  font-size: 16px; font-weight: 700;
}

.back-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
  border: none; border-radius: 10px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.header-currency {
  display: flex; gap: 10px;
  font-family: 'Orbitron', monospace;
  font-size: 12px; font-weight: 700;
}

.panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.shop-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.shop-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  flex-shrink: 0;
}

.shop-icon-text {
  font-family: 'Orbitron', monospace;
  font-size: 18px; font-weight: 900;
}

.shop-info { flex: 1; min-width: 0; }

.shop-name {
  font-weight: 700; font-size: 14px;
}

.shop-desc {
  font-size: 11px; color: var(--hint);
  margin-top: 2px;
}

.shop-buy-btn {
  padding: 8px 14px;
  background: linear-gradient(180deg, #00eeff, var(--accent));
  color: var(--accent-text);
  border: none; border-radius: 10px;
  font-family: 'Orbitron', monospace;
  font-weight: 700; font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.shop-buy-btn:disabled {
  background: rgba(0,255,136,0.2);
  color: var(--ok);
}

.shop-buy-btn:active { transform: scale(0.94); }

.lb-tabs {
  display: flex; gap: 8px;
  padding: 8px 14px;
}

.lb-tab {
  flex: 1; padding: 8px;
  background: rgba(255,255,255,0.06);
  border: none; border-radius: 10px;
  color: var(--hint);
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700; font-size: 13px;
  cursor: pointer;
}

.lb-tab.active {
  background: rgba(0,204,255,0.15);
  color: var(--accent);
}

.lb-info {
  display: flex; justify-content: space-between;
  padding: 0 14px 8px;
  font-size: 12px; color: var(--hint);
}

.lb-info strong { color: var(--accent); }

.lb-weekly-ends {
  text-align: center;
  padding: 6px;
  margin: 0 14px 8px;
  background: rgba(255,138,128,0.1);
  border-radius: 8px;
  font-size: 11px; color: #ff9a8a;
}

.lb-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 10px 12px;
}

.lb-row.top1 { border-color: rgba(255,215,0,0.3); }
.lb-row.top2 { border-color: rgba(192,210,220,0.3); }
.lb-row.top3 { border-color: rgba(217,154,100,0.3); }

.lb-rank {
  font-family: 'Orbitron', monospace;
  font-size: 14px; font-weight: 900;
  width: 30px; text-align: center;
  color: var(--hint);
}

.lb-row.top1 .lb-rank { color: var(--gold); }
.lb-row.top2 .lb-rank { color: #c0d2dc; }
.lb-row.top3 .lb-rank { color: #d99a64; }

.lb-name { flex: 1; font-weight: 600; font-size: 13px; }

.lb-score {
  font-family: 'Orbitron', monospace;
  font-weight: 900; font-size: 13px;
  color: var(--accent);
}

.ach-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.ach-item.locked { opacity: 0.5; }

.ach-icon { font-size: 24px; }

.ach-info { flex: 1; }

.ach-name { font-weight: 700; font-size: 13px; }
.ach-desc { font-size: 11px; color: var(--hint); margin-top: 2px; }

.ach-reward {
  font-family: 'Orbitron', monospace;
  font-size: 12px; font-weight: 700;
  color: var(--gold);
}

.ach-claim-btn {
  padding: 6px 12px;
  background: linear-gradient(180deg, #7fe7ad, var(--ok));
  color: #06281a;
  border: none; border-radius: 8px;
  font-weight: 700; font-size: 11px;
  cursor: pointer;
}

.ach-claimed { color: var(--ok); font-weight: 700; }

.overlay-screen {
  background: rgba(0,0,0,0.7);
  align-items: center; justify-content: center;
}

.overlay-card {
  width: min(90vw, 340px);
  background: var(--bg2);
  border-radius: 20px;
  padding: 22px;
  border: 1px solid rgba(255,255,255,0.08);
}

.overlay-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}

.overlay-header h2 {
  font-family: 'Orbitron', monospace;
  font-size: 16px;
}

.close-btn {
  width: 32px; height: 32px;
  background: rgba(255,255,255,0.06);
  border: none; border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.settings-list {
  display: flex; flex-direction: column; gap: 8px;
}

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 12px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px; font-weight: 600;
  font-family: 'Rajdhani', sans-serif;
  cursor: pointer;
}

.setting-row span { display: inline-flex; align-items: center; gap: 8px; }

.switch {
  width: 40px; height: 22px;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.setting-row.on .switch { background: var(--ok); }
.setting-row.on .switch::after { transform: translateX(18px); }

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.admin-stat {
  background: var(--bg2);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.04);
}

.stat-label {
  font-size: 11px; color: var(--hint);
  font-weight: 700;
}

.stat-value {
  font-family: 'Orbitron', monospace;
  font-size: 18px; font-weight: 900;
  color: var(--accent);
  margin-top: 4px;
}

.stat-sub {
  font-size: 10px; color: var(--hint);
  margin-top: 2px;
}

.admin-section {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.admin-section h3 {
  font-family: 'Orbitron', monospace;
  font-size: 13px; font-weight: 700;
  margin-bottom: 10px;
}

.grant-form {
  display: flex; flex-direction: column; gap: 8px;
}

.grant-form input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px; font-weight: 600;
  font-family: 'Rajdhani', sans-serif;
}

.grant-row {
  display: flex; gap: 8px;
}

.grant-row input { flex: 1; }

.btn-primary {
  padding: 12px;
  background: linear-gradient(180deg, #00eeff, var(--accent));
  color: var(--accent-text);
  border: none; border-radius: 10px;
  font-family: 'Orbitron', monospace;
  font-weight: 700; font-size: 13px;
  cursor: pointer;
}

.admin-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 12px;
}
