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

:root {
  --board-color: #17313a;
  --cell-empty: #edf6f4;
  --player1-color: #ff6b5a;
  --player2-color: #18c6a7;
  --bg-color: #0b1720;
  --text-color: #ffffff;
  --chat-bg: rgba(0, 0, 0, 0.25);
  --chat-self: rgba(24, 198, 167, 0.32);
  --chat-other: rgba(255, 255, 255, 0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(circle at 20% 18%, rgba(24, 198, 167, 0.18), transparent 28%),
    radial-gradient(circle at 82% 78%, rgba(255, 107, 90, 0.14), transparent 32%),
    var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.ambient-board {
  position: fixed;
  inset: -12vh -18vw;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.62;
  transform: rotate(-14deg) scale(1.12);
  z-index: 0;
  animation: ambient-board-drift 9s ease-in-out infinite alternate;
  will-change: transform;
  contain: layout style paint;
}

.ambient-grid {
  width: min(820px, 118vw);
  aspect-ratio: 7 / 6;
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: clamp(8px, 1.7vw, 16px);
  padding: clamp(14px, 3vw, 28px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(135deg, rgba(23, 49, 58, 0.92), rgba(11, 23, 32, 0.58)),
    repeating-linear-gradient(90deg, transparent 0 13%, rgba(255, 255, 255, 0.035) 13% 14%);
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.42);
  contain: strict;
}

.ambient-slot {
  position: relative;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 35%, rgba(237, 246, 244, 0.14), rgba(237, 246, 244, 0.06) 70%);
  outline: 1px solid rgba(255, 255, 255, 0.04);
}

.ambient-token {
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  opacity: 0.96;
  transform: translateY(-620%) scale(0.88);
  animation: ambient-token-drop 520ms cubic-bezier(.16, .9, .22, 1.08) forwards;
  will-change: transform, opacity;
}

.ambient-token.player-1 {
  background: radial-gradient(circle at 35% 30%, #ff9e94, var(--player1-color) 60%, #c44e42);
}

.ambient-token.player-2 {
  background: radial-gradient(circle at 35% 30%, #5ee8c8, var(--player2-color) 60%, #0f9b7a);
}

.ambient-token.ambient-winning {
  animation: ambient-win-pulse 780ms ease-in-out infinite alternate;
}

.ambient-board.ambient-draw {
  animation: ambient-board-drift 9s ease-in-out infinite alternate, ambient-draw-pulse 650ms ease-in-out 3;
}

@keyframes ambient-token-drop {
  0% {
    transform: translateY(-620%) scale(0.88);
  }
  78% {
    transform: translateY(0) scale(1);
  }
  88% {
    transform: translateY(-8%) scale(1.02);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes ambient-win-pulse {
  0% {
    transform: scale(1);
    opacity: 0.96;
  }
  100% {
    transform: scale(1.12);
    opacity: 1;
  }
}

@keyframes ambient-draw-pulse {
  0%, 100% {
    opacity: 0.62;
  }
  50% {
    opacity: 0.85;
  }
}

@keyframes ambient-board-drift {
  0% {
    transform: rotate(-15deg) scale(1.1) translate3d(-1.5%, -1%, 0);
  }
  100% {
    transform: rotate(-11deg) scale(1.16) translate3d(1.5%, 1%, 0);
  }
}


#app {
  width: 100%;
  max-width: 500px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  z-index: 1;
}

.screen {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen.active {
  display: flex;
}

#lobby-screen {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  justify-content: flex-start;
  padding-top: 0;
  padding-bottom: 12px;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

h2 {
  font-size: 1.8rem;
  margin-bottom: 16px;
  text-align: center;
}

.subtitle {
  font-size: 1rem;
  opacity: 0.8;
  margin-bottom: 20px;
}

/* Name toggle */
#name-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  width: 100%;
  max-width: 300px;
}

.toggle-btn {
  flex: 1;
  padding: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-color: rgba(255, 255, 255, 0.5);
}

#name-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

#name-input,
#code-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 1.1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
  letter-spacing: 2px;
}

#name-input::placeholder,
#code-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0;
}

#name-input:focus,
#code-input:focus {
  border-color: rgba(255, 255, 255, 0.7);
}

.name-count {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.35);
  text-align: center;
  align-self: flex-end;
  margin-right: 4px;
}

