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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  overflow: hidden;
}

/* Prevent selection and native drag during tile dragging (fixes Chrome jumping) */
body.dragging-tile {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing !important;
}

body.dragging-tile * {
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.screen.active {
  display: flex;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 2rem;
  color: #f4a261;
}

h2 {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  background: #3d3d5c;
  color: #eee;
  transition: background 0.2s;
}

.btn:hover {
  background: #4d4d6d;
}

.btn.primary {
  background: #e07a5f;
}

.btn.primary:hover {
  background: #d06a4f;
}

.btn.small {
  padding: 8px 12px;
  font-size: 0.9rem;
}

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

input, select {
  padding: 12px;
  border: 2px solid #3d3d5c;
  border-radius: 8px;
  font-size: 1rem;
  background: #16213e;
  color: #eee;
}

input:focus, select:focus {
  outline: none;
  border-color: #e07a5f;
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 300px;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.divider {
  text-align: center;
  color: #666;
  margin: 0.5rem 0;
}

.options {
  margin-top: 1.5rem;
  padding: 1.5rem;
  background: #16213e;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.options label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.hidden {
  display: none !important;
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.player-item {
  padding: 10px 20px;
  background: #16213e;
  border-radius: 8px;
}

.player-item.host::after {
  content: ' (Host)';
  color: #f4a261;
}

.waiting-text {
  color: #666;
  margin-top: 1rem;
}

/* Game Screen */
#game {
  padding: 10px;
  gap: 10px;
  height: 100vh;
  justify-content: flex-start;
}

#game.active {
  display: flex;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 10px;
  flex-shrink: 0;
}

.scoreboard {
  display: flex;
  gap: 20px;
}

.score-item {
  padding: 8px 16px;
  background: #16213e;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 100px;
}

.score-item.active {
  border: 2px solid #e07a5f;
  background: #1e3a5f;
}

.score-item .player-time {
  font-size: 1.2rem;
  font-weight: bold;
}

.score-item.active .player-time {
  color: #e07a5f;
}

.turn-indicator {
  padding: 8px 16px;
  background: #e07a5f;
  border-radius: 8px;
  font-weight: bold;
  animation: pulse 1.5s ease-in-out infinite;
}

.turn-indicator.waiting {
  background: #3d3d5c;
  animation: none;
}

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

.score-item .name {
  font-weight: bold;
}

.score-item .score {
  color: #f4a261;
}

.timer {
  font-size: 1.5rem;
  font-weight: bold;
  padding: 8px 16px;
  background: #16213e;
  border-radius: 8px;
}

.timer.warning {
  color: #e07a5f;
}

.timer.penalty {
  color: #c44536;
  animation: penaltyPulse 1s ease-in-out infinite;
}

@keyframes penaltyPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.game-area {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#board {
  background: #0f3460;
  border-radius: 8px;
  cursor: grab;
}

#board:active {
  cursor: grabbing;
}

.controls {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
}

.game-footer {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.rack {
  display: flex;
  gap: 5px;
  padding: 10px;
  background: #16213e;
  border-radius: 8px;
  min-height: 60px;
}

.tile {
  width: 45px;
  height: 45px;
  background: #f4e4c1;
  color: #1a1a2e;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: grab;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.tile .value {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.6rem;
}

.tile.selected {
  box-shadow: 0 0 0 3px #e07a5f;
}

.tile.placed {
  opacity: 0.6;
}

.tile.dragging {
  opacity: 0.8;
  cursor: grabbing;
}

.action-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.score-preview {
  padding: 8px 16px;
  background: #2a9d8f;
  border-radius: 8px;
  font-weight: bold;
  font-size: 1.1rem;
  display: none;
}

.score-preview.visible {
  display: inline-block;
}

.message {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: #16213e;
  border-radius: 8px;
  display: none;
}

.message.show {
  display: block;
}

.message.error {
  background: #c44536;
}

.message.success {
  background: #2a9d8f;
}

/* Final scores */
.final-scores {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 2rem;
}

.final-score-item {
  padding: 15px 30px;
  background: #16213e;
  border-radius: 8px;
  font-size: 1.2rem;
}

.final-score-item.winner {
  border: 2px solid #f4a261;
}
