/* Reset and base — full-screen canvas game */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; touch-action: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, #0d0820 0%, #1a0f3d 50%, #2e1065 100%);
  color: white;
  user-select: none;
  -webkit-user-select: none;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

/* HUD layer — sits above canvas, mostly click-through */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

/* Top bar — brand left, score right */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: env(safe-area-inset-top, 0.5em) 1em 0.5em;
  pointer-events: auto;
  gap: 1em;
}

#brand {
  display: flex;
  align-items: center;
  gap: 0.5em;
  text-decoration: none;
  color: white;
  font-weight: 600;
  font-size: 0.95em;
  padding: 0.4em 0.8em;
  background: rgba(255,255,255,0.08);
  border-radius: 100px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.brand-logo {
  display: inline-flex;
  width: 1.4em;
  height: 1.4em;
  background: linear-gradient(135deg, #7c3aed, #d946ef);
  color: white;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85em;
}
.brand-text { font-size: 0.85em; opacity: 0.9; }

#score-block {
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 0.5em 0.9em;
  text-align: right;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 0.15em;
  min-width: 140px;
}
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6em;
  font-variant-numeric: tabular-nums;
}
.score-mini-label {
  font-size: 0.65em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
}
#score {
  font-size: 1.3em;
  font-weight: 800;
  background: linear-gradient(90deg, #fbbf24, #f97316);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#wave {
  font-size: 1.1em;
  font-weight: 700;
  color: #06b6d4;
}
#collected {
  font-size: 1em;
  font-weight: 700;
  color: #d946ef;
}
.hp-row #hp {
  font-size: 0.95em;
  letter-spacing: -0.05em;
  filter: drop-shadow(0 0 4px rgba(239, 68, 68, 0.45));
}

/* Виртуальный джойстик — показывается только когда touch активен */
.joystick {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.3);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 12;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.joystick.active { opacity: 1; }
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  margin-left: -25px;
  margin-top: -25px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d946ef, #7c3aed);
  box-shadow: 0 4px 12px rgba(217, 70, 239, 0.5);
}

