/* ===========================
   井字棋游戏样式
   =========================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --bg3: #16213e;
  --accent: #e94560;
  --accent-h: #c73652;
  --gold: #f0c040;
  --text: #eaeaea;
  --muted: #8892a4;
  --r-sm: 8px;
  --r-md: 16px;
  --r-lg: 24px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --tr: 0.25s ease;
}

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ===========================
   顶部导航
   =========================== */
.game-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: color var(--tr);
}

.nav-back:hover {
  color: var(--gold);
}

.nav-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===========================
   大厅样式
   =========================== */
.lobby {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lobby-card {
  background: var(--bg2);
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.lobby-step {
  text-align: center;
}

.lobby-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  display: block;
}

.lobby-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.lobby-desc {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: all var(--tr);
}

.mode-card:hover {
  background: rgba(240, 192, 64, 0.1);
  border-color: rgba(240, 192, 64, 0.25);
  transform: translateY(-2px);
}

.mode-emoji {
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

.mode-name {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
}

.mode-desc {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.room-input {
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--tr);
}

.room-input:focus {
  border-color: var(--gold);
}

.room-input::placeholder {
  color: var(--muted);
}

.lobby-btn {
  width: 100%;
}

.room-code-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.room-code {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-align: center;
}

.copy-btn {
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  color: var(--text);
  cursor: pointer;
  transition: all var(--tr);
}

.copy-btn:hover {
  background: rgba(240, 192, 64, 0.1);
  border-color: rgba(240, 192, 64, 0.25);
}

.lobby-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

.back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--tr);
}

.back-btn:hover {
  color: var(--gold);
}

/* ===========================
   游戏主界面
   =========================== */
.app {
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.header {
  text-align: center;
  margin-bottom: 24px;
}

.title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.main {
  display: flex;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

.board-section {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

#board {
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
  cursor: crosshair;
  touch-action: none;
  width: 450px;
  height: 450px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
}

.panel {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-md);
  padding: 20px;
  box-shadow: var(--shadow);
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg3);
  border-radius: var(--r-sm);
}

.symbol-preview {
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

#turnText {
  font-weight: 600;
  flex: 1;
}

.my-color-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg3);
  border-radius: var(--r-sm);
}

.my-color-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.my-color-name {
  font-weight: 600;
}

.timer-card {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto;
}

.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-track {
  fill: none;
  stroke: var(--bg3);
  stroke-width: 4;
}

.timer-bar {
  fill: none;
  stroke: var(--gold);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 213.6;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}

.timer-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.timer-num {
  font-size: 1.2rem;
  font-weight: 800;
  display: block;
}

.timer-unit {
  font-size: 0.7rem;
  color: var(--muted);
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg3);
  border-radius: var(--r-sm);
}

.score-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-symbol {
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

.score-info {
  flex: 1;
  min-width: 0;
}

.score-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.score-value {
  font-size: 1.1rem;
  font-weight: 800;
}

.score-divider {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--muted);
}

.round-info {
  text-align: center;
  padding: 8px 16px;
  background: var(--bg3);
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--tr);
  text-align: center;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), #e6a800);
  color: var(--bg);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(240, 192, 64, 0.3);
}

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}

.history-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.history-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--muted);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding-right: 4px;
}

.history-list li {
  padding: 6px 8px;
  background: var(--bg3);
  border-radius: var(--r-sm);
  margin-bottom: 4px;
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-list li:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

/* 滚动条样式 */
.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 2px;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 2px;
}

.history-list::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

/* ===========================
   胜利弹窗
   =========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tr);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-md);
  padding: 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  transition: transform var(--tr);
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  display: block;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.modal-desc {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 24px;
}

.modal-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===========================
   页面入场遮罩
   =========================== */
.page-enter-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 99999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
  opacity: 1;
  visibility: visible;
}

.page-enter-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
}

/* ===========================
   响应式
   =========================== */
@media (max-width: 768px) {
  .main {
    flex-direction: column;
    align-items: center;
  }

  .panel {
    width: 100%;
  }

  #board {
    max-width: 100%;
  }

  .lobby-card {
    padding: 24px;
  }

  .app {
    padding: 16px;
  }

  .btn-group {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .lobby-card {
    padding: 20px;
  }

  .mode-card {
    flex-direction: column;
    text-align: center;
    padding: 12px;
  }

  .mode-emoji {
    margin-bottom: 8px;
  }

  .room-code-box {
    flex-direction: column;
  }

  .room-code {
    width: 100%;
  }

  .copy-btn {
    width: 100%;
  }

  .app {
    padding: 12px;
    padding-top: 60px;
  }

  .title {
    font-size: 1.3rem;
  }

  .btn-group .btn {
    flex: 1;
    min-width: 0;
    font-size: .82rem;
    padding: 8px 6px;
  }

  .scoreboard {
    gap: 10px;
    padding: 8px 12px;
  }

  .score-value {
    font-size: 1rem;
  }

  .modal {
    padding: 24px 20px;
  }

  .modal-title {
    font-size: 1.3rem;
  }
}