/* ============================================
   XIANGQI (Chinese Chess) - Game-Specific Styles
   Common styles are in ../css/common.css
   ============================================ */
/* Xiangqi-specific CSS Variables */
:root {
  --board-bg: #d4af37;
  --board-line: #000000;
}
body.theme-light {
  --board-bg: #d4af37;
  --board-line: #000000;
}

/* ============================================
   LOBBY ACTION COLORS (Xiangqi)
   ============================================ */
.lobby-actions .btn {
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 6px 14px rgba(0, 0, 0, 0.24);
}

.lobby-actions .btn:hover {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 10px 20px rgba(0, 0, 0, 0.3);
}

.lobby-actions .btn-primary {
  background: linear-gradient(135deg, #f15f7f 0%, #de3d63 100%);
  color: #fff;
}

.lobby-actions .btn-ai {
  background: linear-gradient(135deg, #5f7bff 0%, #3f58d9 100%);
  color: #fff;
}

.lobby-actions .btn-tutorial {
  background: linear-gradient(135deg, #20be87 0%, #109f71 100%);
  color: #fff;
}

.lobby-actions .btn-secondary {
  color: #f7fbff;
}

.lobby-actions .btn-secondary:nth-child(4) {
  background: linear-gradient(135deg, #2f74c8 0%, #1f5ba8 100%);
  border-color: rgba(169, 215, 255, 0.45);
}

.lobby-actions .btn-secondary:nth-child(5) {
  background: linear-gradient(135deg, #1eaebe 0%, #158694 100%);
  border-color: rgba(162, 244, 255, 0.42);
}

.lobby-actions .btn-secondary:nth-child(6) {
  background: linear-gradient(135deg, #576f96 0%, #3f5578 100%);
  border-color: rgba(188, 209, 241, 0.38);
}

.lobby-actions .btn-board {
  background: linear-gradient(135deg, #f8ad25 0%, #e88808 100%);
  color: #fff;
}
/* ============================================
   XIANGQI BOARD
   ============================================ */
.board-container {
  padding: 22px;
  background: var(--board-bg);
  border-radius: 5px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
  position: relative;
}
.xiangqi-board {
  display: grid;
  grid-template-columns: repeat(9, 79px);
  grid-template-rows: repeat(10, 65px);
  background: var(--board-bg);
  position: relative;
  border-radius: 5px;
}
/* Board lines SVG - grid lines, palace diagonals, border */
.board-lines {
  position: absolute;
  top: 22px;
  left: 22px;
  width: 711px;
  height: 650px;
  pointer-events: none;
  z-index: 1;
}
/* River area styling */
.river-cell {
  position: relative;
  background: transparent;
}
.cell {
  width: 79px;
  height: 65px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  z-index: 1;
}
.cell.valid-move::after {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0, 128, 0, 0.6);
  border: 2px solid rgba(0, 100, 0, 0.8);
  position: absolute;
}
.cell.illegal-move::after {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(220, 20, 60, 0.72);
  border: 2px solid rgba(139, 0, 0, 0.9);
  position: absolute;
}
.cell.disabled {
  cursor: not-allowed;
}
/* Mouse shadow effect */
#mouse-shadow {
  position: absolute;
  width: 46px;
  height: 46px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0.15) 40%, rgba(0, 0, 0, 0) 70%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  display: none;
  transform: translate(-50%, -50%);
}
/* ============================================
   XIANGQI PIECES (Circular / Round)
   ============================================ */
.piece {
  width: 59px;
  height: 59px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: 30px;
  cursor: pointer;
  position: relative;
  z-index: 2;
  transition: transform 0.15s, filter 0.15s;
  font-family: 'Noto Serif SC', 'SimSun', 'KaiTi', serif;
  border-radius: 50%;
  border: none;
  filter: drop-shadow(2px 3px 3px rgba(0, 0, 0, 0.5));
}
.piece.piece-general {
  width: 58px;
  height: 58px;
  font-size: 31px;
}
.piece.piece-small {
  width: 42px;
  height: 42px;
  font-size: 22px;
}
/* Inner cream area (circular) */
.piece::before {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  right: 1px;
  bottom: 1px;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.9) 0%, transparent 50%),
    linear-gradient(150deg, #f5ecd8 0%, #e8dcc0 40%, #d8c8a0 100%);
  z-index: -1;
}
.piece:hover {
  transform: scale(1.1) translateY(-2px);
  filter: drop-shadow(3px 4px 5px rgba(0, 0, 0, 0.6));
}
/* Red pieces */
.piece.red {
  background: linear-gradient(145deg, #d42040 0%, #a01830 50%, #801020 100%);
  color: #a01525;
  text-shadow: 0.5px 0.5px 0 rgba(255,255,255,0.8), -0.5px -0.5px 0 rgba(255,255,255,0.5);
}
/* Black pieces */
.piece.black {
  background: linear-gradient(145deg, #505050 0%, #333333 50%, #1a1a1a 100%);
  color: #222222;
  text-shadow: 0.5px 0.5px 0 rgba(255,255,255,0.8), -0.5px -0.5px 0 rgba(255,255,255,0.5);
}
/* Selected piece */
.piece.selected {
  transform: scale(1.15) translateY(-3px);
}
.piece.red.selected {
  animation: selected-pulse-red 0.8s ease-in-out infinite alternate;
}
.piece.black.selected {
  animation: selected-pulse-black 0.8s ease-in-out infinite alternate;
}
@keyframes selected-pulse-red {
  from {
    transform: scale(1.15) translateY(-3px);
    filter: drop-shadow(0 0 8px rgba(255, 50, 50, 0.9)) drop-shadow(0 0 15px rgba(255, 50, 50, 0.6));
  }
  to {
    transform: scale(1.2) translateY(-5px);
    filter: drop-shadow(0 0 12px rgba(255, 50, 50, 1)) drop-shadow(0 0 25px rgba(255, 50, 50, 0.8)) drop-shadow(0 0 40px rgba(255, 50, 50, 0.5));
  }
}
@keyframes selected-pulse-black {
  from {
    transform: scale(1.15) translateY(-3px);
    filter: drop-shadow(0 0 8px rgba(80, 80, 80, 0.9)) drop-shadow(0 0 15px rgba(80, 80, 80, 0.6));
  }
  to {
    transform: scale(1.2) translateY(-5px);
    filter: drop-shadow(0 0 12px rgba(80, 80, 80, 1)) drop-shadow(0 0 25px rgba(80, 80, 80, 0.8)) drop-shadow(0 0 40px rgba(80, 80, 80, 0.5));
  }
}
/* Last move highlight */
.cell.last-move-cell-red {
  background: radial-gradient(circle, rgba(255, 0, 0, 0.5) 0%, rgba(255, 0, 0, 0.2) 50%, transparent 70%) !important;
  animation: last-move-glow-red 0.8s ease-in-out infinite alternate;
}
.cell.last-move-cell-black {
  background: radial-gradient(circle, rgba(80, 80, 80, 0.5) 0%, rgba(80, 80, 80, 0.2) 50%, transparent 70%) !important;
  animation: last-move-glow-black 0.8s ease-in-out infinite alternate;
}
@keyframes last-move-glow-red {
  0% { background: radial-gradient(circle, rgba(255, 0, 0, 0.3) 0%, rgba(255, 0, 0, 0.1) 50%, transparent 70%); }
  100% { background: radial-gradient(circle, rgba(255, 0, 0, 0.6) 0%, rgba(255, 0, 0, 0.3) 50%, transparent 70%); }
}
@keyframes last-move-glow-black {
  0% { background: radial-gradient(circle, rgba(80, 80, 80, 0.3) 0%, rgba(80, 80, 80, 0.1) 50%, transparent 70%); }
  100% { background: radial-gradient(circle, rgba(80, 80, 80, 0.6) 0%, rgba(80, 80, 80, 0.3) 50%, transparent 70%); }
}
/* Piece indicator for player cards */
.piece-indicator {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  font-weight: bold;
  flex-shrink: 0;
  font-family: 'Noto Serif SC', 'SimSun', serif;
}
.piece-indicator.red {
  background: #f5e6c8;
  border: 3px solid #c41e3a;
  color: #c41e3a;
}
.piece-indicator.black {
  background: #f5e6c8;
  border: 3px solid #333333;
  color: #333333;
}
/* ============================================
   MOVE LIST
   ============================================ */
.move-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px;
  min-height: 0;
  background: transparent;
  border-radius: 0;
}
.move-list-header {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 10px;
  color: var(--text-secondary);
}
.move-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
  overflow-y: auto;
  align-content: flex-start;
  max-height: 80px;
}
.move-item {
  padding: 4px 8px;
  background: var(--bg-card);
  border-radius: 4px;
  font-size: 12px;
  font-family: monospace;
}
.move-item.red {
  border-left: 3px solid #c00;
}
.move-item.black {
  border-left: 3px solid #333;
}
/* ============================================
   SPEECH BUBBLE (Check/Checkmate/Warning)
   ============================================ */
.speech-bubble-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  pointer-events: none;
  display: none;
}
.speech-bubble-container.active {
  display: block;
  animation: bubble-appear 0.3s ease-out forwards;
}
.speech-bubble {
  position: relative;
  background: #fff;
  border: 4px solid #333;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  padding: 25px 40px;
  font-size: 32px;
  font-weight: bold;
  color: #333;
  text-align: center;
  box-shadow: 4px 4px 0 #333, 8px 8px 15px rgba(0, 0, 0, 0.3);
  font-family: 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  min-width: 150px;
}
.speech-bubble::before {
  content: '';
  position: absolute;
  top: -15px;
  left: 20%;
  width: 30px;
  height: 30px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 50%;
  border-bottom: none;
  z-index: -1;
}
.speech-bubble::after {
  content: '';
  position: absolute;
  top: -10px;
  right: 25%;
  width: 25px;
  height: 25px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 50%;
  border-bottom: none;
  z-index: -1;
}
.speech-bubble .cloud-bump-1 {
  position: absolute;
  top: -12px;
  left: 45%;
  width: 35px;
  height: 35px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 50%;
  border-bottom: none;
  z-index: -1;
}
.speech-bubble .cloud-bump-2 {
  position: absolute;
  bottom: -8px;
  left: 30%;
  width: 20px;
  height: 20px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 50%;
  border-top: none;
}
.speech-bubble .cloud-bump-3 {
  position: absolute;
  bottom: -10px;
  right: 35%;
  width: 25px;
  height: 25px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 50%;
  border-top: none;
}
/* Check - Red */
.speech-bubble.check {
  background: linear-gradient(135deg, #fff5f5 0%, #ffe0e0 100%);
  border-color: #c41e3a;
  color: #c41e3a;
  box-shadow: 4px 4px 0 #c41e3a, 8px 8px 20px rgba(196, 30, 58, 0.4);
}
.speech-bubble.check::before,
.speech-bubble.check::after,
.speech-bubble.check .cloud-bump-1,
.speech-bubble.check .cloud-bump-2,
.speech-bubble.check .cloud-bump-3 {
  background: linear-gradient(135deg, #fff5f5 0%, #ffe0e0 100%);
  border-color: #c41e3a;
}
/* Checkmate - Dark */
.speech-bubble.checkmate {
  background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
  border-color: #333333;
  color: #333333;
  box-shadow: 4px 4px 0 #333333, 8px 8px 20px rgba(51, 51, 51, 0.4);
}
.speech-bubble.checkmate::before,
.speech-bubble.checkmate::after,
.speech-bubble.checkmate .cloud-bump-1,
.speech-bubble.checkmate .cloud-bump-2,
.speech-bubble.checkmate .cloud-bump-3 {
  background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
  border-color: #333333;
}
/* Warning - Yellow */
.speech-bubble.warning {
  background: linear-gradient(135deg, #fffff0 0%, #fff8dc 100%);
  border-color: #daa520;
  color: #b8860b;
  box-shadow: 4px 4px 0 #daa520, 8px 8px 20px rgba(218, 165, 32, 0.4);
}
.speech-bubble.warning::before,
.speech-bubble.warning::after,
.speech-bubble.warning .cloud-bump-1,
.speech-bubble.warning .cloud-bump-2,
.speech-bubble.warning .cloud-bump-3 {
  background: linear-gradient(135deg, #fffff0 0%, #fff8dc 100%);
  border-color: #daa520;
}
@keyframes bubble-appear {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.2); }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes bubble-shake {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
  25% { transform: translate(-50%, -50%) rotate(-3deg); }
  75% { transform: translate(-50%, -50%) rotate(3deg); }
}
.speech-bubble-container.shake {
  animation: bubble-appear 0.3s ease-out, bubble-shake 0.15s ease-in-out 0.3s 3;
}
/* ============================================
   HINT HIGHLIGHT
   ============================================ */
.cell.hint-from::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  transform: translate(-50%, -50%);
  border: 4px solid #3b82f6;
  border-radius: 50%;
  animation: hint-pulse-from 0.8s ease-in-out infinite;
  pointer-events: none;
  z-index: 50;
}
.cell.hint-to::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  transform: translate(-50%, -50%);
  border: 4px dashed #fbbf24;
  border-radius: 50%;
  animation: hint-pulse-to 0.8s ease-in-out infinite;
  pointer-events: none;
  z-index: 50;
}
@keyframes hint-pulse-from {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; box-shadow: 0 0 10px rgba(59, 130, 246, 0.8); }
  50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.7; box-shadow: 0 0 20px rgba(59, 130, 246, 1); }
}
@keyframes hint-pulse-to {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; box-shadow: 0 0 10px rgba(251, 191, 36, 0.8); }
  50% { transform: translate(-50%, -50%) scale(1.15); opacity: 0.7; box-shadow: 0 0 25px rgba(251, 191, 36, 1); }
}
/* ============================================
   RESPONSIVE - 1090px (0.9x: 79px -> 71px)
   ============================================ */
