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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #3a2a1a;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ── Back to Lobby Button ─────────────────────────── */
.btn-back {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 5;
  width: 100px;
  height: 42px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: transparent;
  font-size: 0;
  cursor: pointer;
}
.btn-back.hidden { display: none; }

/* ── Lobby ───────────────────────────────────────── */
#lobby {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #3a2a1a 0%, #2a1510 50%, #4a2a2a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#lobby.hidden {
  display: none;
}

.lobby-inner {
  text-align: center;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
}

.lobby-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-bottom: 0.5rem;
}

.lobby-logo {
  width: 90px;
  height: 90px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
  border-radius: 16px;
  flex-shrink: 0;
}

.lobby-inner h1 {
  font-family: 'Fredoka One', cursive;
  font-size: 2.6rem;
  color: #ffd700;
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
  text-align: left;
  line-height: 1.1;
}

.lobby-subtitle {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  color: #b88a5a;
  margin-bottom: 2rem;
  letter-spacing: 0.15em;
}

.lobby-inner button {
  display: block;
  width: 100%;
  padding: 1rem;
  margin: 0.5rem 0;
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  border: 2px solid #8a6a3a;
  border-radius: 12px;
  background: rgba(255,215,0,0.08);
  color: #ddb866;
  cursor: pointer;
  transition: all 0.2s;
}

.lobby-inner button:hover,
.lobby-inner button:active {
  border-color: #ffd700;
  color: #ffd700;
  background: rgba(255,215,0,0.15);
}

.btn-start {
  background: rgba(255,215,0,0.2) !important;
  border-color: #ffd700 !important;
  color: #ffd700 !important;
  margin-top: 0.8rem !important;
}

/* ── Mode Toggle ──────────────────────────────────── */
.mode-toggle {
  display: flex;
  gap: 0;
  margin: 0.5rem 0;
  border: 2px solid #8a6a3a;
  border-radius: 12px;
  overflow: hidden;
}
.mode-toggle-btn {
  flex: 1;
  border: none !important;
  border-radius: 0 !important;
  margin: 0 !important;
  padding: 1rem 0.5rem !important;
  background: transparent !important;
  color: #8a6a3a !important;
  font-size: 1.3rem !important;
  transition: all 0.2s;
}
.mode-toggle-btn + .mode-toggle-btn {
  border-left: 2px solid #8a6a3a !important;
}
.mode-toggle-btn.active {
  background: rgba(255,215,0,0.2) !important;
  color: #ffd700 !important;
}
.mode-toggle-btn:hover:not(.active) {
  color: #ddb866 !important;
}

.lobby-divider {
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  color: #7a5a3a;
  margin: 1.2rem 0 0.6rem;
}

.lobby-status {
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  color: #b88a5a;
  margin-top: 0.8rem;
  min-height: 1.6em;
}

/* ── Name Input ───────────────────────────────────── */
.name-setup {
  margin-top: 0.5rem;
}
.name-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.name-row .name-label {
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  width: 2rem;
  text-align: center;
  flex-shrink: 0;
}
.name-row input {
  flex: 1;
  padding: 0.7rem 0.8rem;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  border: 2px solid #8a6a3a;
  border-radius: 8px;
  background: rgba(0,0,0,0.3);
  color: #ffd700;
  outline: none;
}
.name-row input:focus {
  border-color: #ffd700;
}
.name-row input::placeholder {
  color: #6a4a2a;
}

/* ── Player Count ─────────────────────────────────── */
.local-setup {
  margin-top: 0.5rem;
}

.player-count-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.player-count-btn {
  width: auto !important;
  padding: 0.5rem 1.2rem !important;
  font-size: 1.1rem !important;
  border-radius: 8px !important;
}

.player-count-btn.active {
  background: rgba(255,215,0,0.25) !important;
  border-color: #ffd700 !important;
  color: #ffd700 !important;
}