/* Jump button — большой круглый внизу справа, только mobile */
.jump-btn {
  position: fixed;
  right: 1.5em;
  bottom: calc(env(safe-area-inset-bottom, 1em) + 5em);
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.85), rgba(217, 70, 239, 0.85));
  color: white;
  font-size: 2em;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
  z-index: 13;
  box-shadow: 0 8px 24px rgba(217, 70, 239, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.1s, box-shadow 0.1s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.jump-btn:active {
  transform: scale(0.9);
  box-shadow: 0 4px 12px rgba(217, 70, 239, 0.6);
}
@media (pointer: coarse) {
  .jump-btn { display: flex; }
}

/* Desktop / mobile hint switching */
.desktop-hint { display: inline; }
.mobile-hint { display: none; }
@media (pointer: coarse) {
  .desktop-hint { display: none; }
  .mobile-hint { display: inline; }
}

/* Bottom hint — fades out after first interaction */
.hint {
  position: absolute;
  bottom: 7em;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  padding: 0.7em 1.2em;
  border-radius: 100px;
  font-size: 0.9em;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.5s;
  text-align: center;
  max-width: calc(100vw - 2em);
}
.hint.fade { opacity: 0; }

/* Share button (top-right area below score) */
.float-btn {
  position: absolute;
  top: 11em;
  right: 1em;
  pointer-events: auto;
  background: linear-gradient(135deg, #7c3aed, #d946ef);
  color: white;
  border: none;
  padding: 0.65em 1.1em;
  border-radius: 100px;
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4em;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
  transition: transform 0.15s;
}
.float-btn:active { transform: scale(0.95); }

/* Footer — small Doday cross-promo */
#footer {
  margin-top: auto;
  padding: 1em 1em calc(env(safe-area-inset-bottom, 1em));
  font-size: 0.75em;
  opacity: 0.7;
  text-align: center;
  pointer-events: auto;
}
#footer a { color: #d946ef; text-decoration: none; }
#footer .sep { margin: 0 0.5em; opacity: 0.5; }
#footer .hint-small { font-size: 0.9em; opacity: 0.8; }

/* Wave banner — flashes when new wave starts */
.wave-banner {
  position: fixed;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.4);
  z-index: 25;
  background: linear-gradient(135deg, #06b6d4, #7c3aed);
  color: white;
  padding: 0.6em 1.8em;
  border-radius: 100px;
  font-size: clamp(1.5em, 6vw, 2.3em);
  font-weight: 900;
  letter-spacing: 0.05em;
  box-shadow: 0 12px 40px rgba(6, 182, 212, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1.4);
  white-space: nowrap;
}
.wave-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Achievement popup */
.ach-popup {
  position: fixed;
  top: -150px;
  right: 1em;
  z-index: 20;
  background: linear-gradient(135deg, #fbbf24, #f97316);
  color: #1a0f3d;
  padding: 1em 1.5em;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 1em;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  transition: top 0.6s cubic-bezier(0.2, 0.8, 0.2, 1.2);
  max-width: calc(100vw - 2em);
  pointer-events: none;
}
.ach-popup.show { top: env(safe-area-inset-top, 1em); }
.ach-emoji { font-size: 2em; }
.ach-title { font-weight: 800; font-size: 0.95em; }
.ach-desc { font-size: 0.8em; opacity: 0.8; }

/* «67» fullscreen mem overlay */
.mem-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: radial-gradient(circle, rgba(217, 70, 239, 0.95), rgba(13, 8, 32, 0.98));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
.mem-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.mem-text {
  font-size: clamp(8em, 30vw, 18em);
  font-weight: 900;
  background: linear-gradient(135deg, #fbbf24, #ef4444, #d946ef);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 4px 20px rgba(217, 70, 239, 0.8));
  animation: mem-bounce 0.8s cubic-bezier(0.2, 0.8, 0.2, 1.4);
}
.mem-sub {
  font-size: 1.5em;
  font-weight: 800;
  letter-spacing: 0.2em;
  opacity: 0.9;
  margin-top: -0.5em;
}
.mem-close {
  margin-top: 2em;
  padding: 0.8em 2em;
  background: white;
  color: #1a0f3d;
  border: none;
  border-radius: 100px;
  font-size: 1em;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
@keyframes mem-bounce {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

/* Game over modal */
.gameover-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(13, 8, 32, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
.gameover-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.gameover-card {
  max-width: 420px;
  width: 100%;
  background: linear-gradient(180deg, rgba(76, 29, 149, 0.6), rgba(13, 8, 32, 0.85));
  border: 1px solid rgba(217, 70, 239, 0.3);
  border-radius: 20px;
  padding: 1.5em 1.5em 1.2em;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(217, 70, 239, 0.2);
  text-align: center;
  animation: gameover-pop 0.5s cubic-bezier(0.2, 0.8, 0.2, 1.4);
}
@keyframes gameover-pop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.gameover-title {
  font-size: clamp(1.5em, 6vw, 2em);
  font-weight: 900;
  background: linear-gradient(135deg, #ef4444, #d946ef);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.05em;
  filter: drop-shadow(0 2px 8px rgba(239, 68, 68, 0.4));
}
.gameover-sub {
  font-size: 0.9em;
  opacity: 0.7;
  margin-top: 0.3em;
  margin-bottom: 1.2em;
  font-style: italic;
}
.gameover-stats {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  padding: 1em 1.2em;
  margin-bottom: 1.2em;
}
.gameover-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}
.gameover-stat.best { opacity: 0.85; }
.gameover-stat-label {
  font-size: 0.85em;
  opacity: 0.75;
}
.gameover-stat-value {
  font-size: 1.15em;
  font-weight: 800;
}
.gameover-stat-value.gradient-amber {
  background: linear-gradient(90deg, #fbbf24, #f97316);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.gameover-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0.3em 0;
}
.restart-btn {
  width: 100%;
  padding: 0.9em 1.5em;
  background: linear-gradient(135deg, #7c3aed, #d946ef);
  color: white;
  border: none;
  border-radius: 100px;
  font-size: 1em;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.05em;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.5);
  transition: transform 0.15s, box-shadow 0.15s;
}
.restart-btn:active {
  transform: scale(0.97);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}
.gameover-back {
  display: inline-block;
  margin-top: 0.9em;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  font-size: 0.85em;
}
.gameover-back:hover { color: white; }

/* Click-feedback particles (created in JS, styled here) */
.particle {
  position: fixed;
  pointer-events: none;
  font-size: 1.5em;
  z-index: 15;
  animation: particle-rise 1s ease-out forwards;
  font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
@keyframes particle-rise {
  0% { transform: translate(-50%, 0) scale(0.8); opacity: 1; }
  100% { transform: translate(-50%, -80px) scale(1.4); opacity: 0; }
}

/* Tablet+ adjustments */
@media (min-width: 768px) {
  #top-bar { padding: 1em 2em; }
  .float-btn { right: 2em; }
  #footer { font-size: 0.85em; }
  .gameover-card { padding: 2em; }
}
