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

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

.screen {
  display: none;
  width: 100%;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  background: #16213e;
  border-radius: 16px;
  padding: 40px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

h1 {
  text-align: center;
  font-size: 2.2em;
  margin-bottom: 30px;
  color: #e94560;
}

h2 {
  font-size: 1.5em;
  color: #e94560;
}

/* Login */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-form input {
  padding: 14px 18px;
  border-radius: 10px;
  border: 2px solid #0f3460;
  background: #1a1a2e;
  color: #eee;
  font-size: 1.1em;
  outline: none;
  transition: border-color 0.2s;
}

.login-form input:focus {
  border-color: #e94560;
}

/* Rules section */
.rules-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #0f3460;
}

.rules-section h3 {
  color: #e94560;
  font-size: 1.1em;
  margin-bottom: 12px;
}

.rules-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules-section li {
  color: #aaa;
  font-size: 0.9em;
  line-height: 1.4;
  padding-left: 16px;
  position: relative;
}

.rules-section li::before {
  content: '>';
  position: absolute;
  left: 0;
  color: #e94560;
  font-weight: 600;
}

button {
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 1.05em;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}

.btn-primary, #btn-login {
  background: #e94560;
  color: white;
}

.btn-primary:hover, #btn-login:hover {
  background: #c73652;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #0f3460;
  color: #eee;
}

.btn-secondary:hover {
  background: #1a4a8a;
}

.btn-danger {
  background: #533;
  color: #e94560;
  border: 1px solid #e94560;
}

.btn-danger:hover {
  background: #744;
}

.btn-small {
  padding: 6px 14px;
  font-size: 0.85em;
  background: #0f3460;
  color: #aaa;
  border-radius: 8px;
}

.btn-small:hover {
  background: #1a4a8a;
  color: #eee;
}

/* Animated lobby background */
#screen-lobby {
  position: relative;
  overflow: hidden;
}

#screen-lobby::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(233, 69, 96, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(15, 52, 96, 0.35) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(233, 69, 96, 0.12) 0%, transparent 70%);
  animation: bgPulse 8s ease-in-out infinite alternate;
}

#screen-lobby .container {
  position: relative;
  z-index: 1;
}

.lobby-particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.lobby-particles .particle {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  animation: floatParticle linear infinite;
}

.lobby-particles .particle:nth-child(1) {
  width: 30px;
  height: 30px;
  background: radial-gradient(circle, rgba(240, 217, 181, 0.4), transparent 70%);
  border: 1px solid rgba(240, 217, 181, 0.25);
  left: 10%;
  animation-duration: 18s;
  animation-delay: 0s;
}

.lobby-particles .particle:nth-child(2) {
  width: 22px;
  height: 22px;
  background: radial-gradient(circle, rgba(233, 69, 96, 0.35), transparent 70%);
  border: 1px solid rgba(233, 69, 96, 0.2);
  left: 25%;
  animation-duration: 22s;
  animation-delay: 3s;
}

.lobby-particles .particle:nth-child(3) {
  width: 36px;
  height: 36px;
  background: radial-gradient(circle, rgba(58, 58, 58, 0.5), transparent 70%);
  border: 1px solid rgba(100, 100, 100, 0.25);
  left: 45%;
  animation-duration: 16s;
  animation-delay: 1s;
}

.lobby-particles .particle:nth-child(4) {
  width: 18px;
  height: 18px;
  background: radial-gradient(circle, rgba(240, 217, 181, 0.35), transparent 70%);
  border: 1px solid rgba(240, 217, 181, 0.2);
  left: 65%;
  animation-duration: 20s;
  animation-delay: 5s;
}

.lobby-particles .particle:nth-child(5) {
  width: 28px;
  height: 28px;
  background: radial-gradient(circle, rgba(233, 69, 96, 0.3), transparent 70%);
  border: 1px solid rgba(233, 69, 96, 0.18);
  left: 80%;
  animation-duration: 24s;
  animation-delay: 2s;
}

.lobby-particles .particle:nth-child(6) {
  width: 40px;
  height: 40px;
  background: radial-gradient(circle, rgba(15, 52, 96, 0.4), transparent 70%);
  border: 1px solid rgba(15, 52, 96, 0.25);
  left: 35%;
  animation-duration: 19s;
  animation-delay: 7s;
}

