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

body {
  font-family: 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

h1 {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 1.5rem;
  color: #e0aaff;
  letter-spacing: 2px;
}

.hidden { display: none !important; }

/* ── Lobby ────────────────────────────────────────────────────────────────── */
#lobby, #waiting {
  width: 100%;
  max-width: 360px;
  padding: 1rem;
}

.lobby-card {
  background: #16213e;
  border-radius: 16px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.grid-option label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: #aaa;
}

select, input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid #333;
  background: #0f3460;
  color: #eee;
  font-size: 1rem;
}

button {
  padding: 0.7rem;
  border-radius: 8px;
  border: none;
  background: #7b2ff7;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
  touch-action: manipulation; /* prevents 300ms tap delay on mobile */
}
button:hover { background: #9b4dff; }
button:active { background: #6a1fe0; }

.divider {
  text-align: center;
  color: #555;
  font-size: 0.85rem;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}
.join-row input { flex: 1; text-transform: uppercase; }
.join-row button { width: auto; padding: 0.7rem 1rem; }

.error-msg {
  color: #ff6b6b;
  font-size: 0.85rem;
  min-height: 1rem;
}

#room-code-display {
  font-size: 2.5rem;
  font-weight: bold;
  text-align: center;
  letter-spacing: 8px;
  color: #e0aaff;
  background: #0f3460;
  border-radius: 10px;
  padding: 0.5rem;
}

.waiting-text {
  text-align: center;
  color: #888;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── Game screen ──────────────────────────────────────────────────────────── */
#game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  padding: 1rem;
  width: 100%;
}

/* ── Scoreboard ───────────────────────────────────────────────────────────── */
#scoreboard {
  display: flex;
  align-items: center;
  gap: 0;
  background: #16213e;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  width: 100%;
  max-width: 340px;
}

.score-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.8rem 0.5rem;
  gap: 0.2rem;
  transition: background 0.3s;
}

.score-box.active-turn {
  background: rgba(224, 170, 255, 0.08);
}

.player-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  transition: color 0.3s;
}

.score-box.active-turn .player-label {
  color: #e0aaff;
}

.score-num {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
}

#score-p1 .score-num { color: #7b2ff7; }
#score-p2 .score-num { color: #f7922f; }

#turn-indicator {
  font-size: 0.8rem;
  color: #ccc;
  text-align: center;
  padding: 0 0.5rem;
  min-width: 80px;
  line-height: 1.3;
  border-left: 1px solid #2a2a4a;
  border-right: 1px solid #2a2a4a;
}

/* ── Board ────────────────────────────────────────────────────────────────── */
#board-container {
  border-radius: 12px;
  overflow: auto;
  max-width: 95vw;
  max-height: 70vh;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  -webkit-overflow-scrolling: touch;
}

canvas {
  display: block;
  cursor: pointer;
  background: #16213e;
  touch-action: none; /* prevents scroll interference during touch on canvas */
}

/* ── Move controls — sits below board, always visible when active ─────────── */
#move-controls {
  display: flex;
  gap: 0.8rem;
  width: 100%;
  max-width: 340px;
}

#move-controls button {
  flex: 1;
  padding: 0.85rem;
  font-size: 1rem;
  border-radius: 10px;
}

.secondary-btn {
  background: #2a2a4a;
  color: #ccc;
}
.secondary-btn:hover { background: #3a3a5a; }
.secondary-btn:active { background: #1e1e3a; }

/* ── Game over / disconnect overlay ──────────────────────────────────────── */
#game-message {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  font-size: 1.5rem;
  font-weight: bold;
  text-align: center;
  padding: 2rem;
  z-index: 100;
}

#game-message button {
  font-size: 1rem;
  padding: 0.7rem 2rem;
}