.name-count.warn {
  color: rgba(255, 193, 7, 0.9);
}

#name-submit {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--player1-color);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#name-submit:hover {
  opacity: 0.9;
}

#name-submit:active {
  transform: scale(0.97);
}

/* Code Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: #1a237e;
  padding: 32px;
  border-radius: 20px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin-bottom: 8px;
}

.modal-content p {
  font-size: 0.9rem;
  opacity: 0.8;
  margin-bottom: 16px;
}

/* Challenge Send Modal */
.challenge-send-modal-content #challenge-target-name {
  font-size: 0.95rem;
  opacity: 0.8;
  margin-bottom: 16px;
}

.challenge-send-modal-content textarea {
  width: 100%;
  min-height: 72px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 16px;
  box-sizing: border-box;
}

.challenge-send-modal-content textarea:focus {
  outline: none;
  border-color: #7c4dff;
}

.challenge-send-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.challenge-send-modal-actions button {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.challenge-send-modal-actions #challenge-cancel {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.challenge-send-modal-actions #challenge-send {
  background: #7c4dff;
  color: #fff;
}

.code-display {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 8px;
  background: rgba(255, 255, 255, 0.1);
  padding: 16px 24px;
  border-radius: 12px;
  margin-bottom: 20px;
  border: 2px dashed rgba(255, 255, 255, 0.3);
}

.code-modal-content {
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.code-identity {
  margin-bottom: 16px;
}

.code-username {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  opacity: 0.8;
  margin-bottom: 8px;
}

.code-display {
  margin-bottom: 12px;
}

.pwa-install-section {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.pwa-install-section h3 {
  font-size: 0.95rem;
  margin: 0 0 4px 0;
}

.pwa-install-section p {
  font-size: 0.8rem;
  opacity: 0.7;
  margin: 0 0 8px 0;
}

.pwa-install-section .ios-install-note {
  color: #ffd166;
  opacity: 1;
  font-weight: 600;
}

.pwa-instructions {
  font-size: 0.8rem;
  opacity: 0.6;
  font-style: italic;
}

.pwa-platform {
  display: none;
}

.pwa-steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0 6px 0;
}

.pwa-step {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 8px 12px;
}

.pwa-step-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  font-size: 0.95rem;
  line-height: 1;
  flex-shrink: 0;
}

.pwa-step span:last-child {
  font-size: 0.82rem;
  opacity: 0.9;
  line-height: 1.3;
}

.pwa-step-note {
  font-size: 0.75rem;
  opacity: 0.6;
  margin: 4px 0 0 0;
  font-style: italic;
}

#pwa-install-btn-modal {
  padding: 10px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  background: #2196f3;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

#pwa-install-btn-modal:active {
  transform: scale(0.97);
}

.notification-enable-btn {
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  background: #2e7d32;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

.notification-enable-btn:active {
  transform: scale(0.97);
}

.notification-enable-btn[disabled] {
  opacity: 0.55;
  cursor: default;
}

#code-ok-btn {
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--player1-color);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

#name-taken-change {
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

#name-taken-enter-code {
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--player1-color);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

#name-taken-change:active,
#name-taken-enter-code:active {
  transform: scale(0.97);
}

.invite-card {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px;
  margin-top: 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.invite-message {
  font-size: 1.1rem;
  margin: 0 0 12px 0;
}

.invite-stats {
  font-size: 0.85rem;
  opacity: 0.6;
  margin-bottom: 8px;
}

.invite-status {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.invite-status-online {
  color: #81c784;
}

.invite-status-offline {
  color: #bdbdbd;
}

#invite-form {
  margin-bottom: 12px;
}

#invite-name-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  margin-bottom: 12px;
  box-sizing: border-box;
  outline: none;
}

#invite-name-input:focus {
  border-color: rgba(255, 255, 255, 0.5);
}

#invite-submit {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--player1-color);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

#invite-submit:active {
  transform: scale(0.97);
}

.invite-play-anyway {
  width: 100%;
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.invite-play-anyway:hover {
  color: rgba(255, 255, 255, 0.8);
}

#code-ok-btn:active {
  transform: scale(0.97);
}