.lobby-particles .particle:nth-child(7) {
  width: 24px;
  height: 24px;
  background: radial-gradient(circle, rgba(240, 217, 181, 0.3), transparent 70%);
  border: 1px solid rgba(240, 217, 181, 0.18);
  left: 55%;
  animation-duration: 21s;
  animation-delay: 4s;
}

.lobby-particles .particle:nth-child(8) {
  width: 16px;
  height: 16px;
  background: radial-gradient(circle, rgba(233, 69, 96, 0.35), transparent 70%);
  border: 1px solid rgba(233, 69, 96, 0.2);
  left: 90%;
  animation-duration: 17s;
  animation-delay: 6s;
}

@keyframes floatParticle {
  0% {
    transform: translateY(110vh) translateX(0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-10vh) translateX(80px) rotate(360deg);
    opacity: 0;
  }
}

@keyframes bgPulse {
  0% {
    background:
      radial-gradient(circle at 20% 80%, rgba(233, 69, 96, 0.2) 0%, transparent 50%),
      radial-gradient(circle at 80% 20%, rgba(15, 52, 96, 0.35) 0%, transparent 50%),
      radial-gradient(circle at 50% 50%, rgba(233, 69, 96, 0.12) 0%, transparent 70%);
  }
  100% {
    background:
      radial-gradient(circle at 30% 70%, rgba(15, 52, 96, 0.3) 0%, transparent 50%),
      radial-gradient(circle at 70% 30%, rgba(233, 69, 96, 0.25) 0%, transparent 50%),
      radial-gradient(circle at 40% 60%, rgba(15, 52, 96, 0.2) 0%, transparent 70%);
  }
}

/* Lobby */
.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9em;
  color: #aaa;
}

.lobby-hint {
  color: #888;
  margin-bottom: 16px;
  font-size: 0.95em;
}

.players-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.player-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #1a1a2e;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.player-item:hover {
  border-color: #e94560;
  background: #1f2547;
}

.player-item .player-name {
  font-size: 1.05em;
}

.player-item .invite-text {
  color: #e94560;
  font-size: 0.85em;
  opacity: 0;
  transition: opacity 0.2s;
}

.player-item:hover .invite-text {
  opacity: 1;
}

.empty-message {
  color: #555;
  text-align: center;
  padding: 30px;
  font-style: italic;
}

/* Game */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.game-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 300px;
}

.player-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1em;
  padding: 6px 16px;
  border-radius: 8px;
}

.player-label.active-turn {
  background: #0f3460;
  box-shadow: 0 0 12px rgba(15, 52, 96, 0.5);
}

.piece-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #888;
}

.piece-icon.white {
  background: #f0d9b5;
  border-color: #c4a36e;
}

.piece-icon.black {
  background: #3a3a3a;
  border-color: #666;
}

.game-status {
  font-size: 1.2em;
  font-weight: 600;
  padding: 4px 0;
  color: #e94560;
}

#board-canvas {
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  max-width: 100%;
  height: auto;
}

.game-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

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

.modal.active {
  display: flex;
}

