/* ==========================================================================
   3RB ROYAL CHESS - Luxury Grandmaster Chess Styling
   ========================================================================== */

.chess-game-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  min-height: 100%;
  color: #f8fafc;
  font-family: 'Readex Pro', 'Cairo', sans-serif;
  user-select: none;
  box-sizing: border-box;
  padding: 6px 12px;
}

/* ── Top HUD ── */
.chess-top-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1022px;
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 14px;
  margin-bottom: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
}

.chess-hud-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chess-brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1.5px solid #f59e0b;
}

.chess-hud-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
}

.chess-hud-title span {
  color: #fbbf24;
}

.chess-turn-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 0.92rem;
  background: rgba(245, 158, 11, 0.15);
  border: 1.5px solid rgba(245, 158, 11, 0.5);
  color: #fde68a;
  transition: all 0.25s ease;
}

.chess-turn-pill.is-my-turn {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.35), rgba(217, 119, 6, 0.45));
  border-color: #f59e0b;
  color: #fff;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.55);
  animation: pulse-gold-turn 2s infinite ease-in-out;
}

.chess-turn-pill.in-check {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.4), rgba(185, 28, 28, 0.55));
  border-color: #ef4444;
  color: #fecaca;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.65);
  animation: pulse-red-check 1s infinite alternate;
}

@keyframes pulse-gold-turn {
  0%, 100% { box-shadow: 0 0 10px rgba(245, 158, 11, 0.4); }
  50% { box-shadow: 0 0 22px rgba(245, 158, 11, 0.8); }
}

@keyframes pulse-red-check {
  0% { transform: scale(1); }
  100% { transform: scale(1.04); }
}

.chess-hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chess-hud-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #cbd5e1;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.chess-hud-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: #f59e0b;
  color: #fff;
}

.chess-hud-btn.danger:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
  color: #fca5a5;
}

/* ── Main Arena: Symmetrical 3 Columns ── */
.chess-main-arena {
  display: grid;
  grid-template-columns: minmax(180px, 220px) min(420px, calc(100vh - 230px)) minmax(180px, 220px);
  justify-content: center;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 1022px;
  margin: 0 auto;
  box-sizing: border-box;
  padding-bottom: 25px;
}

/* ── Center Column: Board + Players ── */
.chess-center-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: min(420px, calc(100vh - 230px));
  max-width: 420px;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* ── Player Strips ── */
.chess-player-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 48px;
  min-height: 48px;
  padding: 4px 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  box-sizing: border-box;
  transition: all 0.2s ease;
  overflow: hidden;
}

.chess-player-strip.active-turn {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.16);
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.35);
}

.chess-player-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.chess-player-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid #f59e0b;
  object-fit: cover;
  flex-shrink: 0;
}

.chess-player-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1;
}

.chess-player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
}

.chess-player-name {
  font-weight: 800;
  font-size: 0.88rem;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.chess-color-tag {
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 700;
  flex-shrink: 0;
}

.chess-color-tag.white {
  background: #f8fafc;
  color: #0f172a;
}

.chess-color-tag.black {
  background: #0f172a;
  border: 1px solid #475569;
  color: #f8fafc;
}

.chess-captured-tray {
  display: flex;
  align-items: center;
  flex-direction: row;
  min-height: 18px;
  height: 18px;
  margin-top: 2px;
  padding: 1px 0;
  max-width: 100%;
}

.chess-captured-tray .chess-captured-mini-piece {
  width: 18px;
  height: 18px;
  object-fit: contain;
  margin-inline-end: -4px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.8));
  transition: transform 0.15s ease;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
}

.chess-captured-tray.compact .chess-captured-mini-piece {
  margin-inline-end: -6px;
}

.chess-captured-tray.ultra-compact .chess-captured-mini-piece {
  margin-inline-end: -7.5px;
}

.chess-captured-tray.ultra-compact .chess-captured-mini-piece.is-pawn {
  margin-inline-end: -8.5px;
}

.chess-captured-tray .chess-captured-mini-piece:hover {
  transform: translateY(-3px) scale(1.35);
  z-index: 50 !important;
}

.chess-material-diff {
  font-size: 0.78rem;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 8px;
}

.chess-material-diff.positive {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.15);
}

.chess-material-diff.negative {
  color: #f87171;
  background: rgba(248, 113, 113, 0.15);
}

.chess-material-diff.neutral {
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.1);
}

.chess-player-clock {
  font-size: 1.15rem;
  font-weight: 900;
  font-family: 'Outfit', monospace;
  color: #fff;
  background: #000;
  padding: 3px 12px;
  border-radius: 8px;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  letter-spacing: 1px;
  flex-shrink: 0;
  margin-inline-start: 10px;
}

