/* ============================================
   🐍 Snakey — Style System
   ============================================ */

:root {
  --bg-deep: #0f1923;
  --bg-surface: #162330;
  --bg-card: #1c2e3f;
  --accent: #4ade80;
  --accent-glow: rgba(74, 222, 128, 0.35);
  --accent-dim: #22c55e;
  --food-color: #f472b6;
  --food-glow: rgba(244, 114, 182, 0.5);
  --text-primary: #e8f0f8;
  --text-secondary: #7a9bb5;
  --text-muted: #4a6a80;
  --glass: rgba(22, 35, 48, 0.85);
  --glass-border: rgba(74, 222, 128, 0.15);
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ---- Reset ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- App Layout ---- */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 520px;
  height: 100%;
  max-height: 100dvh;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  gap: 10px;
}

/* ---- Header ---- */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 12px var(--accent-glow);
}

#header h1 {
  font-size: 1.35rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #86efac);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.header-right {
  display: flex;
  gap: 8px;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.05);
  min-width: 60px;
  transition: transform 0.15s ease;
}

.score-box.best {
  border-color: rgba(74, 222, 128, 0.2);
}

.score-box.pop {
  transform: scale(1.12);
}

.score-label {
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.score-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.score-box.best .score-value {
  color: var(--accent);
}

/* ---- Game Container ---- */
#game-container {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 0 60px rgba(0,0,0,0.3);
}

#game-canvas {
  display: block;
  border-radius: var(--radius);
}

/* ---- Overlay ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 25, 35, 0.92);
  backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 10;
  border-radius: var(--radius);
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}

.overlay-icon {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  box-shadow: 0 0 30px var(--accent-glow), 0 8px 24px rgba(0,0,0,0.4);
}

.overlay-content h2 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #86efac, #4ade80);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.overlay-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Final score section */
.final-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 32px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
}

.final-score-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.final-score-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.new-best {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  animation: pulse 0.8s ease infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.7; transform: scale(0.95); }
  to   { opacity: 1;   transform: scale(1.05); }
}

/* Play Button */
.play-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 36px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--accent), #22c55e);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  margin-top: 4px;
}

.play-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 28px var(--accent-glow), 0 4px 12px rgba(0,0,0,0.4);
}

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

.hint {
  font-size: 0.75rem !important;
  color: var(--text-muted) !important;
  margin-top: 4px;
}

/* ---- Pause Button (Header) ---- */
.pause-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex-shrink: 0;
}

.pause-btn:hover {
  background: var(--accent);
  color: var(--bg-deep);
  border-color: var(--accent);
}

.pause-btn:active {
  transform: scale(0.9);
}

/* ---- Pause Indicator ---- */
.pause-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 36px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  z-index: 5;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}

.pause-indicator span {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 3px;
}

.pause-indicator small {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Resume button inside pause overlay */
.resume-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 28px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--accent), #22c55e);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.resume-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.resume-btn:active {
  transform: scale(0.95);
}

/* ---- Mobile D-Pad Controls ---- */
.mobile-controls {
  display: none;
  position: relative;
  width: 160px;
  height: 160px;
  flex-shrink: 0;
  margin-bottom: 8px;
}

.dpad-btn {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.dpad-btn svg {
  width: 22px;
  height: 22px;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: var(--accent);
  color: var(--bg-deep);
  transform: scale(0.92);
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.dpad-btn.up    { top: 0; left: 50%; transform: translateX(-50%); }
.dpad-btn.down  { bottom: 0; left: 50%; transform: translateX(-50%); }
.dpad-btn.left  { left: 0; top: 50%; transform: translateY(-50%); }
.dpad-btn.right { right: 0; top: 50%; transform: translateY(-50%); }

.dpad-btn.up:active    { transform: translateX(-50%) scale(0.92); }
.dpad-btn.down:active  { transform: translateX(-50%) scale(0.92); }
.dpad-btn.left:active  { transform: translateY(-50%) scale(0.92); }
.dpad-btn.right:active { transform: translateY(-50%) scale(0.92); }

/* ---- Utility ---- */
.hidden { display: none !important; }

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

.bounce {
  animation: bounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounceIn {
  0%   { transform: scale(0.3); opacity: 0; }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  #app {
    padding: 8px 10px;
    gap: 8px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }

  .mobile-controls {
    display: block;
  }

  .hint {
    content: 'Swipe or use buttons to move';
  }

  .logo-icon {
    width: 28px;
    height: 28px;
  }

  #header h1 {
    font-size: 1.1rem;
  }

  .score-box {
    padding: 3px 10px;
    min-width: 50px;
  }

  .score-value {
    font-size: 1rem;
  }

  .overlay-icon {
    width: 64px;
    height: 64px;
  }

  .overlay-content h2 {
    font-size: 1.6rem;
  }
}

@media (max-height: 600px) {
  .overlay-icon {
    width: 48px;
    height: 48px;
  }
  .overlay-content {
    gap: 8px;
    padding: 12px;
  }
  .mobile-controls {
    width: 140px;
    height: 140px;
  }
  .dpad-btn {
    width: 44px;
    height: 44px;
  }
}
