:root {
  --bg: #0b1020;
  --panel: #0f172a;
  --panel-2: #0b1320;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #38bdf8;
  --good: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  --sai-top: env(safe-area-inset-top, 0px);
  --sai-right: env(safe-area-inset-right, 0px);
  --sai-bottom: env(safe-area-inset-bottom, 0px);
  --sai-left: env(safe-area-inset-left, 0px);
}


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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #4ec0ca, #78d9e0 55%, #4ec0ca);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


#gameCanvas, .menu, .gameover, .stats-view, .btn {
  will-change: transform;
}


* {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}


#gameContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}


#gameCanvas {
  display: block;
  background: transparent;
  width: 100%;
  height: 100%;
  object-fit: contain;
}


.hud {
  display: none; 
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
}

.hud-label {
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
}

.hud-value {
  color: #fff;
}


.mute-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  font-size: 20px;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.mute-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}


#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  overflow: hidden;
}


#overlay::before {
  content: '';
  position: absolute;
  width: 200%;
  height: 200%;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(56, 189, 248, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(34, 197, 94, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 40% 80%, rgba(251, 191, 36, 0.1) 0%, transparent 50%);
  animation: float-bg 20s ease-in-out infinite;
  pointer-events: none;
}

@keyframes float-bg {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(-50px, -50px) rotate(120deg); }
  66% { transform: translate(50px, 50px) rotate(240deg); }
}


.menu, .gameover, .stats-view {
  position: relative;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow), 0 0 40px rgba(56, 189, 248, 0.15);
  text-align: center;
  max-width: 600px;
  width: 100%;
  overflow: hidden;
  animation: menu-appear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes menu-appear {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}


.menu::before, .gameover::before {
  content: '✨';
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 24px;
  opacity: 0.6;
  animation: twinkle 2s ease-in-out infinite;
}

.menu::after, .gameover::after {
  content: '⭐';
  position: absolute;
  bottom: 15px;
  left: 15px;
  font-size: 20px;
  opacity: 0.6;
  animation: twinkle 2s ease-in-out infinite 1s;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.2); }
}

.menu h1 {
  font-size: 48px;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: title-glow 3s ease-in-out infinite;
}

@keyframes title-glow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.5)); }
  50% { filter: drop-shadow(0 0 20px rgba(56, 189, 248, 0.8)); }
}

.subtitle {
  color: var(--muted);
  margin-bottom: 30px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}

.btn {
  padding: 14px 24px;
  border: 2px solid rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.1), rgba(56, 189, 248, 0.05));
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
  width: 300px;
  height: 300px;
}

.btn:hover {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.2), rgba(56, 189, 248, 0.1));
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.3);
}

.btn:active {
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(180deg, #22c55e, #16a34a);
  border: 2px solid #22c55e;
  color: #fff;
  box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #26d362, #18b550);
  box-shadow: 0 8px 25px rgba(34, 197, 94, 0.5);
  transform: translateY(-3px) scale(1.02);
}


.stats, .stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.stat, .stat-card {
  padding: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  text-align: center;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.stat::before, .stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  transform: translateX(-100%);
  animation: shimmer 3s infinite;
}

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

.stat:hover, .stat-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(56, 189, 248, 0.3);
  transform: translateY(-2px);
}

.stat-label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.3);
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.3));
}

.high-score {
  margin-top: 20px;
  font-size: 18px;
  color: var(--warn);
  padding: 12px 20px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 8px;
  display: inline-block;
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 10px rgba(245, 158, 11, 0.2); }
  50% { box-shadow: 0 0 20px rgba(245, 158, 11, 0.4); }
}