.chess-player-clock.low-time {
  color: #ef4444;
  border-color: #ef4444;
  animation: clock-blink 1s infinite alternate;
}

@keyframes clock-blink {
  0% { opacity: 1; }
  100% { opacity: 0.55; }
}

/* ── The 8x8 Chessboard ── */
.chess-board-outer {
  position: relative;
  width: min(420px, calc(100vh - 230px));
  height: min(420px, calc(100vh - 230px));
  max-width: 420px;
  max-height: 420px;
  aspect-ratio: 1 / 1;
  padding: 12px;
  border-radius: 12px;
  background: linear-gradient(145deg, #3d1d0c, #1a0b04);
  border: 3px solid #b45309;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.85), inset 0 2px 4px rgba(254, 240, 138, 0.3), 0 0 0 4px #1c0b05;
  box-sizing: border-box;
}

.chess-board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  background: url('/assets/chess/chess_board.jpg') center/100% 100% no-repeat;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.8);
}

.chess-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: transparent;
  transition: background 0.15s ease;
}

.chess-square.light-square {
  background: transparent;
}

.chess-square.dark-square {
  background: transparent;
}

.chess-square:hover {
  background: rgba(245, 158, 11, 0.28);
}

.chess-square.selected-square {
  background: rgba(245, 158, 11, 0.55) !important;
  box-shadow: inset 0 0 0 3px #fbbf24;
}

.chess-square.last-move-src,
.chess-square.last-move-dst {
  background: rgba(251, 191, 36, 0.32) !important;
}

.chess-square.in-check-king {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.8) 0%, rgba(185, 28, 28, 0.5) 70%) !important;
  animation: king-check-glow 1s infinite alternate;
}

@keyframes king-check-glow {
  0% { box-shadow: inset 0 0 10px #ef4444; }
  100% { box-shadow: inset 0 0 25px #b91c1c; }
}

/* Legal Move Markers */
.legal-move-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.65);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.8);
  pointer-events: none;
  transition: transform 0.15s;
}

.legal-capture-ring {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  border: 4.5px solid rgba(239, 68, 68, 0.75);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
  pointer-events: none;
}

/* Coordinates - Permanently hidden for luxury authentic board */
.square-coord-file,
.square-coord-rank {
  display: none !important;
}

/* Chess Piece */
.chess-piece-img {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
  transition: transform 0.15s ease-out;
}

.chess-square:active .chess-piece-img {
  transform: scale(1.12);
}

/* ── Symmetrical Side Panels ── */
.chess-side-panel {
  width: 100%;
  max-width: 220px;
  height: min(490px, calc(100vh - 180px));
  max-height: calc(100vh - 180px);
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  overflow-y: auto;
}

.chess-side-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 12px;
}

.side-header-icon {
  font-size: 1.2rem;
}

.side-header-title {
  font-weight: 800;
  font-size: 0.95rem;
  color: #fbbf24;
  flex: 1;
}

.chess-moves-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.chess-side-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}

.side-card-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: #94a3b8;
  margin-bottom: 6px;
}

.side-material-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 700;
  color: #e2e8f0;
}

.chess-side-captured-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 32px;
}

.empty-tray-tip {
  font-size: 0.72rem;
  color: #64748b;
  font-style: italic;
}

.chess-side-captured-tray .chess-captured-mini-piece {
  width: 22px;
  height: 22px;
  object-fit: contain;
  margin: 1px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
  transition: transform 0.2s;
  cursor: pointer;
}

.chess-side-captured-tray .chess-captured-mini-piece:hover {
  transform: scale(1.25);
}

.chess-side-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chess-side-btn {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f1f5f9;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.chess-side-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: #f59e0b;
}

.chess-side-btn.warning:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: #f59e0b;
  color: #fde68a;
}

.chess-side-btn.danger:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
  color: #fca5a5;
}

/* Right Panel: Move History Table */
.chess-history-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  color: #94a3b8;
  margin-bottom: 6px;
}

.chess-history-table-header .col-num {
  width: 28px;
}

.chess-history-table-header .col-white,
.chess-history-table-header .col-black {
  flex: 1;
  text-align: center;
}

.chess-history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 2px;
}

.chess-history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.84rem;
  background: rgba(255, 255, 255, 0.03);
  font-family: 'Outfit', monospace;
  transition: background 0.15s;
}

.chess-history-row:hover {
  background: rgba(245, 158, 11, 0.12);
}

.chess-history-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.06);
}

.history-turn-num {
  color: #94a3b8;
  font-weight: 700;
  width: 28px;
  font-size: 0.78rem;
}

.history-move-white,
.history-move-black {
  flex: 1;
  text-align: center;
  color: #f1f5f9;
  font-weight: 600;
}

