* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Baloo 2", "Fredoka", "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(120% 60% at 50% -10%, #4a7c3a 0%, rgba(74,124,58,0) 60%),
    radial-gradient(90% 50% at 85% 110%, #2c5a26 0%, rgba(44,90,38,0) 55%),
    linear-gradient(180deg, #2f5d27 0%, #1d3319 100%);
  min-height: 100vh;
  color: #2b2118;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#app {
  position: relative;
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  background:
    radial-gradient(rgba(150, 110, 50, .10) 1.2px, transparent 1.3px) 0 0 / 22px 22px,
    linear-gradient(180deg, #faf0da 0%, #f5e7cb 100%);
  padding: 12px 12px 26px;
  box-shadow: 0 0 46px rgba(0,0,0,.45);
  overflow: hidden;
}

/* ---------- header / HUD ---------- */
header { display: flex; justify-content: space-between; align-items: center; }
.brand {
  display: flex; align-items: center; gap: 7px;
  font-size: 25px; font-weight: 800; color: #2f5233; letter-spacing: .3px;
  text-shadow: 0 1px 0 rgba(255,255,255,.6);
}
.brand-ant { width: 38px; height: 26px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.hbtn {
  border: none; background: linear-gradient(180deg, #ffffff, #f1e4c8);
  color: #2f5233; font-family: inherit;
  font-weight: 800; border-radius: 999px; padding: 8px 14px; font-size: 14px;
  cursor: pointer; margin-left: 7px;
  box-shadow: 0 3px 0 #b39b62, 0 5px 10px rgba(90, 60, 10, .18);
}
.hbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b39b62; }
#hud {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 10px; font-weight: 800; color: #5b4632; font-size: 15.5px;
}
#hud-tiles { color: #8a6d3f; font-size: 14px; }
#progress {
  height: 10px; background: #e2cfa6; border-radius: 99px; margin: 6px 0 8px;
  overflow: hidden; box-shadow: inset 0 2px 3px rgba(90, 60, 10, .25);
}
#progress-fill {
  height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(180deg, #5fd63c, #38b000);
  box-shadow: inset 0 2px 2px rgba(255,255,255,.45);
  transition: width .25s ease;
}

/* ---------- canvas play area ---------- */
#game-canvas { display: block; width: 100%; touch-action: manipulation; }

#hint {
  min-height: 38px; margin: 10px 2px 0; font-size: 13.5px; line-height: 1.4;
  font-weight: 600; color: #6b543a; text-align: center;
}
#hint.warn { color: #b3261e; font-weight: 800; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 60;
  background: rgba(22, 16, 6, .62);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadeIn .18s ease both;
}
.overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.panel {
  background: linear-gradient(180deg, #fffaf0, #fdf1da);
  border-radius: 22px; padding: 22px 17px 18px;
  width: 100%; max-width: 400px; max-height: 88%;
  overflow-y: auto; text-align: center;
  box-shadow: 0 16px 44px rgba(0,0,0,.45), inset 0 2px 0 rgba(255,255,255,.8);
  animation: panelIn .28s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes panelIn { from { transform: scale(.88) translateY(14px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.panel h2 { margin: 2px 0 12px; color: #2f5233; font-size: 23px; font-weight: 800; }

#level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-bottom: 14px; }
.lvl-btn {
  border: none; background: linear-gradient(180deg, #ffffff, #f4e8cd);
  border-radius: 14px; padding: 9px 2px 7px;
  font-family: inherit; font-weight: 800; color: #2f5233; cursor: pointer; font-size: 16px;
  box-shadow: 0 3px 0 #c9ae7c, 0 4px 8px rgba(90, 60, 10, .14);
}
.lvl-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #c9ae7c; }
.lvl-btn small { display: block; font-weight: 700; font-size: 10px; color: #8a6d3f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl-btn .stars { display: block; font-size: 11px; color: #e9a13b; min-height: 14px; letter-spacing: 1px; }
.lvl-btn.locked { opacity: .38; box-shadow: none; cursor: default; }
.lvl-btn.current { background: linear-gradient(180deg, #e4f6dc, #cdeabd); box-shadow: 0 3px 0 #7fb069; }

.big-btn {
  display: block; width: 100%; margin-top: 10px;
  background: linear-gradient(180deg, #4cc417, #33a002);
  color: #fff; border: none; border-radius: 999px;
  font-family: inherit; font-size: 17px; font-weight: 800; padding: 13px; cursor: pointer;
  box-shadow: 0 4px 0 #257a00, 0 7px 14px rgba(40, 110, 0, .30);
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #257a00; }
.big-btn.secondary {
  background: linear-gradient(180deg, #ffffff, #f4e8cd); color: #2f5233;
  box-shadow: 0 4px 0 #c9ae7c; text-shadow: none;
}
.big-btn.secondary:active { box-shadow: 0 1px 0 #c9ae7c; }
.big-btn.hidden { display: none; }

#end-stars { font-size: 42px; letter-spacing: 7px; min-height: 50px; line-height: 1.1; }
#end-stars .star-on {
  color: #f2a81d; display: inline-block;
  text-shadow: 0 2px 0 #c47f0a, 0 4px 10px rgba(240, 170, 30, .45);
  animation: starPop .45s cubic-bezier(.2, 1.6, .4, 1) both;
}
#end-stars .dim { color: #ddd3bd; }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

#end-picture { display: grid; gap: 2px; width: 172px; margin: 4px auto 10px; }
#end-picture .tile {
  aspect-ratio: 1/1; border-radius: 3px;
  box-shadow: inset 0 2px 2px rgba(255,255,255,.45), inset 0 -2px 2px rgba(0,0,0,.18), 0 1px 1px rgba(90,60,20,.25);
}
#end-picture .tile.empty { background: rgba(120, 90, 40, .08); box-shadow: none; }
#end-text { color: #6b543a; margin: 6px 0 4px; font-weight: 600; line-height: 1.4; }
