:root {
  --green-dark: #1a4a1a;
  --green-mid: #2d7a2d;
  --green-light: #4caf50;
  --green-bright: #8bc34a;
  --yellow: #ffd600;
  --orange: #ff8f00;
  --brown: #5d4037;
  --sky: #1b5e20;
  --wall: #2e7d32;
  --path: #f1f8e9;
  --player: #ffd600;
  --exit: #ff6f00;
}

* { box-sizing: border-box; margin: 0; padding: 0; touch-action: none; }

body {
  background: var(--green-dark);
  font-family: 'Nunito', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  position: relative;
}

/* Jungle background deco */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(45,122,45,0.6) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 10%, rgba(76,175,80,0.4) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 50%, rgba(26,74,26,0.8) 0%, transparent 80%);
  pointer-events: none;
  z-index: 0;
}

.leaves {
  position: fixed;
  font-size: 3rem;
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
  animation: sway 4s ease-in-out infinite alternate;
}
.leaves:nth-child(1) { top: -10px; left: -20px; font-size: 5rem; animation-delay: 0s; }
.leaves:nth-child(2) { top: -10px; right: -20px; font-size: 5rem; animation-delay: 1s; transform: scaleX(-1); }
.leaves:nth-child(3) { bottom: -10px; left: -10px; font-size: 4rem; animation-delay: 0.5s; }
.leaves:nth-child(4) { bottom: -10px; right: -10px; font-size: 4rem; animation-delay: 1.5s; transform: scaleX(-1); }

@keyframes sway {
  from { transform: rotate(-5deg); }
  to { transform: rotate(5deg); }
}

header {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 16px 20px 8px;
  width: 100%;
}

h1 {
  font-family: 'Fredoka One', cursive;
  font-size: 2.2rem;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--brown), 0 0 20px rgba(255,214,0,0.4);
  letter-spacing: 1px;
}

.subtitle {
  color: #a5d6a7;
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 2px;
}

.stats {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 8px 0;
  z-index: 10;
  position: relative;
}

.stat {
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--green-light);
  border-radius: 20px;
  padding: 4px 14px;
  color: #fff;
  font-weight: 900;
  font-size: 0.9rem;
}

.stat span { color: var(--yellow); }

#game-area {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 10px;
}

#maze-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 4px var(--yellow),
    0 0 0 8px var(--brown),
    0 0 40px rgba(0,0,0,0.6);
}

canvas {
  display: block;
  image-rendering: pixelated;
}

.controls {
  display: grid;
  grid-template-columns: 60px 60px 60px;
  grid-template-rows: 60px 60px;
  gap: 6px;
  position: relative;
  z-index: 10;
}

.btn {
  background: linear-gradient(145deg, #388e3c, #1b5e20);
  border: 3px solid var(--green-bright);
  border-radius: 14px;
  color: #fff;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 4px 0 #1b5e20, 0 6px 12px rgba(0,0,0,0.3);
  transition: transform 0.08s, box-shadow 0.08s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active, .btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1b5e20, 0 2px 6px rgba(0,0,0,0.2);
}

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

/* Win overlay */
#win-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

#win-screen.show { display: flex; }

.win-box {
  background: linear-gradient(135deg, #1a4a1a, #2d7a2d);
  border: 4px solid var(--yellow);
  border-radius: 24px;
  padding: 32px 40px;
  max-width: 320px;
  box-shadow: 0 0 60px rgba(255,214,0,0.4);
  animation: popIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.win-emoji { font-size: 4rem; margin-bottom: 8px; }
.win-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2.4rem;
  color: var(--yellow);
  text-shadow: 2px 2px 0 var(--brown);
  margin-bottom: 8px;
}
.win-msg { color: #c8e6c9; font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }

.next-btn {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  border: none;
  border-radius: 50px;
  padding: 14px 32px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.4rem;
  color: var(--brown);
  cursor: pointer;
  box-shadow: 0 4px 0 #bf6f00, 0 8px 20px rgba(0,0,0,0.3);
  transition: transform 0.1s, box-shadow 0.1s;
}
.next-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #bf6f00; }

.level-badge {
  display: inline-block;
  background: rgba(255,214,0,0.2);
  border: 2px solid var(--yellow);
  border-radius: 20px;
  padding: 2px 12px;
  color: var(--yellow);
  font-weight: 900;
  font-size: 0.85rem;
  margin-bottom: 12px;
}
