/* ==========================================================================
   Design tokens
   ========================================================================== */

:root {
  --bg-0: #07060f;
  --bg-1: #12102a;
  --bg-2: #1c1840;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-hover: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f2ff;
  --text-muted: rgba(244, 242, 255, 0.45);
  --accent: #7c5cff;
  --accent-glow: rgba(124, 92, 255, 0.35);
  --good: #3ee08a;
  --bad: #ff6b6b;
  --neutral: #f0b429;
  --muscle: #ff9f43;
  --fat: #ff6b81;
  --health: #3ee08a;
  --radius-lg: 28px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 28px 70px -20px rgba(0, 0, 0, 0.65);
  --font: 'Outfit', system-ui, sans-serif;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

body {
  font-family: var(--font);
  background: linear-gradient(160deg, var(--bg-0) 0%, var(--bg-1) 45%, var(--bg-2) 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  color: var(--text);
  overflow-x: hidden;
}

.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: floatOrb 14s ease-in-out infinite;
}

.orb-1 {
  width: 320px;
  height: 320px;
  background: #7c5cff;
  top: -80px;
  left: -60px;
}

.orb-2 {
  width: 260px;
  height: 260px;
  background: #ff6b81;
  bottom: 10%;
  right: -40px;
  animation-delay: -5s;
}

.orb-3 {
  width: 200px;
  height: 200px;
  background: #3ee08a;
  bottom: 30%;
  left: 20%;
  animation-delay: -9s;
  opacity: 0.25;
}

@keyframes floatOrb {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -24px) scale(1.08); }
}

/* ==========================================================================
   Layout
   ========================================================================== */

.game-container {
  position: relative;
  z-index: 1;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.03) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  padding: 32px 28px 24px;
  max-width: 720px;
  width: 100%;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  animation: fadeUp 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.game-header {
  text-align: center;
  margin-bottom: 22px;
}

.logo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  font-size: 1.6rem;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.25), rgba(255, 107, 129, 0.15));
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 10px;
  box-shadow: 0 8px 24px var(--accent-glow);
}

h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff 30%, rgba(255, 255, 255, 0.75));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ==========================================================================
   Character stage
   ========================================================================== */

.character-section {
  margin-bottom: 18px;
}

.character-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.character-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#characterCanvas {
  display: block;
  width: 240px;
  height: 308px;
  border-radius: 20px;
  background: radial-gradient(ellipse at 50% 80%, rgba(124, 92, 255, 0.12) 0%, transparent 65%),
    rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  position: relative;
  z-index: 1;
}

.character-glow {
  position: absolute;
  inset: 10% 5% 0;
  background: radial-gradient(ellipse at 50% 60%, var(--accent-glow), transparent 70%);
  filter: blur(20px);
  z-index: 0;
  opacity: 0.7;
  transition: opacity 0.4s ease;
}

