/* 井字棋游戏样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
  padding: 20px;
}

.game-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 500px;
}

/* 头部信息栏 */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 15px 25px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

.game-title {
  text-align: left;
}

.title-main {
  font-size: 24px;
  font-weight: bold;
  color: #fff;
}

.title-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* 控制按钮 */
.control-buttons {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-home {
  background: #e74c3c;
  color: #fff;
}

.btn-home:hover {
  background: #c0392b;
  transform: translateY(-2px);
}

.btn-restart {
  background: #27ae60;
  color: #fff;
}

.btn-restart:hover {
  background: #219a52;
  transform: translateY(-2px);
}

.btn-mode {
  background: #3498db;
  color: #fff;
}

.btn-mode:hover {
  background: #2980b9;
  transform: translateY(-2px);
}

/* 模式选择界面 */
.mode-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 450px;
  overflow: hidden;
}

/* Tab 标签栏 */
.mode-tabs {
  display: flex;
  width: 100%;
}

.mode-tab {
  flex: 1;
  padding: 16px 10px;
  font-size: 16px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: all 0.3s ease;
}

.mode-tab:hover {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.05);
}

.mode-tab.active {
  color: #fff;
  border-bottom-color: #e74c3c;
  background: rgba(255, 255, 255, 0.08);
}

.tab-panel {
  display: none;
  width: 100%;
  padding: 25px 30px 30px;
}

.tab-panel.active {
  display: block;
}

.mode-title {
  font-size: 22px;
  font-weight: bold;
  color: #fff;
  text-align: center;
}

.mode-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  width: 100%;
}

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

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: #3498db;
  transform: translateY(-3px);
}

.mode-icon {
  font-size: 32px;
}

.mode-text {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  text-align: center;
}

.mode-desc {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
}

/* 游戏主界面容器 */
.game-board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

/* 计分板 */
.scoreboard {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 20px;
  border-radius: 8px;
  min-width: 80px;
}

.score-item.player-x {
  background: rgba(231, 76, 60, 0.2);
  border: 2px solid #e74c3c;
}

.score-item.player-o {
  background: rgba(52, 152, 219, 0.2);
  border: 2px solid #3498db;
}

.score-item.draws {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.score-icon {
  font-size: 24px;
}

.score-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-value {
  font-size: 28px;
  font-weight: bold;
  color: #fff;
}

/* 当前玩家指示器 */
.current-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 25px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 25px;
  font-size: 16px;
  font-weight: 600;
}

.cp-icon {
  font-size: 20px;
}

.cp-text {
  color: #fff;
}

/* 游戏棋盘 */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 350px;
  aspect-ratio: 1;
  padding: 15px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  backdrop-filter: blur(10px);
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  font-size: 48px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  user-select: none;
}

.cell:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

.cell.x {
  color: #e74c3c;
  text-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
}

.cell.o {
  color: #3498db;
  text-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

.cell.winner {
  background: rgba(39, 174, 96, 0.4);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* 游戏控制按钮 */
.game-controls {
  display: flex;
  gap: 15px;
  width: 100%;
  justify-content: center;
}

.game-controls .btn {
  padding: 12px 25px;
  font-size: 15px;
}

/* 游戏结束覆盖层 */
.game-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.game-overlay[style*="display: flex"] {
  display: flex !important;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 50px;
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  border-radius: 20px;
  text-align: center;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.overlay-title {
  font-size: 36px;
  font-weight: bold;
  color: #f1c40f;
}

.overlay-message {
  font-size: 20px;
  color: #fff;
}

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
}

.overlay-btn {
  padding: 15px 40px;
  font-size: 18px;
  background: #27ae60;
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
}

.overlay-btn:hover {
  background: #219a52;
  transform: scale(1.05);
}

.overlay-btn.secondary {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

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

/* ============ 联网对战样式 ============ */

/* 在线模式按钮高亮 */
.mode-btn.online-btn {
  border: 2px solid #27ae60;
  background: rgba(39, 174, 96, 0.15);
}

.mode-btn.online-btn:hover {
  background: rgba(39, 174, 96, 0.3);
  border-color: #2ecc71;
}

/* 匹配等待 */
.match-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 50px 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 450px;
}

.match-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.match-text {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}

.match-sub {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
}

.btn-cancel {
  background: #e74c3c;
  color: #fff;
}

.btn-cancel:hover {
  background: #c0392b;
}

/* 房间等待 */
.room-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 450px;
}

.room-info {
  text-align: center;
}

.room-title {
  font-size: 20px;
  font-weight: bold;
  color: #2ecc71;
  margin-bottom: 10px;
}

.room-id {
  font-size: 32px;
  font-weight: bold;
  color: #f1c40f;
  margin: 10px 0;
}

.room-share {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  justify-content: center;
}

.room-share-link {
  flex: 1;
  max-width: 260px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  background: rgba(0,0,0,0.3);
  color: #fff;
  font-size: 13px;
  text-align: center;
  outline: none;
  -webkit-user-select: all;
  user-select: all;
}

.btn-copy {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: #4caf50;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-copy:active {
  background: #388e3c;
}

.btn-copy.copied {
  background: #666;
}

.room-status {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.8);
}