@media (max-width: 1090px) {
  .board-container {
    padding: 20px;
  }
  .xiangqi-board {
    grid-template-columns: repeat(9, 71px);
    grid-template-rows: repeat(10, 59px);
  }
  .board-lines {
    top: 20px;
    left: 20px;
    width: 639px;
    height: 590px;
  }
  .cell {
    width: 71px;
    height: 59px;
  }
  .piece {
    width: 53px;
    height: 53px;
    font-size: 27px;
  }
  .piece.piece-general {
    width: 52px;
    height: 52px;
    font-size: 28px;
  }
  .piece.piece-small {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }
}
/* ============================================
   RESPONSIVE - 1010px (0.83x: 71px -> 59px)
   ============================================ */
@media (max-width: 1010px) {
  .board-container {
    padding: 16px;
  }
  .xiangqi-board {
    grid-template-columns: repeat(9, 59px);
    grid-template-rows: repeat(10, 49px);
  }
  .board-lines {
    top: 16px;
    left: 16px;
    width: 531px;
    height: 490px;
  }
  .cell {
    width: 59px;
    height: 49px;
  }
  .piece {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }
  .piece.piece-general {
    width: 43px;
    height: 43px;
    font-size: 23px;
  }
  .piece.piece-small {
    width: 31px;
    height: 31px;
    font-size: 16px;
  }
}
/* ============================================
   RESPONSIVE - Tablet (900px) (0.9x: 60px -> 54px)
   ============================================ */
