* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  margin: 0;
  background: linear-gradient(135deg, #4A90E2 0%, #2196F3 50%, #64B5F6 100%);
  background-attachment: fixed;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  color: #333;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#game {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  width: 100%;
  box-sizing: border-box;
}

h1, h2 {
  color: #ffffff;
  margin-bottom: 10px;
  font-weight: 700;
  text-shadow: 0 2px 10px rgba(0,0,0,0.1);
  letter-spacing: -0.5px;
}

h2 {
  font-size: 2rem;
}

h3 {
  color: #2c3e50;
  font-weight: 600;
  margin-top: 0;
}

#board {
  display: grid;
  grid-template: repeat(15, 40px) / repeat(15, 40px);
  gap: 1px;
  margin: 20px 0;
  background: linear-gradient(135deg, #d4c5b0 0%, #c4b5a0 100%);
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  padding: 8px;
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.15),
    0 0 0 1px rgba(0,0,0,0.08) inset;
  position: relative;
  width: fit-content;
  max-width: 100%;
  box-sizing: border-box;
}

#board::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}

.cell {
  background: #f5f0e8;
  width: 40px;
  height: 40px;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  text-align: center;
  vertical-align: middle;
  font-size: 20px;
  font-weight: 500;
  border: 1px solid rgba(180, 165, 144, 0.3);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cell:hover {
  transform: scale(1.02);
  background: #f8f5f0;
  z-index: 5;
}

.cell.placed {
  background: #f0ebe0;
}

/* Bonus square styles - softer, more subtle */
.cell.double-letter {
  background: #e3f2fd;
  border-color: rgba(33, 150, 243, 0.2);
}

.cell.triple-letter {
  background: #bbdefb;
  border-color: rgba(33, 150, 243, 0.3);
  color: #1565c0;
}

.cell.double-word {
  background: #fff3e0;
  border-color: rgba(255, 152, 0, 0.2);
}

.cell.triple-word {
  background: #ffe0b2;
  border-color: rgba(255, 152, 0, 0.3);
  color: #e65100;
}

.cell.center {
  background: #fff3e0;
  border-color: rgba(255, 152, 0, 0.25);
}

/* Tile on board styling - modern and realistic */
.board-tile {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #fff8f0 0%, #f5ede0 100%);
  border: 1px solid rgba(180, 165, 144, 0.4);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 1px 3px rgba(0,0,0,0.12),
    inset 0 1px 0 rgba(255,255,255,0.8),
    inset 0 -1px 0 rgba(0,0,0,0.05);
  position: relative;
  font-weight: 600;
  color: #2c2c2c;
  padding: 2px;
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  cursor: default;
}

.board-tile-letter {
  font-size: 20px;
  line-height: 1;
}

.board-tile-letter {
  font-size: 20px;
  line-height: 1;
}

.board-tile::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  right: 2px;
  bottom: 2px;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 2px;
  pointer-events: none;
}

/* Move History Styles */
.move-history-entry {
  padding: 12px;
  margin: 8px 0;
  background: #f9f9f9;
  border-radius: 8px;
  border-left: 3px solid #3b6ea5;
  transition: all 0.2s ease;
}

.move-history-entry:hover {
  background: #f0f0f0;
  transform: translateX(4px);
}

.move-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-weight: 600;
}

.move-number {
  color: #666;
  font-size: 12px;
  min-width: 30px;
}

.move-player {
  flex: 1;
  color: #333;
}

.move-score {
  color: #3b6ea5;
  font-weight: bold;
}

.move-words {
  font-size: 13px;
  color: #666;
  font-style: italic;
}

/* Blank Tile Letter Selection Modal */
#letter-selection-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-top: 20px;
  padding: 10px;
}