.character-wrapper.eating .character-glow {
  opacity: 1;
  animation: pulseGlow 0.5s ease;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.message {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  text-align: center;
  min-height: 22px;
  max-width: 320px;
  line-height: 1.4;
  transition: color 0.3s ease, transform 0.3s ease;
}

.message.pop {
  color: var(--text);
  transform: scale(1.02);
}

/* ==========================================================================
   Stats
   ========================================================================== */

.stats-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  border: 1px solid var(--border);
  transition: transform 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.stat-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.stat-card.bump {
  animation: statBump 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes statBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}

.stat-icon {
  font-size: 0.75rem;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-card[data-stat="muscle"] .stat-value { color: var(--muscle); }
.stat-card[data-stat="fat"] .stat-value { color: var(--fat); }
.stat-card[data-stat="health"] .stat-value { color: var(--health); }

.stat-bar {
  height: 5px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 99px;
  margin-top: 8px;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.7s cubic-bezier(0.34, 1.2, 0.64, 1);
  width: 0;
}

.stat-fill.muscle {
  background: linear-gradient(90deg, #ff9f43, #ff6b6b);
  box-shadow: 0 0 12px rgba(255, 159, 67, 0.4);
}

.stat-fill.fat {
  background: linear-gradient(90deg, #ff6b81, #c0392b);
  box-shadow: 0 0 12px rgba(255, 107, 129, 0.35);
}

.stat-fill.health {
  background: linear-gradient(90deg, #3ee08a, #27ae60);
  box-shadow: 0 0 12px rgba(62, 224, 138, 0.35);
}

/* ==========================================================================
   Food
   ========================================================================== */

.food-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-label {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.food-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-btn {
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.15);
}

.filter-btn.active {
  background: rgba(124, 92, 255, 0.2);
  border-color: rgba(124, 92, 255, 0.45);
  color: #c4b5fd;
}

.food-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(124, 92, 255, 0.4) transparent;
}

.food-grid::-webkit-scrollbar {
  width: 5px;
}

.food-grid::-webkit-scrollbar-thumb {
  background: rgba(124, 92, 255, 0.35);
  border-radius: 99px;
}

.food-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px 8px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.food-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.food-btn[data-type="good"]::before {
  background: linear-gradient(180deg, rgba(62, 224, 138, 0.12), transparent);
}

.food-btn[data-type="bad"]::before {
  background: linear-gradient(180deg, rgba(255, 107, 107, 0.12), transparent);
}

.food-btn[data-type="neutral"]::before {
  background: linear-gradient(180deg, rgba(240, 180, 41, 0.1), transparent);
}

.food-btn:hover:not(:disabled)::before {
  opacity: 1;
}

.food-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.5);
}

.food-btn:active:not(:disabled) {
  transform: translateY(-1px) scale(0.98);
}

.food-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.food-icon {
  font-size: 1.65rem;
  line-height: 1;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  z-index: 1;
}

.food-btn:hover .food-icon {
  transform: scale(1.15) rotate(-6deg);
}

.food-name {
  font-size: 0.68rem;
  font-weight: 600;
  position: relative;
  z-index: 1;
}

.food-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  position: relative;
  z-index: 1;
}

.food-tag {
  font-size: 0.48rem;
  font-weight: 700;
  padding: 2px 4px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

.food-tag.pos { background: rgba(62, 224, 138, 0.15); color: var(--good); }
.food-tag.neg { background: rgba(255, 107, 107, 0.15); color: var(--bad); }

/* ==========================================================================
   Footer & toast
   ========================================================================== */

footer {
  display: flex;
  justify-content: center;
  margin-top: 18px;
  padding-top: 4px;
}

.btn-reset {
  padding: 11px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-reset:hover {
  background: rgba(255, 107, 107, 0.12);
  color: #ff8a8a;
  border-color: rgba(255, 107, 107, 0.25);
  transform: translateY(-1px);
}

#toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  opacity: 0;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s ease;
  z-index: 200;
  pointer-events: none;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  max-width: 90vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.type-good {
  background: linear-gradient(135deg, #2ecc71, #1e8449);
}

#toast.type-bad {
  background: linear-gradient(135deg, #e74c3c, #922b21);
}

#toast.type-neutral {
  background: linear-gradient(135deg, #f39c12, #d68910);
}

#toast.type-info {
  background: linear-gradient(135deg, #3498db, #1f618d);
}

/* ==========================================================================
   Flying food & particles (injected by JS)
   ========================================================================== */

@keyframes foodFly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0deg);
  }
  45% {
    opacity: 0.95;
    transform: translate(var(--tx), var(--ty)) scale(1.2) rotate(120deg);
  }
  100% {
    opacity: 0;
    transform: translate(calc(var(--tx) * 1.15), calc(var(--ty) * 1.15)) scale(0.2) rotate(280deg);
  }
}

.food-particle {
  position: fixed;
  pointer-events: none;
  z-index: 150;
  font-size: 0.9rem;
  animation: particleBurst 0.7s ease-out forwards;
}

@keyframes particleBurst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--px), var(--py)) scale(0.3);
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 520px) {
  .game-container {
    padding: 22px 16px 18px;
    border-radius: 22px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .food-grid {
    grid-template-columns: repeat(2, 1fr);
    max-height: 320px;
  }

  .food-section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  #characterCanvas {
    width: 200px;
    height: 257px;
  }

  .stat-value {
    font-size: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
