:root {
  --ink: #16263a;
  --panel: rgba(16, 38, 66, 0.7);
  --navy: #1d4f8c;
  --red: #e5383b;
  --blue: #2f6fe4;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a8d6f2; color: #fff; }
button { font: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: #e8f1f8;
  border: 1px solid #b9cde0;
  color: var(--ink);
}
.t { font-weight: 800; padding: 0 0.25em; border-radius: 0.3em; color: #fff; }
.t.red { background: var(--red); }
.t.blue { background: var(--blue); }

/* ---------- Scene ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop-label {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -50%);
  font-weight: 800; line-height: 1;
  white-space: nowrap;
  animation: label-in 0.3s cubic-bezier(.2, .9, .3, 1.6) both;
}
.pop-label.bonk {
  font-size: 5.5vh;
  color: #ffd23f;
  -webkit-text-stroke: 0.35vh #16263a;
  paint-order: stroke;
}
.pop-label.gulp { font-size: 6vh; color: #fff; -webkit-text-stroke: 0.35vh #16263a; paint-order: stroke; }
.pop-label.badge {
  width: 6.5vh; height: 6.5vh;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 4.4vh;
  color: #fff;
  border: 0.5vh solid #fff;
  box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.35);
}
.pop-label.badge.red { background: var(--red); }
.pop-label.badge.blue { background: var(--blue); }
@keyframes label-in { from { transform: translate(-50%, -50%) scale(0.2); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* ---------- Top: toolbar, message, scoreboard ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; gap: 2vw;
  padding: 2vh 2vw;
  z-index: 10;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#toolbar { display: flex; gap: 0.5vw; flex: 0 0 auto; width: 26vh; }
#toolbar button {
  width: 5.4vh; height: 5.4vh;
  border-radius: 1.4vh;
  border: none;
  background: var(--panel);
  font-size: 2.8vh;
  cursor: pointer;
  color: #fff;
  display: grid; place-items: center;
}
#toolbar button:hover { background: rgba(16, 38, 66, 0.9); }

#board { flex: 1; display: flex; justify-content: center; }
#task {
  text-align: center;
  font-weight: 800;
  line-height: 1.2;
  border-radius: 3vh;
  font-size: clamp(20px, 4vh, 58px);
  padding: 0.6vh 2.4vw;
  max-width: 60vw;
  background: var(--panel);
  text-shadow: 0 0.25vh 0 rgba(0, 0, 0, 0.3);
}
#task:empty { visibility: hidden; }
#task.pop { animation: pop 0.45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { from { transform: scale(0.85); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }

#scoreboard {
  flex: 0 0 auto; width: 26vh;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.8vh;
  pointer-events: none;
}
.team {
  border-radius: 2vh;
  padding: 0.6vh 1vh 0.8vh;
  text-align: center;
  box-shadow: 0 0.5vh 0 rgba(0, 0, 0, 0.25);
}
.team.red { background: var(--red); }
.team.blue { background: var(--blue); }
.team span { display: block; font-size: 2.3vh; font-weight: 700; line-height: 1; opacity: 0.9; }
.team b { display: block; font-size: 7vh; line-height: 1; }
/* One dot for each penguin still to throw */
.left { display: flex; justify-content: center; gap: 0.5vh; min-height: 1.4vh; }
.left i { width: 1.4vh; height: 1.4vh; border-radius: 50%; background: #fff; }
#round {
  grid-column: 1 / -1;
  margin: 0;
  text-align: center;
  font-size: 2.4vh; font-weight: 800;
  background: var(--panel);
  border-radius: 1.4vh;
}
#round:empty { display: none; }

/* ---------- Bottom: aiming help, Sweep! and Next round ---------- */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; align-items: flex-end;
  padding: 0 2vw 3vh;
  z-index: 10;
  pointer-events: none;
}
#controls > * { pointer-events: auto; }
/* Bottom left, clear of the penguin and the rings */
#aim-box {
  display: none;
  position: fixed; left: 2vw; bottom: 3vh;
  background: var(--panel);
  border-radius: 2.4vh;
  padding: 1vh 2vh 1.4vh;
  width: min(30vw, 46vh);
  pointer-events: none;
}
[data-phase='aim'] #aim-box { display: block; }
#hint { margin: 0 0 0.8vh; font-size: 2.8vh; font-weight: 700; color: #ffe08a; line-height: 1.25; }
#hint:empty { display: none; }
#power { height: 2.6vh; border-radius: 999px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
#power-fill {
  height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffe066, #ff9f1c 60%, #e5383b);
}

#sweep {
  display: none;
  position: fixed; right: 3vw; bottom: 4vh;
  border: none;
  border-radius: 999px;
  width: 34vh; height: 15vh;
  font-size: 7vh; font-weight: 800; line-height: 1;
  background: #ffd23f; color: #4a3300;
  box-shadow: 0 1vh 0 #c99a12;
  cursor: pointer;
  user-select: none;
}
[data-phase='slide'] #sweep { display: block; animation: wiggle 0.6s ease-in-out infinite alternate; }
#sweep.on { background: #fff06a; }
#sweep.hit { animation: hit 0.18s ease-out; }
@keyframes wiggle { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes hit { from { transform: scale(0.88); } to { transform: scale(1); } }

#go {
  border: none;
  border-radius: 1.6vh;
  height: 9vh; min-width: 30vh; padding: 0 4vh;
  font-size: 4.6vh; font-weight: 800; line-height: 1;
  background: #5fd068; color: #0e3a1a;
  box-shadow: 0 0.6vh 0 #2f8f3a;
  cursor: pointer;
}
#go:active { transform: translateY(0.4vh); box-shadow: none; }

/* ---------- Setup menu ---------- */
#setup {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(10, 30, 56, 0.45), rgba(6, 18, 34, 0.85));
  overflow: auto;
  padding: 3vh 2vw;
}
.panel {
  width: min(900px, 94vw);
  background: rgba(250, 253, 255, 0.97);
  color: var(--ink);
  border-radius: 28px;
  padding: 26px 34px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.logo { margin: 0; font-size: 50px; line-height: 1; font-weight: 800; color: var(--navy); letter-spacing: -0.5px; }
.tagline { margin: 8px 0 18px; font-size: 19px; line-height: 1.35; color: #3c5068; }
.panel h2 { margin: 0 0 8px; font-size: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: 18px; }
.cards button {
  border: 3px solid #d3e2ef;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.cards button:hover { transform: translateY(-2px); }
.cards button[aria-pressed='true'] { border-color: var(--navy); background: #eaf3fb; }
.cards b { display: block; font-size: 22px; line-height: 1.1; }
.cards span { display: block; font-size: 15px; color: #52667d; line-height: 1.3; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.check input { width: 20px; height: 20px; accent-color: var(--navy); }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.buttons button.primary {
  border: none;
  background: var(--navy); color: #fff;
  border-radius: 999px;
  font-size: 22px; font-weight: 800;
  padding: 12px 34px;
  box-shadow: 0 6px 0 #0f2f57;
  cursor: pointer;
}
.buttons button.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #0f2f57; }
#offline-status { margin: 10px 0 0; font-size: 15px; font-weight: 700; color: #2e7d4a; }
.help { margin-top: 16px; font-size: 15px; color: #3c5068; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.5; }
