:root {
  --pink: #ff9ec4;
  --pink-deep: #ff6fa5;
  --mint: #a8e6cf;
  --cream: #fff6ef;
  --sky1: #ffe3f1;
  --sky2: #d9f2ff;
  --ink: #6b4a5b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif;
  color: var(--ink);
  background: #ffdff0;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
#app { position: fixed; inset: 0; }
canvas { display: block; touch-action: none; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  gap: 18px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255,255,255,.35), transparent 60%),
    linear-gradient(160deg, var(--sky1), var(--sky2));
  z-index: 20;
  text-align: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/* auto margins center the content vertically when it fits, but let it
   scroll from the top when it's taller than the screen (mobile) */
.overlay > *:first-child { margin-top: auto; }
.overlay > *:last-child  { margin-bottom: auto; }
.hidden { display: none !important; }

.logo {
  font-family: 'Baloo 2', cursive;
  font-weight: 800;
  font-size: clamp(38px, 8vw, 82px);
  line-height: .95;
  color: #fff;
  text-shadow:
    0 4px 0 var(--pink-deep),
    0 8px 0 rgba(255,111,165,.45),
    0 14px 24px rgba(255,111,165,.35);
  letter-spacing: 1px;
  transform: rotate(-2deg);
}
.logo small {
  display: block;
  font-size: .34em;
  color: var(--pink-deep);
  text-shadow: none;
  font-weight: 700;
  letter-spacing: 4px;
  margin-top: 6px;
}
.subtitle { font-size: clamp(15px, 2.6vw, 20px); color: var(--ink); opacity: .8; max-width: 520px; }

.card {
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(6px);
  border: 3px solid #fff;
  border-radius: 28px;
  padding: 22px 26px;
  box-shadow: 0 16px 40px rgba(255,111,165,.28);
}

.btn {
  font-family: 'Baloo 2', cursive;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(180deg, #ffa9cd, var(--pink-deep));
  border: none;
  border-radius: 999px;
  padding: 14px 46px;
  cursor: pointer;
  box-shadow: 0 6px 0 #e05089, 0 10px 22px rgba(224,80,137,.4);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
  /* also render nicely as an <a> link */
  display: inline-block;
  text-decoration: none;
  text-align: center;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-2px); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #e05089, 0 5px 12px rgba(224,80,137,.4); }
.btn.secondary {
  background: linear-gradient(180deg, #d7f3ff, #8fd6f5);
  color: #3f6b7d;
  box-shadow: 0 6px 0 #63b6d8, 0 10px 22px rgba(99,182,216,.35);
}
.btn.secondary:active { box-shadow: 0 2px 0 #63b6d8; }
.btn.disabled { opacity: .5; pointer-events: none; }

.diff-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.diff {
  font-family: 'Baloo 2', cursive; font-weight: 700; font-size: 17px;
  padding: 12px 20px; border-radius: 18px; cursor: pointer;
  background: #fff; color: var(--ink);
  border: 3px solid #ffd3e6;
  transition: all .12s ease;
  min-width: 120px;
}
.diff .emo { font-size: 24px; display: block; margin-bottom: 2px; }
.diff .sub { font-size: 12px; font-weight: 500; opacity: .65; display: block; }
.diff.active { border-color: var(--pink-deep); background: #fff0f6; box-shadow: 0 8px 18px rgba(255,111,165,.3); transform: translateY(-2px); }

.hs-line { font-size: 16px; font-weight: 600; color: var(--ink); }
.hs-line b { color: var(--pink-deep); font-size: 20px; }

.row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; align-items: center; }

.howto { font-size: 14px; opacity: .75; max-width: 460px; line-height: 1.5; }
.howto b { color: var(--pink-deep); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hud-pill {
  position: absolute; top: 18px;
  background: rgba(255,255,255,.82);
  border: 3px solid #fff;
  border-radius: 20px;
  padding: 8px 18px;
  font-weight: 700; font-family: 'Baloo 2', cursive;
  box-shadow: 0 8px 20px rgba(255,111,165,.25);
  font-size: 18px;
}
#hudScore { left: 18px; color: var(--pink-deep); }
#hudScore .lbl, #hudCount .lbl { display:block; font-size: 11px; font-weight:600; color: var(--ink); opacity:.6; letter-spacing:1px; }
#hudCount { right: 18px; color: #4a8fb0; text-align: right; }
#hudDiff { left: 50%; transform: translateX(-50%); color: var(--ink); font-size: 15px; opacity:.85; }

#muteBtn {
  position: absolute; bottom: 16px; right: 16px;
  pointer-events: auto;
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid #fff; background: rgba(255,255,255,.82);
  font-size: 20px; cursor: pointer;
  box-shadow: 0 6px 16px rgba(255,111,165,.25);
}

#hint {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.8); border: 2px solid #fff;
  border-radius: 16px; padding: 8px 18px; font-size: 14px; font-weight:600;
  color: var(--ink); opacity: .9;
  box-shadow: 0 6px 16px rgba(255,111,165,.2);
  transition: opacity .4s;
}

/* lips cursor */
#reticle {
  position: fixed; z-index: 15; pointer-events: none;
  font-size: 34px; transform: translate(-50%, -50%);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.2));
  transition: transform .05s;
  will-change: transform;
}

