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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f5;
  min-height: 100vh;
  color: #333;
}

.view {
  display: none;
  width: 100%;
  min-height: 100vh;
  padding: 40px 20px;
}

.view.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card {
  background: #fff;
  border-radius: 16px;
  padding: 48px 40px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
  text-align: center;
  max-width: 400px;
  width: 100%;
}

h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.subtitle {
  color: #999;
  margin-bottom: 32px;
  font-size: 14px;
}

.error-text {
  color: #e53e3e;
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: #333;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: #333;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #555;
}

.btn-secondary {
  padding: 10px 24px;
  background: #fff;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #f5f5f5;
}

.lobby-container,
.game-container {
  display: flex;
  gap: 24px;
  max-width: 900px;
  width: 100%;
  align-items: flex-start;
}

.lobby-main,
.game-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 24px;
}

.lobby-header h2 {
  font-size: 24px;
}

#welcomeUser {
  color: #666;
  font-size: 14px;
}

.create-room-panel {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  margin-bottom: 24px;
}

.mode-select {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.mode-select label {
  font-size: 14px;
  color: #666;
}

.mode-btn {
  padding: 6px 14px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: #333;
  color: #fff;
  border-color: #333;
}

#customBestOf {
  width: 80px;
  margin-bottom: 0;
}

.room-list {
  width: 100%;
}

.room-list h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: #666;
}

.room-item {
  background: #fff;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 6px rgba(0,0,0,0.03);
}

.room-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.room-item-name {
  font-weight: 600;
  font-size: 15px;
}

.room-item-meta {
  font-size: 12px;
  color: #999;
}

.room-item .btn-primary {
  width: auto;
  padding: 8px 20px;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.waiting-text {
  color: #666;
  margin-bottom: 24px;
}

.loader {
  width: 32px;
  height: 32px;
  border: 3px solid #eee;
  border-top-color: #333;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 24px;
}

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

.game-top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 360px;
  margin-bottom: 24px;
}

.game-header {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sound-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sound-toggle:hover {
  background: #f5f5f5;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-info.right {
  flex-direction: row-reverse;
}

.player-name {
  font-weight: 600;
  font-size: 14px;
}

.player-mark {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
}

.player-score {
  font-size: 20px;
  font-weight: 700;
}

.game-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  color: #999;
}

.board {
  display: grid;
  grid-template-columns: 100px 100px 100px;
  grid-template-rows: 100px 100px 100px;
  gap: 6px;
  margin-bottom: 24px;
}

.cell {
  width: 100px;
  height: 100px;
  background: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: background 0.15s;
  user-select: none;
  line-height: 1;
}

.cell:hover {
  background: #fafafa;
}

.cell.x {
  color: #333;
}

.cell.o {
  color: #888;
}

.chat-panel {
  width: 280px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  height: 500px;
  flex-shrink: 0;
}

.chat-title {
  padding: 14px 16px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid #f0f0f0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-msg {
  font-size: 13px;
  line-height: 1.5;
  word-break: break-all;
}

.chat-msg-time {
  font-size: 11px;
  color: #bbb;
  margin-right: 6px;
}

.chat-msg-user {
  font-weight: 600;
  margin-right: 6px;
  color: #555;
}

.chat-msg-text {
  word-break: break-word;
}

.chat-input-wrap {
  padding: 12px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  gap: 6px;
  align-items: center;
  position: relative;
}

.chat-input-wrap input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  margin-bottom: 0;
}

.chat-input-wrap input:focus {
  border-color: #333;
}

.chat-send-btn {
  padding: 8px 14px;
  background: #333;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

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

.emoji-btn {
  width: 34px;
  height: 34px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.emoji-btn:hover {
  background: #f5f5f5;
}

.emoji-picker {
  position: absolute;
  bottom: 56px;
  left: 12px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  z-index: 50;
  width: 254px;
}

.emoji-picker span {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  border-radius: 4px;
}

.emoji-picker span:hover {
  background: #f0f0f0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  max-width: 360px;
  width: 90%;
}

.modal-content h2 {
  margin-bottom: 12px;
  font-size: 22px;
}

.modal-content p {
  color: #666;
  margin-bottom: 24px;
}

#noRooms {
  text-align: center;
  color: #999;
  padding: 32px;
  font-size: 14px;
}

@media (max-width: 768px) {
  .lobby-container,
  .game-container {
    flex-direction: column;
    align-items: center;
  }
  .chat-panel {
    width: 100%;
    max-width: 400px;
    height: 300px;
  }
  .board {
    grid-template-columns: 85px 85px 85px;
    grid-template-rows: 85px 85px 85px;
  }
  .cell {
    width: 85px;
    height: 85px;
    font-size: 36px;
  }
}
