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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  min-height: 100vh;
  color: #e8e8e8;
}

/* Home page */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
  text-align: center;
}

h1 {
  font-size: 3rem;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #f5af19, #f12711);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 1.2rem;
  color: #a0a0a0;
  margin-bottom: 40px;
}

.section {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 25px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 20px;
  text-align: left;
}

.section h2 {
  text-align: center;
  margin-bottom: 20px;
}

.hidden {
  display: none !important;
}

.btn {
  padding: 14px 32px;
  font-size: 1.1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 600;
}

.btn-primary {
  background: linear-gradient(135deg, #f5af19, #f12711);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(245, 175, 25, 0.3);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

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

.btn-danger {
  background: linear-gradient(135deg, #dc2626, #991b1b);
  color: white;
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(220, 38, 38, 0.3);
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 15px;
  color: #4ade80;
}

.invite-link-container {
  display: flex;
  gap: 10px;
  margin: 20px 0;
}

.invite-link-container input {
  flex: 1;
  padding: 14px;
  font-size: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: white;
}

.feedback {
  color: #4ade80;
  margin-bottom: 20px;
}

/* User Selection */
.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 15px;
}

.user-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 25px 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.user-btn:hover {
  background: rgba(245, 175, 25, 0.15);
  border-color: #f5af19;
  transform: translateY(-4px);
}

.user-emoji {
  font-size: 3rem;
}

.user-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
}

/* Current User Display */
.current-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  margin-bottom: 25px;
}

.current-user-emoji {
  font-size: 1.5rem;
}

.current-user-name {
  font-size: 1rem;
  color: white;
  flex: 1;
}

.logout-btn {
  padding: 6px 12px;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #a0a0a0;
  cursor: pointer;
  transition: all 0.2s;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.actions {
  margin-top: 20px;
}

/* Opponent Selection */
.opponent-selection {
  margin-bottom: 25px;
  text-align: left;
}

.opponent-selection label {
  display: block;
  margin-bottom: 12px;
  color: #a0a0a0;
  font-size: 0.95rem;
}

.opponent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 12px;
}

.opponent-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 15px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.opponent-btn:hover {
  background: rgba(245, 175, 25, 0.1);
  border-color: rgba(245, 175, 25, 0.3);
  transform: translateY(-2px);
}

.opponent-btn.selected {
  background: rgba(245, 175, 25, 0.2);
  border-color: #f5af19;
  box-shadow: 0 0 20px rgba(245, 175, 25, 0.3);
}

.opponent-emoji {
  font-size: 2rem;
}

.opponent-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
}

/* Challenge modal styling */
.challenger-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.challenger-emoji {
  font-size: 2rem;
}

/* Challenges List */
.challenges-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.challenge-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: rgba(245, 175, 25, 0.1);
  border: 1px solid rgba(245, 175, 25, 0.3);
  border-radius: 12px;
}

.challenge-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.challenge-info .challenger-emoji {
  font-size: 1.8rem;
}

.challenger-name {
  font-weight: 600;
  font-size: 1.1rem;
}

.challenge-time {
  color: #a0a0a0;
  font-size: 0.9rem;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
}

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

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

/* Data Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.data-table th {
  font-weight: 600;
  color: #a0a0a0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table tr:hover {
  background: rgba(255, 255, 255, 0.05);
}

.data-table .actions-cell {
  text-align: right;
  white-space: nowrap;
}

.data-table .actions-cell .btn {
  margin-left: 8px;
}

/* User Badge */
.user-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 8px;
}

.user-badge.incoming {
  background: rgba(74, 222, 128, 0.2);
  color: #4ade80;
}

.user-badge.outgoing {
  background: rgba(96, 165, 250, 0.2);
  color: #60a5fa;
}

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-active {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.status-won {
  background: rgba(74, 222, 128, 0.2);
  color: #4ade80;
}

.status-lost {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.status-draw {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}

/* My Turn Indicator */
.my-turn {
  color: #4ade80;
  font-weight: 600;
}

/* Empty Message */
.empty-message {
  text-align: center;
  color: #666;
  padding: 20px;
  font-style: italic;
}

/* Loading */
.loading {
  text-align: center;
  color: #666;
  padding: 20px;
}

/* Create Form */
.create-form {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
}

.create-form .opponent-selection {
  flex: 1;
  min-width: 200px;
}

.create-form .time-control {
  width: 120px;
}

.create-form .btn {
  white-space: nowrap;
}

/* PIN Input */
.pin-input-container {
  margin: 20px 0;
}

.pin-input {
  width: 150px;
  padding: 16px;
  font-size: 2rem;
  text-align: center;
  letter-spacing: 8px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.3);
  color: white;
  font-family: 'Courier New', monospace;
}

.pin-input:focus {
  outline: none;
  border-color: #f5af19;
}

.pin-error {
  color: #ef4444;
  font-weight: 600;
  margin-bottom: 15px;
}

.pin-user-emoji {
  font-size: 1.5rem;
  margin-right: 8px;
}

/* Time Control */
.time-control {
  margin-bottom: 25px;
  text-align: left;
}

.time-control label {
  display: block;
  margin-bottom: 8px;
  color: #a0a0a0;
  font-size: 0.95rem;
}

.select-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: white;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.select-input:focus {
  outline: none;
  border-color: #f5af19;
}

/* Game page */
.game-container {
  display: flex;
  flex-wrap: wrap;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  gap: 30px;
  justify-content: center;
  align-items: flex-start;
}

.board-container {
  width: 100%;
  max-width: 560px;
}

/* Board Players */
.board-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 8px 0;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
}