/* ── Join Input ───────────────────────────────────── */
.join-input {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.join-name {
  width: 100%;
  padding: 0.7rem 0.8rem;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  text-align: center;
  letter-spacing: 0;
  text-transform: none;
  border: 2px solid #8a6a3a;
  border-radius: 10px;
  background: rgba(0,0,0,0.3);
  color: #ffd700;
  outline: none;
}

.join-code-row {
  display: flex;
  gap: 0.5rem;
}

.join-code-row input {
  flex: 1;
  padding: 0.7rem;
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 0.3em;
  border: 2px solid #8a6a3a;
  border-radius: 10px;
  background: rgba(0,0,0,0.3);
  color: #ffd700;
  outline: none;
  text-transform: uppercase;
}

.join-input input:focus {
  border-color: #ffd700;
}

.join-input input::placeholder {
  color: #6a4a2a;
}

.join-input button {
  width: auto !important;
  padding: 0.7rem 1.3rem !important;
  margin: 0 !important;
}

/* ── Host Display ─────────────────────────────────── */
.host-display {
  margin-top: 1rem;
}

.code-label {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  color: #8a6a3a;
}

.room-code {
  font-family: 'Fredoka One', cursive;
  font-size: 3rem;
  letter-spacing: 0.4em;
  color: #ffd700;
  margin: 0.4rem 0;
  cursor: pointer;
  padding: 0.4rem 1rem;
  border: 2px dashed #8a6a3a;
  border-radius: 10px;
  display: inline-block;
  transition: border-color 0.2s;
  text-shadow: 0 2px 8px rgba(255,215,0,0.3);
}

.room-code:active {
  border-color: #ffd700;
}

.code-hint {
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  color: #6a4a2a;
}

.btn-how {
  background: transparent !important;
  border: 1px solid #6a4a2a !important;
  color: #8a6a3a !important;
  font-size: 1rem !important;
  padding: 0.5rem !important;
  margin-top: 1rem !important;
}
.btn-how:hover, .btn-how:active {
  border-color: #b88a5a !important;
  color: #b88a5a !important;
}

/* ── Lobby Leaderboard ────────────────────────────── */
.lobby-leaderboard {
  margin-top: 1rem;
  text-align: left;
  font-family: 'Fredoka One', cursive;
}
.lobby-leaderboard h3 {
  font-size: 1rem;
  color: #8a6a3a;
  text-align: center;
  margin-bottom: 0.4rem;
}
.lobby-leaderboard .lb-row {
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0.5rem;
  font-size: 0.85rem;
  color: #b8a080;
}
.lobby-leaderboard .lb-row:first-of-type {
  color: #ffd700;
}
.lobby-leaderboard .lb-row .lb-rank {
  width: 1.5rem;
  color: #8a6a3a;
}
.lobby-leaderboard .lb-row .lb-name {
  flex: 1;
}
.lobby-leaderboard .lb-row .lb-score {
  text-align: right;
}

.lobby-version {
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  color: #5a3a1a;
  margin-top: 1rem;
}

/* ── Instructions Modal ──────────────────────────── */
.instructions-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,5,2,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  overflow: hidden;
  padding: 1rem;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.instructions-overlay.hidden { display: none; }

.instructions-inner {
  background: linear-gradient(135deg, #3a2a1a 0%, #2a1510 100%);
  border: 2px solid #8a6a3a;
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 380px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  text-align: left;
}
.instructions-inner h2 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  color: #ffd700;
  text-align: center;
  margin-bottom: 1rem;
}
.instructions-section {
  margin-bottom: 1rem;
}
.instructions-section h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  color: #ddb866;
  margin-bottom: 0.3rem;
}
.instructions-section p {
  font-family: 'Fredoka One', cursive;
  font-size: 0.85rem;
  color: #b8a080;
  line-height: 1.4;
  margin-bottom: 0.4rem;
}
.score-row {
  font-family: 'Fredoka One', cursive;
  font-size: 0.82rem;
  color: #c8b090;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
}
.dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 0.7rem;
  color: #fff;
  flex-shrink: 0;
}
#btn-close-how {
  display: block;
  width: 100%;
  padding: 0.8rem;
  margin-top: 1rem;
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  border: 2px solid #ffd700;
  border-radius: 12px;
  background: rgba(255,215,0,0.15);
  color: #ffd700;
  cursor: pointer;
}