@media (max-width: 900px) {
  .board-container {
    padding: 15px;
  }
  .xiangqi-board {
    grid-template-columns: repeat(9, 54px);
    grid-template-rows: repeat(10, 45px);
  }
  .board-lines {
    top: 15px;
    left: 15px;
    width: 486px;
    height: 450px;
  }
  .cell {
    width: 54px;
    height: 45px;
  }
  .piece {
    width: 41px;
    height: 41px;
    font-size: 20px;
  }
  .piece.piece-general {
    width: 40px;
    height: 40px;
    font-size: 21px;
  }
  .piece.piece-small {
    width: 29px;
    height: 29px;
    font-size: 15px;
  }
  .cell.hint-from::before,
  .cell.hint-to::before {
    width: 52px;
    height: 52px;
    border-width: 3px;
  }
}
/* ============================================
   RESPONSIVE - 847px (0.95x: 54px -> 51px)
   ============================================ */
@media (max-width: 847px) {
  .board-container {
    padding: 14px;
  }
  .xiangqi-board {
    grid-template-columns: repeat(9, 51px);
    grid-template-rows: repeat(10, 43px);
  }
  .board-lines {
    top: 14px;
    left: 14px;
    width: 459px;
    height: 430px;
  }
  .cell {
    width: 51px;
    height: 43px;
  }
  .piece {
    width: 39px;
    height: 39px;
    font-size: 19px;
  }
  .piece.piece-general {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }
  .piece.piece-small {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
}
/* ============================================
   RESPONSIVE - Mobile (600px)
   ============================================ */
@media (max-width: 600px) {
  .board-container {
    padding: 8px;
  }
  .xiangqi-board {
    grid-template-columns: repeat(9, 42px);
    grid-template-rows: repeat(10, 36px);
  }
  .xiangqi-board::before {
    top: 18px;
    left: 21px;
    width: calc(42px * 8);
    height: calc(36px * 9);
    background-size: 42px 36px;
  }
  .xiangqi-board::after {
    top: 17px;
    left: 20px;
    width: calc(42px * 8);
    height: calc(36px * 9);
  }
  .board-lines {
    top: 8px;
    left: 8px;
    width: 378px;
    height: 360px;
  }
  .cell {
    width: 42px;
    height: 36px;
  }
  .piece {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
  .piece.piece-general {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }
  .piece.piece-small {
    width: 27px;
    height: 27px;
    font-size: 13px;
  }
  .game-controls {
    max-width: 394px;
  }
  .move-list-container {
    display: none !important;
  }
  .speech-bubble {
    font-size: 24px;
    padding: 18px 30px;
    min-width: 120px;
  }
  .speech-bubble::before {
    width: 22px;
    height: 22px;
    top: -10px;
  }
  .speech-bubble::after {
    width: 18px;
    height: 18px;
    top: -8px;
  }
  .cell.hint-from::before,
  .cell.hint-to::before {
    width: 36px;
    height: 36px;
    border-width: 2px;
  }
}
/* ============================================
   RESPONSIVE - Small Mobile (400px)
   ============================================ */
@media (max-width: 400px) {
  .board-container {
    padding: 5px;
  }
  .xiangqi-board {
    grid-template-columns: repeat(9, 38px);
    grid-template-rows: repeat(10, 32px);
  }
  .xiangqi-board::before {
    top: 16px;
    left: 19px;
    width: calc(38px * 8);
    height: calc(32px * 9);
    background-size: 38px 32px;
  }
  .xiangqi-board::after {
    top: 15px;
    left: 18px;
    width: calc(38px * 8);
    height: calc(32px * 9);
  }
  .board-lines {
    top: 5px;
    left: 5px;
    width: 342px;
    height: 320px;
  }
  .cell {
    width: 38px;
    height: 32px;
  }
  .piece {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  .piece.piece-general {
    width: 30px;
    height: 30px;
    font-size: 16px;
  }
  .piece.piece-small {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  .game-controls {
    max-width: 352px;
  }
  .cell.hint-from::before,
  .cell.hint-to::before {
    width: 32px;
    height: 32px;
    border-width: 2px;
  }
}
/* ============================================
   820px and below: Mobile layout (board 100% width)
   SVG viewBox is 720x660, grid is 80x66 spacing
   Grid intersection: col*80+40, row*66+33
   Cell center and grid intersection alignment requires SVG offset
   ============================================ */
@media (max-width: 820px) {
  .board-container {
    width: 100%;
    padding: 0 !important;
    box-sizing: border-box;
    position: relative;
  }
  .xiangqi-board {
    width: 100%;
    /* SVG viewBox ratio: 720:660 */
    aspect-ratio: 720 / 660;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(10, 1fr);
    position: relative;
  }
  .board-lines {
    position: absolute !important;
    /* Match exactly with .board-container(=.xiangqi-board) */
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    /* SVG viewBox(720x660) and grid(9x10) correspond exactly
       Cell size: 80x66 (viewBox basis)
       Grid intersection: (40+col*80, 33+row*66) = cell center */
  }
  .cell {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  /* Piece sizes: King > Normal > Pawn */
  /* Normal pieces - medium size */
  .piece {
    width: calc((100vw - 12px) * 0.075);
    height: calc((100vw - 12px) * 0.075);
    font-size: calc((100vw - 12px) * 0.038);
  }
  /* King - largest */
  .piece.piece-general {
    width: calc((100vw - 12px) * 0.09);
    height: calc((100vw - 12px) * 0.09);
    font-size: calc((100vw - 12px) * 0.048);
  }
  /* Pawn - smallest */
  .piece.piece-small {
    width: calc((100vw - 12px) * 0.058);
    height: calc((100vw - 12px) * 0.058);
    font-size: calc((100vw - 12px) * 0.028);
  }
  .cell.hint-from::before,
  .cell.hint-to::before {
    width: calc((100vw - 12px) * 0.09);
    height: calc((100vw - 12px) * 0.09);
  }
}
/* ============================================
   RECONNECT OVERLAY
   ============================================ */
#reconnect-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}
#reconnect-overlay.active {
  display: flex;
}
.reconnect-content {
  text-align: center;
  color: white;
  padding: 30px;
  background: rgba(50, 50, 50, 0.9);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.reconnect-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: #6c5ce7;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.reconnect-text {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
}
.reconnect-attempt {
  font-size: 14px;
  color: #aaa;
  margin-bottom: 15px;
}
.reconnect-refresh {
  display: none;
  padding: 12px 24px;
  font-size: 16px;
  background: #6c5ce7;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.reconnect-refresh:hover {
  background: #5b4cdb;
}
/* ============================================
   TUTORIAL MODAL
   ============================================ */
.modal-tutorial {
  max-width: 520px;
  width: 95%;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  border: 2px solid #3a3a5c;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.modal-tutorial h2 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.5rem;
  color: #ffd700;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}
.tutorial-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.tutorial-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
#tutorial-canvas {
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), inset 0 0 30px rgba(0, 0, 0, 0.3);
  background: #dcb35c;
}
.tutorial-caption {
  font-size: 0.85rem;
  color: #a0a0c0;
  text-align: center;
  font-style: italic;
}
.tutorial-text {
  padding: 0 10px;
  text-align: center;
}
.tutorial-text h3 {
  font-size: 1.2rem;
  color: #fff;
  margin-bottom: 10px;
}
.tutorial-text p {
  font-size: 0.95rem;
  color: #c0c0d0;
  line-height: 1.6;
}
.tutorial-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.tutorial-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.progress-dots {
  display: flex;
  gap: 6px;
}
.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3a3a5c;
  transition: all 0.3s ease;
}
.progress-dot.active {
  background: #ffd700;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}
.progress-dot.completed {
  background: #4ade80;
}
.tutorial-progress span {
  font-size: 0.8rem;
  color: #808090;
}
.tutorial-navigation .btn {
  min-width: 90px;
}
.tutorial-navigation .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
/* Light theme */
body.theme-light .modal-tutorial {
  background: linear-gradient(180deg, #f5f5f5 0%, #e8e8e8 100%);
  border-color: #ccc;
}
body.theme-light .modal-tutorial h2 {
  color: #b8860b;
  text-shadow: none;
}
body.theme-light .tutorial-caption {
  color: #666;
}
body.theme-light .tutorial-text h3 {
  color: #333;
}
body.theme-light .tutorial-text p {
  color: #555;
}
body.theme-light .progress-dot {
  background: #ccc;
}
body.theme-light .progress-dot.active {
  background: #b8860b;
  box-shadow: 0 0 8px rgba(184, 134, 11, 0.5);
}
body.theme-light .tutorial-progress span {
  color: #888;
}
/* ============================================
   SPECTATOR MODE STYLES
   ============================================ */
/* Room List - Live Game Styling */
.room-item.room-live {
  border: 2px solid #e74c3c;
  background: linear-gradient(135deg, rgba(231, 76, 60, 0.1), rgba(192, 57, 43, 0.05));
  cursor: default;
}
.room-item.room-live:hover {
  transform: none;
  border-color: #c0392b;
}
.room-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.live-badge {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  animation: live-pulse 1.5s infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
/* ============================================
   CHAT TABS & PARTICIPANT LIST
   ============================================ */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0;
}
.chat-tab {
  flex: 1;
  padding: 10px 15px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.chat-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.chat-tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  font-weight: 500;
}
.participant-count {
  background: var(--accent);
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#chat-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}
#chat-content .chat-messages {
  flex: 1;
}
/* Participants List */
.participants-list {
  padding: 10px;
  overflow-y: auto;
  height: 100%;
}
.participant-section {
  margin-bottom: 15px;
}
.participant-section-header {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-color);
}
.participant-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.participant-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-secondary);
  border-radius: 8px;
  font-size: 13px;
}
.participant-item.player {
  border-left: 3px solid var(--accent);
}
.participant-item.host {
  border-left: 3px solid #f1c40f;
}
.participant-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.participant-info {
  flex: 1;
}
.participant-name {
  font-weight: 500;
  color: var(--text-primary);
}
.participant-role {
  font-size: 11px;
  color: var(--text-secondary);
}
.participant-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}
.participant-badge.host {
  background: #f1c40f;
  color: #000;
}
.participant-badge.red {
  background: #c41e3a;
  color: #fff;
}
.participant-badge.black {
  background: #333333;
  color: #fff;
}
.empty-participants {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
  font-size: 13px;
}

