:root {
  --bg-gradient: radial-gradient(circle at center, #0f2b1d 0%, #08160f 100%);
  --panel-bg: rgba(255, 255, 255, 0.07);
  --panel-border: rgba(255, 255, 255, 0.15);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --color-healthy: #22c55e;
  --color-healthy-glow: rgba(34, 197, 94, 0.5);
  --color-junk: #ef4444;
  --color-junk-glow: rgba(239, 68, 68, 0.5);
  --color-protein: #eab308;
  --color-protein-glow: rgba(234, 179, 8, 0.6);
  --color-accent: #06b6d4;

  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-gradient);
  color: var(--text-main);
  font-family: var(--font-body);
}

#app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100vh;
  padding: 8px 12px;
  max-width: 1024px;
  margin: 0 auto;
}

/* HUD Panel */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
}

.glass-panel-heavy {
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

#game-hud {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.level-badge {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 5px 12px;
  border-radius: 20px;
  box-shadow: 0 0 12px var(--color-healthy-glow);
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.stat-label {
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
}

/* Vitality Bar */
.vitality-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.vitality-icon {
  font-size: 1rem;
}

.vitality-track {
  width: 100px;
  height: 10px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  overflow: hidden;
}

.vitality-fill {
  height: 100%;
  background: linear-gradient(90deg, #eab308, #22c55e);
  border-radius: 5px;
  transition: width 0.3s ease;
}

/* Protein Pill */
.protein-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-family: var(--font-heading);
  font-weight: 700;
  transition: all 0.3s ease;
}

.protein-pill.inactive {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  border: 1px solid transparent;
}

.protein-pill.active {
  background: linear-gradient(135deg, #ca8a04, #eab308);
  color: #000;
  border: 1px solid #fef08a;
  box-shadow: 0 0 16px var(--color-protein-glow);
  animation: pulse-glow 1.2s infinite alternate;
}

@keyframes pulse-glow {
  0% { transform: scale(1); box-shadow: 0 0 8px var(--color-protein-glow); }
  100% { transform: scale(1.05); box-shadow: 0 0 20px var(--color-protein-glow); }
}

.icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

/* Main Canvas Wrapper */
#canvas-wrapper {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 800px;
  max-height: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: #06110a;
}

#game-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Overlay Screens & Modals */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 100; /* ALWAYS on top of canvas and D-pad! */
  background: rgba(6, 17, 10, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.overlay-screen.active {
  opacity: 1;
  visibility: visible;
}

.menu-card {
  width: 100%;
  max-width: 480px;
  max-height: 95%;
  overflow-y: auto;
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.menu-card.small {
  max-width: 380px;
}

.logo-area .logo-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 2px;
}

.logo-area h1 {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 900;
  background: linear-gradient(135deg, #4ade80, #10b981, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}

.logo-area .subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.guide-box {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 14px;
  padding: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.guide-box h3 {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: #f1f5f9;
}

.guide-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 12px;
  border-radius: 12px;
}

.guide-item .emoji {
  font-size: 1.5rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.guide-item strong {
  display: block;
  font-size: 0.85rem;
  color: #fff;
}

.guide-item p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.guide-item.healthy strong { color: var(--color-healthy); }
.guide-item.junk strong { color: var(--color-junk); }
.guide-item.protein strong { color: var(--color-protein); }

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border: none;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.1rem;
  padding: 14px 28px;
  border-radius: 14px;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 8px 24px var(--color-healthy-glow);
  transition: all 0.2s ease;
  z-index: 110;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px var(--color-healthy-glow);
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  padding: 12px 24px;
  border-radius: 12px;
  cursor: pointer;
  width: 100%;
}

.danger-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 8px 24px var(--color-junk-glow);
}

.danger-btn:hover {
  box-shadow: 0 12px 28px var(--color-junk-glow);
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.badge-success {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid var(--color-healthy);
  padding: 6px 16px;
  border-radius: 20px;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.9rem;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid var(--color-junk);
  padding: 6px 16px;
  border-radius: 20px;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.9rem;
}

.trivia-box {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.trivia-icon {
  font-size: 1.4rem;
}

.trivia-box p {
  font-size: 0.82rem;
  color: #e0f2fe;
  line-height: 1.35;
}

.stats-summary {
  display: flex;
  gap: 20px;
  background: rgba(0, 0, 0, 0.3);
  padding: 10px 18px;
  border-radius: 14px;
  width: 100%;
  justify-content: center;
}

.summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.summary-item .label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.summary-item .val {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.3rem;
  color: #fff;
}

/* Mobile D-Pad Controls: Desktop Layout (Default: Centralized, Compact) */
#mobile-controls {
  width: 100%;
  max-width: 400px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  z-index: 20;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Hide D-Pad completely when menu/pause overlay is active */
#mobile-controls.menu-active {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dpad-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dpad-center {
  width: 32px;
  height: 32px;
}

.dpad-btn {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 8px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.dpad-btn:active {
  background: rgba(34, 197, 94, 0.5);
  transform: scale(0.92);
}

/* Mobile Devices (< 768px): Float D-Pad to Bottom-Right Corner */
@media (max-width: 767px) {
  #game-hud {
    padding: 0 10px;
    height: 50px;
  }
  .stat-label { display: none; }
  .vitality-track { width: 65px; }

  #mobile-controls {
    position: fixed;
    bottom: 16px;
    right: 16px;
    top: auto;
    left: auto;
    width: auto;
    height: auto;
    padding: 8px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 22px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.7);
    z-index: 40;
  }

  .dpad-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
    border-radius: 12px;
  }

  .dpad-center {
    width: 40px;
    height: 40px;
  }

  .dpad-row {
    gap: 8px;
  }
}
