:root {
  --ink: #1d2433;
  --paper: #ffffff;
  --accent: #ff5a5f;
  --gold: #ffcc33;
  --font: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #7ec3ff;
  font-family: var(--font);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game { display: block; width: 100vw; height: 100vh; }

#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6);
}
#size { font-size: 22px; }
#size b { font-size: 30px; }
#size .label, #avg { opacity: 0.7; font-size: 15px; }
#board { margin: 6px 0 0; padding-left: 22px; font-size: 14px; line-height: 1.4; }
#board li.me { font-weight: bold; color: var(--accent); }
#board li.human { font-weight: bold; }
#status { margin-top: 4px; font-size: 13px; opacity: 0.7; }

#room {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 16px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 6px 10px;
  font-size: 14px;
}
#room button {
  font: inherit;
  margin-left: 6px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--gold);
  padding: 2px 10px;
  cursor: pointer;
}

#tags { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 14px;
  font-weight: bold;
  color: var(--paper);
  -webkit-text-stroke: 1px var(--ink);
  paint-order: stroke fill;
  white-space: nowrap;
}

#popups { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  color: var(--paper);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  white-space: nowrap;
  animation: pop 0.9s ease-out forwards;
}
.popup.small { font-size: 18px; }
.popup.mid { font-size: 28px; }
.popup.big { font-size: 40px; color: var(--gold); }
.popup.mega { font-size: 56px; color: var(--accent); }
.popup.gain { font-size: 30px; color: #7dff8a; }
.popup.loss { font-size: 30px; color: #ff6b6b; }
.popup.hint { font-size: 16px; color: #ffe; -webkit-text-stroke: 1px var(--ink); }
@keyframes pop {
  0% { opacity: 0; scale: 0.4; }
  15% { opacity: 1; scale: 1.15; }
  30% { scale: 1; }
  100% { opacity: 0; translate: 0 -60px; }
}

#title {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(126, 195, 255, 0.35);
}
#title.hidden { display: none; }
.card {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 24px;
  padding: 24px 28px;
  max-width: min(420px, calc(100vw - 32px));
  text-align: center;
  box-shadow: 0 8px 0 var(--ink);
}
.card h1 { margin: 0 0 8px; font-size: 44px; letter-spacing: -1px; }
.card h1 span { color: var(--accent); }
.card p { margin: 8px 0; }
.card .keys { font-size: 13px; opacity: 0.7; }
#play {
  display: block;
  margin: 10px auto;
  font: inherit;
  font-size: 26px;
  font-weight: bold;
  padding: 10px 42px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
}
#play:active, #friends:active { translate: 0 4px; box-shadow: 0 1px 0 var(--ink); }
#friends {
  display: block;
  margin: 4px auto 0;
  font: inherit;
  font-size: 16px;
  font-weight: bold;
  padding: 6px 20px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}
#play:disabled, #friends:disabled { opacity: 0.6; cursor: default; }
#note { min-height: 1.2em; font-size: 14px; }

#touch { display: none; }
body.touch #touch { display: block; }
body.touch .desktop-only, body:not(.touch) .touch-only { display: none; }

#stick {
  position: fixed;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 3px solid rgba(29, 36, 51, 0.5);
  background: rgba(255, 255, 255, 0.25);
  display: none;
  pointer-events: none;
}
#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid var(--ink);
}
#jump-btn {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  background: rgba(255, 204, 51, 0.85);
  font: inherit;
  font-weight: bold;
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
}
#jump-btn.down { translate: 0 4px; box-shadow: 0 1px 0 var(--ink); }

/* Room key entry */
#join-form {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin: 14px 0 4px;
  font-size: 14px;
}
#join-form[hidden] { display: none; }
#key {
  width: 5.2em;
  font: inherit;
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
  padding: 4px 6px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  color: var(--ink);
  background: #f4f7fb;
  user-select: text;
  -webkit-user-select: text;
}
#key::placeholder { color: rgba(29, 36, 51, 0.25); }
#join {
  font: inherit;
  font-weight: bold;
  padding: 6px 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
}
#join:disabled { opacity: 0.4; cursor: default; }
#room b { font-size: 20px; letter-spacing: 0.12em; }

/* Fullscreen button (touch devices, when fullscreen was left) */
#fs {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  top: max(64px, calc(env(safe-area-inset-top) + 52px));
  width: 44px;
  height: 44px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  font-size: 22px;
  line-height: 1;
  color: var(--ink);
}
#fs[hidden] { display: none; }

/* Portrait phones: a gentle nudge, not a block */
#rotate { display: none; }
@media (orientation: portrait) {
  body.touch #rotate {
    display: block;
    position: fixed;
    left: 50%;
    bottom: max(140px, env(safe-area-inset-bottom));
    translate: -50% 0;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(29, 36, 51, 0.7);
    color: #fff;
    font-size: 13px;
    pointer-events: none;
    white-space: nowrap;
  }
}

/* Short screens (phones held sideways): keep the title card on screen */
.card { max-height: calc(100vh - 24px); overflow-y: auto; }
@media (max-height: 500px) {
  .card { padding: 12px 20px; }
  .card h1 { font-size: 32px; margin-bottom: 2px; }
  .card p { margin: 4px 0; }
  #play { font-size: 22px; padding: 6px 34px; margin: 6px auto; }
  #join-form { margin-top: 8px; }
  .card .keys { display: none; }
}

/* HUD and touch controls only while playing */
body:not(.playing) #hud,
body:not(.playing) #touch { display: none; }

/* Session records under the leaderboard */
#records { margin-top: 4px; font-size: 13px; line-height: 1.35; }

/* Centre-screen announcements */
#banner {
  position: fixed;
  left: 50%;
  top: 22%;
  translate: -50% 0;
  max-width: calc(100vw - 32px);
  text-align: center;
  font-size: clamp(20px, 4vw, 38px);
  font-weight: 900;
  color: var(--paper);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, scale 0.2s;
  scale: 0.8;
}
#banner.show { opacity: 1; scale: 1; }
#banner.rampage { color: var(--accent); animation: shake 0.12s linear 6; }
#banner.crown { color: var(--gold); }
@keyframes shake { 50% { translate: calc(-50% + 4px) 2px; } }

/* Inside a mushroom ring */
#ringwarn {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  translate: -50% 0;
  padding: 6px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-weight: bold;
  font-size: 15px;
  pointer-events: none;
  animation: ringpulse 0.8s ease-in-out infinite alternate;
}
#ringwarn[hidden] { display: none; }
@keyframes ringpulse { to { scale: 1.06; } }