/* Responsive Ads */
@media (max-width: 768px) {
  .ad-pc-only { display: none !important; }
}
@media (min-width: 769px) {
  .ad-mobile-only { display: none !important; }
}

/* Ad Lobby Center */
.ad-lobby {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

/* Game room mobile bottom ad 320x50 (scroll) */
.ad-mobile-fixed {
  position: static;
  margin: 10px auto;
  width: 320px;
  height: 50px;
}

.ad-mobile-fixed.hidden {
  display: none;
}

/* ============================================
   SIDEBAR TAB (tab-based unified sidebar)
   ============================================ */
.sidebar {
  padding: 1px;
  gap: 1px;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1px;
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.sidebar-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  margin-bottom: -1px;
}

.sidebar-tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
}

#sidebar-chat-content .chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  background: var(--bg-card);
  border-radius: 1px;
  overflow: hidden;
  min-height: 0;
}

#sidebar-chat-content .chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#sidebar-chat-content .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1px;
  min-height: 150px;
}

#sidebar-chat-content .game-controls {
  padding: 10px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

#sidebar-chat-content .game-controls .btn {
  flex: 1;
  min-width: 80px;
}

.sidebar .ad-sidebar {
  flex-shrink: 0;
  margin-top: auto;
  display: flex;
  justify-content: center;
}

