* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: "Trebuchet MS", "Comic Sans MS", system-ui, sans-serif;
  background: #1a2a1a;
  color: #fff;
  overscroll-behavior: none;
  position: fixed; inset: 0;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

input { -webkit-user-select: text; user-select: text; }

#game-canvas { position: fixed; inset: 0; display: block; touch-action: none; }

/* ---------- screens & panels ---------- */

.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 30, 18, 0.75);
  backdrop-filter: blur(3px);
}
.hidden { display: none !important; }

.panel {
  background: linear-gradient(160deg, #4a2c3a, #2d1b25);
  border: 4px solid #ff9ec4;
  border-radius: 24px;
  padding: 28px 36px;
  max-width: 620px; width: 92%;
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 12px 60px rgba(0,0,0,0.6);
  text-align: center;
}
.panel.wide { max-width: 860px; }

.title {
  font-size: 52px; letter-spacing: 2px;
  text-shadow: 3px 3px 0 #b54a7a, 6px 6px 0 rgba(0,0,0,0.4);
  margin-bottom: 4px;
}
.tagline { color: #ffb8d4; margin-bottom: 22px; font-style: italic; }

h2 { margin-bottom: 12px; }
h3 { margin-bottom: 10px; color: #ffb8d4; }

input {
  background: #1f1218; border: 2px solid #ff9ec4; border-radius: 10px;
  color: #fff; font-size: 17px; padding: 10px 14px; width: 100%;
  margin-bottom: 10px; outline: none; text-align: center;
}
input:focus { border-color: #ffd166; }
.code-input { width: 110px; text-transform: uppercase; letter-spacing: 4px; }

button {
  background: linear-gradient(180deg, #ff7eb3, #e3578f);
  border: none; border-radius: 12px; color: #fff;
  font-size: 16px; font-weight: bold; font-family: inherit;
  padding: 10px 20px; cursor: pointer;
  box-shadow: 0 4px 0 #a13463;
  transition: transform 0.05s, box-shadow 0.05s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 #a13463; }
button:disabled { filter: grayscale(0.8); cursor: not-allowed; opacity: 0.6; }
button.big { font-size: 20px; padding: 14px 28px; }
button.subtle { background: #5a3a4a; box-shadow: 0 3px 0 #3a2430; font-size: 14px; }
button.gold { background: linear-gradient(180deg, #ffd166, #e0a82e); box-shadow: 0 4px 0 #9c7113; color: #3a2a00; }

.field-row { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 8px; }
.field-row.center { margin-top: 18px; }
.menu-columns, .shop-columns { display: flex; gap: 24px; margin-top: 10px; text-align: left; }
.menu-col, .shop-col { flex: 1; min-width: 0; }

.room-list {
  background: rgba(0,0,0,0.3); border-radius: 10px;
  min-height: 90px; max-height: 160px; overflow-y: auto;
  padding: 8px; margin-bottom: 8px;
}
.room-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; border-radius: 8px; margin-bottom: 4px;
  background: rgba(255,158,196,0.12);
}
.room-row button { font-size: 13px; padding: 5px 12px; }

.muted { color: #b89aa8; font-size: 14px; }
.error { color: #ff6b6b; min-height: 20px; margin-top: 10px; }

.room-code-badge {
  background: #ffd166; color: #3a2a00; font-weight: bold;
  letter-spacing: 4px; padding: 3px 12px; border-radius: 8px; font-size: 20px;
}

.player-list { list-style: none; margin: 16px 0; }
.player-list li {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  font-size: 18px; padding: 6px;
}
.pig-dot { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 2px solid #fff; }
.host-tag { color: #ffd166; font-size: 13px; }

.controls-help {
  background: rgba(0,0,0,0.3); border-radius: 10px; padding: 12px;
  font-size: 14px; color: #e8c8d8; line-height: 1.7; margin-bottom: 8px;
}

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }

#hud-top {
  position: absolute; top: 14px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 24px; align-items: center;
  font-size: 22px; font-weight: bold; text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
}
#hud-timer { font-size: 30px; color: #ffd166; }
#hud-boost { font-size: 16px; color: #9effa0; }

#hud-bottom {
  position: absolute; bottom: calc(16px + env(safe-area-inset-bottom)); left: 0; right: 0;
  display: flex; justify-content: center; gap: 18px; align-items: center;
  font-size: 22px; font-weight: bold; text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
}
#hud-hp-wrap {
  position: relative; width: 260px; height: 28px;
  background: rgba(0,0,0,0.55); border: 2px solid #fff; border-radius: 14px; overflow: hidden;
}
#hud-hp-bar {
  height: 100%; width: 100%; border-radius: 10px;
  background: linear-gradient(90deg, #6bff7a, #2ecc40);
  transition: width 0.15s;
}
#hud-hp-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 15px; text-shadow: 1px 1px 2px #000;
}
#hud-coins { color: #ffd166; }
#hud-score { color: #9ecbff; }

#hud-scoreboard {
  position: absolute; top: 14px; right: 14px;
  background: rgba(0,0,0,0.45); border-radius: 10px; padding: 10px 14px;
  font-size: 14px; line-height: 1.7; min-width: 170px;
}
#hud-scoreboard .sb-row { display: flex; align-items: center; gap: 8px; }
#hud-scoreboard .sb-row.dead { opacity: 0.45; text-decoration: line-through; }
#hud-scoreboard .sb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }

#hud-dead {
  position: absolute; top: 38%; left: 0; right: 0; text-align: center;
  font-size: 34px; font-weight: bold; color: #ff8a8a;
  text-shadow: 3px 3px 0 rgba(0,0,0,0.7);
}

#hud-toast {
  position: absolute; bottom: 70px; left: 0; right: 0; text-align: center;
  font-size: 18px; font-weight: bold; color: #ffd166;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.7);
  opacity: 0; transition: opacity 0.3s;
}
#hud-toast.show { opacity: 1; }

/* ---------- standings ---------- */

.standings { margin: 12px auto 16px; max-width: 480px; }
.standing-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.3); border-radius: 10px;
  padding: 8px 14px; margin-bottom: 6px; font-size: 17px;
}
.standing-row.first { background: rgba(255,209,102,0.25); border: 1px solid #ffd166; }
.standing-row .s-name { flex: 1; text-align: left; }
.standing-row .s-stat { color: #b89aa8; font-size: 14px; }

/* ---------- shop & casino ---------- */

#shop-banner { color: #ffd166; }

.shop-item {
  display: flex; align-items: center; gap: 12px;
  background: rgba(0,0,0,0.3); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 8px;
}
.shop-item .si-icon { font-size: 28px; }
.shop-item .si-body { flex: 1; }
.shop-item .si-name { font-weight: bold; }
.shop-item .si-desc { font-size: 13px; color: #b89aa8; }
.shop-item .si-level { font-size: 13px; color: #ffd166; letter-spacing: 2px; }
.shop-item button { white-space: nowrap; font-size: 14px; }

.shop-col.casino { text-align: center; }

#wheel-wrap { position: relative; width: 220px; height: 240px; margin: 0 auto 10px; }
#wheel-pointer {
  position: absolute; top: -4px; left: 50%; transform: translateX(-50%);
  font-size: 26px; color: #ffd166; z-index: 2; text-shadow: 2px 2px 2px #000;
}
#wheel {
  position: absolute; top: 18px; left: 10px;
  width: 200px; height: 200px; border-radius: 50%;
  border: 6px solid #ffd166;
  box-shadow: 0 0 30px rgba(255,209,102,0.35), inset 0 0 20px rgba(0,0,0,0.5);
  transition: transform 3s cubic-bezier(0.15, 0.9, 0.25, 1);
}
.wheel-label {
  position: absolute; left: 50%; top: 50%;
  font-size: 18px; transform-origin: 0 0;
}

.casino-result { min-height: 24px; font-weight: bold; color: #ffd166; margin-top: 6px; }
.pending-boost { min-height: 22px; color: #9effa0; font-size: 14px; }
.coin-count { font-size: 22px; font-weight: bold; color: #ffd166; }

/* ---------- touch sticks ---------- */

.stick {
  position: absolute; width: 120px; height: 120px;
  margin: -60px 0 0 -60px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.35);
  pointer-events: none;
}
.stick-nub {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 158, 196, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.7);
}
.stick.aim .stick-nub { background: rgba(160, 110, 60, 0.65); }

@media (max-width: 700px) {
  .menu-columns, .shop-columns { flex-direction: column; }
  .title { font-size: 36px; }
  .panel { padding: 18px 16px; border-radius: 18px; }
  button.big { font-size: 18px; padding: 14px 22px; }
  #hud-scoreboard { font-size: 11px; padding: 6px 8px; min-width: 120px; top: calc(8px + env(safe-area-inset-top)); right: 8px; }
  #hud-top { top: calc(8px + env(safe-area-inset-top)); font-size: 16px; gap: 14px; }
  #hud-timer { font-size: 22px; }
  #hud-hp-wrap { width: 170px; height: 24px; }
  #hud-bottom { font-size: 17px; gap: 12px; }
  #hud-dead { font-size: 24px; }
}

/* Cramped landscape phones: tuck the panels in. */
@media (max-height: 480px) {
  .panel { max-height: 96vh; padding: 12px 18px; }
  .title { font-size: 30px; margin-bottom: 0; }
  .tagline { margin-bottom: 8px; }
}
