: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;
  touch-action: none;
  font-family: 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
#gameContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: calc(60px + var(--sai-top)) var(--sai-right) calc(50px + var(--sai-bottom)) var(--sai-left);
}
#gameCanvas {
  display: block;
  background: transparent;
  border-radius: 8px;
  max-width: min(90vw, calc(100vh - 130px));
  max-height: min(90vw, calc(100vh - 130px));
}
.hud {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  padding: max(10px, var(--sai-top)) max(20px, var(--sai-right)) 0 max(20px, var(--sai-left));
  justify-content: center;
  align-items: center;
  gap: 24px;
  z-index: 100;
  pointer-events: none;
}
.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.hud-label {
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
}
.hud-value {
  color: #fff;
}
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
#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;
  font-family: inherit;
}
.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;
  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 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;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}
.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;
}
.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);
}
.btn, .homeBtn, .volumeBtn {
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@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: 14px; max-width: 95%; margin: 5px; }
  .menu h1 { font-size: 28px; margin-bottom: 4px; }
  .gameover h2 { font-size: 22px; margin-bottom: 10px; }
  .stats-view h2 { font-size: 22px; }
  .subtitle { font-size: 12px; margin-bottom: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 10px 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0; }
  .stat { padding: 8px 4px; }
  .stat-card { padding: 10px; }
  .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: 10px 18px; font-size: 14px; }
  .menu-buttons { gap: 8px; margin: 10px 0; }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 10px; margin-bottom: 4px; }
  .high-score { margin-top: 10px; padding: 8px 14px; font-size: 14px; }
  .menu::before, .gameover::before { top: 8px; right: 8px; font-size: 18px; }
  .menu::after, .gameover::after { bottom: 8px; left: 8px; font-size: 16px; }
  .volume-menu { min-width: 260px; padding: 20px; }
  .hud-pause { min-width: 40px; min-height: 40px; font-size: 16px; padding: 4px 10px; }
}
@media (max-width: 375px) {
  .menu, .gameover, .stats-view { padding: 12px; margin: 5px; border-radius: 12px; }
  .menu h1 { font-size: 24px; margin-bottom: 2px; }
  .gameover h2, .stats-view h2 { font-size: 20px; margin-bottom: 8px; }
  .subtitle { font-size: 11px; margin-bottom: 10px; }
  .btn { padding: 10px 14px; font-size: 13px; min-height: 42px; }
  .menu-buttons { gap: 6px; margin: 8px 0; }
  .stats { gap: 4px; }
  .stats-grid { gap: 6px; }
  .stat { padding: 6px 2px; }
  .stat-card { padding: 8px; }
  .stat-label { font-size: 9px; }
  .stat-value { font-size: 18px; }
  .volume-menu { min-width: 160px; padding: 12px; }
  #gameCanvas { max-width: min(95vw, calc(100vh - 100px)); max-height: min(95vw, calc(100vh - 100px)); }
  #gameContainer { padding-top: calc(50px + var(--sai-top)); padding-bottom: calc(40px + var(--sai-bottom)); }
}
@media (orientation: landscape) and (max-height: 600px) {
  .menu, .gameover, .stats-view { max-height: 90vh; overflow-y: auto; padding: 15px; }
  .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 (orientation: landscape) and (max-height: 500px) {
  .hud { height: 40px; }
  .hud-item { font-size: 13px; padding: 4px 10px; }
  .hud-label { font-size: 11px; }
  .hud-pause { min-width: 36px; min-height: 36px; font-size: 14px; padding: 4px 8px; }
  #gameContainer { padding-top: calc(40px + var(--sai-top)); }
  .homeBtn, .volumeBtn { padding: 4px 8px; font-size: 12px; min-height: 32px; min-width: 32px; }
}
@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); }
  .btn.primary:active { background: linear-gradient(180deg, #1ea34a, #158639); }
}
.combo-hud {
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.combo-hud .hud-value {
  font-weight: 800;
  font-size: 20px;
}
.hud-pause {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  padding: 6px 12px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.hud-pause:hover {
  background: rgba(255, 255, 255, 0.15);
}
.speed-bar-wrap {
  width: 60px;
  height: 8px;
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.speed-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.3s ease, background 0.3s ease;
  background: var(--good);
}
#overlay {
  transition: opacity 0.25s ease;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