.letter-btn {
  background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 18px;
  font-size: 22px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 
    0 4px 15px rgba(33, 150, 243, 0.4),
    0 0 0 1px rgba(255,255,255,0.1) inset;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.letter-btn:hover {
  background: linear-gradient(135deg, #1976D2 0%, #2196F3 100%);
  transform: translateY(-3px) scale(1.05);
  box-shadow: 
    0 8px 25px rgba(33, 150, 243, 0.5),
    0 0 0 1px rgba(255,255,255,0.2) inset;
}

.letter-btn:active {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 
    0 4px 15px rgba(33, 150, 243, 0.4),
    0 0 0 1px rgba(255,255,255,0.1) inset;
}

.bonus-label {
  position: absolute;
  font-size: 7px;
  font-weight: 600;
  color: rgba(0,0,0,0.5);
  bottom: 2px;
  right: 2px;
  opacity: 0.7;
}

#rack {
  display: flex;
  margin-bottom: 15px;
  gap: 4px;
  min-height: 50px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 600px;
  padding: 10px;
  box-sizing: border-box;
}

.tile {
  background: linear-gradient(135deg, rgba(255, 248, 240, 0.98) 0%, rgba(245, 237, 224, 0.98) 100%);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(180, 165, 144, 0.4);
  border-radius: 8px;
  padding: 0;
  margin: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  cursor: grab;
  position: relative;
  user-select: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 
    0 2px 6px rgba(0,0,0,0.1),
    0 0 0 1px rgba(255,255,255,0.5) inset;
}

.tile:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 
    0 8px 16px rgba(0,0,0,0.25),
    0 0 0 1px rgba(255,255,255,0.3) inset;
}

.tile:active {
  cursor: grabbing;
}

.tile.selected {
  border-color: #3b6ea5;
  box-shadow: 
    0 0 20px rgba(59, 110, 165, 0.6),
    0 4px 12px rgba(59, 110, 165, 0.4),
    0 0 0 2px rgba(59, 110, 165, 0.2) inset;
  transform: scale(1.1) translateY(-2px);
  z-index: 10;
}

.tile.drag-over {
  background: rgba(200, 230, 255, 0.6);
  border-color: rgba(33, 150, 243, 0.5);
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(33, 150, 243, 0.3);
}

.tile.dragging {
  opacity: 0.7;
  transform: scale(1.2) rotate(5deg);
  z-index: 1000;
  box-shadow: 0 12px 24px rgba(0,0,0,0.4);
}

.tile.swappable {
  border-color: #ff9800;
  box-shadow: 0 0 8px rgba(255, 152, 0, 0.5);
}

.tile[style*="opacity: 0.7"] {
  pointer-events: none;
}

.cell.returnable {
  cursor: pointer;
  position: relative;
}

.cell.returnable::after {
  content: '↩';
  position: absolute;
  top: -5px;
  right: -5px;
  background: linear-gradient(135deg, #ff5722 0%, #ff7043 100%);
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px rgba(255, 87, 34, 0.4);
  border: 2px solid rgba(255,255,255,0.3);
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.cell.returnable:hover {
  transform: scale(1.08);
  z-index: 10;
}

.cell.returnable:hover::after {
  transform: scale(1.2);
  box-shadow: 0 6px 12px rgba(255, 87, 34, 0.6);
}

/* Tile return animation */
.tile-returning {
  animation: returnToRack 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  z-index: 2000 !important;
  pointer-events: none;
}

@keyframes returnToRack {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.3) rotate(180deg) translateY(-50px);
    opacity: 0.8;
  }
  100% {
    transform: scale(0.5) rotate(360deg) translateY(-100px);
    opacity: 0;
  }
}

.button.hidden {
  display: none !important;
}

.tile-score {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 10px;
  color: #694012;
  font-weight: bold;
}

.cell.drag-over {
  background: rgba(200, 230, 255, 0.6);
  backdrop-filter: blur(5px);
  transform: scale(1.05);
  border: 2px solid rgba(33, 150, 243, 0.5);
  box-shadow: 0 0 12px rgba(33, 150, 243, 0.3);
  user-select: none;
  -webkit-user-select: none;
}

#player-info {
  margin: 12px 0;
  font-size: 18px;
  color: #2c3e50;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  padding: 16px 24px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 
    0 8px 24px rgba(0,0,0,0.1),
    0 0 0 1px rgba(0,0,0,0.05) inset;
  width: 100%;
  max-width: 600px;
  text-align: center;
}

#controls {
  margin: 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  width: 100%;
  max-width: 800px;
  padding: 0 10px;
  box-sizing: border-box;
}

