/* Egg Heist — the play surface: canvas, overlay screens, touch controls. */

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { background: #6FB7D8; touch-action: none; }

#stage { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* --- overlay screens ------------------------------------------------------ */
.screen {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 30%, rgba(124,203,236,.55), rgba(59,42,30,.72));
  z-index: 10;
  overflow-y: auto;
}
.screen[data-open] { display: flex; }
.screen__card {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--cream);
  border: var(--border) solid var(--ink);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 26px 26px 22px;
  text-align: center;
  animation: pop .22s cubic-bezier(.2,1.3,.4,1);
}
@keyframes pop { from { transform: scale(.94) translateY(10px); opacity: 0 } to { transform: none; opacity: 1 } }

.screen__title {
  font-family: var(--font-display);
  font-size: clamp(30px, 7vw, 52px);
  text-transform: uppercase;
  color: var(--gold-2);
  text-shadow: 2px 2px 0 var(--gold-3), -2px 0 0 var(--ink), 2px 0 0 var(--ink), 0 -2px 0 var(--ink), 0 2px 0 var(--ink);
  margin: 0 0 14px;
}

/* --- loading -------------------------------------------------------------- */
#loading .bar {
  width: 100%; height: 18px; margin: 18px 0 8px;
  background: var(--cream-2);
  border: 3px solid var(--ink); border-radius: 999px; overflow: hidden;
}
#loading .bar i {
  display: block; height: 100%; width: 0;
  background: repeating-linear-gradient(115deg, var(--gold-2) 0 12px, var(--gold-1) 12px 24px);
  transition: width .2s ease;
}

/* --- menu ----------------------------------------------------------------- */
.menu__actions { display: grid; gap: 12px; margin: 18px 0 4px; }
.menu__row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
/* One uniform row of pills rather than a mix of text links and a button:
   four equal cells on a wide card, two-by-two when it narrows. */
.menu__links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 3px dashed rgba(59,42,30,.22);
}
.menu__links .btn { width: 100%; }
/* Two columns at every width: four across cramps "Leaderboard" into its pill. */
.menu__links .btn { white-space: nowrap; }

.motd {
  background: var(--gold-1);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 700; font-size: 14px;
  margin-bottom: 14px;
}

/* --- counters (players / bots) -------------------------------------------- */
.counter { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.counter__btns { display: flex; gap: 6px; align-items: center; }
.counter__val { font-family: var(--font-ui); font-weight: 900; font-size: 24px; min-width: 2ch; text-align: center; }

/* --- lobby ---------------------------------------------------------------- */
.code {
  font-family: var(--font-display);
  font-size: clamp(38px, 11vw, 64px);
  letter-spacing: .18em;
  color: var(--barn-2);
  background: var(--cream-2);
  border: 4px dashed var(--ink);
  border-radius: 16px;
  padding: 10px 8px 8px 26px;
  margin: 6px 0 14px;
}
.players { display: grid; gap: 8px; margin: 14px 0; text-align: left; }
.players li {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 3px solid var(--ink); border-radius: 12px;
  padding: 8px 12px; font-weight: 700;
  list-style: none;
}
.players .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.players .tag { margin-left: auto; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.players .tag--ready { color: var(--grass-3); }

/* --- results -------------------------------------------------------------- */
.standings { display: grid; gap: 8px; margin: 16px 0; text-align: left; }
.standings li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 8px 12px;
  font-weight: 700; list-style: none;
}
.standings .rank { font-family: var(--font-ui); font-weight: 900; font-size: 17px; color: var(--ink-soft); width: 28px; }
.standings .stars { color: var(--gold-3); letter-spacing: 2px; }
.standings li[data-you] { background: var(--gold-1); }

/* --- top-right utility bar ------------------------------------------------ */
.utility {
  position: fixed; top: 10px; right: 10px; z-index: 8;
  display: flex; gap: 8px;
}
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 18px;
  background: rgba(255,246,224,.9);
  border: 3px solid var(--ink); border-radius: 12px;
  cursor: pointer; padding: 0;
}
.icon-btn:active { transform: translateY(2px); }

