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

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a25;
  --accent-primary: #00ff88;
  --accent-secondary: #00cc6a;
  --accent-glow: rgba(0, 255, 136, 0.3);
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --danger: #ff4757;
  --warning: #ffa502;
  --border: #2a2a3a;
  --grid-line: rgba(255, 255, 255, 0.03);
  --snake-head: #00ff88;
  --snake-body: #00cc6a;
  --snake-tail: #009950;
  --food: #ff6b81;
  --food-glow: rgba(255, 107, 129, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: var(--bg-primary);
  font-family: 'Outfit', sans-serif;
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  min-width: 80px;
}

.score-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.score-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent-primary);
  text-shadow: 0 0 10px var(--accent-glow);
}

.game-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, var(--accent-primary), var(--food));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-lg), inset 0 0 40px rgba(0, 0, 0, 0.3);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
  padding: 32px;
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.snake-icon, .game-over-icon, .pause-icon {
  font-size: 64px;
  margin-bottom: 16px;
  display: block;
  animation: bounce 2s infinite;
}

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

.overlay-content h2 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.overlay-content p {
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.final-score {
  font-size: 20px !important;
  color: var(--accent-primary) !important;
  font-weight: 700;
}

.new-high {
  color: var(--warning);
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 16px;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.new-high.hidden {
  display: none;
}

.btn {
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-xl);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  min-height: 48px;
  min-width: 48px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: var(--bg-primary);
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px var(--accent-glow);
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  gap: 16px;
}

.d-pad {
  display: grid;
  grid-template-rows: auto auto auto;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 160px;
}

.d-pad-center {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
}

.d-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.d-btn:active {
  background: var(--accent-primary);
  color: var(--bg-primary);
  transform: scale(0.95);
}

.d-btn.up { grid-column: 2; }
.d-btn.left { grid-column: 1; }
.d-btn.right { grid-column: 3; }
.d-btn.down { grid-column: 2; }

#pauseBtn {
  flex: 1;
  max-width: 120px;
}

.game-footer {
  text-align: center;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 12px;
}

@media (max-height: 700px) {
  .game-container {
    padding: 12px;
    gap: 8px;
  }
  
  .game-title {
    font-size: 24px;
  }
  
  .score-value {
    font-size: 20px;
  }
  
  .d-btn {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }
  
  .overlay-content {
    padding: 24px;
  }
  
  .overlay-content h2 {
    font-size: 28px;
  }
}

@media (max-width: 360px) {
  .game-container {
    padding: 8px;
  }
  
  .d-pad {
    width: 140px;
  }
  
  .d-btn {
    width: 46px;
    height: 46px;
  }
}