/* Button Styles */
.button {
  background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 
    0 4px 15px rgba(33, 150, 243, 0.4),
    0 0 0 1px rgba(255,255,255,0.1) inset;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  position: relative;
  overflow: hidden;
}

.button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transition: left 0.5s;
}

.button:hover:not(:disabled):not(.hidden) {
  background: linear-gradient(135deg, #1976D2 0%, #2196F3 100%);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 
    0 8px 25px rgba(33, 150, 243, 0.5),
    0 0 0 1px rgba(255,255,255,0.2) inset;
}

.button:hover:not(:disabled):not(.hidden)::before {
  left: 100%;
}

.button:active:not(:disabled):not(.hidden) {
  transform: translateY(-1px) scale(1.01);
  box-shadow: 
    0 4px 15px rgba(33, 150, 243, 0.4),
    0 0 0 1px rgba(255,255,255,0.1) inset;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

#start-game-btn {
  margin: 0 auto 5px;
}

.current-turn {
  color: #e74c3c;
  font-weight: bold;
  background: #ffe0e0;
  padding: 2px 8px;
  border-radius: 4px;
}

#messages {
  min-height: 32px;
  color: #2c3e50;
  font-weight: 600;
  margin-top: 10px;
  text-align: center;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 
    0 4px 16px rgba(0,0,0,0.1),
    0 0 0 1px rgba(0,0,0,0.05) inset;
  width: 100%;
  max-width: 600px;
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(5px);
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background: linear-gradient(135deg, rgba(255,255,255,0.98) 0%, rgba(248,249,250,0.98) 100%);
  backdrop-filter: blur(20px);
  margin: 5% auto;
  padding: 40px;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 24px;
  width: 80%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 
    0 20px 60px rgba(0,0,0,0.3),
    0 0 0 1px rgba(0,0,0,0.05) inset;
  animation: slideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  color: #2c3e50;
}

.modal-content h2 {
  color: #2c3e50;
  margin-top: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.close {
  color: #999;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s ease;
}

.close:hover,
.close:focus {
  color: #2c3e50;
}

#leaderboard-list {
  margin-top: 20px;
}

.leaderboard-entry {
  padding: 12px 16px;
  margin: 8px 0;
  background: rgba(245, 245, 245, 0.8);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(255,255,255,0.3);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

.leaderboard-entry:hover {
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.leaderboard-entry:nth-child(1) {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.9) 0%, rgba(255, 193, 7, 0.9) 100%);
  font-weight: bold;
  box-shadow: 0 4px 16px rgba(255, 215, 0, 0.4);
}

.leaderboard-entry:nth-child(2) {
  background: linear-gradient(135deg, rgba(192, 192, 192, 0.9) 0%, rgba(158, 158, 158, 0.9) 100%);
  box-shadow: 0 4px 12px rgba(158, 158, 158, 0.3);
}

.leaderboard-entry:nth-child(3) {
  background: linear-gradient(135deg, rgba(205, 127, 50, 0.9) 0%, rgba(184, 104, 30, 0.9) 100%);
  box-shadow: 0 4px 12px rgba(184, 104, 30, 0.3);
}

.leaderboard-rank {
  font-weight: bold;
  margin-right: 10px;
  min-width: 30px;
}

.leaderboard-name {
  flex: 1;
}

.leaderboard-score {
  font-weight: bold;
  color: #3b6ea5;
  margin-left: 10px;
}

.leaderboard-date {
  font-size: 12px;
  color: #666;
  margin-left: 10px;
}

/* Live Score Preview */
#live-score-preview {
  background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
  color: white;
  padding: 20px 32px;
  border-radius: 16px;
  margin: 15px 0;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 
    0 8px 32px rgba(33, 150, 243, 0.4),
    0 0 0 1px rgba(255,255,255,0.1) inset;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
  max-width: 600px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.score-preview-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
}

#word-preview-text {
  font-weight: bold;
}

.score-value {
  font-size: 24px;
  font-weight: bold;
  padding: 5px 15px;
  background: rgba(255,255,255,0.2);
  border-radius: 20px;
}