/* --- connection / toast --------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--ink); color: var(--cream);
  border-radius: 999px; padding: 10px 18px;
  font-weight: 700; font-size: 14px;
  z-index: 12; pointer-events: none;
  opacity: 0; transition: opacity .2s ease;
}
.toast[data-show] { opacity: 1; }

.netstat {
  position: fixed; left: 10px; top: 10px; z-index: 8;
  font-size: 11px; font-weight: 800; letter-spacing: .06em;
  color: rgba(255,246,224,.85);
  background: rgba(59,42,30,.45);
  border-radius: 8px; padding: 4px 8px;
  pointer-events: none;
}

/* --- chat ----------------------------------------------------------------- */
.chat { position: fixed; left: 10px; bottom: 10px; z-index: 9; width: min(320px, 46vw); }
.chat__log {
  max-height: 132px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
  font-size: 13px; margin-bottom: 6px;
}
.chat__log p {
  margin: 0; padding: 3px 8px;
  background: rgba(59,42,30,.5); color: var(--cream);
  border-radius: 8px; align-self: flex-start; max-width: 100%;
  word-break: break-word;
}
.chat__log b { color: var(--gold-1); }
.chat__input { display: none; }
.chat[data-typing] .chat__input { display: block; }
.chat__input input {
  width: 100%; font-size: 14px; padding: 7px 10px;
  border: 3px solid var(--ink); border-radius: 10px;
}

/* --- touch controls ------------------------------------------------------- */
.touch-controls { position: fixed; inset: 0; z-index: 7; pointer-events: none; }
.tc-stick {
  position: absolute; left: 20px; bottom: 20px;
  width: 128px; height: 128px; border-radius: 50%;
  background: rgba(255,246,224,.28);
  border: 4px solid rgba(59,42,30,.4);
  pointer-events: auto; touch-action: none;
  display: grid; place-items: center;
}
.tc-stick i {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,246,224,.9);
  border: 4px solid var(--ink);
  display: block;
}
.tc-buttons { position: absolute; right: 20px; bottom: 22px; display: grid; gap: 12px; justify-items: end; pointer-events: none; }
.tc-btn {
  pointer-events: auto; touch-action: none;
  font-family: var(--font-display); font-weight: 800; font-size: 15px;
  border: 4px solid var(--ink); border-radius: 50%;
  width: 84px; height: 84px;
  color: var(--ink);
}
.tc-dash { background: var(--gold-2); box-shadow: 0 5px 0 var(--gold-3); width: 100px; height: 100px; font-size: 17px; }
.tc-flap { background: var(--grass-1); box-shadow: 0 5px 0 var(--grass-3); }
.tc-btn:active { transform: translateY(4px); box-shadow: none; }

@media (min-width: 820px) { .tc-stick, .tc-buttons { display: none; } }

/* --- settings ------------------------------------------------------------- */
.settings { display: grid; gap: 14px; text-align: left; margin: 8px 0 4px; }
.settings label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.settings input[type=range] { width: 100%; accent-color: var(--barn-1); }
.keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; text-align: left; }
.keys div { background: #fff; border: 3px solid var(--ink); border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 700; }
.keys kbd {
  display: inline-block; background: var(--cream-2); border: 2px solid var(--ink);
  border-radius: 5px; padding: 0 5px; font-family: inherit; font-size: 12px;
}

/* On a wide screen, park the menu to the left so the attract-mode match playing
   behind it stays visible instead of hiding under the card. */
@media (min-width: 1040px) {
  #menu, #local { justify-content: flex-start; padding-left: 5vw; }
  #menu .screen__card, #local .screen__card { width: min(520px, 46vw); }
  #menu { background: linear-gradient(100deg, rgba(59,42,30,.78) 0%, rgba(59,42,30,.55) 44%, rgba(59,42,30,.12) 78%); }
}

/* The 3D renderer draws the world into #scene (WebGL) and the HUD into #hud
   (2D) stacked on top, so HUD text stays crisp and is never occluded by
   geometry. The 2D renderer hides #hud and draws everything into #scene. */
#hud {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block; pointer-events: none;
  z-index: 2;
}

/* Capture mode (?capture=1): a clean plate for social cards — no chrome at all. */
body.is-capture .utility,
body.is-capture .chat,
body.is-capture .netstat,
body.is-capture .toast,
body.is-capture .touch-controls { display: none !important; }
