* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fdcff;
  font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas { display: block; touch-action: none; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(120, 30, 80, 0.78);
  backdrop-filter: blur(4px);
}

#top .box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
  padding: 3px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
}

#top .box.wide { min-width: 120px; }
#top .lab { font-size: 10px; letter-spacing: 2px; font-weight: 700; opacity: 0.8; }
#top b { font-size: 22px; font-variant-numeric: tabular-nums; color: #ffe066; }
#top .wide b { color: #b6f7ff; }

#map {
  position: absolute;
  top: max(70px, calc(env(safe-area-inset-top) + 60px));
  left: max(16px, env(safe-area-inset-left));
  width: 150px;
  height: 150px;
  border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: #6fbf5f;
  box-shadow: 0 4px 0 rgba(120, 30, 80, 0.35);
}
.arcade #map { top: max(106px, calc(env(safe-area-inset-top) + 96px)); }

.pill {
  pointer-events: auto;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  touch-action: manipulation;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: rgba(120, 30, 80, 0.6);
  color: #fff;
  font-size: 12px;
  letter-spacing: 2px;
  padding: 8px 14px;
  min-height: 44px;
  backdrop-filter: blur(4px);
}

#pauseBtn { position: absolute; top: max(16px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); }
.arcade #pauseBtn { top: max(52px, calc(env(safe-area-inset-top) + 42px)); }
#soundBtn { position: absolute; top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); }
#soundBtn[aria-pressed="true"] { background: rgba(255, 255, 255, 0.92); color: #7a1f55; }

#toasts {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(250px, calc(env(safe-area-inset-bottom) + 240px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

#toasts div {
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(120, 30, 80, 0.85);
  font-size: 15px;
  font-weight: 700;
  animation: toastIn 0.2s ease-out;
}

@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } }

#msg {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 90%;
  text-align: center;
  font-size: 50px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #fff;
  text-shadow: 0 4px 0 rgba(150, 30, 90, 0.7), 0 0 24px rgba(0, 0, 0, 0.3);
}

#msg small { display: block; font-size: 20px; letter-spacing: 1px; margin-top: 4px; }
#msg.gold { color: #ffe066; }

#hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 8px));
  width: max-content;
  max-width: calc(100% - 420px);
  padding: 9px 18px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  border-radius: 18px;
  background: rgba(120, 30, 80, 0.82);
  backdrop-filter: blur(4px);
}

#hint:empty { display: none; }

/* ---------- stick and buttons ---------- */

.zone { position: absolute; bottom: 0; left: 0; width: 40%; height: 50%; pointer-events: auto; touch-action: none; }

.stick {
  position: absolute;
  bottom: max(26px, calc(env(safe-area-inset-bottom) + 16px));
  left: max(26px, calc(env(safe-area-inset-left) + 16px));
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
  opacity: 0.7;
}

.stick.held { opacity: 1; }

.stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 143, 199, 0.95);
  pointer-events: none;
}

.stick span {
  position: absolute;
  top: -22px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.act {
  position: absolute;
  z-index: 2;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: #ff5fa2;
  color: #fff;
  font: inherit;
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 1.5px;
  pointer-events: auto;
  touch-action: manipulation;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(120, 20, 70, 0.45);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.act small { display: block; font-size: 10px; letter-spacing: 1px; margin-top: 2px; opacity: 0.95; }
.act:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(120, 20, 70, 0.45); }
.act.small { width: 80px; height: 80px; font-size: 26px; }

#openBtn {
  right: max(24px, calc(env(safe-area-inset-right) + 14px));
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
  animation: bounce 0.8s ease-in-out infinite;
}
@keyframes bounce { 50% { transform: translateY(-8px) scale(1.05); } }

#musicBtn { right: max(160px, calc(env(safe-area-inset-right) + 150px)); bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px)); background: #6fd3ff; color: #12405a; text-shadow: none; }
#musicBtn.on { background: #ffe066; color: #6a3b00; box-shadow: 0 0 0 5px rgba(255, 224, 102, 0.55), 0 6px 0 rgba(120, 20, 70, 0.45); }

/* ---------- the serving window ---------- */

