* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fd3ff;
  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;
}

/* the canvas takes every finger itself: no scrolling, no zooming */
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(30, 20, 60, 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.08);
}

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

#gooWrap {
  position: absolute;
  top: max(72px, calc(env(safe-area-inset-top) + 62px));
  left: 50%;
  transform: translateX(-50%);
  width: 180px;
  height: 14px;
  border-radius: 999px;
  background: rgba(30, 20, 60, 0.6);
  overflow: hidden;
}

#goo { height: 100%; width: 0%; background: linear-gradient(90deg, #8ff06f, #3bb83b); transition: width 0.15s; }
#gooWrap span { position: absolute; inset: 0; text-align: center; font-size: 9px; line-height: 14px; letter-spacing: 3px; font-weight: 800; opacity: 0.85; }

.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(30, 20, 60, 0.6);
  color: #fff;
  font-size: 12px;
  letter-spacing: 2px;
  padding: 8px 14px;
  min-height: 44px;
  backdrop-filter: blur(4px);
}

.pill.go { background: #6ff09a; color: #0b3a1c; border-color: #fff; font-size: 15px; }

#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: #2a1b55; }

#readyBtn {
  position: absolute;
  top: max(94px, calc(env(safe-area-inset-top) + 84px));
  left: 50%;
  transform: translateX(-50%);
}

#buildBar {
  position: absolute;
  top: max(146px, calc(env(safe-area-inset-top) + 136px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

#pieces, #colors {
  display: flex;
  gap: 5px;
  padding: 5px;
  border-radius: 16px;
  background: rgba(30, 20, 60, 0.75);
  backdrop-filter: blur(4px);
}

#pieces button {
  width: 62px;
  height: 62px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
}

#pieces button small { display: block; font-size: 9px; letter-spacing: 1px; margin-top: 3px; font-weight: 700; }
#pieces button .cost { color: #ffe066; }
#pieces button.on { border-color: #ffe066; background: rgba(255, 224, 102, 0.25); }

#colors button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
}

#colors button.on { border-color: #fff; transform: scale(1.15); }

/* what the rivals say, and other news: just above the hint */
#toasts {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 62px));
  width: max-content;
  max-width: calc(100% - 440px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

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

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

#msg {
  position: absolute;
  top: 36%;
  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(60, 20, 90, 0.6), 0 0 24px rgba(0, 0, 0, 0.35);
}

#msg small { display: block; font-size: 19px; letter-spacing: 1px; margin-top: 4px; }
#msg.gold { color: #ffe066; }
#msg.bad { color: #9dff7a; }
#msg.boss { color: #6ff5e8; }

#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: 15px;
  font-weight: 700;
  border-radius: 18px;
  background: rgba(30, 20, 60, 0.8);
  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.55);
  background: rgba(255, 255, 255, 0.15);
  pointer-events: none;
  opacity: 0.65;
}

.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, 224, 102, 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: 116px;
  height: 116px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: #ff5fa2;
  color: #fff;
  font: inherit;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 1.5px;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(60, 20, 90, 0.45);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.act small { display: block; font-size: 9px; letter-spacing: 1px; margin-top: 2px; opacity: 0.9; }
.act:active, .act.down { transform: translateY(3px); box-shadow: 0 3px 0 rgba(60, 20, 90, 0.45); }

#splatBtn { right: max(24px, calc(env(safe-area-inset-right) + 14px)); bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px)); }

.act.small { width: 80px; height: 80px; font-size: 13px; }

#buildBtn { right: max(156px, calc(env(safe-area-inset-right) + 146px)); bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px)); background: #ffb02e; color: #4a2a00; text-shadow: none; }
#buildBtn.on { background: #ffe066; box-shadow: 0 0 0 4px rgba(255, 224, 102, 0.5), 0 6px 0 rgba(60, 20, 90, 0.45); }
#actBtn { right: max(40px, calc(env(safe-area-inset-right) + 30px)); bottom: max(160px, calc(env(safe-area-inset-bottom) + 150px)); background: #3bb8ff; }

/* ---------- 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, 120, 190, 0.92), rgba(70, 40, 150, 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 #ff3b6b, 0 10px 0 rgba(40, 10, 80, 0.5);
}

.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: 520px; margin: 0 auto 18px; font-size: 15px; line-height: 1.6; }
.card .big { font-size: 48px; margin: 0 0 6px; letter-spacing: 6px; }

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

.card .btn.ghost { background: transparent; color: #fff; font-size: 15px; min-width: 0; box-shadow: none; padding: 10px 20px; }
.card .btn.danger { background: #ff8a80; color: #4a0a0a; }

.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); }

/* narrower screens (an iPad held tall): the score bar drops below PAUSE and SOUND */
@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)); }
  #gooWrap { top: max(128px, calc(env(safe-area-inset-top) + 118px)); }
  .arcade #gooWrap { top: max(162px, calc(env(safe-area-inset-top) + 152px)); }
  #readyBtn { top: max(150px, calc(env(safe-area-inset-top) + 140px)); }
  .arcade #readyBtn { top: max(184px, calc(env(safe-area-inset-top) + 174px)); }
  #buildBar { top: max(202px, calc(env(safe-area-inset-top) + 192px)); }
  .arcade #buildBar { top: max(236px, calc(env(safe-area-inset-top) + 226px)); }
  #toasts { bottom: max(250px, calc(env(safe-area-inset-bottom) + 240px)); max-width: calc(100% - 40px); }
  #hint { bottom: max(190px, calc(env(safe-area-inset-bottom) + 180px)); max-width: calc(100% - 40px); }
}

@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; }
  #pieces button { width: 48px; height: 52px; font-size: 19px; }
  #colors button { width: 28px; height: 28px; }
  .stick { width: 112px; height: 112px; }
  .act { width: 92px; height: 92px; font-size: 15px; }
  .act.small { width: 66px; height: 66px; font-size: 11px; }
  #buildBtn { right: max(124px, calc(env(safe-area-inset-right) + 114px)); }
  #actBtn { bottom: max(130px, calc(env(safe-area-inset-bottom) + 120px)); }
  #msg { font-size: 34px; }
  #hint { font-size: 12px; }
}