/* Lobby */
.lobby-info {
  text-align: center;
  margin-bottom: 16px;
}

.lobby-info p {
  font-size: 1.1rem;
  margin: 4px 0;
}

#lobby-welcome {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

.lobby-info {
  margin-bottom: 8px;
}

.lobby-position {
  opacity: 0.7;
  font-size: 0.95rem;
}

/* Lobby Action Buttons */
.lobby-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  width: 100%;
  max-width: 360px;
  align-items: stretch;
}

.lobby-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  box-sizing: border-box;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.2;
  padding: 14px 12px;
}

.lobby-action-btn.primary {
  background: var(--player1-color);
  color: white;
}

.lobby-action-btn.secondary {
  background: var(--player2-color);
  color: #333;
}

.lobby-action-btn:active {
  transform: scale(0.97);
}

.lobby-action-btn.in-queue {
  background: rgba(255, 193, 7, 0.8);
  color: #333;
}

/* Queue Status */
.queue-status {
  text-align: center;
  margin-bottom: 20px;
  width: 100%;
  max-width: 360px;
}

.queue-hint {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  margin: 8px 0 12px;
}

/* Lobby Players Section */
.lobby-players {
  width: 100%;
  max-width: 360px;
  margin-bottom: 8px;
}

/* Player Filter Row */
.players-filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.filter-btn {
  flex: 1;
  padding: 8px 6px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-btn.active {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-color: rgba(255, 255, 255, 0.4);
}

/* Friend Badge */
.friend-badge {
  display: none;
}

/* Player List */
.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  padding: 12px 16px;
  border-radius: 10px;
}

.player-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.player-name {
  font-weight: 600;
}

.player-status {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 6px;
  margin-right: 8px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.status-idle {
  background: rgba(76, 175, 80, 0.3);
  color: #81c784;
}

.status-queue {
  background: rgba(255, 193, 7, 0.3);
  color: #ffd54f;
}

.status-ingame {
  background: rgba(244, 67, 54, 0.3);
  color: #e57373;
}

.challenge-btn {
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--player1-color);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.challenge-btn:active {
  transform: scale(0.95);
}

.browse-section {
  margin-bottom: 16px;
}

.browse-section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255, 255, 255, 0.6);
  margin: 0 0 8px 0;
}

.player-item-offline {
  background: rgba(255, 255, 255, 0.05);
  opacity: 0.7;
}

.status-offline {
  background: rgba(158, 158, 158, 0.3);
  color: #bdbdbd;
}

.notify-btn {
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(33, 150, 243, 0.8);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.notify-btn:active {
  transform: scale(0.95);
}

/* Add Friend Button (in-game header) */
.add-friend-btn {
  padding: 4px 8px;
  font-size: 1rem;
  font-weight: 400;
  background: rgba(255, 193, 7, 0.8);
  color: #333;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}

.add-friend-btn:active {
  transform: scale(0.95);
}

.add-friend-btn.added {
  background: rgba(244, 67, 54, 0.7);
  color: white;
}

/* Add Friend Button (gameover screen) */
.add-friend-go-btn {
  padding: 8px 14px;
  font-size: 1.1rem;
  font-weight: 400;
  background: rgba(255, 193, 7, 0.8);
  color: #333;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}

.add-friend-go-btn:active {
  transform: scale(0.97);
}

.add-friend-go-btn.added {
  background: rgba(244, 67, 54, 0.7);
  color: white;
  cursor: default;
}

/* Small Add Friend Button (in player list) */
.add-friend-btn-small {
  width: 32px;
  height: 28px;
  padding: 0;
  font-size: 1rem;
  font-weight: 400;
  background: rgba(255, 193, 7, 0.8);
  color: #333;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.add-friend-btn-small:active {
  transform: scale(0.95);
}

.add-friend-btn-small.added {
  background: rgba(244, 67, 54, 0.7);
  color: white;
}

#play-ai-btn {
  padding: 14px 40px;
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--player2-color);
  color: #333;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 12px;
}

#play-ai-btn:active {
  transform: scale(0.97);
}

#quick-match-btn {
  padding: 14px 40px;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

#quick-match-btn:active {
  transform: scale(0.97);
}