#shop {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  background: #fff6fb;
  color: #5a1f45;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } }

#outside {
  position: relative;
  flex: 0 0 42%;
  min-height: 230px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: max(16px, env(safe-area-inset-top)) 24px 10px;
  background: linear-gradient(#8fd8ff, #c9f0ff 70%, #8fdc7f 70%);
  border-bottom: 14px solid #ff8fc7;
  overflow: hidden;
}

#who { text-align: center; }
#face { font-size: 130px; line-height: 1; animation: walkIn 0.4s ease-out; }
#face.happy { animation: hop 0.5s ease-out; }
#face.oops { animation: shake 0.4s ease-out; }
#name { margin-top: 4px; font-size: 18px; font-weight: 900; color: #5a1f45; background: rgba(255,255,255,0.85); border-radius: 999px; padding: 2px 14px; display: inline-block; }
@keyframes walkIn { from { transform: translateX(-160px); opacity: 0; } }
@keyframes hop { 40% { transform: translateY(-30px) scale(1.1); } }
@keyframes shake { 20% { transform: translateX(-10px); } 50% { transform: translateX(10px); } 80% { transform: translateX(-6px); } }

#bubble {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 520px;
  padding: 12px 20px 12px 12px;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 6px 0 rgba(90, 31, 69, 0.18);
}
#bubble::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 50%;
  margin-top: -14px;
  border: 14px solid transparent;
  border-right: 20px solid #fff;
  border-left: 0;
}
#want svg { width: 110px; height: 190px; display: block; }
#say { font-size: 22px; font-weight: 800; line-height: 1.3; }
#say .oops { color: #e0245e; }
#say .yum { color: #1c9a4c; }

#line { position: absolute; left: 16px; bottom: 10px; font-size: 15px; font-weight: 800; color: #24572a; background: rgba(255,255,255,0.8); padding: 4px 12px; border-radius: 999px; }
#closeBtn { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); background: rgba(90, 31, 69, 0.75); }
.arcade #closeBtn { top: max(12px, env(safe-area-inset-top)); }

#counter {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  min-height: 0;
  background: repeating-linear-gradient(90deg, #ffe3f1 0 40px, #fff 40px 80px);
}

#makeWrap { flex: 0 0 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #fff; border-radius: 22px; border: 3px dashed #ffb3d6; }
#make svg { width: 130px; height: 225px; display: block; }
#makeLab { font-size: 12px; font-weight: 800; letter-spacing: 2px; color: #c0628f; text-transform: uppercase; }