.modal-content {
  background: #16213e;
  padding: 30px;
  border-radius: 16px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-content p {
  font-size: 1.15em;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #e94560;
  color: white;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 1em;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 2000;
  white-space: nowrap;
}

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

/* Button disabled state */
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mobile */
@media (max-width: 600px) {
  body {
    align-items: flex-start;
    padding: 10px;
    overflow-x: hidden;
  }

  .screen {
    overflow-y: auto;
    max-height: 100dvh;
  }

  .container {
    padding: 20px;
    border-radius: 12px;
  }

  h1 {
    font-size: 1.6em;
    margin-bottom: 20px;
  }

  .game-container {
    gap: 6px;
    width: 100%;
    padding: 0 4px;
  }

  .game-info {
    min-width: auto;
    width: 100%;
    gap: 2px;
  }

  .player-label {
    font-size: 0.95em;
    padding: 4px 10px;
  }

  .game-status {
    font-size: 1em;
  }

  .game-actions {
    margin-top: 2px;
  }

  .game-actions button {
    padding: 8px 16px;
    font-size: 0.9em;
  }

  .lobby-header {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .toast {
    bottom: 15px;
    font-size: 0.9em;
    padding: 10px 20px;
  }

  .game-panels {
    flex-direction: column;
  }

  .move-log-body {
    max-height: 80px;
  }

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

  .result-icon {
    font-size: 3.5em;
  }

  .result-text {
    font-size: 1.8em;
  }
}

/* Player stats in lobby */
.player-info-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-stats {
  font-size: 0.8em;
  color: #888;
  background: #0f3460;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

/* Bot section */
.bot-section {
  margin-top: 16px;
}

.bot-buttons {
  display: flex;
  gap: 8px;
}

.btn-bot {
  flex: 1;
  padding: 10px 12px;
  font-size: 0.95em;
}

/* Game panels (move log + chat side by side) */
.game-panels {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 560px;
}

/* Move log */
.move-log {
  flex: 1;
  min-width: 0;
  background: #16213e;
  border-radius: 10px;
  overflow: hidden;
}

.move-log-header {
  padding: 8px 14px;
  font-size: 0.9em;
  font-weight: 600;
  color: #aaa;
  background: #0f3460;
}

.move-log-body {
  max-height: 150px;
  overflow-y: auto;
  padding: 6px 14px;
}

.move-log-row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  color: #ccc;
}

.move-num {
  color: #666;
  min-width: 30px;
}

.move-white {
  min-width: 70px;
  color: #f0d9b5;
}

.move-black {
  min-width: 70px;
  color: #aaa;
}

/* Game chat */
.game-chat {
  flex: 1;
  min-width: 0;
  background: #16213e;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 8px 14px;
  font-size: 0.9em;
  font-weight: 600;
  color: #aaa;
  background: #0f3460;
}

.chat-messages {
  flex: 1;
  min-height: 80px;
  max-height: 150px;
  overflow-y: auto;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-msg {
  font-size: 0.85em;
  line-height: 1.3;
  padding: 4px 8px;
  border-radius: 8px;
  max-width: 90%;
  word-break: break-word;
  animation: chatFadeIn 0.2s ease-out;
}

.chat-msg.self {
  align-self: flex-end;
  background: #0f3460;
  color: #ddd;
}

.chat-msg.opponent {
  align-self: flex-start;
  background: #1a1a2e;
  color: #ccc;
}

.chat-msg .chat-sender {
  font-size: 0.75em;
  color: #888;
  margin-bottom: 2px;
}

.chat-msg.sticker {
  font-size: 2.2em;
  background: none;
  padding: 2px 4px;
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.sticker-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px;
  border-top: 1px solid #0f3460;
  background: #121a30;
}

.sticker-btn {
  font-size: 1.4em;
  padding: 4px 6px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1;
}

.sticker-btn:hover {
  background: #0f3460;
}

.chat-input-row {
  display: flex;
  gap: 4px;
  padding: 6px;
  border-top: 1px solid #0f3460;
}

.chat-input-row input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #0f3460;
  background: #1a1a2e;
  color: #eee;
  font-size: 0.85em;
  outline: none;
}

.chat-input-row input:focus {
  border-color: #e94560;
}

.btn-stickers {
  padding: 4px 8px;
  background: none;
  border: none;
  font-size: 1.2em;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
  line-height: 1;
}

.btn-stickers:hover {
  background: #0f3460;
}

.btn-stickers.active {
  background: #0f3460;
}

.btn-send-chat {
  padding: 4px 10px;
  background: #e94560;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1;
}

.btn-send-chat:hover {
  background: #c73652;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 2px;
}

/* Result overlay */
.result-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  justify-content: center;
  align-items: center;
  z-index: 3000;
  opacity: 0;
  transition: opacity 0.4s;
}

.result-overlay.active {
  display: flex;
  opacity: 1;
  animation: fadeInOverlay 0.4s ease-out;
}

.result-content {
  text-align: center;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.result-icon {
  font-size: 5em;
  margin-bottom: 16px;
  animation: bounce 0.6s ease-out 0.3s both;
}

.result-text {
  font-size: 2.5em;
  font-weight: 700;
  margin-bottom: 8px;
}

.result-text.win {
  color: #4caf50;
  text-shadow: 0 0 30px rgba(76, 175, 80, 0.5);
}

.result-text.loss {
  color: #e94560;
  text-shadow: 0 0 30px rgba(233, 69, 96, 0.5);
}

.result-sub {
  font-size: 1.1em;
  color: #888;
}

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

@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.1); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}

/* Scrollbar */
.players-list::-webkit-scrollbar {
  width: 6px;
}

.players-list::-webkit-scrollbar-track {
  background: transparent;
}

.players-list::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 3px;
}

.move-log-body::-webkit-scrollbar {
  width: 6px;
}

.move-log-body::-webkit-scrollbar-track {
  background: transparent;
}

.move-log-body::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 3px;
}