#quick-match-btn.lobby-action-btn,
#play-ai-btn.lobby-action-btn {
  padding: 16px 12px !important;
  margin-top: 0 !important;
}

#leave-queue-btn {
  margin-top: 12px;
  padding: 10px 24px;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

/* Lobby action buttons */
#leaderboard-btn,
#copy-invite-btn,
#spectate-btn,
#replay-btn {
  margin-top: 6px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  max-width: 300px;
}

#leaderboard-btn:hover,
#copy-invite-btn:hover,
#spectate-btn:hover,
#replay-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Lobby icon row — 2x2 quad */
.lobby-icon-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
  width: 100%;
  max-width: 340px;
}

.lobby-icon-row.single {
  grid-template-columns: 1fr;
}

.lobby-icon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 8px;
  font-size: 0.7rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.lobby-icon-btn:hover,
.lobby-icon-btn:active {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.95);
}

.lobby-icon-btn svg {
  flex-shrink: 0;
}

.lobby-icon-btn span {
  line-height: 1;
}

.lobby-icon-btn[disabled] {
  opacity: 0.4;
  cursor: default;
}

.notification-enable-btn {
  padding: 8px 24px;
  font-size: 0.85rem;
}

/* Lobby account actions */
.lobby-account-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
  margin-bottom: 8px;
}

.lobby-account-actions button {
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.lobby-account-actions button:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
}

.lobby-account-actions button.danger {
  color: rgba(244, 67, 54, 0.8);
  border-color: rgba(244, 67, 54, 0.25);
}

.lobby-account-actions button.danger:hover {
  background: rgba(244, 67, 54, 0.15);
  color: rgba(244, 67, 54, 1);
}

/* Leaderboard */
.leaderboard-content {
  max-width: 420px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 8px;
}

.leaderboard-list {
  max-height: 250px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.lb-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.05);
}

.lb-me {
  background: rgba(255, 235, 59, 0.15);
  border: 1px solid rgba(255, 235, 59, 0.3);
}

.lb-rank {
  width: 32px;
  font-weight: 700;
  opacity: 0.6;
}

.lb-name {
  flex: 1;
  font-weight: 600;
}

.lb-code {
  font-family: monospace;
  font-size: 0.8rem;
  opacity: 0.5;
  letter-spacing: 1px;
}

.lb-stats {
  font-size: 0.8rem;
  opacity: 0.7;
}

.lb-wins {
  font-size: 0.8rem;
  opacity: 0.5;
}

.lb-empty {
  text-align: center;
  opacity: 0.6;
  padding: 24px;
}

#leaderboard-close {
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  align-self: center;
  margin-top: 8px;
  width: 100%;
  max-width: 200px;
  flex-shrink: 0;
}

/* Waiting Overlay */
.waiting-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}

.waiting-content {
  background: var(--bg);
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  max-width: 320px;
  width: 90%;
}

.waiting-content h2 {
  font-size: 1.3rem;
  margin-bottom: 10px;
}

.waiting-content p {
  font-size: 0.9rem;
  opacity: 0.8;
  margin-bottom: 16px;
}

.waiting-timer {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.waiting-timer .timer-track {
  flex: 1;
  height: 6px;
}

/* Challenge Banner */
.challenge-banner {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 193, 7, 0.15);
  border: 1px solid rgba(255, 193, 7, 0.4);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  animation: banner-slide 0.3s ease-out;
}

@keyframes banner-slide {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.challenge-banner button {
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

#challenge-accept-now {
  background: var(--player1-color);
  color: white;
}

#challenge-accept-later {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

#challenge-dismiss {
  background: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 1rem;
  padding: 4px 8px;
}

.sound-toggle-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  padding: 4px 8px;
}

.sound-toggle-btn:hover {
  opacity: 1;
}

.quit-game-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.2s;
  padding: 4px 8px;
}

.quit-game-btn:hover {
  opacity: 1;
}

/* Loader */
.loader {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 16px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Game */
.game-header {
  display: flex;
  justify-content: space-around;
  width: 100%;
  margin-bottom: 10px;
}

.player-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  padding: 6px 14px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  min-width: 0;
  flex: 1;
  max-width: 100%;
}

.player-indicator span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-indicator.active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

.dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid rgba(0, 0, 0, 0.2);
}