/* ── Promotion Modal ── */
.chess-promotion-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  border: 2px solid #f59e0b;
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(245, 158, 11, 0.4);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.promotion-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #fbbf24;
}

.promotion-options {
  display: flex;
  gap: 10px;
}

.promotion-piece-btn {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(245, 158, 11, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.promotion-piece-btn:hover {
  background: rgba(245, 158, 11, 0.28);
  border-color: #fbbf24;
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.4);
}

.promotion-piece-btn img {
  width: 75%;
  height: 75%;
}

/* ── Rules Modal ── */
.chess-rules-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  box-sizing: border-box;
}

.chess-rules-modal-card {
  width: 100%;
  max-width: 520px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 2px solid #f59e0b;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.85), 0 0 35px rgba(245, 158, 11, 0.35);
  box-sizing: border-box;
  animation: pop-modal 0.25s ease-out;
}

@keyframes pop-modal {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.rules-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.rules-modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #fbbf24;
}

.rules-close-x {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.rules-close-x:hover {
  color: #ef4444;
}

.rules-modal-body {
  max-height: 380px;
  overflow-y: auto;
  font-size: 0.9rem;
  color: #cbd5e1;
  line-height: 1.6;
}

.rule-section {
  margin-bottom: 14px;
}

.rule-section h4 {
  margin: 0 0 6px 0;
  font-size: 0.95rem;
  color: #fde68a;
}

.rule-section p, .rule-section ul {
  margin: 0;
  padding-right: 18px;
}

.rule-section li {
  margin-bottom: 4px;
}

.rules-confirm-btn {
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border: none;
  color: #0f172a;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.4);
}

.rules-confirm-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(245, 158, 11, 0.6);
}

/* ── Victory / Checkmate Modal ── */
.chess-gameover-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.chess-gameover-card {
  width: 90%;
  max-width: 440px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 2px solid #f59e0b;
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 35px rgba(245, 158, 11, 0.35);
  animation: pop-gameover 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes pop-gameover {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.gameover-crown-emblem {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

.gameover-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: #fbbf24;
  margin: 0 0 6px 0;
}

.gameover-reason {
  font-size: 1rem;
  color: #cbd5e1;
  margin-bottom: 18px;
}

.gameover-btn {
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border: none;
  color: #0f172a;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.gameover-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(245, 158, 11, 0.6);
}

/* ── Responsive Adaptations ── */
@media (max-width: 1040px) and (min-width: 821px) {
  .chess-main-arena {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: 1010px !important;
  }
  .chess-side-panel {
    width: 210px !important;
    height: min(490px, calc(100vh - 180px)) !important;
    padding: 10px !important;
  }
  .chess-center-column {
    width: auto !important;
    flex-shrink: 0 !important;
  }
  .chess-board-outer {
    width: min(440px, calc(100vh - 215px)) !important;
    height: min(440px, calc(100vh - 215px)) !important;
    padding: 10px !important;
  }
  .chess-player-strip {
    width: 100% !important;
    height: 38px !important;
  }
}

@media (max-height: 720px) {
  .chess-game-root {
    padding: 4px 8px !important;
  }
  .chess-top-hud {
    padding: 4px 12px !important;
    margin-bottom: 4px !important;
  }
  .chess-board-outer {
    width: min(420px, calc(100vh - 215px)) !important;
    height: min(420px, calc(100vh - 215px)) !important;
    padding: 10px !important;
  }
  .chess-side-panel {
    height: min(470px, calc(100vh - 170px)) !important;
    padding: 8px !important;
  }
  .chess-player-strip {
    height: 34px !important;
  }
}

@media (max-height: 620px) {
  .chess-game-root {
    padding: 2px 6px !important;
  }
  .chess-top-hud {
    padding: 3px 8px !important;
    margin-bottom: 3px !important;
    font-size: 0.85rem !important;
  }
  .chess-hud-brand {
    display: none !important;
  }
  .chess-board-outer {
    width: min(350px, calc(100vh - 195px)) !important;
    height: min(350px, calc(100vh - 195px)) !important;
    padding: 6px !important;
  }
  .chess-side-panel {
    height: min(420px, calc(100vh - 130px)) !important;
    padding: 6px !important;
  }
  .chess-player-strip {
    height: 30px !important;
    padding: 2px 8px !important;
  }
}

@media (max-width: 820px) {
  .chess-main-arena {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .chess-side-panel {
    width: 100%;
    max-width: 440px;
    height: auto;
    max-height: 220px;
  }

  .chess-board-outer,
  .chess-player-strip,
  .chess-center-column {
    width: 100%;
    max-width: min(440px, 92vw);
  }
}