@media (max-width: 820px) {
  .sidebar-tabs {
    display: none;
  }
}

/* ============================================
   GAME-OVER MODAL (Xiangqi)
   ============================================ */
#game-over-modal .modal {
  width: min(560px, 94vw);
}

#game-over-modal .game-over-content h2 {
  font-size: 42px;
  margin-bottom: 14px;
  letter-spacing: -0.4px;
}

#game-over-modal .game-over-content .result {
  margin-bottom: 14px;
}

#game-over-modal .game-over-content .rating-change {
  margin-bottom: 10px;
  font-size: 19px;
}

#game-over-record-status {
  min-height: 24px;
  margin-bottom: 10px;
  color: rgba(224, 237, 255, 0.84) !important;
  text-align: center;
}

#game-over-modal .modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 6px;
}

#game-over-modal .modal-actions .btn {
  min-height: 58px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 800;
}

#game-over-modal .btn-go-records {
  grid-column: 2;
  grid-row: 1;
  background: linear-gradient(135deg, #2b7fd0 0%, #1e5eaa 100%);
  border: 1px solid rgba(170, 221, 255, 0.45);
  color: #fff;
}

#game-over-record-save-btn {
  grid-column: 1;
  grid-row: 1;
  background: linear-gradient(135deg, #27c383 0%, #179a65 100%);
  border: 1px solid rgba(170, 255, 220, 0.45);
  color: #fff;
}