.dot-1 {
  background: var(--player1-color);
}

.dot-2 {
  background: var(--player2-color);
}

.board {
  background: var(--board-color);
  padding: 10px;
  border-radius: 12px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 7 / 6;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.board-disabled {
  pointer-events: none;
}

.cell {
  background: var(--cell-empty);
  border-radius: 50%;
  width: 100%;
  aspect-ratio: 1;
  transition: background-color 0.3s ease, transform 0.2s ease;
  position: relative;
}

.cell.player-1 {
  background: radial-gradient(circle at 35% 30%, #ff9e94, var(--player1-color) 60%, #c44e42);
  animation: drop 0.4s ease-out;
}

.cell.player-2 {
  background: radial-gradient(circle at 35% 30%, #5ee8c8, var(--player2-color) 60%, #0f9b7a);
  animation: drop 0.4s ease-out;
}

.cell.winning {
  animation: pulse 0.6s ease-in-out infinite alternate;
}

@keyframes drop {
  from {
    transform: translateY(-300px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.1);
  }
}

.column-indicators {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 400px;
  margin-bottom: 6px;
  height: 38px;
}

.column-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.column-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
}

.column-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.column-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.game-message {
  margin-top: 10px;
  font-size: 1rem;
  text-align: center;
  min-height: 20px;
}

.move-timer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 400px;
  margin-top: 6px;
  font-size: 0.8rem;
  opacity: 0.8;
}

.timer-track {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 2px;
  transition: width 1s linear, background 0.3s;
}

/* Chat */
.chat-container {
  width: 100%;
  max-width: 400px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  border-radius: 12px;
  overflow: hidden;
}

.chat-messages {
  max-height: 120px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  max-width: 85%;
  word-wrap: break-word;
}

.chat-msg.self {
  align-self: flex-end;
  background: var(--chat-self);
}

.chat-msg.other {
  align-self: flex-start;
  background: var(--chat-other);
}

.chat-msg .sender {
  font-weight: 600;
  font-size: 0.75rem;
  opacity: 0.7;
  margin-right: 6px;
}

.chat-form {
  display: flex;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-form input {
  flex: 1;
  padding: 10px 12px;
  font-size: 0.9rem;
  border: none;
  background: transparent;
  color: white;
  outline: none;
}

.chat-form input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.chat-form button {
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: none;
  cursor: pointer;
  transition: color 0.2s;
}

.chat-form button:hover {
  color: white;
}

/* Game Over */
.gameover-board-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 12px;
}

.gameover-chat {
  width: 100%;
  max-width: 400px;
  margin-bottom: 16px;
  background: var(--chat-bg);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.gameover-chat .chat-messages {
  max-height: 80px;
  background: transparent;
}

#play-again-btn {
  padding: 14px 40px;
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--player1-color);
  color: white;
  border: none;
  border-radius: 32px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#play-again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

#play-again-btn:active {
  transform: translateY(0);
}

/* PWA Banner */
.pwa-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a237e;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
  z-index: 500;
}

.pwa-banner span {
  font-size: 0.9rem;
}

#pwa-install-btn {
  padding: 8px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--player1-color);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.pwa-dismiss {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* Win explosion */
.win-particle {
  position: absolute;
  pointer-events: none;
  z-index: 100;
}

@keyframes board-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-2px); }
  40% { transform: translateX(2px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.board-shake {
  animation: board-shake 150ms ease-out;
}

/* Responsive */
@media (max-height: 700px) {
  h1 {
    font-size: 2rem;
    margin-bottom: 12px;
  }

  .board {
    padding: 8px;
    gap: 4px;
  }

  .column-indicators {
    height: 32px;
    gap: 4px;
  }

  .game-header {
    margin-bottom: 8px;
  }

  .chat-messages {
    max-height: 90px;
  }
}

@media (min-width: 768px) {
  #app {
    padding: 32px;
  }

  h1 {
    font-size: 3rem;
  }

  .board {
    max-width: 480px;
    padding: 14px;
    gap: 8px;
  }

  .column-indicators {
    max-width: 480px;
    gap: 8px;
    height: 44px;
  }

  .column-btn {
    font-size: 1.4rem;
  }

  .player-indicator {
    font-size: 1rem;
    padding: 8px 18px;
  }

  .chat-messages {
    max-height: 160px;
  }
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 1000;
  white-space: nowrap;
}

.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Copy Invite Link Button — styled by unified lobby action buttons rule */

/* Share Result Button */
.share-result-btn {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.share-result-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Gameover actions container */
.gameover-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  width: 100%;
}

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

/* Gameover secondary buttons (Share, Friend) */
.gameover-secondary-btn {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.gameover-secondary-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Return to Lobby Button */
#return-lobby-btn {
  padding: 10px 32px;
  font-size: 0.95rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 32px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

#return-lobby-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
}

/* Share Sheet Modal */
.share-sheet-content {
  max-width: 380px;
  padding: 24px;
}

.share-sheet-content h2 {
  margin-bottom: 12px;
}

.share-message {
  font-size: 0.85rem;
  opacity: 0.7;
  margin-bottom: 20px;
  word-break: break-all;
}

.share-platforms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.share-platform-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px 12px;
  border-radius: 12px;
  text-decoration: none;
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  transition: transform 0.2s, opacity 0.2s;
  border: none;
  cursor: pointer;
  min-height: 80px;
}