.score-value.valid {
  background: rgba(255,255,255,0.3);
  color: #c8e6c9;
}

.score-value.invalid {
  background: rgba(255,255,255,0.3);
  color: #ffcdd2;
}

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

/* Scoreboard styles */
.scoreboard-entry {
  padding: 12px;
  margin: 5px 0;
  background: #f5f5f5;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s ease;
}

.scoreboard-entry:hover {
  background: #e8e8e8;
}

.scoreboard-entry.current-turn-entry {
  background: #e3f2fd;
  border-left: 4px solid #2196f3;
  font-weight: bold;
}

.scoreboard-entry.your-entry {
  background: #f1f8e9;
  border-left: 4px solid #8bc34a;
}

.scoreboard-entry.current-turn-entry.your-entry {
  background: #e8f5e9;
  border-left: 4px solid #4caf50;
}

.scoreboard-rank {
  font-weight: bold;
  margin-right: 15px;
  min-width: 40px;
  font-size: 18px;
  color: #666;
}

.scoreboard-name {
  flex: 1;
  font-size: 16px;
}

.scoreboard-score {
  font-weight: bold;
  color: #3b6ea5;
  font-size: 18px;
  margin-left: 10px;
}

/* Screen management */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

#game-screen {
  display: none;
}

#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 10px;
}

#tiles-remaining-counter {
  width: 100%;
  text-align: center;
  padding: 12px 20px;
  margin: 10px 0;
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.15) 0%, rgba(255, 152, 0, 0.15) 100%);
  border: 1px solid rgba(255, 152, 0, 0.3);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #e65100;
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.2);
  animation: slideDown 0.3s ease;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #2c3e50;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4caf50;
  animation: pulse 2s infinite;
}

.status-indicator.disconnected .status-dot {
  background: #f44336;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Lobby styles */
#lobby-content {
  display: flex;
  gap: 40px;
  margin: 30px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.lobby-section {
  background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(248,249,250,0.95) 100%);
  backdrop-filter: blur(10px);
  padding: 40px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 
    0 12px 40px rgba(0,0,0,0.15),
    0 0 0 1px rgba(0,0,0,0.05) inset;
  min-width: 280px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.lobby-section:hover {
  transform: translateY(-4px);
  box-shadow: 
    0 16px 48px rgba(0,0,0,0.2),
    0 0 0 1px rgba(0,0,0,0.05) inset;
}

.lobby-section h3 {
  margin-top: 0;
  color: #333;
}

.lobby-section input {
  width: 100%;
  padding: 14px 18px;
  margin: 12px 0;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 12px;
  font-size: 16px;
  box-sizing: border-box;
  background: white;
  transition: all 0.3s ease;
  font-family: inherit;
}

.lobby-section input:focus {
  outline: none;
  border-color: #2196F3;
  box-shadow: 0 0 0 4px rgba(33, 150, 243, 0.1);
  transform: translateY(-1px);
}

.lobby-section input::placeholder {
  color: #999;
}

.lobby-section .button {
  width: 100%;
  margin-top: 10px;
}

.lobby-divider {
  display: flex;
  align-items: center;
  font-weight: bold;
  color: #666;
  margin: 20px 0;
}

#lobby-messages {
  color: #c12c2c;
  font-weight: bold;
  margin-top: 20px;
  min-height: 30px;
}

/* Waiting room styles */
#waiting-room-screen {
  text-align: center;
}

#room-code-display {
  background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(248,249,250,0.95) 100%);
  backdrop-filter: blur(10px);
  padding: 30px;
  border-radius: 20px;
  margin: 20px 0;
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 
    0 12px 40px rgba(0,0,0,0.15),
    0 0 0 1px rgba(0,0,0,0.05) inset;
}

#room-code-text {
  font-size: 32px;
  font-weight: bold;
  color: #3b6ea5;
  letter-spacing: 4px;
  font-family: monospace;
}

#players-list {
  background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(248,249,250,0.95) 100%);
  backdrop-filter: blur(10px);
  padding: 30px;
  border-radius: 20px;
  margin: 20px 0;
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 
    0 12px 40px rgba(0,0,0,0.15),
    0 0 0 1px rgba(0,0,0,0.05) inset;
  min-width: 300px;
}