.board-player.active-turn {
  background: rgba(74, 222, 128, 0.15);
  border-color: rgba(74, 222, 128, 0.5);
  box-shadow: 0 0 15px rgba(74, 222, 128, 0.2);
}

.player-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-identity .player-emoji {
  font-size: 1.6rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.opponent-player .player-emoji {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  box-shadow: 0 4px 15px rgba(245, 87, 108, 0.4);
}

.my-player .player-emoji {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4);
}

.player-identity .player-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
}

.my-player {
  background: rgba(245, 175, 25, 0.1);
  border-color: rgba(245, 175, 25, 0.3);
}

.my-player.active-turn {
  background: rgba(74, 222, 128, 0.15);
  border-color: rgba(74, 222, 128, 0.5);
}

.board-player.player-offline {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
  opacity: 0.7;
}

.board-player.player-offline::after {
  content: ' (offline)';
  color: #ef4444;
  font-size: 0.85rem;
  margin-left: 8px;
}

/* Chess Clocks */
.chess-clock {
  font-family: 'Courier New', monospace;
}

.chess-clock.hidden {
  display: none;
}

.clock-time {
  font-size: 1.4rem;
  font-weight: bold;
  color: white;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 12px;
  border-radius: 6px;
}

.clock-time.low-time {
  color: #ef4444;
  animation: pulse 1s infinite;
}

.clock-time.active {
  color: #4ade80;
}

.game-info {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.game-info h1 {
  font-size: 2rem;
}

.status-panel {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Connection Status */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
}

.connection-status.connected .status-dot {
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
}

.connection-status.connected {
  color: #4ade80;
}

.connection-status.disconnected .status-dot {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

.connection-status.disconnected {
  color: #ef4444;
}

.connection-status.reconnecting .status-dot {
  background: #f59e0b;
  animation: pulse 1s infinite;
}

.connection-status.reconnecting {
  color: #f59e0b;
}

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

.player-info {
  font-size: 1.1rem;
  margin-bottom: 10px;
  color: #f5af19;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.spectator-badge {
  background: rgba(139, 92, 246, 0.3);
  color: #a78bfa;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  border: 1px solid rgba(139, 92, 246, 0.5);
}

.game-status {
  font-size: 1rem;
  color: #a0a0a0;
}

.move-history {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-height: 300px;
  overflow-y: auto;
}

.move-history h3 {
  margin-bottom: 15px;
  font-size: 1rem;
  color: #a0a0a0;
}

#moves {
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
}

.move-entry {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
}

.move-entry.white-move {
  background: rgba(255, 255, 255, 0.03);
}

.move-entry.black-move {
  background: rgba(0, 0, 0, 0.1);
}

.move-number {
  color: #666;
  margin-right: 4px;
  min-width: 24px;
}

.move-player {
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.white-move .move-player {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.black-move .move-player {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.move-piece {
  font-size: 1.2rem;
}

.move-square {
  font-weight: 600;
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

.move-capture {
  color: #f87171;
  font-weight: bold;
  font-size: 1.1rem;
}

.move-check {
  color: #fbbf24;
  font-weight: 600;
  margin-left: 4px;
}

.move-checkmate {
  color: #ef4444;
  font-weight: bold;
  margin-left: 4px;
}

.game-actions {
  margin-top: auto;
}

.game-save-hint {
  font-size: 0.85rem;
  color: #666;
  text-align: center;
  margin-top: 10px;
  font-style: italic;
}

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

.modal-content {
  background: #1a1a2e;
  padding: 40px;
  border-radius: 16px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-width: 400px;
}

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

.modal-content p {
  margin-bottom: 25px;
  color: #a0a0a0;
}

.modal-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
}

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

.game-actions .btn-icon {
  align-self: flex-start;
  padding: 10px 14px;
  font-size: 1.2rem;
  line-height: 1;
}

.btn-icon.muted {
  opacity: 0.5;
}

/* Promotion Modal */
.promotion-content {
  min-width: 300px;
}

.promotion-pieces {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.promotion-piece {
  width: 60px;
  height: 60px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.promotion-piece:hover {
  border-color: #f5af19;
  background-color: rgba(245, 175, 25, 0.2);
  transform: scale(1.1);
}

/* Responsive */
@media (max-width: 900px) {
  .game-container {
    flex-direction: column-reverse;
    align-items: center;
  }

  .game-info {
    width: 100%;
    max-width: 560px;
  }

  .board-container {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 2rem;
  }

  .section {
    padding: 25px;
  }

  .invite-link-container {
    flex-direction: column;
  }
}

/* Chessboard overrides */
.board-b72b1 {
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