#bins { flex: 1; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; padding: 6px 8px; border-radius: 16px; background: rgba(255, 255, 255, 0.85); }
.row .lab { flex: 0 0 82px; font-size: 11px; font-weight: 900; letter-spacing: 2px; color: #c0628f; }
.row.nudge { animation: shake 0.4s; background: #fff1a8; }

.bin {
  width: 78px;
  height: 84px;
  padding: 2px 0 0;
  border-radius: 14px;
  border: 3px solid #ffd0e6;
  background: #fff;
  color: #5a1f45;
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.1;
  cursor: pointer;
  touch-action: manipulation;
}
.bin svg { width: 46px; height: 56px; display: block; margin: 0 auto 2px; pointer-events: none; }
.bin:active { transform: scale(0.94); }
.bin.on { border-color: #ff5fa2; background: #ffe6f2; }
.bin .new { display: block; color: #e0245e; font-size: 9px; }

#acts { flex: 0 0 130px; display: flex; flex-direction: column; gap: 10px; }
#acts button {
  flex: 1;
  border-radius: 22px;
  border: 3px solid #fff;
  font: inherit;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 0 rgba(90, 31, 69, 0.25);
}
#giveBtn { flex: 2 !important; background: #6ff09a; color: #0b3a1c; }
#trashBtn { background: #ffd0d0; color: #7a1f1f; }
#acts button:active { transform: translateY(3px); }

/* ---------- the menu card ---------- */

.card {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(64px, env(safe-area-inset-top)) 20px 28px;
  text-align: center;
  overflow-y: auto;
  background: radial-gradient(circle at 50% 30%, rgba(255, 170, 210, 0.95), rgba(120, 60, 200, 0.97));
}

.card > * { flex-shrink: 0; }
.card .top { margin-top: auto; }
.card .bottom { margin-bottom: auto; }

.card h1 {
  margin: 0;
  font-size: 68px;
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 5px 0 #ff3b8b, 0 10px 0 rgba(60, 10, 80, 0.45);
}

.card h2 { margin: 0 0 10px; font-size: 38px; font-weight: 900; }
.card .tag { margin: 14px 0 20px; font-size: 19px; font-weight: 700; }
.card .note { max-width: 540px; margin: 0 auto 18px; font-size: 16px; line-height: 1.6; }
.card .big { font-size: 64px; margin: 0 0 6px; }

.card .btn {
  min-width: 240px;
  margin: 6px;
  padding: 16px 28px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: #ffe066;
  color: #6a3b00;
  font: inherit;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(60, 10, 80, 0.4);
  touch-action: manipulation;
}

.card .btn.ghost { background: transparent; color: #fff; font-size: 15px; min-width: 0; box-shadow: none; padding: 10px 20px; }
.card .btn.blue { background: #7fe0ff; color: #0f3a52; }

.card .keys { list-style: none; margin: 18px 0 0; padding: 0; font-size: 14px; line-height: 2; }
.card .keys b { display: inline-block; min-width: 26px; padding: 0 7px; margin: 0 2px; border-radius: 6px; background: rgba(255, 255, 255, 0.2); }

.garage { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 620px; margin: 0 auto 18px; }
.garage button {
  width: 92px;
  padding: 10px 4px;
  border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}
.garage button .sw { display: block; width: 44px; height: 44px; margin: 0 auto 6px; border-radius: 50%; border: 3px solid #fff; }
.garage button.on { border-color: #ffe066; background: rgba(255, 224, 102, 0.3); }
.garage button:disabled { opacity: 0.45; cursor: default; }
.card .coins { font-size: 22px; font-weight: 900; color: #ffe066; margin-bottom: 14px; }

/* narrower screens (an iPad held tall) */
@media (max-width: 1000px) {
  #top { top: max(66px, calc(env(safe-area-inset-top) + 56px)); }
  .arcade #top { top: max(100px, calc(env(safe-area-inset-top) + 90px)); }
  #map { top: max(130px, calc(env(safe-area-inset-top) + 120px)); }
  .arcade #map { top: max(164px, calc(env(safe-area-inset-top) + 154px)); }
  #hint { bottom: max(170px, calc(env(safe-area-inset-bottom) + 160px)); max-width: calc(100% - 40px); }
  #outside { flex-basis: 36%; gap: 12px; }
  #face { font-size: 96px; }
  #say { font-size: 18px; }
  #want svg { width: 100px; height: 172px; }
  /* treat on the left, choices on the right (they scroll), big buttons along the bottom */
  #counter { display: grid; grid-template-columns: 120px 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  #make svg { width: 104px; height: 180px; }
  #bins { min-height: 0; }
  #acts { grid-column: 1 / -1; flex-direction: row; height: 84px; }
  #acts button { padding: 10px; }
  #giveBtn br, #trashBtn br { display: none; }
  .row .lab { flex-basis: 100%; }
}

@media (max-height: 560px), (max-width: 700px) {
  .card h1 { font-size: 44px; }
  .card .tag { font-size: 15px; margin: 8px 0 12px; }
  .card .btn { font-size: 18px; padding: 12px 22px; }
  #top b { font-size: 17px; }
  #top .box { min-width: 50px; padding: 2px 6px; }
  #top .box.wide { min-width: 96px; }
  #map { width: 110px; height: 110px; }
  .stick { width: 112px; height: 112px; }
  .act { width: 92px; height: 92px; font-size: 16px; }
  .act.small { width: 66px; height: 66px; font-size: 20px; }
  #musicBtn { right: max(126px, calc(env(safe-area-inset-right) + 116px)); }
  #msg { font-size: 34px; }
  #hint { font-size: 13px; }
  .bin { width: 64px; height: 72px; }
  .bin svg { width: 38px; height: 46px; }
  #face { font-size: 80px; }
  #want svg { width: 70px; height: 120px; }
}