#players-list-items {
  list-style: none;
  padding: 0;
  text-align: left;
}

#players-list-items li {
  padding: 10px;
  margin: 5px 0;
  background: #f5f5f5;
  border-radius: 4px;
}

#players-list-items li.host {
  background: #e3f2fd;
  font-weight: bold;
}

#waiting-controls {
  margin: 20px 0;
}

#waiting-messages {
  color: #27ae60;
  font-weight: bold;
  margin-top: 20px;
  min-height: 30px;
  text-align: center;
}

/* Responsive Design - Mobile First Approach */

/* Mobile Devices (phones, < 768px) */
@media (max-width: 767px) {
  body {
    padding: 10px;
  }

  #game {
    padding: 10px;
  }

  h1, h2 {
    font-size: 1.5rem;
    text-align: center;
  }

  h3 {
    font-size: 1.1rem;
  }

  .screen {
    padding: 20px 15px;
    margin: 10px auto;
    border-radius: 16px;
  }

  /* Board scaling for mobile - make it fit */
  #board {
    grid-template: repeat(15, 18px) / repeat(15, 18px);
    gap: 1px;
    padding: 2px;
    margin: 15px 0;
    max-width: calc(100vw - 40px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .cell {
    width: 18px;
    height: 18px;
    font-size: 9px;
    border-radius: 2px;
  }

  /* Smaller return icon on mobile */
  .cell.returnable::after {
    width: 12px;
    height: 12px;
    font-size: 8px;
    top: -3px;
    right: -3px;
    border-width: 1px;
    box-shadow: 0 2px 4px rgba(255, 87, 34, 0.4);
  }

  .bonus-label {
    font-size: 5px;
    bottom: 1px;
    right: 1px;
  }

  /* Tiles on board */
  .board-tile {
    font-size: 7px;
  }
  
  .board-tile-letter {
    font-size: 10px !important;
    line-height: 1;
  }

  .board-tile .tile-score {
    font-size: 5px;
    bottom: 1px;
    right: 1px;
  }

  /* Rack tiles */
  #rack {
    gap: 3px;
    padding: 10px 5px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .tile {
    width: 36px;
    height: 36px;
    font-size: 18px;
    flex-shrink: 0;
  }

  .tile-score {
    font-size: 8px;
    right: 2px;
    bottom: 1px;
  }

  /* Controls */
  #controls {
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding: 0 10px;
  }
  
  .button {
    width: 100%;
    padding: 14px 20px;
    font-size: 15px;
    border-radius: 12px;
    min-height: 48px; /* Touch-friendly */
  }

  /* Player info */
  #player-info {
    font-size: 14px;
    padding: 12px 16px;
    margin: 10px 0;
  }

  /* Messages */
  #messages {
    font-size: 13px;
    padding: 10px 14px;
    margin: 10px 0;
  }

  /* Live score preview */
  #live-score-preview {
    padding: 14px 20px;
    margin: 10px 0;
    font-size: 14px;
  }

  .score-preview-content {
    font-size: 14px;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }

  .score-value {
    font-size: 20px;
    padding: 4px 12px;
  }

  /* Lobby */
  #lobby-content {
    flex-direction: column;
    gap: 20px;
    margin: 20px 0;
  }

  .lobby-section {
    width: 100%;
    padding: 25px 20px;
    min-width: auto;
  }

  .lobby-divider {
    margin: 10px 0;
    font-size: 14px;
  }

  /* Waiting room */
  #room-code-display {
    padding: 20px 15px;
    margin: 15px 0;
  }

  #room-code-text {
    font-size: 24px;
    letter-spacing: 2px;
  }

  #players-list {
    padding: 20px 15px;
    margin: 15px 0;
    min-width: auto;
    width: 100%;
  }

  /* Modals */
  .modal-content {
    width: 95%;
    max-width: none;
    padding: 25px 20px;
    margin: 10% auto;
    border-radius: 20px;
    max-height: 85vh;
  }

  .modal-content h2 {
    font-size: 1.5rem;
  }

  /* Letter selection grid */
  #letter-selection-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 10px 5px;
  }

  .letter-btn {
    padding: 14px;
    font-size: 18px;
    border-radius: 10px;
  }

  /* Scoreboard & Leaderboard */
  .scoreboard-entry,
  .leaderboard-entry,
  .move-history-entry {
    padding: 10px;
    font-size: 13px;
  }

  .scoreboard-rank,
  .leaderboard-rank {
    font-size: 14px;
    min-width: 30px;
  }

  /* Game header */
  #game-header {
    flex-direction: column;
    gap: 10px;
    align-items: center;
    width: 100%;
  }

  #game-header h2 {
    font-size: 1.3rem;
    margin-bottom: 0;
  }

  .status-indicator {
    font-size: 12px;
  }
}