/* floating popups */
.popup {
  position: fixed; z-index: 16; pointer-events: none;
  font-family: 'Baloo 2', cursive; font-weight: 800;
  transform: translate(-50%, -50%);
  text-shadow: 0 2px 0 rgba(0,0,0,.12);
  animation: floatUp 1s ease-out forwards;
  white-space: nowrap;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.6); }
  20% { opacity: 1; transform: translate(-50%,-70%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%,-160%) scale(1); }
}

.badge-new {
  display:inline-block; background: var(--pink-deep); color:#fff;
  padding: 4px 14px; border-radius: 999px; font-weight:700; font-size:14px;
  transform: rotate(-4deg); box-shadow: 0 4px 10px rgba(224,80,137,.4);
  animation: pop .5s ease;
}
@keyframes pop { 0%{transform:scale(0) rotate(-4deg);} 70%{transform:scale(1.25) rotate(-4deg);} 100%{transform:scale(1) rotate(-4deg);} }

.fade-in { animation: fadeIn .4s ease; }
@keyframes fadeIn { from{opacity:0; transform: translateY(8px);} to{opacity:1; transform:none;} }

#loading {
  position: fixed; inset: 0; display:flex; align-items:center; justify-content:center;
  background: linear-gradient(160deg, var(--sky1), var(--sky2)); z-index: 40;
  font-family:'Baloo 2',cursive; font-weight:700; font-size:22px; color: var(--pink-deep);
}

/* ---------- Game mode picker ---------- */
.mode-row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.mode-card {
  background: rgba(255,255,255,.72);
  border: 3px solid #ffd3e6; border-radius: 24px;
  padding: 16px 20px; width: 210px; cursor: pointer;
  transition: all .12s ease;
  box-shadow: 0 10px 24px rgba(255,111,165,.18);
}
.mode-card:hover { transform: translateY(-2px); }
.mode-card.active { border-color: var(--pink-deep); background: #fff0f6; box-shadow: 0 12px 26px rgba(255,111,165,.32); transform: translateY(-2px); }
.mode-card .mode-emo { font-size: 40px; line-height: 1; }
.mode-card .mode-name { font-family: 'Baloo 2', cursive; font-weight: 800; font-size: 20px; margin: 6px 0 4px; color: var(--pink-deep); }
.mode-card .mode-desc { font-size: 13px; opacity: .7; line-height: 1.35; }
.mode-card.disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Warehouse HUD ---------- */
#hudWh { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#whCount { left: 18px; color: #4a8fb0; }
#whTimer { right: 18px; text-align: right; color: #a07ab8; }
#whDest { left: 50%; transform: translateX(-50%); color: var(--pink-deep); text-align: center; }
#whCount .lbl, #whTimer .lbl, #whDest .lbl { display:block; font-size: 11px; font-weight:600; color: var(--ink); opacity:.6; letter-spacing:1px; }
#whCross {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: 24px; color: rgba(107,74,91,.75); text-shadow: 0 0 4px rgba(255,255,255,.8);
}
#whMute {
  position: absolute; bottom: calc(16px + env(safe-area-inset-bottom)); right: calc(16px + env(safe-area-inset-right));
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid #fff; background: rgba(255,255,255,.82);
  font-size: 20px; cursor: pointer; box-shadow: 0 6px 16px rgba(255,111,165,.25);
}
#whHint {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.8); border: 2px solid #fff;
  border-radius: 16px; padding: 8px 18px; font-size: 14px; font-weight: 600;
  color: var(--ink); opacity: .95; box-shadow: 0 6px 16px rgba(255,111,165,.2);
  transition: opacity .4s; max-width: 90vw; text-align: center;
}
#whPause {
  position: absolute; bottom: calc(16px + env(safe-area-inset-bottom));
  right: calc(72px + env(safe-area-inset-right));
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid #fff; background: rgba(255,255,255,.82);
  font-size: 20px; cursor: pointer; box-shadow: 0 6px 16px rgba(255,111,165,.25);
}

