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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #5d4037 0%, #795548 50%, #6d4c41 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: 16px;
  width: 100%;
  max-width: 520px;
}

/* 头部信息栏 */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 15px 25px;
  background: rgba(0, 0, 0, 0.25);
  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(0, 0, 0, 0.25);
  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: #ffb74d;
  background: rgba(255, 255, 255, 0.08);
}

/* Tab 面板 */
.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.12);
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: #ffb74d;
  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: 14px;
  width: 100%;
}

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

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

.score-item.player-black {
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid #333;
}

.score-item.player-black .score-icon {
  color: #222;
  text-shadow: 0 0 6px rgba(255,255,255,0.5);
}

.score-item.player-white {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.score-item.player-white .score-icon {
  color: #fff;
  text-shadow: 0 0 6px rgba(0,0,0,0.3);
}

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

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

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

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

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

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

.cp-text {
  color: #fff;
}

/* ============ 棋盘 ============ */
.board-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
}

.board {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1;
  background: #dcb35c;
  background-image:
    linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 50%, rgba(0,0,0,0.05) 100%);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4), inset 0 1px 3px rgba(255,255,255,0.2);
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  padding: 0;
  overflow: hidden;
}

/* 棋盘格线 - 用每个交叉点的 ::before 绘制 */
.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1;
  transition: background 0.15s;
}

.cell:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* 格线绘制 */
.cell::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

/* 水平线 - 穿过每个格子中心 */
.cell::before {
  background:
    linear-gradient(to bottom, transparent calc(50% - 0.5px), #8b6914 calc(50% - 0.5px), #8b6914 calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to right, transparent calc(50% - 0.5px), #8b6914 calc(50% - 0.5px), #8b6914 calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

/* 边缘格子截断线 */
/* 第一列：左边截断 */
.cell[data-col="0"]::before {
  background:
    linear-gradient(to bottom, transparent calc(50% - 0.5px), #8b6914 calc(50% - 0.5px), #8b6914 calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to right, transparent 50%, #8b6914 50%, #8b6914 calc(50% + 1px), transparent calc(50% + 1px));
  background-size: 100% 100%, 100% 100%;
  background-position: 0 0, 0 0;
}

/* 最后一列：右边截断 */
.cell[data-col="14"]::before {
  background:
    linear-gradient(to bottom, transparent calc(50% - 0.5px), #8b6914 calc(50% - 0.5px), #8b6914 calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to right, transparent calc(50% - 1px), #8b6914 calc(50% - 1px), #8b6914 50%, transparent 50%);
}

/* 第一行：上边截断 */
.cell[data-row="0"]::before {
  background:
    linear-gradient(to bottom, transparent 50%, #8b6914 50%, #8b6914 calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to right, transparent calc(50% - 0.5px), #8b6914 calc(50% - 0.5px), #8b6914 calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

/* 最后一行：下边截断 */
.cell[data-row="14"]::before {
  background:
    linear-gradient(to bottom, transparent calc(50% - 1px), #8b6914 calc(50% - 1px), #8b6914 50%, transparent 50%),
    linear-gradient(to right, transparent calc(50% - 0.5px), #8b6914 calc(50% - 0.5px), #8b6914 calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

/* 四角特殊处理 */
.cell[data-row="0"][data-col="0"]::before {
  background:
    linear-gradient(to bottom, transparent 50%, #8b6914 50%, #8b6914 calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to right, transparent 50%, #8b6914 50%, #8b6914 calc(50% + 1px), transparent calc(50% + 1px));
}

.cell[data-row="0"][data-col="14"]::before {
  background:
    linear-gradient(to bottom, transparent 50%, #8b6914 50%, #8b6914 calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to right, transparent calc(50% - 1px), #8b6914 calc(50% - 1px), #8b6914 50%, transparent 50%);
}

.cell[data-row="14"][data-col="0"]::before {
  background:
    linear-gradient(to bottom, transparent calc(50% - 1px), #8b6914 calc(50% - 1px), #8b6914 50%, transparent 50%),
    linear-gradient(to right, transparent 50%, #8b6914 50%, #8b6914 calc(50% + 1px), transparent calc(50% + 1px));
}

.cell[data-row="14"][data-col="14"]::before {
  background:
    linear-gradient(to bottom, transparent calc(50% - 1px), #8b6914 calc(50% - 1px), #8b6914 50%, transparent 50%),
    linear-gradient(to right, transparent calc(50% - 1px), #8b6914 calc(50% - 1px), #8b6914 50%, transparent 50%);
}

/* 星位点（天元和四个角星） */
.cell.star-point::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: #8b6914;
  border-radius: 50%;
  z-index: 0;
  pointer-events: none;
}

/* 棋子 */
.stone {
  width: 85%;
  height: 85%;
  border-radius: 50%;
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.stone.black {
  background: radial-gradient(circle at 35% 35%, #555, #111 60%, #000);
  box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.stone.white {
  background: radial-gradient(circle at 35% 35%, #fff, #e8e8e8 60%, #ccc);
  box-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* 最后一手标记 */
.stone.last-move::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30%;
  height: 30%;
  border-radius: 50%;
}

.stone.black.last-move::after {
  background: rgba(255, 255, 255, 0.5);
}

.stone.white.last-move::after {
  background: rgba(0, 0, 0, 0.3);
}

/* 获胜棋子高亮 */
.stone.winner {
  animation: winPulse 1s infinite;
}

.stone.black.winner {
  box-shadow: 0 0 12px 4px rgba(255, 215, 0, 0.7), 2px 2px 4px rgba(0,0,0,0.5);
}

.stone.white.winner {
  box-shadow: 0 0 12px 4px rgba(255, 215, 0, 0.7), 2px 2px 4px rgba(0,0,0,0.3);
}

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

/* 游戏控制按钮 */
.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, #5d4037 0%, #795548 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: #ffd54f;
}

.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(0, 0, 0, 0.25);
  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: #ffb74d;
  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(0, 0, 0, 0.25);
  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: #ffd54f;
  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(0, 0, 0, 0.25);
  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: #ffb74d;
}

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

/* 在线状态栏 */
.online-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.25);
  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: 8px;
    gap: 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: 10px 12px;
  }

  .score-item {
    padding: 6px 12px;
    min-width: 65px;
  }

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

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

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

  .board {
    max-width: 360px;
  }

  .star-point::after {
    width: 6px !important;
    height: 6px !important;
  }

  .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: 300px;
  }

  .current-player {
    font-size: 14px;
    padding: 8px 18px;
  }

  .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;
  }
}