#game-over-modal .btn-rematch-gameover {
  grid-column: 1;
  grid-row: 2;
  background: linear-gradient(135deg, #ff607f 0%, #ea3d65 100%);
  border: 1px solid rgba(255, 192, 211, 0.45);
  color: #fff;
}

#game-over-modal .btn-close-gameover {
  grid-column: 2;
  grid-row: 2;
  background: linear-gradient(135deg, #4a5d83 0%, #374968 100%);
  border: 1px solid rgba(202, 219, 245, 0.35);
  color: #f6fbff;
}

#game-over-modal .modal-actions .btn:hover {
  filter: brightness(1.06);
}

/* ============================================
   RECORDS PAGE (Xiangqi)
   ============================================ */
.records-page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 30px;
}

.records-main {
  background: linear-gradient(180deg, rgba(20, 33, 82, 0.72), rgba(17, 27, 70, 0.8));
  border: 1px solid rgba(128, 168, 245, 0.22);
  border-radius: 16px;
  padding: 14px;
}

.record-filters {
  display: flex;
  flex-direction: column;
  margin-bottom: 14px;
  gap: 10px;
}

.record-filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.records-inline-title {
  margin: 0;
  font-size: 42px;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.record-filters-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.record-filters-controls select {
  min-height: 44px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  color: #eef5ff !important;
  -webkit-text-fill-color: #eef5ff;
  background: rgba(9, 22, 68, 0.92);
  border-color: rgba(155, 195, 255, 0.34);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.record-filters-controls select option {
  color: #eef5ff;
  background: #0d1f56;
}

.record-filters-controls #record-filter-mode,
.record-filters-controls #record-filter-result {
  min-width: 220px;
  flex: 1 1 260px;
}

.record-filters-head .btn {
  min-height: 40px;
  padding: 0 16px;
  flex: 0 0 auto;
}

.record-layout {
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.record-replay-panel {
  border: 1px solid rgba(138, 175, 246, 0.24);
  background: linear-gradient(180deg, rgba(27, 43, 108, 0.72), rgba(23, 34, 84, 0.68));
  border-radius: 14px;
  padding: 12px;
}

.record-list-panel {
  align-self: start;
  border: 1px solid rgba(138, 175, 246, 0.24);
  background: linear-gradient(180deg, rgba(27, 43, 108, 0.72), rgba(23, 34, 84, 0.68));
  border-radius: 14px;
  padding: 11px;
}

.record-list-container {
  max-height: min(52vh, 430px);
  min-height: 120px;
  overflow-y: auto;
  border-radius: 12px;
  background: rgba(15, 27, 77, 0.72);
}

.record-item {
  border-radius: 10px;
  margin: 7px;
  padding: 13px 14px;
  border: 1px solid rgba(138, 175, 246, 0.2);
  background: rgba(44, 66, 144, 0.2);
  cursor: pointer;
}

.record-item:hover {
  background: rgba(78, 113, 224, 0.28);
}

.record-item.active {
  background: linear-gradient(135deg, rgba(88, 119, 224, 0.45), rgba(67, 92, 192, 0.34));
  border-color: rgba(181, 211, 255, 0.38);
}

.record-item .meta {
  font-size: 13px;
  margin-top: 7px;
  color: rgba(224, 237, 255, 0.82);
}

.record-item.record-empty {
  text-align: center;
  color: var(--text-secondary);
}

.record-xiangqi-board-shell {
  position: relative;
  width: min(100%, 700px);
  aspect-ratio: 711 / 650;
  margin: 0 auto;
  padding: 14px;
  background: #dfbe62;
  border-radius: 10px;
  border: 1px solid rgba(72, 39, 0, 0.22);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32), inset 0 0 0 1px rgba(72, 39, 0, 0.22);
}

.record-xiangqi-board {
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
}

.record-board-lines {
  top: 14px;
  left: 14px;
  width: calc(100% - 28px);
  height: calc(100% - 28px);
}

.record-xiangqi-board .cell {
  width: 100%;
  height: 100%;
  cursor: default;
}

.record-xiangqi-board .piece {
  width: min(80%, 52px);
  height: min(80%, 52px);
  font-size: clamp(16px, 2.4vw, 28px);
  cursor: default;
  transition: none;
}

.record-xiangqi-board .piece.piece-general {
  width: min(82%, 54px);
  height: min(82%, 54px);
  font-size: clamp(17px, 2.6vw, 30px);
}

.record-xiangqi-board .piece.piece-small {
  width: min(64%, 42px);
  height: min(64%, 42px);
  font-size: clamp(13px, 2vw, 22px);
}

.record-xiangqi-board .piece:hover {
  transform: none;
  filter: drop-shadow(2px 3px 3px rgba(0, 0, 0, 0.5));
}

.record-replay-controls {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.record-replay-controls .btn.btn-small {
  min-width: 44px;
  min-height: 36px;
  border-radius: 10px;
  font-size: 15px;
}

#record-replay-speed {
  min-height: 36px;
  border-radius: 10px;
  font-weight: 600;
  color: #eef5ff !important;
  -webkit-text-fill-color: #eef5ff;
}

#record-replay-speed option {
  color: #eef5ff;
  background: #0d1f56;
}

