* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #121212;
  color: #ffffff;
}

.page-body {
  padding: 20px;
}

.lobby-page {
  max-width: 650px;
  margin: 0 auto;
}

.card {
  background: #1e1e1e;
  border: 1px solid #333333;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.card h1 {
  margin-top: 0;
  margin-bottom: 8px;
}

.muted-text {
  color: #bbbbbb;
  margin: 0;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
}

input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #444444;
  background: #0f0f0f;
  color: white;
  font-size: 16px;
}

button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #00b894;
  color: white;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
}

button:hover {
  background: #019874;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.danger-btn {
  background: #d63031;
}

.danger-btn:hover {
  background: #b71c1c;
}

.join-row {
  display: flex;
  gap: 10px;
}

.join-row input {
  flex: 1;
}

.info-line {
  margin-bottom: 10px;
}

.message-box {
  background: #111111;
  border: 1px solid #333333;
  border-radius: 10px;
  padding: 12px;
  min-height: 46px;
  color: #dddddd;
}

.spacer {
  height: 16px;
}

.spacer.small {
  height: 10px;
}

/* Game page */
.game-page-body {
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  background: #0f0f0f;
}

.game-page-shell {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.phone-frame {
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  max-width: 520px;
  max-height: 924px;
  background: #181818;
  border: 2px solid #333333;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.game-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  padding: 12px;
  background: #1e1e1e;
  border-bottom: 1px solid #333333;
  font-size: 13px;
}

.top-player,
.top-center {
  padding: 8px;
  border-radius: 10px;
  background: #131313;
  text-align: center;
}

.player1-border {
  border: 1px solid #00ff99;
}

.player2-border {
  border: 1px solid #6ab0ff;
}

.game-board-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  position: relative;
  touch-action: none;
}

#gameBoard {
  width: min(92vw, 92%);
  max-width: 460px;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  grid-template-rows: repeat(20, 1fr);
  background: #1b1b1b;
  border: 3px solid #444444;
  touch-action: none;
}

.cell {
  border: 1px solid #262626;
}

.snake1 {
  background: #00e676;
}

.snake1-head {
  background: #00ff99;
}

.snake2 {
  background: #4da3ff;
}

.snake2-head {
  background: #7ec0ff;
}

.food {
  background: #ff3b30;
  border-radius: 50%;
}

.game-message-bar {
  padding: 10px 12px;
  background: #121212;
  border-top: 1px solid #333333;
  border-bottom: 1px solid #333333;
  text-align: center;
  min-height: 42px;
  color: #dddddd;
}

.mobile-controls {
  padding: 12px;
  background: #181818;
}

.mobile-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.mobile-row:last-child {
  margin-bottom: 0;
}

.control-btn {
  width: 74px;
  height: 74px;
  border-radius: 16px;
  font-size: 28px;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 5;
}

.countdown-text {
  font-size: 80px;
  font-weight: bold;
  color: white;
}

.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
}

.popup-box {
  width: 320px;
  max-width: calc(100vw - 24px);
  background: #1f1f1f;
  border: 1px solid #333333;
  border-radius: 14px;
  padding: 24px;
  text-align: center;
}

.popup-box h2 {
  margin-top: 0;
}

.popup-info {
  margin: 14px 0;
  color: #dddddd;
}

.popup-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hidden {
  display: none;
}

@media (max-width: 600px) {
  .page-body {
    padding: 12px;
  }

  .join-row {
    flex-direction: column;
  }

  .game-topbar {
    grid-template-columns: 1fr;
  }

  .control-btn {
    width: 78px;
    height: 78px;
    font-size: 30px;
  }
}