:root {
  --compost: #4caf50;
  --compost-dark: #357a38;
  --recycle: #2f7fd1;
  --recycle-dark: #1f5a97;
  --trash: #4a4f57;
  --trash-dark: #2f333a;
  --sky-top: #8fd0f5;
  --sky-bottom: #cdeeff;
  --sun: #ffe27a;
  --ground: #d8b98a;
  --gold: #ffc93c;
  --panel: rgba(15, 30, 40, 0.85);
  --panel-border: #ffc93c;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Baloo 2", "Comic Sans MS", "Trebuchet MS", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* accounts for mobile browsers' collapsible address bar */
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 60%, var(--ground) 60%, var(--ground) 100%);
  overflow-x: hidden;
  overflow-y: auto;
}
.screen.active { display: flex; }

/* ---------------- Decorative scenery ---------------- */
.scenery { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.cloud {
  position: absolute;
  background: #fff;
  border-radius: 50px;
  opacity: 0.9;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,0.03));
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
}
.c1 { width: 90px; height: 32px; top: 8%; left: 8%; }
.c1::before { width: 50px; height: 50px; top: -22px; left: 10px; }
.c1::after { width: 36px; height: 36px; top: -14px; left: 50px; }
.c2 { width: 70px; height: 26px; top: 14%; right: 12%; }
.c2::before { width: 40px; height: 40px; top: -18px; left: 8px; }
.c2::after { width: 28px; height: 28px; top: -10px; left: 38px; }
.c3 { width: 60px; height: 22px; top: 22%; left: 42%; }
.c3::before { width: 32px; height: 32px; top: -14px; left: 8px; }

.tree { position: absolute; font-size: 4rem; bottom: 38%; filter: drop-shadow(0 6px 4px rgba(0,0,0,0.15)); }
.t1 { left: 2%; bottom: 36%; font-size: 5rem; }
.t2 { left: 10%; bottom: 34%; font-size: 3.2rem; }
.t3 { right: 2%; bottom: 36%; font-size: 5rem; }
.t4 { right: 11%; bottom: 34%; font-size: 3.2rem; }

.scenery-game .tree { display: none; }

/* ---------------- Mute button ---------------- */
.mute-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 5;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mute-btn-game { position: static; margin-left: auto; }

/* ================= INTRO SCREEN ================= */
#screen-intro {
  background-image: url('assets/san-francisco-background-01.jpg');
  background-size: cover;
  background-position: center 42%;
  background-repeat: no-repeat;
}

/* Two stacked layers per screen so a new level's background can fade in
   over the previous one once it's actually loaded, instead of popping in
   (or worse, leaving a blank gap) while it downloads on a slower connection. */
.bg-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center 25%;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.7s ease;
}
.bg-layer.bg-visible { opacity: 1; }

.intro-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem 1.5rem;
  max-width: 640px;
  margin: auto;
}

.intro-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  padding: 3.2rem 2rem 1.8rem;
  margin-top: -3.2rem;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mascot-hero {
  position: relative;
  z-index: 2;
  width: 150px;
  height: 150px;
  object-fit: contain;
  filter: drop-shadow(0 10px 12px rgba(0,0,0,0.25));
  animation: bob 3s ease-in-out infinite;
}
.mascot-hero.small { width: 100px; height: 100px; }

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}

.title {
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-weight: 800;
  margin: 0.3em 0 0.1em;
  color: #14324a;
  letter-spacing: 1px;
}

.tagline {
  font-size: 1.15rem;
  color: #14324a;
  font-weight: 700;
  margin: 0 0 1.2rem;
  max-width: 420px;
}

.mini-bins {
  display: flex;
  gap: 1.3rem;
  margin-bottom: 1.6rem;
  flex-wrap: wrap;
  justify-content: center;
}
.mini-bin {
  font-weight: 700;
  font-size: 1rem;
}
.mini-bin.compost { color: var(--compost-dark); }
.mini-bin.recycle { color: var(--recycle-dark); }
.mini-bin.trash { color: var(--trash-dark); }

.start-btn {
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #ffd766, var(--gold));
  border: 2px solid #fff3c4;
  border-radius: 999px;
  padding: 0.85rem 2.6rem;
  cursor: pointer;
  box-shadow: 0 6px 0 #d99a10, 0 10px 18px rgba(0,0,0,0.25);
  color: #7a3e00;
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
  transition: transform 0.08s ease;
  animation: pulse 1.8s ease-in-out infinite;
}
.start-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #d99a10, 0 4px 10px rgba(0,0,0,0.25);
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

.how-to {
  margin-top: 1.4rem;
  font-size: 0.9rem;
  color: #14324a;
  opacity: 0.8;
  font-weight: 600;
}
kbd {
  background: #fff;
  border: 1px solid #99b;
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  box-shadow: 0 2px 0 #99b;
  font-family: inherit;
}

/* ================= GAMEPLAY SCREEN ================= */
.hud {
  position: relative;
  z-index: 2;
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 14px 16px 0;
}

.hud-box {
  background: var(--panel);
  border: 3px solid var(--panel-border);
  border-radius: 14px;
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 92px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.hud-label {
  color: #ffd766;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.hud-value {
  color: #fff;
  font-size: 1.5rem;
  font-weight: 800;
}

.level-box { min-width: 150px; }

.streak-badge {
  position: absolute;
  top: 90px;
  right: 20px;
  z-index: 3;
  background: linear-gradient(180deg, #ff9f43, #ff6b3d);
  color: #fff;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid #fff;
  opacity: 0;
  transform: scale(0.6) translateY(-10px);
  transition: all 0.25s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.streak-badge.show { opacity: 1; transform: scale(1) translateY(0); }

.stage-area {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.item-stage {
  position: relative;
  width: clamp(90px, 28vh, 300px);
  height: clamp(90px, 28vh, 300px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-glow {
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle, rgba(255,255,255,0.85) 0%, rgba(255,255,255,0) 70%);
  border-radius: 50%;
  z-index: -1;
}

.item-emoji {
  font-size: clamp(3.5rem, 11vh, 12rem);
  line-height: 1;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,0.25));
}
.item-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,0.25));
  display: none;
}