/* Touch walk stick (bottom-left) and grab/drop button (bottom-right) —
   hidden on fine pointers, revealed for coarse (touch) pointers below. */
#whStick {
  position: absolute; display: none; touch-action: none; pointer-events: auto;
  left: calc(22px + env(safe-area-inset-left)); bottom: calc(26px + env(safe-area-inset-bottom));
  width: 126px; height: 126px; border-radius: 50%;
  background: rgba(255,255,255,.26); border: 3px solid rgba(255,255,255,.7);
  box-shadow: 0 6px 18px rgba(255,111,165,.25);
}
#whStickKnob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,.9); border: 3px solid #fff;
  box-shadow: 0 4px 12px rgba(255,111,165,.35);
}
#whAction {
  position: absolute; display: none; pointer-events: auto;
  right: calc(16px + env(safe-area-inset-right)); bottom: calc(78px + env(safe-area-inset-bottom));
  min-width: 104px; padding: 14px 18px; border-radius: 22px;
  border: 3px solid #fff; background: linear-gradient(180deg, #ffa9cd, var(--pink-deep));
  color: #fff; font-family: 'Baloo 2', cursive; font-weight: 700; font-size: 17px;
  box-shadow: 0 6px 16px rgba(224,80,137,.4); cursor: pointer;
}
#whAction:active { transform: translateY(3px); }

@media (pointer: coarse) {
  #whStick, #whAction { display: block !important; }
}

/* ---------- Mobile / small screens ---------- */
.hud-pill { top: calc(18px + env(safe-area-inset-top)); }
#muteBtn { bottom: calc(16px + env(safe-area-inset-bottom)); right: calc(16px + env(safe-area-inset-right)); }

@media (max-width: 640px) {
  .overlay { gap: 12px; padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom)); }
  .subtitle, .howto { max-width: 100%; }
  .card { padding: 16px 18px; border-radius: 22px; width: 100%; max-width: 420px; }
  .diff-row { gap: 8px; }
  .diff { min-width: 86px; padding: 10px 12px; font-size: 15px; }
  .diff .emo { font-size: 21px; }
  .btn { font-size: 20px; padding: 13px 40px; }

  .hud-pill { font-size: 14px; padding: 6px 12px; }
  #hudScore { left: 10px; }
  #hudCount { right: 10px; }
  #hudDiff { font-size: 12px; padding: 5px 10px; }
  #hint { font-size: 12px; padding: 7px 14px; bottom: calc(16px + env(safe-area-inset-bottom)); max-width: 82vw; }
  #muteBtn { width: 42px; height: 42px; font-size: 18px; }
}

/* Coarse pointers (touch): the lips cursor follows nothing useful */
@media (pointer: coarse) {
  #reticle { display: none !important; }
}