#record-replay-progress {
  margin-left: auto;
  font-size: 15px;
  font-weight: 700;
  min-width: 78px;
}

.record-replay-panel .modal-actions .btn {
  min-height: 42px;
  border-radius: 11px;
  font-size: 16px;
  font-weight: 700;
}

.records-login-required {
  padding: 18px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary);
  text-align: center;
}

@media (max-width: 820px) {
  .records-page {
    padding: 12px 8px 20px;
  }

  .records-inline-title {
    font-size: 34px;
  }

  .records-main {
    padding: 10px;
    border-radius: 12px;
  }

  .record-filters-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .record-filters-head .btn {
    width: 100%;
  }

  .record-filters-controls #record-filter-mode,
  .record-filters-controls #record-filter-result {
    min-width: 0;
    flex: 1 1 100%;
  }

  .record-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .record-list-container {
    max-height: 260px;
  }

  .record-list-panel,
  .record-replay-panel {
    padding: 8px;
  }

  .record-xiangqi-board-shell {
    padding: 8px;
  }

  #game-over-modal .modal-actions {
    grid-template-columns: 1fr;
  }

  #game-over-modal .game-over-content h2 {
    font-size: 34px;
  }

  #game-over-modal .modal-actions .btn {
    min-height: 52px;
    font-size: 16px;
  }
}