.item-stage.pop-in { animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1); }
@keyframes popIn {
  0% { transform: scale(0) translateY(40px) rotate(-15deg); opacity: 0; }
  70% { transform: scale(1.15) translateY(-6px) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) translateY(0) rotate(0); }
}

.item-stage.fly-away {
  animation: flyAway 0.5s ease-in forwards;
}
@keyframes flyAway {
  0% { transform: scale(1) translateY(0); opacity: 1; }
  100% { transform: scale(0.2) translateY(120px); opacity: 0; }
}

.item-name {
  font-size: 1.4rem;
  font-weight: 800;
  color: #14324a;
  background: rgba(255,255,255,0.85);
  padding: 4px 18px;
  border-radius: 999px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.mascot-corner {
  position: absolute;
  left: 12px;
  top: 100px;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 62%;
}
.mascot-small {
  width: 54px;
  height: 54px;
  object-fit: contain;
  flex-shrink: 0;
  padding: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
.speech-bubble {
  background: #fff;
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #14324a;
  position: relative;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  border: 2px solid #14324a22;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  left: -8px;
  top: 18px;
  border-width: 6px 8px 6px 0;
  border-style: solid;
  border-color: transparent #fff transparent transparent;
}
.speech-bubble.mood-happy { color: var(--compost-dark); }
.speech-bubble.mood-sad { color: #b23a3a; }

.bins-row {
  position: relative;
  z-index: 1;
  display: flex;
  gap: clamp(10px, 3vw, 28px);
  justify-content: center;
  align-items: flex-end;
  width: 100%;
  padding: 0 16px 22px;
}

.bin {
  font-family: inherit;
  position: relative;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: clamp(88px, 24vw, 150px);
  padding: 0;
  transition: transform 0.12s ease;
}
.bin:hover { transform: translateY(-4px); }
.bin:active { transform: translateY(2px); }

/* Explicit aspect-ratio (matches the bin PNGs' real 540:620 pixel size) so
   this box always has a definite height for the checkmark/X badge's
   percentage position to resolve against — an auto/content-driven height
   here was the source of the badge drifting out of alignment. */
.bin-visual {
  position: relative;
  width: 100%;
  aspect-ratio: 540 / 620;
}

.bin-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,0.35));
  border-radius: 10px;
}

/* Checkmark/X badge floats just above the bin's rim, rather than trying to
   stamp over a specific detail baked into the bin art — that depended on
   pixel-matching a raster image and drifted across browsers/devices. A
   fixed spot relative to the bin's own box is much more reliable. */
.bin-mark {
  position: absolute;
  top: -6%;
  left: 50%;
  width: 40%;
  aspect-ratio: 1 / 1;
  min-width: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  opacity: 0;
  z-index: 4;
  pointer-events: none;
  border: 4px solid #fff;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}
.bin-mark svg { width: 58%; height: 58%; }
.bin-mark.show { animation: markFade 2s ease forwards; }
@keyframes markFade {
  0% { opacity: 0; }
  10% { opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}
.mark-correct { background: var(--compost); }
.mark-wrong { background: #e5484d; }

.bin.bump { animation: binBump 0.4s ease; }
@keyframes binBump {
  0% { transform: scale(1); }
  30% { transform: scale(1.12) rotate(-2deg); }
  60% { transform: scale(0.96) rotate(2deg); }
  100% { transform: scale(1); }
}

.bin.shake { animation: binShake 0.4s ease; }
@keyframes binShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* ================= LEVEL RESULT / CONGRATS ================= */
.result-card {
  position: relative;
  z-index: 1;
  margin: auto;
  background: rgba(255,255,255,0.92);
  border-radius: 24px;
  padding: 2rem 2.2rem;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  max-width: 420px;
  border: 4px solid var(--gold);
}

.result-title {
  font-size: 2rem;
  font-weight: 800;
  color: #14324a;
  margin: 0.4rem 0;
}
.congrats-title { color: var(--compost-dark); }

.big-stars { display: flex; justify-content: center; gap: 6px; margin: 0.6rem 0; }
.big-star { font-size: 2.4rem; color: #dcdcdc; text-shadow: 0 2px 2px rgba(0,0,0,0.1); }
.big-star.filled { color: var(--gold); }
.congrats-stars .big-star { font-size: 1.6rem; }

.result-message {
  font-size: 1.05rem;
  font-weight: 700;
  color: #14324a;
  margin: 0.6rem 0 1.2rem;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}
.confetti-piece {
  position: absolute;
  top: -10px;
  width: 10px;
  height: 14px;
  opacity: 0.9;
  animation: confettiFall linear forwards;
  border-radius: 2px;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 0.8; }
}

/* ================= Responsive tweaks ================= */
@media (max-width: 480px) {
  .hud-box { min-width: 76px; padding: 4px 8px; }
  .mascot-corner { max-width: 85%; }
}

@media (max-height: 640px) {
  .mascot-corner { top: 80px; }
  .mascot-small { width: 48px; height: 48px; }
}