.share-platform-btn:hover {
  transform: scale(1.08);
  opacity: 0.9;
}

.share-platform-btn[href*="wa.me"] {
  background: #25D366;
}

.share-platform-btn[href*="facebook"] {
  background: #1877F2;
}

.share-platform-btn[href*="t.me"] {
  background: #0088cc;
}

#share-native {
  background: #17313a;
}

#share-copy {
  background: #6b7280;
}

#share-copy:hover {
  background: #7c8393;
  transform: scale(1.08);
}

.share-close-btn {
  width: 100%;
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.share-close-btn:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* Leaderboard Share Button */
.lb-share {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s;
  color: white;
  flex-shrink: 0;
}

.lb-share:hover {
  opacity: 1;
}

.lb-referred {
  font-size: 0.7rem;
  opacity: 0.4;
  white-space: nowrap;
}

.lb-elo {
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.7;
  white-space: nowrap;
  min-width: 40px;
  text-align: right;
}

/* Analytics section */
.analytics-section {
  margin-top: 8px;
  margin-bottom: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.15);
  width: 100%;
  flex-shrink: 0;
}

.analytics-section h3 {
  font-size: 1rem;
  margin-bottom: 8px;
  opacity: 0.7;
  text-align: center;
}

#analytics-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.analytics-stat {
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.analytics-stat .stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  display: block;
}

.analytics-stat .stat-label {
  font-size: 0.7rem;
  opacity: 0.6;
  text-transform: uppercase;
}

/* Spectator screen */
.spec-move-info {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 350px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  opacity: 0.7;
}

#spec-leave-btn {
  margin-top: 12px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

/* Replay controls */
.replay-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 12px 0;
}

.replay-controls button {
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.replay-controls button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#replay-move-info {
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 80px;
  text-align: center;
}

#replay-back-btn {
  margin-top: 8px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  width: 100%;
  max-width: 300px;
}

.replay-content {
  max-width: 400px;
}

/* Spectate & replay list items */
.spectate-item,
.replay-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  margin-bottom: 6px;
}

.spectate-item .item-info,
.replay-item .item-info {
  flex: 1;
}

.spectate-item .item-names,
.replay-item .item-names {
  font-weight: 600;
  display: block;
}

.spectate-item .item-detail,
.replay-item .item-detail {
  font-size: 0.75rem;
  opacity: 0.6;
}

.spectate-item button,
.replay-item button {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--board-color);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  margin-left: 8px;
}

/* Footer banner */
.footer-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.3);
  z-index: 100;
  letter-spacing: 0.3px;
}

/* Code modal warning */
.code-warning {
  background: rgba(255, 193, 7, 0.12);
  border: 1px solid rgba(255, 193, 7, 0.3);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 0.82rem;
  color: rgba(255, 235, 59, 0.95);
  line-height: 1.4;
}

.code-display-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.copy-code-btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Confirm modal */
.danger-btn {
  background: rgba(244, 67, 54, 0.8) !important;
  color: white !important;
}

.danger-btn:hover {
  background: rgba(244, 67, 54, 1) !important;
}