.gameover h2 {
  font-size: 36px;
  margin-bottom: 20px;
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stats-view h2 {
  font-size: 32px;
  margin-bottom: 20px;
  color: var(--accent);
}


.homeBtn {
  position: fixed;
  top: max(10px, var(--sai-top));
  left: max(10px, var(--sai-left));
  padding: 8px 14px;
  min-height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.homeBtn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.volumeBtn {
  position: fixed;
  top: max(10px, var(--sai-top));
  right: max(10px, var(--sai-right));
  padding: 8px 14px;
  min-height: 40px;
  min-width: 40px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  transition: all 0.2s;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
}

.volumeBtn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}


.volume-menu {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 30px;
  box-shadow: var(--shadow), 0 0 40px rgba(56, 189, 248, 0.15);
  min-width: 300px;
  position: relative;
  animation: menu-appear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.volume-menu::before {
  content: '⚙️';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 18px;
  opacity: 0.4;
}

.volume-menu h3 {
  margin-bottom: 20px;
  text-align: center;
  color: var(--text);
}

.volume-control {
  margin: 20px 0;
}

.volume-control label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.volume-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}

.volume-slider::-webkit-slider-thumb:hover {
  background: #60d0ff;
  transform: scale(1.1);
}

.volume-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.volume-slider::-moz-range-thumb:hover {
  background: #60d0ff;
  transform: scale(1.1);
}

.volume-value {
  display: inline-block;
  margin-left: 10px;
  color: var(--text);
  font-weight: 600;
}

.volume-buttons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.volume-buttons .btn {
  flex: 1;
}


@media (max-width: 1024px) and (min-width: 769px) {
  .menu, .gameover, .stats-view {
    max-width: 80%;
    padding: 35px;
  }

  .menu h1 {
    font-size: 42px;
  }

  .btn {
    padding: 16px 28px;
    font-size: 18px;
  }
}


@media (max-width: 768px) {
  .menu, .gameover, .stats-view {
    padding: 25px;
    max-width: 90%;
    margin: 10px;
  }

  .menu h1 {
    font-size: 36px;
  }

  .gameover h2 {
    font-size: 30px;
  }

  .stats-view h2 {
    font-size: 26px;
  }

  .subtitle {
    font-size: 14px;
  }

  .hud {
    height: 55px;
    padding: max(5px, var(--sai-top)) max(15px, var(--sai-right)) 0 max(15px, var(--sai-left));
  }

  .hud-item {
    font-size: 16px;
  }

  .homeBtn, .volumeBtn {
    padding: 8px 12px;
    font-size: 13px;
    min-width: 38px;
    min-height: 38px;
  }

  .volumeBtn {
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  .menu, .gameover, .stats-view {
    padding: 20px;
    max-width: 95%;
    margin: 5px;
  }

  .menu h1 {
    font-size: 32px;
  }

  .gameover h2 {
    font-size: 26px;
  }

  .stats-view h2 {
    font-size: 22px;
  }

  .subtitle {
    font-size: 13px;
    margin-bottom: 20px;
  }

  .stats, .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .hud {
    height: 50px;
    padding: max(5px, var(--sai-top)) max(10px, var(--sai-right)) 0 max(10px, var(--sai-left));
  }

  .hud-item {
    font-size: 14px;
    gap: 4px;
  }

  .hud-label {
    font-size: 11px;
  }

  .homeBtn, .volumeBtn {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 36px;
    min-width: 36px;
  }

  .volumeBtn {
    font-size: 16px;
  }

  .btn {
    padding: 13px 22px;
    font-size: 15px;
  }

  .stat-value {
    font-size: 28px;
  }

  .stat-label {
    font-size: 12px;
  }

  .high-score {
    font-size: 16px;
  }

  .volume-menu {
    min-width: 260px;
    padding: 25px;
  }

  .menu-buttons {
    gap: 10px;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .menu, .gameover, .stats-view {
    max-height: 90vh;
    overflow-y: auto;
    padding: 15px;
  }

  .hud {
    height: 45px;
  }

  .menu h1, .gameover h2, .stats-view h2 {
    font-size: 24px;
    margin-bottom: 10px;
  }

  .btn {
    padding: 10px 18px;
    font-size: 14px;
  }

  .stats, .stats-grid {
    gap: 8px;
  }

  .stat-value {
    font-size: 24px;
  }

  .menu-buttons {
    gap: 8px;
  }
}


@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 48px;
    touch-action: manipulation;
  }

  .homeBtn, .volumeBtn {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
  }

  
  .btn:hover {
    transform: none;
  }

  .btn:active {
    transform: scale(0.96);
    background: linear-gradient(180deg, rgba(56, 189, 248, 0.25), rgba(56, 189, 248, 0.15));
  }

  .btn.primary:active {
    background: linear-gradient(180deg, #1ea34a, #158639);
  }
}


.btn, .homeBtn, .volumeBtn {
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}


.reset-btn {
  position: absolute;
  bottom: 15px;
  right: 15px;
  padding: 8px 14px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.15), rgba(239, 68, 68, 0.08));
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;
}

.reset-btn:hover {
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.25), rgba(239, 68, 68, 0.15));
  border-color: rgba(239, 68, 68, 0.5);
  transform: translateY(-2px);
}

.reset-btn:active {
  transform: translateY(0);
}


.reset-confirmation {
  position: relative;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow), 0 0 40px rgba(239, 68, 68, 0.15);
  text-align: center;
  max-width: 500px;
  width: 100%;
  animation: menu-appear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reset-confirmation h2 {
  font-size: 32px;
  margin-bottom: 10px;
  color: var(--text);
}