/* Tablet Devices (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  #game {
    padding: 15px;
  }

  h1, h2 {
    font-size: 1.75rem;
  }

  .screen {
    padding: 30px 25px;
    margin: 15px auto;
  }

  /* Board scaling for tablet */
  #board {
    grid-template: repeat(15, 32px) / repeat(15, 32px);
    gap: 2px;
    padding: 4px;
  }
  
  .cell {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .bonus-label {
    font-size: 7px;
  }

  .board-tile {
    font-size: 16px;
  }
  
  .board-tile-letter {
    font-size: 14px !important;
    line-height: 1;
  }

  .board-tile .tile-score {
    font-size: 8px;
  }

  /* Rack tiles */
  .tile {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .tile-score {
    font-size: 9px;
  }

  /* Controls */
  #controls {
    gap: 10px;
  }

  .button {
    padding: 12px 22px;
    font-size: 14px;
  }

  /* Lobby */
  #lobby-content {
    gap: 30px;
  }

  .lobby-section {
    min-width: 280px;
    padding: 35px 30px;
  }

  /* Modals */
  .modal-content {
    width: 85%;
    padding: 35px 30px;
  }

  /* Letter selection grid */
  #letter-selection-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
  }

  .letter-btn {
    padding: 16px;
    font-size: 20px;
  }
}

/* Desktop Devices (> 1024px) */
@media (min-width: 1025px) {
  /* Ensure proper max-widths */
  .screen {
    max-width: 1200px;
  }

  #board {
    grid-template: repeat(15, 40px) / repeat(15, 40px);
  }

  /* Hover effects only on desktop */
  .lobby-section:hover {
    transform: translateY(-4px);
  }

  .button:hover:not(:disabled) {
    transform: translateY(-3px);
  }

  .letter-btn:hover {
    transform: translateY(-3px) scale(1.05);
  }
}

/* Large Desktop (> 1440px) */
@media (min-width: 1440px) {
  #game {
    max-width: 1400px;
  }

  .screen {
    max-width: 1400px;
  }
}

/* Landscape Mobile */
@media (max-width: 767px) and (orientation: landscape) {
  #board {
    grid-template: repeat(15, 20px) / repeat(15, 20px);
  }

  .cell {
    width: 20px;
    height: 20px;
    font-size: 10px;
  }

  .tile {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .screen {
    padding: 15px;
  }

  h1, h2 {
    font-size: 1.3rem;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .button {
    min-height: 48px;
    min-width: 120px;
  }

  .cell {
    min-width: 22px;
    min-height: 22px;
  }

  .tile {
    min-width: 36px;
    min-height: 36px;
  }

  /* Remove hover effects on touch devices */
  .lobby-section:hover {
    transform: none;
  }

  .button:hover:not(:disabled) {
    transform: none;
  }

  .letter-btn:hover {
    transform: none;
  }

  /* Better spacing for touch */
  #controls {
    gap: 10px;
  }

  /* Prevent text selection on touch */
  .tile, .cell, .button {
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    -webkit-touch-callout: none;
    user-select: none;
  }
}

/* Prevent zoom on input focus on iOS */
@media screen and (max-width: 767px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

/* Improve scrolling on mobile */
@media (max-width: 767px) {
  .modal-content {
    -webkit-overflow-scrolling: touch;
  }

  #rack {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  #rack::-webkit-scrollbar {
    height: 4px;
  }

  #rack::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 2px;
  }
}