/* 加入房间 */
.join-room {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 450px;
}

.join-title {
  font-size: 20px;
  font-weight: bold;
  color: #fff;
}

.room-input {
  width: 100%;
  max-width: 200px;
  padding: 15px;
  font-size: 24px;
  text-align: center;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  outline: none;
}

.room-input:focus {
  border-color: #3498db;
}

.join-buttons {
  display: flex;
  gap: 15px;
}

/* 在线状态栏 */
.online-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

.online-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
}

.online-player.me {
  background: rgba(39, 174, 96, 0.2);
  border: 2px solid #27ae60;
}

.online-player.opponent {
  background: rgba(231, 76, 60, 0.2);
  border: 2px solid #e74c3c;
}

.online-symbol {
  font-size: 20px;
}

.online-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.online-vs {
  font-size: 18px;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.5);
}

/* 响应式设计 */
@media (max-width: 500px) {
  .game-container {
    padding: 10px;
  }

  .game-header {
    padding: 12px 15px;
  }

  .title-main {
    font-size: 20px;
  }

  .mode-selector {
    padding: 30px 20px;
  }

  .mode-options {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .mode-btn {
    flex-direction: row;
    padding: 15px 20px;
    gap: 15px;
  }

  .mode-icon {
    font-size: 28px;
  }

  .mode-text, .mode-desc {
    text-align: left;
  }

  .scoreboard {
    padding: 12px 15px;
  }

  .score-item {
    padding: 8px 15px;
    min-width: 70px;
  }

  .score-icon {
    font-size: 20px;
  }

  .score-label {
    font-size: 10px;
  }

  .score-value {
    font-size: 24px;
  }

  .board {
    max-width: 300px;
    padding: 12px;
    gap: 8px;
  }

  .cell {
    font-size: 40px;
    border-radius: 10px;
  }

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

  .game-controls .btn {
    width: 100%;
    justify-content: center;
  }

  .overlay-content {
    padding: 30px 25px;
  }

  .overlay-title {
    font-size: 28px;
  }

  .overlay-message {
    font-size: 18px;
  }
}

@media (max-width: 350px) {
  .board {
    max-width: 260px;
  }

  .cell {
    font-size: 36px;
  }

  .current-player {
    font-size: 14px;
    padding: 10px 20px;
  }

  .cp-icon {
    font-size: 18px;
  }
}

/* 横屏优化 */
@media (max-height: 500px) and (orientation: landscape) {
  .game-container {
    flex-direction: row;
    max-width: 800px;
  }

  .mode-selector {
    flex-direction: row;
    max-width: 600px;
  }

  .mode-options {
    grid-template-columns: repeat(4, 1fr);
  }

  .game-board-container {
    flex-direction: row;
    align-items: center;
  }

  .scoreboard {
    flex-direction: column;
    width: auto;
  }

  .board {
    max-width: 300px;
  }

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