:root {
  --bg-deep: #0f172a;
  --bg-board: #1e293b;
  --bg-cell: #334155;
  --bg-cell-hover: #475569;
  --player-blue: #38bdf8;
  --player-blue-dark: #0ea5e9;
  --player-blue-glow: rgba(56, 189, 248, 0.6);
  --enemy-red: #f87171;
  --enemy-red-dark: #ef4444;
  --enemy-red-glow: rgba(248, 113, 113, 0.6);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-gold: #fbbf24;
  --border-radius: 12px;
  --cell-radius: 10px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(ellipse at top, #1e293b 0%, #0f172a 60%, #020617 100%);
  color: var(--text-primary);
  user-select: none;
  touch-action: none;
}

.game-wrap {
  height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  gap: 16px;
  max-width: 500px;
  margin: 0 auto;
}

/* ===== 顶部栏 ===== */
.top-bar {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 14px;
  background: var(--bg-board);
  border-radius: var(--border-radius);
  min-width: 80px;
}

.player-score {
  justify-self: start;
  border: 1.5px solid rgba(56, 189, 248, 0.3);
}

.enemy-score {
  justify-self: end;
  border: 1.5px solid rgba(248, 113, 113, 0.3);
}

.score-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.player-score .score-label { color: var(--player-blue); }
.enemy-score .score-label { color: var(--enemy-red); }

.score-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.player-score .score-value { color: var(--player-blue); }
.enemy-score .score-value { color: var(--enemy-red); }

.score-count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.turn-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
}

.turn-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.turn-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.turn-indicator.player-turn .turn-text {
  color: var(--player-blue);
  text-shadow: 0 0 12px var(--player-blue-glow);
}

.turn-indicator.enemy-turn .turn-text {
  color: var(--enemy-red);
  text-shadow: 0 0 12px var(--enemy-red-glow);
}

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

.board {
  aspect-ratio: 1;
  width: 100%;
  max-width: 420px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  padding: 10px;
  background: var(--bg-board);
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.04);
}

.cell {
  background: var(--bg-cell);
  border-radius: var(--cell-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
  font-variant-numeric: tabular-nums;
}

.cell:hover:not(.occupied):not(.disabled) {
  background: var(--bg-cell-hover);
  transform: scale(1.04);
}

.cell:active:not(.occupied):not(.disabled) {
  transform: scale(0.96);
}

.cell.disabled {
  cursor: not-allowed;
}

/* 中心格子标识 */
.cell.center-cell::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 8px;
  border: 1.5px dashed rgba(251, 191, 36, 0.25);
  pointer-events: none;
}

/* 玩家棋子 */
.cell.player {
  background: linear-gradient(145deg, var(--player-blue-dark), #0284c7);
  color: #fff;
  box-shadow: 0 4px 12px -2px var(--player-blue-glow), inset 0 1px 0 rgba(255,255,255,0.2);
  cursor: default;
}

/* 敌方棋子 */
.cell.enemy {
  background: linear-gradient(145deg, var(--enemy-red-dark), #dc2626);
  color: #fff;
  box-shadow: 0 4px 12px -2px var(--enemy-red-glow), inset 0 1px 0 rgba(255,255,255,0.2);
  cursor: default;
}

/* 翻转动画 */
.cell.flipping {
  animation: flip 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes flip {
  0% { transform: scale(1) rotateY(0deg); }
  50% { transform: scale(1.12) rotateY(90deg); }
  100% { transform: scale(1) rotateY(0deg); }
}

/* 刚放置的高亮 */
.cell.placed {
  animation: placedPulse 0.6s ease-out;
}

@keyframes placedPulse {
  0% { transform: scale(0.7); opacity: 0; }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* 可点击的提示光晕 */
.cell.hint::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--cell-radius);
  border: 2px solid var(--accent-gold);
  opacity: 0.6;
  animation: hintPulse 1.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.03); }
}

/* ===== 底部栏 ===== */
.bottom-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.best-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.best-score span {
  font-size: 11px;
  color: var(--text-muted);
}

.best-score strong {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-gold);
  font-variant-numeric: tabular-nums;
}

.btn-primary, .btn-secondary {
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(145deg, var(--player-blue-dark), #0284c7);
  color: #fff;
  box-shadow: 0 4px 12px -2px var(--player-blue-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px -2px var(--player-blue-glow);
}

.btn-primary:active {
  transform: translateY(1px) scale(0.98);
}

.btn-primary.full {
  width: 100%;
  padding: 14px;
  font-size: 15px;
}

.btn-secondary {
  background: var(--bg-cell);
  color: var(--text-primary);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.btn-secondary:hover {
  background: var(--bg-cell-hover);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(1px) scale(0.98);
}

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.modal.hidden {
  display: none;
}

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

.modal-content {
  background: linear-gradient(180deg, var(--bg-board), #0f172a);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  box-shadow: 0 25px 80px -15px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-content h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 18px;
  text-align: center;
}

.rules-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.rule-item {
  display: flex;
  gap: 12px;
}

.rule-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-gold);
  padding-top: 2px;
  min-width: 24px;
}

.rule-text h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--text-primary);
}

.rule-text p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.rule-text strong {
  color: var(--player-blue);
  font-weight: 600;
}

/* 结束弹窗 */
.end-content {
  text-align: center;
}

.end-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.end-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.end-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 12px;
  background: var(--bg-cell);
  border-radius: 12px;
}

.end-stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.end-stat-value {
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.end-stat-value.blue { color: var(--player-blue); }
.end-stat-value.red { color: var(--enemy-red); }

.end-diff {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-gold);
  margin-bottom: 20px;
  padding: 10px;
  background: rgba(251, 191, 36, 0.1);
  border-radius: 10px;
}

.end-content h2.victory {
  color: var(--player-blue);
  text-shadow: 0 0 20px var(--player-blue-glow);
}

.end-content h2.defeat {
  color: var(--enemy-red);
  text-shadow: 0 0 20px var(--enemy-red-glow);
}

.end-content h2.draw {
  color: var(--text-secondary);
}

/* 响应式：小屏适配 */
@media (max-height: 650px) {
  .game-wrap {
    padding: 10px;
    gap: 10px;
  }
  .score-value {
    font-size: 22px;
  }
  .cell {
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .score-block {
    min-width: 68px;
    padding: 8px 10px;
  }
  .score-value {
    font-size: 20px;
  }
  .cell {
    font-size: 15px;
  }
  .btn-primary, .btn-secondary {
    padding: 10px 16px;
    font-size: 13px;
  }
}
